// title: Re: midified arpeggiator/auto-accompaniment using patterns // author: elgiano // description: // Re: Let me know if you have ideas for improvement! (code-wise or feature-wise) -> // I used an object prototype to streamline the process of registering notes and getting sequences of them. Code looks simpler to me and easier to further develop :) // code: ( s.waitForBoot({ var right, left; MIDIdef.freeAll; if (~midi_initilized.isNil) { MIDIClient.init; MIDIIn.connectAll; ~midi_initialized = 1; }; ~n = ( table: Order(), noteOn: {|n,note| n.table[note] = 1}, noteOff: {|n,note| n.table.removeAt(note)}, get: {|n,i| n.table.indices[i] ?? n.table.indices.first ?? Rest(1) }, seq: {|n,notes| notes.asArray.collect{|i| Plazy{n.get(i)}} } ); MIDIdef.noteOn( \mynoteonhandler, // just a name for this handler { |val, num, chan, src| ~n.noteOn(num) } ); MIDIdef.noteOff( \mynoteoffhandler, // just a name for this handler { |val, num, chan, src| ~n.noteOff(num) // update note table and update ~n /* // only enable the following lines if you want the arpeggio to stop as soon as you release the keys ~n.table.clear */ } ); right = Pbind( \instrument, \default, \midinote, Pseq(~n.seq( [ 0, 2, 1, 2] ++ (([ 0, 2, 1, 2] + 12)!2).flatten )), \dur, 2*Pseq([1, 1, 1, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 ].normalizeSum) ); left = Pbind( \instrument, \default, \midinote, Pseq(~n.seq([ 0, 2, 0, 2, 0, 2, 0, 2] - 12)), \dur, 2*Pseq([1, 1, 1, 1, 1, 1, 1, 1].normalizeSum) ); if (~player.notNil) { ~player.stop; }; ~player = Pn(Ppar([right,left])).play; }); )