blob: ccb9b3c214ee8a1ada6aa3a44b38491f165f39b5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#include "midimap.h"
#include <stdio.h>
#include <stdlib.h>
MidiMap::MidiMap()
{
}
bool MidiMap::load(std::string file)
{
FILE *fp = fopen(file.c_str(), "r");
if(!fp) return false;
std::string line;
while(!feof(fp)) {
int c = fgetc(fp);
if(c == '\n') {
if(line != "") {
int from = atoi(line.substr(0, line.find('=')).c_str());
int to = atoi(line.substr(line.find('=')+1,
line.length()-line.find('=')+1).c_str());
map[from] = to;
}
line = "";
} else {
if((c >= '0' && c <= '9') || c == ',' || c == '-' || c == '=') {
line += (char)c;
} else {
if(c != '\t' && c != ' ') return false;
}
}
}
return true;
}
int MidiMap::lookup(int note)
{
return map[note];
}
#ifdef TEST_MIDIMAP
#include "test.h"
TEST_BEGIN;
TEST_END;
#endif
|