Pārlūkot izejas kodu

SC part (almost) fully implemented

Thomas GUFFROY 6 mēneši atpakaļ
vecāks
revīzija
3c91ac38ab
4 mainītis faili ar 89 papildinājumiem un 45 dzēšanām
  1. 17 5
      SC/2_synthdefs.scd
  2. 15 2
      SC/3_effects_integration.scd
  3. 57 38
      SC/4_osc_communication.scd
  4. 0 0
      SC/5_midi_controller.scd

+ 17 - 5
SC/2b_rgb_synthdefs.scd → SC/2_synthdefs.scd

@@ -2,6 +2,7 @@
 
 // Define the bus to send the audio to the filter
 ~bus = Bus.audio(s, 2);
+~fxBus = Bus.audio(s, 2);
 ~synthGroup = Group.head(s);             // synths go here
 ~filterGroup = Group.after(~synthGroup); // filter comes after
 
@@ -32,8 +33,8 @@ SynthDef(\lfo, { |out=0, freq=2, min=(-0.5), max=0.5, waveform=0|
 
 // RGB-controlled synthesizer with amplitude envelope
 SynthDef(\rgbSynth, { |out=0, freq=440, amp=1, ampAttack=0.01, ampRelease=1,
-	pitchAttack=0, pitchRelease=0, pitchRatio=2,
-	redAmt=0.5, greenAmt=0.5, blueAmt=0.5,
+	pitchAttack=0, pitchDecay=0, pitchRatio=1,
+	redAmt=1, greenAmt=1, blueAmt=1,
 	lfoBus=(-1), lfoDepth=0|
 
     var env, gate, pitchEnv, red, green, blue, sig, modFreq, lfo;
@@ -44,7 +45,7 @@ SynthDef(\rgbSynth, { |out=0, freq=440, amp=1, ampAttack=0.01, ampRelease=1,
     env = EnvGen.kr(Env.adsr(ampAttack, 0, 1, ampRelease), gate);
 
     // Pitch envelope
-    pitchEnv = EnvGen.kr(Env.adsr(pitchAttack, 0, 1, pitchRelease), gate);
+    pitchEnv = EnvGen.kr(Env.adsr(pitchAttack, pitchDecay, 0, pitchDecay), gate);
 
 	 // If lfoBus < 0, read from bus 0 (assumed silent)
 	lfo = In.kr(lfoBus.max(0));
@@ -68,9 +69,9 @@ SynthDef(\rgbSynth, { |out=0, freq=440, amp=1, ampAttack=0.01, ampRelease=1,
 
 
 SynthDef(\filterEnv, {
-    |out=0, gate=1, attack=0.01, decay=0, sustain=1, release=0.5|
+    |out=0, gate=1, attack=0.001, decay=0|
 
-    var env = EnvGen.kr(Env.adsr(attack, decay, sustain, release), gate);
+    var env = EnvGen.kr(Env.adsr(attack, decay, 0, decay), gate);
     Out.kr(out, env);
 }).add;
 
@@ -97,6 +98,17 @@ SynthDef(\lpf, { |in=0, out=0, cutoff=18000, resonance=1,
 }).add;
 
 
+
+// Create a SynthDef with the VSTPlugin UGen
+SynthDef(\juceVST, { |in, out|
+
+	var sound = In.ar(in, 2);
+	ReplaceOut.ar(out, VSTPlugin.ar(sound, 2))
+
+}).add;
+
+
+
 "RGB-controlled synthesizer loaded".postln;
 )
 

+ 15 - 2
SC/2c_voice_allocation_setup.scd → SC/3_effects_integration.scd

@@ -2,6 +2,9 @@
 //PUT HERE THE NUMBER OF POLYPHONY VOICES
 var nbVoices = 16;
 
+//PUT HERE THE PATH TO THE JUCE VST3 PLUGIN
+var vst3Path = "Users/thomas/Desktop/MOscilloscope.vst3";
+
 
 // LFO Synth
 ~lfo = Synth(\lfo, [\out, ~lfoBus.index]);
@@ -31,17 +34,27 @@ var nbVoices = 16;
 
 ~filter = Synth(\lpf, [
 	\in, ~bus,
-	\out, 0,
+	\out, ~fxBus,
 	\lfoBus, ~lfoBus.index,
 	\envBus, ~filterEnvBus.index
 ], target: ~filterGroup, addAction: \addToTail);
 
 
+~vst = Synth(\juceVST, [\in, ~fxBus, \out, 0], addAction: \addToTail);
+
+
+~ctl = VSTPluginController(~vst);
+
+// Open the JUCE plugin as a VST3
+~ctl.open(vst3Path, info: true, verbose: true, editor: true);
+//~ctl.editor;
+
+
 "Voice allocation arrays loaded".postln
 )
 
 
-//~setSynthsParam.(\lfoDepth, 0.01);
+//~setSynthsParam.(\lfoDepth, 0.05);
 
 //~filter.set(\cutoff, 10000, \resonance, 0, \lfoDepth, 2, \envDepth, 0);
 

+ 57 - 38
SC/5_osc_communication.scd → SC/4_osc_communication.scd

@@ -6,9 +6,9 @@
 OSCdef.freeAll;
 
 // Variables to track current pen type and color
-~currentPenType = \pen;
+~currentPenType = "\pen";
 ~currentColor = (r: 0.0, g: 0.0, b: 1.0); // Default blue
-~currentPadValues = (x: 0.0, y: 0.0, pressure: 1.0); //Default pad values
+~currentPadValues = (x: 0.0, y: 0.0, pressure: 1.0, a: 1); //Default pad values
 
 
 // Define OSC responder for iDraw touch data
@@ -16,9 +16,10 @@ OSCdef.freeAll;
     var x = ~currentPadValues.x;
     var y = ~currentPadValues.y;
     var pressure = ~currentPadValues.pressure;
+	var a = ~currentPadValues.a;
 
     // Log the received data
-    ["Touch data:", x, y, pressure, ~currentPenType, ~currentColor].postln;
+    //["Touch data:", x, y, pressure, ~currentPenType, ~currentColor].postln;
 
     // Handle touch based on current pen type
     switch(~currentPenType,
@@ -30,38 +31,43 @@ OSCdef.freeAll;
 			~setSynthsParam.(\ampAttack, ampAttack);
 			~setSynthsParam.(\ampRelease, ampRelease);
 
-            ["Amplitude envelope:", ampAttack, ampRelease].postln;
+            //["Amplitude envelope:", ampAttack, ampRelease].postln;
         },
 
         // Monoline - Controls filter envelope
 		"/monoline", {
             var filterAttack = y.linexp(-0.5, 0.5, 0.001, 5);
-            var filterRelease = x.linexp(-0.5, 0.5, 0.001, 10);
+            var filterDecay = x.linexp(-0.5, 0.5, 0.001, 10);
+			var envDepth = a.linlin(0, 1, 50, 0.001);
 
-			~setSynthsParam.(\filterAttack, filterAttack);
-			~setSynthsParam.(\filterRelease, filterRelease);
+			~filterEnv.set(\attack, filterAttack);
+			~filterEnv.set(\decay, filterDecay);
+			~filter.set(\envDepth, envDepth);
 
-            ["Filter envelope:", filterAttack, filterRelease].postln;
+
+            //["Filter envelope:", filterAttack, filterDecay, envDepth].postln;
         },
 
         // Marker - Controls pitch envelope
 		"/marker", {
             var pitchAttack = y.linexp(-0.5, 0.5, 0.001, 5);
-            var pitchRelease = x.linexp(-0.5, 0.5, 0.001, 10);
+            var pitchDecay = x.linexp(-0.5, 0.5, 0.001, 10);
+			var pitchRatio = a.linexp(0, 1, 10, 1);
 
 			~setSynthsParam.(\pitchAttack, pitchAttack);
-			~setSynthsParam.(\pitchRelease, pitchRelease);
+			~setSynthsParam.(\pitchDecay, pitchDecay);
+			~setSynthsParam.(\pitchRatio, pitchRatio);
 
-            ["Pitch envelope:", pitchAttack, pitchRelease].postln;
+            //["Pitch envelope:", pitchAttack, pitchDecay, pitchRatio].postln;
         },
 
         // Pencil - Effect preset 1
 		"/pencil", {
             // Apply Preset 1 effects
             ~filter.set(
-                \cutoff, x.linexp(-0.5, 0.5, 20, 18000),
+                \cutoff, x.linexp(-0.5, 0.5, 100, 18000),
                 \resonance, y.linlin(-0.5, 0.5, 0, 1),
-				\lfoDepth, pressure.linlin(1, 8, 0, 3)
+				\lfoDepth, pressure.linlin(1, 8, 0, 4)
             );
 
             ~lfo.set(
@@ -69,44 +75,50 @@ OSCdef.freeAll;
 				\waveform, 2
             );
 
+			~ctl.set(9, y.linlin(-0.5, 0.5, 0, 1));
 
-			/*
-            ~reverbSynth.set(
-                \roomsize, y.linlin(-0.5, 0.5, 0.1, 0.9)
-            );
-			*/
-
-            ["Pencil preset:", "Cutoff", x.linexp(-0.5, 0.5, 20, 18000), "LFO", x.linlin(-0.5, 0.5, 0, 15)].postln;
+            //["Pencil preset:", "Cutoff", x.linexp(-0.5, 0.5, 20, 18000), "LFO", x.linlin(-0.5, 0.5, 0, 15)].postln;
         },
 
         // Crayon - Effect preset 2
 		"/crayon", {
             // Apply Preset 2 effects
-            ~lfoSynth.set(
+            ~lfo.set(
                 \freq, x.linlin(-0.5, 0.5, 15, 1),
-                \intensity, x.linlin(-0.5, 0.5, 0, 1)
-            );
-
-            ~delaySynth.set(
-                \delaytime, x.linlin(-0.5, 0.5, 0.01, 1.0)
+				\waveform, 3
             );
 
-            ~filterSynth.set(
+            ~filter.set(
                 \cutoff, y.linexp(-0.5, 0.5, 20, 18000),
-                \res, pressure.linlin(1, 5, 0, 1)
+                \resonance, pressure.linlin(1, 5, 0, 1),
+				\lfoDepth, x.linlin(-0.5, 0.5, 0, 3)
             );
 
-            ~reverbSynth.set(
-                \mix, y.linlin(-0.5, 0.5, 0, 1)
-            );
 
-            ["Crayon preset:", "LFO", x.linlin(-0.5, 0.5, 15, 1), "Filter", y.linexp(-0.5, 0.5, 20, 18000)].postln;
+			~ctl.set(10, y.linlin(-0.5, 0.5, 0, 1)); // Reverb dry/wet
+
+			~ctl.set(8, x.linlin(-0.5, 0.5, 0.001, 1.0)); // Delay amount
+
+
+            //["Crayon preset:", "LFO", x.linlin(-0.5, 0.5, 15, 1), "Filter", y.linexp(-0.5, 0.5, 20, 18000)].postln;
         },
 
         // Fountain pen - Effect preset 3 (placeholder)
 		"/fountainPen", {
-            // Apply Preset 3 effects (TBD in documentation)
-            ["Fountain pen preset (TBD)"].postln;
+            // Apply Preset 3 effects
+			~lfo.set(
+                \freq, x.linlin(-0.5, 0.5, 1, 15),
+				\waveform, 0
+            );
+
+			~filter.set(
+				\lfoDepth, 0
+            );
+
+			~setSynthsParam.(\lfoDepth, pressure.linlin(1, 5, 0, 0.5));
+
+			//["fountainPen preset:", "LFO Depth", pressure.linlin(1, 5, 0, 0.5), "LFO Freq", x.linlin(-0.5, 0.5, 1, 15)].postln;
+
         },
 
         // Water color - Effect preset 4 (placeholder)
@@ -237,6 +249,14 @@ OSCdef(\waterColorOSC, { |msg, time, addr, port|
 
 
 
+// ----- OSC Drawing Width -----
+OSCdef(\opacityOSC, { |msg, time, addr, port|
+    var a = msg[1].asFloat;
+	~currentPadValues.a = a;
+
+}, '/a');
+
+
 // ----- OSC RGB Colors -----
 // OSC responder for red changes
 OSCdef(\redOSC, { |msg, time, addr, port|
@@ -246,7 +266,7 @@ OSCdef(\redOSC, { |msg, time, addr, port|
     ~currentColor.r = component;
 	~setSynthsParam.(\redAmt, component);
 
-    ["Color changed:", ~currentColor].postln;
+    //["Color changed:", ~currentColor].postln;
 }, '/r');
 
 // OSC responder for green changes
@@ -257,7 +277,7 @@ OSCdef(\greenOSC, { |msg, time, addr, port|
     ~currentColor.g = component;
 	~setSynthsParam.(\greenAmt, component);
 
-    ["Color changed:", ~currentColor].postln;
+    //["Color changed:", ~currentColor].postln;
 }, '/g');
 
 // OSC responder for blue changes
@@ -268,7 +288,7 @@ OSCdef(\blueOSC, { |msg, time, addr, port|
     ~currentColor.b = component;
 	~setSynthsParam.(\blueAmt, component);
 
-    ["Color changed:", ~currentColor].postln;
+    //["Color changed:", ~currentColor].postln;
 }, '/b');
 
 
@@ -278,6 +298,5 @@ OSCdef(\blueOSC, { |msg, time, addr, port|
 // Start the OSC server on port 57120 (default SuperCollider port)
 thisProcess.openUDPPort(57120);
 "OSC server ready on port 57120".postln;
-"Registered OSC commands: /touch, /pen, /color".postln;
 "Ready to receive data from iDraw OSC app".postln;
 )

+ 0 - 0
SC/9_midi_controller.scd → SC/5_midi_controller.scd