Advertisement
Sebi

Arduino + SuperCollider

Jul 3rd, 2015
3,524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Author: Sebastian Grygiel (Sebi)
  2. // Date: Spring 2015
  3.  
  4. // Demo video: https://www.youtube.com/watch?v=MJAmfSJmgrA
  5. // See the Arduino script for more info: https://pastebin.com/yTEnXhfb
  6. // Ask in youtube comments, although I haven't done much with Supercollider specifically
  7. // Edit the COM port at the bottom of this file before use
  8.  
  9. ( // For restarting
  10.  SerialPort.closeAll;
  11.  s.reboot;
  12. )
  13.  
  14. ( // Synth definition
  15. SynthDef(\sinewave,{
  16.     // key -> 49 == middle c
  17.     // volume and mix take values of 0 to 1
  18.     |key = 50, volume = 0, mix = 0.3|
  19.     var freq = 440*pow(2,(key-49)/12);
  20.     // Mix Sine and Saw using mix variable for ratios
  21.     var output = Mix([SinOsc.ar(freq,0,volume*(1-mix)),Saw.ar(freq,volume*mix*0.8)]);
  22.     Out.ar(0, [output, output]);
  23. }).send(s);
  24. )
  25.  
  26. // Create the synth
  27. a = Synth(\sinewave);
  28.  
  29. (
  30. // Open arduino link -- EDIT IN YOUR COM PORT PATH
  31. p = ArduinoSMS("/dev/ttyUSB0", 115200);
  32. p.action = {
  33.     | ... msg |
  34.     msg.postln;
  35.     a.set(\volume, pow(min(1, msg[1]/200),2)/5);
  36.     a.set(\mix,    pow(min(1,(msg[1] - 400)/600),2)/1.5);
  37.     a.set(\key, msg[0]);
  38. }
  39. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement