Advertisement
Guest User

scMidiKeys

a guest
Oct 26th, 2016
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (
  2. //Make SynthDef
  3. SynthDef(\sineNote, {|out = 0, gate=1, freq = 262, amp = 0.2|
  4.     var sig, env;
  5.     //Use sustaining envelope
  6.     env = EnvGen.kr(Env.asr(0.1,1,0.1), gate, doneAction: 2);
  7.     sig = SinOsc.ar(freq);
  8.     Out.ar(out, sig * env * amp);
  9. }).add;
  10. )
  11. (
  12. //Initialize MIDIClient
  13. MIDIClient.init
  14. //Connect Instrument(s)
  15. MIDIIn.connectAll
  16. // create array which will hold the individual synths for each key
  17. ~keys = nil!128;
  18.  
  19. MIDIdef.noteOn(\noteOn, {|vel, note|
  20.     ~keys[note] = Synth(\sineNote, [\freq, note.midicps, \amp, vel.linexp(0,127,0.01,1)]);
  21.     note.postln;
  22.     vel.postln;
  23.     })
  24. //If you want them to last after CmdPeriod
  25. // .permanent_(true)
  26. ;
  27.  
  28. MIDIdef.noteOff(\noteOff, {|vel, note|
  29.     ~keys[note].release;
  30.     })
  31. //.permanent_(true);
  32. ;
  33. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement