Sampler in ChucK
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.9KB

  1. // Effects chain
  2. Gain mixer => dac; // Main mixer
  3. adc => Gain adcThru => mixer; // Monitor the input
  4. adc => LiSa sample => mixer; // Sampler
  5. // TODO: turn off adcThru when recording
  6. //Times
  7. 10::second => sample.duration;
  8. 0::second => sample.recPos;
  9. 1::second => sample.playPos => sample.loopEnd => sample.loopEndRec;
  10. // Start recording and playing in a loop
  11. 1 => sample.loop => sample.record => sample.play;
  12. // Levels
  13. //0 => adc.gain;
  14. 1 => sample.feedback;
  15. .5 => sample.gain;
  16. .5 => adcThru.gain;
  17. // OSC listener class
  18. class OSCListener {
  19. fun void run(int port, string address) {
  20. OscRecv recv; port => recv.port; recv.listen();
  21. recv.event(address) @=> OscEvent oe;
  22. while (true) { oe => now; while (oe.nextMsg() != 0) { this.handle(oe); } }
  23. me.yield();
  24. }
  25. fun void handle(OscEvent oe){};
  26. }
  27. // define child class Y
  28. class InputListener extends OSCListener {
  29. fun void handle(OscEvent oe){
  30. oe.getFloat() => adc.gain;
  31. oe.getFloat() => adcThru.gain;
  32. <<< "Edit input" >>>;
  33. }
  34. }
  35. // define child class Y
  36. class DelayListener extends OSCListener
  37. {
  38. fun void handle(OscEvent oe){
  39. //TODO: this doesn't work
  40. // oe.getFloat()::second => sample.recPos => sample.loopEnd => sample.loopEndRec;
  41. //oe.getFloat()::second => sample.playPos => sample.loopEnd => sample.loopEndRec;
  42. oe.getFloat();
  43. oe.getFloat() => sample.feedback;
  44. <<< "Edit delay" >>>;
  45. }
  46. }
  47. // define child class Y
  48. class ChannelListener extends OSCListener
  49. {
  50. fun void handle(OscEvent oe){
  51. oe.getInt() => int channel;
  52. oe.getFloat();
  53. oe.getFloat();
  54. <<< "Edit channel" >>>;
  55. }
  56. }
  57. InputListener il;
  58. DelayListener dl;
  59. ChannelListener cl;
  60. spork ~ il.run(9000, "/input, f, f");
  61. spork ~ dl.run(9000, "/delay, f, f");
  62. spork ~ cl.run(9000, "/channel, i, f, f");
  63. // Loop forever
  64. while(true) { 1::second => now; }