comparison jnmr/midiEventHolder.cpp @ 52:13194a9dca77 tip

Added exporting of image and text data
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Tue, 17 Jul 2012 22:13:10 +0100
parents 158f5f38e9d3
children
comparison
equal deleted inserted replaced
51:ef30f465a904 52:13194a9dca77
20 20
21 #include <iostream> 21 #include <iostream>
22 #include <fstream> 22 #include <fstream>
23 #include <assert.h> 23 #include <assert.h>
24 24
25 #pragma mark -initialise
26
27 int matchedColor = 0xAAAAAA;
28 int bestMatchedColor = 0xFF0000;
29
25 midiEventHolder::midiEventHolder(){ 30 midiEventHolder::midiEventHolder(){
26 31
27 timeProjectionToMeet = 600;//ms in future they will intersect bet predicted and causal play position 32 timeProjectionToMeet = 600;//ms in future they will intersect bet predicted and causal play position
28 33
29 double scalarForPositionVectors = 10; 34 double scalarForPositionVectors = 10;
32 alignmentPosition = 0; 37 alignmentPosition = 0;
33 38
34 useTempoPrior = false;//puts sine wave round tempo 39 useTempoPrior = false;//puts sine wave round tempo
35 confidenceWeightingUsed = true; 40 confidenceWeightingUsed = true;
36 newOptimalMethod = true; 41 newOptimalMethod = true;
42 printInfo = false;
37 43
38 matchWindowWidth = 20000;//window size for matching in ms 44 matchWindowWidth = 20000;//window size for matching in ms
39 interNoteRange = 1600;//preferred duration 45 interNoteRange = 1600;//preferred duration
40 //so max here is really four 46 //so max here is really four
41 47
42
43 likelihoodWidth = 100;//using 100 is good 48 likelihoodWidth = 100;//using 100 is good
44 likelihoodToNoiseRatio = 0.20;//was 0.02 on 18/11/11, changing to give more weight to observations 49 likelihoodToNoiseRatio = 0.80;//was 0.02 on 18/11/11, changing to give more weight to observations
45 //was 0.08 on 11/12/11 but need more for tempo varn in rwc database 50 //was 0.08 on 11/12/11 but need more for tempo varn in rwc database
51 //0.2 on main tests of
46 52
47 bayesStruct.speedLikelihoodNoise = 0.2;//changed from 0.1, was 0.05 53 bayesStruct.speedLikelihoodNoise = 0.2;//changed from 0.1, was 0.05
48 bayesStruct.speedDecayWidth = 40; 54 bayesStruct.speedDecayWidth = 40;
49 bayesStruct.speedDecayAmount = 10; 55 bayesStruct.speedDecayAmount = 10;
50 56
67 tickLocation = 0; 73 tickLocation = 0;
68 pulsesPerQuarternote = 240; 74 pulsesPerQuarternote = 240;
69 noteArrayIndex = 0; 75 noteArrayIndex = 0;
70 noteMinimum = 30; 76 noteMinimum = 30;
71 noteMaximum = 96; 77 noteMaximum = 96;
72
73
74
75
76 78
77 speedPriorValue = 1.0; 79 speedPriorValue = 1.0;
78 80
79 int tmpArraySize = (int)(matchWindowWidth/scalarForPositionVectors); 81 int tmpArraySize = (int)(matchWindowWidth/scalarForPositionVectors);
80 bayesStruct.resetSize(tmpArraySize); 82 bayesStruct.resetSize(tmpArraySize);
84 bayesStruct.resetSpeedSize(200); 86 bayesStruct.resetSpeedSize(200);
85 bayesStruct.setRelativeSpeedScalar(0.01); 87 bayesStruct.setRelativeSpeedScalar(0.01);
86 bayesStruct.relativeSpeedPrior.getMaximum(); 88 bayesStruct.relativeSpeedPrior.getMaximum();
87 //bayesStruct.simpleExample(); 89 //bayesStruct.simpleExample();
88 90
89
90 speedWindowWidthMillis = 1600;//4000 91 speedWindowWidthMillis = 1600;//4000
91 92
92 noteHeight = (*screenHeight) / (float)(noteMaximum - noteMinimum); 93 noteHeight = (*screenHeight) / (float)(noteMaximum - noteMinimum);
93 94
94
95 intervalsToCheck.push_back(1); 95 intervalsToCheck.push_back(1);
96 intervalsToCheck.push_back(2); 96 intervalsToCheck.push_back(2);
97 //intervalsToCheck.push_back(3); 97 //intervalsToCheck.push_back(3);
98 intervalsToCheck.push_back(4); 98 intervalsToCheck.push_back(4);
99 intervalsToCheck.push_back(6); 99 intervalsToCheck.push_back(6);
100 intervalsToCheck.push_back(8); 100 intervalsToCheck.push_back(8);
101 intervalsToCheck.push_back(16); 101 intervalsToCheck.push_back(16);
102 102
103
104 drawPhaseMode = true; 103 drawPhaseMode = true;
104 saveImage = false;
105 105
106 printf("lookup index %f value %f\n", bayesStruct.prior.getLookupIndex(100, 30., 10.0), bayesStruct.prior.gaussianLookupTable[(int)bayesStruct.prior.getLookupIndex(100, 30., 10.0)]); 106 printf("lookup index %f value %f\n", bayesStruct.prior.getLookupIndex(100, 30., 10.0), bayesStruct.prior.gaussianLookupTable[(int)bayesStruct.prior.getLookupIndex(100, 30., 10.0)]);
107 } 107 }
108 108
109 109
153 updatePeriodValue(0);// periodValues[0][2]; 153 updatePeriodValue(0);// periodValues[0][2];
154 printf("Resetting period to %f , size is %i\n", period, (int)periodValues.size()); 154 printf("Resetting period to %f , size is %i\n", period, (int)periodValues.size());
155 } 155 }
156 */ 156 */
157 //period = 500.0; 157 //period = 500.0;
158 }
159
160 void midiEventHolder::testSpeedPriorSetting(){
161 if (speedPriorValue > 2){
162 bayesStruct.resetSpeedSize(speedPriorValue * 200);
163 bayesStruct.setRelativeSpeedScalar(0.01);
164 bayesStruct.relativeSpeedPrior.getMaximum();
165 printf("SPEED SIZE EXCEEDS MAXIMUM!!! RESETTING TO SIXE %i\n", (int)(speedPriorValue * 200));
166 }
167 else{
168 bayesStruct.resetSpeedSize(200);
169 bayesStruct.setRelativeSpeedScalar(0.01);
170 bayesStruct.relativeSpeedPrior.getMaximum();
171 }
172
173 }
174
175 void midiEventHolder::setMatchedNotesBackToFalse(){
176 for (int i = 0;i < noteOnMatches.size();i++)
177 noteOnMatches[i] = false;
178 } 158 }
179 159
180 void midiEventHolder::clearAllEvents(){ 160 void midiEventHolder::clearAllEvents(){
181 recordedNoteOnMatrix.clear(); 161 recordedNoteOnMatrix.clear();
182 matchesFound.clear(); 162 matchesFound.clear();
195 recordedTotalNoteCounterByPitch.clear(); 175 recordedTotalNoteCounterByPitch.clear();
196 recordedTotalNoteCounterByPitch.assign(127, 0); 176 recordedTotalNoteCounterByPitch.assign(127, 0);
197 totalNoteCounterIndex = 0; 177 totalNoteCounterIndex = 0;
198 } 178 }
199 179
180 void midiEventHolder::testSpeedPriorSetting(){
181 if (speedPriorValue > 2){
182 bayesStruct.resetSpeedSize(speedPriorValue * 200);
183 bayesStruct.setRelativeSpeedScalar(0.01);
184 bayesStruct.relativeSpeedPrior.getMaximum();
185 printf("SPEED SIZE EXCEEDS MAXIMUM!!! RESETTING TO SIXE %i\n", (int)(speedPriorValue * 200));
186 }
187 else{
188 bayesStruct.resetSpeedSize(200);
189 bayesStruct.setRelativeSpeedScalar(0.01);
190 bayesStruct.relativeSpeedPrior.getMaximum();
191 }
192
193 }
194
195 void midiEventHolder::setMatchedNotesBackToFalse(){
196 for (int i = 0;i < noteOnMatches.size();i++)
197 noteOnMatches[i] = false;
198 }
199
200
201
200 void midiEventHolder::printNotes(){ 202 void midiEventHolder::printNotes(){
201 printf("RECORDED MATRIX\n"); 203 printf("RECORDED MATRIX\n");
202 for (int i = 0;i < recordedNoteOnMatrix.size();i++){ 204 for (int i = 0;i < recordedNoteOnMatrix.size();i++){
203 printf("ticktime %i :: pitch %i @ millis %f\n", recordedNoteOnMatrix[i][0], recordedNoteOnMatrix[i][1], recordedEventTimes[i]); 205 printf("ticktime %i :: pitch %i @ millis %f\n", recordedNoteOnMatrix[i][0], recordedNoteOnMatrix[i][1], recordedEventTimes[i]);
204 } 206 }
205 } 207 }
206 208
207 209
208 double midiEventHolder::getEventTimeTicks(double millis){ 210 #pragma mark -New Observed Event
209 return 0.0; 211
210 //return (millis * pulsesPerQuarternote / period);
211 }
212
213 double midiEventHolder::getEventTimeMillis(double ticks){
214 return (period * ticks / (double) pulsesPerQuarternote);
215 }
216 212
217 void midiEventHolder::newNoteOnEvent(int pitch, int velocity, double timePlayed){ 213 void midiEventHolder::newNoteOnEvent(int pitch, int velocity, double timePlayed){
218 // tempoSpeedString = ""; 214 // tempoSpeedString = "";
219 215
220 //MOVE INTO BAYESSTRUCT?? XXX 216 //MOVE INTO BAYESSTRUCT?? XXX
320 316
321 //storedSmoothPlayPosition = smoothPlayPosition; 317 //storedSmoothPlayPosition = smoothPlayPosition;
322 318
323 } 319 }
324 320
321 double midiEventHolder::getEventTimeTicks(double millis){
322 return 0.0;
323 //return (millis * pulsesPerQuarternote / period);
324 }
325
326 double midiEventHolder::getEventTimeMillis(double ticks){
327 return (period * ticks / (double) pulsesPerQuarternote);
328 }
329
330
331
332 double midiEventHolder::getTimeNow(double eventTime){
333 double timeNow = eventTime;
334 if (runningInRealTime)
335 timeNow = ofGetElapsedTimeMillis();
336 return timeNow;
337 }
338
339 #pragma mark -Tempo Update
340
325 void midiEventHolder::updateTempo(){ 341 void midiEventHolder::updateTempo(){
326 //having found matches we have matches for new note and matches for previous notes 342 //having found matches we have matches for new note and matches for previous notes
327 if (newOptimalMethod)//now true 343 if (newOptimalMethod)//now true
328 findOptimumTempoPairsToCurrentBestMatch(); 344 findOptimumTempoPairsToCurrentBestMatch();
329 else if (!confidenceWeightingUsed) 345 else if (!confidenceWeightingUsed)
330 findLocalTempoPairs(); 346 findLocalTempoPairs();
331 else 347 else
332 findLocalTempoPairsWeightedForConfidence(); 348 findLocalTempoPairsWeightedForConfidence();
333 349
334 //bayesStruct.addGaussianNoiseToSpeedPosterior(10); 350 //bayesStruct.addGaussianNoiseToSpeedPosterior(10);
335 }
336
337 double midiEventHolder::getTimeNow(double eventTime){
338 double timeNow = eventTime;
339 if (runningInRealTime)
340 timeNow = ofGetElapsedTimeMillis();
341 return timeNow;
342 } 351 }
343 352
344 int midiEventHolder::findLocalMatches(int notePitch){ 353 int midiEventHolder::findLocalMatches(int notePitch){
345 354
346 //here we find the matches to the new note within appropriate range 355 //here we find the matches to the new note within appropriate range
788 // printf("int %f / %i :: %f ", playedTimeDifference, intervalsToCheck[intervalIndex], possibleDuration); 797 // printf("int %f / %i :: %f ", playedTimeDifference, intervalsToCheck[intervalIndex], possibleDuration);
789 } 798 }
790 } 799 }
791 } 800 }
792 801
802 #pragma mark -Position Update
793 803
794 void midiEventHolder::updatePlayPosition(){ 804 void midiEventHolder::updatePlayPosition(){
795 //timeDifference = ofGetElapsedTimeMillis() - startPlayingTime;//elpased 805 //timeDifference = ofGetElapsedTimeMillis() - startPlayingTime;//elpased
796 806
797 //in actual fact if we are changing the speed of the play position 807 //in actual fact if we are changing the speed of the play position
999 recordedTotalNoteCounterByPitch[tmpPitch] += 1; 1009 recordedTotalNoteCounterByPitch[tmpPitch] += 1;
1000 totalNoteCounterIndex++; 1010 totalNoteCounterIndex++;
1001 } 1011 }
1002 } 1012 }
1003 1013
1014 #pragma mark -Drawing
1004 1015
1005 void midiEventHolder::drawMidiFile(){ 1016 void midiEventHolder::drawMidiFile(){
1006 //ofBackground(80,80,80); 1017 //ofBackground(80,80,80);
1007 1018
1008 //draws midi file on scrolling screen 1019 //draws midi file on scrolling screen
1034 for (int tmpIndex = max(0,minNoteIndexToPrint);tmpIndex < min(maxNoteIndexToPrint, (int)recordedNoteOnMatrix.size());tmpIndex++){ 1045 for (int tmpIndex = max(0,minNoteIndexToPrint);tmpIndex < min(maxNoteIndexToPrint, (int)recordedNoteOnMatrix.size());tmpIndex++){
1035 1046
1036 ofSetColor(255,255,255); 1047 ofSetColor(255,255,255);
1037 if (checkIfMatchedNote(tmpIndex)) 1048 if (checkIfMatchedNote(tmpIndex))
1038 ofSetColor(100,100,100);//0,0,255); 1049 ofSetColor(100,100,100);//0,0,255);
1039 else if(noteOnMatches[tmpIndex]){ 1050 else if(noteOnMatches[tmpIndex] && !saveImage){
1040 ofSetColor(255,0,255);//pink 1051 ofSetHexColor(matchedColor);//pink
1041 } 1052 }
1042 else{ 1053 else{
1043 ofSetColor(255,255,255);//255,255,255); 1054 ofSetColor(255,255,255);//255,255,255);
1044 } 1055 }
1045 1056
1046 //ofSetColor(255,255,255); 1057 //ofSetColor(255,255,255);
1047 if (tmpIndex == bestMatchIndex) 1058 if (tmpIndex == bestMatchIndex && !saveImage)
1048 ofSetColor(255,0,0);//best recent match is in red 1059 ofSetHexColor(bestMatchedColor);//best recent match is in red
1049 1060
1050 // XXX replace ofgetwidth below 1061 // XXX replace ofgetwidth below
1051 //if (tmpIndex >= 0 && tmpIndex < size) 1062 //if (tmpIndex >= 0 && tmpIndex < size)
1052 int xLocation = (float)(recordedNoteOnMatrix[tmpIndex][0] - numberOfScreensIn*ticksPerScreen)*(*screenWidth)/(float)ticksPerScreen; 1063 int xLocation = (float)(recordedNoteOnMatrix[tmpIndex][0] - numberOfScreensIn*ticksPerScreen)*(*screenWidth)/(float)ticksPerScreen;
1053 int duration = (float)(recordedNoteOnMatrix[tmpIndex][3]*(*screenWidth))/(float)ticksPerScreen; 1064 int duration = (float)(recordedNoteOnMatrix[tmpIndex][3]*(*screenWidth))/(float)ticksPerScreen;
1063 // ofLine(xLocation, 0, xLocation, (*screenHeight)); 1074 // ofLine(xLocation, 0, xLocation, (*screenHeight));
1064 1075
1065 //orange line at best estimate 1076 //orange line at best estimate
1066 xLocation = getLocationFromMillis(bayesStruct.bestEstimate); 1077 xLocation = getLocationFromMillis(bayesStruct.bestEstimate);
1067 ofSetColor(250,250,20);//250,100,0); 1078 ofSetColor(250,250,20);//250,100,0);
1079 if (!saveImage)
1068 ofLine(xLocation, 0, xLocation, (*screenHeight)); 1080 ofLine(xLocation, 0, xLocation, (*screenHeight));
1069 1081
1070 1082
1071 /* 1083 /*
1072 //cyan blue - smooth position 1084 //cyan blue - smooth position
1075 ofLine(xLocation, 0, xLocation, (*screenHeight)); 1087 ofLine(xLocation, 0, xLocation, (*screenHeight));
1076 */ 1088 */
1077 //bright green is the causal play position 1089 //bright green is the causal play position
1078 xLocation = getLocationFromMillis(causalPlayPosition);//bayesStruct.tmpBestEstimate 1090 xLocation = getLocationFromMillis(causalPlayPosition);//bayesStruct.tmpBestEstimate
1079 ofSetColor(0,250,0);//250,150, 250,100,0); 1091 ofSetColor(0,250,0);//250,150, 250,100,0);
1080 ofLine(xLocation, 0, xLocation, (*screenHeight)); 1092 if (!saveImage)
1093 ofLine(xLocation, 0, xLocation, (*screenHeight));
1081 1094
1082 //lines where matching window start and end are 1095 //lines where matching window start and end are
1083 ofSetColor(0);//0,100,255); 1096 ofSetColor(0);//0,100,255);
1084 xLocation = getLocationFromMillis(windowStartTime); 1097 xLocation = getLocationFromMillis(windowStartTime);
1085 ofLine(xLocation, 0, xLocation, (*screenHeight)); 1098 ofLine(xLocation, 0, xLocation, (*screenHeight));
1091 1104
1092 int tmpIndex = 0; 1105 int tmpIndex = 0;
1093 while (tmpIndex < measureVector.size() && measureVector[tmpIndex] < (numberOfScreensIn+1)*ticksPerScreen){ 1106 while (tmpIndex < measureVector.size() && measureVector[tmpIndex] < (numberOfScreensIn+1)*ticksPerScreen){
1094 int measureLocation = measureVector[tmpIndex]; 1107 int measureLocation = measureVector[tmpIndex];
1095 int xLocation = (float)(measureLocation - numberOfScreensIn*ticksPerScreen)*(*screenWidth)/(float)ticksPerScreen; 1108 int xLocation = (float)(measureLocation - numberOfScreensIn*ticksPerScreen)*(*screenWidth)/(float)ticksPerScreen;
1096 ofSetColor(155,155,0); 1109 ofSetColor(155,155,155);
1097 ofLine(xLocation, 0, xLocation, (*screenHeight)); 1110 ofLine(xLocation, 0, xLocation, (*screenHeight));
1098 tmpIndex++; 1111 tmpIndex++;
1099 } 1112 }
1100 1113
1101 1114
1105 ofDrawBitmapString(indexString, 20, 40); 1118 ofDrawBitmapString(indexString, 20, 40);
1106 */ 1119 */
1107 } 1120 }
1108 1121
1109 //ofDrawBitmapString(ofToString(timeOffsetForScreen, 1), 20,20); 1122 //ofDrawBitmapString(ofToString(timeOffsetForScreen, 1), 20,20);
1123
1124 if (printInfo){
1110 ofSetColor(255,255,255); 1125 ofSetColor(255,255,255);
1111 ofDrawBitmapString(timeString, 20, 60); 1126 ofDrawBitmapString(timeString, 20, 60);
1112 string diffString = "diff "+ofToString(smoothDifference); 1127 string diffString = "diff "+ofToString(smoothDifference);
1113 diffString += "\ncausal posn: "+ofToString(causalPlayPosition, 0); 1128 diffString += "\ncausal posn: "+ofToString(causalPlayPosition, 0);
1114 diffString += "\nsmooth posn: "+ofToString(smoothPlayPosition, 0); 1129 diffString += "\nsmooth posn: "+ofToString(smoothPlayPosition, 0);
1115 diffString += "\noutput posn: "+ofToString(outputPosition, 0); 1130 diffString += "\noutput posn: "+ofToString(outputPosition, 0);
1116 diffString += "\nbest est: "+ofToString(bayesStruct.bestEstimate, 0); 1131 diffString += "\nbest est: "+ofToString(bayesStruct.bestEstimate, 0);
1117 diffString += "\nlast best est: "+ofToString(bayesStruct.lastBestEstimateUpdateTime, 0); 1132 diffString += "\nlast best est: "+ofToString(bayesStruct.lastBestEstimateUpdateTime, 0);
1118 1133
1119 ofDrawBitmapString(diffString, 20, 140); 1134 ofDrawBitmapString(diffString, 20, 140);
1135 }
1120 1136
1121 //last played pitch 1137 //last played pitch
1138
1122 ofSetColor(0,200,0,50); 1139 ofSetColor(0,200,0,50);
1123 int yLocation = (*screenHeight) - ((lastPlayedPitch - noteMinimum )*(*screenHeight)/ (float)(noteMaximum - noteMinimum)); 1140 int yLocation = (*screenHeight) - ((lastPlayedPitch - noteMinimum )*(*screenHeight)/ (float)(noteMaximum - noteMinimum));
1124 ofRect(0,yLocation, 100, noteHeight); 1141 if (!saveImage)
1142 ofRect(0,yLocation, 100, noteHeight);
1125 1143
1126 1144
1127 1145
1128 } 1146 }
1129 1147
1181 } 1199 }
1182 1200
1183 1201
1184 1202
1185 void midiEventHolder::drawFile(){ 1203 void midiEventHolder::drawFile(){
1186 drawMidiFile(); 1204 drawMidiFile();
1187 1205
1206 if (saveImage){
1207 std::string file = "/Users/andrew/Documents/work/programming/of_preRelease_v007_osx/apps/myOpenFrameworks007/JNMR_MidiFollower/bin/data/FilesOut/cleanMidiLayout.png";
1208 saveImageFile(file);
1209 }
1210
1211
1212 if (printInfo){
1188 ofSetColor(0,0,255); 1213 ofSetColor(0,0,255);
1189 ofDrawBitmapString("period"+ofToString(period, 2), ofGetWidth() - 180, 20); 1214 ofDrawBitmapString("period"+ofToString(period, 2), ofGetWidth() - 180, 20);
1215 }
1190 1216
1191 // bayesStruct.drawArrays(); 1217 // bayesStruct.drawArrays();
1192 1218
1193 // ofSetColor(200,200,0); 1219 // ofSetColor(200,200,0);
1194 // bayesStruct.prior.drawConstrainedVector(0, bayesStruct.prior.arraySize, 400, 800); 1220 // bayesStruct.prior.drawConstrainedVector(0, bayesStruct.prior.arraySize, 400, 800);
1195 1221
1196 //need to draw arrays within correct timescope 1222 //need to draw arrays within correct timescope
1197 if (drawPhaseMode) 1223 if (drawPhaseMode)
1198 bayesStruct.drawArraysRelativeToTimeframe(timeOffsetForScreen, timeOffsetForScreen + getEventTimeMillis(ticksPerScreen)); 1224 bayesStruct.drawArraysRelativeToTimeframe(timeOffsetForScreen, timeOffsetForScreen + getEventTimeMillis(ticksPerScreen));
1199 1225
1200 if (drawTempoMode) 1226 if (drawTempoMode)
1201 bayesStruct.drawTempoArrays(); 1227 bayesStruct.drawTempoArrays();
1202 1228
1229 if (saveImage){
1230 std::string file = "/Users/andrew/Documents/work/programming/of_preRelease_v007_osx/apps/myOpenFrameworks007/JNMR_MidiFollower/bin/data/FilesOut/distbnMidiLayout.png";
1231 saveImageFile(file);
1232 saveImage = false;
1233 }
1203 1234
1204 ofSetColor(0, 0, 0); 1235 ofSetColor(0, 0, 0);
1205 //ofDrawBitmapString(matchString, 20, ofGetHeight() - 20); 1236 //ofDrawBitmapString(matchString, 20, ofGetHeight() - 20);
1206 1237
1207 double confidence = bayesStruct.posterior.getValueAtMillis(mouseX); 1238 double confidence = bayesStruct.posterior.getValueAtMillis(mouseX);
1217 */ 1248 */
1218 1249
1219 //drawInterNoteIntervals(); 1250 //drawInterNoteIntervals();
1220 1251
1221 } 1252 }
1253
1254
1255
1256
1222 1257
1223 void midiEventHolder::drawInterNoteIntervals(){ 1258 void midiEventHolder::drawInterNoteIntervals(){
1224 1259
1225 ofSetColor(0,0,150); 1260 ofSetColor(0,0,150);
1226 int size = interNoteIntervals.size(); 1261 int size = interNoteIntervals.size();
1233 x *= (*screenWidth) / 200.0; 1268 x *= (*screenWidth) / 200.0;
1234 } 1269 }
1235 double h = (double)(y * (*screenHeight)) / numberToShow; 1270 double h = (double)(y * (*screenHeight)) / numberToShow;
1236 ofCircle(x, h, 5); 1271 ofCircle(x, h, 5);
1237 } 1272 }
1273
1274 }
1275
1276 #pragma mark -saveDistributionsAsTextFile
1277
1278 void midiEventHolder::writeAllDistributions(){
1279 std::string file = "/Users/andrew/Documents/work/programming/of_preRelease_v007_osx/apps/myOpenFrameworks007/JNMR_MidiFollower/bin/data/FilesOut/priorDistbnOut.txt";
1280 writeDistribution(bayesStruct.prior, file);
1281 file = "/Users/andrew/Documents/work/programming/of_preRelease_v007_osx/apps/myOpenFrameworks007/JNMR_MidiFollower/bin/data/FilesOut/likelihoodDistbnOut.txt";
1282 writeDistribution(bayesStruct.likelihood, file);
1283 file = "/Users/andrew/Documents/work/programming/of_preRelease_v007_osx/apps/myOpenFrameworks007/JNMR_MidiFollower/bin/data/FilesOut/posteriorDistbnOut.txt";
1284 writeDistribution(bayesStruct.posterior, file);
1285
1286 saveImage = true;
1287
1288 }
1289
1290 void midiEventHolder::saveImageFile(std::string file){
1291 img.grabScreen(0, 0, ofGetWidth(), ofGetHeight());
1292 img.saveImage(file);
1293 }
1294
1295
1296 void midiEventHolder::writeDistribution(DynamicVector& distribution, std::string file){
1297
1298 dataWriter.openFile(file);
1299
1300 double startTimeMillis = timeOffsetForScreen;
1301 double endTimeMillis = timeOffsetForScreen + getEventTimeMillis(ticksPerScreen);
1302
1303 int startArrayIndex = 0;
1304
1305 if (distribution.getIndexInRealTerms(distribution.arraySize-1) > startTimeMillis){
1306 //i.e. the array is on the page
1307
1308 while (distribution.getIndexInRealTerms(startArrayIndex) < startTimeMillis){
1309 startArrayIndex++;
1310 }
1311 }
1312
1313 int endArrayIndex = distribution.arraySize-1;
1314 //could find constraints here
1315 if (distribution.getIndexInRealTerms(distribution.arraySize-1) > endTimeMillis)
1316 endArrayIndex = (floor)((endTimeMillis - distribution.offset)/distribution.scalar);
1317
1318
1319
1320 for (int i = startArrayIndex;i <= endArrayIndex;i++){
1321 dataWriter.writeValue(distribution.getIndexInRealTerms(i), distribution.array[i]);
1322 }
1323 dataWriter.closeFile();
1324
1238 1325
1239 } 1326 }
1240 1327
1241 1328
1242 void midiEventHolder::printInterNoteIntervals(){ 1329 void midiEventHolder::printInterNoteIntervals(){