6_test_functions.scd 4.3 KB

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