67 |
Definition::Definition() : |
Definition::Definition() : |
68 |
locc(128), hicc(128), start_locc(128), start_hicc(128), stop_locc(128), |
locc(128), hicc(128), start_locc(128), start_hicc(128), stop_locc(128), |
69 |
stop_hicc(128), on_locc(128), on_hicc(128), delay_oncc(128), delay_samples_oncc(128), |
stop_hicc(128), on_locc(128), on_hicc(128), delay_oncc(128), delay_samples_oncc(128), |
70 |
offset_oncc(128), amp_velcurve_(128), gain_oncc(128), xfin_locc(128), xfin_hicc(128), |
offset_oncc(128), amp_velcurve(128), gain_oncc(128), xfin_locc(128), xfin_hicc(128), |
71 |
xfout_locc(128), xfout_hicc(128), cutoff_oncc(128), cutoff2_oncc(128), cutoff_smoothcc(128), |
xfout_locc(128), xfout_hicc(128), cutoff_oncc(128), cutoff2_oncc(128), cutoff_smoothcc(128), |
72 |
cutoff2_smoothcc(128), cutoff_stepcc(128), cutoff2_stepcc(128), cutoff_curvecc(128), |
cutoff2_smoothcc(128), cutoff_stepcc(128), cutoff2_stepcc(128), cutoff_curvecc(128), |
73 |
cutoff2_curvecc(128), resonance_oncc(128), resonance2_oncc(128), resonance_smoothcc(128), |
cutoff2_curvecc(128), resonance_oncc(128), resonance2_oncc(128), resonance_smoothcc(128), |
89 |
Region::Region() |
Region::Region() |
90 |
{ |
{ |
91 |
pSample = NULL; |
pSample = NULL; |
92 |
|
seq_counter = 1; |
93 |
} |
} |
94 |
|
|
95 |
Region::~Region() |
Region::~Region() |
122 |
Region::OnKey(uint8_t chan, uint8_t key, uint8_t vel, |
Region::OnKey(uint8_t chan, uint8_t key, uint8_t vel, |
123 |
int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, |
int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, |
124 |
uint8_t prog, float rand, trigger_t trig, uint8_t* cc, |
uint8_t prog, float rand, trigger_t trig, uint8_t* cc, |
125 |
float timer, uint8_t seq, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key) |
float timer, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key) |
126 |
{ |
{ |
127 |
// chan (MIDI channel) |
// chan (MIDI channel) |
128 |
// key (MIDI note) |
// key (MIDI note) |
138 |
// cc (all 128 CC values) |
// cc (all 128 CC values) |
139 |
|
|
140 |
// timer (time since previous region in the group was triggered) |
// timer (time since previous region in the group was triggered) |
|
// seq (the state of the region sequence counter) |
|
141 |
// sw (the state of region key switches, 128 possible values) |
// sw (the state of region key switches, 128 possible values) |
142 |
// last_sw_key (the last key pressed in the key switch range) |
// last_sw_key (the last key pressed in the key switch range) |
143 |
// prev_sw_key (the previous note value) |
// prev_sw_key (the previous note value) |
147 |
key >= lokey && key <= hikey && |
key >= lokey && key <= hikey && |
148 |
vel >= lovel && vel <= hivel && |
vel >= lovel && vel <= hivel && |
149 |
bend >= lobend && bend <= hibend && |
bend >= lobend && bend <= hibend && |
150 |
bpm >= lobpm && bpm <= hibpm && |
bpm >= lobpm && bpm < hibpm && |
151 |
chanaft >= lochanaft && chanaft <= hichanaft && |
chanaft >= lochanaft && chanaft <= hichanaft && |
152 |
polyaft >= lopolyaft && polyaft <= hipolyaft && |
polyaft >= lopolyaft && polyaft <= hipolyaft && |
153 |
prog >= loprog && prog <= hiprog && |
prog >= loprog && prog <= hiprog && |
154 |
rand >= lorand && rand <= hirand && |
rand >= lorand && rand < hirand && |
155 |
timer >= lotimer && timer <= hitimer && |
timer >= lotimer && timer <= hitimer && |
|
seq == seq_position && |
|
156 |
|
|
157 |
( (sw_lokey == -1 || sw_hikey == -1 || sw_last == -1) || |
( (sw_lokey == -1 || sw_hikey == -1 || sw_last == -1) || |
158 |
((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (last_sw_key == sw_last) : true) ) && |
((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (last_sw_key == sw_last) : true) ) && |
176 |
return false; |
return false; |
177 |
} |
} |
178 |
|
|
179 |
return true; |
// seq_position has to be checked last, so we know that we |
180 |
|
// increment the right counter |
181 |
|
is_triggered = (seq_counter == seq_position); |
182 |
|
seq_counter = (seq_counter % seq_length) + 1; |
183 |
|
|
184 |
|
return is_triggered; |
185 |
} |
} |
186 |
|
|
187 |
bool |
bool |
188 |
Region::OnControl(uint8_t chan, uint8_t cont, uint8_t val, |
Region::OnControl(uint8_t chan, uint8_t cont, uint8_t val, |
189 |
int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, |
int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, |
190 |
uint8_t prog, float rand, trigger_t trig, uint8_t* cc, |
uint8_t prog, float rand, trigger_t trig, uint8_t* cc, |
191 |
float timer, uint8_t seq, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key) |
float timer, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key) |
192 |
{ |
{ |
193 |
// chan (MIDI channel) |
// chan (MIDI channel) |
194 |
// cont (MIDI controller) |
// cont (MIDI controller) |
204 |
// cc (all CC values) |
// cc (all CC values) |
205 |
|
|
206 |
// timer (time since previous region in the group was triggered) |
// timer (time since previous region in the group was triggered) |
|
// seq (the state of the region sequence counter) |
|
207 |
// sw (the state of region key switches, 128 possible values) |
// sw (the state of region key switches, 128 possible values) |
208 |
// last_sw_key (the last key pressed in the key switch range) |
// last_sw_key (the last key pressed in the key switch range) |
209 |
// prev_sw_key (the previous note value) |
// prev_sw_key (the previous note value) |
213 |
((val >= on_locc[cont] && val <= on_hicc[cont]) || |
((val >= on_locc[cont] && val <= on_hicc[cont]) || |
214 |
(val >= start_locc[cont] && val <= start_hicc[cont])) && |
(val >= start_locc[cont] && val <= start_hicc[cont])) && |
215 |
bend >= lobend && bend <= hibend && |
bend >= lobend && bend <= hibend && |
216 |
bpm >= lobpm && bpm <= hibpm && |
bpm >= lobpm && bpm < hibpm && |
217 |
chanaft >= lochanaft && chanaft <= hichanaft && |
chanaft >= lochanaft && chanaft <= hichanaft && |
218 |
polyaft >= lopolyaft && polyaft <= hipolyaft && |
polyaft >= lopolyaft && polyaft <= hipolyaft && |
219 |
prog >= loprog && prog <= hiprog && |
prog >= loprog && prog <= hiprog && |
220 |
rand >= lorand && rand <= hirand && |
rand >= lorand && rand < hirand && |
221 |
timer >= lotimer && timer <= hitimer && |
timer >= lotimer && timer <= hitimer && |
|
seq == seq_position && |
|
222 |
|
|
223 |
( (sw_lokey == -1 || sw_hikey == -1 || sw_last == -1) || |
( (sw_lokey == -1 || sw_hikey == -1 || sw_last == -1) || |
224 |
((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (last_sw_key == sw_last) : true) ) && |
((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (last_sw_key == sw_last) : true) ) && |
289 |
uint8_t chan, uint8_t key, uint8_t vel, |
uint8_t chan, uint8_t key, uint8_t vel, |
290 |
int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, |
int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, |
291 |
uint8_t prog, float rand, trigger_t trig, uint8_t* cc, |
uint8_t prog, float rand, trigger_t trig, uint8_t* cc, |
292 |
float timer, uint8_t seq, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key |
float timer, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key |
293 |
) { |
) { |
294 |
std::vector<Region*> v; |
std::vector<Region*> v; |
295 |
for (int i = 0; i < regions.size(); i++) { |
for (int i = 0; i < regions.size(); i++) { |
296 |
if (regions[i]->OnKey ( |
if (regions[i]->OnKey ( |
297 |
chan, key, vel, bend, bpm, chanaft, polyaft, prog, |
chan, key, vel, bend, bpm, chanaft, polyaft, prog, |
298 |
rand, trig, cc, timer, seq, sw, last_sw_key, prev_sw_key) |
rand, trig, cc, timer, sw, last_sw_key, prev_sw_key) |
299 |
) { v.push_back(regions[i]); } |
) { v.push_back(regions[i]); } |
300 |
} |
} |
301 |
|
|
471 |
offset_oncc[i].unset(); |
offset_oncc[i].unset(); |
472 |
|
|
473 |
// amplifier |
// amplifier |
474 |
amp_velcurve_[i] = 0; //fixme: 20 log (127^2 / i^2) |
amp_velcurve[i] = -1; |
475 |
gain_oncc[i] = 0; |
gain_oncc[i] = 0; |
476 |
xfin_locc[i] = 0; |
xfin_locc[i] = 0; |
477 |
xfin_hicc[i] = 0; |
xfin_hicc[i] = 0; |
535 |
pitcheg_decay = 0; |
pitcheg_decay = 0; |
536 |
pitcheg_sustain = 100; // in percentage |
pitcheg_sustain = 100; // in percentage |
537 |
pitcheg_release = 0; |
pitcheg_release = 0; |
538 |
|
|
539 |
|
amplfo_delay = 0; |
540 |
|
amplfo_fade = 0; |
541 |
|
amplfo_freq = 0; |
542 |
|
amplfo_depth = 0; |
543 |
|
|
544 |
|
fillfo_delay = 0; |
545 |
|
fillfo_fade = 0; |
546 |
|
fillfo_freq = 0; |
547 |
|
fillfo_depth = 0; |
548 |
|
|
549 |
|
pitchlfo_delay = 0; |
550 |
|
pitchlfo_fade = 0; |
551 |
|
pitchlfo_freq = 0; |
552 |
|
pitchlfo_depth = 0; |
553 |
} |
} |
554 |
|
|
555 |
Region* |
Region* |
635 |
region->amp_keytrack = amp_keytrack; |
region->amp_keytrack = amp_keytrack; |
636 |
region->amp_keycenter = amp_keycenter; |
region->amp_keycenter = amp_keycenter; |
637 |
region->amp_veltrack = amp_veltrack; |
region->amp_veltrack = amp_veltrack; |
638 |
region->amp_velcurve_ = amp_velcurve_; |
region->amp_velcurve = amp_velcurve; |
639 |
region->amp_random = amp_random; |
region->amp_random = amp_random; |
640 |
region->rt_decay = rt_decay; |
region->rt_decay = rt_decay; |
641 |
region->gain_oncc = gain_oncc; |
region->gain_oncc = gain_oncc; |
757 |
region->pitcheg_sustain = pitcheg_sustain; |
region->pitcheg_sustain = pitcheg_sustain; |
758 |
region->pitcheg_release = pitcheg_release; |
region->pitcheg_release = pitcheg_release; |
759 |
|
|
760 |
|
region->amplfo_delay = amplfo_delay; |
761 |
|
region->amplfo_fade = amplfo_fade; |
762 |
|
region->amplfo_freq = amplfo_freq; |
763 |
|
region->amplfo_depth = amplfo_depth; |
764 |
|
|
765 |
|
region->fillfo_delay = fillfo_delay; |
766 |
|
region->fillfo_fade = fillfo_fade; |
767 |
|
region->fillfo_freq = fillfo_freq; |
768 |
|
region->fillfo_depth = fillfo_depth; |
769 |
|
|
770 |
|
region->pitchlfo_delay = pitchlfo_delay; |
771 |
|
region->pitchlfo_fade = pitchlfo_fade; |
772 |
|
region->pitchlfo_freq = pitchlfo_freq; |
773 |
|
region->pitchlfo_depth = pitchlfo_depth; |
774 |
|
|
775 |
return region; |
return region; |
776 |
} |
} |
777 |
|
|
889 |
} else { |
} else { |
890 |
std::cerr << "Invalid key switch range: " << low << " - " << high << std::endl; |
std::cerr << "Invalid key switch range: " << low << " - " << high << std::endl; |
891 |
} |
} |
892 |
|
|
893 |
|
// create velocity response curve |
894 |
|
int prev = 0; |
895 |
|
float prevvalue = 0; |
896 |
|
for (int v = 0 ; v < 128 ; v++) { |
897 |
|
if (pRegion->amp_velcurve[v] >= 0) { |
898 |
|
float step = (pRegion->amp_velcurve[v] - prevvalue) / (v - prev); |
899 |
|
for ( ; prev < v ; prev++) { |
900 |
|
pRegion->amp_velcurve[prev] = prevvalue; |
901 |
|
prevvalue += step; |
902 |
|
} |
903 |
|
} |
904 |
|
} |
905 |
|
if (prev) { |
906 |
|
float step = (1 - prevvalue) / (127 - prev); |
907 |
|
for ( ; prev < 128 ; prev++) { |
908 |
|
pRegion->amp_velcurve[prev] = prevvalue; |
909 |
|
prevvalue += step; |
910 |
|
} |
911 |
|
} else { |
912 |
|
// default curve |
913 |
|
for (int v = 0 ; v < 128 ; v++) { |
914 |
|
pRegion->amp_velcurve[v] = v * v / (127.0 * 127.0); |
915 |
|
} |
916 |
|
} |
917 |
|
// apply amp_veltrack |
918 |
|
float offset = -pRegion->amp_veltrack; |
919 |
|
if (offset <= 0) offset += 100; |
920 |
|
for (int v = 0 ; v < 128 ; v++) { |
921 |
|
pRegion->amp_velcurve[v] = |
922 |
|
(offset + pRegion->amp_veltrack * pRegion->amp_velcurve[v]) / 100; |
923 |
|
} |
924 |
} |
} |
925 |
} |
} |
926 |
|
|
1211 |
else if ("eq2_vel2gain" == key) pCurDef->eq2_vel2gain = ToFloat(value); |
else if ("eq2_vel2gain" == key) pCurDef->eq2_vel2gain = ToFloat(value); |
1212 |
else if ("eq3_vel2gain" == key) pCurDef->eq3_vel2gain = ToFloat(value); |
else if ("eq3_vel2gain" == key) pCurDef->eq3_vel2gain = ToFloat(value); |
1213 |
|
|
1214 |
//fixme: parse amp_velcurve_N |
else if (sscanf(key.c_str(), "amp_velcurve_%d", &x)) { |
1215 |
|
pCurDef->amp_velcurve[x] = ToFloat(value); |
1216 |
|
} |
1217 |
|
|
1218 |
// CCs |
// CCs |
1219 |
else if (key.find("cc") != std::string::npos) |
else if (key.find("cc") != std::string::npos) |
1311 |
else if ("pitcheg_decay" == key) pCurDef->pitcheg_decay = ToFloat(value); |
else if ("pitcheg_decay" == key) pCurDef->pitcheg_decay = ToFloat(value); |
1312 |
else if ("pitcheg_sustain" == key) pCurDef->pitcheg_sustain = ToFloat(value); |
else if ("pitcheg_sustain" == key) pCurDef->pitcheg_sustain = ToFloat(value); |
1313 |
else if ("pitcheg_release" == key) pCurDef->pitcheg_release = ToFloat(value); |
else if ("pitcheg_release" == key) pCurDef->pitcheg_release = ToFloat(value); |
1314 |
|
|
1315 |
|
// v1 LFO |
1316 |
|
else if ("amplfo_delay" == key) pCurDef->amplfo_delay = ToFloat(value); |
1317 |
|
else if ("amplfo_fade" == key) pCurDef->amplfo_fade = ToFloat(value); |
1318 |
|
else if ("amplfo_freq" == key) pCurDef->amplfo_freq = ToFloat(value); |
1319 |
|
else if ("amplfo_depth" == key) pCurDef->amplfo_depth = ToFloat(value); |
1320 |
|
else if ("fillfo_delay" == key) pCurDef->fillfo_delay = ToFloat(value); |
1321 |
|
else if ("fillfo_fade" == key) pCurDef->fillfo_fade = ToFloat(value); |
1322 |
|
else if ("fillfo_freq" == key) pCurDef->fillfo_freq = ToFloat(value); |
1323 |
|
else if ("fillfo_depth" == key) pCurDef->fillfo_depth = ToFloat(value); |
1324 |
|
else if ("pitchlfo_delay" == key) pCurDef->pitchlfo_delay = ToFloat(value); |
1325 |
|
else if ("pitchlfo_fade" == key) pCurDef->pitchlfo_fade = ToFloat(value); |
1326 |
|
else if ("pitchlfo_freq" == key) pCurDef->pitchlfo_freq = ToFloat(value); |
1327 |
|
else if ("pitchlfo_depth" == key) pCurDef->pitchlfo_depth = ToInt(value); |
1328 |
|
|
1329 |
else { |
else { |
1330 |
std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
1331 |
} |
} |