Changing time of MidiMessages


#1

hi

I'm looking to do a simple reverse function on a sequence of MIDI messages, so need a way to change the time of a message.

At the moment, I get the time by looking at the EventHolder relating to the message,  and can get the timestamp/time via

sequence.getEventTime(i);

 

but if I do a simple call like:

eventHolder->message.setTimeStamp(endTime - tmpTime);

just for the first message, then the whole sequence becomes unordered. The message timestamp itself () is not changed, eg:

when the endTime is 3840 and the first message is reversed the list appears:

print seq[7]: eventtime 3840, timestamp 0 (3) note on : 144, 48, 98 note off matches 8
print seq[8]: eventtime 264, timestamp 264 (3) note off: 128, 48, 64
print seq[9]: eventtime 490, timestamp 490 (3) note on : 144, 50, 98 note off matches 10
print seq[10]: eventtime 714, timestamp 714 (3) note off: 128, 50, 64

 

here eventtime is sequence.getEventTime(index) and the timestamp is event->message.getTimestamp()

 

 

what is the best way to reorder the timing of a single MIDI message in a MidiMessageSequence? and to ensure the event times in the sequence match the individual message timestamps?

 

 


#2

Well yes.. think about it: if you have some note ons and offs and reverse them, the offs will come before the ons!

Sounds like you need to think more deeply about how the midi format works and what you're trying to do - reversing midi isn't straightforward!


#3

sure, that's of course what I'd expect. maybe I'll try and be more specific here:

 

how do MidiMessageSequence::getEventTime(int index) and MidiMessage::getTimeStamp() differ?

 

I would have thought if I change the timestamp of an event in a MidiMessageSequence that would:

first alter the timestamp of the message

second, somehow change the pointer system of the sequence - not quite sure how this would work...

 

maybe a simpler example, how would you go about even moving a single note on event to happen earlier in a sequence? would you call setTimeStamp() on the eventHolder->message and then do some reordering call for the sequence?

 

 


#4

I can see from the documentation that when inserting an event into a sequence, the index will depend on the timestamp, so it sounds like by getting the timestamp right and inserting the message, it shoudl be okay.

 

for some reason, if I do something simple like

MidiMessageSequence emptySequence;

MidiMessage newNoteOnMessage(144,60,100,250);

 

emptySequence.addEvent(newNoteOnMessage);

 

I get a sequence with incorrect data, it has 1 event (correct) but is:

print seq[0]: eventtime 250, timestamp 0 (4) other   : 255, 32, 1

 

i.e. correct eventtime (from our timestamp for event) but midi metadata instead of note on.

 

am I doing something wrong here?

 

 


#5

Why are you trying to modify all these events in-place in the sequence? I'd have thought it'd make a lot more sense to just build a new sequence and swap them over when you're finished..


#6

yes, I've started looking at building a new sequence instead. hence the above question about the empty sequence.

 

MidiBuffer on the other hand works fine. If I create an empty MidiBuffer and an empty MidiMessageSequence then add a simple message MidiMessage(144,60,100,250) to both then buffer will display that fine i.e. note on pitch 60 etc.

but in the emptySequence I still find metadata instead (i.e. the oxFF2001 or 255,32,1) at the beginning and not the note on as added using addEvent(). Feel there's something I might be missing about initialising a message sequence in terms of MIDI metadata?


#7

my error about the metadata above

it was reading the wrong MidiSequence for the data part of the print out.

 

I'll investigate using a new MidiSequence for the transformed midi - with the correct data structure it should be fine!

 

 

Any thoughts on how to create metadata when writing a MIDI file?