Mercurial > hg > movesynth
changeset 47:26547e2847cd
added control change data stream from the left and right hands, sent to the max patch, added faces with three masks, better info in user window
author | Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk> |
---|---|
date | Fri, 04 Mar 2011 19:04:14 +0000 |
parents | fac6468026a1 |
children | f33398343f18 |
files | of/testApp.cpp |
diffstat | 1 files changed, 170 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/of/testApp.cpp Fri Mar 04 13:57:39 2011 +0000 +++ b/of/testApp.cpp Fri Mar 04 19:04:14 2011 +0000 @@ -26,11 +26,13 @@ typeOfFaceToUse[y] = y%2; } - anubis.loadImage("images/anubis-wall-mask.gif"); + anubis.loadImage("images/mask1.png");//anubis-wall-mask.gif + secondUserImage.loadImage("images/mask2.png");//davy2.jpg" + thirdUserImage.loadImage("images/mask3.png");//mubrarksign.jpg franklinBook.loadFont("frabk.ttf", 32); - sender.setup( HOST, PORT ); +// sender.setup( HOST, PORT ); stopSender.setup( STOPHOST, STOPPORT ); heresySender.setup(HERESY_HOST, HERESY_PORT); @@ -41,6 +43,9 @@ double timeNow = ofGetElapsedTimeMillis(); for (int user = 0;user < NUMBER_OF_USERS;user++) lastRecordedTime[user] = timeNow; + + leftMaximum[0] = 700; + } //-------------------------------------------------------------- @@ -99,7 +104,7 @@ ofSetColor(0x00FF00); outputString = "HeadX : "; outputString += ofToString(torso[0][0]); - franklinBook.drawString(outputString, 100,600); + //franklinBook.drawString(outputString, 100,600); } @@ -108,10 +113,21 @@ if (torso[id][h] > maxTorsoValues[h]) maxTorsoValues[h] = torso[id][h]; } + + for (int h = 0; h < 3;h++){ + if (leftHandPosition[id][h] > leftMaximum[h]) + leftMaximum[h] = leftHandPosition[id][h]; + } + + for (int h = 0; h < 3;h++){ + if (rightHandPosition[id][h] > rightMaximum[h]) + rightMaximum[h] = rightHandPosition[id][h]; + } + } void testApp::sendDataViaOSC(int userID){ - +/* ofxOscMessage m; m.setAddress( "/person" ); m.addIntArg( userID ); @@ -119,7 +135,7 @@ m.addFloatArg( torso[userID][1] /maxTorsoValues[1]); m.addFloatArg( torso[userID][2] /maxTorsoValues[2]); sender.sendMessage( m ); - +*/ } void testApp::sendStopMessageForUser(int userID){ @@ -131,11 +147,12 @@ m.addFloatArg( torso[userID][2] /maxTorsoValues[2]); stopSender.sendMessage( m ); - + /* ofxOscMessage newMess; newMess.setAddress( "/stopperson" ); newMess.addIntArg( userID ); sender.sendMessage( newMess ); +*/ } @@ -149,37 +166,94 @@ else pitch = 15; - double leftHand, rightHand; - leftHand = leftHandPosition[userID][2]/maxTorsoValues[2];//i.e. z position but 0 to 1 - rightHand = rightHandPosition[userID][2]/maxTorsoValues[2];//same for right + - if (userID == 0){ + if (userID < 3){ + double leftHand, rightHand, leftHandX, rightHandX, leftHandY, rightHandY; + leftHand = leftHandPosition[userID][0]/leftMaximum[0];//i.e x [position + rightHand = rightHandPosition[userID][0]/rightMaximum[0];//same for right + + + leftHandY = leftHandPosition[userID][1]/leftMaximum[1];//i.e. x position but 0 to 1 + rightHandY = rightHandPosition[userID][1]/rightMaximum[1];//same for right + + //THIS IS THE ONLY ROUTINE CALLED //i.e. monophonic + // int controlChangeLeft[3][4];//userId, leftX, leftR, rightX, right Y + //need to send continuous control change not just when note changes + int controlChangeLeft = (int) min((double)127,max((double)0,(leftHand*127))); + int controlChangeRight = (int) min((double)127,max((double)0,(rightHand*127))); + + int controlChangeLeftY = (int)((double)127 - min((double)127,max((double)0,(leftHandY*127)))); + int controlChangeRightY = (int)((double)127 - min((double)127,max((double)0,(rightHandY*127)))); + + ControlChangeData[userID][0] = controlChangeLeft ; + ControlChangeData[userID][1] = controlChangeLeftY ; + ControlChangeData[userID][2] = controlChangeRight ; + ControlChangeData[userID][3] = controlChangeRightY ; + + userInfoString[userID] = "USER "; + userInfoString[userID] += ofToString(userID+1, 0); + userInfoString[userID] += " Pitch "; + userInfoString[userID] += ofToString(pitch, 0); + + userInfoString[userID] += " ccL "; + userInfoString[userID] += ofToString(controlChangeLeft, 0); + userInfoString[userID] += " , "; + userInfoString[userID] += ofToString(controlChangeLeftY, 0); + + userInfoString[userID] += " ccR "; + userInfoString[userID] += ofToString(controlChangeRight, 0); + userInfoString[userID] += " , "; + userInfoString[userID] += ofToString(controlChangeRightY, 0); + + sendControlChangeDataToMax(userID); + if (pitch != pitchPlaying[userID]){ //then we have a change //send note off sendNoteMessageToHeresy(pitchPlaying[userID], 0, 0, userID); + printf("note OFF user %i pitch %i \n ", userID+1, pitchPlaying[userID]); sendNoteMessageToHeresy(pitch, 1, 127, userID);// int channel){ + pitchPlaying[userID] = pitch; - //the send control change for the hands XXX TO DO + //now get send control change for the hands XXX TO DO + /* + leftHand *= 127; + rightHand *= 127; + */ + + // printf("note ON user %i pitch %i \n", userID+1, pitch); } } else{ - //i.e. channel for user 2 and 3 + //NO LONGER CALLED - WE SEND JUST MAIN PITCHES TRIGGERED BY BODY POSITION + //i.e. for was channel for user 2 and 3 + /* double minimum = min(leftHand, rightHand); double maximum = max(leftHand, rightHand); int minPitch = (int) (16 * minimum); int maxPitch = (int) (16 * maximum); minMaxValues[userID][0] = minPitch; minMaxValues[userID][1] = maxPitch; - if (maxPitch > 15) + + if (maxPitch > 15) maxPitch = 15; - printf("user %i min %i max %i\n", userID, minPitch, maxPitch); + userInfoString[userID] = "USER "; + userInfoString[userID] += ofToString(userID+1, 0); + + printf("user %i min %i max %i\n", userID+1, minPitch, maxPitch); + + userInfoString[userID] += "min "; + userInfoString[userID] += ofToString(minPitch, 0); + userInfoString[userID] += "max "; + userInfoString[userID] += ofToString(maxPitch, 0); + for (int p = 0;p < 16;p++){ if (p < minPitch || p > maxPitch){ @@ -194,17 +268,17 @@ if (nowPlaying[userID][p] != lastPlaying[userID][p]){ if (nowPlaying[userID][p]) { - sendNoteMessageToHeresy(p, 1, 127, userID); + //sendNoteMessageToHeresy(p, 1, 127, userID); lastPlaying[userID][p] = true; } else { - sendNoteMessageToHeresy(p, 0, 0, userID); + //sendNoteMessageToHeresy(p, 0, 0, userID); lastPlaying[userID][p] = false; } } - }//edn for - - } + }//end for p + */ + }//end else - not called! @@ -221,6 +295,10 @@ } + + + + void testApp::sendNoteMessageToHeresy(int noteNumber, int onOrOff, int velocity, int channel){ channel++; @@ -237,6 +315,20 @@ } +void testApp::sendControlChangeDataToMax(int userID){ + int channel = userID+1; + + ofxOscMessage m; + m.setAddress( "/controlChangeData" ); + m.addIntArg( channel ); + m.addIntArg( ControlChangeData[userID][0] ); + m.addIntArg( ControlChangeData[userID][1] ); + m.addIntArg( ControlChangeData[userID][2] ); + m.addIntArg( ControlChangeData[userID][3] ); + stopSender.sendMessage( m ); + +} + //-------------------------------------------------------------- void testApp::draw(){ ofBackground(238,238,224); @@ -257,11 +349,11 @@ // draw the neck positions of each user for(int i = 0; i < user.getNumTrackedUsers(); ++i) { + ofxTrackedUser* tracked = user.getTrackedUser(i); + if(tracked != NULL) { - - //andrews code int userID = i; @@ -271,7 +363,7 @@ if (userPresent[userID]){ - sendDataViaOSC(userID); + // sendDataViaOSC(userID); sendInformationToHeresy(userID); ofSetColor(0x000000); @@ -285,18 +377,61 @@ outputString += ofToString(torso[userID][1], 2); outputString += " HeadZ : "; outputString += ofToString(torso[userID][2], 2); + + franklinBook.drawString(outputString, 100,600+userID*160); - franklinBook.drawString(outputString, 100,600+userID*40); + + outputString = "LeftX : "; + outputString += ofToString(leftHandPosition[userID][0], 2); + outputString += " LeftY : "; + outputString += ofToString(leftHandPosition[userID][1], 2); + outputString += " LeftZ : "; + outputString += ofToString(leftHandPosition[userID][2], 2); + + franklinBook.drawString(outputString, 100,640+userID*160); + + outputString = "RightX : "; + outputString += ofToString(rightHandPosition[userID][0], 2); + outputString += " LeftY : "; + outputString += ofToString(rightHandPosition[userID][1], 2); + outputString += " LeftZ : "; + outputString += ofToString(rightHandPosition[userID][2], 2); + + franklinBook.drawString(outputString, 100,680+userID*160); + + outputString = "MaxX: "; + outputString += ofToString(maxTorsoValues[0], 2); + outputString += " MaxY: "; + outputString += ofToString(maxTorsoValues[1], 2); + outputString += " MaxZ: "; + outputString += ofToString(maxTorsoValues[2], 2); + + + franklinBook.drawString(outputString, 100,720+userID*160); + ofSetColor(0,0,255); ofCircle(tracked->neck.begin.x, tracked->neck.begin.y , 40); - - } - - ofSetColor(255,255,255); - anubis.draw(tracked->neck.begin.x- anubis.width/2,tracked->neck.begin.y - anubis.height/2); + + ofSetColor(255,255,255); + float scalingFactor = 0.75; + switch (userID){ + + case 0: + anubis.draw(tracked->neck.begin.x- anubis.width*scalingFactor /2,tracked->neck.begin.y - anubis.height*scalingFactor /2, anubis.width*scalingFactor, anubis.height*scalingFactor ); + break; + case 1: + secondUserImage.draw(tracked->neck.begin.x- secondUserImage.width*scalingFactor /2,tracked->neck.begin.y - secondUserImage.height*scalingFactor /2, secondUserImage.width*scalingFactor, secondUserImage.height*scalingFactor ); + break; + case 2: + thirdUserImage.draw(tracked->neck.begin.x- thirdUserImage.width*scalingFactor /2,tracked->neck.begin.y - thirdUserImage.height*scalingFactor /2, thirdUserImage.width*scalingFactor, thirdUserImage.height*scalingFactor ); + break; + + }//end switch user image + + }//end if is present } @@ -324,6 +459,11 @@ drawAcidSmiley(userID); */ } + ofSetColor(0,0,0); + for (int userNumber = 0;userNumber < 3;userNumber++){ + franklinBook.drawString(userInfoString[userNumber], 600, (userNumber*60)+60); + } + } @@ -342,7 +482,7 @@ // drawIt =!drawIt; ofToggleFullscreen(); - sendDataViaOSC(0); + //sendDataViaOSC(0); } //-------------------------------------------------------------- @@ -367,7 +507,7 @@ ofRect(0,0,ofGetWidth(),ofGetHeight()); int pitch = (int) ofRandom(0, 15); - sendNoteMessageToHeresy(pitch, 1, 127, 1); + //sendNoteMessageToHeresy(pitch, 1, 127, 1); } //--------------------------------------------------------------