-
Notifications
You must be signed in to change notification settings - Fork 34
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
Is there already a method to get note length/duration? #4
Comments
I had this in an ancient version of the library, and it looks like this method got dropped by accident. This code is from 1993 and may not integrate directly but the algorithm was used to find note lengths to create sheet music display: ulong MIDITrack::GetNoteGateTime( unsigned int event ) const
{
ulong gate=0;
ulong start=0;
uchar channel, note;
// make sure buffer is valid and event is within it.
if( !buffer || event>last_event )
return 0;
// make sure that event is a note ON message
if( buffer[event].GetStatus() != M_NOTE_ON )
return 0;
// make sure that event has velocity>0
if( buffer[event].GetVelocity() == 0 )
return 0;
start=buffer[event].GetTime();
channel= buffer[event].GetChannel();
note= buffer[event].GetNote();
while( event<last_event-1 )
{
event++;
if( buffer[event].GetChannel() == channel )
{
if( buffer[event].GetNote()==note )
{
if( (buffer[event].GetStatus()==M_NOTE_OFF )
|| (buffer[event].GetStatus()==M_NOTE_ON
&& buffer[event].GetVelocity()==0 )
)
{
// we found the matching note off!
gate=buffer[event].GetTime()-start;
return gate;
}
}
}
}
return 0;
}
|
Thanks for the quick response Jeff, I really appreciate it. I'll give it a test today and make any necessary adjustments. If there's any major changes, i'll post back with my result. |
Added to the class MIDITrack the method NoteLength to get the length of a note (as requested in issue jdkoftinoff#4) in track.cpp Tuned doxygen comments in track.h Improved example test_stepsequencer (.h and .cpp)
Before I dive into creating my own method, I wanted to double check if there was already a way to get note length/durations when parsing or using the sequencer.
If that's not possible, is there a recommended way to implement this? Ideally I'd like to sequence a midi file and get the note lengths as it's playing back so I can visualize the length on screen.
The text was updated successfully, but these errors were encountered: