6_test_functions.scd 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. };
  35. // Test function for parameter changes
  36. ~testParameters = {
  37. // Start effects chain if not already running
  38. if(~effectsChain.isNil, { ~startEffectsChain.value; });
  39. // Test different oscillator types with varying parameters
  40. [
  41. [\sineTone, 440, 0.3, -0.5, 0.05, 0.5],
  42. [\squareTone, 330, 0.2, 0, 0.01, 0.8],
  43. [\sawTone, 220, 0.15, 0.5, 0.1, 1.2],
  44. [\triTone, 550, 0.25, -0.2, 0.02, 0.7],
  45. [\fmTone, 660, 0.2, 0.3, 0.05, 1.0]
  46. ].do { |params, i|
  47. var synthType, freq, amp, pan, attack, release;
  48. #synthType, freq, amp, pan, attack, release = params;
  49. // Create the synth with the specified parameters
  50. Synth(synthType, [
  51. \out, ~sourceBus,
  52. \freq, freq,
  53. \amp, amp,
  54. \pan, pan,
  55. \attack, attack,
  56. \release, release
  57. ]);
  58. // Change effect parameters for demonstration
  59. ~filterSynth.set(\cutoff, 500 + (i * 1000));
  60. ~delaySynth.set(\mix, 0.2 + (i * 0.1));
  61. ~reverbSynth.set(\room, 0.3 + (i * 0.1));
  62. // Log the current sound
  63. ["Testing synth:", synthType, freq, amp].postln;
  64. // Wait between notes
  65. 0.8.wait;
  66. };
  67. // Clean up
  68. "Parameter test complete".postln;
  69. };
  70. // Function to simulate Arduino touch input
  71. ~simulateTouch = { |numTouches=10, duration=5|
  72. var endTime = SystemClock.seconds + duration;
  73. "Starting touch simulation for % seconds".format(duration).postln;
  74. // Start the effects chain
  75. ~startEffectsChain.value;
  76. // Generate random touches until the duration expires
  77. while { SystemClock.seconds < endTime } {
  78. var x = 1.0.rand;
  79. var y = 1.0.rand;
  80. var pressure = 0.3 + 0.7.rand;
  81. var color = 5.rand; // 0-4 for different synth types
  82. // Send the simulated touch data through our OSC handler
  83. OSCdef(\touchOSC).value(['/touch', x, y, pressure, color], nil, nil, nil);
  84. // Random wait time between touches
  85. (0.1 + 0.3.rand).wait;
  86. };
  87. "Touch simulation complete".postln;
  88. };
  89. // Run parameter test in a Routine
  90. ~runParameterTest = {
  91. Routine(~testParameters).play;
  92. };
  93. // Run touch simulation in a Routine
  94. ~runTouchSimulation = { |duration=5|
  95. Routine({ ~simulateTouch.value(10, duration) }).play;
  96. };
  97. "Test functions loaded".postln;
  98. )