Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (
- //Make SynthDef
- SynthDef(\sineNote, {|out = 0, gate=1, freq = 262, amp = 0.2|
- var sig, env;
- //Use sustaining envelope
- env = EnvGen.kr(Env.asr(0.1,1,0.1), gate, doneAction: 2);
- sig = SinOsc.ar(freq);
- Out.ar(out, sig * env * amp);
- }).add;
- )
- (
- //Initialize MIDIClient
- MIDIClient.init
- //Connect Instrument(s)
- MIDIIn.connectAll
- // create array which will hold the individual synths for each key
- ~keys = nil!128;
- MIDIdef.noteOn(\noteOn, {|vel, note|
- ~keys[note] = Synth(\sineNote, [\freq, note.midicps, \amp, vel.linexp(0,127,0.01,1)]);
- note.postln;
- vel.postln;
- })
- //If you want them to last after CmdPeriod
- // .permanent_(true)
- ;
- MIDIdef.noteOff(\noteOff, {|vel, note|
- ~keys[note].release;
- })
- //.permanent_(true);
- ;
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement