| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- // 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.0, g: 0.0, b: 1.0); // Default blue
- ~currentPadValues = (x: 0.0, y: 0.0, pressure: 1.0); //Default pad values
- // Define OSC responder for iDraw touch data
- ~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;
- // Handle touch based on current pen type
- switch(~currentPenType,
- // Pen - Controls amplitude envelope
- "/pen", {
- var ampAttack = y.linexp(-0.5, 0.5, 0.001, 5);
- var ampRelease = x.linexp(-0.5, 0.5, 0.001, 10);
- ~setSynthsParam.(\ampAttack, ampAttack);
- ~setSynthsParam.(\ampRelease, ampRelease);
- ["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);
- ~setSynthsParam.(\filterAttack, filterAttack);
- ~setSynthsParam.(\filterRelease, filterRelease);
- ["Filter envelope:", filterAttack, filterRelease].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);
- ~setSynthsParam.(\pitchAttack, pitchAttack);
- ~setSynthsParam.(\pitchRelease, pitchRelease);
- ["Pitch envelope:", pitchAttack, pitchRelease].postln;
- },
- // Pencil - Effect preset 1
- "/pencil", {
- // Apply Preset 1 effects
- ~filter.set(
- \cutoff, x.linexp(-0.5, 0.5, 20, 18000),
- \resonance, y.linlin(-0.5, 0.5, 0, 1),
- \lfoDepth, pressure.linlin(1, 8, 0, 3)
- );
- ~lfo.set(
- \freq, x.linlin(-0.5, 0.5, 0, 15),
- \waveform, 2
- );
- /*
- ~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;
- }
- );
- };
- // ----- OSC Pad Vaues -----
- // OSC responder for x coordinate
- OSCdef(\xOSC, { |msg, time, addr, port|
- var x = msg[1].asFloat;
- // 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;
- }
- }, '/pen');
- // 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 = component;
- ~setSynthsParam.(\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;
- ~setSynthsParam.(\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;
- ~setSynthsParam.(\blueAmt, component);
- ["Color changed:", ~currentColor].postln;
- }, '/b');
- // 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;
- )
|