[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] SimpleMIDIFile, get the duration and onset-time of the events




Am 07.03.2019 um 01:03 schrieb jamshark70@xxxxxxxxx:

You have to scan forward in the list of notes until you find the next
noteOff with the same note number. Then you have t1.

Actually this is not necessary, Wouter has built in a number of convenience methods, e.g. there's 'noteSustainEvents'.

Rewritten help file example

(
m = SimpleMIDIFile( "~/Desktop/midifiletest.mid" ); // create empty file

m.init0(1); // init for type 0

m.timeMode = \ticks;

((0, 20..500)).do({ |starttick| // add random notes
m.addNote(36 + 36.rand, 64 + 32.rand, starttick, rrand(1, 100), 127, 
channel: 0  
)
});

~ticks = Pseq([10, 20, 30], inf).iter;

((0, 20..500)).do({ |starttick| // add random notes to next track
m.addNote(72 + 36.rand, 64 + 32.rand, starttick, ~ticks.next, 127, 
channel: 1  
)
});
)


m.midiEvents.dopostln; 

m.noteSustainEvents(0).dopostln; // length values at 6th position
m.noteSustainEvents(1).dopostln;


With "actually" I meant that my quick tests showed some quirks:

.) Resetting time mode ( m.timeMode = \seconds; ) doesn't convert into seconds
.) In some cases this doesn't seem to work with multitrack files

However with file type 0 and also in mode \seconds it should give what's needed.

Best

Daniel

-----------------------------
http://daniel-mayer.at
-----------------------------