/[svn]/linuxsampler/trunk/src/engines/gig/InstrumentResourceManager.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/gig/InstrumentResourceManager.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2901 by persson, Sun Aug 23 06:14:00 2015 UTC revision 2902 by schoenebeck, Tue May 3 14:00:16 2016 UTC
# Line 3  Line 3 
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 - 2015 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2016 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  *
# Line 392  namespace LinuxSampler { namespace gig { Line 392  namespace LinuxSampler { namespace gig {
392      }      }
393    
394      void InstrumentResourceManager::OnDataStructureToBeChanged(void* pStruct, String sStructType, InstrumentEditor* pSender) {      void InstrumentResourceManager::OnDataStructureToBeChanged(void* pStruct, String sStructType, InstrumentEditor* pSender) {
395            dmsg(5,("gig::InstrumentResourceManager::OnDataStructureToBeChanged(%s)\n", sStructType.c_str()));
396          //TODO: remove code duplication          //TODO: remove code duplication
397          if (sStructType == "gig::File") {          if (sStructType == "gig::File") {
398              // completely suspend all engines that use that file              // completely suspend all engines that use that file
# Line 432  namespace LinuxSampler { namespace gig { Line 433  namespace LinuxSampler { namespace gig {
433              std::set<Engine*>::iterator end  = engines.end();              std::set<Engine*>::iterator end  = engines.end();
434              for (; iter != end; ++iter) (*iter)->Suspend(pRegion);              for (; iter != end; ++iter) (*iter)->Suspend(pRegion);
435              Unlock();              Unlock();
436            } else if (sStructType == "gig::Script") {
437                // no need to suspend anything here, since the sampler is
438                // processing a translated VM representation of the original script
439                // source code, not accessing the source code itself during playback
440                ::gig::Script* pScript = (::gig::Script*) pStruct;
441                // remember the original source code of the script, since the script
442                // resource manager uses the source code as key
443                pendingScriptUpdatesMutex.Lock();
444                pendingScriptUpdates[pScript] = pScript->GetScriptAsText();
445                pendingScriptUpdatesMutex.Unlock();
446          } else {          } else {
447              std::cerr << "gig::InstrumentResourceManager: ERROR, unknown data "              std::cerr << "gig::InstrumentResourceManager: ERROR, unknown data "
448                           "structure '" << sStructType << "' requested to be "                           "structure '" << sStructType << "' requested to be "
# Line 442  namespace LinuxSampler { namespace gig { Line 453  namespace LinuxSampler { namespace gig {
453      }      }
454    
455      void InstrumentResourceManager::OnDataStructureChanged(void* pStruct, String sStructType, InstrumentEditor* pSender) {      void InstrumentResourceManager::OnDataStructureChanged(void* pStruct, String sStructType, InstrumentEditor* pSender) {
456            dmsg(5,("gig::InstrumentResourceManager::OnDataStructureChanged(%s)\n", sStructType.c_str()));
457          //TODO: remove code duplication          //TODO: remove code duplication
458          if (sStructType == "gig::File") {          if (sStructType == "gig::File") {
459              // resume all previously suspended engines              // resume all previously suspended engines
# Line 499  namespace LinuxSampler { namespace gig { Line 511  namespace LinuxSampler { namespace gig {
511              std::set<Engine*>::iterator end  = engines.end();              std::set<Engine*>::iterator end  = engines.end();
512              for (; iter != end; ++iter) (*iter)->Resume(pRegion);              for (; iter != end; ++iter) (*iter)->Resume(pRegion);
513              Unlock();              Unlock();
514            } else if (sStructType == "gig::Script") {
515                // inform all engine channels which are using this script, that
516                // they need to reload (parse) the script's source code text
517                ::gig::Script* pScript = (::gig::Script*) pStruct;
518                pendingScriptUpdatesMutex.Lock();
519                if (pendingScriptUpdates.count(pScript)) {
520                    const String& code = pendingScriptUpdates[pScript];
521                    std::set<EngineChannel*> channels = GetEngineChannelsUsingScriptSourceCode(code, true/*lock*/);
522                    pendingScriptUpdates.erase(pScript);
523                    std::set<EngineChannel*>::iterator iter = channels.begin();
524                    std::set<EngineChannel*>::iterator end  = channels.end();
525                    for (; iter != end; ++iter) (*iter)->reloadScript(pScript);
526                }
527                pendingScriptUpdatesMutex.Unlock();
528          } else {          } else {
529              std::cerr << "gig::InstrumentResourceManager: ERROR, unknown data "              std::cerr << "gig::InstrumentResourceManager: ERROR, unknown data "
530                           "structure '" << sStructType << "' requested to be "                           "structure '" << sStructType << "' requested to be "
# Line 713  namespace LinuxSampler { namespace gig { Line 739  namespace LinuxSampler { namespace gig {
739          if (bLock) Unlock();          if (bLock) Unlock();
740          return result;          return result;
741      }      }
742    
743        /**
744         * Returns a list with all gig engine channels that are currently using
745         * the given real-time instrument script (provided as source code).
746         *
747         * @param pScript - search criteria
748         * @param bLock - whether we should lock (mutex) the instrument manager
749         *                during this call and unlock at the end of this call
750         */
751        std::set<EngineChannel*> InstrumentResourceManager::GetEngineChannelsUsingScriptSourceCode(const String& code, bool bLock) {
752            if (bLock) Lock();
753            std::set<EngineChannel*> result;
754            std::set<InstrumentScriptConsumer*> consumers = scripts.ConsumersOf(code);
755            std::set<InstrumentScriptConsumer*>::iterator iter = consumers.begin();
756            std::set<InstrumentScriptConsumer*>::iterator end  = consumers.end();
757            for (; iter != end; ++iter) {
758                EngineChannel* pEngineChannel = dynamic_cast<EngineChannel*>(*iter);
759                if (!pEngineChannel) continue;
760                result.insert(pEngineChannel);
761            }
762            if (bLock) Unlock();
763            return result;
764        }
765    
766      /**      /**
767       * Returns a list with all gig engine channels that are currently using       * Returns a list with all gig engine channels that are currently using

Legend:
Removed from v.2901  
changed lines
  Added in v.2902

  ViewVC Help
Powered by ViewVC