86 |
|
|
87 |
// fills a mapping array for a given control change number |
// fills a mapping array for a given control change number |
88 |
int LookupTable::fillMapArr(const std::vector<Region*>& regions, |
int LookupTable::fillMapArr(const std::vector<Region*>& regions, |
89 |
int cc, int* a) { |
int cc, int* a, int triggercc) { |
90 |
std::set<int> s; |
std::set<int> s; |
91 |
s.insert(0); |
s.insert(0); |
92 |
s.insert(128); |
s.insert(128); |
93 |
for (std::vector<Region*>::const_iterator i = regions.begin() ; |
for (std::vector<Region*>::const_iterator i = regions.begin() ; |
94 |
i != regions.end() ; ++i) { |
i != regions.end() ; ++i) { |
95 |
s.insert((*i)->locc[cc]); |
int lo = (*i)->locc[cc]; |
96 |
s.insert((*i)->hicc[cc] + 1); |
int hi = (*i)->hicc[cc]; |
97 |
|
if (cc == triggercc) { |
98 |
|
lo = std::max(lo, (*i)->on_locc[cc]); |
99 |
|
hi = std::min(hi, (*i)->on_hicc[cc]); |
100 |
|
} |
101 |
|
|
102 |
|
s.insert(lo); |
103 |
|
s.insert(hi + 1); |
104 |
} |
} |
105 |
|
|
106 |
int j = 0; |
int j = 0; |
122 |
int offset = 0; |
int offset = 0; |
123 |
int dim; |
int dim; |
124 |
for (dim = 0 ; qargs[dim] ; dim++) { |
for (dim = 0 ; qargs[dim] ; dim++) { |
125 |
offset += mapArr[dim][q.*qargs[dim]]; |
offset += mapArr[dim][int8_t(q.*qargs[dim])]; |
126 |
} |
} |
127 |
for (int cc = 0 ; ccargs[cc] >= 0 ; cc++, dim++) { |
for (int cc = 0 ; ccargs[cc] >= 0 ; cc++, dim++) { |
128 |
offset += mapArr[dim][q.cc[ccargs[cc]]]; |
offset += mapArr[dim][q.cc[ccargs[cc]]]; |
132 |
|
|
133 |
// recursively fills the region array with regions |
// recursively fills the region array with regions |
134 |
void LookupTable::fillRegionArr(const int* len, Region* region, |
void LookupTable::fillRegionArr(const int* len, Region* region, |
135 |
std::vector<int>::size_type dim, int j) { |
std::vector<int>::size_type dim, int j, |
136 |
|
int triggercc) { |
137 |
if (dim == dims.size() + ccs.size()) { |
if (dim == dims.size() + ccs.size()) { |
138 |
regionArr[j].add(region); |
regionArr[j].add(region); |
139 |
} else if (dim < dims.size()) { |
} else if (dim < dims.size()) { |
143 |
if (hi == -1) hi = 127; |
if (hi == -1) hi = 127; |
144 |
for (int l = mapArr[dim][region->*dimDefs[d].lo] ; |
for (int l = mapArr[dim][region->*dimDefs[d].lo] ; |
145 |
l <= mapArr[dim][hi] ; l++) { |
l <= mapArr[dim][hi] ; l++) { |
146 |
fillRegionArr(len, region, dim + 1, j * len[dim] + l); |
fillRegionArr(len, region, dim + 1, j * len[dim] + l, |
147 |
|
triggercc); |
148 |
} |
} |
149 |
} else { |
} else { |
150 |
int cc = ccs[dim - dims.size()]; |
int cc = ccs[dim - dims.size()]; |
151 |
for (int l = mapArr[dim][region->locc[cc]] ; |
int lo = region->locc[cc]; |
152 |
l <= mapArr[dim][region->hicc[cc]] ; l++) { |
int hi = region->hicc[cc]; |
153 |
fillRegionArr(len, region, dim + 1, j * len[dim] + l); |
if (cc == triggercc) { |
154 |
|
lo = std::max(lo, region->on_locc[cc]); |
155 |
|
hi = std::min(hi, region->on_hicc[cc]); |
156 |
|
} |
157 |
|
for (int l = mapArr[dim][lo] ; l <= mapArr[dim][hi] ; l++) { |
158 |
|
fillRegionArr(len, region, dim + 1, j * len[dim] + l, |
159 |
|
triggercc); |
160 |
} |
} |
161 |
} |
} |
162 |
} |
} |
163 |
|
|
164 |
|
|
165 |
LookupTable::LookupTable(const Instrument* instrument) { |
LookupTable::LookupTable(const Instrument* instrument, int triggercc) { |
166 |
const std::vector<Region*>& regions = instrument->regions; |
std::vector<Region*> regions; |
167 |
|
|
168 |
|
// copy the interesting regions |
169 |
|
for (std::vector<Region*>::const_iterator i = |
170 |
|
instrument->regions.begin() ; |
171 |
|
i != instrument->regions.end() ; ++i) { |
172 |
|
|
173 |
|
if (triggercc == -1) { |
174 |
|
if ((*i)->lokey >= 0) { |
175 |
|
regions.push_back(*i); |
176 |
|
} |
177 |
|
} else { |
178 |
|
if ((*i)->hikey < 0 && |
179 |
|
(*i)->on_locc[triggercc] >= 0 && |
180 |
|
(*i)->on_hicc[triggercc] >= 0) { |
181 |
|
regions.push_back(*i); |
182 |
|
} |
183 |
|
} |
184 |
|
} |
185 |
|
|
186 |
|
dmsg(2,("\nregions before filter: %d, after: %d\n", |
187 |
|
instrument->regions.size(), regions.size())); |
188 |
|
|
189 |
// find dimensions used by the instrument |
// find dimensions used by the instrument |
190 |
for (int dim = 0 ; dimDefs[dim].lo ; dim++) { |
for (int dim = 0 ; dimDefs[dim].lo ; dim++) { |
191 |
for (std::vector<Region*>::const_iterator i = regions.begin() ; |
for (std::vector<Region*>::const_iterator i = regions.begin() ; |
192 |
i != regions.end() ; ++i) { |
i != regions.end() ; ++i) { |
193 |
if ((*i)->*dimDefs[dim].lo != dimDefs[dim].min || |
|
194 |
(*i)->*dimDefs[dim].hi != dimDefs[dim].max) { |
if ((triggercc == -1 || dimDefs[dim].lo != &Region::lokey) && |
195 |
|
((*i)->*dimDefs[dim].lo != dimDefs[dim].min || |
196 |
|
(*i)->*dimDefs[dim].hi != dimDefs[dim].max)) { |
197 |
dims.push_back(dim); |
dims.push_back(dim); |
198 |
break; |
break; |
199 |
} |
} |
200 |
} |
} |
201 |
} |
} |
202 |
|
|
|
dmsg(2,("\n")); |
|
|
|
|
203 |
// create and fill the qargs array with pointers to Query |
// create and fill the qargs array with pointers to Query |
204 |
// members |
// members |
205 |
qargs = new const uint8_t Query::*[dims.size() + 1]; |
qargs = new const uint8_t Query::*[dims.size() + 1]; |
213 |
for (int cc = 0 ; cc < 128 ; cc++) { |
for (int cc = 0 ; cc < 128 ; cc++) { |
214 |
for (std::vector<Region*>::const_iterator i = regions.begin() ; |
for (std::vector<Region*>::const_iterator i = regions.begin() ; |
215 |
i != regions.end() ; ++i) { |
i != regions.end() ; ++i) { |
216 |
if ((*i)->locc[cc] > 0 || |
int lo = (*i)->locc[cc]; |
217 |
((*i)->hicc[cc] != 127 && (*i)->hicc[cc] != -1)) { |
int hi = (*i)->hicc[cc]; // TODO == -1 ? 127 : (*i)->hicc[cc]; |
218 |
|
if (cc == triggercc) { |
219 |
|
lo = std::max(lo, (*i)->on_locc[cc]); |
220 |
|
hi = std::min(hi, (*i)->on_hicc[cc]); |
221 |
|
} |
222 |
|
if (lo > 0 || hi != 127) { |
223 |
ccs.push_back(cc); |
ccs.push_back(cc); |
224 |
break; |
break; |
225 |
} |
} |
249 |
int max = dimDefs[*dimi].max == -1 ? 127 : dimDefs[*dimi].max; |
int max = dimDefs[*dimi].max == -1 ? 127 : dimDefs[*dimi].max; |
250 |
mapArr[dim] = new int[max - min + 1] - min; |
mapArr[dim] = new int[max - min + 1] - min; |
251 |
len[dim] = fillMapArr(regions, dimDefs[*dimi].lo, dimDefs[*dimi].hi, |
len[dim] = fillMapArr(regions, dimDefs[*dimi].lo, dimDefs[*dimi].hi, |
252 |
min, max, mapArr[dim]); |
min, max, mapArr[dim]); |
253 |
size *= len[dim]; |
size *= len[dim]; |
254 |
dim++; |
dim++; |
255 |
} |
} |
257 |
for (std::vector<int>::const_iterator cci = ccs.begin() ; |
for (std::vector<int>::const_iterator cci = ccs.begin() ; |
258 |
cci != ccs.end() ; ++cci) { |
cci != ccs.end() ; ++cci) { |
259 |
mapArr[dim] = new int[128]; |
mapArr[dim] = new int[128]; |
260 |
len[dim] = fillMapArr(regions, *cci, mapArr[dim]); |
len[dim] = fillMapArr(regions, *cci, mapArr[dim], triggercc); |
261 |
size *= len[dim]; |
size *= len[dim]; |
262 |
dim++; |
dim++; |
263 |
} |
} |
271 |
|
|
272 |
for (std::vector<Region*>::const_iterator i = regions.begin() ; |
for (std::vector<Region*>::const_iterator i = regions.begin() ; |
273 |
i != regions.end() ; ++i) { |
i != regions.end() ; ++i) { |
274 |
fillRegionArr(len, *i, 0, 0); |
fillRegionArr(len, *i, 0, 0, triggercc); |
275 |
} |
} |
276 |
|
|
277 |
// multiply the offsets in the mapping arrays so simple |
// multiply the offsets in the mapping arrays so simple |