-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpttypes.cpp
95 lines (79 loc) · 2.59 KB
/
pttypes.cpp
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
#include "pttypes.hpp"
std::ostream &operator<<(std::ostream &o, const EVERECORD &p) {
return o << (int)p.unit_no << " " << (int)p.kind << "\t" << p.clock << "\t"
<< p.value;
}
std::ostream &operator<<(std::ostream &o, const Press &p) {
return o << "(" << p.vel << ", " << p.length << ")";
}
std::vector<Woice> Woice::get_woices(const pxtnService &pxtn) {
std::vector<Woice> woices(pxtn.Woice_Num());
for (int i = 0; i < pxtn.Woice_Num(); ++i) {
const pxtnWoice *woice = pxtn.Woice_Get(i);
if (woice->is_name_buf()) {
std::string name(woice->get_name_buf(nullptr));
// some naive string parsing to match (D|M)[0-9]+.*
if (name.length() >= 2 && (name[0] == 'D' || name[0] == 'M')) {
if (isdigit(name[1])) {
int num = std::stoi(name.substr(1));
if (num >= 0 && num < 128) {
woices[i].num = num;
woices[i].drum = (name[0] == 'D');
}
}
}
}
}
return woices;
}
std::vector<Unit> Unit::get_units(const pxtnService &pxtn) {
std::vector<Unit> units(pxtn.Unit_Num());
for (const EVERECORD *p = pxtn.evels->get_Records(); p; p = p->next) {
if (p->clock >= pxtn.master->get_last_clock() &&
pxtn.master->get_last_clock() > 0)
continue;
switch (p->kind) {
case EVENTKIND_ON: {
auto &hist = units[p->unit_no].presses;
hist.emplace(p->clock, Press{}).first->second.length = p->value;
break;
}
case EVENTKIND_VELOCITY: {
auto &hist = units[p->unit_no].presses;
hist.emplace(p->clock, Press{}).first->second.vel = p->value;
break;
}
case EVENTKIND_KEY:
units[p->unit_no].notes[p->clock] = p->value / 256 - 27;
break;
case EVENTKIND_TUNING: {
auto &hist = units[p->unit_no].tunings;
float value = reinterpret_cast<const float &>(p->value);
units[p->unit_no].tunings[p->clock] = std::log2(value) * 12;
break;
}
case EVENTKIND_PORTAMENT:
units[p->unit_no].portas[p->clock] = p->value;
break;
case EVENTKIND_VOLUME:
units[p->unit_no].volume[p->clock] = p->value;
break;
case EVENTKIND_PAN_VOLUME:
units[p->unit_no].pan_v[p->clock] = p->value;
break;
case EVENTKIND_PAN_TIME:
units[p->unit_no].pan_t[p->clock] = p->value;
break;
case EVENTKIND_VOICENO:
units[p->unit_no].voice[p->clock] = p->value;
break;
case EVENTKIND_GROUPNO:
units[p->unit_no].group[p->clock] = p->value;
break;
default:
std::cerr << "warning: unhandled event - " << *p << std::endl;
break;
}
}
return units;
}