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" |
36 |
namespace sfz |
namespace sfz |
37 |
{ |
{ |
38 |
|
|
39 |
LinuxSampler::SampleFile* SampleManager::FindSample(std::string samplePath) { |
Sample* SampleManager::FindSample(std::string samplePath) { |
40 |
std::map<LinuxSampler::SampleFile*, std::set<Region*> >::iterator it = sampleMap.begin(); |
std::map<Sample*, std::set<Region*> >::iterator it = sampleMap.begin(); |
41 |
for (; it != sampleMap.end(); it++) { |
for (; it != sampleMap.end(); it++) { |
42 |
if (it->first->GetFile() == samplePath) return it->first; |
if (it->first->GetFile() == samplePath) return it->first; |
43 |
} |
} |
89 |
Region::Region() |
Region::Region() |
90 |
{ |
{ |
91 |
pSample = NULL; |
pSample = NULL; |
92 |
|
seq_counter = 1; |
93 |
} |
} |
94 |
|
|
95 |
Region::~Region() |
Region::~Region() |
97 |
DestroySampleIfNotUsed(); |
DestroySampleIfNotUsed(); |
98 |
} |
} |
99 |
|
|
100 |
LinuxSampler::SampleFile* Region::GetSample(bool create) |
Sample* Region::GetSample(bool create) |
101 |
{ |
{ |
102 |
if(pSample == NULL && create) { |
if(pSample == NULL && create) { |
103 |
LinuxSampler::SampleFile* sf = GetInstrument()->GetSampleManager()->FindSample(sample); |
Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample); |
104 |
if (sf != NULL) pSample = sf; // Reuse already created sample |
if (sf != NULL) pSample = sf; // Reuse already created sample |
105 |
else pSample = new LinuxSampler::SampleFile(sample); |
else pSample = new Sample(sample); |
106 |
GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this); |
GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this); |
107 |
} |
} |
108 |
return pSample; |
return pSample; |
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) |
251 |
return new Articulation(); //todo: implement GetArticulation() |
return new Articulation(); //todo: implement GetArticulation() |
252 |
} |
} |
253 |
|
|
254 |
|
bool Region::HasLoop() { |
255 |
|
bool b = loop_mode == ::sfz::LOOP_CONTINUOUS || loop_mode == ::sfz::LOOP_SUSTAIN; // TODO: ONE_SHOT mode |
256 |
|
return b && GetLoopStart() && GetLoopEnd() && GetLoopEnd() > GetLoopStart(); |
257 |
|
} |
258 |
|
|
259 |
|
uint Region::GetLoopStart() { |
260 |
|
return (!loop_start) ? 0 : *loop_start; // TODO: use sample loop when loop_start not defined |
261 |
|
} |
262 |
|
|
263 |
|
uint Region::GetLoopEnd() { |
264 |
|
return (!loop_end) ? 0 : *loop_end; // TODO: use sample loop when loop_end not defined |
265 |
|
} |
266 |
|
|
267 |
|
uint Region::GetLoopCount() { |
268 |
|
return (!count) ? 0 : *count; |
269 |
|
} |
270 |
|
|
271 |
///////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////// |
272 |
// class Instrument |
// class Instrument |
273 |
|
|
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 |
|
|
369 |
|
|
370 |
trigger = TRIGGER_ATTACK; |
trigger = TRIGGER_ATTACK; |
371 |
|
|
372 |
group.unset(); |
group = 0; |
373 |
off_by.unset(); |
off_by.unset(); |
374 |
off_mode = OFF_FAST; |
off_mode = OFF_FAST; |
375 |
|
|
508 |
eq2_gain_oncc[i] = 0; |
eq2_gain_oncc[i] = 0; |
509 |
eq3_gain_oncc[i] = 0; |
eq3_gain_oncc[i] = 0; |
510 |
} |
} |
511 |
|
|
512 |
|
eg.clear(); |
513 |
|
|
514 |
|
// deprecated |
515 |
|
ampeg_delay = 0; |
516 |
|
ampeg_start = 0; //in percentage |
517 |
|
ampeg_attack = 0; |
518 |
|
ampeg_hold = 0; |
519 |
|
ampeg_decay = 0; |
520 |
|
ampeg_sustain = 100; // in percentage |
521 |
|
ampeg_release = 0; |
522 |
|
|
523 |
|
fileg_delay = 0; |
524 |
|
fileg_start = 0; //in percentage |
525 |
|
fileg_attack = 0; |
526 |
|
fileg_hold = 0; |
527 |
|
fileg_decay = 0; |
528 |
|
fileg_sustain = 100; // in percentage |
529 |
|
fileg_release = 0; |
530 |
|
|
531 |
|
pitcheg_delay = 0; |
532 |
|
pitcheg_start = 0; //in percentage |
533 |
|
pitcheg_attack = 0; |
534 |
|
pitcheg_hold = 0; |
535 |
|
pitcheg_decay = 0; |
536 |
|
pitcheg_sustain = 100; // in percentage |
537 |
|
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* |
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 |
736 |
|
region->ampeg_delay = ampeg_delay; |
737 |
|
region->ampeg_start = ampeg_start; |
738 |
|
region->ampeg_attack = ampeg_attack; |
739 |
|
region->ampeg_hold = ampeg_hold; |
740 |
|
region->ampeg_decay = ampeg_decay; |
741 |
|
region->ampeg_sustain = ampeg_sustain; |
742 |
|
region->ampeg_release = ampeg_release; |
743 |
|
|
744 |
|
region->fileg_delay = fileg_delay; |
745 |
|
region->fileg_start = fileg_start; |
746 |
|
region->fileg_attack = fileg_attack; |
747 |
|
region->fileg_hold = fileg_hold; |
748 |
|
region->fileg_decay = fileg_decay; |
749 |
|
region->fileg_sustain = fileg_sustain; |
750 |
|
region->fileg_release = fileg_release; |
751 |
|
|
752 |
|
region->pitcheg_delay = pitcheg_delay; |
753 |
|
region->pitcheg_start = pitcheg_start; |
754 |
|
region->pitcheg_attack = pitcheg_attack; |
755 |
|
region->pitcheg_hold = pitcheg_hold; |
756 |
|
region->pitcheg_decay = pitcheg_decay; |
757 |
|
region->pitcheg_sustain = pitcheg_sustain; |
758 |
|
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; |
911 |
{ |
{ |
912 |
_current_section = GROUP; |
_current_section = GROUP; |
913 |
_current_group->Reset(); |
_current_group->Reset(); |
914 |
pCurDef = _current_group; |
pCurDef = _current_group; |
915 |
} |
} |
916 |
else if (token == "<region>") |
else if (token == "<region>") |
917 |
{ |
{ |
918 |
_current_section = REGION; |
_current_section = REGION; |
919 |
_current_region = _current_group->RegionFactory(); |
_current_region = _current_group->RegionFactory(); |
920 |
pCurDef = _current_region; |
pCurDef = _current_region; |
921 |
_instrument->regions.push_back(_current_region); |
_instrument->regions.push_back(_current_region); |
922 |
_current_region->SetInstrument(_instrument); |
_current_region->SetInstrument(_instrument); |
923 |
} |
} |
924 |
else if (token == "<control>") |
else if (token == "<control>") |
925 |
{ |
{ |
944 |
std::string::size_type delimiter_index = token.find('='); |
std::string::size_type delimiter_index = token.find('='); |
945 |
std::string key = token.substr(0, delimiter_index); |
std::string key = token.substr(0, delimiter_index); |
946 |
std::string value = token.substr(delimiter_index + 1); |
std::string value = token.substr(delimiter_index + 1); |
947 |
|
int x, y; |
948 |
|
|
949 |
// sample definition |
// sample definition |
950 |
if ("sample" == key) |
if ("sample" == key) |
991 |
// input controls |
// input controls |
992 |
else if ("lochan" == key) pCurDef->lochan = ToInt(value); |
else if ("lochan" == key) pCurDef->lochan = ToInt(value); |
993 |
else if ("hichan" == key) pCurDef->hichan = ToInt(value); |
else if ("hichan" == key) pCurDef->hichan = ToInt(value); |
994 |
else if ("lokey" == key) pCurDef->lokey = ToInt(value) + note_offset + 12 * octave_offset; |
else if ("lokey" == key) pCurDef->lokey = parseKey(value); |
995 |
else if ("hikey" == key) pCurDef->hikey = ToInt(value) + note_offset + 12 * octave_offset; |
else if ("hikey" == key) pCurDef->hikey = parseKey(value); |
996 |
else if ("key" == key) |
else if ("key" == key) |
997 |
{ |
{ |
998 |
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; |
|
999 |
} |
} |
1000 |
else if ("lovel" == key) pCurDef->lovel = ToInt(value); |
else if ("lovel" == key) pCurDef->lovel = ToInt(value); |
1001 |
else if ("hivel" == key) pCurDef->hivel = ToInt(value); |
else if ("hivel" == key) pCurDef->hivel = ToInt(value); |
1015 |
else if ("hitimer" == key) pCurDef->hitimer = ToFloat(value); |
else if ("hitimer" == key) pCurDef->hitimer = ToFloat(value); |
1016 |
else if ("seq_length" == key) pCurDef->seq_length = ToInt(value); |
else if ("seq_length" == key) pCurDef->seq_length = ToInt(value); |
1017 |
else if ("seq_position" == key) pCurDef->seq_position = ToInt(value); |
else if ("seq_position" == key) pCurDef->seq_position = ToInt(value); |
1018 |
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); |
1019 |
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); |
1020 |
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); |
1021 |
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); |
1022 |
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); |
1023 |
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); |
1024 |
else if ("sw_vel" == key) |
else if ("sw_vel" == key) |
1025 |
{ |
{ |
1026 |
if (value == "current") pCurDef->sw_vel = VEL_CURRENT; |
if (value == "current") pCurDef->sw_vel = VEL_CURRENT; |
1034 |
else if (value == "legato") pCurDef->trigger = TRIGGER_LEGATO; |
else if (value == "legato") pCurDef->trigger = TRIGGER_LEGATO; |
1035 |
} |
} |
1036 |
else if ("group" == key) pCurDef->group = ToInt(value); |
else if ("group" == key) pCurDef->group = ToInt(value); |
1037 |
else if ("off_by" == key) pCurDef->off_by = ToInt(value); |
else if ("off_by" == key || "offby" == key) pCurDef->off_by = ToInt(value); |
1038 |
else if ("off_mode" == key) |
else if ("off_mode" == key || "offmode" == key) |
1039 |
{ |
{ |
1040 |
if (value == "fast") _current_group->off_mode = OFF_FAST; |
if (value == "fast") _current_group->off_mode = OFF_FAST; |
1041 |
else if (value == "normal") _current_group->off_mode = OFF_NORMAL; |
else if (value == "normal") _current_group->off_mode = OFF_NORMAL; |
1042 |
} |
} |
1043 |
|
|
1044 |
// sample player |
// sample player |
1045 |
else if ("count" == key) pCurDef->count = ToInt(value); |
else if ("count" == key) { pCurDef->count = ToInt(value); pCurDef->loop_mode = ONE_SHOT; } |
1046 |
else if ("delay" == key) pCurDef->delay = ToFloat(value); |
else if ("delay" == key) pCurDef->delay = ToFloat(value); |
1047 |
else if ("delay_random" == key) pCurDef->delay_random = ToFloat(value); |
else if ("delay_random" == key) pCurDef->delay_random = ToFloat(value); |
1048 |
else if ("delay_beats" == key) pCurDef->delay_beats = ToInt(value); |
else if ("delay_beats" == key) pCurDef->delay_beats = ToInt(value); |
1051 |
else if ("end" == key) pCurDef->end = ToInt(value); |
else if ("end" == key) pCurDef->end = ToInt(value); |
1052 |
else if ("loop_crossfade" == key) pCurDef->loop_crossfade = ToFloat(value); |
else if ("loop_crossfade" == key) pCurDef->loop_crossfade = ToFloat(value); |
1053 |
else if ("offset_random" == key) pCurDef->offset_random = ToInt(value); |
else if ("offset_random" == key) pCurDef->offset_random = ToInt(value); |
1054 |
else if ("loop_mode" == key) |
else if ("loop_mode" == key || "loopmode" == key) |
1055 |
{ |
{ |
1056 |
if (value == "no_loop") pCurDef->loop_mode = NO_LOOP; |
if (value == "no_loop") pCurDef->loop_mode = NO_LOOP; |
1057 |
else if (value == "one_shot") pCurDef->loop_mode = ONE_SHOT; |
else if (value == "one_shot") pCurDef->loop_mode = ONE_SHOT; |
1058 |
else if (value == "loop_continous") pCurDef->loop_mode = LOOP_CONTINOUS; |
else if (value == "loop_continuous") pCurDef->loop_mode = LOOP_CONTINUOUS; |
1059 |
else if (value == "loop_sustain") pCurDef->loop_mode = LOOP_SUSTAIN; |
else if (value == "loop_sustain") pCurDef->loop_mode = LOOP_SUSTAIN; |
1060 |
} |
} |
1061 |
else if ("loop_start" == key) pCurDef->loop_start = ToInt(value); |
else if ("loop_start" == key) pCurDef->loop_start = ToInt(value); |
1062 |
|
else if ("loopstart" == key) pCurDef->loop_start = ToInt(value); // nonstandard |
1063 |
else if ("loop_end" == key) pCurDef->loop_end = ToInt(value); |
else if ("loop_end" == key) pCurDef->loop_end = ToInt(value); |
1064 |
|
else if ("loopend" == key) pCurDef->loop_end = ToInt(value); // nonstandard |
1065 |
else if ("sync_beats" == key) pCurDef->sync_beats = ToInt(value); |
else if ("sync_beats" == key) pCurDef->sync_beats = ToInt(value); |
1066 |
else if ("sync_offset" == key) pCurDef->sync_offset = ToInt(value); |
else if ("sync_offset" == key) pCurDef->sync_offset = ToInt(value); |
1067 |
|
|
1071 |
else if ("width" == key) pCurDef->width = ToFloat(value); |
else if ("width" == key) pCurDef->width = ToFloat(value); |
1072 |
else if ("position" == key) pCurDef->position = ToFloat(value); |
else if ("position" == key) pCurDef->position = ToFloat(value); |
1073 |
else if ("amp_keytrack" == key) pCurDef->amp_keytrack = ToFloat(value); |
else if ("amp_keytrack" == key) pCurDef->amp_keytrack = ToFloat(value); |
1074 |
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); |
1075 |
else if ("amp_veltrack" == key) pCurDef->amp_veltrack = ToFloat(value); |
else if ("amp_veltrack" == key) pCurDef->amp_veltrack = ToFloat(value); |
1076 |
else if ("amp_random" == key) pCurDef->amp_random = ToFloat(value); |
else if ("amp_random" == key) pCurDef->amp_random = ToFloat(value); |
1077 |
else if ("rt_decay" == key) pCurDef->rt_decay = ToFloat(value); |
else if ("rt_decay" == key) pCurDef->rt_decay = ToFloat(value); |
1078 |
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); |
1079 |
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); |
1080 |
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); |
1081 |
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); |
1082 |
else if ("xf_keycurve" == key) |
else if ("xf_keycurve" == key) |
1083 |
{ |
{ |
1084 |
if (value == "gain") pCurDef->xf_keycurve = GAIN; |
if (value == "gain") pCurDef->xf_keycurve = GAIN; |
1102 |
// pitch |
// pitch |
1103 |
else if ("transpose" == key) pCurDef->transpose = ToInt(value); |
else if ("transpose" == key) pCurDef->transpose = ToInt(value); |
1104 |
else if ("tune" == key) pCurDef->tune = ToInt(value); |
else if ("tune" == key) pCurDef->tune = ToInt(value); |
1105 |
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); |
1106 |
else if ("pitch_keytrack" == key) pCurDef->pitch_keytrack = ToInt(value); |
else if ("pitch_keytrack" == key) pCurDef->pitch_keytrack = ToInt(value); |
1107 |
else if ("pitch_veltrack" == key) pCurDef->pitch_veltrack = ToInt(value); |
else if ("pitch_veltrack" == key) pCurDef->pitch_veltrack = ToInt(value); |
1108 |
else if ("pitch_random" == key) pCurDef->pitch_random = ToInt(value); |
else if ("pitch_random" == key) pCurDef->pitch_random = ToInt(value); |
1109 |
else if ("bend_up" == key) pCurDef->bend_up = ToInt(value); |
else if ("bend_up" == key || "bendup" == key) pCurDef->bend_up = ToInt(value); |
1110 |
else if ("bend_down" == key) pCurDef->bend_down = ToInt(value); |
else if ("bend_down" == key || "benddown" == key) pCurDef->bend_down = ToInt(value); |
1111 |
else if ("bend_step" == key) pCurDef->bend_step = ToInt(value); |
else if ("bend_step" == key) pCurDef->bend_step = ToInt(value); |
1112 |
|
|
1113 |
// filter |
// filter |
1155 |
else if ("resonance2" == key) pCurDef->resonance2 = ToFloat(value); |
else if ("resonance2" == key) pCurDef->resonance2 = ToFloat(value); |
1156 |
else if ("fil_keytrack" == key) pCurDef->fil_keytrack = ToInt(value); |
else if ("fil_keytrack" == key) pCurDef->fil_keytrack = ToInt(value); |
1157 |
else if ("fil2_keytrack" == key) pCurDef->fil2_keytrack = ToInt(value); |
else if ("fil2_keytrack" == key) pCurDef->fil2_keytrack = ToInt(value); |
1158 |
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); |
1159 |
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); |
1160 |
else if ("fil_veltrack" == key) pCurDef->fil_veltrack = ToInt(value); |
else if ("fil_veltrack" == key) pCurDef->fil_veltrack = ToInt(value); |
1161 |
else if ("fil2_veltrack" == key) pCurDef->fil2_veltrack = ToInt(value); |
else if ("fil2_veltrack" == key) pCurDef->fil2_veltrack = ToInt(value); |
1162 |
else if ("fil_random" == key) pCurDef->fil_random = ToInt(value); |
else if ("fil_random" == key) pCurDef->fil_random = ToInt(value); |
1239 |
else if ("eq2_gain_on" == key_cc) pCurDef->eq2_gain_oncc[num_cc] = ToInt(value); |
else if ("eq2_gain_on" == key_cc) pCurDef->eq2_gain_oncc[num_cc] = ToInt(value); |
1240 |
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); |
1241 |
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
1242 |
} else { |
} |
1243 |
|
// v2 envelope generators |
1244 |
|
else if (sscanf(key.c_str(), "eg%d%n", &x, &y)) { |
1245 |
|
const char* s = key.c_str() + y; |
1246 |
|
if (sscanf(s, "_time%d", &y)) egnode(x, y).time = ToFloat(value); |
1247 |
|
else if (sscanf(s, "_level%d", &y)) egnode(x, y).level = ToFloat(value); |
1248 |
|
else if (sscanf(s, "_shape%d", &y)) egnode(x, y).shape = ToFloat(value); |
1249 |
|
else if (sscanf(s, "_curve%d", &y)) egnode(x, y).curve = ToFloat(value); |
1250 |
|
else if (strcmp(s, "_sustain") == 0) eg(x).sustain = ToInt(value); |
1251 |
|
else if (strcmp(s, "_loop") == 0) eg(x).loop = ToInt(value); |
1252 |
|
else if (strcmp(s, "_loop_count") == 0) eg(x).loop_count = ToInt(value); |
1253 |
|
else if (strcmp(s, "_amplitude") == 0) eg(x).amplitude = ToFloat(value); |
1254 |
|
else if (strcmp(s, "_cutoff") == 0) eg(x).cutoff = ToFloat(value); |
1255 |
|
else std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
1256 |
|
} |
1257 |
|
|
1258 |
|
// v1 envelope generators |
1259 |
|
else if ("ampeg_delay" == key) pCurDef->ampeg_delay = ToFloat(value); |
1260 |
|
else if ("ampeg_start" == key) pCurDef->ampeg_start = ToFloat(value); |
1261 |
|
else if ("ampeg_attack" == key) pCurDef->ampeg_attack = ToFloat(value); |
1262 |
|
else if ("ampeg_hold" == key) pCurDef->ampeg_hold = ToFloat(value); |
1263 |
|
else if ("ampeg_decay" == key) pCurDef->ampeg_decay = ToFloat(value); |
1264 |
|
else if ("ampeg_sustain" == key) pCurDef->ampeg_sustain = ToFloat(value); |
1265 |
|
else if ("ampeg_release" == key) pCurDef->ampeg_release = ToFloat(value); |
1266 |
|
else if ("fileg_delay" == key) pCurDef->fileg_delay = ToFloat(value); |
1267 |
|
else if ("fileg_start" == key) pCurDef->fileg_start = ToFloat(value); |
1268 |
|
else if ("fileg_attack" == key) pCurDef->fileg_attack = ToFloat(value); |
1269 |
|
else if ("fileg_hold" == key) pCurDef->fileg_hold = ToFloat(value); |
1270 |
|
else if ("fileg_decay" == key) pCurDef->fileg_decay = ToFloat(value); |
1271 |
|
else if ("fileg_sustain" == key) pCurDef->fileg_sustain = ToFloat(value); |
1272 |
|
else if ("fileg_release" == key) pCurDef->fileg_release = ToFloat(value); |
1273 |
|
else if ("pitcheg_delay" == key) pCurDef->pitcheg_delay = ToFloat(value); |
1274 |
|
else if ("pitcheg_start" == key) pCurDef->pitcheg_start = ToFloat(value); |
1275 |
|
else if ("pitcheg_attack" == key) pCurDef->pitcheg_attack = ToFloat(value); |
1276 |
|
else if ("pitcheg_hold" == key) pCurDef->pitcheg_hold = ToFloat(value); |
1277 |
|
else if ("pitcheg_decay" == key) pCurDef->pitcheg_decay = ToFloat(value); |
1278 |
|
else if ("pitcheg_sustain" == key) pCurDef->pitcheg_sustain = ToFloat(value); |
1279 |
|
else if ("pitcheg_release" == key) pCurDef->pitcheg_release = ToFloat(value); |
1280 |
|
|
1281 |
|
// v1 LFO |
1282 |
|
else if ("amplfo_delay" == key) pCurDef->amplfo_delay = ToFloat(value); |
1283 |
|
else if ("amplfo_fade" == key) pCurDef->amplfo_fade = ToFloat(value); |
1284 |
|
else if ("amplfo_freq" == key) pCurDef->amplfo_freq = ToFloat(value); |
1285 |
|
else if ("amplfo_depth" == key) pCurDef->amplfo_depth = ToFloat(value); |
1286 |
|
else if ("fillfo_delay" == key) pCurDef->fillfo_delay = ToFloat(value); |
1287 |
|
else if ("fillfo_fade" == key) pCurDef->fillfo_fade = ToFloat(value); |
1288 |
|
else if ("fillfo_freq" == key) pCurDef->fillfo_freq = ToFloat(value); |
1289 |
|
else if ("fillfo_depth" == key) pCurDef->fillfo_depth = ToFloat(value); |
1290 |
|
else if ("pitchlfo_delay" == key) pCurDef->pitchlfo_delay = ToFloat(value); |
1291 |
|
else if ("pitchlfo_fade" == key) pCurDef->pitchlfo_fade = ToFloat(value); |
1292 |
|
else if ("pitchlfo_freq" == key) pCurDef->pitchlfo_freq = ToFloat(value); |
1293 |
|
else if ("pitchlfo_depth" == key) pCurDef->pitchlfo_depth = ToInt(value); |
1294 |
|
|
1295 |
|
else { |
1296 |
std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
std::cerr << "The opcode '" << key << "' is unsupported by libsfz!" << std::endl; |
1297 |
} |
} |
1298 |
} |
} |
1299 |
|
|
1300 |
|
int File::parseKey(const std::string& s) { |
1301 |
|
int i; |
1302 |
|
std::istringstream iss(s); |
1303 |
|
if (isdigit(iss.peek())) { |
1304 |
|
iss >> i; |
1305 |
|
} else { |
1306 |
|
switch (tolower(iss.get())) { |
1307 |
|
case 'c': i = 0; break; |
1308 |
|
case 'd': i = 2; break; |
1309 |
|
case 'e': i = 4; break; |
1310 |
|
case 'f': i = 5; break; |
1311 |
|
case 'g': i = 7; break; |
1312 |
|
case 'a': i = 9; break; |
1313 |
|
case 'b': i = 11; break; |
1314 |
|
default: |
1315 |
|
std::cerr << "Not a note: " << s << std::endl; |
1316 |
|
return 0; |
1317 |
|
} |
1318 |
|
if (iss.peek() == '#') { |
1319 |
|
i++; |
1320 |
|
iss.get(); |
1321 |
|
} else if (tolower(iss.peek()) == 'b') { |
1322 |
|
i--; |
1323 |
|
iss.get(); |
1324 |
|
} |
1325 |
|
int octave; |
1326 |
|
if (!(iss >> octave)) { |
1327 |
|
std::cerr << "Not a note: " << s << std::endl; |
1328 |
|
return 0; |
1329 |
|
} |
1330 |
|
i += (octave + 1) * 12; |
1331 |
|
} |
1332 |
|
return i + note_offset + 12 * octave_offset; |
1333 |
|
} |
1334 |
|
|
1335 |
|
EGNode::EGNode() : time(0), level(0), shape(0), curve(0) { |
1336 |
|
} |
1337 |
|
|
1338 |
|
EG::EG() : |
1339 |
|
sustain(0), loop(0), loop_count(0), |
1340 |
|
amplitude(0), cutoff(0) { |
1341 |
|
} |
1342 |
|
|
1343 |
|
EG& File::eg(int x) { |
1344 |
|
while (pCurDef->eg.size() <= x) { |
1345 |
|
pCurDef->eg.add(EG()); |
1346 |
|
} |
1347 |
|
return pCurDef->eg[x]; |
1348 |
|
} |
1349 |
|
|
1350 |
|
EGNode& File::egnode(int x, int y) { |
1351 |
|
EG& e = eg(x); |
1352 |
|
while (e.node.size() <= y) { |
1353 |
|
e.node.add(EGNode()); |
1354 |
|
} |
1355 |
|
return e.node[y]; |
1356 |
|
} |
1357 |
|
|
1358 |
} // !namespace sfz |
} // !namespace sfz |