MAUI_View myWinder; MAUI_Slider pots[5]; MAUI_Button exit; MAUI_Button butts[5]; MAUI_Slider FSR; MAUI_Slider JACK; MAUI_Button tiltButt; MAUI_Slider tiltSlider[2]; MAUI_Button midiLabel; MAUI_LED midiStatus; doGUI(); MidiIn min; // a midi event MidiMsg msg; // a message for retrieving data -1.0 => float MIDINote; 0 => int gotMIDI; 0 => int flashMIDI; setupMIDI(); 1.0 => float blowsuck; 0.0 => float MIDIVolume; [0.0, 0.0] @=> float tilts[]; 0 => int newTilt; [0.0, 0.0, 0.0, 0.0, 0.0] @=> float pot[]; 0 => int newPots; [0,0,0,0,0] @=> int valves[]; 0.0 => float FSRval; 0.0 => float JACKval; 1 => int notDone; spork ~ handleMIDI(); spork ~ updateMAUI(); 3 => int NUM; [60, 64, 67] @=> int notes[]; [ 0, 0, 0] @=> int noteCount[]; SndBuf dope => dac; "special:dope" => dope.read; dope.samples() => dope.pos; Mandolin mand => dac; // 0.0 => mand.gain; 0.53 => float LOWERBOUND; 0.06 => float INCREMENT; 0.0 => float tempPot; while (notDone) { (1-exit.state()) => notDone; 0.05 :: second => now; pots[0].value() => tempPot; if (tempPot < LOWERBOUND) { if (noteCount[0] > 0) { if (noteCount[0] == 2 & noteCount[1] == 2 & noteCount[2] == 1) { <<< "SUCCESS!!" >>>; happyMelody(); } else { 0 => dope.pos; } for (0 => int i; i < NUM; i++) 0 => noteCount[i]; } } else playLoop(); } myWinder.destroy(); fun void playLoop() { while (tempPot > LOWERBOUND && notDone) { for (0 => int i; i < NUM; i++) { LOWERBOUND + i*INCREMENT => float templow; if (within(tempPot, templow, templow + INCREMENT)) { Std.mtof(notes[i]) => mand.freq; 1.0 => mand.noteOn; 1 +=> noteCount[i]; } } 0.3 :: second => now; (1-exit.state()) => notDone; pots[0].value() => tempPot; } } fun int within(float value, float lower, float upper) { 1 => int result; if (value < lower) 0 => result; if (value > upper) 0 => result; <<< value, lower, upper, result >>>; return result; } fun void happyMelody() { Std.mtof(72) => mand.freq; 1 => mand.noteOn; 0.1 :: second => now; Std.mtof(76) => mand.freq; 1 => mand.noteOn; 0.1 :: second => now; Std.mtof(79) => mand.freq; 1 => mand.noteOn; 0.1 :: second => now; Std.mtof(84) => mand.freq; 1 => mand.noteOn; 0.1 :: second => now; } fun void handleMIDI() { int temp,note; while (notDone) { min => now; // wait on the event 'min' 1 => gotMIDI; (1 - flashMIDI) => flashMIDI; while( min.recv(msg) ) { // get the message(s) // <<< msg.data1, msg.data2, msg.data3 >>>; // print out midi message if (msg.data1 == 144) { msg.data2 => MIDINote; } else if (msg.data1 == 128) { -1 * Std.fabs(MIDINote) => MIDINote; } else if (msg.data1 == 208) { /* MIDI Aftertouch, Do Nothing, Same as MIDI Volume??? */ } else if (msg.data1 == 176) { // MIDI CONTROLLERS if (msg.data2 == 2) { msg.data3 / 127.0 => pot[0]; 1 => newPots; } else if (msg.data2 == 1) { msg.data3 / 127.0 => pot[1]; 1 => newPots; } else if (msg.data2 == 4) { msg.data3 / 127.0 => pot[2]; 1 => newPots; } else if (msg.data2 == 11) { msg.data3 / 127.0 => pot[3]; 1 => newPots; } else if (msg.data2 == 44) { msg.data3 / 127.0 => pot[4]; 1 => newPots; } else if (msg.data2 > 63 & msg.data2 < 69) { msg.data3/127 => valves[msg.data2-64]; } else if (msg.data2 == 7) { 1.0 -(msg.data3/127.0) => JACKval; } else if (msg.data2 == 12) { 1.0 -(msg.data3/127.0) => FSRval; } else if (msg.data2 == 8) { 1.0 - (msg.data3 / 127.0) => tilts[1]; 1 => newTilt; } else if (msg.data2 == 10) { msg.data3 / 127.0 => tilts[0]; 1 => newTilt; } else { <<< "Unknown MIDI:", msg.data1, msg.data2, msg.data3 >>>; } } else if (msg.data1 == 153) { ; } // ignore drum noteOn else if (msg.data1 == 137) { ; } // ignore drum noteOff else if (msg.data1 == 192) { ; } // ignore program change else { <<< "Unknown MIDI:", msg.data1, msg.data2, msg.data3 >>>; } } } } fun void updateMAUI() { while (notDone) { 0.1 :: second => now; if (gotMIDI) { 0 => gotMIDI; if (newTilt == 1) { (275+tilts[0]*100,35 + tilts[1]*90) => tiltButt.position; 0 => newTilt; } tilts[0] => tiltSlider[0].value; tilts[1] => tiltSlider[1].value; if (newPots == 1) { for (0=>int i; i<5; i++) pot[i] => pots[i].value; 0 => newPots; } FSRval => FSR.value; JACKval => JACK.value; for (0=>int i; i<5; i++) valves[i] => butts[i].state; } else { // Got No MIDI? Then Feed MAUI Widget Values Into Global Variables if (tiltButt.state() == 1) { 0.5 => tiltSlider[0].value; 0.5 => tiltSlider[1].value; 0 => tiltButt.state; } tiltSlider[0].value() => tilts[0]; tiltSlider[1].value() => tilts[1]; (235+tilts[0]*100,35 + tilts[1]*90) => tiltButt.position; pots[0].value() => pot[0]; pots[1].value() => pot[1]; pots[2].value() => pot[2]; pots[3].value() => pot[3]; FSR.value() => FSRval; butts[0].state() => valves[0]; butts[1].state() => valves[1]; butts[2].state() => valves[2]; butts[3].state() => valves[3]; } if (midiLabel.state()) { if (flashMIDI) midiStatus.unlight(); else midiStatus.light(); } else midiStatus.light(); } } fun void doGUI() { myWinder.name("PICOBox Dashboard"); myWinder.size(470,350); for (0 => int i; i < 5; 1 +=> i) { butts[i].size(65,65); butts[i].position(0,i * 47); butts[i].toggleType(); pots[i].range(0,1.0); pots[i].size(230,60);pots[i].position(40,47*i); pots[i].precision(2); pots[i].name("Pot "+Std.itoa(i+1)); butts[i].name(Std.itoa(i+1)); myWinder.addElement(butts[i]); myWinder.addElement(pots[i]); } FSR.name("FSR");FSR.range(0.0,1.0); FSR.size(260.0,60.0); FSR.precision(2);FSR.position(0,250); myWinder.addElement(FSR); JACK.name("JACK");JACK.range(0.0,1.0); JACK.size(260.0,60.0); JACK.precision(2);JACK.position(0,290); myWinder.addElement(JACK); tiltButt.name("tilt"); tiltButt.size(61,61); tiltButt.position(320,75); MAUI_Button tiltBorders[2]; for (0 => int i; i < 2; 1 +=> i) { tiltSlider[i].range(0.0,1.0); tiltSlider[i].precision(2); tiltSlider[i].size(195.0,60.0); tiltSlider[i].position(258,i*155); tiltSlider[i].value(0.5); tiltBorders[i].size(42,170); tiltBorders[i].toggleType(); tiltBorders[i].state(1); tiltBorders[i].position(250 + i*170,30); myWinder.addElement(tiltSlider[i]); myWinder.addElement(tiltBorders[i]); } tiltSlider[0].name(" X Tilt"); tiltSlider[1].name(" Y Tilt"); exit.name("Exit"); exit.size(100,70); exit.position(360,280); exit.toggleType(); myWinder.addElement(exit); myWinder.addElement(tiltButt); myWinder.display(); midiLabel.position(250,285);midiLabel.size(85,65);midiLabel.name("MIDI"); midiLabel.toggleType(); midiLabel.state(1); midiStatus.position(305,285); myWinder.addElement(midiLabel);myWinder.addElement(midiStatus); } fun void setupMIDI() { /* MIDI STUFF IS HERE */ 0 => int device; // device# to open (see: chuck --probe) if( !min.open( device ) ) { // me.exit(); // open the device <<< "Can't Open MIDI...", "Using MAUI-Only Mode" >>>; midiStatus.color(3); } else { midiStatus.color(1); } midiStatus.light(); }