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 - 2015 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 * |
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 |
} |
} |
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 " |
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 neededSilenceSamples = (maxSamplesPerCycle << CONFIG_MAX_PITCH) + 3; |
const uint neededSilenceSamples = uint((maxSamplesPerCycle << CONFIG_MAX_PITCH) + 6); |
706 |
const uint currentlyCachedSilenceSamples = pSample->GetCache().NullExtensionSize / pSample->FrameSize; |
const uint currentlyCachedSilenceSamples = uint(pSample->GetCache().NullExtensionSize / pSample->FrameSize); |
707 |
if (currentlyCachedSilenceSamples < neededSilenceSamples) { |
if (currentlyCachedSilenceSamples < neededSilenceSamples) { |
708 |
dmsg(3,("Caching whole sample (sample name: \"%s\", sample size: %lu)\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 %lu Bytes, %lu 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 |
742 |
if (bLock) Unlock(); |
if (bLock) Unlock(); |
743 |
return result; |
return result; |
744 |
} |
} |
745 |
|
|
746 |
|
/** |
747 |
|
* 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({ |
758 |
|
.code = code, .wildcardPatchVars = true |
759 |
|
}); |
760 |
|
std::set<InstrumentScriptConsumer*>::iterator iter = consumers.begin(); |
761 |
|
std::set<InstrumentScriptConsumer*>::iterator end = consumers.end(); |
762 |
|
for (; iter != end; ++iter) { |
763 |
|
EngineChannel* pEngineChannel = dynamic_cast<EngineChannel*>(*iter); |
764 |
|
if (!pEngineChannel) continue; |
765 |
|
result.insert(pEngineChannel); |
766 |
|
} |
767 |
|
if (bLock) Unlock(); |
768 |
|
return result; |
769 |
|
} |
770 |
|
|
771 |
/** |
/** |
772 |
* Returns a list with all gig engine channels that are currently using |
* Returns a list with all gig engine channels that are currently using |