comparison jnmr/midiEventHolder.cpp @ 42:3837125603e8

Annotations are correctly loaded so the time difference between observed notes and the predictor is output to saved file
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Tue, 24 Jan 2012 00:26:15 +0000
parents 60c1f0fbc8f4
children 6c8a048720c3
comparison
equal deleted inserted replaced
41:60c1f0fbc8f4 42:3837125603e8
12 12
13 #include "midiEventHolder.h" 13 #include "midiEventHolder.h"
14 14
15 #include <iostream> 15 #include <iostream>
16 #include <fstream> 16 #include <fstream>
17 #include <assert.h>
17 18
18 midiEventHolder::midiEventHolder(){ 19 midiEventHolder::midiEventHolder(){
19 20
20 21
21 22
793 updateNoteCounter(); 794 updateNoteCounter();
794 795
795 } 796 }
796 797
797 void midiEventHolder::updateSmoothPositionTo(const double& newPosition){ 798 void midiEventHolder::updateSmoothPositionTo(const double& newPosition){
799 //smooth play position was where we last outputted notes from.
800 //checking index is there to make sense.
798 while (smoothIndex > 0 && recordedEventTimes[smoothIndex] > smoothPlayPosition){ 801 while (smoothIndex > 0 && recordedEventTimes[smoothIndex] > smoothPlayPosition){
799 smoothIndex--; 802 smoothIndex--;
803 //printf("going backewaers on smooth, ");
800 } 804 }
801 while (smoothIndex < recordedEventTimes.size()-1 && recordedEventTimes[smoothIndex] < smoothPlayPosition){ 805 while (smoothIndex < recordedEventTimes.size()-1 && recordedEventTimes[smoothIndex] < smoothPlayPosition){
802 smoothIndex++; 806 smoothIndex++;
807 //printf("outputting smooth\n ");
803 } 808 }
804 809
805 810
806 double playingTime = ofGetElapsedTimeMillis(); 811 double playingTime = ofGetElapsedTimeMillis();
807 playingTime -= startPlayingTime; 812 playingTime -= startPlayingTime;
811 int currentNote = recordedNoteOnMatrix[smoothIndex][1]; 816 int currentNote = recordedNoteOnMatrix[smoothIndex][1];
812 817
813 while (smoothIndex < recordedEventTimes.size() && recordedEventTimes[smoothIndex] < newPosition){ 818 while (smoothIndex < recordedEventTimes.size() && recordedEventTimes[smoothIndex] < newPosition){
814 float annotationTime = 0; 819 float annotationTime = 0;
815 float annotationLocation = 0; 820 float annotationLocation = 0;
821 int annotationTick = 0;
816 int annotationNote = 0; 822 int annotationNote = 0;
817 float difference = 10000;//very big 823 float difference = 10000;//very big
818 float currentLocationDifference = 1.0; 824 float currentLocationDifference = 1.0;
819 float range = 1.0; 825 float range = 1.0;
820 if (smoothIndex < myNotation.rwcAnnotations.size()){ 826 if (smoothIndex < myNotation.rwcAnnotations.size()){
821 //add in test here to find closest matching note 827 //add in test here to find closest matching note
822 828
823 /* 829
824 int testIndex = smoothIndex;
825 while (testIndex >= 0 && abs(smoothLocation - myNotation.rwcAnnotations[testIndex].beatLocation) < range){
826
827 if (myNotation.rwcAnnotations[testIndex].midiNote == currentNote){
828 if (abs(myNotation.rwcAnnotations[testIndex].beatLocation - smoothLocation) < currentLocationDifference){
829 currentLocationDifference = abs(myNotation.rwcAnnotations[testIndex].beatLocation - smoothLocation);
830 difference = playingTime - (myNotation.rwcAnnotations[testIndex].eventTime*1000.0);
831 annotationNote = myNotation.rwcAnnotations[testIndex].midiNote;
832 annotationLocation = myNotation.rwcAnnotations[testIndex].beatLocation;
833 annotationTime = myNotation.rwcAnnotations[testIndex].eventTime;
834 }
835 }
836 testIndex--;
837 }
838
839 testIndex = smoothIndex;
840 while (testIndex >= 0 && testIndex < myNotation.rwcAnnotations.size() && abs(smoothLocation - myNotation.rwcAnnotations[testIndex].beatLocation) < range){
841
842 if (myNotation.rwcAnnotations[testIndex].midiNote == currentNote){
843 if (abs(myNotation.rwcAnnotations[testIndex].beatLocation - smoothLocation) < currentLocationDifference){
844 currentLocationDifference = abs(myNotation.rwcAnnotations[testIndex].beatLocation - smoothLocation);
845 difference = playingTime - (myNotation.rwcAnnotations[testIndex].eventTime*1000.0);
846 annotationNote = myNotation.rwcAnnotations[testIndex].midiNote;
847 annotationLocation = myNotation.rwcAnnotations[testIndex].beatLocation;
848 annotationTime = myNotation.rwcAnnotations[testIndex].eventTime;
849 }
850 }
851 testIndex++;
852 }
853 */
854 annotationTime = myNotation.rwcAnnotations[smoothIndex].eventTime; 830 annotationTime = myNotation.rwcAnnotations[smoothIndex].eventTime;
855 annotationNote = myNotation.rwcAnnotations[smoothIndex].midiNote; 831 annotationNote = myNotation.rwcAnnotations[smoothIndex].midiNote;
856 annotationLocation = myNotation.rwcAnnotations[smoothIndex].beatLocation; 832 annotationLocation = myNotation.rwcAnnotations[smoothIndex].beatLocation;
833 annotationTick = round(annotationLocation*480.0);
834 }else{
835 printf("No annotaion size %i\n", (int)myNotation.rwcAnnotations.size());
857 } 836 }
858 837
859 difference = playingTime - (annotationTime*1000.0); 838 difference = playingTime - (annotationTime*1000.0);
860 839
861 if ((*fileOutput).is_open()){ 840 if ((*fileOutput).is_open()){
869 848
870 849
871 850
872 } 851 }
873 852
853 printf("assert rec tick time %i vs %i midi %i beat pos %f playing time now at %f :: annotaion %i loc % f time %f diff \t%f ms\n",
854 recordedNoteOnMatrix[smoothIndex][0], annotationTick, recordedNoteOnMatrix[smoothIndex][1],
855 beatPositions[smoothIndex], playingTime,
856 annotationNote, annotationLocation, annotationTime, difference);
857
858 // assert(annotationNote == recordedNoteOnMatrix[smoothIndex][1]);
859 assert(annotationTick == recordedNoteOnMatrix[smoothIndex][0]);
860
861
874 if ((*differenceOutput).is_open()){ 862 if ((*differenceOutput).is_open()){
875 (*differenceOutput) << beatPositions[smoothIndex] << "," << difference << "\n"; 863 (*differenceOutput) << beatPositions[smoothIndex] << "," << difference << "\n";
876 printf("midi %i beat pos %f now at %f :: annotaion %i loc % f time %f diff \t%f ms\n", 864 // printf("midi %i beat pos %f playing time now at %f :: annotaion %i loc % f time %f diff \t%f ms\n",
877 recordedNoteOnMatrix[smoothIndex][1], 865 // recordedNoteOnMatrix[smoothIndex][1],
878 beatPositions[smoothIndex], playingTime, 866 // beatPositions[smoothIndex], playingTime,
879 annotationNote, annotationLocation, annotationTime, difference); 867 // annotationNote, annotationLocation, annotationTime, difference);
868 }else{
869 printf("file not open\n");
880 } 870 }
881 871
882 smoothIndex++; 872 smoothIndex++;
883 } 873 }
884 874
1170 1160
1171 1161
1172 void midiEventHolder::setStartPlayingTimes(){ 1162 void midiEventHolder::setStartPlayingTimes(){
1173 startPlayingTime = getTimeNow(0);//ofGetElapsedTimeMillis(); 1163 startPlayingTime = getTimeNow(0);//ofGetElapsedTimeMillis();
1174 //startTime = startPlayingTime; 1164 //startTime = startPlayingTime;
1175 1165 printf("starting playing at time %f\n", startPlayingTime);
1176 /* 1166 /*
1177 bayesStruct.lastEventTime = 0;//ofGetElapsedTimeMillis(); 1167 bayesStruct.lastEventTime = 0;//ofGetElapsedTimeMillis();
1178 bayesStruct.bestEstimate = 0; 1168 bayesStruct.bestEstimate = 0;
1179 bayesStruct.resetArrays(); 1169 bayesStruct.resetArrays();
1180 bayesStruct.lastBestEstimateUpdateTime = ofGetElapsedTimeMillis(); 1170 bayesStruct.lastBestEstimateUpdateTime = ofGetElapsedTimeMillis();
1407 bayesStruct.updateTempoDistribution(); 1397 bayesStruct.updateTempoDistribution();
1408 //printf("current speed is %f\n", bayesStruct.relativeSpeedPosterior.getIndexInRealTerms(bayesStruct.relativeSpeedPosterior.MAPestimate)); 1398 //printf("current speed is %f\n", bayesStruct.relativeSpeedPosterior.getIndexInRealTerms(bayesStruct.relativeSpeedPosterior.MAPestimate));
1409 } 1399 }
1410 */ 1400 */
1411 1401
1402 /*
1403 JUNK SMOOTH StuffHex
1404 /*
1405 int testIndex = smoothIndex;
1406 while (testIndex >= 0 && abs(smoothLocation - myNotation.rwcAnnotations[testIndex].beatLocation) < range){
1407
1408 if (myNotation.rwcAnnotations[testIndex].midiNote == currentNote){
1409 if (abs(myNotation.rwcAnnotations[testIndex].beatLocation - smoothLocation) < currentLocationDifference){
1410 currentLocationDifference = abs(myNotation.rwcAnnotations[testIndex].beatLocation - smoothLocation);
1411 difference = playingTime - (myNotation.rwcAnnotations[testIndex].eventTime*1000.0);
1412 annotationNote = myNotation.rwcAnnotations[testIndex].midiNote;
1413 annotationLocation = myNotation.rwcAnnotations[testIndex].beatLocation;
1414 annotationTime = myNotation.rwcAnnotations[testIndex].eventTime;
1415 }
1416 }
1417 testIndex--;
1418 }
1419
1420 testIndex = smoothIndex;
1421 while (testIndex >= 0 && testIndex < myNotation.rwcAnnotations.size() && abs(smoothLocation - myNotation.rwcAnnotations[testIndex].beatLocation) < range){
1422
1423 if (myNotation.rwcAnnotations[testIndex].midiNote == currentNote){
1424 if (abs(myNotation.rwcAnnotations[testIndex].beatLocation - smoothLocation) < currentLocationDifference){
1425 currentLocationDifference = abs(myNotation.rwcAnnotations[testIndex].beatLocation - smoothLocation);
1426 difference = playingTime - (myNotation.rwcAnnotations[testIndex].eventTime*1000.0);
1427 annotationNote = myNotation.rwcAnnotations[testIndex].midiNote;
1428 annotationLocation = myNotation.rwcAnnotations[testIndex].beatLocation;
1429 annotationTime = myNotation.rwcAnnotations[testIndex].eventTime;
1430 }
1431 }
1432 testIndex++;
1433 }
1434 */