andrew@36: /* andrew@36: * annotations.cpp andrew@36: * jnmr_MidiFollower andrew@36: * andrew@36: * Created by Andrew on 15/12/2011. andrew@36: * Copyright 2011 QMUL. All rights reserved. andrew@36: * andrew@36: */ andrew@36: andrew@36: #include "Annotations.h" andrew@36: andrew@36: Annotations::Annotations(){ andrew@36: andrew@36: } andrew@36: andrew@38: void Annotations::readInRWCfile(std::string& pathName){ andrew@36: andrew@38: // "/Users/andrew/Documents/work/MuseScore/RWC/ANNOTATION/RM-C002_annotation+WavPos.csv" andrew@36: rwcAnnotations.clear(); andrew@36: andrew@50: // printf("ANNOTATIONS : READ FILE %s\n", pathName.c_str()); andrew@38: ifstream file ( pathName.c_str()); // declare file stream: http://www.cplusplus.com/reference/iostream/ifstream/ andrew@41: string value, tmpLine; andrew@41: stringstream iss; andrew@36: int count = 0; andrew@36: Notation n; andrew@36: while ( file.good() ) andrew@36: { andrew@41: getline(file, tmpLine); andrew@41: iss << tmpLine; andrew@41: // printf("tmp line %s\n", tmpLine.c_str()); andrew@41: while(getline ( iss, value, ',' )){ // read a string until next comma: http://www.cplusplus.com/reference/string/getline/ andrew@49: // cout << string( value, 1, value.length()-2 ); // display value removing the first and the last character from it andrew@49: andrew@41: string::size_type start = value.find_first_not_of(" ,\t\v\n"); andrew@36: string part = value.substr(start, string::npos); andrew@41: // printf("%s (%i)\n", part.c_str(), count); andrew@36: float my_float; andrew@36: int my_int; andrew@41: // printf("reading %s\n", part.c_str()); andrew@41: switch (count%7) { andrew@41: andrew@49: case 0: andrew@41: my_float = atof(part.c_str()); andrew@49: n.midiTime = my_float; andrew@41: break; andrew@41: andrew@36: case 1: andrew@41: andrew@36: my_float = atof(part.c_str()); andrew@42: // printf("count%i, beat loc float is %f\n", count, my_float); andrew@36: n.beatLocation = my_float; andrew@36: break; andrew@36: case 2: andrew@41: andrew@36: my_int = atoi(part.c_str()); andrew@42: // printf("count %i, MIDI note float is %i\n", count, my_int); andrew@36: n.midiNote = my_int; andrew@36: break; andrew@49: andrew@42: andrew@49: andrew@49: case 6: andrew@49: my_float = atof(part.c_str()); andrew@49: n.eventTime = my_float; andrew@49: rwcAnnotations.push_back(n); andrew@49: // printf("count%i, event time float is %f\n", count, my_float); andrew@49: break; andrew@49: andrew@49: andrew@36: default: andrew@36: break; andrew@49: andrew@49: andrew@36: } andrew@41: count++; andrew@41: }//end while reading line andrew@41: iss.clear(); andrew@41: andrew@41: andrew@41: }//end while andrew@36: andrew@49: // printAnnotations(); andrew@49: // printf("There are %i annotations\n", (int)rwcAnnotations.size()); andrew@36: andrew@36: } andrew@36: andrew@36: void Annotations::printAnnotations(){ andrew@38: //rwcAnnotations.size() andrew@43: for (int i = 0;i < min(100, (int)rwcAnnotations.size());i++){ andrew@49: printf("Annotation: Loaded Beat position %f, note %i happens at time %f midi played time %f \n", andrew@49: rwcAnnotations[i].beatLocation, rwcAnnotations[i].midiNote, rwcAnnotations[i].eventTime, andrew@49: rwcAnnotations[i].midiTime); andrew@36: } andrew@36: } andrew@36: andrew@38: /* andrew@38: ifstream fp ("/Users/andrew/Documents/work/MuseScore/RWC/ANNOTATION/RM-C002_annotation+WavPos.csv"); andrew@38: //FILE *fp = fopen("/Users/andrew/Documents/work/MuseScore/RWC/ANNOTATION/RM-C002_annotation+WavPos.csv", "r"); andrew@38: int x, y, z; andrew@38: float a, b, c, d; andrew@38: std::vector vec; andrew@38: andrew@38: while (fscanf(fp, "%f, %f, %d, %f, %d, %d, %f", &a, &b, &x, &c, &y, &z, &d) == 6) { andrew@38: printf("a is %f", a); andrew@38: } andrew@38: fclose(fp); andrew@38: */