3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2008 Anders Dahnielson <anders@dahnielson.com> * |
* Copyright (C) 2008 Anders Dahnielson <anders@dahnielson.com> * |
6 |
* Copyright (C) 2009 - 2010 Anders Dahnielson and Grigor Iliev * |
* Copyright (C) 2009 - 2011 Anders Dahnielson and Grigor Iliev * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
32 |
#include "../../common/File.h" |
#include "../../common/File.h" |
33 |
#include "../../common/Path.h" |
#include "../../common/Path.h" |
34 |
#include "../../common/global_private.h" |
#include "../../common/global_private.h" |
35 |
|
#include "LookupTable.h" |
36 |
|
|
37 |
namespace sfz |
namespace sfz |
38 |
{ |
{ |
39 |
|
template <typename T> T check(std::string name, T min, T max, T val) { |
40 |
|
if (val < min) { |
41 |
|
std::cerr << "sfz: The value of opcode '" << name; |
42 |
|
std::cerr << "' is below the minimum allowed value (min=" << min << "): " << val << std::endl; |
43 |
|
val = min; |
44 |
|
} |
45 |
|
if (val > max) { |
46 |
|
std::cerr << "sfz: The value of opcode '" << name; |
47 |
|
std::cerr << "' is above the maximum allowed value (max=" << max << "): " << val << std::endl; |
48 |
|
val = max; |
49 |
|
} |
50 |
|
|
51 |
|
return val; |
52 |
|
} |
53 |
|
|
54 |
Sample* SampleManager::FindSample(std::string samplePath) { |
Sample* SampleManager::FindSample(std::string samplePath, uint offset, int end) { |
55 |
std::map<Sample*, std::set<Region*> >::iterator it = sampleMap.begin(); |
std::map<Sample*, std::set<Region*> >::iterator it = sampleMap.begin(); |
56 |
for (; it != sampleMap.end(); it++) { |
for (; it != sampleMap.end(); it++) { |
57 |
if (it->first->GetFile() == samplePath) return it->first; |
if (it->first->GetFile() == samplePath) { |
58 |
|
/* Because the start of the sample is cached in RAM we treat |
59 |
|
* same sample with different offset as different samples |
60 |
|
* // TODO: Ignore offset when the whole sample is cached in RAM? |
61 |
|
*/ |
62 |
|
if (it->first->Offset == offset && it->first->End == end) return it->first; |
63 |
|
} |
64 |
} |
} |
65 |
|
|
66 |
return NULL; |
return NULL; |
110 |
Sample* Region::GetSample(bool create) |
Sample* Region::GetSample(bool create) |
111 |
{ |
{ |
112 |
if(pSample == NULL && create) { |
if(pSample == NULL && create) { |
113 |
Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample); |
uint i = offset ? *offset : 0; |
114 |
|
int e = end ? *end : -2; |
115 |
|
Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample, i, e); |
116 |
if (sf != NULL) pSample = sf; // Reuse already created sample |
if (sf != NULL) pSample = sf; // Reuse already created sample |
117 |
else pSample = new Sample(sample); |
else pSample = new Sample(sample, false, i, e); |
118 |
GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this); |
GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this); |
119 |
} |
} |
120 |
return pSample; |
return pSample; |
131 |
} |
} |
132 |
|
|
133 |
bool Region::OnKey(const Query& q) { |
bool Region::OnKey(const Query& q) { |
134 |
|
// As the region comes from a LookupTable search on the query, |
135 |
|
// the following parameters are not checked here: chan, key, |
136 |
|
// vel, chanaft, polyaft, prog, sw_previous, cc. They are all |
137 |
|
// handled by the lookup table. |
138 |
bool is_triggered( |
bool is_triggered( |
|
q.chan >= lochan && q.chan <= hichan && |
|
|
q.key >= lokey && q.key <= hikey && |
|
|
q.vel >= lovel && q.vel <= hivel && |
|
139 |
q.bend >= lobend && q.bend <= hibend && |
q.bend >= lobend && q.bend <= hibend && |
140 |
q.bpm >= lobpm && q.bpm < hibpm && |
q.bpm >= lobpm && q.bpm < hibpm && |
|
q.chanaft >= lochanaft && q.chanaft <= hichanaft && |
|
|
q.polyaft >= lopolyaft && q.polyaft <= hipolyaft && |
|
|
q.prog >= loprog && q.prog <= hiprog && |
|
141 |
q.rand >= lorand && q.rand < hirand && |
q.rand >= lorand && q.rand < hirand && |
142 |
q.timer >= lotimer && q.timer <= hitimer && |
q.timer >= lotimer && q.timer <= hitimer && |
143 |
|
|
150 |
( sw_up == -1 || |
( sw_up == -1 || |
151 |
((sw_up >= sw_lokey && (sw_hikey == -1 || sw_up <= sw_hikey)) ? (!q.sw[sw_up]) : true) ) && |
((sw_up >= sw_lokey && (sw_hikey == -1 || sw_up <= sw_hikey)) ? (!q.sw[sw_up]) : true) ) && |
152 |
|
|
|
( sw_previous == -1 || |
|
|
q.prev_sw_key == sw_previous ) && |
|
|
|
|
153 |
((trigger & q.trig) != 0) |
((trigger & q.trig) != 0) |
154 |
); |
); |
155 |
|
|
156 |
if (!is_triggered) |
if (!is_triggered) |
157 |
return false; |
return false; |
158 |
|
|
|
for (int i = 0; i < 128; ++i) { |
|
|
if (locc[i] != -1 && hicc[i] != -1 && !(q.cc[i] >= locc[i] && q.cc[i] <= hicc[i])) |
|
|
return false; |
|
|
} |
|
|
|
|
159 |
// seq_position has to be checked last, so we know that we |
// seq_position has to be checked last, so we know that we |
160 |
// increment the right counter |
// increment the right counter |
161 |
is_triggered = (seq_counter == seq_position); |
is_triggered = (seq_counter == seq_position); |
164 |
return is_triggered; |
return is_triggered; |
165 |
} |
} |
166 |
|
|
|
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; |
|
|
} |
|
|
|
|
167 |
Articulation* |
Articulation* |
168 |
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) |
169 |
{ |
{ |
171 |
} |
} |
172 |
|
|
173 |
bool Region::HasLoop() { |
bool Region::HasLoop() { |
174 |
bool b = loop_mode == ::sfz::LOOP_CONTINUOUS || loop_mode == ::sfz::LOOP_SUSTAIN; // TODO: ONE_SHOT mode |
bool b = loop_mode == ::sfz::LOOP_UNSET ? pSample->GetLoops() : |
175 |
|
(loop_mode == ::sfz::LOOP_CONTINUOUS || loop_mode == ::sfz::LOOP_SUSTAIN); |
176 |
return b && GetLoopStart() && GetLoopEnd() && GetLoopEnd() > GetLoopStart(); |
return b && GetLoopStart() && GetLoopEnd() && GetLoopEnd() > GetLoopStart(); |
177 |
} |
} |
178 |
|
|
179 |
uint Region::GetLoopStart() { |
uint Region::GetLoopStart() { |
180 |
return (!loop_start) ? 0 : *loop_start; // TODO: use sample loop when loop_start not defined |
return (!loop_start) ? pSample->GetLoopStart() : *loop_start; |
181 |
} |
} |
182 |
|
|
183 |
uint Region::GetLoopEnd() { |
uint Region::GetLoopEnd() { |
184 |
return (!loop_end) ? 0 : *loop_end; // TODO: use sample loop when loop_end not defined |
return (!loop_end) ? pSample->GetLoopEnd() : *loop_end; |
185 |
} |
} |
186 |
|
|
187 |
uint Region::GetLoopCount() { |
uint Region::GetLoopCount() { |
195 |
{ |
{ |
196 |
this->name = name; |
this->name = name; |
197 |
this->pSampleManager = pSampleManager ? pSampleManager : this; |
this->pSampleManager = pSampleManager ? pSampleManager : this; |
198 |
|
pLookupTable = 0; |
199 |
|
|
200 |
|
// The first 6 curves are defined internally (actually 7 with the one at index 0) |
201 |
|
Curve c; |
202 |
|
for (int i = 0; i < 128; i++) c.v[i] = i / 127.0f; |
203 |
|
curves.add(c); curves.add(c); curves.add(c); curves.add(c); |
204 |
|
curves.add(c); curves.add(c); curves.add(c); |
205 |
|
/////// |
206 |
} |
} |
207 |
|
|
208 |
Instrument::~Instrument() |
Instrument::~Instrument() |
209 |
{ |
{ |
210 |
for(int i = 0; i < regions.size(); i++) { |
for (int i = 0; i < regions.size(); i++) { |
211 |
delete (regions[i]); |
delete regions[i]; |
212 |
|
} |
213 |
|
delete pLookupTable; |
214 |
|
for (int i = 0 ; i < 128 ; i++) { |
215 |
|
delete pLookupTableCC[i]; |
216 |
} |
} |
|
regions.clear(); |
|
217 |
} |
} |
218 |
|
|
219 |
Query::Query(const Instrument& instrument) { |
void Query::search(const Instrument* pInstrument) { |
220 |
i = instrument.regions.begin(); |
pRegionList = &pInstrument->pLookupTable->query(*this); |
221 |
regions_end = instrument.regions.end(); |
regionIndex = 0; |
222 |
|
} |
223 |
|
|
224 |
|
void Query::search(const Instrument* pInstrument, int triggercc) { |
225 |
|
pRegionList = &pInstrument->pLookupTableCC[triggercc]->query(*this); |
226 |
|
regionIndex = 0; |
227 |
} |
} |
228 |
|
|
229 |
Region* Query::next() { |
Region* Query::next() { |
230 |
while (i != regions_end) { |
for ( ; regionIndex < pRegionList->size() ; regionIndex++) { |
231 |
if ((*i++)->OnKey(*this)) return *i; |
if ((*pRegionList)[regionIndex]->OnKey(*this)) { |
232 |
|
return (*pRegionList)[regionIndex++]; |
233 |
|
} |
234 |
} |
} |
235 |
return 0; |
return 0; |
236 |
} |
} |
303 |
trigger = TRIGGER_ATTACK; |
trigger = TRIGGER_ATTACK; |
304 |
|
|
305 |
group = 0; |
group = 0; |
306 |
off_by.unset(); |
off_by = 0; |
307 |
off_mode = OFF_FAST; |
off_mode = OFF_FAST; |
308 |
|
|
309 |
// sample player |
// sample player |
314 |
end.unset(); |
end.unset(); |
315 |
loop_crossfade.unset(); |
loop_crossfade.unset(); |
316 |
offset.unset(); offset_random.unset(); |
offset.unset(); offset_random.unset(); |
317 |
loop_mode = NO_LOOP; |
loop_mode = LOOP_UNSET; |
318 |
loop_start.unset(); loop_end.unset(); |
loop_start.unset(); loop_end.unset(); |
319 |
sync_beats.unset(); sync_offset.unset(); |
sync_beats.unset(); sync_offset.unset(); |
320 |
|
|
321 |
// amplifier |
// amplifier |
322 |
volume = 0; |
volume = 0; |
323 |
|
volume_oncc.clear(); |
324 |
|
volume_curvecc.clear(); |
325 |
|
volume_smoothcc.clear(); |
326 |
pan = 0; |
pan = 0; |
327 |
width = 100; |
width = 100; |
328 |
position = 0; |
position = 0; |
443 |
eq1_gain_oncc.set(i, 0); |
eq1_gain_oncc.set(i, 0); |
444 |
eq2_gain_oncc.set(i, 0); |
eq2_gain_oncc.set(i, 0); |
445 |
eq3_gain_oncc.set(i, 0); |
eq3_gain_oncc.set(i, 0); |
446 |
|
|
447 |
|
pitchlfo_depthcc.set(i, 0); |
448 |
} |
} |
449 |
|
cutoff_cc = 0; |
450 |
|
|
451 |
eg.clear(); |
eg.clear(); |
452 |
|
lfos.clear(); |
453 |
|
|
454 |
// deprecated |
// deprecated |
455 |
ampeg_delay = 0; |
ampeg_delay = 0; |
457 |
ampeg_attack = 0; |
ampeg_attack = 0; |
458 |
ampeg_hold = 0; |
ampeg_hold = 0; |
459 |
ampeg_decay = 0; |
ampeg_decay = 0; |
460 |
ampeg_sustain = 100; // in percentage |
ampeg_sustain = -1; // in percentage |
461 |
ampeg_release = 0; |
ampeg_release = 0; |
462 |
|
|
463 |
|
ampeg_vel2delay = 0; |
464 |
|
ampeg_vel2attack = 0; |
465 |
|
ampeg_vel2hold = 0; |
466 |
|
ampeg_vel2decay = 0; |
467 |
|
ampeg_vel2sustain = 0; |
468 |
|
ampeg_vel2release = 0; |
469 |
|
|
470 |
|
ampeg_delaycc.clear(); |
471 |
|
ampeg_startcc.clear(); |
472 |
|
ampeg_attackcc.clear(); |
473 |
|
ampeg_holdcc.clear(); |
474 |
|
ampeg_decaycc.clear(); |
475 |
|
ampeg_sustaincc.clear(); |
476 |
|
ampeg_releasecc.clear(); |
477 |
|
|
478 |
fileg_delay = 0; |
fileg_delay = 0; |
479 |
fileg_start = 0; //in percentage |
fileg_start = 0; //in percentage |
480 |
fileg_attack = 0; |
fileg_attack = 0; |
483 |
fileg_sustain = 100; // in percentage |
fileg_sustain = 100; // in percentage |
484 |
fileg_release = 0; |
fileg_release = 0; |
485 |
|
|
486 |
|
fileg_vel2delay = 0; |
487 |
|
fileg_vel2attack = 0; |
488 |
|
fileg_vel2hold = 0; |
489 |
|
fileg_vel2decay = 0; |
490 |
|
fileg_vel2sustain = 0; |
491 |
|
fileg_vel2release = 0; |
492 |
|
fileg_depth = 0; |
493 |
|
|
494 |
pitcheg_delay = 0; |
pitcheg_delay = 0; |
495 |
pitcheg_start = 0; //in percentage |
pitcheg_start = 0; //in percentage |
496 |
pitcheg_attack = 0; |
pitcheg_attack = 0; |
498 |
pitcheg_decay = 0; |
pitcheg_decay = 0; |
499 |
pitcheg_sustain = 100; // in percentage |
pitcheg_sustain = 100; // in percentage |
500 |
pitcheg_release = 0; |
pitcheg_release = 0; |
501 |
|
pitcheg_depth = 0; |
502 |
|
|
503 |
|
pitcheg_vel2delay = 0; |
504 |
|
pitcheg_vel2attack = 0; |
505 |
|
pitcheg_vel2hold = 0; |
506 |
|
pitcheg_vel2decay = 0; |
507 |
|
pitcheg_vel2sustain = 0; |
508 |
|
pitcheg_vel2release = 0; |
509 |
|
|
510 |
amplfo_delay = 0; |
amplfo_delay = 0; |
511 |
amplfo_fade = 0; |
amplfo_fade = 0; |
512 |
amplfo_freq = 0; |
amplfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */ |
513 |
amplfo_depth = 0; |
amplfo_depth = 0; |
514 |
|
amplfo_depthcc.clear(); |
515 |
|
amplfo_freqcc.clear(); |
516 |
|
|
517 |
fillfo_delay = 0; |
fillfo_delay = 0; |
518 |
fillfo_fade = 0; |
fillfo_fade = 0; |
519 |
fillfo_freq = 0; |
fillfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */ |
520 |
fillfo_depth = 0; |
fillfo_depth = 0; |
521 |
|
fillfo_depthcc.clear(); |
522 |
|
fillfo_freqcc.clear(); |
523 |
|
|
524 |
pitchlfo_delay = 0; |
pitchlfo_delay = 0; |
525 |
pitchlfo_fade = 0; |
pitchlfo_fade = 0; |
526 |
pitchlfo_freq = 0; |
pitchlfo_freq = -1; /* -1 is used to determine whether the LFO was initialized */ |
527 |
pitchlfo_depth = 0; |
pitchlfo_depth = 0; |
528 |
|
pitchlfo_freqcc.clear(); |
529 |
} |
} |
530 |
|
|
531 |
Region* |
Region* |
605 |
|
|
606 |
// amplifier |
// amplifier |
607 |
region->volume = volume; |
region->volume = volume; |
608 |
|
region->volume_oncc = volume_oncc; |
609 |
|
region->volume_curvecc = volume_curvecc; |
610 |
|
region->volume_smoothcc = volume_smoothcc; |
611 |
region->pan = pan; |
region->pan = pan; |
612 |
region->width = width; |
region->width = width; |
613 |
region->position = position; |
region->position = position; |
649 |
region->fil_type = fil_type; |
region->fil_type = fil_type; |
650 |
region->cutoff = cutoff; |
region->cutoff = cutoff; |
651 |
region->cutoff_oncc = cutoff_oncc; |
region->cutoff_oncc = cutoff_oncc; |
652 |
|
region->cutoff_cc = cutoff_cc; |
653 |
region->cutoff_smoothcc = cutoff_smoothcc; |
region->cutoff_smoothcc = cutoff_smoothcc; |
654 |
region->cutoff_stepcc = cutoff_stepcc; |
region->cutoff_stepcc = cutoff_stepcc; |
655 |
region->cutoff_curvecc = cutoff_curvecc; |
region->cutoff_curvecc = cutoff_curvecc; |
721 |
region->ampeg_sustain = ampeg_sustain; |
region->ampeg_sustain = ampeg_sustain; |
722 |
region->ampeg_release = ampeg_release; |
region->ampeg_release = ampeg_release; |
723 |
|
|
724 |
|
region->ampeg_vel2delay = ampeg_vel2delay; |
725 |
|
region->ampeg_vel2attack = ampeg_vel2attack; |
726 |
|
region->ampeg_vel2hold = ampeg_vel2hold; |
727 |
|
region->ampeg_vel2decay = ampeg_vel2decay; |
728 |
|
region->ampeg_vel2sustain = ampeg_vel2sustain; |
729 |
|
region->ampeg_vel2release = ampeg_vel2release; |
730 |
|
|
731 |
|
region->ampeg_delaycc = ampeg_delaycc; |
732 |
|
region->ampeg_startcc = ampeg_startcc; |
733 |
|
region->ampeg_attackcc = ampeg_attackcc; |
734 |
|
region->ampeg_holdcc = ampeg_holdcc; |
735 |
|
region->ampeg_decaycc = ampeg_decaycc; |
736 |
|
region->ampeg_sustaincc = ampeg_sustaincc; |
737 |
|
region->ampeg_releasecc = ampeg_releasecc; |
738 |
|
|
739 |
region->fileg_delay = fileg_delay; |
region->fileg_delay = fileg_delay; |
740 |
region->fileg_start = fileg_start; |
region->fileg_start = fileg_start; |
741 |
region->fileg_attack = fileg_attack; |
region->fileg_attack = fileg_attack; |
743 |
region->fileg_decay = fileg_decay; |
region->fileg_decay = fileg_decay; |
744 |
region->fileg_sustain = fileg_sustain; |
region->fileg_sustain = fileg_sustain; |
745 |
region->fileg_release = fileg_release; |
region->fileg_release = fileg_release; |
746 |
|
region->fileg_depth = fileg_depth; |
747 |
|
|
748 |
|
region->fileg_vel2delay = fileg_vel2delay; |
749 |
|
region->fileg_vel2attack = fileg_vel2attack; |
750 |
|
region->fileg_vel2hold = fileg_vel2hold; |
751 |
|
region->fileg_vel2decay = fileg_vel2decay; |
752 |
|
region->fileg_vel2sustain = fileg_vel2sustain; |
753 |
|
region->fileg_vel2release = fileg_vel2release; |
754 |
|
|
755 |
region->pitcheg_delay = pitcheg_delay; |
region->pitcheg_delay = pitcheg_delay; |
756 |
region->pitcheg_start = pitcheg_start; |
region->pitcheg_start = pitcheg_start; |
759 |
region->pitcheg_decay = pitcheg_decay; |
region->pitcheg_decay = pitcheg_decay; |
760 |
region->pitcheg_sustain = pitcheg_sustain; |
region->pitcheg_sustain = pitcheg_sustain; |
761 |
region->pitcheg_release = pitcheg_release; |
region->pitcheg_release = pitcheg_release; |
762 |
|
region->pitcheg_depth = pitcheg_depth; |
763 |
|
|
764 |
|
region->pitcheg_vel2delay = pitcheg_vel2delay; |
765 |
|
region->pitcheg_vel2attack = pitcheg_vel2attack; |
766 |
|
region->pitcheg_vel2hold = pitcheg_vel2hold; |
767 |
|
region->pitcheg_vel2decay = pitcheg_vel2decay; |
768 |
|
region->pitcheg_vel2sustain = pitcheg_vel2sustain; |
769 |
|
region->pitcheg_vel2release = pitcheg_vel2release; |
770 |
|
|
771 |
region->amplfo_delay = amplfo_delay; |
region->amplfo_delay = amplfo_delay; |
772 |
region->amplfo_fade = amplfo_fade; |
region->amplfo_fade = amplfo_fade; |
773 |
region->amplfo_freq = amplfo_freq; |
region->amplfo_freq = amplfo_freq; |
774 |
region->amplfo_depth = amplfo_depth; |
region->amplfo_depth = amplfo_depth; |
775 |
|
|
776 |
|
region->amplfo_depthcc = amplfo_depthcc; |
777 |
|
region->amplfo_freqcc = amplfo_freqcc; |
778 |
|
|
779 |
region->fillfo_delay = fillfo_delay; |
region->fillfo_delay = fillfo_delay; |
780 |
region->fillfo_fade = fillfo_fade; |
region->fillfo_fade = fillfo_fade; |
781 |
region->fillfo_freq = fillfo_freq; |
region->fillfo_freq = fillfo_freq; |
782 |
region->fillfo_depth = fillfo_depth; |
region->fillfo_depth = fillfo_depth; |
783 |
|
|
784 |
|
region->fillfo_depthcc = fillfo_depthcc; |
785 |
|
region->fillfo_freqcc = fillfo_freqcc; |
786 |
|
|
787 |
region->pitchlfo_delay = pitchlfo_delay; |
region->pitchlfo_delay = pitchlfo_delay; |
788 |
region->pitchlfo_fade = pitchlfo_fade; |
region->pitchlfo_fade = pitchlfo_fade; |
789 |
region->pitchlfo_freq = pitchlfo_freq; |
region->pitchlfo_freq = pitchlfo_freq; |
790 |
region->pitchlfo_depth = pitchlfo_depth; |
region->pitchlfo_depth = pitchlfo_depth; |
791 |
|
|
792 |
|
region->pitchlfo_depthcc = pitchlfo_depthcc; |
793 |
|
region->pitchlfo_freqcc = pitchlfo_freqcc; |
794 |
|
|
795 |
|
region->eg = eg; |
796 |
|
region->lfos = lfos; |
797 |
|
|
798 |
return region; |
return region; |
799 |
} |
} |
897 |
::sfz::Region* pRegion = _instrument->regions[i]; |
::sfz::Region* pRegion = _instrument->regions[i]; |
898 |
int low = pRegion->lokey; |
int low = pRegion->lokey; |
899 |
int high = pRegion->hikey; |
int high = pRegion->hikey; |
900 |
if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) { |
if (low != -1) { // lokey -1 means region doesn't play on note-on |
901 |
std::cerr << "Invalid key range: " << low << " - " << high << std::endl; |
// hikey -1 is the same as no limit, except that it |
902 |
} else { |
// also enables on_locc/on_hicc |
903 |
for (int j = low; j <= high; j++) _instrument->KeyBindings[j] = true; |
if (high == -1) high = 127; |
904 |
|
if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) { |
905 |
|
std::cerr << "Invalid key range: " << low << " - " << high << std::endl; |
906 |
|
} else { |
907 |
|
for (int j = low; j <= high; j++) _instrument->KeyBindings[j] = true; |
908 |
|
} |
909 |
} |
} |
910 |
|
|
911 |
// get keyswitches |
// get keyswitches |
958 |
} |
} |
959 |
} |
} |
960 |
} |
} |
961 |
|
|
962 |
|
_instrument->pLookupTable = new LookupTable(_instrument); |
963 |
|
|
964 |
|
// create separate lookup tables for controller triggered |
965 |
|
// regions, one for each CC |
966 |
|
for (int i = 0 ; i < 128 ; i++) { |
967 |
|
_instrument->pLookupTableCC[i] = new LookupTable(_instrument, i); |
968 |
|
} |
969 |
|
|
970 |
|
for (int i = 0; i < _instrument->regions.size(); i++) { |
971 |
|
Region* r = _instrument->regions[i]; |
972 |
|
|
973 |
|
copyCurves(r->volume_curvecc, r->volume_oncc); |
974 |
|
r->volume_curvecc.clear(); |
975 |
|
|
976 |
|
copySmoothValues(r->volume_smoothcc, r->volume_oncc); |
977 |
|
r->volume_smoothcc.clear(); |
978 |
|
|
979 |
|
for (int j = 0; j < r->lfos.size(); j++) { |
980 |
|
copySmoothValues(r->lfos[j].volume_smoothcc, r->lfos[j].volume_oncc); |
981 |
|
r->lfos[j].volume_smoothcc.clear(); |
982 |
|
|
983 |
|
copySmoothValues(r->lfos[j].freq_smoothcc, r->lfos[j].freq_oncc); |
984 |
|
r->lfos[j].freq_smoothcc.clear(); |
985 |
|
|
986 |
|
copySmoothValues(r->lfos[j].pitch_smoothcc, r->lfos[j].pitch_oncc); |
987 |
|
r->lfos[j].pitch_smoothcc.clear(); |
988 |
|
|
989 |
|
copySmoothValues(r->lfos[j].pan_smoothcc, r->lfos[j].pan_oncc); |
990 |
|
r->lfos[j].pan_smoothcc.clear(); |
991 |
|
|
992 |
|
copySmoothValues(r->lfos[j].cutoff_smoothcc, r->lfos[j].cutoff_oncc); |
993 |
|
r->lfos[j].cutoff_smoothcc.clear(); |
994 |
|
|
995 |
|
copySmoothValues(r->lfos[j].resonance_smoothcc, r->lfos[j].resonance_oncc); |
996 |
|
r->lfos[j].resonance_smoothcc.clear(); |
997 |
|
} |
998 |
|
} |
999 |
} |
} |
1000 |
|
|
1001 |
File::~File() |
File::~File() |
1009 |
{ |
{ |
1010 |
return _instrument; |
return _instrument; |
1011 |
} |
} |
1012 |
|
|
1013 |
|
void File::copyCurves(LinuxSampler::ArrayList<CC>& curves, LinuxSampler::ArrayList<CC>& dest) { |
1014 |
|
for (int i = 0; i < curves.size(); i++) { |
1015 |
|
for (int j = 0; j < dest.size(); j++) { |
1016 |
|
if (curves[i].Controller == dest[j].Controller) { |
1017 |
|
dest[j].Curve = curves[i].Curve; |
1018 |
|
} |
1019 |
|
} |
1020 |
|
} |
1021 |
|
} |
1022 |
|
|
1023 |
|
void File::copySmoothValues(LinuxSampler::ArrayList<CC>& smooths, LinuxSampler::ArrayList<CC>& dest) { |
1024 |
|
for (int i = 0; i < smooths.size(); i++) { |
1025 |
|
for (int j = 0; j < dest.size(); j++) { |
1026 |
|
if (smooths[i].Controller == dest[j].Controller) { |
1027 |
|
dest[j].Smooth = smooths[i].Smooth; |
1028 |
|
} |
1029 |
|
} |
1030 |
|
} |
1031 |
|
} |
1032 |
|
|
1033 |
void |
void |
1034 |
File::push_header(std::string token) |
File::push_header(std::string token) |
1054 |
octave_offset = 0; |
octave_offset = 0; |
1055 |
note_offset = 0; |
note_offset = 0; |
1056 |
} |
} |
1057 |
|
else if (token == "<curve>") |
1058 |
|
{ |
1059 |
|
_current_section = CURVE; |
1060 |
|
_instrument->curves.add(Curve()); |
1061 |
|
_current_curve = &_instrument->curves[_instrument->curves.size() - 1]; |
1062 |
|
} |
1063 |
else |
else |
1064 |
{ |
{ |
1065 |
_current_section = UNKNOWN; |
_current_section = UNKNOWN; |
1076 |
std::string::size_type delimiter_index = token.find('='); |
std::string::size_type delimiter_index = token.find('='); |
1077 |
std::string key = token.substr(0, delimiter_index); |
std::string key = token.substr(0, delimiter_index); |
1078 |
std::string value = token.substr(delimiter_index + 1); |
std::string value = token.substr(delimiter_index + 1); |
1079 |
int x, y; |
int x, y, z; |
1080 |
|
|
1081 |
|
if (_current_section == CURVE) { |
1082 |
|
if (sscanf(key.c_str(), "v%d", &x)) { |
1083 |
|
if (x < 0 || x > 127) { |
1084 |
|
std::cerr << "Invalid curve index: " << x << std::endl; |
1085 |
|
} |
1086 |
|
_current_curve->v[x] = check(key, 0.0f, 1.0f, ToFloat(value)); |
1087 |
|
} else { |
1088 |
|
std::cerr << "The opcode '" << key << "' in section <curve> is unsupported by libsfz!" << std::endl; |
1089 |
|
} |
1090 |
|
|
1091 |
|
return; |
1092 |
|
} |
1093 |
|
|
1094 |
// sample definition |
// sample definition |
1095 |
if ("sample" == key) |
if ("sample" == key) |
1146 |
else if ("hivel" == key) pCurDef->hivel = ToInt(value); |
else if ("hivel" == key) pCurDef->hivel = ToInt(value); |
1147 |
else if ("lobend" == key) pCurDef->lobend = ToInt(value); |
else if ("lobend" == key) pCurDef->lobend = ToInt(value); |
1148 |
else if ("hibend" == key) pCurDef->hibend = ToInt(value); |
else if ("hibend" == key) pCurDef->hibend = ToInt(value); |
1149 |
else if ("lobpm" == key) pCurDef->lobpm = ToInt(value); |
else if ("lobpm" == key) pCurDef->lobpm = ToFloat(value); |
1150 |
else if ("hibpm" == key) pCurDef->hibpm = ToInt(value); |
else if ("hibpm" == key) pCurDef->hibpm = ToFloat(value); |
1151 |
else if ("lochanaft" == key) pCurDef->lochanaft = ToInt(value); |
else if ("lochanaft" == key) pCurDef->lochanaft = ToInt(value); |
1152 |
else if ("hichanaft" == key) pCurDef->hichanaft = ToInt(value); |
else if ("hichanaft" == key) pCurDef->hichanaft = ToInt(value); |
1153 |
else if ("lopolyaft" == key) pCurDef->lopolyaft = ToInt(value); |
else if ("lopolyaft" == key) pCurDef->lopolyaft = ToInt(value); |
1182 |
else if ("off_by" == key || "offby" == key) pCurDef->off_by = ToInt(value); |
else if ("off_by" == key || "offby" == key) pCurDef->off_by = ToInt(value); |
1183 |
else if ("off_mode" == key || "offmode" == key) |
else if ("off_mode" == key || "offmode" == key) |
1184 |
{ |
{ |
1185 |
if (value == "fast") _current_group->off_mode = OFF_FAST; |
if (value == "fast") pCurDef->off_mode = OFF_FAST; |
1186 |
else if (value == "normal") _current_group->off_mode = OFF_NORMAL; |
else if (value == "normal") pCurDef->off_mode = OFF_NORMAL; |
1187 |
} |
} |
1188 |
|
|
1189 |
// sample player |
// sample player |
1207 |
else if ("loopstart" == key) pCurDef->loop_start = ToInt(value); // nonstandard |
else if ("loopstart" == key) pCurDef->loop_start = ToInt(value); // nonstandard |
1208 |
else if ("loop_end" == key) pCurDef->loop_end = ToInt(value); |
else if ("loop_end" == key) pCurDef->loop_end = ToInt(value); |
1209 |
else if ("loopend" == key) pCurDef->loop_end = ToInt(value); // nonstandard |
else if ("loopend" == key) pCurDef->loop_end = ToInt(value); // nonstandard |
1210 |
|
else if ("offset" == key) pCurDef->offset = ToInt(value); |
1211 |
else if ("sync_beats" == key) pCurDef->sync_beats = ToInt(value); |
else if ("sync_beats" == key) pCurDef->sync_beats = ToInt(value); |
1212 |
else if ("sync_offset" == key) pCurDef->sync_offset = ToInt(value); |
else if ("sync_offset" == key) pCurDef->sync_offset = ToInt(value); |
1213 |
|
|
1220 |
else if ("amp_keycenter" == key) pCurDef->amp_keycenter = parseKey(value); |
else if ("amp_keycenter" == key) pCurDef->amp_keycenter = parseKey(value); |
1221 |
else if ("amp_veltrack" == key) pCurDef->amp_veltrack = ToFloat(value); |
else if ("amp_veltrack" == key) pCurDef->amp_veltrack = ToFloat(value); |
1222 |
else if ("amp_random" == key) pCurDef->amp_random = ToFloat(value); |
else if ("amp_random" == key) pCurDef->amp_random = ToFloat(value); |
1223 |
else if ("rt_decay" == key) pCurDef->rt_decay = ToFloat(value); |
else if ("rt_decay" == key || "rtdecay" == key) pCurDef->rt_decay = ToFloat(value); |
1224 |
else if ("xfin_lokey" == key) pCurDef->xfin_lokey = parseKey(value); |
else if ("xfin_lokey" == key) pCurDef->xfin_lokey = parseKey(value); |
1225 |
else if ("xfin_hikey" == key) pCurDef->xfin_hikey = parseKey(value); |
else if ("xfin_hikey" == key) pCurDef->xfin_hikey = parseKey(value); |
1226 |
else if ("xfout_lokey" == key) pCurDef->xfout_lokey = parseKey(value); |
else if ("xfout_lokey" == key) pCurDef->xfout_lokey = parseKey(value); |
1254 |
else if ("pitch_random" == key) pCurDef->pitch_random = ToInt(value); |
else if ("pitch_random" == key) pCurDef->pitch_random = ToInt(value); |
1255 |
else if ("bend_up" == key || "bendup" == key) pCurDef->bend_up = ToInt(value); |
else if ("bend_up" == key || "bendup" == key) pCurDef->bend_up = ToInt(value); |
1256 |
else if ("bend_down" == key || "benddown" == key) pCurDef->bend_down = ToInt(value); |
else if ("bend_down" == key || "benddown" == key) pCurDef->bend_down = ToInt(value); |
1257 |
else if ("bend_step" == key) pCurDef->bend_step = ToInt(value); |
else if ("bend_step" == key || "bendstep" == key) pCurDef->bend_step = ToInt(value); |
1258 |
|
|
1259 |
// filter |
// filter |
1260 |
else if ("fil_type" == key || "filtype" == key) |
else if ("fil_type" == key || "filtype" == key) |
1328 |
else if (sscanf(key.c_str(), "amp_velcurve_%d", &x)) { |
else if (sscanf(key.c_str(), "amp_velcurve_%d", &x)) { |
1329 |
pCurDef->amp_velcurve.set(x, ToFloat(value)); |
pCurDef->amp_velcurve.set(x, ToFloat(value)); |
1330 |
} |
} |
1331 |
|
|
1332 |
|
// v2 envelope generators |
1333 |
|
else if (sscanf(key.c_str(), "eg%d%n", &x, &y)) { |
1334 |
|
const char* s = key.c_str() + y; |
1335 |
|
if (sscanf(s, "_time%d%n", &y, &z)) { |
1336 |
|
const char* s2 = s + z; |
1337 |
|
if (strcmp(s2, "") == 0) egnode(x, y).time = check(key, 0.0f, 100.0f, ToFloat(value)); |
1338 |
|
else if (sscanf(s2, "_oncc%d", &z)) egnode(x, y).time_oncc.add( CC(z, check(key, 0.0f, 100.0f, ToFloat(value))) ); |
1339 |
|
} else if (sscanf(s, "_level%d%n", &y, &z)) { |
1340 |
|
const char* s2 = s + z; |
1341 |
|
if (strcmp(s2, "") == 0) egnode(x, y).level = check(key, 0.0f, 1.0f, ToFloat(value)); |
1342 |
|
else if (sscanf(s2, "_oncc%d", &z)) egnode(x, y).level_oncc.add( CC(z, check(key, 0.0f, 1.0f, ToFloat(value))) ); |
1343 |
|
} |
1344 |
|
else if (sscanf(s, "_shape%d", &y)) egnode(x, y).shape = ToFloat(value); |
1345 |
|
else if (sscanf(s, "_curve%d", &y)) egnode(x, y).curve = ToFloat(value); |
1346 |
|
else if (strcmp(s, "_sustain") == 0) eg(x).sustain = ToInt(value); |
1347 |
|
else if (strcmp(s, "_loop") == 0) eg(x).loop = ToInt(value); |
1348 |
|
else if (strcmp(s, "_loop_count") == 0) eg(x).loop_count = ToInt(value); |
1349 |
|
else if (strcmp(s, "_amplitude") == 0) eg(x).amplitude = ToFloat(value); |
1350 |
|
else if (strcmp(s, "_cutoff") == 0) eg(x).cutoff = ToFloat(value); |
1351 |
|
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
1352 |
|
} |
1353 |
|
|
1354 |
|
// v1 envelope generators |
1355 |
|
else if ("ampeg_delay" == key) pCurDef->ampeg_delay = ToFloat(value); |
1356 |
|
else if ("ampeg_start" == key) pCurDef->ampeg_start = ToFloat(value); |
1357 |
|
else if ("ampeg_attack" == key) pCurDef->ampeg_attack = ToFloat(value); |
1358 |
|
else if ("ampeg_hold" == key) pCurDef->ampeg_hold = ToFloat(value); |
1359 |
|
else if ("ampeg_decay" == key) pCurDef->ampeg_decay = ToFloat(value); |
1360 |
|
else if ("ampeg_sustain" == key) pCurDef->ampeg_sustain = ToFloat(value); |
1361 |
|
else if ("ampeg_release" == key) pCurDef->ampeg_release = ToFloat(value); |
1362 |
|
else if ("ampeg_vel2delay" == key) pCurDef->ampeg_vel2delay = ToFloat(value); |
1363 |
|
else if ("ampeg_vel2attack" == key) pCurDef->ampeg_vel2attack = ToFloat(value); |
1364 |
|
else if ("ampeg_vel2hold" == key) pCurDef->ampeg_vel2hold = ToFloat(value); |
1365 |
|
else if ("ampeg_vel2decay" == key) pCurDef->ampeg_vel2decay = ToFloat(value); |
1366 |
|
else if ("ampeg_vel2sustain" == key) pCurDef->ampeg_vel2sustain = ToFloat(value); |
1367 |
|
else if ("ampeg_vel2release" == key) pCurDef->ampeg_vel2release = ToFloat(value); |
1368 |
|
else if ("fileg_delay" == key) pCurDef->fileg_delay = ToFloat(value); |
1369 |
|
else if ("fileg_start" == key) pCurDef->fileg_start = ToFloat(value); |
1370 |
|
else if ("fileg_attack" == key) pCurDef->fileg_attack = ToFloat(value); |
1371 |
|
else if ("fileg_hold" == key) pCurDef->fileg_hold = ToFloat(value); |
1372 |
|
else if ("fileg_decay" == key) pCurDef->fileg_decay = ToFloat(value); |
1373 |
|
else if ("fileg_sustain" == key) pCurDef->fileg_sustain = ToFloat(value); |
1374 |
|
else if ("fileg_release" == key) pCurDef->fileg_release = ToFloat(value); |
1375 |
|
else if ("fileg_depth" == key) pCurDef->fileg_depth = check(key, -12000, 12000, ToInt(value)); |
1376 |
|
else if ("fileg_vel2delay" == key) pCurDef->fileg_vel2delay = check(key, -100.0f, 100.0f, ToFloat(value)); |
1377 |
|
else if ("fileg_vel2attack" == key) pCurDef->fileg_vel2attack = ToFloat(value); |
1378 |
|
else if ("fileg_vel2hold" == key) pCurDef->fileg_vel2hold = ToFloat(value); |
1379 |
|
else if ("fileg_vel2decay" == key) pCurDef->fileg_vel2decay = ToFloat(value); |
1380 |
|
else if ("fileg_vel2sustain" == key) pCurDef->fileg_vel2sustain = ToFloat(value); |
1381 |
|
else if ("fileg_vel2release" == key) pCurDef->fileg_vel2release = ToFloat(value); |
1382 |
|
else if ("pitcheg_delay" == key) pCurDef->pitcheg_delay = ToFloat(value); |
1383 |
|
else if ("pitcheg_start" == key) pCurDef->pitcheg_start = ToFloat(value); |
1384 |
|
else if ("pitcheg_attack" == key) pCurDef->pitcheg_attack = ToFloat(value); |
1385 |
|
else if ("pitcheg_hold" == key) pCurDef->pitcheg_hold = ToFloat(value); |
1386 |
|
else if ("pitcheg_decay" == key) pCurDef->pitcheg_decay = ToFloat(value); |
1387 |
|
else if ("pitcheg_sustain" == key) pCurDef->pitcheg_sustain = ToFloat(value); |
1388 |
|
else if ("pitcheg_release" == key) pCurDef->pitcheg_release = ToFloat(value); |
1389 |
|
else if ("pitcheg_depth" == key) pCurDef->pitcheg_depth = check(key, -12000, 12000, ToInt(value)); |
1390 |
|
else if ("pitcheg_vel2delay" == key) pCurDef->pitcheg_vel2delay = check(key, -100.0f, 100.0f, ToFloat(value)); |
1391 |
|
else if ("pitcheg_vel2attack" == key) pCurDef->pitcheg_vel2attack = ToFloat(value); |
1392 |
|
else if ("pitcheg_vel2hold" == key) pCurDef->pitcheg_vel2hold = ToFloat(value); |
1393 |
|
else if ("pitcheg_vel2decay" == key) pCurDef->pitcheg_vel2decay = ToFloat(value); |
1394 |
|
else if ("pitcheg_vel2sustain" == key) pCurDef->pitcheg_vel2sustain = ToFloat(value); |
1395 |
|
else if ("pitcheg_vel2release" == key) pCurDef->pitcheg_vel2release = ToFloat(value); |
1396 |
|
|
1397 |
|
|
1398 |
|
// v1 LFO |
1399 |
|
else if ("amplfo_delay" == key) pCurDef->amplfo_delay = ToFloat(value); |
1400 |
|
else if ("amplfo_fade" == key) pCurDef->amplfo_fade = ToFloat(value); |
1401 |
|
else if ("amplfo_freq" == key) pCurDef->amplfo_freq = ToFloat(value); |
1402 |
|
else if ("amplfo_depth" == key) pCurDef->amplfo_depth = ToFloat(value); |
1403 |
|
else if ("fillfo_delay" == key) pCurDef->fillfo_delay = ToFloat(value); |
1404 |
|
else if ("fillfo_fade" == key) pCurDef->fillfo_fade = ToFloat(value); |
1405 |
|
else if ("fillfo_freq" == key) pCurDef->fillfo_freq = ToFloat(value); |
1406 |
|
else if ("fillfo_depth" == key) pCurDef->fillfo_depth = ToFloat(value); |
1407 |
|
else if ("pitchlfo_delay" == key) pCurDef->pitchlfo_delay = ToFloat(value); |
1408 |
|
else if ("pitchlfo_fade" == key) pCurDef->pitchlfo_fade = ToFloat(value); |
1409 |
|
else if ("pitchlfo_freq" == key) pCurDef->pitchlfo_freq = ToFloat(value); |
1410 |
|
else if ("pitchlfo_depth" == key) pCurDef->pitchlfo_depth = ToInt(value); |
1411 |
|
|
1412 |
|
// v2 LFO |
1413 |
|
else if (sscanf(key.c_str(), "lfo%d%n", &x, &y)) { |
1414 |
|
const char* s = key.c_str() + y; |
1415 |
|
if (strcmp(s, "_freq") == 0) lfo(x).freq = check(key, 0.0f, 20.0f, ToFloat(value)); |
1416 |
|
else if (sscanf(s, "_freq_oncc%d", &y)) lfo(x).freq_oncc.add( CC(y, check(key, 0.0f, 20.0f, ToFloat(value))) ); |
1417 |
|
else if (sscanf(s, "_freq_smoothcc%d", &y)) lfo(x).freq_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) ); |
1418 |
|
else if (strcmp(s, "_wave") == 0) lfo(x).wave = ToInt(value); |
1419 |
|
else if (strcmp(s, "_delay") == 0) lfo(x).delay = check(key, 0.0f, 100.0f, ToFloat(value)); |
1420 |
|
else if (sscanf(s, "_delay_oncc%d", &y)) lfo(x).delay_oncc.add( CC(y, check(key, 0.0f, 100.0f, ToFloat(value))) ); |
1421 |
|
else if (strcmp(s, "_fade") == 0) lfo(x).fade = check(key, 0.0f, 100.0f, ToFloat(value)); |
1422 |
|
else if (sscanf(s, "_fade_oncc%d", &y)) lfo(x).fade_oncc.add( CC(y, check(key, 0.0f, 100.0f, ToFloat(value))) ); |
1423 |
|
else if (strcmp(s, "_phase") == 0) lfo(x).phase = check(key, 0.0f, 360.0f, ToFloat(value)); |
1424 |
|
else if (sscanf(s, "_phase_oncc%d", &y)) lfo(x).phase_oncc.add( CC(y, check(key, 0.0f, 360.0f, ToFloat(value))) ); |
1425 |
|
else if (strcmp(s, "_volume") == 0) lfo(x).volume = check(key, -144.0f, 6.0f, ToFloat(value)); |
1426 |
|
else if (sscanf(s, "_volume_oncc%d", &y)) lfo(x).volume_oncc.add( CC(y, check(key, -144.0f, 6.0f, ToFloat(value))) ); |
1427 |
|
else if (sscanf(s, "_volume_smoothcc%d", &y)) lfo(x).volume_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) ); |
1428 |
|
else if (strcmp(s, "_pitch") == 0) lfo(x).pitch = check(key, -9600, 9600, ToInt(value)); |
1429 |
|
else if (sscanf(s, "_pitch_oncc%d", &y)) lfo(x).pitch_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) ); |
1430 |
|
else if (sscanf(s, "_pitch_smoothcc%d", &y)) lfo(x).pitch_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) ); |
1431 |
|
else if (strcmp(s, "_cutoff") == 0) lfo(x).cutoff = check(key, -9600, 9600, ToInt(value)); |
1432 |
|
else if (sscanf(s, "_cutoff_oncc%d", &y)) lfo(x).cutoff_oncc.add( CC(y, check(key, -9600, 9600, ToInt(value))) ); |
1433 |
|
else if (sscanf(s, "_cutoff_smoothcc%d", &y)) lfo(x).cutoff_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) ); |
1434 |
|
else if (strcmp(s, "_resonance") == 0) lfo(x).resonance = check(key, 0.0f, 40.0f, ToFloat(value)); |
1435 |
|
else if (sscanf(s, "_resonance_oncc%d", &y)) lfo(x).resonance_oncc.add( CC(y, check(key, 0.0f, 40.0f, ToFloat(value))) ); |
1436 |
|
else if (sscanf(s, "_resonance_smoothcc%d", &y)) lfo(x).resonance_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) ); |
1437 |
|
else if (strcmp(s, "_pan") == 0) lfo(x).pan = check(key, -100.0f, 100.0f, ToFloat(value)); |
1438 |
|
else if (sscanf(s, "_pan_oncc%d", &y)) lfo(x).pan_oncc.add( CC(y, check(key, -100.0f, 100.0f, ToFloat(value))) ); |
1439 |
|
else if (sscanf(s, "_pan_smoothcc%d", &y)) lfo(x).pan_smoothcc.add( CC(y, 0, -1, check(key, 0, 100000 /* max? */, ToInt(value))) ); |
1440 |
|
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
1441 |
|
} |
1442 |
|
|
1443 |
// CCs |
// CCs |
1444 |
else if (key.find("cc") != std::string::npos) |
else if (key.find("cc") != std::string::npos) |
1445 |
{ |
{ |
1470 |
else if ("xfout_hi" == key_cc) pCurDef->xfout_hicc.set(num_cc, ToInt(value)); |
else if ("xfout_hi" == key_cc) pCurDef->xfout_hicc.set(num_cc, ToInt(value)); |
1471 |
|
|
1472 |
// filter |
// filter |
1473 |
else if ("cutoff_on" == key_cc || "cutoff_" == key_cc) pCurDef->cutoff_oncc.set(num_cc, ToInt(value)); |
else if ("cutoff_on" == key_cc || "cutoff_" == key_cc) { |
1474 |
else if ("cutoff2_on" == key_cc) pCurDef->cutoff2_oncc.set(num_cc, ToInt(value)); |
pCurDef->cutoff_oncc.set(num_cc, ToInt(value)); |
1475 |
|
pCurDef->cutoff_cc = num_cc; |
1476 |
|
} else if ("cutoff2_on" == key_cc) pCurDef->cutoff2_oncc.set(num_cc, ToInt(value)); |
1477 |
else if ("cutoff_smooth" == key_cc) pCurDef->cutoff_smoothcc.set(num_cc, ToInt(value)); |
else if ("cutoff_smooth" == key_cc) pCurDef->cutoff_smoothcc.set(num_cc, ToInt(value)); |
1478 |
else if ("cutoff2_smooth" == key_cc) pCurDef->cutoff2_smoothcc.set(num_cc, ToInt(value)); |
else if ("cutoff2_smooth" == key_cc) pCurDef->cutoff2_smoothcc.set(num_cc, ToInt(value)); |
1479 |
else if ("cutoff_step" == key_cc) pCurDef->cutoff_stepcc.set(num_cc, ToInt(value)); |
else if ("cutoff_step" == key_cc) pCurDef->cutoff_stepcc.set(num_cc, ToInt(value)); |
1499 |
else if ("eq1_gain_on" == key_cc || "eq1_gain" == key_cc) pCurDef->eq1_gain_oncc.set(num_cc, ToInt(value)); |
else if ("eq1_gain_on" == key_cc || "eq1_gain" == key_cc) pCurDef->eq1_gain_oncc.set(num_cc, ToInt(value)); |
1500 |
else if ("eq2_gain_on" == key_cc || "eq2_gain" == key_cc) pCurDef->eq2_gain_oncc.set(num_cc, ToInt(value)); |
else if ("eq2_gain_on" == key_cc || "eq2_gain" == key_cc) pCurDef->eq2_gain_oncc.set(num_cc, ToInt(value)); |
1501 |
else if ("eq3_gain_on" == key_cc || "eq3_gain" == key_cc) pCurDef->eq3_gain_oncc.set(num_cc, ToInt(value)); |
else if ("eq3_gain_on" == key_cc || "eq3_gain" == key_cc) pCurDef->eq3_gain_oncc.set(num_cc, ToInt(value)); |
1502 |
|
|
1503 |
|
else if ("ampeg_delay" == key_cc) pCurDef->ampeg_delaycc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); |
1504 |
|
else if ("ampeg_start" == key_cc) pCurDef->ampeg_startcc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); |
1505 |
|
else if ("ampeg_attack" == key_cc) pCurDef->ampeg_attackcc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); |
1506 |
|
else if ("ampeg_hold" == key_cc) pCurDef->ampeg_holdcc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); |
1507 |
|
else if ("ampeg_decay" == key_cc) pCurDef->ampeg_decaycc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); |
1508 |
|
else if ("ampeg_sustain" == key_cc) pCurDef->ampeg_sustaincc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); |
1509 |
|
else if ("ampeg_release" == key_cc) pCurDef->ampeg_releasecc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); |
1510 |
|
|
1511 |
|
else if ("pitchlfo_depth" == key_cc) pCurDef->pitchlfo_depthcc.set(num_cc, ToInt(value)); |
1512 |
|
else if ("pitchlfo_freq" == key_cc) pCurDef->pitchlfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) ); |
1513 |
|
else if ("fillfo_depth" == key_cc) pCurDef->fillfo_depthcc.add( CC(num_cc, check(key, -1200, 1200, ToInt(value))) ); |
1514 |
|
else if ("fillfo_freq" == key_cc) pCurDef->fillfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) ); |
1515 |
|
else if ("amplfo_depth" == key_cc) pCurDef->amplfo_depthcc.add( CC(num_cc, check(key, -10.0f, 10.0f, ToFloat(value))) ); |
1516 |
|
else if ("amplfo_freq" == key_cc) pCurDef->amplfo_freqcc.add( CC(num_cc, check(key, -200.0f, 200.0f, ToFloat(value))) ); |
1517 |
|
else if ("volume_on" == key_cc) pCurDef->volume_oncc.add( CC(num_cc, check(key, -100.0f, 100.0f, ToFloat(value))) ); |
1518 |
|
else if ("volume_curve" == key_cc) pCurDef->volume_curvecc.add( CC(num_cc, 0, check(key, 0, 30000, ToInt(value))) ); |
1519 |
|
else if ("volume_smooth" == key_cc) pCurDef->volume_smoothcc.add( CC(num_cc, 0, -1, check(key, 0.0f, 100000.0f /* max? */, ToFloat(value))) ); |
1520 |
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
1521 |
} |
} |
|
// v2 envelope generators |
|
|
else if (sscanf(key.c_str(), "eg%d%n", &x, &y)) { |
|
|
const char* s = key.c_str() + y; |
|
|
if (sscanf(s, "_time%d", &y)) egnode(x, y).time = ToFloat(value); |
|
|
else if (sscanf(s, "_level%d", &y)) egnode(x, y).level = ToFloat(value); |
|
|
else if (sscanf(s, "_shape%d", &y)) egnode(x, y).shape = ToFloat(value); |
|
|
else if (sscanf(s, "_curve%d", &y)) egnode(x, y).curve = ToFloat(value); |
|
|
else if (strcmp(s, "_sustain") == 0) eg(x).sustain = ToInt(value); |
|
|
else if (strcmp(s, "_loop") == 0) eg(x).loop = ToInt(value); |
|
|
else if (strcmp(s, "_loop_count") == 0) eg(x).loop_count = ToInt(value); |
|
|
else if (strcmp(s, "_amplitude") == 0) eg(x).amplitude = ToFloat(value); |
|
|
else if (strcmp(s, "_cutoff") == 0) eg(x).cutoff = ToFloat(value); |
|
|
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
|
|
} |
|
|
|
|
|
// v1 envelope generators |
|
|
else if ("ampeg_delay" == key) pCurDef->ampeg_delay = ToFloat(value); |
|
|
else if ("ampeg_start" == key) pCurDef->ampeg_start = ToFloat(value); |
|
|
else if ("ampeg_attack" == key) pCurDef->ampeg_attack = ToFloat(value); |
|
|
else if ("ampeg_hold" == key) pCurDef->ampeg_hold = ToFloat(value); |
|
|
else if ("ampeg_decay" == key) pCurDef->ampeg_decay = ToFloat(value); |
|
|
else if ("ampeg_sustain" == key) pCurDef->ampeg_sustain = ToFloat(value); |
|
|
else if ("ampeg_release" == key) pCurDef->ampeg_release = ToFloat(value); |
|
|
else if ("fileg_delay" == key) pCurDef->fileg_delay = ToFloat(value); |
|
|
else if ("fileg_start" == key) pCurDef->fileg_start = ToFloat(value); |
|
|
else if ("fileg_attack" == key) pCurDef->fileg_attack = ToFloat(value); |
|
|
else if ("fileg_hold" == key) pCurDef->fileg_hold = ToFloat(value); |
|
|
else if ("fileg_decay" == key) pCurDef->fileg_decay = ToFloat(value); |
|
|
else if ("fileg_sustain" == key) pCurDef->fileg_sustain = ToFloat(value); |
|
|
else if ("fileg_release" == key) pCurDef->fileg_release = ToFloat(value); |
|
|
else if ("pitcheg_delay" == key) pCurDef->pitcheg_delay = ToFloat(value); |
|
|
else if ("pitcheg_start" == key) pCurDef->pitcheg_start = ToFloat(value); |
|
|
else if ("pitcheg_attack" == key) pCurDef->pitcheg_attack = ToFloat(value); |
|
|
else if ("pitcheg_hold" == key) pCurDef->pitcheg_hold = ToFloat(value); |
|
|
else if ("pitcheg_decay" == key) pCurDef->pitcheg_decay = ToFloat(value); |
|
|
else if ("pitcheg_sustain" == key) pCurDef->pitcheg_sustain = ToFloat(value); |
|
|
else if ("pitcheg_release" == key) pCurDef->pitcheg_release = ToFloat(value); |
|
|
|
|
|
// v1 LFO |
|
|
else if ("amplfo_delay" == key) pCurDef->amplfo_delay = ToFloat(value); |
|
|
else if ("amplfo_fade" == key) pCurDef->amplfo_fade = ToFloat(value); |
|
|
else if ("amplfo_freq" == key) pCurDef->amplfo_freq = ToFloat(value); |
|
|
else if ("amplfo_depth" == key) pCurDef->amplfo_depth = ToFloat(value); |
|
|
else if ("fillfo_delay" == key) pCurDef->fillfo_delay = ToFloat(value); |
|
|
else if ("fillfo_fade" == key) pCurDef->fillfo_fade = ToFloat(value); |
|
|
else if ("fillfo_freq" == key) pCurDef->fillfo_freq = ToFloat(value); |
|
|
else if ("fillfo_depth" == key) pCurDef->fillfo_depth = ToFloat(value); |
|
|
else if ("pitchlfo_delay" == key) pCurDef->pitchlfo_delay = ToFloat(value); |
|
|
else if ("pitchlfo_fade" == key) pCurDef->pitchlfo_fade = ToFloat(value); |
|
|
else if ("pitchlfo_freq" == key) pCurDef->pitchlfo_freq = ToFloat(value); |
|
|
else if ("pitchlfo_depth" == key) pCurDef->pitchlfo_depth = ToInt(value); |
|
1522 |
|
|
1523 |
else { |
else { |
1524 |
std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
1539 |
case 'g': i = 7; break; |
case 'g': i = 7; break; |
1540 |
case 'a': i = 9; break; |
case 'a': i = 9; break; |
1541 |
case 'b': i = 11; break; |
case 'b': i = 11; break; |
1542 |
|
case '-': if (s == "-1") return -1; |
1543 |
default: |
default: |
1544 |
std::cerr << "Not a note: " << s << std::endl; |
std::cerr << "Not a note: " << s << std::endl; |
1545 |
return 0; |
return 0; |
1563 |
|
|
1564 |
EGNode::EGNode() : time(0), level(0), shape(0), curve(0) { |
EGNode::EGNode() : time(0), level(0), shape(0), curve(0) { |
1565 |
} |
} |
1566 |
|
|
1567 |
|
void EGNode::Copy(const EGNode& egNode) { |
1568 |
|
time = egNode.time; |
1569 |
|
level = egNode.level; |
1570 |
|
shape = egNode.shape; |
1571 |
|
curve = egNode.curve; |
1572 |
|
|
1573 |
|
time_oncc = egNode.time_oncc; |
1574 |
|
level_oncc = egNode.level_oncc; |
1575 |
|
} |
1576 |
|
|
1577 |
EG::EG() : |
EG::EG() : |
1578 |
sustain(0), loop(0), loop_count(0), |
sustain(0), loop(0), loop_count(0), |
1579 |
amplitude(0), cutoff(0) { |
amplitude(0), cutoff(0) { |
1580 |
} |
} |
1581 |
|
|
1582 |
|
void EG::Copy(const EG& eg) { |
1583 |
|
sustain = eg.sustain; |
1584 |
|
loop = eg.loop; |
1585 |
|
loop_count = eg.loop_count; |
1586 |
|
amplitude = eg.amplitude; |
1587 |
|
cutoff = eg.cutoff; |
1588 |
|
node = eg.node; |
1589 |
|
} |
1590 |
|
|
1591 |
|
LFO::LFO(): freq (-1),/* -1 is used to determine whether the LFO was initialized */ |
1592 |
|
fade(0), phase(0), wave(0), delay(0), pitch(0), cutoff(0), resonance(0), pan(0) { |
1593 |
|
|
1594 |
|
} |
1595 |
|
|
1596 |
|
void LFO::Copy(const LFO& lfo) { |
1597 |
|
delay = lfo.delay; |
1598 |
|
freq = lfo.freq; |
1599 |
|
fade = lfo.fade; |
1600 |
|
phase = lfo.phase; |
1601 |
|
wave = lfo.wave; |
1602 |
|
volume = lfo.volume; |
1603 |
|
pitch = lfo.pitch; |
1604 |
|
cutoff = lfo.cutoff; |
1605 |
|
resonance = lfo.resonance; |
1606 |
|
pan = lfo.pan; |
1607 |
|
|
1608 |
|
delay_oncc = lfo.delay_oncc; |
1609 |
|
freq_oncc = lfo.freq_oncc; |
1610 |
|
freq_smoothcc = lfo.freq_smoothcc; |
1611 |
|
fade_oncc = lfo.fade_oncc; |
1612 |
|
phase_oncc = lfo.phase_oncc; |
1613 |
|
pitch_oncc = lfo.pitch_oncc; |
1614 |
|
pitch_smoothcc = lfo.pitch_smoothcc; |
1615 |
|
volume_oncc = lfo.volume_oncc; |
1616 |
|
volume_smoothcc = lfo.volume_smoothcc; |
1617 |
|
pan_oncc = lfo.pan_oncc; |
1618 |
|
pan_smoothcc = lfo.pan_smoothcc; |
1619 |
|
cutoff_oncc = lfo.cutoff_oncc; |
1620 |
|
cutoff_smoothcc = lfo.cutoff_smoothcc; |
1621 |
|
resonance_oncc = lfo.resonance_oncc; |
1622 |
|
resonance_smoothcc = lfo.resonance_smoothcc; |
1623 |
|
} |
1624 |
|
|
1625 |
EG& File::eg(int x) { |
EG& File::eg(int x) { |
1626 |
while (pCurDef->eg.size() <= x) { |
while (pCurDef->eg.size() <= x) { |
1637 |
return e.node[y]; |
return e.node[y]; |
1638 |
} |
} |
1639 |
|
|
1640 |
|
LFO& File::lfo(int x) { |
1641 |
|
while (pCurDef->lfos.size() <= x) { |
1642 |
|
pCurDef->lfos.add(LFO()); |
1643 |
|
} |
1644 |
|
return pCurDef->lfos[x]; |
1645 |
|
} |
1646 |
|
|
1647 |
} // !namespace sfz |
} // !namespace sfz |