Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Voice and Visual Commands to move chairs in a space
import processing.serial.*;
import arb.soundcipher.*;
SoundCipher sc = new SoundCipher(this);
Serial myPort;
Box[] bx;
int currentbox=0;
int size = 190;
float gap = 350;
int numberofboxes = 4;
float[] pitches = {20, 40, 20, 40, 60};
int avgclr;
float volume = 120;
void setup(){
sc.instrument = 0;
//setup emic2
String portName[] = Serial.list();
if (portName == null) {
println("Failed to retrieve the list of available serial devices...");
} if (portName.length == 0) {
println("There are no serial ports currently available.");
exit();
} else {
println("Available serial devices:");
for (int i = 0; i < portName.length; i++) {
println(portName[i]);
}
}
//myPort = new Serial(this, "COM10", 9600);
// myPort = new Serial(this, portName[6], 9600);
//doCommand("R"); // Reset at the outset
//doCommand("P0"); // Put Emic 2 into DecTalk mode
//doCommand("W200");
//doCommand("N3");
//setup canvas
fill(255);
size ( displayWidth, displayHeight);
sketchFullScreen();
noStroke();
float xpositions = width/2 - ((((size*numberofboxes)+(gap*(numberofboxes-1)))/4) + gap/2 );
float ypositions = height/2-size/2;
bx = new Box[numberofboxes];
for(int i=0;i<=(numberofboxes-1);i++){
bx[i] = new Box(xpositions,ypositions,25);
xpositions = xpositions + gap;
//setup sound
}
}
class Box{
float x,y;
int state = 0;
int fil = 255;
Box(float xpos, float ypos,int fl){
x = xpos;
y = ypos;
fil = fl;
}
void display(){
fill(fil);
rect(x,y,size,size);
}
void moveup(){
float oldy;
oldy = this.y;
this.y = oldy - size;
}
void movedown(){
float oldy;
oldy = this.y;
this.y = oldy + size;
}
}
void draw(){
background(avgclr,avgclr+volume/2,volume);
textSize(120);
fill(255,255,255,volume*2);
text((currentbox+1),width/2-60,height/2-170);
textSize(60);
text( int(bx[currentbox].y),width/2,height/2-120);
/*stroke(125);
for(int i=0,dist=100;i<=height/size;i++){
line(0,dist, width, dist);
text(dist/10,5,dist);
dist=dist+size;
}
line(0,height/2,width,height/2);
line(width/2,0,width/2,height);
stroke(125);
*/
bx[currentbox].display();
for(int i=0;i<=(numberofboxes-1);i++){
//bx[currentbox].display();
//bx[i].fil=255;
pitches[i]=bx[i].y/8;
//println(i);
//println(bx[i].x);
avgclr = (avgclr+int(bx[i].y))/2+60;
//delay(100);
}
bx[currentbox].fil=255;
sc.playChord(pitches, volume, 4*bx[currentbox].y/10);
volume = volume - 0.25;
avgclr=avgclr/5;
//background(volume,avgclr/2,avgclr/4*volume);
}
void refresh()
{ int reply;
while (true){
reply = myPort.read();
if (reply != -1) {
println((char)reply);
if (reply == ':') break;
}
}
}
void keyPressed() {
switch(keyCode) {
case UP:
bx[currentbox].moveup();
//bx[currentbox].display();
println(currentbox+1);
println("up");
println(bx[currentbox].y/10);
//myPort.write("S"+ "[:rate 180][:dv sm 40][:dv qu 200][:dv hr 60][:dv pr 90]"+ "Move Chair" + (currentbox+1) + "up to[:comma 2]" + int(bx[currentbox].y/10) +".\n");
volume = 120 - currentbox*3;
break;
case DOWN:
bx[currentbox].movedown();
//bx[currentbox].display();
println(currentbox+1);
println("down");
println(bx[currentbox].y/100);
//myPort.write("S"+ "[:rate 200][:dv sm 40][:dv qu 200][:dv hr 60][:dv pr 75]" + "Move Chair"+ (currentbox+1) + "down to" + int(bx[currentbox].y/10) +".\n");
volume = 120 - currentbox*3;
break;
case RIGHT:
if(currentbox<(numberofboxes-1)){
currentbox=currentbox+1;
//bx[currentbox].display();
}
else {
currentbox = 0 ;
//bx[currentbox].display();
}
println("Box"+(currentbox+1));
//myPort.write("S"+ "[:rate 200][:dv sm 40][:dv qu 200][:dv hr 50][:dv pr 75]"+ "Chair"+ (currentbox+1) + ".\n");
// noLoop();
//for(int i=0;i<numberofboxes;i++){
//sc.playNote(bx[i].y/5,120,20);
//delay(320);
//}
//loop();
volume = 120 - currentbox*3;
break;
case LEFT:
if(currentbox>0){
currentbox=currentbox-1;
//bx[currentbox].display();
}
else {
currentbox = numberofboxes-1;
//bx[currentbox].display();
}
println("Box"+(currentbox+1));
//myPort.write("S"+"[:rate 200][:dv sm 40][:dv qu 200][:dv hr 60][:dv pr 75]"+ "Chair"+ (currentbox+1) + ".\n");
volume = 120 - currentbox*3;
break;
case TAB:
for(int i=0;i<numberofboxes;i++){
sc.playNote(bx[i].y/8,120,20);
delay(220);
break;
}
}
delay(220);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment