3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
* Copyright (C) 2005 - 2009 Christian Schoenebeck * |
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 * |
160 |
gig->SetAutoLoad(false); // avoid time consuming samples scanning |
gig->SetAutoLoad(false); // avoid time consuming samples scanning |
161 |
pInstrument = gig->GetInstrument(ID.Index); |
pInstrument = gig->GetInstrument(ID.Index); |
162 |
} |
} |
163 |
|
|
164 |
if (!pInstrument) throw InstrumentManagerException("There is no instrument " + ToString(ID.Index) + " in " + ID.FileName); |
if (!pInstrument) throw InstrumentManagerException("There is no instrument " + ToString(ID.Index) + " in " + ID.FileName); |
165 |
|
|
166 |
instrument_info_t info; |
instrument_info_t info; |
185 |
} else { |
} else { |
186 |
for (int i = low; i <= high; i++) info.KeyBindings[i] = 1; |
for (int i = low; i <= high; i++) info.KeyBindings[i] = 1; |
187 |
} |
} |
188 |
|
|
189 |
pRegion = pInstrument->GetNextRegion(); |
pRegion = pInstrument->GetNextRegion(); |
190 |
} |
} |
191 |
|
|
192 |
if (loaded) { // retrieve keyswitching only if the instrument is fully loaded. |
if (loaded) { // retrieve keyswitching only if the instrument is fully loaded. |
193 |
int low = pInstrument->DimensionKeyRange.low; |
|
194 |
int high = pInstrument->DimensionKeyRange.high; |
// only return keyswitch range if keyswitching is used |
195 |
if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) { |
bool hasKeyswitches = false; |
196 |
std::cerr << "Invalid keyswitch range: " << low << " - " << high << std::endl; |
for (::gig::Region* pRegion = pInstrument->GetFirstRegion() ; |
197 |
} else { |
pRegion && !hasKeyswitches ; |
198 |
for (int i = low; i <= high; i++) info.KeySwitchBindings[i] = 1; |
pRegion = pInstrument->GetNextRegion()) { |
199 |
|
for (int i = 0 ; i < pRegion->Dimensions ; i++) { |
200 |
|
if (pRegion->pDimensionDefinitions[i].dimension == ::gig::dimension_keyboard) { |
201 |
|
hasKeyswitches = true; |
202 |
|
break; |
203 |
|
} |
204 |
|
} |
205 |
|
} |
206 |
|
|
207 |
|
if (hasKeyswitches) { |
208 |
|
int low = pInstrument->DimensionKeyRange.low; |
209 |
|
int high = pInstrument->DimensionKeyRange.high; |
210 |
|
if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) { |
211 |
|
std::cerr << "Invalid keyswitch range: " << low << " - " << high << std::endl; |
212 |
|
} else { |
213 |
|
for (int i = low; i <= high; i++) info.KeySwitchBindings[i] = 1; |
214 |
|
} |
215 |
} |
} |
216 |
} |
} |
217 |
|
|
233 |
} |
} |
234 |
} |
} |
235 |
|
|
236 |
void InstrumentResourceManager::LaunchInstrumentEditor(instrument_id_t ID) throw (InstrumentManagerException) { |
InstrumentEditor* InstrumentResourceManager::LaunchInstrumentEditor(instrument_id_t ID, void* pUserData) throw (InstrumentManagerException) { |
237 |
const String sDataType = GetInstrumentDataStructureName(ID); |
const String sDataType = GetInstrumentDataStructureName(ID); |
238 |
const String sDataVersion = GetInstrumentDataStructureVersion(ID); |
const String sDataVersion = GetInstrumentDataStructureVersion(ID); |
239 |
// find instrument editors capable to handle given instrument |
// find instrument editors capable to handle given instrument |
260 |
InstrumentEditorProxies.add(pProxy); |
InstrumentEditorProxies.add(pProxy); |
261 |
InstrumentEditorProxiesMutex.Unlock(); |
InstrumentEditorProxiesMutex.Unlock(); |
262 |
// launch the instrument editor for the given instrument |
// launch the instrument editor for the given instrument |
263 |
pEditor->Launch(pInstrument, sDataType, sDataVersion); |
pEditor->Launch(pInstrument, sDataType, sDataVersion, pUserData); |
264 |
|
|
265 |
// register the instrument editor as virtual MIDI device as well ... |
// register the instrument editor as virtual MIDI device as well ... |
266 |
VirtualMidiDevice* pVirtualMidiDevice = |
VirtualMidiDevice* pVirtualMidiDevice = |
267 |
dynamic_cast<VirtualMidiDevice*>(pEditor); |
dynamic_cast<VirtualMidiDevice*>(pEditor); |
268 |
if (!pVirtualMidiDevice) { |
if (!pVirtualMidiDevice) { |
269 |
std::cerr << "Instrument editor not a virtual MIDI device\n" << std::flush; |
std::cerr << "Instrument editor not a virtual MIDI device\n" << std::flush; |
270 |
return; |
return pEditor; |
271 |
} |
} |
272 |
// NOTE: for now connect the virtual MIDI keyboard of the instrument editor (if any) with all engine channels that have the same instrument as the editor was opened for ( other ideas ? ) |
// NOTE: for now connect the virtual MIDI keyboard of the instrument editor (if any) with all engine channels that have the same instrument as the editor was opened for ( other ideas ? ) |
273 |
Lock(); |
Lock(); |
277 |
std::set<gig::EngineChannel*>::iterator end = engineChannels.end(); |
std::set<gig::EngineChannel*>::iterator end = engineChannels.end(); |
278 |
for (; iter != end; ++iter) (*iter)->Connect(pVirtualMidiDevice); |
for (; iter != end; ++iter) (*iter)->Connect(pVirtualMidiDevice); |
279 |
Unlock(); |
Unlock(); |
280 |
|
|
281 |
|
return pEditor; |
282 |
} |
} |
283 |
|
|
284 |
/** |
/** |
472 |
} else if (sStructType == "gig::Instrument") { |
} else if (sStructType == "gig::Instrument") { |
473 |
// resume all previously suspended engines |
// resume all previously suspended engines |
474 |
ResumeAllEngines(); |
ResumeAllEngines(); |
475 |
|
} else if (sStructType == "gig::Sample") { |
476 |
|
// we're assuming here, that OnDataStructureToBeChanged() with |
477 |
|
// "gig::File" was called previously, so we won't resume anything |
478 |
|
// here, but just re-cache the given sample |
479 |
|
Lock(); |
480 |
|
::gig::Sample* pSample = (::gig::Sample*) pStruct; |
481 |
|
::gig::File* pFile = (::gig::File*) pSample->GetParent(); |
482 |
|
UncacheInitialSamples(pSample); |
483 |
|
// now re-cache ... |
484 |
|
std::vector< ::gig::Instrument*> instruments = |
485 |
|
GetInstrumentsCurrentlyUsedOf(pFile, false/*don't lock again*/); |
486 |
|
for (int i = 0; i < instruments.size(); i++) { |
487 |
|
if (SampleReferencedByInstrument(pSample, instruments[i])) { |
488 |
|
std::set<gig::EngineChannel*> engineChannels = |
489 |
|
GetEngineChannelsUsing(instruments[i], false/*don't lock again*/); |
490 |
|
std::set<gig::EngineChannel*>::iterator iter = engineChannels.begin(); |
491 |
|
std::set<gig::EngineChannel*>::iterator end = engineChannels.end(); |
492 |
|
for (; iter != end; ++iter) |
493 |
|
CacheInitialSamples(pSample, *iter); |
494 |
|
} |
495 |
|
} |
496 |
|
Unlock(); |
497 |
} else if (sStructType == "gig::Region") { |
} else if (sStructType == "gig::Region") { |
498 |
// advice the engines to resume the given region, that is to |
// advice the engines to resume the given region, that is to |
499 |
// using it for playback again |
// using it for playback again |
537 |
Lock(); |
Lock(); |
538 |
::gig::Sample* pSample = (::gig::Sample*) pOldSample; |
::gig::Sample* pSample = (::gig::Sample*) pOldSample; |
539 |
::gig::File* pFile = (::gig::File*) pSample->GetParent(); |
::gig::File* pFile = (::gig::File*) pSample->GetParent(); |
540 |
|
bool bSampleStillInUse = false; |
541 |
std::vector< ::gig::Instrument*> instruments = |
std::vector< ::gig::Instrument*> instruments = |
542 |
GetInstrumentsCurrentlyUsedOf(pFile, false/*don't lock again*/); |
GetInstrumentsCurrentlyUsedOf(pFile, false/*don't lock again*/); |
543 |
for (int i = 0; i < instruments.size(); i++) |
for (int i = 0; i < instruments.size(); i++) { |
544 |
if (!SampleReferencedByInstrument(pSample, instruments[i])) |
if (SampleReferencedByInstrument(pSample, instruments[i])) { |
545 |
UncacheInitialSamples(pSample); |
bSampleStillInUse = true; |
546 |
|
break; |
547 |
|
} |
548 |
|
} |
549 |
|
if (!bSampleStillInUse) UncacheInitialSamples(pSample); |
550 |
Unlock(); |
Unlock(); |
551 |
} |
} |
552 |
// make sure new sample reference is cached |
// make sure new sample reference is cached |
789 |
*/ |
*/ |
790 |
std::set<gig::EngineChannel*> InstrumentResourceManager::GetEngineChannelsUsing(::gig::Instrument* pInstrument, bool bLock) { |
std::set<gig::EngineChannel*> InstrumentResourceManager::GetEngineChannelsUsing(::gig::Instrument* pInstrument, bool bLock) { |
791 |
if (bLock) Lock(); |
if (bLock) Lock(); |
792 |
std::set<gig::EngineChannel*> result; |
std::set<gig::EngineChannel*> result; |
793 |
std::set<ResourceConsumer< ::gig::Instrument>*> consumers = ConsumersOf(pInstrument); |
std::set<ResourceConsumer< ::gig::Instrument>*> consumers = ConsumersOf(pInstrument); |
794 |
std::set<ResourceConsumer< ::gig::Instrument>*>::iterator iter = consumers.begin(); |
std::set<ResourceConsumer< ::gig::Instrument>*>::iterator iter = consumers.begin(); |
795 |
std::set<ResourceConsumer< ::gig::Instrument>*>::iterator end = consumers.end(); |
std::set<ResourceConsumer< ::gig::Instrument>*>::iterator end = consumers.end(); |
812 |
*/ |
*/ |
813 |
std::set<gig::Engine*> InstrumentResourceManager::GetEnginesUsing(::gig::Instrument* pInstrument, bool bLock) { |
std::set<gig::Engine*> InstrumentResourceManager::GetEnginesUsing(::gig::Instrument* pInstrument, bool bLock) { |
814 |
if (bLock) Lock(); |
if (bLock) Lock(); |
815 |
std::set<gig::Engine*> result; |
std::set<gig::Engine*> result; |
816 |
std::set<ResourceConsumer< ::gig::Instrument>*> consumers = ConsumersOf(pInstrument); |
std::set<ResourceConsumer< ::gig::Instrument>*> consumers = ConsumersOf(pInstrument); |
817 |
std::set<ResourceConsumer< ::gig::Instrument>*>::iterator iter = consumers.begin(); |
std::set<ResourceConsumer< ::gig::Instrument>*>::iterator iter = consumers.begin(); |
818 |
std::set<ResourceConsumer< ::gig::Instrument>*>::iterator end = consumers.end(); |
std::set<ResourceConsumer< ::gig::Instrument>*>::iterator end = consumers.end(); |