--- linuxsampler/trunk/src/engines/gig/InstrumentResourceManager.cpp 2007/09/04 01:12:49 1321 +++ linuxsampler/trunk/src/engines/gig/InstrumentResourceManager.cpp 2009/10/23 17:53:17 2012 @@ -3,7 +3,7 @@ * LinuxSampler - modular, streaming capable sampler * * * * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * - * Copyright (C) 2005 - 2007 Christian Schoenebeck * + * Copyright (C) 2005 - 2009 Christian Schoenebeck * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -24,8 +24,11 @@ #include #include "InstrumentResourceManager.h" +#include "EngineChannel.h" +#include "Engine.h" -#include "../InstrumentEditorFactory.h" +#include "../../common/global_private.h" +#include "../../plugins/InstrumentEditorFactory.h" // 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 @@ -66,6 +69,8 @@ // the instrument we borrowed on behalf of the editor ::gig::Instrument* pInstrument; + // the instrument editor we work on behalf + InstrumentEditor* pEditor; }; /** @@ -89,15 +94,6 @@ return Entries(); } - InstrumentManager::mode_t InstrumentResourceManager::GetMode(const instrument_id_t& ID) { - return static_cast(AvailabilityMode(ID)); - } - - void InstrumentResourceManager::SetMode(const instrument_id_t& ID, InstrumentManager::mode_t Mode) { - dmsg(2,("gig::InstrumentResourceManager: setting mode for %s (Index=%d) to %d\n",ID.FileName.c_str(),ID.Index,Mode)); - SetAvailabilityMode(ID, static_cast::mode_t>(Mode)); - } - String InstrumentResourceManager::GetInstrumentName(instrument_id_t ID) { Lock(); ::gig::Instrument* pInstrument = Resource(ID, false); @@ -114,7 +110,123 @@ return ::gig::libraryVersion(); } - void InstrumentResourceManager::LaunchInstrumentEditor(instrument_id_t ID) throw (InstrumentManagerException) { + std::vector InstrumentResourceManager::GetInstrumentFileContent(String File) throw (InstrumentManagerException) { + ::RIFF::File* riff = NULL; + ::gig::File* gig = NULL; + try { + std::vector result; + riff = new ::RIFF::File(File); + gig = new ::gig::File(riff); + gig->SetAutoLoad(false); // avoid time consuming samples scanning + for (int i = 0; gig->GetInstrument(i); i++) { + instrument_id_t id; + id.FileName = File; + id.Index = i; + result.push_back(id); + } + if (gig) delete gig; + if (riff) delete riff; + return result; + } catch (::RIFF::Exception e) { + if (gig) delete gig; + if (riff) delete riff; + throw InstrumentManagerException(e.Message); + } catch (...) { + if (gig) delete gig; + if (riff) delete riff; + throw InstrumentManagerException("Unknown exception while trying to parse '" + File + "'"); + } + } + + InstrumentResourceManager::instrument_info_t InstrumentResourceManager::GetInstrumentInfo(instrument_id_t ID) throw (InstrumentManagerException) { + Lock(); + ::gig::Instrument* pInstrument = Resource(ID, false); + bool loaded = (pInstrument != NULL); + if (!loaded) Unlock(); + + ::RIFF::File* riff = NULL; + ::gig::File* gig = NULL; + try { + if(!loaded) { + riff = new ::RIFF::File(ID.FileName); + gig = new ::gig::File(riff); + gig->SetAutoLoad(false); // avoid time consuming samples scanning + pInstrument = gig->GetInstrument(ID.Index); + } + + if (!pInstrument) throw InstrumentManagerException("There is no instrument " + ToString(ID.Index) + " in " + ID.FileName); + + instrument_info_t info; + for (int i = 0; i < 128; i++) { info.KeyBindings[i] = info.KeySwitchBindings[i] = 0; } + + ::gig::File* pFile = (::gig::File*) pInstrument->GetParent(); + + if (pFile->pVersion) { + info.FormatVersion = ToString(pFile->pVersion->major); + info.Product = pFile->pInfo->Product; + info.Artists = pFile->pInfo->Artists; + } + + info.InstrumentName = pInstrument->pInfo->Name; + + ::gig::Region* pRegion = pInstrument->GetFirstRegion(); + while (pRegion) { + int low = pRegion->KeyRange.low; + int high = pRegion->KeyRange.high; + if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) { + std::cerr << "Invalid key range: " << low << " - " << high << std::endl; + } else { + for (int i = low; i <= high; i++) info.KeyBindings[i] = 1; + } + + pRegion = pInstrument->GetNextRegion(); + } + + if (loaded) { // retrieve keyswitching only if the instrument is fully loaded. + + // only return keyswitch range if keyswitching is used + bool hasKeyswitches = false; + for (::gig::Region* pRegion = pInstrument->GetFirstRegion() ; + pRegion && !hasKeyswitches ; + pRegion = pInstrument->GetNextRegion()) { + for (int i = 0 ; i < pRegion->Dimensions ; i++) { + if (pRegion->pDimensionDefinitions[i].dimension == ::gig::dimension_keyboard) { + hasKeyswitches = true; + break; + } + } + } + + if (hasKeyswitches) { + int low = pInstrument->DimensionKeyRange.low; + int high = pInstrument->DimensionKeyRange.high; + if (low < 0 || low > 127 || high < 0 || high > 127 || low > high) { + std::cerr << "Invalid keyswitch range: " << low << " - " << high << std::endl; + } else { + for (int i = low; i <= high; i++) info.KeySwitchBindings[i] = 1; + } + } + } + + if (loaded) Unlock(); + + if (gig) delete gig; + if (riff) delete riff; + return info; + } catch (::RIFF::Exception e) { + if (loaded) Unlock(); + if (gig) delete gig; + if (riff) delete riff; + throw InstrumentManagerException(e.Message); + } catch (...) { + if (loaded) Unlock(); + if (gig) delete gig; + if (riff) delete riff; + throw InstrumentManagerException("Unknown exception while trying to parse '" + ID.FileName + "'"); + } + } + + InstrumentEditor* InstrumentResourceManager::LaunchInstrumentEditor(instrument_id_t ID, void* pUserData) throw (InstrumentManagerException) { const String sDataType = GetInstrumentDataStructureName(ID); const String sDataVersion = GetInstrumentDataStructureVersion(ID); // find instrument editors capable to handle given instrument @@ -136,11 +248,30 @@ ::gig::Instrument* pInstrument = Borrow(ID, pProxy); // remember the proxy and instrument for this instrument editor pProxy->pInstrument = pInstrument; + pProxy->pEditor = pEditor; InstrumentEditorProxiesMutex.Lock(); - InstrumentEditorProxies[pEditor] = pProxy; + InstrumentEditorProxies.add(pProxy); InstrumentEditorProxiesMutex.Unlock(); // launch the instrument editor for the given instrument - pEditor->Launch(pInstrument, sDataType, sDataVersion); + pEditor->Launch(pInstrument, sDataType, sDataVersion, pUserData); + + // register the instrument editor as virtual MIDI device as well ... + VirtualMidiDevice* pVirtualMidiDevice = + dynamic_cast(pEditor); + if (!pVirtualMidiDevice) { + std::cerr << "Instrument editor not a virtual MIDI device\n" << std::flush; + return pEditor; + } + // 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 ? ) + Lock(); + std::set engineChannels = + GetEngineChannelsUsing(pInstrument, false/*don't lock again*/); + std::set::iterator iter = engineChannels.begin(); + std::set::iterator end = engineChannels.end(); + for (; iter != end; ++iter) (static_cast(*iter))->Connect(pVirtualMidiDevice); + Unlock(); + + return pEditor; } /** @@ -152,24 +283,108 @@ */ void InstrumentResourceManager::OnInstrumentEditorQuit(InstrumentEditor* pSender) { dmsg(1,("InstrumentResourceManager: instrument editor quit, doing cleanup\n")); - // hand back instrument and free proxy + + ::gig::Instrument* pInstrument = NULL; + InstrumentEditorProxy* pProxy = NULL; + int iProxyIndex = -1; + + // first find the editor proxy entry for this editor InstrumentEditorProxiesMutex.Lock(); - if (InstrumentEditorProxies.count(pSender)) { - InstrumentEditorProxy* pProxy = + for (int i = 0; i < InstrumentEditorProxies.size(); i++) { + InstrumentEditorProxy* pCurProxy = dynamic_cast( - InstrumentEditorProxies[pSender] + InstrumentEditorProxies[i] ); - InstrumentEditorProxies.erase(pSender); - InstrumentEditorProxiesMutex.Unlock(); - HandBack(pProxy->pInstrument, pProxy); - if (pProxy) delete pProxy; + if (pCurProxy->pEditor == pSender) { + pProxy = pCurProxy; + iProxyIndex = i; + pInstrument = pCurProxy->pInstrument; + } + } + InstrumentEditorProxiesMutex.Unlock(); + + if (!pProxy) { + std::cerr << "Eeeek, could not find instrument editor proxy, " + "this is a bug!\n" << std::flush; + return; + } + + // now unregister editor as not being available as a virtual MIDI device anymore + VirtualMidiDevice* pVirtualMidiDevice = + dynamic_cast(pSender); + if (pVirtualMidiDevice) { + Lock(); + // NOTE: see note in LaunchInstrumentEditor() + std::set engineChannels = + GetEngineChannelsUsing(pInstrument, false/*don't lock again*/); + std::set::iterator iter = engineChannels.begin(); + std::set::iterator end = engineChannels.end(); + for (; iter != end; ++iter) (*iter)->Disconnect(pVirtualMidiDevice); + Unlock(); } else { + std::cerr << "Could not unregister editor as not longer acting as " + "virtual MIDI device. Wasn't it registered?\n" + << std::flush; + } + + // finally delete proxy entry and hand back instrument + if (pInstrument) { + InstrumentEditorProxiesMutex.Lock(); + InstrumentEditorProxies.remove(iProxyIndex); InstrumentEditorProxiesMutex.Unlock(); - std::cerr << "Eeeek, could not find instrument editor proxy, this is a bug!\n" << std::flush; + + HandBack(pInstrument, pProxy); + delete pProxy; + } + + // Note that we don't need to free the editor here. As it + // derives from Thread, it will delete itself when the thread + // dies. + } + +#if 0 // currently unused : + /** + * Try to inform the respective instrument editor(s), that a note on + * event just occured. This method is called by the MIDI thread. If any + * obstacles are in the way (e.g. if a wait for an unlock would be + * required) we give up immediately, since the RT safeness of the MIDI + * thread has absolute priority. + */ + void InstrumentResourceManager::TrySendNoteOnToEditors(uint8_t Key, uint8_t Velocity, ::gig::Instrument* pInstrument) { + const bool bGotLock = InstrumentEditorProxiesMutex.Trylock(); // naively assumes RT safe implementation + if (!bGotLock) return; // hell, forget it, not worth the hassle + for (int i = 0; i < InstrumentEditorProxies.size(); i++) { + InstrumentEditorProxy* pProxy = + dynamic_cast( + InstrumentEditorProxies[i] + ); + if (pProxy->pInstrument == pInstrument) + pProxy->pEditor->SendNoteOnToDevice(Key, Velocity); + } + InstrumentEditorProxiesMutex.Unlock(); // naively assumes RT safe implementation + } + + /** + * Try to inform the respective instrument editor(s), that a note off + * event just occured. This method is called by the MIDI thread. If any + * obstacles are in the way (e.g. if a wait for an unlock would be + * required) we give up immediately, since the RT safeness of the MIDI + * thread has absolute priority. + */ + void InstrumentResourceManager::TrySendNoteOffToEditors(uint8_t Key, uint8_t Velocity, ::gig::Instrument* pInstrument) { + const bool bGotLock = InstrumentEditorProxiesMutex.Trylock(); // naively assumes RT safe implementation + if (!bGotLock) return; // hell, forget it, not worth the hassle + for (int i = 0; i < InstrumentEditorProxies.size(); i++) { + InstrumentEditorProxy* pProxy = + dynamic_cast( + InstrumentEditorProxies[i] + ); + if (pProxy->pInstrument == pInstrument) + pProxy->pEditor->SendNoteOffToDevice(Key, Velocity); } - // free the editor - InstrumentEditorFactory::Destroy(pSender); + InstrumentEditorProxiesMutex.Unlock(); // naively assumes RT safe implementation } +#endif // unused void InstrumentResourceManager::OnSamplesToBeRemoved(std::set Samples, InstrumentEditor* pSender) { if (Samples.empty()) { @@ -210,10 +425,10 @@ ::gig::Instrument* pInstrument = (::gig::Instrument*) pRegion->GetParent(); Lock(); - std::set engines = + std::set engines = GetEnginesUsing(pInstrument, false/*don't lock again*/); - std::set::iterator iter = engines.begin(); - std::set::iterator end = engines.end(); + std::set::iterator iter = engines.begin(); + std::set::iterator end = engines.end(); for (; iter != end; ++iter) (*iter)->Suspend(pRegion); Unlock(); } else if (sStructType == "gig::DimensionRegion") { @@ -227,10 +442,10 @@ ::gig::Instrument* pInstrument = (::gig::Instrument*) pRegion->GetParent(); Lock(); - std::set engines = + std::set engines = GetEnginesUsing(pInstrument, false/*don't lock again*/); - std::set::iterator iter = engines.begin(); - std::set::iterator end = engines.end(); + std::set::iterator iter = engines.begin(); + std::set::iterator end = engines.end(); for (; iter != end; ++iter) (*iter)->Suspend(pRegion); Unlock(); } else { @@ -250,6 +465,28 @@ } else if (sStructType == "gig::Instrument") { // resume all previously suspended engines ResumeAllEngines(); + } else if (sStructType == "gig::Sample") { + // we're assuming here, that OnDataStructureToBeChanged() with + // "gig::File" was called previously, so we won't resume anything + // here, but just re-cache the given sample + Lock(); + ::gig::Sample* pSample = (::gig::Sample*) pStruct; + ::gig::File* pFile = (::gig::File*) pSample->GetParent(); + UncacheInitialSamples(pSample); + // now re-cache ... + std::vector< ::gig::Instrument*> instruments = + GetInstrumentsCurrentlyUsedOf(pFile, false/*don't lock again*/); + for (int i = 0; i < instruments.size(); i++) { + if (SampleReferencedByInstrument(pSample, instruments[i])) { + std::set engineChannels = + GetEngineChannelsUsing(instruments[i], false/*don't lock again*/); + std::set::iterator iter = engineChannels.begin(); + std::set::iterator end = engineChannels.end(); + for (; iter != end; ++iter) + CacheInitialSamples(pSample, *iter); + } + } + Unlock(); } else if (sStructType == "gig::Region") { // advice the engines to resume the given region, that is to // using it for playback again @@ -257,10 +494,10 @@ ::gig::Instrument* pInstrument = (::gig::Instrument*) pRegion->GetParent(); Lock(); - std::set engines = + std::set engines = GetEnginesUsing(pInstrument, false/*don't lock again*/); - std::set::iterator iter = engines.begin(); - std::set::iterator end = engines.end(); + std::set::iterator iter = engines.begin(); + std::set::iterator end = engines.end(); for (; iter != end; ++iter) (*iter)->Resume(pRegion); Unlock(); } else if (sStructType == "gig::DimensionRegion") { @@ -272,10 +509,10 @@ ::gig::Instrument* pInstrument = (::gig::Instrument*) pRegion->GetParent(); Lock(); - std::set engines = + std::set engines = GetEnginesUsing(pInstrument, false/*don't lock again*/); - std::set::iterator iter = engines.begin(); - std::set::iterator end = engines.end(); + std::set::iterator iter = engines.begin(); + std::set::iterator end = engines.end(); for (; iter != end; ++iter) (*iter)->Resume(pRegion); Unlock(); } else { @@ -293,11 +530,16 @@ Lock(); ::gig::Sample* pSample = (::gig::Sample*) pOldSample; ::gig::File* pFile = (::gig::File*) pSample->GetParent(); + bool bSampleStillInUse = false; std::vector< ::gig::Instrument*> instruments = GetInstrumentsCurrentlyUsedOf(pFile, false/*don't lock again*/); - for (int i = 0; i < instruments.size(); i++) - if (!SampleReferencedByInstrument(pSample, instruments[i])) - UncacheInitialSamples(pSample); + for (int i = 0; i < instruments.size(); i++) { + if (SampleReferencedByInstrument(pSample, instruments[i])) { + bSampleStillInUse = true; + break; + } + } + if (!bSampleStillInUse) UncacheInitialSamples(pSample); Unlock(); } // make sure new sample reference is cached @@ -306,9 +548,9 @@ ::gig::Sample* pSample = (::gig::Sample*) pNewSample; ::gig::File* pFile = (::gig::File*) pSample->GetParent(); // get all engines that use that same gig::File - std::set engines = GetEnginesUsing(pFile, false/*don't lock again*/); - std::set::iterator iter = engines.begin(); - std::set::iterator end = engines.end(); + std::set engines = GetEnginesUsing(pFile, false/*don't lock again*/); + std::set::iterator iter = engines.begin(); + std::set::iterator end = engines.end(); for (; iter != end; ++iter) CacheInitialSamples(pSample, *iter); Unlock(); @@ -349,10 +591,10 @@ if (pRgn->GetSample() && !pRgn->GetSample()->GetCache().Size) { dmsg(2,("C")); - CacheInitialSamples(pRgn->GetSample(), (gig::EngineChannel*) pConsumer); + CacheInitialSamples(pRgn->GetSample(), (EngineChannel*) pConsumer); } for (uint i = 0; i < pRgn->DimensionRegions; i++) { - CacheInitialSamples(pRgn->pDimensionRegions[i]->pSample, (gig::EngineChannel*) pConsumer); + CacheInitialSamples(pRgn->pDimensionRegions[i]->pSample, (EngineChannel*) pConsumer); } pRgn = pInstrument->GetNextRegion(); @@ -367,12 +609,12 @@ pEntry->ID.Index = Key.Index; pEntry->pGig = pGig; - gig::EngineChannel* pEngineChannel = dynamic_cast(pConsumer); + EngineChannel* pEngineChannel = dynamic_cast(pConsumer); // and we save this to check if we need to reallocate for a engine with higher value of 'MaxSamplesPerSecond' pEntry->MaxSamplesPerCycle = (!pEngineChannel) ? 0 /* don't care for instrument editors */ : (pEngineChannel->GetEngine()) ? - dynamic_cast(pEngineChannel->GetEngine())->pAudioOutputDevice->MaxSamplesPerCycle() + dynamic_cast(pEngineChannel->GetEngine())->pAudioOutputDevice->MaxSamplesPerCycle() : GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE; pArg = pEntry; @@ -388,63 +630,29 @@ void InstrumentResourceManager::OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg) { instr_entry_t* pEntry = (instr_entry_t*) pArg; - gig::EngineChannel* pEngineChannel = dynamic_cast(pConsumer); + EngineChannel* pEngineChannel = dynamic_cast(pConsumer); uint maxSamplesPerCycle = - (pEngineChannel && pEngineChannel->GetEngine()) ? dynamic_cast(pEngineChannel->GetEngine())->pAudioOutputDevice->MaxSamplesPerCycle() + (pEngineChannel && pEngineChannel->GetEngine()) ? dynamic_cast(pEngineChannel->GetEngine())->pAudioOutputDevice->MaxSamplesPerCycle() : GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE; if (pEntry->MaxSamplesPerCycle < maxSamplesPerCycle) { Update(pResource, pConsumer); } } - /** - * Give back an instrument. This should be used instead of - * HandBack if there are some dimension regions that are still in - * use. (When an instrument is changed, the voices currently - * playing is allowed to keep playing with the old instrument - * until note off arrives. New notes will use the new instrument.) - */ - void InstrumentResourceManager::HandBackInstrument(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, - ::gig::DimensionRegion** dimRegionsInUse) { - DimRegInfoMutex.Lock(); - for (int i = 0 ; dimRegionsInUse[i] ; i++) { - DimRegInfo[dimRegionsInUse[i]].refCount++; - SampleRefCount[dimRegionsInUse[i]->pSample]++; - } - HandBack(pResource, pConsumer, true); - DimRegInfoMutex.Unlock(); + void InstrumentResourceManager::DeleteRegionIfNotUsed(::gig::DimensionRegion* pRegion, region_info_t* pRegInfo) { + // TODO: we could delete Region and Instrument here if they have become unused } - - /** - * Give back a dimension region that belongs to an instrument that - * was previously handed back. - */ - void InstrumentResourceManager::HandBackDimReg(::gig::DimensionRegion* pDimReg) { - DimRegInfoMutex.Lock(); - dimreg_info_t& dimRegInfo = DimRegInfo[pDimReg]; - int dimRegRefCount = --dimRegInfo.refCount; - int sampleRefCount = --SampleRefCount[pDimReg->pSample]; - if (dimRegRefCount == 0) { - ::gig::File* gig = dimRegInfo.file; - ::RIFF::File* riff = dimRegInfo.riff; - DimRegInfo.erase(pDimReg); - // TODO: we could delete Region and Instrument here if - // they have become unused - - if (sampleRefCount == 0) { - SampleRefCount.erase(pDimReg->pSample); - - if (gig) { - gig->DeleteSample(pDimReg->pSample); - if (!gig->GetFirstSample()) { - dmsg(2,("No more samples in use - freeing gig\n")); - delete gig; - delete riff; - } - } + void InstrumentResourceManager::DeleteSampleIfNotUsed(::gig::Sample* pSample, region_info_t* pRegInfo) { + ::gig::File* gig = pRegInfo->file; + ::RIFF::File* riff = static_cast< ::RIFF::File*>(pRegInfo->pArg); + if (gig) { + gig->DeleteSample(pSample); + if (!gig->GetFirstSample()) { + dmsg(2,("No more samples in use - freeing gig\n")); + delete gig; + delete riff; } } - DimRegInfoMutex.Unlock(); } /** @@ -455,10 +663,10 @@ * (may be NULL, in this case default amount of samples * will be cached) */ - void InstrumentResourceManager::CacheInitialSamples(::gig::Sample* pSample, gig::EngineChannel* pEngineChannel) { - gig::Engine* pEngine = + void InstrumentResourceManager::CacheInitialSamples(::gig::Sample* pSample, EngineChannel* pEngineChannel) { + Engine* pEngine = (pEngineChannel && pEngineChannel->GetEngine()) ? - dynamic_cast(pEngineChannel->GetEngine()) : NULL; + dynamic_cast(pEngineChannel->GetEngine()) : NULL; CacheInitialSamples(pSample, pEngine); } @@ -473,7 +681,7 @@ * (may be NULL, in this case default amount of samples * will be cached) */ - void InstrumentResourceManager::CacheInitialSamples(::gig::Sample* pSample, gig::Engine* pEngine) { + void InstrumentResourceManager::CacheInitialSamples(::gig::Sample* pSample, AbstractEngine* pEngine) { if (!pSample) { dmsg(4,("gig::InstrumentResourceManager: Skipping sample (pSample == NULL)\n")); return; @@ -531,6 +739,29 @@ } /** + * Returns a list with all gig engine channels that are currently using + * the given instrument. + * + * @param pInstrument - search criteria + * @param bLock - whether we should lock (mutex) the instrument manager + * during this call and unlock at the end of this call + */ + std::set InstrumentResourceManager::GetEngineChannelsUsing(::gig::Instrument* pInstrument, bool bLock) { + if (bLock) Lock(); + std::set result; + std::set*> consumers = ConsumersOf(pInstrument); + std::set*>::iterator iter = consumers.begin(); + std::set*>::iterator end = consumers.end(); + for (; iter != end; ++iter) { + EngineChannel* pEngineChannel = dynamic_cast(*iter); + if (!pEngineChannel) continue; + result.insert(pEngineChannel); + } + if (bLock) Unlock(); + return result; + } + + /** * Returns a list with all gig Engines that are currently using the given * instrument. * @@ -538,16 +769,16 @@ * @param bLock - whether we should lock (mutex) the instrument manager * during this call and unlock at the end of this call */ - std::set InstrumentResourceManager::GetEnginesUsing(::gig::Instrument* pInstrument, bool bLock) { + std::set InstrumentResourceManager::GetEnginesUsing(::gig::Instrument* pInstrument, bool bLock) { if (bLock) Lock(); - std::set result; + std::set result; std::set*> consumers = ConsumersOf(pInstrument); std::set*>::iterator iter = consumers.begin(); std::set*>::iterator end = consumers.end(); for (; iter != end; ++iter) { - gig::EngineChannel* pEngineChannel = dynamic_cast(*iter); + EngineChannel* pEngineChannel = dynamic_cast(*iter); if (!pEngineChannel) continue; - gig::Engine* pEngine = dynamic_cast(pEngineChannel->GetEngine()); + Engine* pEngine = dynamic_cast(pEngineChannel->GetEngine()); if (!pEngine) continue; result.insert(pEngine); } @@ -563,23 +794,23 @@ * @param bLock - whether we should lock (mutex) the instrument manager * during this call and unlock at the end of this call */ - std::set InstrumentResourceManager::GetEnginesUsing(::gig::File* pFile, bool bLock) { + std::set InstrumentResourceManager::GetEnginesUsing(::gig::File* pFile, bool bLock) { if (bLock) Lock(); // get all instruments (currently in usage) that use that same gig::File std::vector< ::gig::Instrument*> instrumentsOfInterest = GetInstrumentsCurrentlyUsedOf(pFile, false/*don't lock again*/); // get all engines that use that same gig::File - std::set result; + std::set result; { for (int i = 0; i < instrumentsOfInterest.size(); i++) { std::set*> consumers = ConsumersOf(instrumentsOfInterest[i]); std::set*>::iterator iter = consumers.begin(); std::set*>::iterator end = consumers.end(); for (; iter != end; ++iter) { - gig::EngineChannel* pEngineChannel = dynamic_cast(*iter); + EngineChannel* pEngineChannel = dynamic_cast(*iter); if (!pEngineChannel) continue; - gig::Engine* pEngine = dynamic_cast(pEngineChannel->GetEngine()); + Engine* pEngine = dynamic_cast(pEngineChannel->GetEngine()); if (!pEngine) continue; // the unique, sorted container std::set makes // sure we won't have duplicates @@ -633,8 +864,8 @@ // get all engines that use that same gig::Instrument suspendedEngines = GetEnginesUsing(pInstrument, true/*lock*/); // finally, completely suspend all engines that use that same gig::Instrument - std::set::iterator iter = suspendedEngines.begin(); - std::set::iterator end = suspendedEngines.end(); + std::set::iterator iter = suspendedEngines.begin(); + std::set::iterator end = suspendedEngines.end(); for (; iter != end; ++iter) (*iter)->SuspendAll(); } @@ -657,8 +888,8 @@ // get all engines that use that same gig::File suspendedEngines = GetEnginesUsing(pFile, true/*lock*/); // finally, completely suspend all engines that use that same gig::File - std::set::iterator iter = suspendedEngines.begin(); - std::set::iterator end = suspendedEngines.end(); + std::set::iterator iter = suspendedEngines.begin(); + std::set::iterator end = suspendedEngines.end(); for (; iter != end; ++iter) (*iter)->SuspendAll(); } @@ -714,11 +945,11 @@ for (int i = 0 ; i < region->DimensionRegions ; i++) { ::gig::DimensionRegion *d = region->pDimensionRegions[i]; - std::map< ::gig::DimensionRegion*, dimreg_info_t>::iterator iter = parent->DimRegInfo.find(d); - if (iter != parent->DimRegInfo.end()) { - dimreg_info_t& dimRegInfo = (*iter).second; + std::map< ::gig::DimensionRegion*, region_info_t>::iterator iter = parent->RegionInfo.find(d); + if (iter != parent->RegionInfo.end()) { + region_info_t& dimRegInfo = (*iter).second; dimRegInfo.file = pResource; - dimRegInfo.riff = (::RIFF::File*)pArg; + dimRegInfo.pArg = (::RIFF::File*)pArg; deleteFile = deleteInstrument = deleteRegion = false; } }