// title: MIDIFile player with CC capability // author: LFSaw // description: // Play 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 // code: ( // 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; )