|
|
@@ -7,13 +7,32 @@ OSCdef.freeAll;
|
|
|
|
|
|
// Variables to track current pen type and color
|
|
|
~currentPenType = \pen;
|
|
|
-~currentColor = (r: 0, g: 0, b: 1); // Default blue
|
|
|
+~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
|
|
|
+
|
|
|
+~synthParams = (
|
|
|
+ out: 0,
|
|
|
+ freq: 440,
|
|
|
+ amp: 0.5,
|
|
|
+ ampAttack: 0.01,
|
|
|
+ ampRelease: 1,
|
|
|
+ filterAttack: 0,
|
|
|
+ filterRelease: 0,
|
|
|
+ filterMin: 200,
|
|
|
+ filterMax: 5000,
|
|
|
+ pitchAttack: 0,
|
|
|
+ pitchRelease: 0,
|
|
|
+ pitchRatio: 2,
|
|
|
+ redAmt: 0.5,
|
|
|
+ greenAmt: 0.5,
|
|
|
+ blueAmt: 0.5
|
|
|
+);
|
|
|
|
|
|
// 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;
|
|
|
+~changeEffectParams = {
|
|
|
+ var x = ~currentPadValues.x;
|
|
|
+ var y = ~currentPadValues.y;
|
|
|
+ var pressure = ~currentPadValues.pressure;
|
|
|
|
|
|
// Log the received data
|
|
|
["Touch data:", x, y, pressure, ~currentPenType, ~currentColor].postln;
|
|
|
@@ -21,74 +40,40 @@ OSCdef(\touchOSC, { |msg, time, addr, port|
|
|
|
// 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;
|
|
|
+ "/pen", {
|
|
|
+ var ampAttack = y.linexp(-0.5, 0.5, 0.001, 5);
|
|
|
+ var ampRelease = x.linexp(-0.5, 0.5, 0.001, 10);
|
|
|
+
|
|
|
+ ~synthParams.ampAttack = ampAttack;
|
|
|
+ ~synthParams.ampRelease = ampRelease;
|
|
|
+
|
|
|
+ ["Amplitude envelope:", ampAttack, ampRelease].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;
|
|
|
+ "/monoline", {
|
|
|
+ var filterAttack = y.linexp(-0.5, 0.5, 0.001, 5);
|
|
|
+ var filterRelease = x.linexp(-0.5, 0.5, 0.001, 10);
|
|
|
+
|
|
|
+ ~synthParams.filterAttack = filterAttack;
|
|
|
+ ~synthParams.filterRelease = filterRelease;
|
|
|
+
|
|
|
+ ["Filter envelope:", filterAttack, filterRelease].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;
|
|
|
+ "/marker", {
|
|
|
+ var pitchAttack = y.linexp(-0.5, 0.5, 0.001, 5);
|
|
|
+ var pitchRelease = x.linexp(-0.5, 0.5, 0.001, 10);
|
|
|
+
|
|
|
+ ~synthParams.pitchAttack = pitchAttack;
|
|
|
+ ~synthParams.pitchRelease = pitchRelease;
|
|
|
+
|
|
|
+ ["Pitch envelope:", pitchAttack, pitchRelease].postln;
|
|
|
},
|
|
|
|
|
|
// Pencil - Effect preset 1
|
|
|
- \pencil, {
|
|
|
+ "/pencil", {
|
|
|
// Apply Preset 1 effects
|
|
|
~filterSynth.set(
|
|
|
\cutoff, x.linexp(-0.5, 0.5, 20, 18000),
|
|
|
@@ -108,7 +93,7 @@ OSCdef(\touchOSC, { |msg, time, addr, port|
|
|
|
},
|
|
|
|
|
|
// Crayon - Effect preset 2
|
|
|
- \crayon, {
|
|
|
+ "/crayon", {
|
|
|
// Apply Preset 2 effects
|
|
|
~lfoSynth.set(
|
|
|
\freq, x.linlin(-0.5, 0.5, 15, 1),
|
|
|
@@ -132,48 +117,176 @@ OSCdef(\touchOSC, { |msg, time, addr, port|
|
|
|
},
|
|
|
|
|
|
// Fountain pen - Effect preset 3 (placeholder)
|
|
|
- \fountainPen, {
|
|
|
+ "/fountainPen", {
|
|
|
// Apply Preset 3 effects (TBD in documentation)
|
|
|
["Fountain pen preset (TBD)"].postln;
|
|
|
},
|
|
|
|
|
|
// Water color - Effect preset 4 (placeholder)
|
|
|
- \waterColor, {
|
|
|
+ "/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;
|
|
|
+// ----- OSC Pad Vaues -----
|
|
|
+// OSC responder for x coordinate
|
|
|
+OSCdef(\xOSC, { |msg, time, addr, port|
|
|
|
+ var x = msg[1].asFloat;
|
|
|
|
|
|
- ["Pen type changed:", penType].postln;
|
|
|
+ // Update current pad value and change effects
|
|
|
+ ~currentPadValues.x = x;
|
|
|
+ ~changeEffectParams.value;
|
|
|
+
|
|
|
+}, '/aspectX');
|
|
|
+
|
|
|
+// OSC responder for y coordinate
|
|
|
+OSCdef(\yOSC, { |msg, time, addr, port|
|
|
|
+ var y = msg[1].asFloat;
|
|
|
+
|
|
|
+ // Update current pad value and change effects
|
|
|
+ ~currentPadValues.y = y;
|
|
|
+ ~changeEffectParams.value;
|
|
|
+
|
|
|
+}, '/aspectY');
|
|
|
+
|
|
|
+// OSC responder for pressure coordinate
|
|
|
+OSCdef(\pressureOSC, { |msg, time, addr, port|
|
|
|
+ var pressure = msg[1].asFloat;
|
|
|
+
|
|
|
+ // Update current pad value and change effects
|
|
|
+ ~currentPadValues.pressure = pressure;
|
|
|
+ ~changeEffectParams.value;
|
|
|
+
|
|
|
+}, '/pressure');
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// ----- OSC Pen Types -----
|
|
|
+// OSC responder for pen
|
|
|
+OSCdef(\penOSC, { |msg, time, addr, port|
|
|
|
+ var penType = msg[1].asFloat;
|
|
|
+
|
|
|
+ if (penType == 1.0) {
|
|
|
+ ~currentPenType = msg[0].asString;
|
|
|
+ ["Current pen type:", ~currentPenType].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;
|
|
|
+// OSC responder for monoline
|
|
|
+OSCdef(\monolineOSC, { |msg, time, addr, port|
|
|
|
+ var penType = msg[1].asFloat;
|
|
|
+
|
|
|
+ if (penType == 1.0) {
|
|
|
+ ~currentPenType = msg[0].asString;
|
|
|
+ ["Current pen type:", ~currentPenType].postln;
|
|
|
+ }
|
|
|
+
|
|
|
+}, '/monoline');
|
|
|
+
|
|
|
+// OSC responder for marker
|
|
|
+OSCdef(\markerOSC, { |msg, time, addr, port|
|
|
|
+ var penType = msg[1].asFloat;
|
|
|
+
|
|
|
+ if (penType == 1.0) {
|
|
|
+ ~currentPenType = msg[0].asString;
|
|
|
+ ["Current pen type:", ~currentPenType].postln;
|
|
|
+ }
|
|
|
+
|
|
|
+}, '/marker');
|
|
|
+
|
|
|
+// OSC responder for pencil
|
|
|
+OSCdef(\pencilOSC, { |msg, time, addr, port|
|
|
|
+ var penType = msg[1].asFloat;
|
|
|
+
|
|
|
+ if (penType == 1.0) {
|
|
|
+ ~currentPenType = msg[0].asString;
|
|
|
+ ~initializePreset1.value;
|
|
|
+ ["Current pen type:", ~currentPenType].postln;
|
|
|
+ }
|
|
|
+
|
|
|
+}, '/pencil');
|
|
|
+
|
|
|
+// OSC responder for crayon
|
|
|
+OSCdef(\crayonOSC, { |msg, time, addr, port|
|
|
|
+ var penType = msg[1].asFloat;
|
|
|
+
|
|
|
+ if (penType == 1.0) {
|
|
|
+ ~currentPenType = msg[0].asString;
|
|
|
+ ~initializePreset2.value;
|
|
|
+ ["Current pen type:", ~currentPenType].postln;
|
|
|
+ }
|
|
|
+
|
|
|
+}, '/crayon');
|
|
|
+
|
|
|
+// OSC responder for fountainPen
|
|
|
+OSCdef(\fountainPenOSC, { |msg, time, addr, port|
|
|
|
+ var penType = msg[1].asFloat;
|
|
|
+
|
|
|
+ if (penType == 1.0) {
|
|
|
+ ~currentPenType = msg[0].asString;
|
|
|
+ ~initializePreset3.value;
|
|
|
+ ["Current pen type:", ~currentPenType].postln;
|
|
|
+ }
|
|
|
+
|
|
|
+}, '/fountainPen');
|
|
|
+
|
|
|
+// OSC responder for waterColor
|
|
|
+OSCdef(\waterColorOSC, { |msg, time, addr, port|
|
|
|
+ var penType = msg[1].asFloat;
|
|
|
+
|
|
|
+ if (penType == 1.0) {
|
|
|
+ ~currentPenType = msg[0].asString;
|
|
|
+ ~initializePreset4.value;
|
|
|
+ ["Current pen type:", ~currentPenType].postln;
|
|
|
+ }
|
|
|
+
|
|
|
+}, '/waterColor');
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// ----- OSC RGB Colors -----
|
|
|
+// OSC responder for red changes
|
|
|
+OSCdef(\redOSC, { |msg, time, addr, port|
|
|
|
+ var component = msg[1].asFloat;
|
|
|
|
|
|
// Update current color
|
|
|
- ~currentColor = (r: r, g: g, b: b);
|
|
|
+ ~currentColor.r = component;
|
|
|
+ ~synthParams.redAmt = component;
|
|
|
+
|
|
|
+ ["Color changed:", ~currentColor].postln;
|
|
|
+}, '/r');
|
|
|
+
|
|
|
+// OSC responder for green changes
|
|
|
+OSCdef(\greenOSC, { |msg, time, addr, port|
|
|
|
+ var component = msg[1].asFloat;
|
|
|
+
|
|
|
+ // Update current color
|
|
|
+ ~currentColor.g = component;
|
|
|
+ ~synthParams.greenAmt = component;
|
|
|
+
|
|
|
+ ["Color changed:", ~currentColor].postln;
|
|
|
+}, '/g');
|
|
|
+
|
|
|
+// OSC responder for blue changes
|
|
|
+OSCdef(\blueOSC, { |msg, time, addr, port|
|
|
|
+ var component = msg[1].asFloat;
|
|
|
+
|
|
|
+ // Update current color
|
|
|
+ ~currentColor.b = component;
|
|
|
+ ~synthParams.blueAmt = component;
|
|
|
+
|
|
|
+ ["Color changed:", ~currentColor].postln;
|
|
|
+}, '/b');
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- ["Color changed:", r, g, b].postln;
|
|
|
-}, '/color');
|
|
|
|
|
|
// Start the OSC server on port 57120 (default SuperCollider port)
|
|
|
thisProcess.openUDPPort(57120);
|