6_test_functions.scd 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. (
  2. // Function to start effects chain
  3. ~startEffectsChain = {
  4. // Create audio buses for effects chain
  5. ~sourceBus = Bus.audio(s, 2);
  6. ~reverbBus = Bus.audio(s, 2);
  7. ~delayBus = Bus.audio(s, 2);
  8. // Create effects synths in chain
  9. ~filterSynth = Synth(\lpf, [\in, ~sourceBus, \out, ~delayBus, \cutoff, 1000, \res, 0.5]);
  10. ~delaySynth = Synth(\delay, [\in, ~delayBus, \out, ~reverbBus, \delaytime, 0.4, \feedback, 0.3, \mix, 0.3], ~filterSynth, \addAfter);
  11. ~reverbSynth = Synth(\reverb, [\in, ~reverbBus, \out, 0, \mix, 0.2, \room, 0.5, \damp, 0.5], ~delaySynth, \addAfter);
  12. // Store the effects chain nodes in an array for easy access
  13. ~effectsChain = [~filterSynth, ~delaySynth, ~reverbSynth];
  14. "Effects chain started".postln;
  15. };
  16. // Function to stop effects chain
  17. ~stopEffectsChain = {
  18. if(~effectsChain.notNil, {
  19. ~effectsChain.do(_.free);
  20. ~effectsChain = nil;
  21. });
  22. if(~sourceBus.notNil, { ~sourceBus.free; ~sourceBus = nil; });
  23. if(~reverbBus.notNil, { ~reverbBus.free; ~reverbBus = nil; });
  24. if(~delayBus.notNil, { ~delayBus.free; ~delayBus = nil; });
  25. "Effects chain stopped".postln;
  26. };
  27. // Function to reset the entire system
  28. ~resetSystem = {
  29. ~stopEffectsChain.value;
  30. OSCdef.freeAll;
  31. // Reload OSC definitions
  32. thisProcess.interpreter.executeFile("5_osc_communication.scd");
  33. "System reset complete".postln;
  34. ~touchSynths = (); // Clear any active touch synths
  35. };
  36. // Test function for parameter changes
  37. ~testParameters = {
  38. // Start effects chain if not already running
  39. if(~effectsChain.isNil, { ~startEffectsChain.value; });
  40. // Test different oscillator types with varying parameters
  41. [
  42. [\sineTone, 440, 0.3, -0.5, 0.05, 0.5],
  43. [\squareTone, 330, 0.2, 0, 0.01, 0.8],
  44. [\sawTone, 220, 0.15, 0.5, 0.1, 1.2],
  45. [\triTone, 550, 0.25, -0.2, 0.02, 0.7],
  46. [\fmTone, 660, 0.2, 0.3, 0.05, 1.0]
  47. ].do { |params, i|
  48. var synthType, freq, amp, pan, attack, release;
  49. #synthType, freq, amp, pan, attack, release = params;
  50. // Create the synth with the specified parameters
  51. Synth(synthType, [
  52. \out, ~sourceBus,
  53. \freq, freq,
  54. \amp, amp,
  55. \pan, pan,
  56. \attack, attack,
  57. \release, release
  58. ]);
  59. // Change effect parameters for demonstration
  60. ~filterSynth.set(\cutoff, 500 + (i * 1000));
  61. ~delaySynth.set(\mix, 0.2 + (i * 0.1));
  62. ~reverbSynth.set(\room, 0.3 + (i * 0.1));
  63. // Log the current sound
  64. ["Testing synth:", synthType, freq, amp].postln;
  65. // Wait between notes
  66. 0.8.wait;
  67. };
  68. // Clean up
  69. "Parameter test complete".postln;
  70. };
  71. // Function to simulate Arduino touch input
  72. ~simulateTouch = { |numTouches=10, duration=5|
  73. var endTime = SystemClock.seconds + duration;
  74. "Starting touch simulation for % seconds".format(duration).postln;
  75. // Start the effects chain
  76. ~startEffectsChain.value;
  77. // Generate random touches until the duration expires
  78. while { SystemClock.seconds < endTime } {
  79. var x = 1.0.rand;
  80. var y = 1.0.rand;
  81. var pressure = 0.3 + 0.7.rand;
  82. var color = 5.rand; // 0-4 for different synth types
  83. // Send the simulated touch data through our OSC handler
  84. OSCdef(\touchOSC).value(['/touch', x, y, pressure, color], nil, nil, nil);
  85. // Random wait time between touches
  86. (0.1 + 0.3.rand).wait;
  87. };
  88. "Touch simulation complete".postln;
  89. };
  90. // Run parameter test in a Routine
  91. ~runParameterTest = {
  92. Routine(~testParameters).play;
  93. };
  94. // Run touch simulation in a Routine
  95. ~runTouchSimulation = { |duration=5|
  96. Routine({ ~simulateTouch.value(10, duration) }).play;
  97. };
  98. "Test functions loaded".postln;
  99. )