//---------------------------------------------------------------------------- // name: wekinator-outputs.ck // desc: demonstrates receiving Wekinator outputs over OSC // * listens for OSC message "/wek/output" // * prints out each message typetag and numArgs as it arrives // * NOTE: msg.numArgs() is the number of output dimension // * NOTE: this code can be modified to control synthesis //---------------------------------------------------------------------------- SndBuf hihat => dac; SndBuf kick => dac; SndBuf clap => dac; //SndBuf shh => dac; 0 => int playing_kick; 0 => int playing_hihat; 0 => int playing_clap; 1::second => now; fun void play_kick() { 1 => playing_kick; "/Users/grantbishko/Music/Music/Media.localized/Music/Unknown Artist/Unknown Album/kick.wav" => kick.read; 500::ms => now; 0 => playing_kick; } fun void play_hihat() { 1 => playing_hihat; "/Users/grantbishko/Music/Music/Media.localized/Music/Unknown Artist/Unknown Album/hihat-open.wav" => hihat.read; 500::ms => now; 0 => playing_hihat; } fun void play_clap() { 1 => playing_clap; "/Users/grantbishko/Music/Music/Media.localized/Music/Unknown Artist/Unknown Album/clap.wav" => clap.read; 500::ms => now; 0 => playing_clap; } // create our OSC receiver OscIn oin; // create our OSC message OscMsg msg; // use port 12000 (default Wekinator output port) 12000 => oin.port; // create an address in the receiver, expect an int and a float oin.addAddress( "/wek/outputs" ); // print cherr <= "listening for \"/wek/outputs\" messages on port " <= oin.port() <= "..." <= IO.newline(); // infinite event loop while( true ) { // wait for event to arrive oin => now; // grab the next message from the queue. while( oin.recv(msg) ) { // print stuff cherr <= "received OSC message: \"" <= msg.address <= "\" " <= "typetag: \"" <= msg.typetag <= "\" " <= "arguments: " <= msg.numArgs() <= IO.newline(); msg.getFloat(0) => float gesture; <<< gesture >>>; if (gesture == 1 && playing_kick == 0) { spork ~ play_kick(); } else if (gesture == 2 && playing_hihat == 0) { spork ~ play_hihat(); } else if (gesture == 3 && playing_clap == 0) { spork ~ play_clap(); } else if (gesture == 4) { //spork ~ play_shh(); } // done with line cherr <= IO.newline(); } }