Always-on computer music
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.

63 lines
2.0KB

  1. s = Server.local;
  2. s.waitForBoot {
  3. var module, msg, modules;
  4. // Connect to OSC
  5. thisProcess.openUDPPort(5005);
  6. n = NetAddr.new("0.0.0.0", 5005);
  7. o = OSCFunc({ arg msg, time, addr, recvPort; [msg, time, addr, recvPort].postln; }, '/radio', n);
  8. // Create the synth definition and load it
  9. module = SynthDef.new(\module, {
  10. arg hue, saturation, value, pan, gain;
  11. var oscillator, noise, filter, panner, mixer, frequency, qfactor, noise_level, osc_level;
  12. // Calculate some parameters
  13. frequency = 800 + 500*hue;
  14. qfactor = (1 - saturation)**4;
  15. osc_level = saturation;
  16. noise_level = 1 - osc_level;
  17. // Generate some sounds
  18. // noise = WhiteNoise.ar(1);
  19. noise = Crackle.ar(1.9, 1.0);
  20. filter = BPF.ar(noise, frequency, qfactor) * noise_level;
  21. oscillator = SinOsc.ar(frequency) * osc_level;
  22. mixer = Mix.ar([filter, oscillator]);
  23. panner = LinPan2.ar(mixer, 2*pan - 1, value * 0.2);
  24. Out.ar(0, panner);
  25. });
  26. module.load(s);
  27. s.sync;
  28. // Create multiple sound generators
  29. modules = Array.fill(12,
  30. {
  31. arg index;
  32. var pan;
  33. pan = ((index % 4) - 1.5)/1.5;
  34. Synth.new(\module,
  35. [\hue, 0.5, \saturation, 0.1, \value, 0.5, pan, 0.5, \gain, 0.9]
  36. )
  37. }
  38. );
  39. "%\n".postf(modules[0]);
  40. "%\n".postf(modules[1]);
  41. // Hook up OSC
  42. f = { |msg, time, addr|
  43. if(msg[0] == '/radio') {
  44. "Got data: index: % hue: % sat: % value: % pan: %\n".postf(msg[1], msg[2], msg[3], msg[4], msg[5]);
  45. if(msg[1]<modules.size){
  46. "Applying to module %\n\n".postf(msg[1]);
  47. modules[msg[1]].set(\hue, msg[2]);
  48. modules[msg[1]].set(\saturation, msg[3]);
  49. modules[msg[1]].set(\value, msg[4]);
  50. modules[msg[1]].set(\pan, msg[5]);
  51. }
  52. }
  53. };
  54. thisProcess.addOSCRecvFunc(f);
  55. };