hekeus@6: #include "melodyTriangle.h" hekeus@6: #include hekeus@6: samer@10: #define BUFFER_ZONE 50 // have to drag this far to snap out of triange. 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@8: melodyTriangle::melodyTriangle(const char *host, int port, int numVoices, bool enableKeys,int voiceIdOffset,int receivePort){ hekeus@8: printf("in constructor: %s %i %i %i %i %i\n",host,port,numVoices,enableKeys,voiceIdOffset,receivePort); 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@8: receiver.setup( receivePort ); hekeus@8: 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: samer@12: sendCalibrate(); samer@12: for (int i=0;ix2 && xy1 && y BUFFER_ZONE) { hekeus@6: hekeus@7: samer@10: ofxOscMessage m; samer@10: ///track id x y left right top bottom area samer@10: m.setAddress( "/death" ); samer@10: m.addIntArg( (*voices[voiceGrabbed]).id ); samer@10: sender.sendMessage( m ); hekeus@6: samer@10: printf("sent /death %i \n",(*voices[voiceGrabbed]).id); samer@10: (*voices[voiceGrabbed]).posx=mouseX; samer@10: (*voices[voiceGrabbed]).posy=mouseY; hekeus@6: } else { hekeus@6: //printf("e"); hekeus@6: //On Edge samer@10: constrained=true; 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: }; samer@10: samer@10: //let's draw our triangle samer@11: ofSetLineWidth(2); samer@12: ofSetColor(96,96,96); samer@10: ofFill(); samer@10: ofTriangle(x1, y1, x2, y2, x3, y3); samer@12: if (constrained) ofSetColor(255,96,96); samer@10: samer@10: // draw smooth edge, brighter if a token is constrained samer@10: ofNoFill(); samer@10: ofTriangle(x1, y1, x2, y2, x3, y3); samer@10: hekeus@6: for (int i=0; iisInVoice(mouseX,mouseY)){ samer@12: Voice *v=voices[i]; samer@12: switch (key) { samer@12: case 'a': { samer@12: ofxOscMessage m; samer@12: const char *addr = v->isActive ? "/stop" : "/start"; samer@12: v->isActive=!v->isActive; samer@12: m.setAddress(addr); samer@12: m.addIntArg(v->id ); samer@12: sender.sendMessage( m ); samer@12: printf("sent %s %i \n",addr,v->id); samer@12: break; samer@12: } samer@12: case OF_KEY_LEFT: sendShift(v->id,-1,2); break; samer@12: case OF_KEY_RIGHT: sendShift(v->id,1,2); break; samer@12: case OF_KEY_UP: sendPeriod(v->id,1,2); break; samer@12: case OF_KEY_DOWN: sendPeriod(v->id,2,1); break; samer@12: case '.': sendPeriod(v->id,1,3); break; samer@12: case ',': sendPeriod(v->id,3,1); break; samer@12: case '+': sendOctave(v->id, ++v->octave); break; samer@12: case '-': sendOctave(v->id, --v->octave); break; samer@13: case '*': sendAmplitude(v->id, v->louder()); break; samer@13: case '/': sendAmplitude(v->id, v->quieter()); break; samer@13: default: printf("unrecognised key: %d.\n",key); samer@12: } hekeus@6: } hekeus@6: } hekeus@6: } hekeus@6: } hekeus@6: } hekeus@6: } hekeus@6: hekeus@6: //-------------------------------------------------------------- hekeus@6: void melodyTriangle::keyReleased (int key){ hekeus@6: hekeus@6: } hekeus@6: hekeus@6: //-------------------------------------------------------------- hekeus@6: void melodyTriangle::mouseMoved(int x, int y ){ hekeus@6: for (int i=0; i