142 |
return is_triggered; |
return is_triggered; |
143 |
} |
} |
144 |
|
|
|
bool |
|
|
Region::OnControl(uint8_t chan, uint8_t cont, uint8_t val, |
|
|
int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, |
|
|
uint8_t prog, float rand, trigger_t trig, uint8_t* cc, |
|
|
float timer, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key) |
|
|
{ |
|
|
// chan (MIDI channel) |
|
|
// cont (MIDI controller) |
|
|
// val (MIDI controller value) |
|
|
|
|
|
// bend (MIDI pitch bend) |
|
|
// bpm (host BPM) |
|
|
// chanaft (MIDI channel pressure) |
|
|
// polyaft (MIDI polyphonic aftertouch) |
|
|
// prog (MIDI program change) |
|
|
// rand (generated random number) |
|
|
// trigger (how it was triggered) |
|
|
// cc (all CC values) |
|
|
|
|
|
// timer (time since previous region in the group was triggered) |
|
|
// sw (the state of region key switches, 128 possible values) |
|
|
// last_sw_key (the last key pressed in the key switch range) |
|
|
// prev_sw_key (the previous note value) |
|
|
|
|
|
bool is_triggered = ( |
|
|
chan >= lochan && chan <= hichan && |
|
|
((val >= on_locc[cont] && val <= on_hicc[cont]) || |
|
|
(val >= start_locc[cont] && val <= start_hicc[cont])) && |
|
|
bend >= lobend && bend <= hibend && |
|
|
bpm >= lobpm && bpm < hibpm && |
|
|
chanaft >= lochanaft && chanaft <= hichanaft && |
|
|
polyaft >= lopolyaft && polyaft <= hipolyaft && |
|
|
prog >= loprog && prog <= hiprog && |
|
|
rand >= lorand && rand < hirand && |
|
|
timer >= lotimer && timer <= hitimer && |
|
|
|
|
|
( sw_last == -1 || |
|
|
((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (last_sw_key == sw_last) : false) ) && |
|
|
|
|
|
( sw_down == -1 || |
|
|
((sw_down >= sw_lokey && (sw_hikey == -1 || sw_down <= sw_hikey)) ? (sw[sw_down]) : false) ) && |
|
|
|
|
|
( sw_up == -1 || |
|
|
((sw_up >= sw_lokey && (sw_hikey == -1 || sw_up <= sw_hikey)) ? (!sw[sw_up]) : true) ) && |
|
|
|
|
|
( sw_previous == -1 || |
|
|
prev_sw_key == sw_previous ) && |
|
|
|
|
|
((trigger & trig) != 0) |
|
|
); |
|
|
|
|
|
if (!is_triggered) |
|
|
return false; |
|
|
|
|
|
for (int i = 0; i < 128; ++i) |
|
|
{ |
|
|
if (locc[i] != -1 && hicc[i] != -1 && !(cc[i] >= locc[i] && cc[i] <= hicc[i])) |
|
|
return false; |
|
|
} |
|
|
|
|
|
return true; |
|
|
} |
|
|
|
|
145 |
Articulation* |
Articulation* |
146 |
Region::GetArticulation(int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, uint8_t* cc) |
Region::GetArticulation(int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, uint8_t* cc) |
147 |
{ |
{ |
181 |
delete regions[i]; |
delete regions[i]; |
182 |
} |
} |
183 |
delete pLookupTable; |
delete pLookupTable; |
184 |
|
for (int i = 0 ; i < 128 ; i++) { |
185 |
|
delete pLookupTableCC[i]; |
186 |
|
} |
187 |
} |
} |
188 |
|
|
189 |
void Query::search(const Instrument* pInstrument) { |
void Query::search(const Instrument* pInstrument) { |
191 |
regionIndex = 0; |
regionIndex = 0; |
192 |
} |
} |
193 |
|
|
194 |
|
void Query::search(const Instrument* pInstrument, int triggercc) { |
195 |
|
pRegionList = &pInstrument->pLookupTableCC[triggercc]->query(*this); |
196 |
|
regionIndex = 0; |
197 |
|
} |
198 |
|
|
199 |
Region* Query::next() { |
Region* Query::next() { |
200 |
for ( ; regionIndex < pRegionList->size() ; regionIndex++) { |
for ( ; regionIndex < pRegionList->size() ; regionIndex++) { |
201 |
if ((*pRegionList)[regionIndex]->OnKey(*this)) { |
if ((*pRegionList)[regionIndex]->OnKey(*this)) { |
777 |
::sfz::Region* pRegion = _instrument->regions[i]; |
::sfz::Region* pRegion = _instrument->regions[i]; |
778 |
int low = pRegion->lokey; |
int low = pRegion->lokey; |
779 |
int high = pRegion->hikey; |
int high = pRegion->hikey; |
780 |
if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) { |
if (low != -1) { // lokey -1 means region doesn't play on note-on |
781 |
std::cerr << "Invalid key range: " << low << " - " << high << std::endl; |
// hikey -1 is the same as no limit, except that it |
782 |
} else { |
// also enables on_locc/on_hicc |
783 |
for (int j = low; j <= high; j++) _instrument->KeyBindings[j] = true; |
if (high == -1) high = 127; |
784 |
|
if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) { |
785 |
|
std::cerr << "Invalid key range: " << low << " - " << high << std::endl; |
786 |
|
} else { |
787 |
|
for (int j = low; j <= high; j++) _instrument->KeyBindings[j] = true; |
788 |
|
} |
789 |
} |
} |
790 |
|
|
791 |
// get keyswitches |
// get keyswitches |
840 |
} |
} |
841 |
|
|
842 |
_instrument->pLookupTable = new LookupTable(_instrument); |
_instrument->pLookupTable = new LookupTable(_instrument); |
843 |
|
|
844 |
|
// create separate lookup tables for controller triggered |
845 |
|
// regions, one for each CC |
846 |
|
for (int i = 0 ; i < 128 ; i++) { |
847 |
|
_instrument->pLookupTableCC[i] = new LookupTable(_instrument, i); |
848 |
|
} |
849 |
} |
} |
850 |
|
|
851 |
File::~File() |
File::~File() |
1269 |
case 'g': i = 7; break; |
case 'g': i = 7; break; |
1270 |
case 'a': i = 9; break; |
case 'a': i = 9; break; |
1271 |
case 'b': i = 11; break; |
case 'b': i = 11; break; |
1272 |
|
case '-': if (s == "-1") return -1; |
1273 |
default: |
default: |
1274 |
std::cerr << "Not a note: " << s << std::endl; |
std::cerr << "Not a note: " << s << std::endl; |
1275 |
return 0; |
return 0; |