//MUST CREATE FONT: "ArialMT-48.vlw" FOR THIS TO RUN!!!! /* Serial Codes: Inside Play Mode: [startbit, finger, sound, velocity] Inside Menu Mode: [startbit, finger, sound, 0] UNLOCK: [startbit, finger, UNLOCK, 0] LOCK: [startbit, finger, LOCK, 0] Transfer Play Mode: [startbit, PLAY, 0, 0] Transfer Menu Mode: [startbit, MENU, 0, 0] Serial Codes: Inside Play Mode: [200, 0-9, 0-50, 0-127] Inside Menu Mode: [200, 0-9, 0-50, 0 ] UNLOCK: [200, 0-9, 210, 0] LOCK: [200, 0-9, 211, 0] Transfer Play Mode: [200, 220, 0, 0] Transfer Menu Mode: [200, 221, 0, 0] */ import processing.serial.*; Serial myPort; // The serial port Finger[] f= new Finger[10]; PFont font; Smsg serialmsg; //Control Variables int initial=-1; boolean waiting; int count=0; //Global Variables boolean Play; //true if in Play mode false if in Menu mode int startbit=200; int playmsg=220; int menumsg=221; void setup() { size(900,750); background(0); smooth(); initializeRUN(); } void draw() { background(0); readPORT(); renderLHAND(); renderRHAND(); renderscreen(); } /////////////////////////////////////////PAGE2 void readPORT() { int code; if (myPort.available() > 0) { code = myPort.read(); if(code == startbit) { count=0;} else if(count==0) { serialmsg.setMSG(0,code); count=1;} else if(count==1) { serialmsg.setMSG(1,code); count=2;} else if(count==2) { serialmsg.setMSG(2,code); evalmsg(serialmsg);} } } ///////////////////////////////////////////PAGE 3 /* This page has 3 code sections: 1. functions that intialize the program 2. functions that evalute the incoming serial message 3. functions that render to the screen */ /////////////////////////////////////////////////////////////////////// //INITIALIZE FUNCTIONS /////////////////////////////////////////////////////////////////////// void initializeRUN() { //LOAD font font = loadFont("ArialMT-48.vlw"); textFont(font, 12); //INITIALIZE Fingers initializeF(); //INITIALIZE Variables serialmsg= new Smsg(0,0,0); Play=true; //INITIALIZE serial println(Serial.list()); myPort = new Serial(this, Serial.list()[0], 19200); //initialize getting to punctuation bit while(initial != startbit) { if (myPort.available() > 0) { initial = myPort.read(); println(initial); } } waiting = false; count=0; }//END initializeRUN() void initializeF() { int sp=60; //LEFT hand /*pointer*/ f[5]= new Finger(1,100 + 4*sp, 100, 10, 0, true); /*middle*/ f[6]= new Finger(2,100 + 3*sp, 100, 12, 0, true); /*ring*/ f[7]= new Finger(3,100 + 2*sp, 100, 16, 0, true); /*pinky*/ f[8]= new Finger(4,100 + sp, 100, 19, 0, true); /*thumb*/ f[9]= new Finger(0,100 + 5*sp, 100,0, 0, true); //RIGHT hand /*pointer*/ f[0]= new Finger(1,450 + 2*sp, 100, 10, 0, true); /*middle*/ f[1]= new Finger(2,450 + 3*sp, 100, 12, 0, true); /*ring*/ f[2]= new Finger(3,450 + 4*sp, 100, 16, 0, true); /*pinky*/ f[3]= new Finger(4,450 + 5*sp, 100, 19, 0, true); /*thumb*/ f[4]= new Finger(0,450 + sp, 100, 0, 0, true); }//END initializeF() /////////////////////////////////////////////////////////////////////// //EVALUATE FUNCTIONS /////////////////////////////////////////////////////////////////////// void evalmsg(Smsg SEmsg) { int[] msg= new int[3]; //parse message apart here, assume its an array msg[0]=SEmsg.getMSG(0); msg[1]=SEmsg.getMSG(1); msg[2]=SEmsg.getMSG(2); //evaluate hit codes if(msg[0] >-1 && msg[0] <13) { if(msg[0]>=5)//corrects for the fact one hand is 8-12 { msg[0]=msg[0]-3; } if(Play) { f[msg[0]].setVELOCITY(2*msg[2]); } else if(Play==false && (msg[1]==210 || msg[1]==211) )//unlock { f[msg[0]].setLOCKED(!f[msg[0]].getLOCKED()); } else //menu mode { if(f[msg[0]].getLOCKED()==false) { f[msg[0]].setSOUND((f[msg[0]].getSOUND()+1)%35); } else { f[msg[0]].setVELOCITY(100); } } } //switch to play if(msg[0] == playmsg) { Play=true; lockF(); } //switch to menu if(msg[0] == menumsg) { Play=false; } }//END evalmsg() void lockF() { for(int i=0; i < f.length; i++) { f[i].setLOCKED(true); } }//END lockF() //////////////////////////////////////////////////////////////////////////// //RENDER FUNCTIONS //////////////////////////////////////////////////////////////////////////// void renderscreen() { renderFingers(); renderMode(); resetFvel(); }//END renderscreen() void renderFingers() { for(int i=0; i < f.length; i++) { f[i].render(); } }//END renderFingers() void renderMode() { textSize(24); if(Play) { text("PLAY",20,40); } else { text("MENU",20,40); } textSize(14); }//END renderMode() void resetFvel() { for(int i=0; i < f.length; i++) { if(f[i].getVELOCITY() > 0) { f[i].setVELOCITY(f[i].getVELOCITY()-1); } } }//END resetFvel() void renderLHAND() { int sp=30; noStroke(); fill(100); for(int i=0; i<4; i++) { rect(150+2*i*sp,200,sp,100); } rect(150,300,2*4*sp-sp,220); rect(150,350,270,40); } void renderRHAND() { int sp=30; noStroke(); fill(100); for(int i=0; i<4; i++) { rect(550+2*i*sp,200,sp,100); } rect(550,300,2*4*sp-sp,220); rect(550,350,-70,40); } ///////////////////////////////////////////////////PAGE 4 class Finger { float x, y; int sound; float velocity; boolean locked; String[] sounds= new String[35]; int Theight; Finger(int Theight_, float x_, float y_, int sound_, float velocity_, boolean locked_) { Theight=Theight_; x=x_; y=y_; sound=sound_; velocity=velocity_; locked=locked_; sounds[0]="Real Kick"; sounds[1]="Side Kick"; sounds[2]="Hard Snare"; sounds[3]="Drum Sticks Together"; sounds[4]="Kick Drum"; sounds[5]="Hard Sharp Drum"; sounds[6]="Acoustic Bass Drum"; sounds[7]="Bass Drum 1"; sounds[8]="Side Stick"; sounds[9]="Acoustic Snare"; sounds[10]="Electric Snare"; sounds[11]="Low Floor Tom"; sounds[12]="Closed Hi-Hat"; sounds[13]="High Floor Tom"; sounds[14]="Pedal Hi-Hat"; sounds[15]="Low Tom"; sounds[16]="Open Hi-Hat"; sounds[17]="Low-Mid Tom"; sounds[18]="Hi-Mid Tom"; sounds[19]="Crash Cymbal 1"; sounds[20]="High Tom"; sounds[21]="Ride Cymbal 1"; sounds[22]="Ride Bell"; sounds[23]="Tambourine"; sounds[24]="Splash Cymbal"; sounds[25]="Cowbell"; sounds[26]="Crash Cymbal 2"; sounds[27]="Ride Cymbal 2"; sounds[28]="Hi Bongo"; sounds[29]="Low Bongo"; sounds[30]="Mute Hi Conga"; sounds[31]="Open Hi Conga"; sounds[32]="Low Conga"; sounds[33]="High Timbale"; sounds[34]="Low Timbale"; }//END Finger int getSOUND() {return sound;} void setSOUND(int sound_) {sound = sound_;} float getVELOCITY() {return velocity;} void setVELOCITY(float v_) {velocity=v_;} boolean getLOCKED() {return locked;} void setLOCKED(boolean l_) {locked=l_;} void render() { noStroke(); fill(255-velocity); ellipse(x,y,10+velocity/10,10+velocity/10); if(!Play) { text(sounds[sound], x, y-12-Theight*12); } if(locked==false) { for(int i=0; i