«MIDIFile player with CC capability» by LFSaw
on 20 May'17 19:03 inPlay a midi file and include CC value changes. Code taken from sc-users mailinglist.
http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/simpleMIDIfile-play-via-MIDIOut-including-CC-td7632193.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
(
// create a MIDI file
m = SimpleMIDIFile("~/output.mid");
m.init1;
m.timeMode_( \seconds ); // correct timeMode
// add some random Notes
((0,(1/8)..5)).do({ |starttime|
m.addNote( 36 + 50.rand, 32 + 96.rand, starttime, [0.1,0.05].choose, 127,
track: 1 )
});
// add some random CCs
((0,(1/8)..5)).do({ |starttime|
m.addMIDITypeEvent(type: 'cc', args: [7, 128.rand], absTime: starttime,
track: 1 )
});
m.adjustEndOfTrack; // may not be really needed, but nice if you want to do m.plot
)
MIDIClient.init;
(
~events = m.midiEvents;
~midiout = MIDIOut(0);
~routine = {
var lastTime = 0;
~events.do({ |evt|
(evt[1] - lastTime).wait;
lastTime = evt[1];
switch( evt[2].post,
\noteOn, { ~midiout.noteOn( *evt[3..].postln ); },
\noteOff, { ~midiout.noteOff( *evt[3..].postln ); },
\cc, { ~midiout.control( *evt[3..].postln ); }
); });
}.fork;
)
reception
comments