Просмотр исходного кода

updated supercolider based on the new req

Farnoosh Rad 6 месяцев назад
Родитель
Сommit
f46c8d490d

+ 0 - 15
1_environment_setup.scd

@@ -1,15 +0,0 @@
-// Basic environment setup
-s = Server.local;
-s.boot;
-
-// Test server connection
-s.doWhenBooted({
-    "SuperCollider server ready!".postln;
-
-    // Test simple sine wave
-    {
-        var sig = SinOsc.ar(440, 0, 0.5);
-        sig = sig * EnvGen.kr(Env.perc(0.01, 1), doneAction: 2);
-        sig!2
-    }.play;
-});

+ 0 - 106
5_osc_communication.scd

@@ -1,106 +0,0 @@
-(
-// Clear any existing OSC definitions
-OSCdef.freeAll;
-
-// Define OSC responder for mobile touch events
-// Mobile touch data format will likely be different from Arduino
-OSCdef(\touchOSC, { |msg, time, addr, port|
-    // Typical mobile touch data might include:
-    // - touch ID (for multi-touch)
-    // - x position (normalized 0-1)
-    // - y position (normalized 0-1)
-    // - touch state (began, moved, ended)
-    // - pressure/force (if supported)
-
-    var touchId = msg[1];
-    var x = msg[2];
-    var y = msg[3];
-    var state = msg[4];
-    var pressure = if(msg[5].notNil, { msg[5] }, { 0.7 }); // Default if not provided
-
-    // Convert mobile screen coordinates to parameters
-    var freq = x.linexp(0, 1, 100, 2000);
-    var amp = pressure.linlin(0, 1, 0.1, 0.8);
-    var pan = y.linlin(0, 1, -0.8, 0.8);
-
-    // Log the received data
-    ["Mobile touch:", touchId, x, y, state, pressure].postln;
-
-    // Handle touch based on state
-    switch(state,
-        // Touch began - start a new synth
-        \began, {
-            var synthType = (touchId % 5).switch(
-                0, { \sineTone },
-                1, { \squareTone },
-                2, { \sawTone },
-                3, { \triTone },
-                4, { \fmTone }
-            );
-
-            // Create a new synth and store it by ID
-            ~touchSynths = ~touchSynths ? ();
-            ~touchSynths[touchId] = Synth(synthType, [
-                \out, ~sourceBus ? 0,
-                \freq, freq,
-                \amp, amp,
-                \pan, pan,
-                \attack, 0.05,
-                \release, 1.0
-            ]);
-
-            ["Touch began:", touchId, synthType, freq, amp].postln;
-        },
-
-        // Touch moved - update existing synth
-        \moved, {
-            if(~touchSynths[touchId].notNil, {
-                ~touchSynths[touchId].set(\freq, freq, \amp, amp, \pan, pan);
-            });
-        },
-
-        // Touch ended - release synth
-        \ended, {
-            if(~touchSynths[touchId].notNil, {
-                ~touchSynths[touchId].release;
-                ~touchSynths[touchId] = nil;
-            });
-        }
-    );
-}, '/touch');
-
-// OSC responder for mobile control messages (e.g., UI controls)
-OSCdef(\controlOSC, { |msg, time, addr, port|
-    var control = msg[1].asSymbol;
-    var value = msg[2];
-
-    ["Mobile control:", control, value].postln;
-
-    // Handle different control parameters
-    switch(control,
-        \reverb_mix, { ~reverbSynth.set(\mix, value); },
-        \reverb_room, { ~reverbSynth.set(\room, value); },
-        \delay_time, { ~delaySynth.set(\delaytime, value); },
-        \delay_feedback, { ~delaySynth.set(\feedback, value); },
-        \filter_cutoff, { ~filterSynth.set(\cutoff, value.linexp(0, 1, 200, 10000)); }
-    );
-}, '/control');
-
-// Add a separate responder for color changes from mobile UI
-OSCdef(\colorOSC, { |msg, time, addr, port|
-    var colorIndex = msg[1].asInteger;
-
-    // Store the current color for new touches
-    ~currentColor = colorIndex;
-
-    ["Color changed:", colorIndex].postln;
-}, '/color');
-
-// Start the OSC server on port 57120 (default SuperCollider port)
-thisProcess.openUDPPort(57120);
-"OSC server ready on port 57120".postln;
-"Registered OSC commands: /touch, /control, /color".postln;
-
-// Print the local IP address for connecting the mobile device
-"Connect mobile device to: %:%".format(Platform.myHostName, 57120).postln;
-)

+ 21 - 0
SC/1_environment_setup.scd

@@ -0,0 +1,21 @@
+// Server configuration
+s = Server.local;
+ServerOptions.devices;  // List available audio devices if needed
+
+// Server boot with status reporting
+(
+s.waitForBoot({
+    "SuperCollider server ready!".postln;
+    "Available audio inputs: %".format(ServerOptions.inDevices).postln;
+    "Available audio outputs: %".format(ServerOptions.outDevices).postln;
+    "Sample rate: % Hz".format(s.sampleRate).postln;
+    "Audio latency: % ms".format(s.options.blockSize / s.sampleRate * 1000).postln;
+
+    // Run a quick audio test
+    {
+        var sig = SinOsc.ar(440, 0, 0.2);
+        sig = sig * EnvGen.kr(Env.perc(0.01, 1), doneAction: 2);
+        sig!2  // Stereo output
+    }.play;
+});
+)

+ 0 - 0
2_oscillator_synthdefs.scd → SC/2_oscillator_synthdefs.scd


+ 0 - 0
SC/2b_rgb_synthdefs.scd


+ 0 - 0
3_effects_synthdefs.scd → SC/3_effects_synthdefs.scd


+ 0 - 0
4_modulation_synthdefs.scd → SC/4_modulation_synthdefs.scd


+ 0 - 0
SC/4b_lfo_effects.scd


+ 183 - 0
SC/5_osc_communication.scd

@@ -0,0 +1,183 @@
+// Module 5: OSC Communication Setup - MODIFIED FOR IDRAW OSC
+// Save as "5_osc_communication.scd"
+
+(
+// Clear any existing OSC definitions
+OSCdef.freeAll;
+
+// Variables to track current pen type and color
+~currentPenType = \pen;
+~currentColor = (r: 0, g: 0, b: 1); // Default blue
+
+// Define OSC responder for iDraw touch data
+OSCdef(\touchOSC, { |msg, time, addr, port|
+    var x = msg[1].asFloat;
+    var y = msg[2].asFloat;
+    var pressure = msg[3].asFloat;
+
+    // Log the received data
+    ["Touch data:", x, y, pressure, ~currentPenType, ~currentColor].postln;
+
+    // Handle touch based on current pen type
+    switch(~currentPenType,
+        // Pen - Controls amplitude envelope
+        \pen, {
+            var attack = x.linlin(-0.5, 0.5, 0, 5);
+            var release = y.linlin(-0.5, 0.5, 0, 10);
+            var freq = x.linexp(-0.5, 0.5, 100, 2000);
+
+            // Generate sound with RGB-controlled waveform mix
+            var synth = Synth(\rgbSynth, [
+                \out, ~sourceBus ? 0,
+                \freq, freq,
+                \amp, pressure.linlin(1, 8, 0.1, 0.8),
+                \attack, attack,
+                \release, release,
+                \redAmt, ~currentColor.r,
+                \greenAmt, ~currentColor.g,
+                \blueAmt, ~currentColor.b
+            ]);
+
+            ["Amplitude envelope:", attack, release].postln;
+        },
+
+        // Monoline - Controls filter envelope
+        \monoline, {
+            var attack = x.linlin(-0.5, 0.5, 0, 5);
+            var release = y.linlin(-0.5, 0.5, 0, 10);
+            var freq = x.linexp(-0.5, 0.5, 100, 2000);
+
+            // Generate sound with filter envelope
+            var synth = Synth(\rgbFilterSynth, [
+                \out, ~sourceBus ? 0,
+                \freq, freq,
+                \amp, pressure.linlin(1, 8, 0.1, 0.8),
+                \attack, attack,
+                \release, release,
+                \filterAttack, attack,
+                \filterRelease, release,
+                \redAmt, ~currentColor.r,
+                \greenAmt, ~currentColor.g,
+                \blueAmt, ~currentColor.b
+            ]);
+
+            ["Filter envelope:", attack, release].postln;
+        },
+
+        // Marker - Controls pitch envelope
+        \marker, {
+            var attack = x.linlin(-0.5, 0.5, 0, 5);
+            var release = y.linlin(-0.5, 0.5, 0, 10);
+            var freq = x.linexp(-0.5, 0.5, 100, 2000);
+
+            // Generate sound with pitch envelope
+            var synth = Synth(\rgbPitchSynth, [
+                \out, ~sourceBus ? 0,
+                \freq, freq,
+                \amp, pressure.linlin(1, 8, 0.1, 0.8),
+                \attack, attack,
+                \release, release,
+                \pitchAttack, attack,
+                \pitchRelease, release,
+                \redAmt, ~currentColor.r,
+                \greenAmt, ~currentColor.g,
+                \blueAmt, ~currentColor.b
+            ]);
+
+            ["Pitch envelope:", attack, release].postln;
+        },
+
+        // Pencil - Effect preset 1
+        \pencil, {
+            // Apply Preset 1 effects
+            ~filterSynth.set(
+                \cutoff, x.linexp(-0.5, 0.5, 20, 18000),
+                \res, y.linlin(-0.5, 0.5, 0, 1)
+            );
+
+            ~lfoSynth.set(
+                \freq, x.linlin(-0.5, 0.5, 0, 15),
+                \intensity, pressure.linlin(1, 8, 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;
+        },
+
+        // Crayon - Effect preset 2
+        \crayon, {
+            // Apply Preset 2 effects
+            ~lfoSynth.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)
+            );
+
+            ~filterSynth.set(
+                \cutoff, y.linexp(-0.5, 0.5, 20, 18000),
+                \res, pressure.linlin(1, 5, 0, 1)
+            );
+
+            ~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;
+        },
+
+        // Fountain pen - Effect preset 3 (placeholder)
+        \fountainPen, {
+            // Apply Preset 3 effects (TBD in documentation)
+            ["Fountain pen preset (TBD)"].postln;
+        },
+
+        // Water color - Effect preset 4 (placeholder)
+        \waterColor, {
+            // Apply Preset 4 effects (TBD in documentation)
+            ["Water color preset (TBD)"].postln;
+        }
+    );
+}, '/touch');
+
+// OSC responder for pen type selection
+OSCdef(\penTypeOSC, { |msg, time, addr, port|
+    var penType = msg[1].asSymbol;
+
+    // Update current pen type
+    ~currentPenType = penType;
+
+    ["Pen type changed:", penType].postln;
+
+    // Initialize relevant effects based on pen type
+    switch(penType,
+        \pencil, { ~initializePreset1.value; },
+        \crayon, { ~initializePreset2.value; },
+        \fountainPen, { ~initializePreset3.value; },
+        \waterColor, { ~initializePreset4.value; }
+    );
+}, '/pen');
+
+// OSC responder for color changes
+OSCdef(\colorOSC, { |msg, time, addr, port|
+    var r = msg[1].asFloat;
+    var g = msg[2].asFloat;
+    var b = msg[3].asFloat;
+
+    // Update current color
+    ~currentColor = (r: r, g: g, b: b);
+
+    ["Color changed:", r, g, b].postln;
+}, '/color');
+
+// 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
6_test_functions.scd → SC/6_test_functions.scd


+ 0 - 0
SC/6b_effect_presets.scd


+ 0 - 0
SC/7_idraw_connection.scd


+ 0 - 0
7_mobile_connection.s → SC/7_mobile_connection.s


+ 0 - 0
main.scd → SC/main.scd