Adrian's Chuck Code.ck

From CSWiki
Revision as of 00:43, 9 May 2009 by Adrian.kwok (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

// Adrian Kwok // MUS 314 Final Project // OSC code is borrowed with permission from examples by // Rebecca Fiebrink and Dan Trueman 5503 => int oscToProcessingPort; 5504 => int oscFromProcessingPort; int instrument; StkInstrument lower; StkInstrument middle; StkInstrument higher; Clarinet cl; Clarinet cm; Clarinet ch; Flute fl; Flute fm; Flute fh; fl @=> lower; fm @=> middle; fh @=> higher; OscSend osc_to_processing; osc_to_processing.setHost("localhost", oscToProcessingPort); spork ~ buttonMsgFromGui(); spork ~ instrumentMsgFromGui(); 1::day => now; // anything that needs a frequency change fun void buttonMsgFromGui() { // this comes from the GUI OscRecv recv; oscFromProcessingPort => recv.port; recv.listen(); recv.event("/guioscdemo/button, i") @=> OscEvent oe; while (true) { oe => now; while (oe.nextMsg() !=0) { oe.getInt() => int which; <<<"yay, got messages from GUI! ", which>>>; if (instrument == 1) { which / 80 + 4 => lower.freq; which / 102 + 180 => middle.freq; which / 120 + 276 => higher.freq; } else { which / 80 + 204 => lower.freq; which / 102 + 380 => middle.freq; which / 120 + 476 => higher.freq; } } } } // instrument change fun void instrumentMsgFromGui() { // this comes from the GUI OscRecv recv; oscFromProcessingPort => recv.port; recv.listen(); recv.event("/guioscdemo/instrument, i") @=> OscEvent oe; while (true) { oe => now; while (oe.nextMsg() !=0) { oe.getInt() => int which; <<<"yay, got messages from GUI! ", which>>>; if (which == 1) { 1 => instrument; lower =< dac; middle =< dac; higher =< dac; cl @=> lower; cm @=> middle; ch @=> higher; lower => dac; middle => dac; higher => dac; 1 => lower.noteOn; 1 => middle.noteOn; 1 => higher.noteOn; } else if (which == 2) { 2 => instrument; lower =< dac; middle =< dac; higher =< dac; fl @=> lower; fm @=> middle; fh @=> higher; lower => dac; middle => dac; higher => dac; 1 => lower.noteOn; 1 => middle.noteOn; 1 => higher.noteOn; } } } }