54 |
|
|
55 |
String InstrumentResourceManager::GetInstrumentName(instrument_id_t ID) { |
String InstrumentResourceManager::GetInstrumentName(instrument_id_t ID) { |
56 |
Lock(); |
Lock(); |
57 |
::sf2::InstrumentBase* pInstrument = Resource(ID, false); |
::sf2::Preset* pInstrument = Resource(ID, false); |
58 |
String res = (pInstrument) ? pInstrument->GetName() : ""; |
String res = (pInstrument) ? pInstrument->GetName() : ""; |
59 |
Unlock(); |
Unlock(); |
60 |
return res; |
return res; |
89 |
|
|
90 |
InstrumentResourceManager::instrument_info_t InstrumentResourceManager::GetInstrumentInfo(instrument_id_t ID) throw (InstrumentManagerException) { |
InstrumentResourceManager::instrument_info_t InstrumentResourceManager::GetInstrumentInfo(instrument_id_t ID) throw (InstrumentManagerException) { |
91 |
Lock(); |
Lock(); |
92 |
::sf2::InstrumentBase* pInstrument = Resource(ID, false); |
::sf2::Preset* pInstrument = Resource(ID, false); |
93 |
bool loaded = (pInstrument != NULL); |
bool loaded = (pInstrument != NULL); |
94 |
if (!loaded) Unlock(); |
if (!loaded) Unlock(); |
95 |
|
|
116 |
for (int i = 0; i < pInstrument->GetRegionCount(); i++) { |
for (int i = 0; i < pInstrument->GetRegionCount(); i++) { |
117 |
int low = pInstrument->GetRegion(i)->loKey; |
int low = pInstrument->GetRegion(i)->loKey; |
118 |
int high = pInstrument->GetRegion(i)->hiKey; |
int high = pInstrument->GetRegion(i)->hiKey; |
119 |
if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) { |
if (low == ::sf2::NONE || high == ::sf2::NONE) { |
120 |
std::cerr << "Invalid key range: " << low << " - " << high << std::endl; |
::sf2::Instrument* layer = pInstrument->GetRegion(i)->pInstrument; |
121 |
|
for (int j = 0; j < layer->GetRegionCount(); j++) { |
122 |
|
int lo = layer->GetRegion(j)->loKey; |
123 |
|
int hi = layer->GetRegion(j)->hiKey; |
124 |
|
SetKeyBindings(info.KeyBindings, lo, hi, ::sf2::NONE); |
125 |
|
} |
126 |
} else { |
} else { |
127 |
for (int i = low; i <= high; i++) info.KeyBindings[i] = 1; |
SetKeyBindings(info.KeyBindings, low, high, ::sf2::NONE); |
128 |
} |
} |
129 |
} |
} |
130 |
|
|
146 |
} |
} |
147 |
} |
} |
148 |
|
|
149 |
::sf2::InstrumentBase* InstrumentResourceManager::Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg) { |
::sf2::Preset* InstrumentResourceManager::Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg) { |
150 |
// get sfz file from internal sfz file manager |
// get sfz file from internal sfz file manager |
151 |
::sf2::File* pSf2 = Sf2s.Borrow(Key.FileName, (Sf2Consumer*) Key.Index); // conversion kinda hackish :/ |
::sf2::File* pSf2 = Sf2s.Borrow(Key.FileName, (Sf2Consumer*) Key.Index); // conversion kinda hackish :/ |
152 |
|
|
153 |
dmsg(1,("Loading sf2 instrument ('%s',%d)...",Key.FileName.c_str(),Key.Index)); |
dmsg(1,("Loading sf2 instrument ('%s',%d)...",Key.FileName.c_str(),Key.Index)); |
154 |
::sf2::InstrumentBase* pInstrument = GetSfInstrument(pSf2, Key.Index); |
::sf2::Preset* pInstrument = GetSfInstrument(pSf2, Key.Index); |
155 |
dmsg(1,("OK\n")); |
dmsg(1,("OK\n")); |
156 |
|
|
157 |
// cache initial samples points (for actually needed samples) |
// cache initial samples points (for actually needed samples) |
160 |
for(int i = 0 ; i < pInstrument->GetRegionCount(); i++) { |
for(int i = 0 ; i < pInstrument->GetRegionCount(); i++) { |
161 |
::sf2::Instrument* sf2Instr = pInstrument->GetRegion(i)->pInstrument; |
::sf2::Instrument* sf2Instr = pInstrument->GetRegion(i)->pInstrument; |
162 |
if(sf2Instr) regTotal += sf2Instr->GetRegionCount(); |
if(sf2Instr) regTotal += sf2Instr->GetRegionCount(); |
|
else regTotal++; // if sf2Instr is null, than pInstrument is not a preset |
|
163 |
} |
} |
164 |
for(int i = 0 ; i < pInstrument->GetRegionCount(); i++) { |
for(int i = 0 ; i < pInstrument->GetRegionCount(); i++) { |
165 |
::sf2::Instrument* sf2Instr = pInstrument->GetRegion(i)->pInstrument; |
::sf2::Instrument* sf2Instr = pInstrument->GetRegion(i)->pInstrument; |
|
::sf2::Sample* sf2Sample = pInstrument->GetRegion(i)->GetSample(); |
|
166 |
if(sf2Instr != NULL) { |
if(sf2Instr != NULL) { |
167 |
// pInstrument is ::sf2::Preset |
// pInstrument is ::sf2::Preset |
168 |
for(int j = 0; j < sf2Instr->GetRegionCount(); j++) { |
for(int j = 0; j < sf2Instr->GetRegionCount(); j++) { |
170 |
DispatchResourceProgressEvent(Key, localProgress); |
DispatchResourceProgressEvent(Key, localProgress); |
171 |
CacheInitialSamples(sf2Instr->GetRegion(j)->GetSample(), dynamic_cast<AbstractEngineChannel*>(pConsumer)); |
CacheInitialSamples(sf2Instr->GetRegion(j)->GetSample(), dynamic_cast<AbstractEngineChannel*>(pConsumer)); |
172 |
} |
} |
|
} else if(sf2Sample != NULL) { |
|
|
// pInstrument is ::sf2::Instrument |
|
|
CacheInitialSamples(sf2Sample, dynamic_cast<AbstractEngineChannel*>(pConsumer)); |
|
173 |
} |
} |
174 |
} |
} |
175 |
dmsg(1,("OK\n")); |
dmsg(1,("OK\n")); |
193 |
return pInstrument; |
return pInstrument; |
194 |
} |
} |
195 |
|
|
196 |
void InstrumentResourceManager::Destroy( ::sf2::InstrumentBase* pResource, void* pArg) { |
void InstrumentResourceManager::Destroy( ::sf2::Preset* pResource, void* pArg) { |
197 |
instr_entry_t* pEntry = (instr_entry_t*) pArg; |
instr_entry_t* pEntry = (instr_entry_t*) pArg; |
198 |
// we don't need the .sf2 file here anymore |
// we don't need the .sf2 file here anymore |
199 |
Sf2s.HandBack(pEntry->pSf2, (Sf2Consumer*) pEntry->ID.Index); // conversion kinda hackish :/ |
Sf2s.HandBack(pEntry->pSf2, (Sf2Consumer*) pEntry->ID.Index); // conversion kinda hackish :/ |
200 |
delete pEntry; |
delete pEntry; |
201 |
} |
} |
202 |
|
|
203 |
void InstrumentResourceManager::OnBorrow(::sf2::InstrumentBase* pResource, InstrumentConsumer* pConsumer, void*& pArg) { |
void InstrumentResourceManager::OnBorrow(::sf2::Preset* pResource, InstrumentConsumer* pConsumer, void*& pArg) { |
204 |
instr_entry_t* pEntry = (instr_entry_t*) pArg; |
instr_entry_t* pEntry = (instr_entry_t*) pArg; |
205 |
EngineChannel* pEngineChannel = dynamic_cast<EngineChannel*>(pConsumer); |
EngineChannel* pEngineChannel = dynamic_cast<EngineChannel*>(pConsumer); |
206 |
uint maxSamplesPerCycle = |
uint maxSamplesPerCycle = |
285 |
} |
} |
286 |
|
|
287 |
int InstrumentResourceManager::GetSfInstrumentCount(::sf2::File* pFile) { |
int InstrumentResourceManager::GetSfInstrumentCount(::sf2::File* pFile) { |
288 |
return pFile->GetInstrumentCount() + pFile->GetPresetCount(); |
return pFile->GetPresetCount(); |
289 |
} |
} |
290 |
|
|
291 |
::sf2::InstrumentBase* InstrumentResourceManager::GetSfInstrument(::sf2::File* pFile, int idx) { |
::sf2::Preset* InstrumentResourceManager::GetSfInstrument(::sf2::File* pFile, int idx) { |
292 |
if (idx >= pFile->GetInstrumentCount() + pFile->GetPresetCount()) { |
if (idx >= pFile->GetPresetCount()) { |
293 |
throw InstrumentManagerException("There is no instrument with index " + ToString(idx)); |
throw InstrumentManagerException("There is no instrument with index " + ToString(idx)); |
294 |
} |
} |
295 |
|
return pFile->GetPreset(idx); |
|
if (idx < pFile->GetInstrumentCount()) { |
|
|
return pFile->GetInstrument(idx); |
|
|
} |
|
|
|
|
|
int presetIdx = idx - pFile->GetInstrumentCount(); |
|
|
return pFile->GetPreset(presetIdx); |
|
296 |
} |
} |
297 |
|
|
298 |
}} // namespace LinuxSampler::sfz |
}} // namespace LinuxSampler::sfz |