andrew@0: #include "testApp.h" andrew@0: andrew@0: andrew@0: //-------------------------------------------------------------- andrew@0: //relooking at this problem andrew@0: //bayesianTempo7 - have had working well with Bayesian8NEW maxmsp set andrew@0: andrew@0: //updated in bayesian8 andrew@0: //integrate so that maxPhase and tempo are the integrated result across the pdf andrew@0: //rather tahn the maximum index - tends to reflect the actuial distribution better andrew@0: //and is the "correct" bayesian method andrew@0: andrew@0: //added [ and ] tpo change the alignment when rescue is needed andrew@0: andrew@0: //in Bayesian9 (BayesianTest8NEW) andrew@0: //added noise in phase process andrew@0: //started probability distribution for observed beat events andrew@0: andrew@0: //in bayesian 11 andrew@0: //get s.d. of posterior andrew@0: //this is set to be used as the s.d. of the likelihood andrew@0: andrew@0: andrew@0: //Initialiser : the algorithm has an initialisation stage with flat prior that detects liekly tempo andrew@0: andrew@0: andrew@0: andrew@0: //BAYESIAN DISTRIBUTION SET by class BayesianArray andrew@0: //SETUP - initialises array andrew@0: //UPDATE - decay the distribution with noise andrew@0: //this should be done using tempo and noise andrew@0: //DRAW - Draw current distributions and also the maximum andrew@0: andrew@0: //Runs with bayesian11NEW andrew@0: //and B-KeeperOldBayesianTestNew in Live andrew@0: //Needs - categorisation of beats and tempo andrew@0: //can we use our distribution to filter the input or is that cheating? andrew@0: andrew@0: //INtroduce lock scheme for tempo - we know where the beat fell, so can calculate the appropriate tempo interval andrew@0: andrew@0: void testApp::setup(){ andrew@0: // listen on the given port andrew@0: cout << "listening for osc messages on port " << PORT << "\n"; andrew@0: receiver.setup( PORT ); andrew@0: andrew@0: // sender.setup( HOST, OUTPORT ); andrew@0: ofSetCircleResolution(50); andrew@0: ofBackground(255,255,255); andrew@0: bSmooth = false; andrew@0: msg_string = "setup"; andrew@0: andrew@0: ofSetWindowTitle("Bayesian Test"); andrew@0: andrew@0: ofSetFrameRate(60); // if vertical sync is off, we can go a bit fast... this caps the framerate at 60fps. andrew@0: andrew@0: /* andrew@0: beatDistribution.initialiseArray(); andrew@0: tempoDistribution.initialiseArray(); andrew@0: beatTimes.lastBeatTime = 0; andrew@0: correctionFactor = 0.5; andrew@0: andrew@0: andrew@0: andrew@0: tempoDistribution.likelihoodStdDev = ARRAY_SIZE / 32; andrew@0: // tempoDistribution.likelihoodNoise = 0.96; andrew@0: tempoDistribution.likelihoodNoise = 0.7; andrew@0: tempoDistribution.setGaussianPrior(ARRAY_SIZE/2, ARRAY_SIZE/1);//wide andrew@0: andrew@0: beatDistribution.likelihoodStdDev = ARRAY_SIZE / 32; andrew@0: beatDistribution.likelihoodNoise = 0.56; andrew@0: beatDistribution.setGaussianPrior(ARRAY_SIZE/2, ARRAY_SIZE/1); andrew@0: andrew@0: andrew@0: tempoMinimum = 180; andrew@0: tempoMaximum = 400; andrew@0: posteriorMaximum = 0.1; andrew@0: andrew@0: */ andrew@0: hidePriorMode = false; andrew@0: andrew@0: printInterval = true; andrew@0: drawData = false; andrew@0: andrew@0: screenToDraw = 0; andrew@0: andrew@0: ofSetLineWidth(2); andrew@0: ofEnableSmoothing(); andrew@0: andrew@0: andrew@0: bSnapshot = false; andrew@0: snapCounter = 0; andrew@0: andrew@0: drumTracker.paused = false; andrew@0: andrew@0: // setDistributionOnStartTempo = true; andrew@0: andrew@0: resetParameters(); andrew@0: andrew@0: arrayToMsecScaleFactor = (drumTracker.tempoMaximum - drumTracker.tempoMinimum)/ ARRAY_SIZE;//turns array into ms andrew@0: tempoWindowMinimum = 100; andrew@0: tempoWindowMaximum = 150; andrew@0: tempoWindowWidth = 50; andrew@0: } andrew@0: andrew@0: andrew@0: void testApp::resetParameters(){ andrew@0: /* andrew@0: beatTimes.startIndex = 0; andrew@0: beatTimes.lastBeatTime = 0; andrew@0: maxPhase = 0; andrew@0: posteriorMaximum = 0.1; andrew@0: andrew@0: accompanimentStarted = false; andrew@0: andrew@0: tempoDistribution.likelihoodNoise = 0.8; andrew@0: tempoDistribution.setGaussianPrior(ARRAY_SIZE/2, ARRAY_SIZE/2);//wide andrew@0: andrew@0: beatDistribution.initialiseArray(); andrew@0: tempoDistribution.initialiseArray(); andrew@0: andrew@0: tempoDistribution.calculateStandardDeviation(); andrew@0: beatDistribution.calculateStandardDeviation(); andrew@0: andrew@0: tempoStdDev = tempoDistribution.standardDeviation; andrew@0: andrew@0: beatTimes.resetBeatTimeArray(); andrew@0: */ andrew@0: } andrew@0: andrew@0: //-------------------------------------------------------------- andrew@0: void testApp::update(){ andrew@0: andrew@0: andrew@0: updateOSCmessages(); andrew@0: andrew@0: //update tempo window range - this for viewing tempo closeup andrew@0: while (tempoWindowMinimum + tempoWindowWidth/4 > drumTracker.tempoDistribution.integratedEstimate) andrew@0: tempoWindowMinimum -= tempoWindowWidth/4; andrew@0: andrew@0: while (tempoWindowMinimum + 3*tempoWindowWidth/4 < drumTracker.tempoDistribution.integratedEstimate) andrew@0: tempoWindowMinimum += tempoWindowWidth/4; andrew@0: andrew@0: tempoWindowMaximum = tempoWindowMinimum + tempoWindowWidth; andrew@0: andrew@0: drumTracker.decayDistributions(); andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: void testApp::updateOSCmessages(){ andrew@0: andrew@0: andrew@0: // check for waiting messages andrew@0: while( receiver.hasWaitingMessages() ) andrew@0: { andrew@0: ofxOscMessage m; andrew@0: receiver.getNextMessage( &m ); andrew@0: string newAddress = m.getAddress(); andrew@0: andrew@0: if ( m.getAddress() == "/Reset" ){ andrew@0: printf("baysian reset\n"); andrew@0: drumTracker.resetParameters(); andrew@0: } andrew@0: andrew@0: andrew@0: if ( m.getAddress() == "/beatError" ){ andrew@0: double timeNow = ofGetElapsedTimeMillis(); andrew@0: if (timeNow - drumTracker.setBeatToNowTime > 1000) andrew@0: drumTracker.newKickError(m.getArgAsFloat(0), m.getArgAsFloat(2), m.getArgAsString(1)); andrew@0: }//end if new error andrew@0: andrew@0: andrew@0: andrew@0: if ( m.getAddress() == "/tatum" ){ andrew@0: drumTracker.beatTimes.tatum = m.getArgAsFloat(0); andrew@0: printf("got tatum as %f\n", m.getArgAsFloat(0)); andrew@0: } andrew@0: andrew@0: if ( m.getAddress() == "/startTatum" ){ andrew@0: drumTracker.startTatum(m.getArgAsFloat(0)); andrew@0: printf("START TATUM %f\n", m.getArgAsFloat(0)); andrew@0: //then change so tempo distribution is correct.... andrew@0: }//end start tatum andrew@0: andrew@0: andrew@0: if ( m.getAddress() == "/uniformTempo" ){ andrew@0: drumTracker.setUniformTempo(); andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: if ( m.getAddress() == "/uniformPhase" ){ andrew@0: drumTracker.setUniformPhase(); andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: if ( m.getAddress() == "/setBeatNow" ){ andrew@0: andrew@0: double beatTime = m.getArgAsFloat(0); andrew@0: drumTracker.setBeatNow(beatTime); andrew@0: //printf("SET BEAT NOW %f\n", beatTime); andrew@0: } andrew@0: andrew@0: andrew@0: if ( m.getAddress() == "/clickindex" ){ andrew@0: andrew@0: int clickIndex = m.getArgAsInt32(0); andrew@0: float clickTime = m.getArgAsFloat(1); andrew@0: drumTracker.setNewClickIndex(clickIndex, clickTime); andrew@0: } andrew@0: andrew@0: andrew@0: if ( m.getAddress() == "/newBeat" ){ andrew@0: int beatIndex = m.getArgAsInt32(0); andrew@0: drumTracker.newBeat(beatIndex); andrew@0: } andrew@0: andrew@0: andrew@0: if ( m.getAddress() == "/beatCorrection" ) andrew@0: { andrew@0: float beatCorrValue = m.getArgAsFloat(0); andrew@0: drumTracker.doBeatCorrection(beatCorrValue); andrew@0: andrew@0: }//end correction by andrew@0: andrew@0: andrew@0: if ( m.getAddress() == "/BayesianNoise" ){ andrew@0: drumTracker.beatDistribution.likelihoodNoise = m.getArgAsFloat(0);; andrew@0: printf("bayesian noise set to %f\n", drumTracker.beatDistribution.likelihoodNoise); andrew@0: // beatDistribution.setGaussianLikelihood(beatDistribution.likelihoodMean, beatDistribution.likelihoodStdDev); andrew@0: } andrew@0: andrew@0: if ( m.getAddress() == "/BayesianStdDev" ){ andrew@0: drumTracker.beatDistribution.likelihoodStdDev = ARRAY_SIZE / m.getArgAsFloat(0); andrew@0: // beatDistribution.setGaussianLikelihood(beatDistribution.likelihoodMean, beatDistribution.likelihoodStdDev); andrew@0: } andrew@0: andrew@0: andrew@0: }//end while there is new message andrew@0: andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: void testApp::takePictureOfScreen(){ andrew@0: // grab a rectangle at 200,200, width and height of 300,180 andrew@0: img.grabScreen(0,0,screenWidth,screenHeight); andrew@0: char fileName[255]; andrew@0: sprintf(fileName, "snapshot_%0.3i.png", snapCounter); andrew@0: img.saveImage(fileName); andrew@0: //printf("saved %s\n", fileName); andrew@0: snapCounter++; andrew@0: bSnapshot = false; andrew@0: } andrew@0: andrew@0: /* andrew@0: void testApp::setBeatDistribution(int beatPosition){ andrew@0: switch (beatPosition){ andrew@0: //early sixteenth is that the beat is a sixteenth earlier andrew@0: case 0: andrew@0: case 1: andrew@0: case 11: andrew@0: //i.e. these zones are interpreted as "on the beat" andrew@0: beatDistribution.eighthNoteProportion = 0; andrew@0: beatDistribution.earlySixteenthNoteProportion = 0; andrew@0: beatDistribution.lateSixteenthNoteProportion = 0; andrew@0: break; andrew@0: //10 and 2 were here andrew@0: andrew@0: case 2: andrew@0: beatDistribution.eighthNoteProportion = 0; andrew@0: beatDistribution.earlySixteenthNoteProportion = 0.25;//was 0.3 in Bayesian8 andrew@0: //i.e. a 25% chance it is early sixteenth - 75% that the beat actually lies here andrew@0: beatDistribution.lateSixteenthNoteProportion = 0; andrew@0: break; andrew@0: andrew@0: case 3: andrew@0: beatDistribution.eighthNoteProportion = 0; andrew@0: beatDistribution.earlySixteenthNoteProportion = 0.3;//was 0.4 in Bayesian8 //half chance it is early andrew@0: beatDistribution.lateSixteenthNoteProportion = 0; andrew@0: break; andrew@0: andrew@0: case 5: andrew@0: case 6: andrew@0: case 7: andrew@0: beatDistribution.eighthNoteProportion = 0.3;//i.e. nearly half a chance we are on the 8th note andrew@0: beatDistribution.earlySixteenthNoteProportion = 0; andrew@0: beatDistribution.lateSixteenthNoteProportion = 0; andrew@0: break; andrew@0: andrew@0: case 4: andrew@0: beatDistribution.eighthNoteProportion = 0; andrew@0: beatDistribution.earlySixteenthNoteProportion = 0.25;//was 0.3 in Bayesian8 andrew@0: beatDistribution.lateSixteenthNoteProportion = 0.05;//was 0.2 in Bayesian8 andrew@0: //chsanged to 0.2 and 0.1 then back andrew@0: break; andrew@0: andrew@0: case 8: andrew@0: beatDistribution.eighthNoteProportion = 0; andrew@0: beatDistribution.earlySixteenthNoteProportion = 0.05;//was 0.2 in Bayesian8 andrew@0: beatDistribution.lateSixteenthNoteProportion = 0.25;//was 0.3 in Bayesian8 andrew@0: break; andrew@0: andrew@0: case 9: andrew@0: beatDistribution.eighthNoteProportion = 0; andrew@0: beatDistribution.earlySixteenthNoteProportion = 0; andrew@0: beatDistribution.lateSixteenthNoteProportion = 0.35;//was 0.4 in Bayesian8 andrew@0: break; andrew@0: andrew@0: case 10: andrew@0: beatDistribution.eighthNoteProportion = 0; andrew@0: beatDistribution.earlySixteenthNoteProportion = 0; andrew@0: beatDistribution.lateSixteenthNoteProportion = 0.25;//was 0.2 in Bayesian8 andrew@0: break; andrew@0: andrew@0: } andrew@0: andrew@0: } andrew@0: */ andrew@0: //-------------------------------------------------------------- andrew@0: void testApp::draw(){ andrew@0: //--------------------------- lines andrew@0: // a bunch of red lines, make them smooth if the flag is set andrew@0: andrew@0: andrew@0: andrew@0: if (bSmooth){ andrew@0: ofEnableSmoothing(); andrew@0: } andrew@0: andrew@0: switch (screenToDraw){ andrew@0: case 0: andrew@0: drawBayesianDistribution(); andrew@0: break; andrew@0: case 1: andrew@0: drawTempoDistribution(); andrew@0: break; andrew@0: case 2: andrew@0: drawBeatMap(); andrew@0: break; andrew@0: case 3: andrew@0: // drawNormalisedLikelihood(); andrew@0: drawRestrictedTempoDistribution(tempoWindowMinimum, tempoWindowMaximum); andrew@0: break; andrew@0: case 4: andrew@0: drawTempoData(); andrew@0: break; andrew@0: case 5: andrew@0: drawBeatProbabilityDistribution(); andrew@0: break; andrew@0: case 6: andrew@0: drawPosterior(); andrew@0: break; andrew@0: case 7: andrew@0: drawGreyscaleBayesianDistribution(); andrew@0: break; andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: andrew@0: if (bSnapshot == true){ andrew@0: takePictureOfScreen(); andrew@0: bSnapshot = false; andrew@0: } andrew@0: andrew@0: }//end draw andrew@0: andrew@0: andrew@0: void testApp::drawTempoData(){ andrew@0: andrew@0: ofSetColor(0xFFFF00); andrew@0: //yellow line in centre andrew@0: ofLine( 0, (screenHeight/2), screenWidth, (screenHeight/2)); andrew@0: andrew@0: ofSetColor(0x0000FF); andrew@0: int tempoIndex = 0; andrew@0: int widthOffset = 20; andrew@0: float stepWidth = screenWidth / 16; andrew@0: ofDrawBitmapString("tatums : ", 600,180); andrew@0: ofDrawBitmapString(ofToString(drumTracker.beatTimes.tatum, 1), 700,180); andrew@0: ofDrawBitmapString("bpm : ", 600,200); andrew@0: ofDrawBitmapString(ofToString((drumTracker.beatTimes.tatum/30000), 1), 700,200); andrew@0: int intervalIndex; andrew@0: int intervalWidth = 2; andrew@0: float magnifyingFactor = 8; andrew@0: for (tempoIndex = 0;tempoIndex < 16; tempoIndex++){ andrew@0: andrew@0: for (intervalIndex = 0;intervalIndex < 16;intervalIndex++){ andrew@0: //new color code andrew@0: if (drumTracker.beatTimes.intervalUsed[tempoIndex][intervalIndex] == true){ andrew@0: ofSetColor(0x00FFFF); andrew@0: } andrew@0: else{ andrew@0: ofSetColor(0xFF00FF); andrew@0: } andrew@0: //end new code andrew@0: andrew@0: ofLine((stepWidth*tempoIndex)+ (intervalWidth*intervalIndex) + widthOffset, screenHeight, andrew@0: (stepWidth*tempoIndex) + (intervalWidth*intervalIndex) + widthOffset, (screenHeight/2) * (1 + (magnifyingFactor * (1-drumTracker.beatTimes.intervalDifferences[tempoIndex][intervalIndex])))); andrew@0: andrew@0: if (printInterval == true){ andrew@0: ofDrawBitmapString(ofToString(drumTracker.beatTimes.intervalDifferences[tempoIndex][intervalIndex], 3), andrew@0: (stepWidth*tempoIndex) + widthOffset,20+(intervalIndex*20)); andrew@0: } andrew@0: andrew@0: andrew@0: ofDrawBitmapString(ofToString(drumTracker.beatTimes.relativeIntervals[tempoIndex][0], 3), 700,220+(tempoIndex*20)); andrew@0: ofDrawBitmapString(ofToString(drumTracker.beatTimes.relativeIntervals[tempoIndex][1], 1), 750,220+(tempoIndex*20)); andrew@0: }//end for interval index andrew@0: }//end for tempo index andrew@0: andrew@0: ofDrawBitmapString(ofToString(drumTracker.beatTimes.clickIndex), 750,20); andrew@0: andrew@0: ofDrawBitmapString(ofToString(mouseBPM), 50,20); andrew@0: ofDrawBitmapString(drumTracker.tempoDataString, 50, 100); andrew@0: andrew@0: }//end draw tempo data andrew@0: andrew@0: andrew@0: void testApp::drawTempoDistribution(){ andrew@0: float maximum = drumTracker.tempoDistribution.getMaximum(&drumTracker.tempoDistribution.likelihood[0], ARRAY_SIZE); andrew@0: maximum = max(maximum, drumTracker.tempoDistribution.getMaximum(&drumTracker.tempoDistribution.prior[0], ARRAY_SIZE)); andrew@0: maximum = max(maximum, drumTracker.tempoDistribution.getMaximum(&drumTracker.tempoDistribution.posterior[0], ARRAY_SIZE)); andrew@0: andrew@0: maximum *= 1.1; andrew@0: andrew@0: float stepHeight = screenHeight/maximum; andrew@0: andrew@0: andrew@0: andrew@0: //draw prior in green andrew@0: ofSetColor(0x888888); andrew@0: for (int i = 1; i < ARRAY_SIZE; i+=2){ andrew@0: ofLine((i-1)*stepSize, screenHeight - (drumTracker.tempoDistribution.prior[i-1]*stepHeight), i*stepSize, screenHeight - (drumTracker.tempoDistribution.prior[i]*stepHeight)); andrew@0: } andrew@0: andrew@0: andrew@0: //draw posterior in dark andrew@0: ofSetColor(0x000000); andrew@0: for (int i = 1; i < ARRAY_SIZE; i++){ andrew@0: ofLine((i-1)*stepSize, screenHeight - (drumTracker.tempoDistribution.posterior[i-1]*stepHeight), i*stepSize, screenHeight - (drumTracker.tempoDistribution.posterior[i]*stepHeight)); andrew@0: } andrew@0: andrew@0: andrew@0: //black line is the max probability andrew@0: ofSetColor(0x000000); andrew@0: ofLine(drumTracker.tempoDistribution.integratedEstimate *stepSize, screenHeight, drumTracker.tempoDistribution.integratedEstimate *stepSize, 0); andrew@0: andrew@0: //blue is the current kick received andrew@0: ofSetColor(0xAAAAAA); andrew@0: andrew@0: int altIndex = 0; andrew@0: for (altIndex = 0;altIndex< 16;altIndex++){ andrew@0: andrew@0: double tempoInterval = drumTracker.beatTimes.intervalDifferences[drumTracker.beatTimes.index][altIndex]; andrew@0: andrew@0: if (altIndex != drumTracker.beatTimes.index && tempoInterval > drumTracker.tempoMinimum && tempoInterval < drumTracker.tempoMaximum){ andrew@0: andrew@0: andrew@0: andrew@0: //draw likelihood andrew@0: //draw likelhood in blue andrew@0: // //need to reset likelihood for this! andrew@0: //XXX remove andrew@0: double timeInterval = drumTracker.beatTimes.beatTimes[drumTracker.beatTimes.index] - drumTracker.beatTimes.beatTimes[altIndex]; andrew@0: if (timeInterval > 2*drumTracker.tempoMinimum && timeInterval < 2*drumTracker.tempoMaximum) andrew@0: { andrew@0: andrew@0: ofLine(stepSize*(ARRAY_SIZE * (tempoInterval-drumTracker.tempoMinimum)/(drumTracker.tempoMaximum - drumTracker.tempoMinimum)), screenHeight, andrew@0: stepSize*(ARRAY_SIZE * (tempoInterval - drumTracker.tempoMinimum)/(drumTracker.tempoMaximum - drumTracker.tempoMinimum)) , 0); andrew@0: andrew@0: drumTracker.tempoDistribution.setGaussianLikelihood(ARRAY_SIZE * (tempoInterval - drumTracker.tempoMinimum)/(drumTracker.tempoMaximum - drumTracker.tempoMinimum), drumTracker.tempoDistribution.likelihoodStdDev); andrew@0: for (int i = 1; i < ARRAY_SIZE; i++){ andrew@0: ofLine((i-1)*stepSize, screenHeight - (drumTracker.tempoDistribution.likelihood[i-1]*stepHeight), i*stepSize, screenHeight - (drumTracker.tempoDistribution.likelihood[i]*stepHeight)); andrew@0: } andrew@0: } andrew@0: andrew@0: } andrew@0: andrew@0: }//end for andrew@0: andrew@0: if (bSmooth){ andrew@0: ofDisableSmoothing(); andrew@0: } andrew@0: andrew@0: drawTempoInfo(); andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: int testApp::xcoordinateFromTempoDataPoint(float f){ andrew@0: //f is the time andrew@0: andrew@0: int xcoordinateForInterval = 0; andrew@0: if (f >= drumTracker.tempoMinimum && f <= drumTracker.tempoMaximum) andrew@0: xcoordinateForInterval = ((float)(f - drumTracker.tempoMinimum)*screenWidth/(float)(drumTracker.tempoMaximum - drumTracker.tempoMinimum)); andrew@0: return xcoordinateForInterval; andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: int testApp::xcoordinateFromRestrictedTempoDataPoint(float f, const int& tmpMin, const int& tmpMax){ andrew@0: andrew@0: andrew@0: int xcoordinateForInterval = -1; andrew@0: if (f >= drumTracker.tempoMinimum+tmpMin && f <= min(drumTracker.tempoMinimum+tmpMax,drumTracker.tempoMaximum)) andrew@0: xcoordinateForInterval = ((float)(f - drumTracker.tempoMinimum - tmpMin*arrayToMsecScaleFactor)*screenWidth/(float)((tmpMax - tmpMin)*arrayToMsecScaleFactor)); andrew@0: return xcoordinateForInterval; andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: void testApp::drawTempoInfo(){ andrew@0: float maximum = drumTracker.tempoDistribution.getMaximum(&drumTracker.tempoDistribution.likelihood[0], ARRAY_SIZE); andrew@0: maximum = max(maximum, drumTracker.tempoDistribution.getMaximum(&drumTracker.tempoDistribution.prior[0], ARRAY_SIZE)); andrew@0: maximum = max(maximum, drumTracker.tempoDistribution.getMaximum(&drumTracker.tempoDistribution.posterior[0], ARRAY_SIZE)); andrew@0: andrew@0: andrew@0: ofSetColor(0x000000); andrew@0: string testString; andrew@0: testString = "max is "; andrew@0: testString += ofToString(maximum); andrew@0: ofDrawBitmapString(testString, 700,620); andrew@0: andrew@0: ofDrawBitmapString(msg_string, 700,650); andrew@0: andrew@0: ofDrawBitmapString(kickString, 700,670); andrew@0: andrew@0: testString = "std dev : "; andrew@0: testString += ofToString(drumTracker.tempoStdDev, 6); andrew@0: andrew@0: testString += ", "; andrew@0: testString += ofToString(drumTracker.accompanimentStarted); andrew@0: ofDrawBitmapString(testString, 20, 120); andrew@0: andrew@0: int tempoUpdateIndex; andrew@0: for (tempoUpdateIndex = 0;tempoUpdateIndex<16;tempoUpdateIndex++){ andrew@0: // ofDrawBitmapString(tempoUpdateStrings[tempoUpdateIndex], 700, 200 + (20 * tempoUpdateIndex)); andrew@0: } andrew@0: andrew@0: ofDrawBitmapString("Mouse located at tempo: ", 50,10); andrew@0: ofDrawBitmapString(ofToString(mouseBPM, 1), 50,20); andrew@0: andrew@0: ofDrawBitmapString("Current tempo: ", 50,40); andrew@0: ofDrawBitmapString(ofToString(30000/drumTracker.beatTimes.tatum, 1), 50,50); andrew@0: andrew@0: ofDrawBitmapString(drumTracker.tempoDataString, 50, 100); andrew@0: andrew@0: andrew@0: for (int i = 1;i < 16; i++){ andrew@0: for (int altIndex = 0; altIndex < 16;altIndex++){ andrew@0: string newString; andrew@0: newString = " :"; andrew@0: int recentIndex = (altIndex-i+16)%16; andrew@0: if (drumTracker.beatTimes.intervalDifferences[altIndex][recentIndex] > 0 && drumTracker.beatTimes.intervalUsed[altIndex][recentIndex]){ andrew@0: andrew@0: andrew@0: int xcoordinateForInterval = xcoordinateFromTempoDataPoint(drumTracker.beatTimes.intervalDifferences[altIndex][recentIndex]); andrew@0: float beatInterval = (float) drumTracker.beatTimes.tatumMultiples[altIndex][recentIndex]/2; andrew@0: andrew@0: if (drumTracker.beatTimes.OnsetIsKick[altIndex]) andrew@0: ofSetColor(255*(8-beatInterval)/(float)8, 0, 255*beatInterval/(float)8); andrew@0: else andrew@0: ofSetColor(0, 255*(8-beatInterval)/(float)8, 255*beatInterval/(float)8); andrew@0: //red kick, green snare andrew@0: andrew@0: ofCircle(xcoordinateForInterval, 200 + (altIndex * 20), 3); andrew@0: andrew@0: newString += ofToString(drumTracker.beatTimes.intervalDifferences[altIndex][recentIndex],0); andrew@0: newString += " ("; andrew@0: newString += ofToString(drumTracker.beatTimes.tatumMultiples[altIndex][recentIndex]/2, 0); andrew@0: newString += ")"; andrew@0: andrew@0: } andrew@0: ofSetColor(0,0,0); andrew@0: //ofDrawBitmapString(newString, 200 + i*80, 200 + (altIndex * 20)); andrew@0: andrew@0: andrew@0: } andrew@0: } andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: void testApp::drawTempoDataPoints(const int& tmpMin, const int& tmpMax, const float& tmpStepSize){ andrew@0: andrew@0: for (int i = 1;i < 16; i++){ andrew@0: for (int altIndex = 0; altIndex < 16;altIndex++){ andrew@0: // string newString; andrew@0: // newString = " :"; andrew@0: andrew@0: int recentIndex = (altIndex-i+16)%16; andrew@0: if (drumTracker.beatTimes.intervalDifferences[altIndex][recentIndex] > 0 && drumTracker.beatTimes.intervalUsed[altIndex][recentIndex]){ andrew@0: andrew@0: int xcoordinateForInterval = xcoordinateFromRestrictedTempoDataPoint(drumTracker.beatTimes.intervalDifferences[altIndex][recentIndex], tmpMin, tmpMax); andrew@0: float beatInterval = (float) drumTracker.beatTimes.tatumMultiples[altIndex][recentIndex]/2; andrew@0: andrew@0: if (drumTracker.beatTimes.OnsetIsKick[altIndex]) andrew@0: ofSetColor(255*(7-beatInterval+1)/(float)7, 255*(beatInterval-1)/(float)7, 0);//100+155*(8-beatInterval)/(float)8 andrew@0: else andrew@0: ofSetColor(0, 255*(7-beatInterval+1)/(float)7, 255*(beatInterval-1)/(float)7);//, 155*beatInterval/(float)8); andrew@0: //red kick, green snare andrew@0: andrew@0: ofCircle(xcoordinateForInterval, 200 + (altIndex * 20), 3); andrew@0: ofDrawBitmapString(ofToString(beatInterval, 0), xcoordinateForInterval-2, 200 + (altIndex * 20) - 3); andrew@0: /* newString += ofToString(beatTimes.intervalDifferences[altIndex][recentIndex],0); andrew@0: newString += " ("; andrew@0: newString += ofToString(beatTimes.tatumMultiples[altIndex][recentIndex]/2, 0); andrew@0: newString += ")"; andrew@0: */ andrew@0: } andrew@0: ofSetColor(0,0,0); andrew@0: //ofDrawBitmapString(newString, 200 + i*80, 200 + (altIndex * 20)); andrew@0: andrew@0: andrew@0: } andrew@0: } andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: void testApp::drawRestrictedTempoDistribution(int tmpMin, int tmpMax){ andrew@0: //min and max are in the tempo array coordinates andrew@0: andrew@0: tmpMin = max(tmpMin, 0); andrew@0: tmpMax = min(tmpMax, ARRAY_SIZE-1); andrew@0: andrew@0: float maximum = drumTracker.tempoDistribution.getMaximum(&drumTracker.tempoDistribution.likelihood[0], ARRAY_SIZE); andrew@0: maximum = max(maximum, drumTracker.tempoDistribution.getMaximum(&drumTracker.tempoDistribution.prior[0], ARRAY_SIZE)); andrew@0: maximum = max(maximum, drumTracker.tempoDistribution.getMaximum(&drumTracker.tempoDistribution.posterior[0], ARRAY_SIZE)); andrew@0: andrew@0: maximum *= 1.1; andrew@0: andrew@0: float stepHeight = screenHeight/maximum; andrew@0: int tmpWidth = tmpMax - 1 - tmpMin; andrew@0: float tmpStepSize = screenWidth / (float) tmpWidth; andrew@0: andrew@0: andrew@0: //draw prior in green andrew@0: ofSetColor(0x888888); andrew@0: for (int i = 1; i < tmpWidth; i+=2){ andrew@0: ofLine((i-1)*tmpStepSize, screenHeight - (drumTracker.tempoDistribution.prior[tmpMin+i-1]*stepHeight), i * tmpStepSize, screenHeight - (drumTracker.tempoDistribution.prior[tmpMin+i]*stepHeight)); andrew@0: } andrew@0: andrew@0: andrew@0: //draw posterior in dark andrew@0: ofSetColor(0x000000); andrew@0: for (int i = 1; i < tmpWidth; i++){ andrew@0: ofLine((i-1) * tmpStepSize, screenHeight - (drumTracker.tempoDistribution.posterior[tmpMin+i-1]*stepHeight), i*tmpStepSize, screenHeight - (drumTracker.tempoDistribution.posterior[tmpMin+i]*stepHeight)); andrew@0: } andrew@0: andrew@0: andrew@0: //black line is the max probability andrew@0: ofSetColor(0x000000); andrew@0: ofLine((drumTracker.tempoDistribution.integratedEstimate - tmpMin)* tmpStepSize, screenHeight, (drumTracker.tempoDistribution.integratedEstimate-tmpMin) *tmpStepSize, 0); andrew@0: andrew@0: //blue is the current kick received andrew@0: ofSetColor(0xAAAAAA); andrew@0: andrew@0: int altIndex = 0; andrew@0: for (altIndex = 0;altIndex< 16;altIndex++){ andrew@0: //iterate through all recent beat intervals andrew@0: andrew@0: double tempoInterval = drumTracker.beatTimes.intervalDifferences[drumTracker.beatTimes.index][altIndex]; andrew@0: andrew@0: if (altIndex != drumTracker.beatTimes.index && tempoInterval > drumTracker.tempoMinimum && tempoInterval < drumTracker.tempoMaximum){ andrew@0: andrew@0: double timeInterval = drumTracker.beatTimes.beatTimes[drumTracker.beatTimes.index] - drumTracker.beatTimes.beatTimes[altIndex]; andrew@0: andrew@0: if (timeInterval > 2*drumTracker.tempoMinimum && timeInterval < 2*drumTracker.tempoMaximum){ andrew@0: //i.e. within the beat range only andrew@0: //so we only draw the likelihood realtime for happening beat intervals andrew@0: //in fact much more is going on than this but harder to visualise andrew@0: andrew@0: float indexOfNewLocation = ARRAY_SIZE*(tempoInterval-drumTracker.tempoMinimum)/(float)(drumTracker.tempoMaximum - drumTracker.tempoMinimum); andrew@0: andrew@0: andrew@0: if (indexOfNewLocation >= tmpMin){ andrew@0: ofLine(tmpStepSize * (indexOfNewLocation-tmpMin), screenHeight, tmpStepSize * (indexOfNewLocation-tmpMin) , 0); andrew@0: } andrew@0: andrew@0: andrew@0: drumTracker.tempoDistribution.setGaussianLikelihood(ARRAY_SIZE * (tempoInterval - drumTracker.tempoMinimum)/(drumTracker.tempoMaximum - drumTracker.tempoMinimum), drumTracker.tempoDistribution.likelihoodStdDev); andrew@0: //setting the tempo distribution likeihood just for visualisation purposes andrew@0: for (int i = 1; i < tmpWidth; i++){ andrew@0: ofLine((i-1)*tmpStepSize, screenHeight - (drumTracker.tempoDistribution.likelihood[i+tmpMin-1]*stepHeight), i*tmpStepSize, screenHeight - (drumTracker.tempoDistribution.likelihood[i+tmpMin]*stepHeight)); andrew@0: andrew@0: } andrew@0: } andrew@0: andrew@0: } andrew@0: andrew@0: }//end for andrew@0: andrew@0: if (bSmooth){ andrew@0: ofDisableSmoothing(); andrew@0: } andrew@0: andrew@0: andrew@0: drawTempoDataPoints(tmpMin, tmpMax, tmpStepSize); andrew@0: andrew@0: // lines for background andrew@0: for (int i = tmpMin-(tmpMin%20);i < tmpMax; i+=20){ andrew@0: ofSetColor(0,0,200,100); andrew@0: ofLine(tmpStepSize * (i-tmpMin), screenHeight, tmpStepSize * (i-tmpMin) , 0); andrew@0: string tmpTempoString = ofToString(drumTracker.tempoMinimum + i*arrayToMsecScaleFactor, 0); andrew@0: ofDrawBitmapString(tmpTempoString, tmpStepSize * (i-tmpMin) , 20); andrew@0: } andrew@0: andrew@0: string currentTatumString = "Beat Period : "; andrew@0: currentTatumString += ofToString(drumTracker.beatTimes.tatum, 1); andrew@0: currentTatumString += " MaxIndex : "; andrew@0: currentTatumString += ofToString(drumTracker.tempoDistribution.integratedEstimate, 1); andrew@0: andrew@0: ofDrawBitmapString(currentTatumString, 20, 40); andrew@0: //drawTempoInfo(); andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: void testApp::drawBeatMap(){ andrew@0: int x,y; andrew@0: andrew@0: for (x=0;x < 6;x++){ andrew@0: for (y=0;y<8;y++){ andrew@0: int cell = x+(y*6); andrew@0: if (cell == drumTracker.beatTimes.beatSegment){ andrew@0: if (drumTracker.beatTimes.beatMap[cell] == 1)//for kick andrew@0: ofSetColor(drumTracker.beatTimes.beatMap[cell]*255, 0, 0); andrew@0: andrew@0: if (drumTracker.beatTimes.beatMap[cell] == 2)//for kick andrew@0: ofSetColor(0, drumTracker.beatTimes.beatMap[cell]*255, 100); andrew@0: andrew@0: } andrew@0: else{ andrew@0: if (drumTracker.beatTimes.beatMap[cell] == 1)//for kick andrew@0: ofSetColor(drumTracker.beatTimes.beatMap[cell]*155, 0, 0); andrew@0: else //for snare andrew@0: ofSetColor(0,drumTracker.beatTimes.beatMap[cell]*155, 0);//beatTimes.beatMap[cell]*155); andrew@0: andrew@0: } andrew@0: ofRect(screenWidth*x/6, screenHeight*y/8, screenWidth/6, screenHeight/8); andrew@0: andrew@0: ofSetColor(255,0,0); andrew@0: ofDrawBitmapString(ofToString(x+(y*6)), screenWidth*x/6, screenHeight*y/8); andrew@0: andrew@0: if (drumTracker.beatTimes.beatMap[cell] == 1){ andrew@0: ofSetColor(0,255,255);// andrew@0: ofDrawBitmapString(ofToString(drumTracker.beatTimes.beatMapTimeDifferences[cell], 2), (screenWidth*(x+0.5)/6) , (screenHeight*(y+0.5)/8) ); andrew@0: } andrew@0: if (drumTracker.beatTimes.beatMap[cell] == 2){ andrew@0: ofSetColor(0,0,100);// andrew@0: ofDrawBitmapString(ofToString(drumTracker.beatTimes.beatMapTimeDifferences[cell], 2), (screenWidth*(x+0.5)/6) , (screenHeight*(y+0.5)/8) ); andrew@0: } andrew@0: andrew@0: andrew@0: } andrew@0: } andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: void testApp::drawBeatProbabilityDistribution(){ andrew@0: int x,y; andrew@0: andrew@0: for (x=0;x < 6;x++){ andrew@0: for (y=0;y<4;y++){ andrew@0: int cell = x+(y*6); andrew@0: ofSetColor(drumTracker.beatTimes.beatProbabilityDistribution[y][x][0]*255, 0, 0); andrew@0: ofRect(screenWidth*x/6, screenHeight*y/8, screenWidth/6, screenHeight/8); andrew@0: } andrew@0: } andrew@0: for (x=0;x < 6;x++){ andrew@0: for (y=0;y<4;y++){ andrew@0: int cell = x+(y*6); andrew@0: ofSetColor(0, drumTracker.beatTimes.beatProbabilityDistribution[y][x][1]*255, 0); andrew@0: ofRect(screenWidth*x/6, screenHeight*(y+4)/8, screenWidth/6, screenHeight/8); andrew@0: } andrew@0: } andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: void testApp::drawNormalisedLikelihood(){ andrew@0: float maximum = drumTracker.beatDistribution.getMaximum(&drumTracker.beatDistribution.likelihood[0], ARRAY_SIZE); andrew@0: maximum = max(maximum, drumTracker.beatDistribution.getMaximum(&drumTracker.beatDistribution.prior[0], ARRAY_SIZE)); andrew@0: //maximum = max(maximum, beatDistribution.getMaximum(&beatDistribution.posterior[0], ARRAY_SIZE)); andrew@0: float stepHeight = screenHeight/maximum; andrew@0: andrew@0: if (!hidePriorMode){ andrew@0: //draw likelhood in blue andrew@0: andrew@0: ofSetColor(0x0000FF); andrew@0: for (int i = 1; i < ARRAY_SIZE; i++){ andrew@0: ofLine((i-1)*stepSize, screenHeight - (drumTracker.beatDistribution.likelihood[i-1]*stepHeight), i*stepSize, screenHeight - (drumTracker.beatDistribution.likelihood[i]*stepHeight)); andrew@0: } andrew@0: andrew@0: //draw prior in green andrew@0: ofSetColor(0x00AA00); andrew@0: for (int i = 1; i < ARRAY_SIZE; i++){ andrew@0: ofLine((i-1)*stepSize, screenHeight - (drumTracker.beatDistribution.prior[i-1]*stepHeight), i*stepSize, screenHeight - (drumTracker.beatDistribution.prior[i]*stepHeight)); andrew@0: } andrew@0: }//end hide prior mode andrew@0: andrew@0: andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: andrew@0: void testApp::drawPosterior(){ andrew@0: float maximum = drumTracker.beatDistribution.getMaximum(&drumTracker.beatDistribution.posterior[0], ARRAY_SIZE); andrew@0: andrew@0: if (drumTracker.posteriorMaximum < maximum){ andrew@0: drumTracker.posteriorMaximum = 1.2*maximum; andrew@0: } andrew@0: andrew@0: float stepHeight = screenHeight/drumTracker.posteriorMaximum; andrew@0: ofSetColor(0xFF00FF); andrew@0: for (int i = 1; i < ARRAY_SIZE; i++){ andrew@0: ofLine((i-1)*stepSize, screenHeight - (drumTracker.beatDistribution.posterior[i-1]*stepHeight), i*stepSize, screenHeight - (drumTracker.beatDistribution.posterior[i]*stepHeight)); andrew@0: } andrew@0: andrew@0: andrew@0: //yellow is the middle andrew@0: ofSetColor(0xFFFF00); andrew@0: ofLine(ARRAY_SIZE*stepSize/2, screenHeight, ARRAY_SIZE*stepSize/2, 0); andrew@0: andrew@0: andrew@0: andrew@0: //blue is the current kick received andrew@0: ofSetColor(0x0000FF); andrew@0: ofLine(stepSize*((ARRAY_SIZE/2) + (ARRAY_SIZE*drumTracker.kickError)), screenHeight,stepSize*((ARRAY_SIZE/2) + (ARRAY_SIZE*drumTracker.kickError)), 0); andrew@0: andrew@0: //purple line is the integrated max probability andrew@0: int integratedBeatEstimateDrawPoint = round(drumTracker.beatDistribution.integratedEstimate*stepSize) ; andrew@0: ofSetColor(0xFF22FF); andrew@0: ofLine(integratedBeatEstimateDrawPoint, screenHeight, integratedBeatEstimateDrawPoint, 0); andrew@0: andrew@0: string testString = "maximum: "; andrew@0: testString += ofToString(drumTracker.posteriorMaximum, 2); andrew@0: ofDrawBitmapString(testString, 100,120); andrew@0: andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: void testApp::drawBayesianDistribution(){ andrew@0: float maximum = drumTracker.beatDistribution.getMaximum(&drumTracker.beatDistribution.likelihood[0], ARRAY_SIZE); andrew@0: maximum = max(maximum, drumTracker.beatDistribution.getMaximum(&drumTracker.beatDistribution.prior[0], ARRAY_SIZE)); andrew@0: maximum = max(maximum, drumTracker.beatDistribution.getMaximum(&drumTracker.beatDistribution.posterior[0], ARRAY_SIZE)); andrew@0: float stepHeight = screenHeight/maximum; andrew@0: andrew@0: if (!hidePriorMode){ andrew@0: //draw likelhood in blue andrew@0: if (drumTracker.onsetType == "kick") andrew@0: ofSetColor(0xff0000);//red : kick andrew@0: else andrew@0: ofSetColor(0x00FF00);//green : snare andrew@0: andrew@0: for (int i = 1; i < ARRAY_SIZE; i++){ andrew@0: ofLine((i-1)*stepSize, screenHeight - (drumTracker.beatDistribution.likelihood[i-1]*stepHeight), i*stepSize, screenHeight - (drumTracker.beatDistribution.likelihood[i]*stepHeight)); andrew@0: } andrew@0: andrew@0: //;line where the current kick is received andrew@0: ofLine(stepSize*((ARRAY_SIZE/2) + (ARRAY_SIZE*drumTracker.kickError)), screenHeight,stepSize*((ARRAY_SIZE/2) + (ARRAY_SIZE*drumTracker.kickError)), 0); andrew@0: andrew@0: andrew@0: //draw prior in aqua blue andrew@0: ofSetColor(0x00AAAA); andrew@0: for (int i = 1; i < ARRAY_SIZE; i++){ andrew@0: ofLine((i-1)*stepSize, screenHeight - (drumTracker.beatDistribution.prior[i-1]*stepHeight), i*stepSize, screenHeight - (drumTracker.beatDistribution.prior[i]*stepHeight)); andrew@0: } andrew@0: }//end hide prior mode andrew@0: andrew@0: //draw posterior in red andrew@0: ofSetColor(0x0000FF); andrew@0: for (int i = 1; i < ARRAY_SIZE; i++){ andrew@0: ofLine((i-1)*stepSize, screenHeight - (drumTracker.beatDistribution.posterior[i-1]*stepHeight), i*stepSize, screenHeight - (drumTracker.beatDistribution.posterior[i]*stepHeight)); andrew@0: } andrew@0: andrew@0: //draw the previous updated posteriror in purple andrew@0: /* ofSetColor(0xFF22FF); andrew@0: for (int i = 1; i < ARRAY_SIZE; i++){ andrew@0: ofLine((i-1)*stepSize, screenHeight - (tmpArray[i-1]*stepHeight), i*stepSize, screenHeight - (tmpArray[i]*stepHeight)); andrew@0: } andrew@0: */ andrew@0: andrew@0: //yellow is the middle andrew@0: ofSetColor(0xFFFF00); andrew@0: ofLine(ARRAY_SIZE*stepSize/2, screenHeight, ARRAY_SIZE*stepSize/2, 0); andrew@0: andrew@0: //black line is the max probability andrew@0: ofSetColor(0x000000); andrew@0: ofLine(drumTracker.beatDistribution.maximumIndex*stepSize, screenHeight, drumTracker.beatDistribution.maximumIndex*stepSize, 0); andrew@0: andrew@0: andrew@0: //purple line is the integrated max probability andrew@0: int integratedBeatEstimate = drumTracker.beatDistribution.integratedEstimate ; andrew@0: ofSetColor(0x2222FF); andrew@0: ofLine(integratedBeatEstimate *stepSize, screenHeight, integratedBeatEstimate *stepSize, 0); andrew@0: andrew@0: andrew@0: if (bSmooth){ andrew@0: ofDisableSmoothing(); andrew@0: } andrew@0: andrew@0: printBayesianData(); andrew@0: } andrew@0: andrew@0: void testApp::printBayesianData(){ andrew@0: //not optimised!!! XXX andrew@0: float maximum = drumTracker.beatDistribution.getMaximum(&drumTracker.beatDistribution.likelihood[0], ARRAY_SIZE); andrew@0: maximum = max(maximum, drumTracker.beatDistribution.getMaximum(&drumTracker.beatDistribution.prior[0], ARRAY_SIZE)); andrew@0: maximum = max(maximum, drumTracker.beatDistribution.getMaximum(&drumTracker.beatDistribution.posterior[0], ARRAY_SIZE)); andrew@0: andrew@0: ofSetColor(0x000000); andrew@0: string testString; andrew@0: testString = "max2 is "; andrew@0: testString += ofToString(maximum, 3); andrew@0: testString += " :: "; andrew@0: andrew@0: testString = "correction of "; andrew@0: testString += ofToString(drumTracker.beatCorrection); andrew@0: testString += " corr by :"; andrew@0: testString += ofToString(drumTracker.correctBeatBy); andrew@0: andrew@0: //ofDrawBitmapString(testString, 100,120); andrew@0: andrew@0: testString = "MaxPhase "; andrew@0: testString += ofToString(drumTracker.maxPhase); andrew@0: // ofDrawBitmapString(testString, 100,140); andrew@0: andrew@0: andrew@0: testString = "Likelihood noise "; andrew@0: testString += ofToString(drumTracker.beatDistribution.likelihoodNoise, 2); andrew@0: //ofDrawBitmapString(testString, 100,160); andrew@0: andrew@0: // ofDrawBitmapString(msg_string, 100,140); andrew@0: andrew@0: // ofDrawBitmapString(kickString, 100,180); andrew@0: andrew@0: /* debugString = "Min Debug = "; andrew@0: debugString += ofToString(drumTracker.tempoDistribution.maximumIndex + drumTracker.minTempoIndex); andrew@0: debugString += " Max Debug = "; andrew@0: debugString += ofToString(drumTracker.tempoDistribution.maximumIndex + drumTracker.maxTempoIndex); andrew@0: */ andrew@0: //ofDrawBitmapString(debugString, 300,370); andrew@0: andrew@0: debugString = "CLICK INDEX = "; andrew@0: debugString += ofToString(drumTracker.beatTimes.clickIndex); andrew@0: //ofDrawBitmapString(debugString, 100, 20); andrew@0: andrew@0: debugString = "STD DEV = "; andrew@0: debugString += ofToString(drumTracker.beatDistribution.standardDeviation, 2); andrew@0: // ofDrawBitmapString(debugString, 100, 40); andrew@0: andrew@0: andrew@0: andrew@0: debugString = "interval "; andrew@0: debugString += ofToString(drumTracker.debugArray[2], 2); andrew@0: debugString += " time int = "; andrew@0: debugString += ofToString(drumTracker.debugArray[1], 2); andrew@0: debugString += " Beat max = "; andrew@0: debugString += ofToString(drumTracker.debugArray[0 ], 2); andrew@0: debugString += " Tempo max = "; andrew@0: debugString += ofToString(drumTracker.debugArray[3 ], 2); andrew@0: // ofDrawBitmapString(debugString, 300,570); andrew@0: andrew@0: debugString = " last = "; andrew@0: debugString += ofToString(drumTracker.beatTimes.lastBeatTime, 2); andrew@0: // ofDrawBitmapString(debugString, 300,470); andrew@0: andrew@0: andrew@0: string closestClickString = "Closest Click "; andrew@0: closestClickString += ofToString(drumTracker.beatTimes.closestClickIndexToBeat[drumTracker.beatTimes.index]); andrew@0: closestClickString += " beat seg "; andrew@0: closestClickString += ofToString(drumTracker.beatTimes.beatSegment%12); andrew@0: closestClickString += " lastCindex"; andrew@0: closestClickString += ofToString(drumTracker.beatTimes.lastClickIndex); andrew@0: closestClickString += " TD "; andrew@0: closestClickString += ofToString(drumTracker.beatTimes.timeDifference); andrew@0: andrew@0: // ofDrawBitmapString(closestClickString, 100,100); andrew@0: andrew@0: // ofDrawBitmapString(timeString, 100,60); andrew@0: } andrew@0: andrew@0: andrew@0: andrew@0: void testApp::drawGreyscaleBayesianDistribution(){ andrew@0: ofSetColor(255,255,255); andrew@0: ofRect(0,0,screenWidth, screenHeight); andrew@0: andrew@0: float maximum = drumTracker.beatDistribution.getMaximum(&drumTracker.beatDistribution.likelihood[0], ARRAY_SIZE); andrew@0: maximum = max(maximum, drumTracker.beatDistribution.getMaximum(&drumTracker.beatDistribution.prior[0], ARRAY_SIZE)); andrew@0: maximum = max(maximum, drumTracker.beatDistribution.getMaximum(&drumTracker.beatDistribution.posterior[0], ARRAY_SIZE)); andrew@0: maximum *= 1.1; andrew@0: float stepHeight = screenHeight/maximum; andrew@0: andrew@0: if (!hidePriorMode){ andrew@0: //draw likelhood in blue andrew@0: ofSetColor(0x555555); andrew@0: for (int i = 1; i < ARRAY_SIZE; i+=2){ andrew@0: ofLine((i-1)*stepSize, screenHeight - (drumTracker.beatDistribution.likelihood[i-1]*stepHeight), i*stepSize, screenHeight - (drumTracker.beatDistribution.likelihood[i]*stepHeight)); andrew@0: } andrew@0: andrew@0: //draw prior in green andrew@0: ofSetColor(0xAAAAAA); andrew@0: for (int i = 1; i < ARRAY_SIZE; i++){ andrew@0: ofLine((i-1)*stepSize, screenHeight - (drumTracker.beatDistribution.prior[i-1]*stepHeight), i*stepSize, screenHeight - (drumTracker.beatDistribution.prior[i]*stepHeight)); andrew@0: } andrew@0: }//end hide prior mode andrew@0: andrew@0: //draw posterior in dark grey andrew@0: ofSetColor(0x222222); andrew@0: for (int i = 1; i < ARRAY_SIZE; i++){ andrew@0: ofLine((i-1)*stepSize, screenHeight - (drumTracker.beatDistribution.posterior[i-1]*stepHeight), i*stepSize, screenHeight - (drumTracker.beatDistribution.posterior[i]*stepHeight)); andrew@0: } andrew@0: andrew@0: /* andrew@0: //dotted the middle andrew@0: ofSetColor(0x555555); andrew@0: for (int i = 1; i < screenHeight; i+=4){ andrew@0: ofLine(ARRAY_SIZE*stepSize/2, i, ARRAY_SIZE*stepSize/2, i-2); andrew@0: } andrew@0: */ andrew@0: andrew@0: //purple line is the integrated max probability andrew@0: // int integratedBeatEstimate = beatDistribution.integratedEstimate ; andrew@0: // ofSetColor(0x000000); andrew@0: // ofLine(integratedBeatEstimate *stepSize, screenHeight, integratedBeatEstimate *stepSize, 0); andrew@0: andrew@0: //purple line is the integrated max probability andrew@0: float tmpIntegratedBeatEstimate = drumTracker.beatDistribution.getIntegratedEstimateIndex(); andrew@0: ofSetColor(0x000000); andrew@0: int drawLinePoint = round(tmpIntegratedBeatEstimate *stepSize); andrew@0: ofLine(drawLinePoint, screenHeight, drawLinePoint, 0); andrew@0: andrew@0: //blue is the current kick received andrew@0: ofSetColor(0x555555); andrew@0: for (int i = 1; i < screenHeight; i+=40){ andrew@0: ofLine(stepSize*((ARRAY_SIZE/2) + (ARRAY_SIZE*drumTracker.kickError)), i,stepSize*((ARRAY_SIZE/2) + (ARRAY_SIZE*drumTracker.kickError)), i-20); andrew@0: } andrew@0: andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: void testApp::drawGreyscaleTempoDistribution(double tempoInterval){ andrew@0: ofSetColor(255,255,255); andrew@0: ofRect(0,0,screenWidth, screenHeight); andrew@0: andrew@0: float maximum = drumTracker.tempoDistribution.getMaximum(&drumTracker.tempoDistribution.likelihood[0], ARRAY_SIZE); andrew@0: maximum = max(maximum, drumTracker.tempoDistribution.getMaximum(&drumTracker.tempoDistribution.prior[0], ARRAY_SIZE)); andrew@0: maximum = max(maximum, drumTracker.tempoDistribution.getMaximum(&drumTracker.tempoDistribution.posterior[0], ARRAY_SIZE)); andrew@0: andrew@0: maximum *= 1.1; andrew@0: andrew@0: float stepHeight = screenHeight/maximum; andrew@0: andrew@0: //draw prior in green andrew@0: ofSetColor(0x777777); andrew@0: for (int i = 1; i < ARRAY_SIZE; i++){ andrew@0: ofLine((i-1)*stepSize, screenHeight - (drumTracker.tempoDistribution.prior[i-1]*stepHeight), i*stepSize, screenHeight - (drumTracker.tempoDistribution.prior[i]*stepHeight)); andrew@0: } andrew@0: andrew@0: andrew@0: //draw posterior in dark andrew@0: ofSetColor(0x000000); andrew@0: for (int i = 1; i < ARRAY_SIZE; i++){ andrew@0: ofLine((i-1)*stepSize, screenHeight - (drumTracker.tempoDistribution.posterior[i-1]*stepHeight), i*stepSize, screenHeight - (drumTracker.tempoDistribution.posterior[i]*stepHeight)); andrew@0: } andrew@0: andrew@0: andrew@0: //black line is the max probability andrew@0: ofSetColor(0xFF0000); andrew@0: ofLine(drumTracker.tempoDistribution.integratedEstimate *stepSize, screenHeight, drumTracker.tempoDistribution.integratedEstimate *stepSize, 0); andrew@0: andrew@0: //blue is the current kick received andrew@0: ofSetColor(0xAAAAAA); andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: for (int k =1;k < screenHeight/12;k+=2){ andrew@0: ofLine(stepSize*(ARRAY_SIZE * (tempoInterval-drumTracker.tempoMinimum)/(drumTracker.tempoMaximum - drumTracker.tempoMinimum)), 12*k, andrew@0: stepSize*(ARRAY_SIZE * (tempoInterval-drumTracker.tempoMinimum)/(drumTracker.tempoMaximum - drumTracker.tempoMinimum)) , 12*(k-1)); andrew@0: } andrew@0: andrew@0: drumTracker.tempoDistribution.setGaussianLikelihood(ARRAY_SIZE * (tempoInterval - drumTracker.tempoMinimum)/(drumTracker.tempoMaximum - drumTracker.tempoMinimum), drumTracker.tempoDistribution.likelihoodStdDev); andrew@0: for (int i = 1; i < ARRAY_SIZE; i+=2){ andrew@0: //dotted line likelihood fn andrew@0: ofLine((i-1)*stepSize, screenHeight - (drumTracker.tempoDistribution.likelihood[i-1]*stepHeight), i*stepSize, screenHeight - (drumTracker.tempoDistribution.likelihood[i]*stepHeight)); andrew@0: } andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: if (bSmooth){ andrew@0: ofDisableSmoothing(); andrew@0: } andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: //-------------------------------------------------------------- andrew@0: void testApp::keyPressed (int key){ andrew@0: if (key == 's'){ andrew@0: bSmooth = !bSmooth; andrew@0: } andrew@0: andrew@0: if (key == 'x'){ andrew@0: printInterval = !printInterval; andrew@0: } andrew@0: andrew@0: andrew@0: if (key == 'y'){ andrew@0: drawData = !drawData; andrew@0: } andrew@0: andrew@0: if (key == 'f'){ andrew@0: ofToggleFullscreen(); andrew@0: } andrew@0: andrew@0: if (key == 'h' || key == 'H'){ andrew@0: hidePriorMode = !hidePriorMode;//drawData; andrew@0: } andrew@0: andrew@0: andrew@0: andrew@0: if ( key =='a' || key == 'A' ) andrew@0: { andrew@0: andrew@0: } andrew@0: andrew@0: if (key == ' '){ andrew@0: drumTracker.paused = !drumTracker.paused; andrew@0: } andrew@0: andrew@0: if (key == OF_KEY_RIGHT){ andrew@0: screenToDraw++; andrew@0: screenToDraw = screenToDraw % NUMBER_OF_SCREENS; andrew@0: } andrew@0: if (key == OF_KEY_LEFT){ andrew@0: screenToDraw += NUMBER_OF_SCREENS - 1; andrew@0: screenToDraw = screenToDraw % NUMBER_OF_SCREENS; andrew@0: } andrew@0: andrew@0: if (key == ']') andrew@0: drumTracker.beatDistribution.translateDistribution(ARRAY_SIZE / 4); andrew@0: andrew@0: if (key == '[') andrew@0: drumTracker.beatDistribution.translateDistribution(-1*ARRAY_SIZE / 4); andrew@0: andrew@0: if (key == 'x'){ andrew@0: bSnapshot = true; andrew@0: } andrew@0: andrew@0: if (key == 'q') andrew@0: drumTracker.adaptiveStandardDeviationMode = !drumTracker.adaptiveStandardDeviationMode; andrew@0: andrew@0: } andrew@0: andrew@0: /* andrew@0: void testApp::sendMaxTempo(){ andrew@0: ofxOscMessage m; andrew@0: m.setAddress( "/tempo" ); andrew@0: andrew@0: //maxTempo = tempoDistribution.maximumIndex * (tempoMaximum - tempoMinimum) / ARRAY_SIZE; andrew@0: //would be introduced new in bayesian8 andrew@0: maxTempo = drumTracker.tempoDistribution.getIntegratedEstimateIndex() * (tempoMaximum - tempoMinimum) / ARRAY_SIZE; andrew@0: maxTempo += tempoMinimum; andrew@0: andrew@0: andrew@0: m.addFloatArg( maxTempo ); andrew@0: sender.sendMessage( m ); andrew@0: andrew@0: printf("max tempo %f\n", maxTempo); andrew@0: andrew@0: } andrew@0: andrew@0: void testApp::sendMaxPhase(){ andrew@0: andrew@0: andrew@0: // maxPhase = (beatDistribution.maximumIndex - (ARRAY_SIZE/2)) / ARRAY_SIZE; andrew@0: maxPhase = (drumTracker.beatDistribution.getIntegratedEstimateIndex() - (ARRAY_SIZE/2)) / ARRAY_SIZE; andrew@0: printf("\nphase index %f :: %i\n", drumTracker.beatDistribution.integratedEstimate , maxPhase); andrew@0: ofxOscMessage m; andrew@0: m.setAddress( "/phase" ); andrew@0: m.addFloatArg( maxPhase ); andrew@0: sender.sendMessage( m ); andrew@0: andrew@0: //beatCorrection = maxPhase * beatTimes.tatum / 4; andrew@0: } andrew@0: */ andrew@0: //-------------------------------------------------------------- andrew@0: void testApp::keyReleased (int key){ andrew@0: andrew@0: } andrew@0: andrew@0: //-------------------------------------------------------------- andrew@0: void testApp::mouseMoved(int x, int y ){ andrew@0: andrew@0: mouseBPM = convertToBPM(drumTracker.tempoMinimum+ ((x * (drumTracker.tempoMaximum - drumTracker.tempoMinimum) ) / ofGetWidth() )) ; andrew@0: } andrew@0: andrew@0: //-------------------------------------------------------------- andrew@0: void testApp::mouseDragged(int x, int y, int button){ andrew@0: } andrew@0: andrew@0: //-------------------------------------------------------------- andrew@0: void testApp::mousePressed(int x, int y, int button){ andrew@0: } andrew@0: andrew@0: andrew@0: //-------------------------------------------------------------- andrew@0: void testApp::mouseReleased(int x, int y, int button){ andrew@0: andrew@0: } andrew@0: andrew@0: //-------------------------------------------------------------- andrew@0: void testApp::windowResized(int w, int h){ andrew@0: screenWidth = ofGetWidth(); andrew@0: screenHeight = ofGetHeight(); andrew@0: stepSize = screenWidth / (float)(ARRAY_SIZE); andrew@0: } andrew@0: andrew@0: double testApp::convertToBPM(double interval){ andrew@0: //interval is in ms and is the tatum interval - eighth nbote - so 250ms for 120bpm andrew@0: return (30000/interval); andrew@0: andrew@0: } andrew@0: /* andrew@0: noyt needed? andrew@0: float testApp::tempoIndexToMsec(int index){ andrew@0: float msec; andrew@0: msec = index * (tempoMaximum - tempoMinimum) / ARRAY_SIZE; andrew@0: msec += tempoMinimum; andrew@0: return msec; andrew@0: } andrew@0: andrew@0: float testApp::beatIndexToMsec(int index){ andrew@0: float msec; andrew@0: msec = index * maxTempo / ARRAY_SIZE; andrew@0: msec += tempoMinimum; andrew@0: return msec; andrew@0: } andrew@0: */ andrew@0: /* andrew@0: andrew@0: bool testApp::filterBeatTime(double newBeatTime){ andrew@0: bool newBeatFound = false; andrew@0: if ((newBeatTime - beatTimes.lastBeatTime) > 20 || beatTimes.lastBeatTime == 0){ andrew@0: andrew@0: crossUpdateArrays((float)(newBeatTime - beatTimes.lastBeatTime)); andrew@0: beatTimes.lastBeatTime = newBeatTime; andrew@0: newBeatFound = true; andrew@0: } andrew@0: return newBeatFound; andrew@0: } andrew@0: andrew@0: void testApp::crossUpdateArrays(float timeInterval){ andrew@0: andrew@0: int finalBeatIndex, tmpTempoIndex, startBeatIndex; andrew@0: //finalBeat has contribution from BEAT[finalBeat + INT.k] * TEMPO[Max_tempo + k] where INT = INTERVAL andrew@0: float interval; andrew@0: interval = timeInterval / maxTempo;//beatTimes.tatum; andrew@0: tempoDistribution.resetMaximumPosterior(); andrew@0: beatDistribution.resetMaximumPosterior(); andrew@0: andrew@0: andrew@0: int tmpBeatIndex; andrew@0: //&& interval > 0.8 idea? andrew@0: if (timeInterval > 0 && timeInterval < 12000 ){//need between 0 and 12 seconds only to update andrew@0: andrew@0: for (tmpBeatIndex = 0;tmpBeatIndex < ARRAY_SIZE;tmpBeatIndex++){ andrew@0: andrew@0: tmpArray[tmpBeatIndex] = 0; andrew@0: float minusMsecToMakeUp = beatIndexToMsec(tmpBeatIndex) / interval; andrew@0: float plusMsecToMakeUp = beatIndexToMsec(ARRAY_SIZE - tmpBeatIndex) / interval; andrew@0: float convertMsecToTempoIndex = ARRAY_SIZE / (tempoMaximum - tempoMinimum) ; andrew@0: andrew@0: andrew@0: int minTempoIndex = -1 * (int)(minusMsecToMakeUp * convertMsecToTempoIndex); andrew@0: int maxTempoIndex = (int)(plusMsecToMakeUp * convertMsecToTempoIndex); andrew@0: andrew@0: andrew@0: if (tmpBeatIndex == beatDistribution.maximumIndex){ andrew@0: minTmpDebug = tempoDistribution.maximumIndex + minTempoIndex; andrew@0: maxTmpDebug = tempoDistribution.maximumIndex + maxTempoIndex; andrew@0: debugArray[0] = beatDistribution.maximumIndex;// andrew@0: debugArray[1] = timeInterval; andrew@0: debugArray[2] = interval;//beatDistribution.maximumIndex; andrew@0: debugArray[3] = tempoDistribution.maximumIndex; andrew@0: } andrew@0: andrew@0: for (tmpTempoIndex = minTempoIndex;tmpTempoIndex <= maxTempoIndex;tmpTempoIndex++){ andrew@0: andrew@0: if ((tempoDistribution.maximumIndex + tmpTempoIndex) >= 0 andrew@0: && (tempoDistribution.maximumIndex + tmpTempoIndex) < ARRAY_SIZE andrew@0: && (tmpBeatIndex - (int)(interval*tmpTempoIndex)) >= 0 andrew@0: && (tmpBeatIndex - (int)(interval*tmpTempoIndex))< ARRAY_SIZE){ andrew@0: tmpArray[tmpBeatIndex] += beatDistribution.posterior[tmpBeatIndex - (int)(interval*tmpTempoIndex)] * tempoDistribution.posterior[(int)tempoDistribution.maximumIndex + tmpTempoIndex]; andrew@0: } andrew@0: }//end for tmpTmepo andrew@0: andrew@0: andrew@0: andrew@0: } andrew@0: andrew@0: float tmpFloat; andrew@0: for (tmpBeatIndex = 0;tmpBeatIndex < ARRAY_SIZE;tmpBeatIndex++){ andrew@0: //debug - dont actually update:: andrew@0: andrew@0: tmpFloat = beatDistribution.posterior[tmpBeatIndex]; andrew@0: beatDistribution.posterior[tmpBeatIndex] = tmpArray[tmpBeatIndex]; andrew@0: tmpArray[tmpBeatIndex] = tmpFloat; andrew@0: } andrew@0: beatDistribution.renormaliseArray(&beatDistribution.posterior[0], ARRAY_SIZE); andrew@0: andrew@0: } //end if andrew@0: andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: void testApp::updateTempoProcess(double cpuTime, string onsetDescription){ andrew@0: andrew@0: if (filterBeatTime(cpuTime) == true){ andrew@0: //checks for no repeat andrew@0: andrew@0: if (onsetDescription == "kick") andrew@0: beatTimes.addBeatTime(cpuTime, 1); andrew@0: else andrew@0: beatTimes.addBeatTime(cpuTime, 2); andrew@0: andrew@0: andrew@0: //recalculate the distribution andrew@0: int altIndex = 0; andrew@0: andrew@0: tempoDataString = "Tatum :"; andrew@0: tempoDataString += ofToString(beatTimes.tatum, 2); andrew@0: tempoDataString += " BPM "; andrew@0: tempoDataString += ofToString((double)30000/beatTimes.tatum, 2); andrew@0: andrew@0: timeString = "Last BEAT "; andrew@0: timeString += ofToString(beatTimes.lastBeatTime); andrew@0: timeString += " CLICK "; andrew@0: timeString += ofToString(beatTimes.lastClickTime); andrew@0: timeString += " DIFDF "; andrew@0: timeString += ofToString(beatTimes.timeDifference); andrew@0: timeString += " segment "; andrew@0: timeString += ofToString(beatTimes.beatSegment); andrew@0: andrew@0: andrew@0: for (altIndex = 0;altIndex< 16;altIndex++){ andrew@0: tempoInterval = beatTimes.intervalDifferences[beatTimes.index][altIndex]; andrew@0: integerMultipleOfTatum = beatTimes.relativeIntervals[altIndex][1]; andrew@0: andrew@0: andrew@0: ///NEW VERSION andrew@0: tempoUpdateStrings[altIndex] = ""; andrew@0: double timeInterval = beatTimes.beatTimes[beatTimes.index] - beatTimes.beatTimes[altIndex]; andrew@0: //raw time difference andrew@0: beatTimes.intervalDifferences[beatTimes.index][altIndex] = 0; andrew@0: beatTimes.intervalUsed[beatTimes.index][altIndex] = false; andrew@0: andrew@0: if (onsetType == "kick") andrew@0: beatTimes.OnsetIsKick[beatTimes.index] = true; andrew@0: else andrew@0: beatTimes.OnsetIsKick[beatTimes.index] = false; andrew@0: andrew@0: andrew@0: andrew@0: if (!accompanimentStarted){ andrew@0: //if we need to find tempo and start use this method andrew@0: //we have 'started' once std dev is sufficiently low andrew@0: andrew@0: updateTempoIfWithinRange(timeInterval);//taken as being the tatum interval andrew@0: andrew@0: andrew@0: andrew@0: for (int i = 1;i <= 4;i++){ andrew@0: //we test the main beats and the two bar (16 tatum intervals) andrew@0: andrew@0: double testInterval = timeInterval / 2*i;//pow(2, i);//pow(2.0, i); andrew@0: andrew@0: if (updateTempoIfWithinRange(testInterval)){ andrew@0: printf("test time %f, beats %i\n", testInterval, i); andrew@0: andrew@0: beatTimes.intervalUsed[beatTimes.index][altIndex] = true; andrew@0: beatTimes.intervalDifferences[beatTimes.index][altIndex] = testInterval; andrew@0: //xx what if two within range here? andrew@0: andrew@0: tempoUpdateStrings[altIndex] = "Tempo Updates ("; andrew@0: tempoUpdateStrings[altIndex] += ofToString(beatTimes.index, 0); andrew@0: tempoUpdateStrings[altIndex] += ") : ["; andrew@0: tempoUpdateStrings[altIndex] += ofToString(altIndex); andrew@0: tempoUpdateStrings[altIndex] += "]] : "; andrew@0: tempoUpdateStrings[altIndex] += ofToString(timeInterval); andrew@0: tempoUpdateStrings[altIndex] += ", ioi:"; andrew@0: tempoUpdateStrings[altIndex] += ofToString(i); andrew@0: //tempoUpdateStrings[altIndex] += ""; andrew@0: andrew@0: } andrew@0: andrew@0: } andrew@0: andrew@0: double testInterval = timeInterval / 16;//pow(2, i);//pow(2.0, i); andrew@0: if (updateTempoIfWithinRange(testInterval)){ andrew@0: beatTimes.intervalUsed[beatTimes.index][altIndex] = true; andrew@0: beatTimes.intervalDifferences[beatTimes.index][altIndex] = testInterval; andrew@0: } andrew@0: andrew@0: }else{ andrew@0: //OLD VERSON andrew@0: //THIS USES THE CURRENT TEMPO ESTIMATE TO DECIDE WHAT THE BEST INTERVAL IS andrew@0: //&& integerMultipleOfTatum % 2 == 0 removed below XXX put back andrew@0: if (altIndex != beatTimes.index && integerMultipleOfTatum < 17 andrew@0: && integerMultipleOfTatum > 0 && beatTimes.startIndex > 8//beattimes.index > 8 - the start andrew@0: && integerMultipleOfTatum%2 == 0){//mod 2 - i.e. proper beat intervals only andrew@0: andrew@0: double testInterval = timeInterval / integerMultipleOfTatum; andrew@0: andrew@0: if (updateTempoIfWithinRange(testInterval)){ andrew@0: andrew@0: beatTimes.intervalUsed[beatTimes.index][altIndex] = true; andrew@0: beatTimes.intervalDifferences[beatTimes.index][altIndex] = testInterval; andrew@0: andrew@0: if (paused == false){ andrew@0: tempoUpdateStrings[altIndex] = "Tempo Updates : ("; andrew@0: tempoUpdateStrings[altIndex] += ofToString(beatTimes.index, 0); andrew@0: tempoUpdateStrings[altIndex] += ") : ["; andrew@0: tempoUpdateStrings[altIndex] += ofToString(altIndex, 0); andrew@0: tempoUpdateStrings[altIndex] += "] :: "; andrew@0: tempoUpdateStrings[altIndex] += ofToString(integerMultipleOfTatum); andrew@0: tempoUpdateStrings[altIndex] += " intervals :: "; andrew@0: tempoUpdateStrings[altIndex] += ofToString(tempoInterval); andrew@0: tempoUpdateStrings[altIndex] += " ms."; andrew@0: // tempoUpdateStrings[altIndex] += ", ioi:"; andrew@0: andrew@0: // tempoUpdateStrings[altIndex] += ofToString(integerMultipleOfTatum); andrew@0: andrew@0: andrew@0: andrew@0: andrew@0: }//end if not paused andrew@0: andrew@0: andrew@0: }//end if good interval to update andrew@0: andrew@0: }//end if not same index etc andrew@0: andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: andrew@0: }//end for all intervals andrew@0: andrew@0: sendMaxTempo(); andrew@0: }//end if new beat time andrew@0: double tempoEstimate = tempoDistribution.getIntegratedEstimateIndex(); andrew@0: tempoDistribution.calculateStandardDeviation(); andrew@0: tempoStdDev = tempoDistribution.standardDeviation; andrew@0: andrew@0: } andrew@0: andrew@0: andrew@0: bool testApp::updateTempoIfWithinRange(double timeInterval){ andrew@0: andrew@0: bool updated = false; andrew@0: andrew@0: if (timeInterval > tempoMinimum && timeInterval < tempoMaximum ){ andrew@0: calculateTempoUpdate(timeInterval); andrew@0: updated = true; andrew@0: } andrew@0: andrew@0: return updated; andrew@0: } andrew@0: andrew@0: andrew@0: */ andrew@0: //end andrew@0: /* andrew@0: void testApp::calculateTempoUpdate(double tempoInterval){ andrew@0: andrew@0: andrew@0: tempoDistribution.resetPrior(); andrew@0: //need to relook at likelihood for the tempo distribution - not the same as.... andrew@0: tempoDistribution.setGaussianLikelihood(ARRAY_SIZE * (tempoInterval-tempoMinimum)/(tempoMaximum - tempoMinimum), tempoDistribution.likelihoodStdDev); andrew@0: tempoDistribution.calculatePosterior(); andrew@0: tempoDistribution.renormalisePosterior(); andrew@0: andrew@0: //did take pic of screen here - see initialiser4 andrew@0: } andrew@0: */ andrew@0: