hekeus@6: #include "melodyTriangle.h" hekeus@6: #include hekeus@6: hekeus@6: /* hekeus@6: /birth id hekeus@6: /death id hekeus@6: /start id hekeus@6: /stop id hekeus@6: /track id x y left right top bottom area hekeus@6: /tempo hekeus@6: hekeus@6: hekeus@6: */ hekeus@6: melodyTriangle::melodyTriangle(const char *host, int port, int numVoices, bool enableKeys,int voiceIdOffset){ hekeus@6: printf("in constructor: %s %i %i %i\n",host,port,numVoices,enableKeys); hekeus@6: this->numVoices=numVoices; hekeus@6: this->enableKeys=enableKeys; hekeus@6: this->voiceIdOffset=voiceIdOffset; hekeus@6: //voices=*Voice[numVoices]; hekeus@6: sender.setup( host,port ); hekeus@6: } hekeus@6: hekeus@6: //-------------------------------------------------------------- hekeus@6: void melodyTriangle::setup(){ hekeus@6: //voices = new Voice[NUMVOICES]; hekeus@6: hekeus@6: ofSetCircleResolution(100); hekeus@6: ofBackground(0,0,0); hekeus@6: ofSetWindowTitle("Melody Triangle"); hekeus@6: triangleHeight=ofGetHeight()*0.75; hekeus@6: ofSetFrameRate(40); // if vertical sync is off, we can go a bit fast... this caps the framerate at 60fps. hekeus@6: ofEnableSmoothing(); hekeus@6: x1=ofGetWidth()/2; hekeus@6: y1=(ofGetHeight()-triangleHeight)/2; hekeus@6: x2=ofGetWidth()/2-triangleHeight/sqrt(3); hekeus@6: y2=ofGetHeight()-(ofGetHeight()-triangleHeight)/2; hekeus@6: x3=ofGetWidth()/2+triangleHeight/sqrt(3); hekeus@6: y3=y2; hekeus@6: hekeus@6: ofxOscMessage m; hekeus@6: m.setAddress( "/calibrate" ); hekeus@6: m.addIntArg( x1 ); hekeus@6: m.addIntArg( y1 ); hekeus@6: m.addIntArg( x2 ); hekeus@6: m.addIntArg( y2 ); hekeus@6: m.addIntArg( x3 ); hekeus@6: m.addIntArg( y3 ); hekeus@6: sender.sendMessage( m ); hekeus@6: printf("sent /calibrate %i %i %i %i %i %i\n",x1,y1,x2,y2,x3,y3); hekeus@6: hekeus@6: for (int i=0;ix2 && xy1 && y (*voices[voiceGrabbed]).radius*2){ hekeus@6: hekeus@7: hekeus@6: ofxOscMessage m; hekeus@6: ///track id x y left right top bottom area hekeus@6: m.setAddress( "/death" ); hekeus@6: m.addIntArg( (*voices[voiceGrabbed]).id ); hekeus@6: sender.sendMessage( m ); hekeus@6: hekeus@6: printf("sent /death %i \n",(*voices[voiceGrabbed]).id); hekeus@6: (*voices[voiceGrabbed]).posx=mouseX; hekeus@6: (*voices[voiceGrabbed]).posy=mouseY; hekeus@6: hekeus@6: } else { hekeus@6: //printf("e"); hekeus@6: //On Edge hekeus@6: } hekeus@6: hekeus@6: }else{ hekeus@6: (*voices[voiceGrabbed]).posx=mouseX; hekeus@6: (*voices[voiceGrabbed]).posy=mouseY; hekeus@6: //(*voices[voiceGrabbed]).posx=(*voices[voiceGrabbed]).posx*0.9+mouseX*0.1; hekeus@6: //(*voices[voiceGrabbed]).posy=(*voices[voiceGrabbed]).posy*0.9+mouseY*0.1; hekeus@6: hekeus@6: hekeus@6: } hekeus@6: if (!(*voices[voiceGrabbed]).inTriangle && isInTriangle(mouseX,mouseY)){ hekeus@6: //birth id hekeus@6: hekeus@6: ofxOscMessage m; hekeus@6: ///track id x y left right top bottom area hekeus@6: m.setAddress( "/birth" ); hekeus@6: m.addIntArg( (*voices[voiceGrabbed]).id ); hekeus@6: sender.sendMessage( m ); hekeus@6: hekeus@6: printf("sent /birth %i \n",(*voices[voiceGrabbed]).id); hekeus@6: sendStart=true; hekeus@6: } hekeus@6: hekeus@6: hekeus@6: //(*voices[voiceGrabbed]).inTriangle = isInTriangle(mouseX,mouseY); hekeus@6: hekeus@6: (*voices[voiceGrabbed]).inTriangle = isInTriangle((*voices[voiceGrabbed]).posx,(*voices[voiceGrabbed]).posy); hekeus@6: hekeus@6: if ((*voices[voiceGrabbed]).inTriangle){ hekeus@6: sendStatus(*voices[voiceGrabbed]); hekeus@6: if (sendStart){ hekeus@6: if ((*voices[voiceGrabbed]).isActive){ hekeus@6: ofxOscMessage m; hekeus@6: ///track id x y left right top bottom area hekeus@6: m.setAddress( "/start" ); hekeus@6: m.addIntArg( (*voices[voiceGrabbed]).id ); hekeus@6: sender.sendMessage( m ); hekeus@6: printf("sent /start %i \n",(*voices[voiceGrabbed]).id); hekeus@6: } hekeus@6: } hekeus@6: } hekeus@6: hekeus@6: } hekeus@6: }; hekeus@6: for (int i=0; i