Am 07.03.2019 um 14:45 schrieb mailinglists@xxxxxxxxxxxxxx:
Hey Wouter, thanks, this side-remark clarifies a lot ! I have to withdraw my remark from last post: >>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 Everything works perfectly fine now, supposed we do 'adjustEndOfTrack" and write the MIDI file ! ( 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 ) }); ) // finish and store is necessary for changing mode! m.adjustEndOfTrack; m.write; m.midiEvents.dopostln; // get lengths in ticks m.noteSustainEvents(0).dopostln; // length values at 6th position m.noteSustainEvents(1).dopostln; m.timeMode = \seconds; m.midiEvents.dopostln; // get lengths in seconds m.noteSustainEvents(0).dopostln; // length values at 6th position m.noteSustainEvents(1).dopostln; ////////////////////////////////////// // version with multitrack midi file ( m = SimpleMIDIFile( "~/Desktop/midifiletest.mid" ); // create empty file m.init1(3, 120, "4/4"); // 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, track: 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: 5, track: 1 ) }); ) // finish and store is necessary for changing mode! m.adjustEndOfTrack; m.write; m.midiEvents.dopostln; // get lengths in ticks m.noteSustainEvents(0, 0).dopostln; // length values at 6th position m.noteSustainEvents(5, 1).dopostln; m.timeMode = \seconds; m.midiEvents.dopostln; // get lengths in seconds m.noteSustainEvents(0, 0).dopostln; // length values at 6th position m.noteSustainEvents(5, 1).dopostln; No wonder wslib quark turned out to be so popular in the user survey, it's a must have :) Cheers Daniel ----------------------------- http://daniel-mayer.at ----------------------------- |