2 |
* * |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2008-2009 Anders Dahnielson <anders@dahnielson.com> * |
* Copyright (C) 2008 Anders Dahnielson <anders@dahnielson.com> * |
6 |
* Copyright (C) 2009 Grigor Iliev * |
* Copyright (C) 2009 - 2010 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 * |
25 |
|
|
26 |
#include <iostream> |
#include <iostream> |
27 |
#include <sstream> |
#include <sstream> |
28 |
|
#include <cctype> |
29 |
|
#include <cstdio> |
30 |
|
#include <cstring> |
31 |
|
|
32 |
#include "../../common/File.h" |
#include "../../common/File.h" |
33 |
#include "../../common/Path.h" |
#include "../../common/Path.h" |
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) ) && |
164 |
((sw_up >= sw_lokey && sw_up <= sw_hikey) ? (!sw[sw_up]) : true) ) && |
((sw_up >= sw_lokey && sw_up <= sw_hikey) ? (!sw[sw_up]) : true) ) && |
165 |
|
|
166 |
((sw_previous != -1) ? (prev_sw_key == sw_previous) : true) && |
((sw_previous != -1) ? (prev_sw_key == sw_previous) : true) && |
167 |
((trigger && trig) != 0) |
((trigger & trig) != 0) |
168 |
); |
); |
169 |
|
|
170 |
if (!is_triggered) |
if (!is_triggered) |
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) ) && |
230 |
((sw_up >= sw_lokey && sw_up <= sw_hikey) ? (!sw[sw_up]) : true) ) && |
((sw_up >= sw_lokey && sw_up <= sw_hikey) ? (!sw[sw_up]) : true) ) && |
231 |
|
|
232 |
((sw_previous != -1) ? (prev_sw_key == sw_previous) : true) && |
((sw_previous != -1) ? (prev_sw_key == sw_previous) : true) && |
233 |
((trigger && trig) != 0) |
((trigger & trig) != 0) |
234 |
); |
); |
235 |
|
|
236 |
if (!is_triggered) |
if (!is_triggered) |
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; |
509 |
eq3_gain_oncc[i] = 0; |
eq3_gain_oncc[i] = 0; |
510 |
} |
} |
511 |
|
|
512 |
|
eg.clear(); |
513 |
|
|
514 |
// deprecated |
// deprecated |
515 |
ampeg_delay = 0; |
ampeg_delay = 0; |
516 |
ampeg_start = 0; //in percentage |
ampeg_start = 0; //in percentage |
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; |
729 |
region->eq2_vel2gain = eq2_vel2gain; |
region->eq2_vel2gain = eq2_vel2gain; |
730 |
region->eq3_vel2gain = eq3_vel2gain; |
region->eq3_vel2gain = eq3_vel2gain; |
731 |
|
|
732 |
|
// envelope generator |
733 |
|
region->eg = eg; |
734 |
|
|
735 |
// deprecated |
// deprecated |
736 |
region->ampeg_delay = ampeg_delay; |
region->ampeg_delay = ampeg_delay; |
737 |
region->ampeg_start = ampeg_start; |
region->ampeg_start = ampeg_start; |
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 |
|
|
786 |
{ |
{ |
787 |
_instrument = new Instrument(LinuxSampler::Path::getBaseName(file), pSampleManager); |
_instrument = new Instrument(LinuxSampler::Path::getBaseName(file), pSampleManager); |
788 |
_current_group = new Group(); |
_current_group = new Group(); |
789 |
pCurDef = _current_group; |
pCurDef = _current_group; |
790 |
enum token_type_t { HEADER, OPCODE }; |
enum token_type_t { HEADER, OPCODE }; |
791 |
token_type_t token_type; |
token_type_t token_type; |
792 |
std::string token_string; |
std::string token_string; |
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 |
|
|
943 |
{ |
{ |
944 |
_current_section = GROUP; |
_current_section = GROUP; |
945 |
_current_group->Reset(); |
_current_group->Reset(); |
946 |
pCurDef = _current_group; |
pCurDef = _current_group; |
947 |
} |
} |
948 |
else if (token == "<region>") |
else if (token == "<region>") |
949 |
{ |
{ |
950 |
_current_section = REGION; |
_current_section = REGION; |
951 |
_current_region = _current_group->RegionFactory(); |
_current_region = _current_group->RegionFactory(); |
952 |
pCurDef = _current_region; |
pCurDef = _current_region; |
953 |
_instrument->regions.push_back(_current_region); |
_instrument->regions.push_back(_current_region); |
954 |
_current_region->SetInstrument(_instrument); |
_current_region->SetInstrument(_instrument); |
955 |
} |
} |
956 |
else if (token == "<control>") |
else if (token == "<control>") |
957 |
{ |
{ |
976 |
std::string::size_type delimiter_index = token.find('='); |
std::string::size_type delimiter_index = token.find('='); |
977 |
std::string key = token.substr(0, delimiter_index); |
std::string key = token.substr(0, delimiter_index); |
978 |
std::string value = token.substr(delimiter_index + 1); |
std::string value = token.substr(delimiter_index + 1); |
979 |
|
int x, y; |
980 |
|
|
981 |
// sample definition |
// sample definition |
982 |
if ("sample" == key) |
if ("sample" == key) |
1023 |
// input controls |
// input controls |
1024 |
else if ("lochan" == key) pCurDef->lochan = ToInt(value); |
else if ("lochan" == key) pCurDef->lochan = ToInt(value); |
1025 |
else if ("hichan" == key) pCurDef->hichan = ToInt(value); |
else if ("hichan" == key) pCurDef->hichan = ToInt(value); |
1026 |
else if ("lokey" == key) pCurDef->lokey = ToInt(value) + note_offset + 12 * octave_offset; |
else if ("lokey" == key) pCurDef->lokey = parseKey(value); |
1027 |
else if ("hikey" == key) pCurDef->hikey = ToInt(value) + note_offset + 12 * octave_offset; |
else if ("hikey" == key) pCurDef->hikey = parseKey(value); |
1028 |
else if ("key" == key) |
else if ("key" == key) |
1029 |
{ |
{ |
1030 |
pCurDef->lokey = ToInt(value) + note_offset + 12 * octave_offset; |
pCurDef->lokey = pCurDef->hikey = pCurDef->pitch_keycenter = parseKey(value); |
|
pCurDef->hikey = ToInt(value) + note_offset + 12 * octave_offset; |
|
1031 |
} |
} |
1032 |
else if ("lovel" == key) pCurDef->lovel = ToInt(value); |
else if ("lovel" == key) pCurDef->lovel = ToInt(value); |
1033 |
else if ("hivel" == key) pCurDef->hivel = ToInt(value); |
else if ("hivel" == key) pCurDef->hivel = ToInt(value); |
1047 |
else if ("hitimer" == key) pCurDef->hitimer = ToFloat(value); |
else if ("hitimer" == key) pCurDef->hitimer = ToFloat(value); |
1048 |
else if ("seq_length" == key) pCurDef->seq_length = ToInt(value); |
else if ("seq_length" == key) pCurDef->seq_length = ToInt(value); |
1049 |
else if ("seq_position" == key) pCurDef->seq_position = ToInt(value); |
else if ("seq_position" == key) pCurDef->seq_position = ToInt(value); |
1050 |
else if ("sw_lokey" == key) pCurDef->sw_lokey = ToInt(value) + note_offset + 12 * octave_offset; |
else if ("sw_lokey" == key) pCurDef->sw_lokey = parseKey(value); |
1051 |
else if ("sw_hikey" == key) pCurDef->sw_hikey = ToInt(value) + note_offset + 12 * octave_offset; |
else if ("sw_hikey" == key) pCurDef->sw_hikey = parseKey(value); |
1052 |
else if ("sw_last" == key) pCurDef->sw_last = ToInt(value) + note_offset + 12 * octave_offset; |
else if ("sw_last" == key) pCurDef->sw_last = parseKey(value); |
1053 |
else if ("sw_down" == key) pCurDef->sw_down = ToInt(value) + note_offset + 12 * octave_offset; |
else if ("sw_down" == key) pCurDef->sw_down = parseKey(value); |
1054 |
else if ("sw_up" == key) pCurDef->sw_up = ToInt(value) + note_offset + 12 * octave_offset; |
else if ("sw_up" == key) pCurDef->sw_up = parseKey(value); |
1055 |
else if ("sw_previous" == key) pCurDef->sw_previous = ToInt(value) + note_offset + 12 * octave_offset; |
else if ("sw_previous" == key) pCurDef->sw_previous = parseKey(value); |
1056 |
else if ("sw_vel" == key) |
else if ("sw_vel" == key) |
1057 |
{ |
{ |
1058 |
if (value == "current") pCurDef->sw_vel = VEL_CURRENT; |
if (value == "current") pCurDef->sw_vel = VEL_CURRENT; |
1066 |
else if (value == "legato") pCurDef->trigger = TRIGGER_LEGATO; |
else if (value == "legato") pCurDef->trigger = TRIGGER_LEGATO; |
1067 |
} |
} |
1068 |
else if ("group" == key) pCurDef->group = ToInt(value); |
else if ("group" == key) pCurDef->group = ToInt(value); |
1069 |
else if ("off_by" == key) pCurDef->off_by = ToInt(value); |
else if ("off_by" == key || "offby" == key) pCurDef->off_by = ToInt(value); |
1070 |
else if ("off_mode" == key) |
else if ("off_mode" == key || "offmode" == key) |
1071 |
{ |
{ |
1072 |
if (value == "fast") _current_group->off_mode = OFF_FAST; |
if (value == "fast") _current_group->off_mode = OFF_FAST; |
1073 |
else if (value == "normal") _current_group->off_mode = OFF_NORMAL; |
else if (value == "normal") _current_group->off_mode = OFF_NORMAL; |
1083 |
else if ("end" == key) pCurDef->end = ToInt(value); |
else if ("end" == key) pCurDef->end = ToInt(value); |
1084 |
else if ("loop_crossfade" == key) pCurDef->loop_crossfade = ToFloat(value); |
else if ("loop_crossfade" == key) pCurDef->loop_crossfade = ToFloat(value); |
1085 |
else if ("offset_random" == key) pCurDef->offset_random = ToInt(value); |
else if ("offset_random" == key) pCurDef->offset_random = ToInt(value); |
1086 |
else if ("loop_mode" == key) |
else if ("loop_mode" == key || "loopmode" == key) |
1087 |
{ |
{ |
1088 |
if (value == "no_loop") pCurDef->loop_mode = NO_LOOP; |
if (value == "no_loop") pCurDef->loop_mode = NO_LOOP; |
1089 |
else if (value == "one_shot") pCurDef->loop_mode = ONE_SHOT; |
else if (value == "one_shot") pCurDef->loop_mode = ONE_SHOT; |
1103 |
else if ("width" == key) pCurDef->width = ToFloat(value); |
else if ("width" == key) pCurDef->width = ToFloat(value); |
1104 |
else if ("position" == key) pCurDef->position = ToFloat(value); |
else if ("position" == key) pCurDef->position = ToFloat(value); |
1105 |
else if ("amp_keytrack" == key) pCurDef->amp_keytrack = ToFloat(value); |
else if ("amp_keytrack" == key) pCurDef->amp_keytrack = ToFloat(value); |
1106 |
else if ("amp_keycenter" == key) pCurDef->amp_keycenter = ToInt(value) + note_offset + 12 * octave_offset; |
else if ("amp_keycenter" == key) pCurDef->amp_keycenter = parseKey(value); |
1107 |
else if ("amp_veltrack" == key) pCurDef->amp_veltrack = ToFloat(value); |
else if ("amp_veltrack" == key) pCurDef->amp_veltrack = ToFloat(value); |
1108 |
else if ("amp_random" == key) pCurDef->amp_random = ToFloat(value); |
else if ("amp_random" == key) pCurDef->amp_random = ToFloat(value); |
1109 |
else if ("rt_decay" == key) pCurDef->rt_decay = ToFloat(value); |
else if ("rt_decay" == key) pCurDef->rt_decay = ToFloat(value); |
1110 |
else if ("xfin_lokey" == key) pCurDef->xfin_lokey = ToInt(value) + note_offset + 12 * octave_offset; |
else if ("xfin_lokey" == key) pCurDef->xfin_lokey = parseKey(value); |
1111 |
else if ("xfin_hikey" == key) pCurDef->xfin_hikey = ToInt(value) + note_offset + 12 * octave_offset; |
else if ("xfin_hikey" == key) pCurDef->xfin_hikey = parseKey(value); |
1112 |
else if ("xfout_lokey" == key) pCurDef->xfout_lokey = ToInt(value) + note_offset + 12 * octave_offset; |
else if ("xfout_lokey" == key) pCurDef->xfout_lokey = parseKey(value); |
1113 |
else if ("xfout_hikey" == key) pCurDef->xfout_hikey = ToInt(value) + note_offset + 12 * octave_offset; |
else if ("xfout_hikey" == key) pCurDef->xfout_hikey = parseKey(value); |
1114 |
else if ("xf_keycurve" == key) |
else if ("xf_keycurve" == key) |
1115 |
{ |
{ |
1116 |
if (value == "gain") pCurDef->xf_keycurve = GAIN; |
if (value == "gain") pCurDef->xf_keycurve = GAIN; |
1134 |
// pitch |
// pitch |
1135 |
else if ("transpose" == key) pCurDef->transpose = ToInt(value); |
else if ("transpose" == key) pCurDef->transpose = ToInt(value); |
1136 |
else if ("tune" == key) pCurDef->tune = ToInt(value); |
else if ("tune" == key) pCurDef->tune = ToInt(value); |
1137 |
else if ("pitch_keycenter" == key) pCurDef->pitch_keycenter = ToInt(value) + note_offset + 12 * octave_offset; |
else if ("pitch_keycenter" == key) pCurDef->pitch_keycenter = parseKey(value); |
1138 |
else if ("pitch_keytrack" == key) pCurDef->pitch_keytrack = ToInt(value); |
else if ("pitch_keytrack" == key) pCurDef->pitch_keytrack = ToInt(value); |
1139 |
else if ("pitch_veltrack" == key) pCurDef->pitch_veltrack = ToInt(value); |
else if ("pitch_veltrack" == key) pCurDef->pitch_veltrack = ToInt(value); |
1140 |
else if ("pitch_random" == key) pCurDef->pitch_random = ToInt(value); |
else if ("pitch_random" == key) pCurDef->pitch_random = ToInt(value); |
1141 |
else if ("bend_up" == key) pCurDef->bend_up = ToInt(value); |
else if ("bend_up" == key || "bendup" == key) pCurDef->bend_up = ToInt(value); |
1142 |
else if ("bend_down" == key) pCurDef->bend_down = ToInt(value); |
else if ("bend_down" == key || "benddown" == key) pCurDef->bend_down = ToInt(value); |
1143 |
else if ("bend_step" == key) pCurDef->bend_step = ToInt(value); |
else if ("bend_step" == key) pCurDef->bend_step = ToInt(value); |
1144 |
|
|
1145 |
// filter |
// filter |
1187 |
else if ("resonance2" == key) pCurDef->resonance2 = ToFloat(value); |
else if ("resonance2" == key) pCurDef->resonance2 = ToFloat(value); |
1188 |
else if ("fil_keytrack" == key) pCurDef->fil_keytrack = ToInt(value); |
else if ("fil_keytrack" == key) pCurDef->fil_keytrack = ToInt(value); |
1189 |
else if ("fil2_keytrack" == key) pCurDef->fil2_keytrack = ToInt(value); |
else if ("fil2_keytrack" == key) pCurDef->fil2_keytrack = ToInt(value); |
1190 |
else if ("fil_keycenter" == key) pCurDef->fil_keycenter = ToInt(value) + note_offset + 12 * octave_offset; |
else if ("fil_keycenter" == key) pCurDef->fil_keycenter = parseKey(value); |
1191 |
else if ("fil2_keycenter" == key) pCurDef->fil2_keycenter = ToInt(value) + note_offset + 12 * octave_offset; |
else if ("fil2_keycenter" == key) pCurDef->fil2_keycenter = parseKey(value); |
1192 |
else if ("fil_veltrack" == key) pCurDef->fil_veltrack = ToInt(value); |
else if ("fil_veltrack" == key) pCurDef->fil_veltrack = ToInt(value); |
1193 |
else if ("fil2_veltrack" == key) pCurDef->fil2_veltrack = ToInt(value); |
else if ("fil2_veltrack" == key) pCurDef->fil2_veltrack = ToInt(value); |
1194 |
else if ("fil_random" == key) pCurDef->fil_random = ToInt(value); |
else if ("fil_random" == key) pCurDef->fil_random = ToInt(value); |
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) |
1274 |
else if ("eq3_gain_on" == key_cc) pCurDef->eq3_gain_oncc[num_cc] = ToInt(value); |
else if ("eq3_gain_on" == key_cc) pCurDef->eq3_gain_oncc[num_cc] = ToInt(value); |
1275 |
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
1276 |
} |
} |
1277 |
// Deprecated opcodes |
// v2 envelope generators |
1278 |
|
else if (sscanf(key.c_str(), "eg%d%n", &x, &y)) { |
1279 |
|
const char* s = key.c_str() + y; |
1280 |
|
if (sscanf(s, "_time%d", &y)) egnode(x, y).time = ToFloat(value); |
1281 |
|
else if (sscanf(s, "_level%d", &y)) egnode(x, y).level = ToFloat(value); |
1282 |
|
else if (sscanf(s, "_shape%d", &y)) egnode(x, y).shape = ToFloat(value); |
1283 |
|
else if (sscanf(s, "_curve%d", &y)) egnode(x, y).curve = ToFloat(value); |
1284 |
|
else if (strcmp(s, "_sustain") == 0) eg(x).sustain = ToInt(value); |
1285 |
|
else if (strcmp(s, "_loop") == 0) eg(x).loop = ToInt(value); |
1286 |
|
else if (strcmp(s, "_loop_count") == 0) eg(x).loop_count = ToInt(value); |
1287 |
|
else if (strcmp(s, "_amplitude") == 0) eg(x).amplitude = ToFloat(value); |
1288 |
|
else if (strcmp(s, "_cutoff") == 0) eg(x).cutoff = ToFloat(value); |
1289 |
|
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
1290 |
|
} |
1291 |
|
|
1292 |
|
// v1 envelope generators |
1293 |
else if ("ampeg_delay" == key) pCurDef->ampeg_delay = ToFloat(value); |
else if ("ampeg_delay" == key) pCurDef->ampeg_delay = ToFloat(value); |
1294 |
else if ("ampeg_start" == key) pCurDef->ampeg_start = ToFloat(value); |
else if ("ampeg_start" == key) pCurDef->ampeg_start = ToFloat(value); |
1295 |
else if ("ampeg_attack" == key) pCurDef->ampeg_attack = ToFloat(value); |
else if ("ampeg_attack" == key) pCurDef->ampeg_attack = ToFloat(value); |
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 |
} |
} |
1332 |
} |
} |
1333 |
|
|
1334 |
|
int File::parseKey(const std::string& s) { |
1335 |
|
int i; |
1336 |
|
std::istringstream iss(s); |
1337 |
|
if (isdigit(iss.peek())) { |
1338 |
|
iss >> i; |
1339 |
|
} else { |
1340 |
|
switch (tolower(iss.get())) { |
1341 |
|
case 'c': i = 0; break; |
1342 |
|
case 'd': i = 2; break; |
1343 |
|
case 'e': i = 4; break; |
1344 |
|
case 'f': i = 5; break; |
1345 |
|
case 'g': i = 7; break; |
1346 |
|
case 'a': i = 9; break; |
1347 |
|
case 'b': i = 11; break; |
1348 |
|
default: |
1349 |
|
std::cerr << "Not a note: " << s << std::endl; |
1350 |
|
return 0; |
1351 |
|
} |
1352 |
|
if (iss.peek() == '#') { |
1353 |
|
i++; |
1354 |
|
iss.get(); |
1355 |
|
} else if (tolower(iss.peek()) == 'b') { |
1356 |
|
i--; |
1357 |
|
iss.get(); |
1358 |
|
} |
1359 |
|
int octave; |
1360 |
|
if (!(iss >> octave)) { |
1361 |
|
std::cerr << "Not a note: " << s << std::endl; |
1362 |
|
return 0; |
1363 |
|
} |
1364 |
|
i += (octave + 1) * 12; |
1365 |
|
} |
1366 |
|
return i + note_offset + 12 * octave_offset; |
1367 |
|
} |
1368 |
|
|
1369 |
|
EGNode::EGNode() : time(0), level(0), shape(0), curve(0) { |
1370 |
|
} |
1371 |
|
|
1372 |
|
EG::EG() : |
1373 |
|
sustain(0), loop(0), loop_count(0), |
1374 |
|
amplitude(0), cutoff(0) { |
1375 |
|
} |
1376 |
|
|
1377 |
|
EG& File::eg(int x) { |
1378 |
|
while (pCurDef->eg.size() <= x) { |
1379 |
|
pCurDef->eg.add(EG()); |
1380 |
|
} |
1381 |
|
return pCurDef->eg[x]; |
1382 |
|
} |
1383 |
|
|
1384 |
|
EGNode& File::egnode(int x, int y) { |
1385 |
|
EG& e = eg(x); |
1386 |
|
while (e.node.size() <= y) { |
1387 |
|
e.node.add(EGNode()); |
1388 |
|
} |
1389 |
|
return e.node[y]; |
1390 |
|
} |
1391 |
|
|
1392 |
} // !namespace sfz |
} // !namespace sfz |