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 * |
142 |
return is_triggered; |
return is_triggered; |
143 |
} |
} |
144 |
|
|
|
bool |
|
|
Region::OnControl(uint8_t chan, uint8_t cont, uint8_t val, |
|
|
int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, |
|
|
uint8_t prog, float rand, trigger_t trig, uint8_t* cc, |
|
|
float timer, bool* sw, uint8_t last_sw_key, uint8_t prev_sw_key) |
|
|
{ |
|
|
// chan (MIDI channel) |
|
|
// cont (MIDI controller) |
|
|
// val (MIDI controller value) |
|
|
|
|
|
// bend (MIDI pitch bend) |
|
|
// bpm (host BPM) |
|
|
// chanaft (MIDI channel pressure) |
|
|
// polyaft (MIDI polyphonic aftertouch) |
|
|
// prog (MIDI program change) |
|
|
// rand (generated random number) |
|
|
// trigger (how it was triggered) |
|
|
// cc (all CC values) |
|
|
|
|
|
// timer (time since previous region in the group was triggered) |
|
|
// sw (the state of region key switches, 128 possible values) |
|
|
// last_sw_key (the last key pressed in the key switch range) |
|
|
// prev_sw_key (the previous note value) |
|
|
|
|
|
bool is_triggered = ( |
|
|
chan >= lochan && chan <= hichan && |
|
|
((val >= on_locc[cont] && val <= on_hicc[cont]) || |
|
|
(val >= start_locc[cont] && val <= start_hicc[cont])) && |
|
|
bend >= lobend && bend <= hibend && |
|
|
bpm >= lobpm && bpm < hibpm && |
|
|
chanaft >= lochanaft && chanaft <= hichanaft && |
|
|
polyaft >= lopolyaft && polyaft <= hipolyaft && |
|
|
prog >= loprog && prog <= hiprog && |
|
|
rand >= lorand && rand < hirand && |
|
|
timer >= lotimer && timer <= hitimer && |
|
|
|
|
|
( sw_last == -1 || |
|
|
((sw_last >= sw_lokey && sw_last <= sw_hikey) ? (last_sw_key == sw_last) : false) ) && |
|
|
|
|
|
( sw_down == -1 || |
|
|
((sw_down >= sw_lokey && (sw_hikey == -1 || sw_down <= sw_hikey)) ? (sw[sw_down]) : false) ) && |
|
|
|
|
|
( sw_up == -1 || |
|
|
((sw_up >= sw_lokey && (sw_hikey == -1 || sw_up <= sw_hikey)) ? (!sw[sw_up]) : true) ) && |
|
|
|
|
|
( sw_previous == -1 || |
|
|
prev_sw_key == sw_previous ) && |
|
|
|
|
|
((trigger & trig) != 0) |
|
|
); |
|
|
|
|
|
if (!is_triggered) |
|
|
return false; |
|
|
|
|
|
for (int i = 0; i < 128; ++i) |
|
|
{ |
|
|
if (locc[i] != -1 && hicc[i] != -1 && !(cc[i] >= locc[i] && cc[i] <= hicc[i])) |
|
|
return false; |
|
|
} |
|
|
|
|
|
return true; |
|
|
} |
|
|
|
|
145 |
Articulation* |
Articulation* |
146 |
Region::GetArticulation(int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, uint8_t* cc) |
Region::GetArticulation(int bend, uint8_t bpm, uint8_t chanaft, uint8_t polyaft, uint8_t* cc) |
147 |
{ |
{ |
149 |
} |
} |
150 |
|
|
151 |
bool Region::HasLoop() { |
bool Region::HasLoop() { |
152 |
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() : |
153 |
|
(loop_mode == ::sfz::LOOP_CONTINUOUS || loop_mode == ::sfz::LOOP_SUSTAIN); |
154 |
return b && GetLoopStart() && GetLoopEnd() && GetLoopEnd() > GetLoopStart(); |
return b && GetLoopStart() && GetLoopEnd() && GetLoopEnd() > GetLoopStart(); |
155 |
} |
} |
156 |
|
|
157 |
uint Region::GetLoopStart() { |
uint Region::GetLoopStart() { |
158 |
return (!loop_start) ? 0 : *loop_start; // TODO: use sample loop when loop_start not defined |
return (!loop_start) ? pSample->GetLoopStart() : *loop_start; |
159 |
} |
} |
160 |
|
|
161 |
uint Region::GetLoopEnd() { |
uint Region::GetLoopEnd() { |
162 |
return (!loop_end) ? 0 : *loop_end; // TODO: use sample loop when loop_end not defined |
return (!loop_end) ? pSample->GetLoopEnd() : *loop_end; |
163 |
} |
} |
164 |
|
|
165 |
uint Region::GetLoopCount() { |
uint Region::GetLoopCount() { |
182 |
delete regions[i]; |
delete regions[i]; |
183 |
} |
} |
184 |
delete pLookupTable; |
delete pLookupTable; |
185 |
|
for (int i = 0 ; i < 128 ; i++) { |
186 |
|
delete pLookupTableCC[i]; |
187 |
|
} |
188 |
} |
} |
189 |
|
|
190 |
void Query::search(const Instrument* pInstrument) { |
void Query::search(const Instrument* pInstrument) { |
192 |
regionIndex = 0; |
regionIndex = 0; |
193 |
} |
} |
194 |
|
|
195 |
|
void Query::search(const Instrument* pInstrument, int triggercc) { |
196 |
|
pRegionList = &pInstrument->pLookupTableCC[triggercc]->query(*this); |
197 |
|
regionIndex = 0; |
198 |
|
} |
199 |
|
|
200 |
Region* Query::next() { |
Region* Query::next() { |
201 |
for ( ; regionIndex < pRegionList->size() ; regionIndex++) { |
for ( ; regionIndex < pRegionList->size() ; regionIndex++) { |
202 |
if ((*pRegionList)[regionIndex]->OnKey(*this)) { |
if ((*pRegionList)[regionIndex]->OnKey(*this)) { |
274 |
trigger = TRIGGER_ATTACK; |
trigger = TRIGGER_ATTACK; |
275 |
|
|
276 |
group = 0; |
group = 0; |
277 |
off_by.unset(); |
off_by = 0; |
278 |
off_mode = OFF_FAST; |
off_mode = OFF_FAST; |
279 |
|
|
280 |
// sample player |
// sample player |
285 |
end.unset(); |
end.unset(); |
286 |
loop_crossfade.unset(); |
loop_crossfade.unset(); |
287 |
offset.unset(); offset_random.unset(); |
offset.unset(); offset_random.unset(); |
288 |
loop_mode = NO_LOOP; |
loop_mode = LOOP_UNSET; |
289 |
loop_start.unset(); loop_end.unset(); |
loop_start.unset(); loop_end.unset(); |
290 |
sync_beats.unset(); sync_offset.unset(); |
sync_beats.unset(); sync_offset.unset(); |
291 |
|
|
778 |
::sfz::Region* pRegion = _instrument->regions[i]; |
::sfz::Region* pRegion = _instrument->regions[i]; |
779 |
int low = pRegion->lokey; |
int low = pRegion->lokey; |
780 |
int high = pRegion->hikey; |
int high = pRegion->hikey; |
781 |
if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) { |
if (low != -1) { // lokey -1 means region doesn't play on note-on |
782 |
std::cerr << "Invalid key range: " << low << " - " << high << std::endl; |
// hikey -1 is the same as no limit, except that it |
783 |
} else { |
// also enables on_locc/on_hicc |
784 |
for (int j = low; j <= high; j++) _instrument->KeyBindings[j] = true; |
if (high == -1) high = 127; |
785 |
|
if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) { |
786 |
|
std::cerr << "Invalid key range: " << low << " - " << high << std::endl; |
787 |
|
} else { |
788 |
|
for (int j = low; j <= high; j++) _instrument->KeyBindings[j] = true; |
789 |
|
} |
790 |
} |
} |
791 |
|
|
792 |
// get keyswitches |
// get keyswitches |
841 |
} |
} |
842 |
|
|
843 |
_instrument->pLookupTable = new LookupTable(_instrument); |
_instrument->pLookupTable = new LookupTable(_instrument); |
844 |
|
|
845 |
|
// create separate lookup tables for controller triggered |
846 |
|
// regions, one for each CC |
847 |
|
for (int i = 0 ; i < 128 ; i++) { |
848 |
|
_instrument->pLookupTableCC[i] = new LookupTable(_instrument, i); |
849 |
|
} |
850 |
} |
} |
851 |
|
|
852 |
File::~File() |
File::~File() |
994 |
else if ("off_by" == key || "offby" == key) pCurDef->off_by = ToInt(value); |
else if ("off_by" == key || "offby" == key) pCurDef->off_by = ToInt(value); |
995 |
else if ("off_mode" == key || "offmode" == key) |
else if ("off_mode" == key || "offmode" == key) |
996 |
{ |
{ |
997 |
if (value == "fast") _current_group->off_mode = OFF_FAST; |
if (value == "fast") pCurDef->off_mode = OFF_FAST; |
998 |
else if (value == "normal") _current_group->off_mode = OFF_NORMAL; |
else if (value == "normal") pCurDef->off_mode = OFF_NORMAL; |
999 |
} |
} |
1000 |
|
|
1001 |
// sample player |
// sample player |
1270 |
case 'g': i = 7; break; |
case 'g': i = 7; break; |
1271 |
case 'a': i = 9; break; |
case 'a': i = 9; break; |
1272 |
case 'b': i = 11; break; |
case 'b': i = 11; break; |
1273 |
|
case '-': if (s == "-1") return -1; |
1274 |
default: |
default: |
1275 |
std::cerr << "Not a note: " << s << std::endl; |
std::cerr << "Not a note: " << s << std::endl; |
1276 |
return 0; |
return 0; |