comparison jnmr/midiEventHolder.cpp @ 49:3ce6dadd8167

Added src for the results calculator, comparing match output with the JNMR midi follower output
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Fri, 23 Mar 2012 10:53:57 +0000
parents 803edc47e825
children 158f5f38e9d3
comparison
equal deleted inserted replaced
48:803edc47e825 49:3ce6dadd8167
22 #include <fstream> 22 #include <fstream>
23 #include <assert.h> 23 #include <assert.h>
24 24
25 midiEventHolder::midiEventHolder(){ 25 midiEventHolder::midiEventHolder(){
26 26
27 27 timeProjectionToMeet = 600;//ms in future they will intersect bet predicted and causal play position
28
28 double scalarForPositionVectors = 10; 29 double scalarForPositionVectors = 10;
29 30
30 // recordedNoteOnIndex = 0; 31 // recordedNoteOnIndex = 0;
31 alignmentPosition = 0; 32 alignmentPosition = 0;
32 33
788 789
789 bayesStruct.updateBestEstimate(0);//was timedifference 790 bayesStruct.updateBestEstimate(0);//was timedifference
790 // bayesStruct.updateTmpBestEstimate(timeDifference); 791 // bayesStruct.updateTmpBestEstimate(timeDifference);
791 } 792 }
792 793
793 794 //did just update smooth to current if it was less
794 795
795 if (smoothPlayPosition < bayesStruct.bestEstimate){ 796 if (smoothPlayPosition < bayesStruct.bestEstimate){
796 updateSmoothPositionTo(bayesStruct.bestEstimate); 797 updateSmoothPositionTo(bayesStruct.bestEstimate);
797 //smoothPlayPosition = bayesStruct.bestEstimate; 798 //smoothPlayPosition = bayesStruct.bestEstimate;
798 } 799 }
799 800
801
802
800 updateCausalPlayPosition(getTimeNow(bayesStruct.lastBestEstimateUpdateTime)); 803 updateCausalPlayPosition(getTimeNow(bayesStruct.lastBestEstimateUpdateTime));
804
805 /*
806 //now we try updating it to a causal path that tries to match into the future
807 if (smoothPlayPosition < causalPlayPosition){
808 updateSmoothPositionTo(causalPlayPosition);
809 }
810 */
801 811
802 // playPositionInMillis = timeDifference;//based on updating from when we change period 812 // playPositionInMillis = timeDifference;//based on updating from when we change period
803 //this to be added 813 //this to be added
804 814
805 815
871 annotationNote, annotationLocation, annotationTime, difference); 881 annotationNote, annotationLocation, annotationTime, difference);
872 882
873 // assert(annotationNote == recordedNoteOnMatrix[smoothIndex][1]); 883 // assert(annotationNote == recordedNoteOnMatrix[smoothIndex][1]);
874 assert(annotationTick == recordedNoteOnMatrix[smoothIndex][0]); 884 assert(annotationTick == recordedNoteOnMatrix[smoothIndex][0]);
875 885
886 smoothDifference = difference;
876 887
877 if ((*differenceOutput).is_open()){ 888 if ((*differenceOutput).is_open()){
878 (*differenceOutput) << beatPositions[smoothIndex] << "," << difference << "," << playingTime << "," << (annotationTime*1000.0) << "\n"; 889 (*differenceOutput) << beatPositions[smoothIndex] << "," << difference << "," << playingTime << "," << (annotationTime*1000.0) << "\n";
879 // printf("midi %i beat pos %f playing time now at %f :: annotaion %i loc % f time %f diff \t%f ms\n", 890 // printf("midi %i beat pos %f playing time now at %f :: annotaion %i loc % f time %f diff \t%f ms\n",
880 // recordedNoteOnMatrix[smoothIndex][1], 891 // recordedNoteOnMatrix[smoothIndex][1],
892 903
893 } 904 }
894 905
895 void midiEventHolder::updateCausalPlayPosition(const double& timeNow){ 906 void midiEventHolder::updateCausalPlayPosition(const double& timeNow){
896 //projected position 907 //projected position
897 double timeProjectionToMeet = 1000;//ms in future they will intersect 908
898 double difference = bayesStruct.bestEstimate - causalPlayPosition; 909 double difference = bayesStruct.bestEstimate - causalPlayPosition;
899 causalSpeed = bayesStruct.speedEstimate; 910 causalSpeed = bayesStruct.speedEstimate;
900 causalSpeed += (difference/timeProjectionToMeet); 911 causalSpeed += (difference/timeProjectionToMeet);
901 912
902 if (causalSpeed < 0) 913 if (causalSpeed < 0)
1036 } 1047 }
1037 1048
1038 //ofDrawBitmapString(ofToString(timeOffsetForScreen, 1), 20,20); 1049 //ofDrawBitmapString(ofToString(timeOffsetForScreen, 1), 20,20);
1039 ofSetColor(255,255,255); 1050 ofSetColor(255,255,255);
1040 ofDrawBitmapString(timeString, 20, 60); 1051 ofDrawBitmapString(timeString, 20, 60);
1052 ofDrawBitmapString("diff "+ofToString(smoothDifference), 20, 140);
1041 1053
1042 //last played piutch 1054 //last played piutch
1043 ofSetColor(0,200,0,50); 1055 ofSetColor(0,200,0,50);
1044 int yLocation = (*screenHeight) - ((lastPlayedPitch - noteMinimum )*(*screenHeight)/ (float)(noteMaximum - noteMinimum)); 1056 int yLocation = (*screenHeight) - ((lastPlayedPitch - noteMinimum )*(*screenHeight)/ (float)(noteMaximum - noteMinimum));
1045 ofRect(0,yLocation, 100, noteHeight); 1057 ofRect(0,yLocation, 100, noteHeight);