Ver Fonte

upload new modules

Farnoosh Rad há 6 meses atrás
pai
commit
bd9156b3f0
7 ficheiros alterados com 303 adições e 7 exclusões
  1. BIN
      .DS_Store
  2. BIN
      SC/.DS_Store
  3. 81 0
      SC/2b_rgb_synthdefs.scd
  4. 22 0
      SC/4b_lfo_effects.scd
  5. 43 7
      SC/6_test_functions.scd
  6. 47 0
      SC/6b_effect_presets.scd
  7. 110 0
      SC/7_idraw_connection.scd

BIN
.DS_Store


BIN
SC/.DS_Store


+ 81 - 0
SC/2b_rgb_synthdefs.scd

@@ -0,0 +1,81 @@
+(
+// RGB-controlled synthesizer with amplitude envelope
+SynthDef(\rgbSynth, { |out=0, freq=440, amp=0.5, attack=0.01, release=1, redAmt=0.5, greenAmt=0.5, blueAmt=0.5|
+    var env, red, green, blue, sig;
+
+    // Amplitude envelope
+    env = EnvGen.kr(Env.perc(attack, release), doneAction: 2);
+
+    // Different waveforms for RGB components
+    red = SinOsc.ar(freq) * redAmt;
+    green = Saw.ar(freq) * greenAmt;
+    blue = Pulse.ar(freq, 0.5) * blueAmt;
+
+    // Mix the waveforms
+    sig = (red + green + blue) / 3;
+
+    // Apply envelope and output
+    sig = sig * env * amp;
+    Out.ar(out, sig!2);
+}).add;
+
+// RGB-controlled synthesizer with filter envelope
+SynthDef(\rgbFilterSynth, { |out=0, freq=440, amp=0.5, attack=0.01, release=1,
+    filterAttack=0.01, filterRelease=1, filterMin=200, filterMax=5000,
+    redAmt=0.5, greenAmt=0.5, blueAmt=0.5|
+
+    var ampEnv, filterEnv, red, green, blue, sig;
+
+    // Amplitude envelope
+    ampEnv = EnvGen.kr(Env.perc(attack, release), doneAction: 2);
+
+    // Filter envelope
+    filterEnv = EnvGen.kr(Env.perc(filterAttack, filterRelease));
+
+    // Different waveforms for RGB components
+    red = SinOsc.ar(freq) * redAmt;
+    green = Saw.ar(freq) * greenAmt;
+    blue = Pulse.ar(freq, 0.5) * blueAmt;
+
+    // Mix the waveforms
+    sig = (red + green + blue) / 3;
+
+    // Apply filter with envelope control
+    sig = RLPF.ar(sig, filterEnv.linexp(0, 1, filterMin, filterMax), 0.5);
+
+    // Apply amplitude envelope and output
+    sig = sig * ampEnv * amp;
+    Out.ar(out, sig!2);
+}).add;
+
+// RGB-controlled synthesizer with pitch envelope
+SynthDef(\rgbPitchSynth, { |out=0, freq=440, amp=0.5, attack=0.01, release=1,
+    pitchAttack=0.01, pitchRelease=1, pitchRatio=2,
+    redAmt=0.5, greenAmt=0.5, blueAmt=0.5|
+
+    var ampEnv, pitchEnv, red, green, blue, sig;
+
+    // Amplitude envelope
+    ampEnv = EnvGen.kr(Env.perc(attack, release), doneAction: 2);
+
+    // Pitch envelope
+    pitchEnv = EnvGen.kr(Env.perc(pitchAttack, pitchRelease));
+
+    // Calculate modulated frequency
+    freq = freq * (1 + (pitchEnv * (pitchRatio - 1)));
+
+    // Different waveforms for RGB components
+    red = SinOsc.ar(freq) * redAmt;
+    green = Saw.ar(freq) * greenAmt;
+    blue = Pulse.ar(freq, 0.5) * blueAmt;
+
+    // Mix the waveforms
+    sig = (red + green + blue) / 3;
+
+    // Apply amplitude envelope and output
+    sig = sig * ampEnv * amp;
+    Out.ar(out, sig!2);
+}).add;
+
+"RGB-controlled synthesizers loaded".postln;
+)

+ 22 - 0
SC/4b_lfo_effects.scd

@@ -0,0 +1,22 @@
+(
+// LFO SynthDef with multiple waveform options
+SynthDef(\lfoEffect, { |out=0, freq=1, min=0, max=1, waveform=0, target=0|
+    var lfo;
+
+    // Select waveform based on parameter
+    lfo = Select.kr(waveform, [
+        SinOsc.kr(freq),        // Sine wave (waveform=0)
+        LFTri.kr(freq),         // Triangle wave (waveform=1)
+        LFSaw.kr(freq, 0, -1),  // Decreasing sawtooth (waveform=2)
+        LFPulse.kr(freq, 0, 0.5) // Square wave (waveform=3)
+    ]);
+
+    // Scale to range
+    lfo = lfo.range(min, max);
+
+    // Output to control bus
+    Out.kr(out, lfo);
+}).add;
+
+"Enhanced LFO effects loaded".postln;
+)

+ 43 - 7
SC/6_test_functions.scd

@@ -3,20 +3,56 @@
 ~startEffectsChain = {
     // Create audio buses for effects chain
     ~sourceBus = Bus.audio(s, 2);
-    ~reverbBus = Bus.audio(s, 2);
+    ~filterBus = Bus.audio(s, 2);
     ~delayBus = Bus.audio(s, 2);
+    ~reverbBus = Bus.audio(s, 2);
+
+    // Create control buses for modulation
+    ~lfoControlBus = Bus.control(s, 1);
 
     // Create effects synths in chain
-    ~filterSynth = Synth(\lpf, [\in, ~sourceBus, \out, ~delayBus, \cutoff, 1000, \res, 0.5]);
-    ~delaySynth = Synth(\delay, [\in, ~delayBus, \out, ~reverbBus, \delaytime, 0.4, \feedback, 0.3, \mix, 0.3], ~filterSynth, \addAfter);
-    ~reverbSynth = Synth(\reverb, [\in, ~reverbBus, \out, 0, \mix, 0.2, \room, 0.5, \damp, 0.5], ~delaySynth, \addAfter);
+    ~lfoSynth = Synth(\lfoEffect, [
+        \out, ~lfoControlBus,
+        \freq, 1,
+        \min, 100,
+        \max, 5000,
+        \waveform, 0,
+        \target, 0
+    ]);
+
+    ~filterSynth = Synth(\lpf, [
+        \in, ~sourceBus,
+        \out, ~delayBus,
+        \cutoff, 1000,
+        \res, 0.5
+    ]);
+
+    ~delaySynth = Synth(\delay, [
+        \in, ~delayBus,
+        \out, ~reverbBus,
+        \delaytime, 0.4,
+        \feedback, 0.3,
+        \mix, 0.3
+    ], ~filterSynth, \addAfter);
+
+    ~reverbSynth = Synth(\reverb, [
+        \in, ~reverbBus,
+        \out, 0,
+        \mix, 0.2,
+        \room, 0.5,
+        \damp, 0.5
+    ], ~delaySynth, \addAfter);
+
+    // Create a mapping for the LFO to control the filter
+    s.sync;
+    ~lfoControlBus.asMap.postln;
+    ~filterSynth.map(\cutoff, ~lfoControlBus);
 
     // Store the effects chain nodes in an array for easy access
-    ~effectsChain = [~filterSynth, ~delaySynth, ~reverbSynth];
+    ~effectsChain = [~lfoSynth, ~filterSynth, ~delaySynth, ~reverbSynth];
 
-    "Effects chain started".postln;
+    "Effects chain started with LFO mapping".postln;
 };
-
 // Function to stop effects chain
 ~stopEffectsChain = {
     if(~effectsChain.notNil, {

+ 47 - 0
SC/6b_effect_presets.scd

@@ -0,0 +1,47 @@
+(
+// Initialize Effect Preset 1 (Pencil)
+~initializePreset1 = {
+    // Make sure effects chain exists
+    if(~effectsChain.isNil, { ~startEffectsChain.value; });
+
+    // Set LFO to specific settings for Preset 1
+    ~lfoSynth.set(
+        \waveform, 2,  // Decreasing sawtooth
+        \target, 0     // Target filter cutoff
+    );
+
+    "Initialized Preset 1 (Pencil) - LFO + Filter + Reverb".postln;
+};
+
+// Initialize Effect Preset 2 (Crayon)
+~initializePreset2 = {
+    // Make sure effects chain exists
+    if(~effectsChain.isNil, { ~startEffectsChain.value; });
+
+    // Set LFO to specific settings for Preset 2
+    ~lfoSynth.set(
+        \waveform, 3,  // Square wave
+        \target, 0     // Target filter cutoff
+    );
+
+    "Initialized Preset 2 (Crayon) - LFO + Filter + Reverb + Delay".postln;
+};
+
+// Initialize Effect Preset 3 (Fountain Pen)
+~initializePreset3 = {
+    // Make sure effects chain exists
+    if(~effectsChain.isNil, { ~startEffectsChain.value; });
+
+    "Initialized Preset 3 (Fountain Pen) - TBD".postln;
+};
+
+// Initialize Effect Preset 4 (Water Color)
+~initializePreset4 = {
+    // Make sure effects chain exists
+    if(~effectsChain.isNil, { ~startEffectsChain.value; });
+
+    "Initialized Preset 4 (Water Color) - TBD".postln;
+};
+
+"Effect preset initializers loaded".postln;
+)

+ 110 - 0
SC/7_idraw_connection.scd

@@ -0,0 +1,110 @@
+(
+// Function to test iDraw OSC connection
+~testiDrawConnection = {
+    var interfaces, ip;
+
+    // Log local IP and port information
+    "SuperCollider OSC server info for iDraw OSC connection:".postln;
+    "Hostname: %".format(Platform.myHostName).postln;
+    "Local IP addresses:".postln;
+
+    try {
+        interfaces = "ifconfig".unixCmdGetStdOutLines;
+        interfaces.do { |line|
+            if(line.containsi("inet ") && line.containsStringAt(0, "inet").not, {
+                line = line.replace("\t", "").replace(" ", "");
+                ip = line.findRegexp("inet([0-9.]+)")[1][1];
+                "  %".format(ip).postln;
+            });
+        };
+    } { |err|
+        "Could not detect network interfaces: %".format(err).postln;
+    };
+
+    // Alternate way to find IP addresses that might work better on some systems
+    "Alternative method to find IP addresses:".postln;
+    try {
+        thisProcess.platform.getNetworkNameList.do { |netname|
+            var addr = netname.findRegexp("\\d+\\.\\d+\\.\\d+\\.\\d+");
+            if(addr.size > 0, {
+                "  %".format(addr[0][1]).postln;
+            });
+        };
+    } { |err|
+        "Could not use network name list method: %".format(err).postln;
+    };
+
+    "OSC Port: 57120".postln;
+    "".postln;
+    "To connect from iDraw OSC:".postln;
+    "1. Ensure iPad/iPhone is on the same WiFi network".postln;
+    "2. Open iDraw OSC app".postln;
+    "3. Set the host/IP to one of the above addresses".postln;
+    "4. Set the port to 57120".postln;
+    "5. Ensure iDraw OSC is sending messages with these addresses:".postln;
+    "   - /touch (x, y, pressure)".postln;
+    "   - /pen (pen type)".postln;
+    "   - /color (r, g, b)".postln;
+};
+
+// Function to simulate iDraw OSC messages for testing
+~simulateiDrawTouch = { |duration=10|
+    var endTime, penTypes, penType, r, g, b;
+
+    endTime = SystemClock.seconds + duration;
+    "Simulating iDraw OSC touch events for % seconds".format(duration).postln;
+
+    // Start the effects chain if needed
+    if(~effectsChain.isNil, { ~startEffectsChain.value; });
+
+    // First set a pen type
+    penTypes = [\pen, \monoline, \marker, \pencil, \crayon, \fountainPen, \waterColor];
+    penType = penTypes.choose;
+
+    OSCdef(\penTypeOSC).value(['/pen', penType], nil, nil, nil);
+
+    // Set a random color
+    r = 1.0.rand;
+    g = 1.0.rand;
+    b = 1.0.rand;
+
+    OSCdef(\colorOSC).value(['/color', r, g, b], nil, nil, nil);
+
+    // Generate simulated touch events
+    fork {
+        while { SystemClock.seconds < endTime } {
+            var x = (-0.5 + 1.0.rand);
+            var y = (-0.5 + 1.0.rand);
+            var pressure = 1 + 7.rand;
+
+            // Send touch message
+            OSCdef(\touchOSC).value(['/touch', x, y, pressure], nil, nil, nil);
+
+            // Wait random time between touch events
+            rrand(0.1, 0.3).wait;
+
+            // Occasionally change pen type or color
+            if(0.1.coin, {
+                penType = penTypes.choose;
+                OSCdef(\penTypeOSC).value(['/pen', penType], nil, nil, nil);
+                "Changed to pen type: %".format(penType).postln;
+            });
+
+            if(0.1.coin, {
+                r = 1.0.rand;
+                g = 1.0.rand;
+                b = 1.0.rand;
+                OSCdef(\colorOSC).value(['/color', r, g, b], nil, nil, nil);
+                "Changed to color: % % %".format(r, g, b).postln;
+            });
+        };
+
+        "iDraw OSC simulation complete".postln;
+    };
+};
+
+// Run these functions directly
+"iDraw OSC connection test functions loaded.".postln;
+"To test connection info, run: ~testiDrawConnection.value".postln;
+"To simulate iDraw OSC events, run: ~simulateiDrawTouch.value(20)".postln;
+)