andrew@36
|
1 /*
|
andrew@36
|
2 * annotations.cpp
|
andrew@36
|
3 * jnmr_MidiFollower
|
andrew@36
|
4 *
|
andrew@36
|
5 * Created by Andrew on 15/12/2011.
|
andrew@36
|
6 * Copyright 2011 QMUL. All rights reserved.
|
andrew@36
|
7 *
|
andrew@36
|
8 */
|
andrew@36
|
9
|
andrew@36
|
10 #include "Annotations.h"
|
andrew@36
|
11
|
andrew@36
|
12 Annotations::Annotations(){
|
andrew@36
|
13
|
andrew@36
|
14 }
|
andrew@36
|
15
|
andrew@38
|
16 void Annotations::readInRWCfile(std::string& pathName){
|
andrew@36
|
17
|
andrew@38
|
18 // "/Users/andrew/Documents/work/MuseScore/RWC/ANNOTATION/RM-C002_annotation+WavPos.csv"
|
andrew@36
|
19 rwcAnnotations.clear();
|
andrew@36
|
20
|
andrew@50
|
21 // printf("ANNOTATIONS : READ FILE %s\n", pathName.c_str());
|
andrew@38
|
22 ifstream file ( pathName.c_str()); // declare file stream: http://www.cplusplus.com/reference/iostream/ifstream/
|
andrew@41
|
23 string value, tmpLine;
|
andrew@41
|
24 stringstream iss;
|
andrew@36
|
25 int count = 0;
|
andrew@36
|
26 Notation n;
|
andrew@36
|
27 while ( file.good() )
|
andrew@36
|
28 {
|
andrew@41
|
29 getline(file, tmpLine);
|
andrew@41
|
30 iss << tmpLine;
|
andrew@41
|
31 // printf("tmp line %s\n", tmpLine.c_str());
|
andrew@41
|
32 while(getline ( iss, value, ',' )){ // read a string until next comma: http://www.cplusplus.com/reference/string/getline/
|
andrew@49
|
33 // cout << string( value, 1, value.length()-2 ); // display value removing the first and the last character from it
|
andrew@49
|
34
|
andrew@41
|
35 string::size_type start = value.find_first_not_of(" ,\t\v\n");
|
andrew@36
|
36 string part = value.substr(start, string::npos);
|
andrew@41
|
37 // printf("%s (%i)\n", part.c_str(), count);
|
andrew@36
|
38 float my_float;
|
andrew@36
|
39 int my_int;
|
andrew@41
|
40 // printf("reading %s\n", part.c_str());
|
andrew@41
|
41 switch (count%7) {
|
andrew@41
|
42
|
andrew@49
|
43 case 0:
|
andrew@41
|
44 my_float = atof(part.c_str());
|
andrew@49
|
45 n.midiTime = my_float;
|
andrew@41
|
46 break;
|
andrew@41
|
47
|
andrew@36
|
48 case 1:
|
andrew@41
|
49
|
andrew@36
|
50 my_float = atof(part.c_str());
|
andrew@42
|
51 // printf("count%i, beat loc float is %f\n", count, my_float);
|
andrew@36
|
52 n.beatLocation = my_float;
|
andrew@36
|
53 break;
|
andrew@36
|
54 case 2:
|
andrew@41
|
55
|
andrew@36
|
56 my_int = atoi(part.c_str());
|
andrew@42
|
57 // printf("count %i, MIDI note float is %i\n", count, my_int);
|
andrew@36
|
58 n.midiNote = my_int;
|
andrew@36
|
59 break;
|
andrew@49
|
60
|
andrew@42
|
61
|
andrew@49
|
62
|
andrew@49
|
63 case 6:
|
andrew@49
|
64 my_float = atof(part.c_str());
|
andrew@49
|
65 n.eventTime = my_float;
|
andrew@49
|
66 rwcAnnotations.push_back(n);
|
andrew@49
|
67 // printf("count%i, event time float is %f\n", count, my_float);
|
andrew@49
|
68 break;
|
andrew@49
|
69
|
andrew@49
|
70
|
andrew@36
|
71 default:
|
andrew@36
|
72 break;
|
andrew@49
|
73
|
andrew@49
|
74
|
andrew@36
|
75 }
|
andrew@41
|
76 count++;
|
andrew@41
|
77 }//end while reading line
|
andrew@41
|
78 iss.clear();
|
andrew@41
|
79
|
andrew@41
|
80
|
andrew@41
|
81 }//end while
|
andrew@36
|
82
|
andrew@49
|
83 // printAnnotations();
|
andrew@49
|
84 // printf("There are %i annotations\n", (int)rwcAnnotations.size());
|
andrew@36
|
85
|
andrew@36
|
86 }
|
andrew@36
|
87
|
andrew@36
|
88 void Annotations::printAnnotations(){
|
andrew@38
|
89 //rwcAnnotations.size()
|
andrew@43
|
90 for (int i = 0;i < min(100, (int)rwcAnnotations.size());i++){
|
andrew@49
|
91 printf("Annotation: Loaded Beat position %f, note %i happens at time %f midi played time %f \n",
|
andrew@49
|
92 rwcAnnotations[i].beatLocation, rwcAnnotations[i].midiNote, rwcAnnotations[i].eventTime,
|
andrew@49
|
93 rwcAnnotations[i].midiTime);
|
andrew@36
|
94 }
|
andrew@36
|
95 }
|
andrew@36
|
96
|
andrew@38
|
97 /*
|
andrew@38
|
98 ifstream fp ("/Users/andrew/Documents/work/MuseScore/RWC/ANNOTATION/RM-C002_annotation+WavPos.csv");
|
andrew@38
|
99 //FILE *fp = fopen("/Users/andrew/Documents/work/MuseScore/RWC/ANNOTATION/RM-C002_annotation+WavPos.csv", "r");
|
andrew@38
|
100 int x, y, z;
|
andrew@38
|
101 float a, b, c, d;
|
andrew@38
|
102 std::vector<float> vec;
|
andrew@38
|
103
|
andrew@38
|
104 while (fscanf(fp, "%f, %f, %d, %f, %d, %d, %f", &a, &b, &x, &c, &y, &z, &d) == 6) {
|
andrew@38
|
105 printf("a is %f", a);
|
andrew@38
|
106 }
|
andrew@38
|
107 fclose(fp);
|
andrew@38
|
108 */
|