Created
February 18, 2017 16:23
-
-
Save genekogan/d5525fe4c02f7391d69499ad6c0d5e2e to your computer and use it in GitHub Desktop.
wekinator + processing + sound
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import netP5.*; | |
import oscP5.*; | |
import processing.sound.*; | |
OscP5 oscP5; | |
NetAddress myRemoteLocation; | |
SoundFile s1, s2, s3, s4; | |
boolean sending; | |
float prediction; | |
void setup() { | |
size(500, 500); | |
oscP5 = new OscP5(this,12000); | |
myRemoteLocation = new NetAddress("127.0.0.1",6448); | |
s1 = new SoundFile(this, "sound1.wav"); | |
s2 = new SoundFile(this, "sound2.wav"); | |
s3 = new SoundFile(this, "sound3.wav"); | |
s4 = new SoundFile(this, "sound4.wav"); | |
} | |
void sendMessage() { | |
OscMessage myMessage = new OscMessage("/wek/inputs"); | |
myMessage.add(float(mouseX)); | |
myMessage.add(float(mouseY)); | |
oscP5.send(myMessage, myRemoteLocation); | |
} | |
void draw() { | |
background(0); | |
if (prediction == 1.0) { | |
fill(255); | |
} else if (prediction == 2.0) { | |
fill(0, 255, 0); | |
} else if (prediction == 3.0) { | |
fill(255, 0, 0); | |
} else if (prediction == 4.0) { | |
fill(0, 0, 255); | |
} | |
ellipse(mouseX, mouseY, 50, 50); | |
if (sending) { | |
fill(255, 0, 0); | |
ellipse(10, 10, 10, 10); | |
sendMessage(); | |
} | |
} | |
void oscEvent(OscMessage theOscMessage) { | |
if (theOscMessage.addrPattern().equals("/wek/outputs")) { | |
float newPrediction = theOscMessage.get(0).floatValue(); | |
if (newPrediction != prediction) { | |
s1.stop(); | |
s2.stop(); | |
s3.stop(); | |
s4.stop(); | |
prediction = newPrediction; | |
if (prediction == 1.0) {s1.loop();} | |
if (prediction == 2.0) {s2.loop();} | |
if (prediction == 3.0) {s3.loop();} | |
if (prediction == 4.0) {s4.loop();} | |
} | |
} | |
} | |
void keyPressed() { | |
if (key==' ') { | |
sending = !sending; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment