-
-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not Exact an issue- Get note time near to song time #5
Comments
Hi, Welcome back! Watched the video, looks really nice! Great job :) As for you problem, can you say what are Max |
@FabioZumbi12 Is your question still actual? |
Oh sorry, Still... but only for too near notes. The position and actual time is in Edit.: A print to show what i mean: http://prntscr.com/i83jk4 |
So your task is to get nearest note to the current position in audio file, yes? For example:
When current song pointer stays on note |
The initial task its to get the exact time from song to note. But i have a music playing in runtime, then i need to get the note using the song time. On my trys, using something like The task need to get the nearest, if is not Thanks for your time and sorry for the delayed aswers. |
Now I got it, thanks! :) What about this code: var notes = midiFile.GetNotes().ToArray();
var usedNotes = new List<Note>();
// ...
// Find the note nearest to the current position (this should be done every frame)
Note nearestNote = null;
var distance = long.MaxValue;
foreach (var note in notes.Where(n => !usedNotes.Contains(n)))
{
var newDistance = Math.Abs(position - note.TimeAs<MetricTimeSpan>(tempo).TotalMicroseconds);
// Notes are returned by GetNotes in order of ascending times so we can stop the loop
// when current distance between position and note's time is not decreased
if (newDistance >= distance)
break;
distance = newDistance;
nearestNote = note;
}
if (nearestNote != null)
usedNotes.Add(nearestNote); Can you test it and say whether it is faster than your solution or not? |
@FabioZumbi12 Is your problem solved? |
Sorry for the delay. I think yes changing the music speed. Thanks for help <3 |
Hi,
Me again and now with my game come to be ready soon using your source <3
Take a look: https://www.youtube.com/watch?v=fqLiBD0p2cI
But i am not here only to show you the game, but to ask about notes.
As you can see on some notes in this video, some notes next to other one have different distances, where on midi the distance is equals.
I think the way i using to get notes is not the best, but the song time is not the exat time of note, then, i cant get the note form midi only quering the song time, i need to get next nearest note based on last note time and new time in a interval.
Is there a best way to get the exat note using the song time?
I have created a Dictionary to cache the notes for difficulties based on note time. The way i get the note is:
Where the key is the note time.
And i run this loop on every frame.
If you know a better way to get and put the note time on my Disctionay or a better way to get the next note, ill glad if you can help.
Thank you!
Edit: This is only with too near notes, with other notes theres no problems.
The text was updated successfully, but these errors were encountered: