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 * |
37 |
namespace sfz |
namespace sfz |
38 |
{ |
{ |
39 |
|
|
40 |
Sample* SampleManager::FindSample(std::string samplePath) { |
Sample* SampleManager::FindSample(std::string samplePath, int offset) { |
41 |
std::map<Sample*, std::set<Region*> >::iterator it = sampleMap.begin(); |
std::map<Sample*, std::set<Region*> >::iterator it = sampleMap.begin(); |
42 |
for (; it != sampleMap.end(); it++) { |
for (; it != sampleMap.end(); it++) { |
43 |
if (it->first->GetFile() == samplePath) return it->first; |
if (it->first->GetFile() == samplePath) { |
44 |
|
/* Because the start of the sample is cached in RAM we treat |
45 |
|
* same sample with different offset as different samples |
46 |
|
* // TODO: Ignore offset when the whole sample is cached in RAM? |
47 |
|
*/ |
48 |
|
int maxOffset = it->first->MaxOffset; |
49 |
|
if(it->first->Offset == offset || (it->first->Offset < maxOffset && offset < maxOffset)) { |
50 |
|
return it->first; |
51 |
|
} |
52 |
|
} |
53 |
} |
} |
54 |
|
|
55 |
return NULL; |
return NULL; |
99 |
Sample* Region::GetSample(bool create) |
Sample* Region::GetSample(bool create) |
100 |
{ |
{ |
101 |
if(pSample == NULL && create) { |
if(pSample == NULL && create) { |
102 |
Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample); |
int i = offset ? *offset : 0; |
103 |
|
Sample* sf = GetInstrument()->GetSampleManager()->FindSample(sample, i); |
104 |
if (sf != NULL) pSample = sf; // Reuse already created sample |
if (sf != NULL) pSample = sf; // Reuse already created sample |
105 |
else pSample = new Sample(sample); |
else pSample = new Sample(sample, false, i); |
106 |
GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this); |
GetInstrument()->GetSampleManager()->AddSampleConsumer(pSample, this); |
107 |
} |
} |
108 |
return pSample; |
return pSample; |
159 |
} |
} |
160 |
|
|
161 |
bool Region::HasLoop() { |
bool Region::HasLoop() { |
162 |
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() : |
163 |
|
(loop_mode == ::sfz::LOOP_CONTINUOUS || loop_mode == ::sfz::LOOP_SUSTAIN); |
164 |
return b && GetLoopStart() && GetLoopEnd() && GetLoopEnd() > GetLoopStart(); |
return b && GetLoopStart() && GetLoopEnd() && GetLoopEnd() > GetLoopStart(); |
165 |
} |
} |
166 |
|
|
167 |
uint Region::GetLoopStart() { |
uint Region::GetLoopStart() { |
168 |
return (!loop_start) ? 0 : *loop_start; // TODO: use sample loop when loop_start not defined |
return (!loop_start) ? pSample->GetLoopStart() : *loop_start; |
169 |
} |
} |
170 |
|
|
171 |
uint Region::GetLoopEnd() { |
uint Region::GetLoopEnd() { |
172 |
return (!loop_end) ? 0 : *loop_end; // TODO: use sample loop when loop_end not defined |
return (!loop_end) ? pSample->GetLoopEnd() : *loop_end; |
173 |
} |
} |
174 |
|
|
175 |
uint Region::GetLoopCount() { |
uint Region::GetLoopCount() { |
295 |
end.unset(); |
end.unset(); |
296 |
loop_crossfade.unset(); |
loop_crossfade.unset(); |
297 |
offset.unset(); offset_random.unset(); |
offset.unset(); offset_random.unset(); |
298 |
loop_mode = NO_LOOP; |
loop_mode = LOOP_UNSET; |
299 |
loop_start.unset(); loop_end.unset(); |
loop_start.unset(); loop_end.unset(); |
300 |
sync_beats.unset(); sync_offset.unset(); |
sync_beats.unset(); sync_offset.unset(); |
301 |
|
|
422 |
eq2_gain_oncc.set(i, 0); |
eq2_gain_oncc.set(i, 0); |
423 |
eq3_gain_oncc.set(i, 0); |
eq3_gain_oncc.set(i, 0); |
424 |
} |
} |
425 |
|
cutoff_cc = 0; |
426 |
|
|
427 |
eg.clear(); |
eg.clear(); |
428 |
|
|
435 |
ampeg_sustain = 100; // in percentage |
ampeg_sustain = 100; // in percentage |
436 |
ampeg_release = 0; |
ampeg_release = 0; |
437 |
|
|
438 |
|
ampeg_vel2delay = 0; |
439 |
|
ampeg_vel2attack = 0; |
440 |
|
ampeg_vel2hold = 0; |
441 |
|
ampeg_vel2decay = 0; |
442 |
|
ampeg_vel2sustain = 0; |
443 |
|
ampeg_vel2release = 0; |
444 |
|
|
445 |
fileg_delay = 0; |
fileg_delay = 0; |
446 |
fileg_start = 0; //in percentage |
fileg_start = 0; //in percentage |
447 |
fileg_attack = 0; |
fileg_attack = 0; |
592 |
region->fil_type = fil_type; |
region->fil_type = fil_type; |
593 |
region->cutoff = cutoff; |
region->cutoff = cutoff; |
594 |
region->cutoff_oncc = cutoff_oncc; |
region->cutoff_oncc = cutoff_oncc; |
595 |
|
region->cutoff_cc = cutoff_cc; |
596 |
region->cutoff_smoothcc = cutoff_smoothcc; |
region->cutoff_smoothcc = cutoff_smoothcc; |
597 |
region->cutoff_stepcc = cutoff_stepcc; |
region->cutoff_stepcc = cutoff_stepcc; |
598 |
region->cutoff_curvecc = cutoff_curvecc; |
region->cutoff_curvecc = cutoff_curvecc; |
664 |
region->ampeg_sustain = ampeg_sustain; |
region->ampeg_sustain = ampeg_sustain; |
665 |
region->ampeg_release = ampeg_release; |
region->ampeg_release = ampeg_release; |
666 |
|
|
667 |
|
region->ampeg_vel2delay = ampeg_vel2delay; |
668 |
|
region->ampeg_vel2attack = ampeg_vel2attack; |
669 |
|
region->ampeg_vel2hold = ampeg_vel2hold; |
670 |
|
region->ampeg_vel2decay = ampeg_vel2decay; |
671 |
|
region->ampeg_vel2sustain = ampeg_vel2sustain; |
672 |
|
region->ampeg_vel2release = ampeg_vel2release; |
673 |
|
|
674 |
region->fileg_delay = fileg_delay; |
region->fileg_delay = fileg_delay; |
675 |
region->fileg_start = fileg_start; |
region->fileg_start = fileg_start; |
676 |
region->fileg_attack = fileg_attack; |
region->fileg_attack = fileg_attack; |
1045 |
else if ("loopstart" == key) pCurDef->loop_start = ToInt(value); // nonstandard |
else if ("loopstart" == key) pCurDef->loop_start = ToInt(value); // nonstandard |
1046 |
else if ("loop_end" == key) pCurDef->loop_end = ToInt(value); |
else if ("loop_end" == key) pCurDef->loop_end = ToInt(value); |
1047 |
else if ("loopend" == key) pCurDef->loop_end = ToInt(value); // nonstandard |
else if ("loopend" == key) pCurDef->loop_end = ToInt(value); // nonstandard |
1048 |
|
else if ("offset" == key) pCurDef->offset = ToInt(value); |
1049 |
else if ("sync_beats" == key) pCurDef->sync_beats = ToInt(value); |
else if ("sync_beats" == key) pCurDef->sync_beats = ToInt(value); |
1050 |
else if ("sync_offset" == key) pCurDef->sync_offset = ToInt(value); |
else if ("sync_offset" == key) pCurDef->sync_offset = ToInt(value); |
1051 |
|
|
1197 |
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)); |
1198 |
|
|
1199 |
// filter |
// filter |
1200 |
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) { |
1201 |
else if ("cutoff2_on" == key_cc) pCurDef->cutoff2_oncc.set(num_cc, ToInt(value)); |
pCurDef->cutoff_oncc.set(num_cc, ToInt(value)); |
1202 |
|
pCurDef->cutoff_cc = num_cc; |
1203 |
|
} else if ("cutoff2_on" == key_cc) pCurDef->cutoff2_oncc.set(num_cc, ToInt(value)); |
1204 |
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)); |
1205 |
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)); |
1206 |
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)); |
1250 |
else if ("ampeg_hold" == key) pCurDef->ampeg_hold = ToFloat(value); |
else if ("ampeg_hold" == key) pCurDef->ampeg_hold = ToFloat(value); |
1251 |
else if ("ampeg_decay" == key) pCurDef->ampeg_decay = ToFloat(value); |
else if ("ampeg_decay" == key) pCurDef->ampeg_decay = ToFloat(value); |
1252 |
else if ("ampeg_sustain" == key) pCurDef->ampeg_sustain = ToFloat(value); |
else if ("ampeg_sustain" == key) pCurDef->ampeg_sustain = ToFloat(value); |
1253 |
else if ("ampeg_release" == key) pCurDef->ampeg_release = ToFloat(value); |
else if ("ampeg_release" == key) pCurDef->ampeg_release = ToFloat(value); |
1254 |
|
else if ("ampeg_vel2delay" == key) pCurDef->ampeg_vel2delay = ToFloat(value); |
1255 |
|
else if ("ampeg_vel2attack" == key) pCurDef->ampeg_vel2attack = ToFloat(value); |
1256 |
|
else if ("ampeg_vel2hold" == key) pCurDef->ampeg_vel2hold = ToFloat(value); |
1257 |
|
else if ("ampeg_vel2decay" == key) pCurDef->ampeg_vel2decay = ToFloat(value); |
1258 |
|
else if ("ampeg_vel2sustain" == key) pCurDef->ampeg_vel2sustain = ToFloat(value); |
1259 |
|
else if ("ampeg_vel2release" == key) pCurDef->ampeg_vel2release = ToFloat(value); |
1260 |
else if ("fileg_delay" == key) pCurDef->fileg_delay = ToFloat(value); |
else if ("fileg_delay" == key) pCurDef->fileg_delay = ToFloat(value); |
1261 |
else if ("fileg_start" == key) pCurDef->fileg_start = ToFloat(value); |
else if ("fileg_start" == key) pCurDef->fileg_start = ToFloat(value); |
1262 |
else if ("fileg_attack" == key) pCurDef->fileg_attack = ToFloat(value); |
else if ("fileg_attack" == key) pCurDef->fileg_attack = ToFloat(value); |