1 |
|
|
2 |
/*************************************************************************** |
/*************************************************************************** |
3 |
* * |
* * |
4 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
5 |
* * |
* * |
6 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
7 |
* Copyright (C) 2005 - 2009 Christian Schoenebeck * |
* Copyright (C) 2005 - 2020 Christian Schoenebeck * |
8 |
* * |
* * |
9 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
10 |
* 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 * |
31 |
#include "../../common/global_private.h" |
#include "../../common/global_private.h" |
32 |
#include "../../plugins/InstrumentEditorFactory.h" |
#include "../../plugins/InstrumentEditorFactory.h" |
33 |
|
|
|
// We need to know the maximum number of sample points which are going to |
|
|
// be processed for each render cycle of the audio output driver, to know |
|
|
// how much initial sample points we need to cache into RAM. If the given |
|
|
// sampler channel does not have an audio output device assigned yet |
|
|
// though, we simply use this default value. |
|
|
#define GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE 128 |
|
|
|
|
34 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
35 |
|
|
|
// data stored as long as an instrument resource exists |
|
|
struct instr_entry_t { |
|
|
InstrumentManager::instrument_id_t ID; |
|
|
::gig::File* pGig; |
|
|
uint MaxSamplesPerCycle; ///< if some engine requests an already allocated instrument with a higher value, we have to reallocate the instrument |
|
|
}; |
|
|
|
|
36 |
// some data needed for the libgig callback function |
// some data needed for the libgig callback function |
37 |
struct progress_callback_arg_t { |
struct progress_callback_arg_t { |
38 |
InstrumentResourceManager* pManager; |
InstrumentResourceManager* pManager; |
42 |
// we use this to react on events concerning an instrument on behalf of an instrument editor |
// we use this to react on events concerning an instrument on behalf of an instrument editor |
43 |
class InstrumentEditorProxy : public InstrumentConsumer { |
class InstrumentEditorProxy : public InstrumentConsumer { |
44 |
public: |
public: |
45 |
|
virtual ~InstrumentEditorProxy() {} |
46 |
|
|
47 |
virtual void ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg) { |
virtual void ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg) { |
48 |
//TODO: inform the instrument editor about the pending update |
//TODO: inform the instrument editor about the pending update |
49 |
} |
} |
72 |
* instrument ID |
* instrument ID |
73 |
*/ |
*/ |
74 |
void InstrumentResourceManager::OnInstrumentLoadingProgress(::gig::progress_t* pProgress) { |
void InstrumentResourceManager::OnInstrumentLoadingProgress(::gig::progress_t* pProgress) { |
75 |
dmsg(7,("gig::InstrumentResourceManager: progress %f%", pProgress->factor)); |
dmsg(7,("gig::InstrumentResourceManager: progress %f%%", pProgress->factor)); |
76 |
progress_callback_arg_t* pArg = static_cast<progress_callback_arg_t*>(pProgress->custom); |
progress_callback_arg_t* pArg = static_cast<progress_callback_arg_t*>(pProgress->custom); |
77 |
// we randomly schedule 90% for the .gig file loading and the remaining 10% later for sample caching |
// we randomly schedule 90% for the .gig file loading and the remaining 10% later for sample caching |
78 |
const float localProgress = 0.9f * pProgress->factor; |
const float localProgress = 0.9f * pProgress->factor; |
79 |
pArg->pManager->DispatchResourceProgressEvent(*pArg->pInstrumentKey, localProgress); |
pArg->pManager->DispatchResourceProgressEvent(*pArg->pInstrumentKey, localProgress); |
80 |
} |
} |
81 |
|
|
|
std::vector<InstrumentResourceManager::instrument_id_t> InstrumentResourceManager::Instruments() { |
|
|
return Entries(); |
|
|
} |
|
|
|
|
82 |
String InstrumentResourceManager::GetInstrumentName(instrument_id_t ID) { |
String InstrumentResourceManager::GetInstrumentName(instrument_id_t ID) { |
83 |
Lock(); |
Lock(); |
84 |
::gig::Instrument* pInstrument = Resource(ID, false); |
::gig::Instrument* pInstrument = Resource(ID, false); |
132 |
::RIFF::File* riff = NULL; |
::RIFF::File* riff = NULL; |
133 |
::gig::File* gig = NULL; |
::gig::File* gig = NULL; |
134 |
try { |
try { |
135 |
if(!loaded) { |
if (!loaded) { |
136 |
riff = new ::RIFF::File(ID.FileName); |
riff = new ::RIFF::File(ID.FileName); |
137 |
gig = new ::gig::File(riff); |
gig = new ::gig::File(riff); |
138 |
gig->SetAutoLoad(false); // avoid time consuming samples scanning |
gig->SetAutoLoad(false); // avoid time consuming samples scanning |
211 |
} |
} |
212 |
} |
} |
213 |
|
|
214 |
InstrumentEditor* InstrumentResourceManager::LaunchInstrumentEditor(instrument_id_t ID, void* pUserData) throw (InstrumentManagerException) { |
InstrumentEditor* InstrumentResourceManager::LaunchInstrumentEditor(LinuxSampler::EngineChannel* pEngineChannel, instrument_id_t ID, void* pUserData) throw (InstrumentManagerException) { |
215 |
const String sDataType = GetInstrumentDataStructureName(ID); |
const String sDataType = GetInstrumentDataStructureName(ID); |
216 |
const String sDataVersion = GetInstrumentDataStructureVersion(ID); |
const String sDataVersion = GetInstrumentDataStructureVersion(ID); |
217 |
// find instrument editors capable to handle given instrument |
// find instrument editors capable to handle given instrument |
238 |
InstrumentEditorProxies.add(pProxy); |
InstrumentEditorProxies.add(pProxy); |
239 |
InstrumentEditorProxiesMutex.Unlock(); |
InstrumentEditorProxiesMutex.Unlock(); |
240 |
// launch the instrument editor for the given instrument |
// launch the instrument editor for the given instrument |
241 |
pEditor->Launch(pInstrument, sDataType, sDataVersion, pUserData); |
pEditor->Launch(pEngineChannel, pInstrument, sDataType, sDataVersion, pUserData); |
242 |
|
|
243 |
// register the instrument editor as virtual MIDI device as well ... |
// register the instrument editor as virtual MIDI device as well ... |
244 |
VirtualMidiDevice* pVirtualMidiDevice = |
VirtualMidiDevice* pVirtualMidiDevice = |
274 |
int iProxyIndex = -1; |
int iProxyIndex = -1; |
275 |
|
|
276 |
// first find the editor proxy entry for this editor |
// first find the editor proxy entry for this editor |
277 |
InstrumentEditorProxiesMutex.Lock(); |
{ |
278 |
for (int i = 0; i < InstrumentEditorProxies.size(); i++) { |
LockGuard lock(InstrumentEditorProxiesMutex); |
279 |
InstrumentEditorProxy* pCurProxy = |
for (int i = 0; i < InstrumentEditorProxies.size(); i++) { |
280 |
dynamic_cast<InstrumentEditorProxy*>( |
InstrumentEditorProxy* pCurProxy = |
281 |
InstrumentEditorProxies[i] |
dynamic_cast<InstrumentEditorProxy*>( |
282 |
); |
InstrumentEditorProxies[i] |
283 |
if (pCurProxy->pEditor == pSender) { |
); |
284 |
pProxy = pCurProxy; |
if (pCurProxy->pEditor == pSender) { |
285 |
iProxyIndex = i; |
pProxy = pCurProxy; |
286 |
pInstrument = pCurProxy->pInstrument; |
iProxyIndex = i; |
287 |
|
pInstrument = pCurProxy->pInstrument; |
288 |
|
} |
289 |
} |
} |
290 |
} |
} |
|
InstrumentEditorProxiesMutex.Unlock(); |
|
291 |
|
|
292 |
if (!pProxy) { |
if (!pProxy) { |
293 |
std::cerr << "Eeeek, could not find instrument editor proxy, " |
std::cerr << "Eeeek, could not find instrument editor proxy, " |
315 |
|
|
316 |
// finally delete proxy entry and hand back instrument |
// finally delete proxy entry and hand back instrument |
317 |
if (pInstrument) { |
if (pInstrument) { |
318 |
InstrumentEditorProxiesMutex.Lock(); |
{ |
319 |
InstrumentEditorProxies.remove(iProxyIndex); |
LockGuard lock(InstrumentEditorProxiesMutex); |
320 |
InstrumentEditorProxiesMutex.Unlock(); |
InstrumentEditorProxies.remove(iProxyIndex); |
321 |
|
} |
322 |
|
|
323 |
HandBack(pInstrument, pProxy); |
HandBack(pInstrument, pProxy); |
324 |
delete pProxy; |
delete pProxy; |
395 |
} |
} |
396 |
|
|
397 |
void InstrumentResourceManager::OnDataStructureToBeChanged(void* pStruct, String sStructType, InstrumentEditor* pSender) { |
void InstrumentResourceManager::OnDataStructureToBeChanged(void* pStruct, String sStructType, InstrumentEditor* pSender) { |
398 |
|
dmsg(5,("gig::InstrumentResourceManager::OnDataStructureToBeChanged(%s)\n", sStructType.c_str())); |
399 |
//TODO: remove code duplication |
//TODO: remove code duplication |
400 |
if (sStructType == "gig::File") { |
if (sStructType == "gig::File") { |
401 |
// completely suspend all engines that use that file |
// completely suspend all engines that use that file |
436 |
std::set<Engine*>::iterator end = engines.end(); |
std::set<Engine*>::iterator end = engines.end(); |
437 |
for (; iter != end; ++iter) (*iter)->Suspend(pRegion); |
for (; iter != end; ++iter) (*iter)->Suspend(pRegion); |
438 |
Unlock(); |
Unlock(); |
439 |
|
} else if (sStructType == "gig::Script") { |
440 |
|
// no need to suspend anything here, since the sampler is |
441 |
|
// processing a translated VM representation of the original script |
442 |
|
// source code, not accessing the source code itself during playback |
443 |
|
::gig::Script* pScript = (::gig::Script*) pStruct; |
444 |
|
// remember the original source code of the script, since the script |
445 |
|
// resource manager uses the source code as key |
446 |
|
pendingScriptUpdatesMutex.Lock(); |
447 |
|
pendingScriptUpdates[pScript] = pScript->GetScriptAsText(); |
448 |
|
pendingScriptUpdatesMutex.Unlock(); |
449 |
} else { |
} else { |
450 |
std::cerr << "gig::InstrumentResourceManager: ERROR, unknown data " |
std::cerr << "gig::InstrumentResourceManager: ERROR, unknown data " |
451 |
"structure '" << sStructType << "' requested to be " |
"structure '" << sStructType << "' requested to be " |
456 |
} |
} |
457 |
|
|
458 |
void InstrumentResourceManager::OnDataStructureChanged(void* pStruct, String sStructType, InstrumentEditor* pSender) { |
void InstrumentResourceManager::OnDataStructureChanged(void* pStruct, String sStructType, InstrumentEditor* pSender) { |
459 |
|
dmsg(5,("gig::InstrumentResourceManager::OnDataStructureChanged(%s)\n", sStructType.c_str())); |
460 |
//TODO: remove code duplication |
//TODO: remove code duplication |
461 |
if (sStructType == "gig::File") { |
if (sStructType == "gig::File") { |
462 |
// resume all previously suspended engines |
// resume all previously suspended engines |
514 |
std::set<Engine*>::iterator end = engines.end(); |
std::set<Engine*>::iterator end = engines.end(); |
515 |
for (; iter != end; ++iter) (*iter)->Resume(pRegion); |
for (; iter != end; ++iter) (*iter)->Resume(pRegion); |
516 |
Unlock(); |
Unlock(); |
517 |
|
} else if (sStructType == "gig::Script") { |
518 |
|
// inform all engine channels which are using this script, that |
519 |
|
// they need to reload (parse) the script's source code text |
520 |
|
::gig::Script* pScript = (::gig::Script*) pStruct; |
521 |
|
pendingScriptUpdatesMutex.Lock(); |
522 |
|
if (pendingScriptUpdates.count(pScript)) { |
523 |
|
const String& code = pendingScriptUpdates[pScript]; |
524 |
|
std::set<EngineChannel*> channels = GetEngineChannelsUsingScriptSourceCode(code, true/*lock*/); |
525 |
|
pendingScriptUpdates.erase(pScript); |
526 |
|
std::set<EngineChannel*>::iterator iter = channels.begin(); |
527 |
|
std::set<EngineChannel*>::iterator end = channels.end(); |
528 |
|
for (; iter != end; ++iter) (*iter)->reloadScript(pScript); |
529 |
|
} |
530 |
|
pendingScriptUpdatesMutex.Unlock(); |
531 |
} else { |
} else { |
532 |
std::cerr << "gig::InstrumentResourceManager: ERROR, unknown data " |
std::cerr << "gig::InstrumentResourceManager: ERROR, unknown data " |
533 |
"structure '" << sStructType << "' requested to be " |
"structure '" << sStructType << "' requested to be " |
572 |
|
|
573 |
::gig::Instrument* InstrumentResourceManager::Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg) { |
::gig::Instrument* InstrumentResourceManager::Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg) { |
574 |
// get gig file from internal gig file manager |
// get gig file from internal gig file manager |
575 |
::gig::File* pGig = Gigs.Borrow(Key.FileName, (GigConsumer*) Key.Index); // conversion kinda hackish :/ |
::gig::File* pGig = Gigs.Borrow(Key.FileName, reinterpret_cast<GigConsumer*>(Key.Index)); // conversion kinda hackish :/ |
576 |
|
|
577 |
// we pass this to the progress callback mechanism of libgig |
// we pass this to the progress callback mechanism of libgig |
578 |
progress_callback_arg_t callbackArg; |
progress_callback_arg_t callbackArg; |
593 |
pGig->GetFirstSample(); // just to force complete instrument loading |
pGig->GetFirstSample(); // just to force complete instrument loading |
594 |
dmsg(1,("OK\n")); |
dmsg(1,("OK\n")); |
595 |
|
|
596 |
|
uint maxSamplesPerCycle = GetMaxSamplesPerCycle(pConsumer); |
597 |
|
|
598 |
// cache initial samples points (for actually needed samples) |
// cache initial samples points (for actually needed samples) |
599 |
dmsg(1,("Caching initial samples...")); |
dmsg(1,("Caching initial samples...")); |
600 |
uint iRegion = 0; // just for progress calculation |
uint iRegion = 0; // just for progress calculation |
606 |
|
|
607 |
if (pRgn->GetSample() && !pRgn->GetSample()->GetCache().Size) { |
if (pRgn->GetSample() && !pRgn->GetSample()->GetCache().Size) { |
608 |
dmsg(2,("C")); |
dmsg(2,("C")); |
609 |
CacheInitialSamples(pRgn->GetSample(), (EngineChannel*) pConsumer); |
CacheInitialSamples(pRgn->GetSample(), maxSamplesPerCycle); |
610 |
} |
} |
611 |
for (uint i = 0; i < pRgn->DimensionRegions; i++) { |
for (uint i = 0; i < pRgn->DimensionRegions; i++) { |
612 |
CacheInitialSamples(pRgn->pDimensionRegions[i]->pSample, (EngineChannel*) pConsumer); |
CacheInitialSamples(pRgn->pDimensionRegions[i]->pSample, maxSamplesPerCycle); |
613 |
} |
} |
614 |
|
|
615 |
pRgn = pInstrument->GetNextRegion(); |
pRgn = pInstrument->GetNextRegion(); |
622 |
instr_entry_t* pEntry = new instr_entry_t; |
instr_entry_t* pEntry = new instr_entry_t; |
623 |
pEntry->ID.FileName = Key.FileName; |
pEntry->ID.FileName = Key.FileName; |
624 |
pEntry->ID.Index = Key.Index; |
pEntry->ID.Index = Key.Index; |
625 |
pEntry->pGig = pGig; |
pEntry->pFile = pGig; |
626 |
|
|
627 |
EngineChannel* pEngineChannel = dynamic_cast<EngineChannel*>(pConsumer); |
// and we save this to check if we need to reallocate for an engine with higher value of 'MaxSamplesPerSecond' |
628 |
// and we save this to check if we need to reallocate for a engine with higher value of 'MaxSamplesPerSecond' |
pEntry->MaxSamplesPerCycle = maxSamplesPerCycle; |
629 |
pEntry->MaxSamplesPerCycle = |
|
|
(!pEngineChannel) ? 0 /* don't care for instrument editors */ : |
|
|
(pEngineChannel->GetEngine()) ? |
|
|
dynamic_cast<Engine*>(pEngineChannel->GetEngine())->pAudioOutputDevice->MaxSamplesPerCycle() |
|
|
: GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE; |
|
630 |
pArg = pEntry; |
pArg = pEntry; |
631 |
|
|
632 |
return pInstrument; |
return pInstrument; |
633 |
} |
} |
634 |
|
|
635 |
void InstrumentResourceManager::Destroy( ::gig::Instrument* pResource, void* pArg) { |
void InstrumentResourceManager::Destroy(::gig::Instrument* pResource, void* pArg) { |
636 |
instr_entry_t* pEntry = (instr_entry_t*) pArg; |
instr_entry_t* pEntry = (instr_entry_t*) pArg; |
637 |
// we don't need the .gig file here anymore |
// we don't need the .gig file here anymore |
638 |
Gigs.HandBack(pEntry->pGig, (GigConsumer*) pEntry->ID.Index); // conversion kinda hackish :/ |
Gigs.HandBack(pEntry->pFile, reinterpret_cast<GigConsumer*>(pEntry->ID.Index)); // conversion kinda hackish :/ |
639 |
delete pEntry; |
delete pEntry; |
640 |
} |
} |
641 |
|
|
|
void InstrumentResourceManager::OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg) { |
|
|
instr_entry_t* pEntry = (instr_entry_t*) pArg; |
|
|
EngineChannel* pEngineChannel = dynamic_cast<EngineChannel*>(pConsumer); |
|
|
uint maxSamplesPerCycle = |
|
|
(pEngineChannel && pEngineChannel->GetEngine()) ? dynamic_cast<Engine*>(pEngineChannel->GetEngine())->pAudioOutputDevice->MaxSamplesPerCycle() |
|
|
: GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE; |
|
|
if (pEntry->MaxSamplesPerCycle < maxSamplesPerCycle) { |
|
|
Update(pResource, pConsumer); |
|
|
} |
|
|
} |
|
|
|
|
642 |
void InstrumentResourceManager::DeleteRegionIfNotUsed(::gig::DimensionRegion* pRegion, region_info_t* pRegInfo) { |
void InstrumentResourceManager::DeleteRegionIfNotUsed(::gig::DimensionRegion* pRegion, region_info_t* pRegInfo) { |
643 |
// TODO: we could delete Region and Instrument here if they have become unused |
// TODO: we could delete Region and Instrument here if they have become unused |
644 |
} |
} |
645 |
|
|
646 |
void InstrumentResourceManager::DeleteSampleIfNotUsed(::gig::Sample* pSample, region_info_t* pRegInfo) { |
void InstrumentResourceManager::DeleteSampleIfNotUsed(::gig::Sample* pSample, region_info_t* pRegInfo) { |
647 |
::gig::File* gig = pRegInfo->file; |
::gig::File* gig = pRegInfo->file; |
648 |
::RIFF::File* riff = static_cast< ::RIFF::File*>(pRegInfo->pArg); |
::RIFF::File* riff = static_cast< ::RIFF::File*>(pRegInfo->pArg); |
683 |
* will be cached) |
* will be cached) |
684 |
*/ |
*/ |
685 |
void InstrumentResourceManager::CacheInitialSamples(::gig::Sample* pSample, AbstractEngine* pEngine) { |
void InstrumentResourceManager::CacheInitialSamples(::gig::Sample* pSample, AbstractEngine* pEngine) { |
686 |
|
uint maxSamplesPerCycle = |
687 |
|
(pEngine) ? pEngine->pAudioOutputDevice->MaxSamplesPerCycle() : |
688 |
|
DefaultMaxSamplesPerCycle(); |
689 |
|
CacheInitialSamples(pSample, maxSamplesPerCycle); |
690 |
|
} |
691 |
|
|
692 |
|
void InstrumentResourceManager::CacheInitialSamples(::gig::Sample* pSample, uint maxSamplesPerCycle) { |
693 |
if (!pSample) { |
if (!pSample) { |
694 |
dmsg(4,("gig::InstrumentResourceManager: Skipping sample (pSample == NULL)\n")); |
dmsg(4,("gig::InstrumentResourceManager: Skipping sample (pSample == NULL)\n")); |
695 |
return; |
return; |
702 |
// number of '0' samples (silence samples) behind the official buffer |
// number of '0' samples (silence samples) behind the official buffer |
703 |
// border, to allow the interpolator do it's work even at the end of |
// border, to allow the interpolator do it's work even at the end of |
704 |
// the sample. |
// the sample. |
705 |
const uint maxSamplesPerCycle = |
const uint neededSilenceSamples = uint((maxSamplesPerCycle << CONFIG_MAX_PITCH) + 6); |
706 |
(pEngine) ? pEngine->pAudioOutputDevice->MaxSamplesPerCycle() |
const uint currentlyCachedSilenceSamples = uint(pSample->GetCache().NullExtensionSize / pSample->FrameSize); |
|
: GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE; |
|
|
const uint neededSilenceSamples = (maxSamplesPerCycle << CONFIG_MAX_PITCH) + 3; |
|
|
const uint currentlyCachedSilenceSamples = pSample->GetCache().NullExtensionSize / pSample->FrameSize; |
|
707 |
if (currentlyCachedSilenceSamples < neededSilenceSamples) { |
if (currentlyCachedSilenceSamples < neededSilenceSamples) { |
708 |
dmsg(3,("Caching whole sample (sample name: \"%s\", sample size: %d)\n", pSample->pInfo->Name.c_str(), pSample->SamplesTotal)); |
dmsg(3,("Caching whole sample (sample name: \"%s\", sample size: %llu)\n", pSample->pInfo->Name.c_str(), (long long)pSample->SamplesTotal)); |
709 |
::gig::buffer_t buf = pSample->LoadSampleDataWithNullSamplesExtension(neededSilenceSamples); |
::gig::buffer_t buf = pSample->LoadSampleDataWithNullSamplesExtension(neededSilenceSamples); |
710 |
dmsg(4,("Cached %d Bytes, %d silence bytes.\n", buf.Size, buf.NullExtensionSize)); |
dmsg(4,("Cached %llu Bytes, %llu silence bytes.\n", (long long)buf.Size, (long long)buf.NullExtensionSize)); |
711 |
} |
} |
712 |
} |
} |
713 |
else { // we only cache CONFIG_PRELOAD_SAMPLES and stream the other sample points from disk |
else { // we only cache CONFIG_PRELOAD_SAMPLES and stream the other sample points from disk |
718 |
} |
} |
719 |
|
|
720 |
void InstrumentResourceManager::UncacheInitialSamples(::gig::Sample* pSample) { |
void InstrumentResourceManager::UncacheInitialSamples(::gig::Sample* pSample) { |
721 |
dmsg(1,("Uncaching sample %x\n",pSample)); |
dmsg(1,("Uncaching sample %p\n",(void*)pSample)); |
722 |
if (pSample->GetCache().Size) pSample->ReleaseSampleData(); |
if (pSample->GetCache().Size) pSample->ReleaseSampleData(); |
723 |
} |
} |
724 |
|
|
745 |
|
|
746 |
/** |
/** |
747 |
* Returns a list with all gig engine channels that are currently using |
* Returns a list with all gig engine channels that are currently using |
748 |
|
* the given real-time instrument script (provided as source code). |
749 |
|
* |
750 |
|
* @param pScript - search criteria |
751 |
|
* @param bLock - whether we should lock (mutex) the instrument manager |
752 |
|
* during this call and unlock at the end of this call |
753 |
|
*/ |
754 |
|
std::set<EngineChannel*> InstrumentResourceManager::GetEngineChannelsUsingScriptSourceCode(const String& code, bool bLock) { |
755 |
|
if (bLock) Lock(); |
756 |
|
std::set<EngineChannel*> result; |
757 |
|
std::set<InstrumentScriptConsumer*> consumers = scripts.ConsumersOf(code); |
758 |
|
std::set<InstrumentScriptConsumer*>::iterator iter = consumers.begin(); |
759 |
|
std::set<InstrumentScriptConsumer*>::iterator end = consumers.end(); |
760 |
|
for (; iter != end; ++iter) { |
761 |
|
EngineChannel* pEngineChannel = dynamic_cast<EngineChannel*>(*iter); |
762 |
|
if (!pEngineChannel) continue; |
763 |
|
result.insert(pEngineChannel); |
764 |
|
} |
765 |
|
if (bLock) Unlock(); |
766 |
|
return result; |
767 |
|
} |
768 |
|
|
769 |
|
/** |
770 |
|
* Returns a list with all gig engine channels that are currently using |
771 |
* the given instrument. |
* the given instrument. |
772 |
* |
* |
773 |
* @param pInstrument - search criteria |
* @param pInstrument - search criteria |
952 |
} |
} |
953 |
|
|
954 |
void InstrumentResourceManager::GigResourceManager::Destroy(::gig::File* pResource, void* pArg) { |
void InstrumentResourceManager::GigResourceManager::Destroy(::gig::File* pResource, void* pArg) { |
955 |
dmsg(1,("Freeing gig file from memory...")); |
dmsg(1,("Freeing gig file '%s' from memory ...", pResource->GetFileName().c_str())); |
956 |
|
|
957 |
// Delete as much as possible of the gig file. Some of the |
// Delete as much as possible of the gig file. Some of the |
958 |
// dimension regions and samples may still be in use - these |
// dimension regions and samples may still be in use - these |