// SLC 21 03 2023 // VERY COMPACT: exampe with MIDI keyboard input // edit: add a third hand and more // USE with different instruments: MIDIClient.destinations.postln; ( s.waitForBoot({ var right, left, timeOn, timeOff; var midiOut; MIDIdef.freeAll; if (~midi_initilized.isNil) { MIDIClient.init; MIDIIn.connectAll; midiOut = MIDIOut(0); // MIDI out ~midi_initialized = 1; }; ~n = ( // IS AN OBJECT WITH DATA AND FUNCTION IN A SINGLE LIST // compact notes: [2, 5, 4, 5, 6, 8, 2, 4, 9,5,8,1] + 55, // 12 pitches velos: { rrand(60, 100); }.dup(12), durs: { 1/5 }.dup(12), // table: Order(), noteOn: { arg n, note, val; timeOn = AppClock.beats; n.notes.size.postln; if(n.notes.size > 12, { n.notes.removeAt(0); }); n.notes.add((note % 24) + 55); n.notes.postln; // if(n.velos.size > 12, { n.velos.removeAt(0); }); n.velos.add(val); n.velos.postln; }, // noteOn: {|n,note| n.table[note] = 1}, noteOff: {|n, note| var d; timeOff = AppClock.beats; d = timeOff - timeOn; d.postln; note.postln; if(n.durs.size > 12, { n.durs.removeAt(0); }); n.durs.add(d); n.durs.postln; }, // noteOff: {|n,note| n.table.removeAt(note)}, get: {|n,i| n.table.indices[i] ?? n.table.indices.first ?? Rest(1) }, seq: { n.notes.scramble; }, /* seq: {|n, notes| notes.asArray.collect{|i| Plazy{n.get(i)}} }, */ seq2: {|n, notes| notes.asArray.collect{|i| Plazy{n.get(i)} + rrand(-5, 5); }.scramble; }, seq3: {|n, notes| notes.asArray.collect{|i| Plazy{n.get(i)} + rrand(-5, 5); }.reverse; } ); // MIDI on handler MIDIdef.noteOn(\noteOnHandle, { |val, num, chan, src| ~n.noteOn(num, val) } ); MIDIdef.noteOff(\noteOffHandle, { |val, num, chan, src| ~n.noteOff(num) } ); // EDIT AND EXPAND right = Pbind( // ************ \midiout, midiOut, \instrument, \default, \midinote, Pseq(~n.notes ), \amp, Pseq(~n.velos / 127), // \dur, 2*Pseq([1, 1, 1, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ].normalizeSum) \dur, Pseq(~n.durs) ); left = Pbind( // ************ \midiout, midiOut, \instrument, \default, \midinote, Pwrand([Pseq(~n.notes + 7, 1), Prand(~n.notes + 12, 7)], [0.8, 0.2], inf), \amp, Pseq(~n.velos / 127 ), \dur, Pseq(~n.durs) // \dur, 2*Pseq([1, 1, 1, 1, 1, 1, 1, 1].normalizeSum) ); if (~player.notNil) { ~player.stop; }; ~player = Pn(Ppar([right,left])).play; }); )