MidiIn mIn; MidiMsg mInMsg; MidiOut mOut; MidiMsg mOutMsg; // midi initialization mIn.open(0); mOut.open(0); //////////////////////////////////////////////////////////// //midi state of controller //////////////////////////////////////////////////////////// //red 176 => mOutMsg.data1; 0 => mOutMsg.data2; 127 => mOutMsg.data3; mOut.send(mOutMsg); //green 176 => mOutMsg.data1; 1 => mOutMsg.data2; 127 => mOutMsg.data3; mOut.send(mOutMsg); //blue 176 => mOutMsg.data1; 2 => mOutMsg.data2; 127 => mOutMsg.data3; mOut.send(mOutMsg); //master 176 => mOutMsg.data1; 3 => mOutMsg.data2; 127 => mOutMsg.data3; mOut.send(mOutMsg); //lfoR 176 => mOutMsg.data1; 4 => mOutMsg.data2; 63 => mOutMsg.data3; mOut.send(mOutMsg); //lfoG 176 => mOutMsg.data1; 5 => mOutMsg.data2; 63 => mOutMsg.data3; mOut.send(mOutMsg); //lfoB 176 => mOutMsg.data1; 6 => mOutMsg.data2; 63 => mOutMsg.data3; mOut.send(mOutMsg); //lfoM 176 => mOutMsg.data1; 7 => mOutMsg.data2; 63 => mOutMsg.data3; mOut.send(mOutMsg); //pinspot1 176 => mOutMsg.data1; 8 => mOutMsg.data2; 127 => mOutMsg.data3; mOut.send(mOutMsg); //pinspot2 176 => mOutMsg.data1; 9 => mOutMsg.data2; 127 => mOutMsg.data3; mOut.send(mOutMsg); //pinspot3 176 => mOutMsg.data1; 10 => mOutMsg.data2; 127 => mOutMsg.data3; mOut.send(mOutMsg); //pinspot4 176 => mOutMsg.data1; 11 => mOutMsg.data2; 127 => mOutMsg.data3; mOut.send(mOutMsg); //////////////////////////////////////////////////////////// //rgb stuff //////////////////////////////////////////////////////////// int redValue; int blueValue; int greenValue; int masterValue; 127 => redValue; 127 => blueValue; 127 => greenValue; 127 => masterValue; int redToggle; int blueToggle; int greenToggle; int masterToggle; 1 => redToggle; 1 => blueToggle; 1 => greenToggle; 1 => masterToggle; int redLFOToggle; int blueLFOToggle; int greenLFOToggle; int masterLFOToggle; 1 => redLFOToggle; 1 => blueLFOToggle; 1 => greenLFOToggle; 1 => masterLFOToggle; int spotToggle1; int spotToggle2; int spotToggle3; int spotToggle4; //////////////////////////////////////////////////////////// //tap tempo stuff //////////////////////////////////////////////////////////// time currTempoTap; time prevTempoTap; dur sinceLastTap; int msSinceLastTap; float msTapTempoRate; int tapTempoShredID; int tapTempoLatch; 0 => tapTempoLatch; 500 => msTapTempoRate; Shred tapTempoShredReference; spork~Blink(msTapTempoRate) @=> tapTempoShredReference; float tempoMultiplier; 1 => tempoMultiplier; float prevTempoMultiplier; 1 => prevTempoMultiplier; //////////////////////////////////////////////////////////// //LFO stuff //////////////////////////////////////////////////////////// Shred lfoModShredReference; TriOsc lfo => blackhole; spork~LFOMod(msTapTempoRate) @=> lfoModShredReference; float lfoPhase; int redModCoefficientIsPositive; float redModCoefficient; int redLFOModAmount; int greenModCoefficientIsPositive; float greenModCoefficient; int greenLFOModAmount; int blueModCoefficientIsPositive; float blueModCoefficient; int blueLFOModAmount; int masterModCoefficientIsPositive; float masterModCoefficient; int masterLFOModAmount; //////////////////////////////////////////////////////////// //dmx control stuff //////////////////////////////////////////////////////////// SerialIO cereal; cereal.open(0, SerialIO.B9600, SerialIO.ASCII); // list serial devices SerialIO.list() @=> string list[]; // no serial devices available if(list.cap() == 0) { cherr <= "no serial devices available\n"; // me.exit(); } // print list of serial devices chout <= "Available devices\n"; for(int i; i < list.cap(); i++) { chout <= i <= ": " <= list[i] <= IO.newline(); } /////////////////////////////////////////////////////////////// //DMX /////////////////////////////////////////////////////////////// //DMX channels: //1 - blue //2 - green //3 - red //4 - reserved (0) //5 - reserved (0) //6 - reserved (0) //7 - rgb master briteness //8 - fog //9 - dimmer 1 //10 - dimmer 2 //11 - dimmer 3 //12 - dimmer 4 //rgb master briteness at 100% SendDMX(255,255,255,0,0,0,255,0,0,0,0,0); // loop while( true ) { mIn => now; while( mIn.recv(mInMsg) ) { // print out midi message <<< mInMsg.data1, mInMsg.data2, mInMsg.data3 >>>; //////////////////////////////////////////////////////////// //RGB/LFO Toggles //////////////////////////////////////////////////////////// //data3 of 127 turns off, 0 turns on if (mInMsg.data1 == 129) { if (mInMsg.data3 == 0) { if (mInMsg.data2 == 0) { 1 => redToggle; } if (mInMsg.data2 == 1) { 1 => greenToggle; } if (mInMsg.data2 == 2) { 1 => blueToggle; } if (mInMsg.data2 == 3) { 1 => masterToggle; } if (mInMsg.data2 == 4) { 1 => redLFOToggle; } if (mInMsg.data2 == 5) { 1 => greenLFOToggle; } if (mInMsg.data2 == 6) { 1 => blueLFOToggle; } if (mInMsg.data2 == 7) { 1 => masterLFOToggle; } } } if (mInMsg.data1 == 145) { if (mInMsg.data3 == 127) { if (mInMsg.data2 == 0) { 0 => redToggle; } if (mInMsg.data2 == 1) { 0 => greenToggle; } if (mInMsg.data2 == 2) { 0 => blueToggle; } if (mInMsg.data2 == 3) { 0 => masterToggle; } if (mInMsg.data2 == 4) { 0 => redLFOToggle; } if (mInMsg.data2 == 5) { 0 => greenLFOToggle; } if (mInMsg.data2 == 6) { 0 => blueLFOToggle; } if (mInMsg.data2 == 7) { 0 => masterLFOToggle; } } } //////////////////////////////////////////////////////////// //RGB Knobs //////////////////////////////////////////////////////////// if (mInMsg.data1 == 176) { if (mInMsg.data2 == 0) { mInMsg.data3 => redValue; } if (mInMsg.data2 == 1) { mInMsg.data3 => greenValue; } if (mInMsg.data2 == 2) { mInMsg.data3 => blueValue; } if (mInMsg.data2 == 3) { mInMsg.data3 => masterValue; } } //////////////////////////////////////////////////////////// //tempo tap //////////////////////////////////////////////////////////// if (mInMsg.data1 == 145) { if (mInMsg.data2 == 15) { //tap detected 1 => tapTempoLatch; now - prevTempoTap @=> sinceLastTap; now => prevTempoTap; //<<>>; if (sinceLastTap/second < 2) { if (prevTempoTap/second > 0) { now => now; sinceLastTap/ms @=> msTapTempoRate; <<< sinceLastTap/ms + " since last tap">>>; tapTempoShredReference.id() => Machine.remove; spork~Blink(msTapTempoRate) @=> tapTempoShredReference; lfoModShredReference.id() => Machine.remove; spork~LFOMod(msTapTempoRate) @=> lfoModShredReference; //sync lfo if (redModCoefficientIsPositive == 1) { 0.25 => lfo.phase; } if (redModCoefficientIsPositive == 0) { 0.75 => lfo.phase; } } } } } //latch if (mInMsg.data1 == 129) { if (mInMsg.data2 == 15) { //release detected 0 => tapTempoLatch; } } //lfo modulation if (mInMsg.data1 == 176) { //red modulation if (mInMsg.data2 == 4) { //positive modulation if (mInMsg.data3 == 127) { 1 => redModCoefficientIsPositive; 1 => redModCoefficient; <<< redModCoefficient + " POSITIVE redModCoefficient " >>>; } if ((mInMsg.data3 > 63) && (mInMsg.data3 != 127)) { 1 => redModCoefficientIsPositive; ((mInMsg.data3 - 63) * 1.58) / 100 => redModCoefficient; <<< redModCoefficient + " POSITIVE redModCoefficient " >>>; } //negative modulation if ((mInMsg.data3 < 63) && (mInMsg.data3 != 0)) { 0 => redModCoefficientIsPositive; ((63 - mInMsg.data3) * 1.58) / 100 => redModCoefficient; <<< redModCoefficient + " NEGATIVE redModCoefficient " >>>; } if (mInMsg.data3 == 63) { 1 => redModCoefficientIsPositive; 0 => redModCoefficient; <<< redModCoefficient + " ZERO redModCoefficient " >>>; } if (mInMsg.data3 == 0) { 0 => redModCoefficientIsPositive; 1 => redModCoefficient; <<< redModCoefficient + " NEGATIVE redModCoefficient " >>>; } } //green modulation if (mInMsg.data2 == 5) { //positive modulation if (mInMsg.data3 == 127) { 1 => greenModCoefficientIsPositive; 1 => greenModCoefficient; <<< greenModCoefficient + " POSITIVE greenModCoefficient " >>>; } if ((mInMsg.data3 > 63) && (mInMsg.data3 != 127)) { 1 => greenModCoefficientIsPositive; ((mInMsg.data3 - 63) * 1.58) / 100 => greenModCoefficient; <<< greenModCoefficient + " POSITIVE greenModCoefficient " >>>; } //negative modulation if ((mInMsg.data3 < 63) && (mInMsg.data3 != 0)) { 0 => greenModCoefficientIsPositive; ((63 - mInMsg.data3) * 1.58) / 100 => greenModCoefficient; <<< greenModCoefficient + " NEGATIVE greenModCoefficient " >>>; } if (mInMsg.data3 == 63) { 1 => greenModCoefficientIsPositive; 0 => greenModCoefficient; <<< greenModCoefficient + " ZERO greenModCoefficient " >>>; } if (mInMsg.data3 == 0) { 0 => greenModCoefficientIsPositive; 1 => greenModCoefficient; <<< greenModCoefficient + " NEGATIVE greenModCoefficient " >>>; } } //blue modulation if (mInMsg.data2 == 6) { //positive modulation if (mInMsg.data3 == 127) { 1 => blueModCoefficientIsPositive; 1 => blueModCoefficient; <<< blueModCoefficient + " POSITIVE blueModCoefficient " >>>; } if ((mInMsg.data3 > 63) && (mInMsg.data3 != 127)) { 1 => blueModCoefficientIsPositive; ((mInMsg.data3 - 63) * 1.58) / 100 => blueModCoefficient; <<< blueModCoefficient + " POSITIVE blueModCoefficient " >>>; } //negative modulation if ((mInMsg.data3 < 63) && (mInMsg.data3 != 0)) { 0 => blueModCoefficientIsPositive; ((63 - mInMsg.data3) * 1.58) / 100 => blueModCoefficient; <<< blueModCoefficient + " NEGATIVE blueModCoefficient " >>>; } if (mInMsg.data3 == 63) { 1 => blueModCoefficientIsPositive; 0 => blueModCoefficient; <<< blueModCoefficient + " ZERO blueModCoefficient " >>>; } if (mInMsg.data3 == 0) { 0 => blueModCoefficientIsPositive; 1 => blueModCoefficient; <<< blueModCoefficient + " NEGATIVE blueModCoefficient " >>>; } } //master modulation if (mInMsg.data2 == 7) { //positive modulation if (mInMsg.data3 == 127) { 1 => masterModCoefficientIsPositive; 1 => masterModCoefficient; <<< masterModCoefficient + " POSITIVE masterModCoefficient " >>>; } if ((mInMsg.data3 > 63) && (mInMsg.data3 != 127)) { 1 => masterModCoefficientIsPositive; ((mInMsg.data3 - 63) * 1.58) / 100 => masterModCoefficient; <<< masterModCoefficient + " POSITIVE masterModCoefficient " >>>; } //negative modulation if ((mInMsg.data3 < 63) && (mInMsg.data3 != 0)) { 0 => masterModCoefficientIsPositive; ((63 - mInMsg.data3) * 1.58) / 100 => masterModCoefficient; <<< masterModCoefficient + " NEGATIVE masterModCoefficient " >>>; } if (mInMsg.data3 == 63) { 1 => masterModCoefficientIsPositive; 0 => masterModCoefficient; <<< masterModCoefficient + " ZERO masterModCoefficient " >>>; } if (mInMsg.data3 == 0) { 0 => masterModCoefficientIsPositive; 1 => masterModCoefficient; <<< masterModCoefficient + " NEGATIVE masterModCoefficient " >>>; } } //tempo multiplier if (mInMsg.data1 == 176) { if (mInMsg.data2 == 15) { if (mInMsg.data3 == 127) { 0.03125 => tempoMultiplier; } if ((mInMsg.data3 > 111) && (mInMsg.data3 < 127)) { 0.0625 => tempoMultiplier; } if ((mInMsg.data3 > 95) && (mInMsg.data3 < 111)) { 0.125 => tempoMultiplier; } if ((mInMsg.data3 > 79) && (mInMsg.data3 < 95)) { 0.25 => tempoMultiplier; } if ((mInMsg.data3 > 63) && (mInMsg.data3 < 79)) { 0.5 => tempoMultiplier; } if (mInMsg.data3 == 63) { 1 => tempoMultiplier; } if ((mInMsg.data3 > 50) && (mInMsg.data3 < 60)) { 2 => tempoMultiplier; } if ((mInMsg.data3 > 32) && (mInMsg.data3 < 50)) { 4 => tempoMultiplier; } if ((mInMsg.data3 > 15) && (mInMsg.data3 < 32)) { 8 => tempoMultiplier; } if (mInMsg.data3 < 15) { 16 => tempoMultiplier; } if (tempoMultiplier != prevTempoMultiplier) { <<< tempoMultiplier >>>; lfoModShredReference.id() => Machine.remove; spork~LFOMod(msTapTempoRate) @=> lfoModShredReference; tempoMultiplier => prevTempoMultiplier; } } } } } } fun void SendDMX(int c1, int c2, int c3, int c4, int c5, int c6, int c7, int c8, int c9, int c10, int c11, int c12) { if (c1 < 0) { 0 => c1; } if (c2 < 0) { 0 => c2; } if (c3 < 0) { 0 => c3; } if (c7 < 0) { 0 => c7; } //<<< c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12 >>>; [126,6,13,0,0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,231] @=> int bytes[]; cereal.writeBytes(bytes); } fun void Blink(float _msTapTempoRate) { while( true ) { if (tapTempoLatch == 0) { 145 => mOutMsg.data1; 4 => mOutMsg.data2; 127 => mOutMsg.data3; mOut.send(mOutMsg); 145 => mOutMsg.data1; 5 => mOutMsg.data2; 127 => mOutMsg.data3; mOut.send(mOutMsg); 145 => mOutMsg.data1; 6 => mOutMsg.data2; 127 => mOutMsg.data3; mOut.send(mOutMsg); 145 => mOutMsg.data1; 7 => mOutMsg.data2; 127 => mOutMsg.data3; mOut.send(mOutMsg); 145 => mOutMsg.data1; 15 => mOutMsg.data2; 127 => mOutMsg.data3; mOut.send(mOutMsg); } 50::ms => now; 145 => mOutMsg.data1; 4 => mOutMsg.data2; 0 => mOutMsg.data3; mOut.send(mOutMsg); 145 => mOutMsg.data1; 5 => mOutMsg.data2; 0 => mOutMsg.data3; mOut.send(mOutMsg); 145 => mOutMsg.data1; 6 => mOutMsg.data2; 0 => mOutMsg.data3; mOut.send(mOutMsg); 145 => mOutMsg.data1; 7 => mOutMsg.data2; 0 => mOutMsg.data3; mOut.send(mOutMsg); 145 => mOutMsg.data1; 15 => mOutMsg.data2; 0 => mOutMsg.data3; mOut.send(mOutMsg); //<<< "blink",now/ms >>>; (msTapTempoRate - 50)::ms => now; me.yield(); } } fun void LFOMod(float _LFORate) { (1 / (_LFORate / 1000)) * tempoMultiplier => lfo.freq; while( true ) { //<<< _LFORate / 250 >>>; 10::ms => now; lfo.last() => lfoPhase; //<<< (lfoPhase + 1) / 2 >>>; //<<< redValue >>>; if (redModCoefficientIsPositive == 1) { ((((lfoPhase + 1) / 2) * (255 - (redValue * 2)) * redModCoefficient)) $ int => redLFOModAmount; } if (redModCoefficientIsPositive == 0) { (((((lfoPhase + 1) / 2) * (redValue * 2) * redModCoefficient)) * -1) $ int => redLFOModAmount; } if (greenModCoefficientIsPositive == 1) { ((((lfoPhase + 1) / 2) * (255 - (greenValue * 2)) * greenModCoefficient)) $ int => greenLFOModAmount; } if (greenModCoefficientIsPositive == 0) { (((((lfoPhase + 1) / 2) * (greenValue * 2) * greenModCoefficient)) * -1) $ int => greenLFOModAmount; } if (blueModCoefficientIsPositive == 1) { ((((lfoPhase + 1) / 2) * (255 - (blueValue * 2)) * blueModCoefficient)) $ int => blueLFOModAmount; } if (blueModCoefficientIsPositive == 0) { (((((lfoPhase + 1) / 2) * (blueValue * 2) * blueModCoefficient)) * -1) $ int => blueLFOModAmount; } if (masterModCoefficientIsPositive == 1) { ((((lfoPhase + 1) / 2) * (255 - (masterValue * 2)) * masterModCoefficient)) $ int => masterLFOModAmount; } if (masterModCoefficientIsPositive == 0) { (((((lfoPhase + 1) / 2) * (masterValue * 2) * masterModCoefficient)) * -1) $ int => masterLFOModAmount; } SendDMX((blueValue * 2 + blueLFOModAmount) * blueToggle ,(greenValue * 2 + greenLFOModAmount) * greenToggle,(redValue * 2 + redLFOModAmount) * redToggle ,0,0,0,(masterValue * 2 + masterLFOModAmount) * masterToggle,0,0,0,0,0); me.yield(); } }