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

Diff of /linuxsampler/trunk/src/engines/InstrumentManagerThread.cpp

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

revision 1649 by nagata, Fri Jan 25 15:06:02 2008 UTC revision 1761 by iliev, Fri Aug 29 15:42:06 2008 UTC
# Line 25  Line 25 
25  namespace LinuxSampler {  namespace LinuxSampler {
26    
27      InstrumentManagerThread::InstrumentManagerThread() : Thread(true, false, 0, -4) {      InstrumentManagerThread::InstrumentManagerThread() : Thread(true, false, 0, -4) {
28            eventHandler.pThread = this;
29      }      }
30    
31      InstrumentManagerThread::~InstrumentManagerThread() {      InstrumentManagerThread::~InstrumentManagerThread() {
# Line 43  namespace LinuxSampler { Line 44  namespace LinuxSampler {
44       */       */
45      void InstrumentManagerThread::StartNewLoad(String Filename, uint uiInstrumentIndex, EngineChannel* pEngineChannel) {      void InstrumentManagerThread::StartNewLoad(String Filename, uint uiInstrumentIndex, EngineChannel* pEngineChannel) {
46          dmsg(1,("Scheduling '%s' (Index=%d) to be loaded in background (if not loaded yet).\n",Filename.c_str(),uiInstrumentIndex));          dmsg(1,("Scheduling '%s' (Index=%d) to be loaded in background (if not loaded yet).\n",Filename.c_str(),uiInstrumentIndex));
47    
48            static bool listenerRegistered = false;
49            if (!listenerRegistered) {
50                pEngineChannel->GetSampler()->AddChannelCountListener(&eventHandler);
51                listenerRegistered = true;
52            }
53            
54            
55          // already tell the engine which instrument to load          // already tell the engine which instrument to load
56          pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrumentIndex);          pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrumentIndex);
57    
# Line 99  namespace LinuxSampler { Line 108  namespace LinuxSampler {
108                  // grab a new command from the queue                  // grab a new command from the queue
109                  mutex.Lock();                  mutex.Lock();
110                  cmd = queue.front();                  cmd = queue.front();
111                    queue.pop_front();
112                  mutex.Unlock();                  mutex.Unlock();
113    
114                  try {                  try {
# Line 117  namespace LinuxSampler { Line 127  namespace LinuxSampler {
127                  } catch (...) {                  } catch (...) {
128                      std::cerr << "InstrumentManagerThread: some exception occured, could not finish task\n" << std::flush;                      std::cerr << "InstrumentManagerThread: some exception occured, could not finish task\n" << std::flush;
129                  }                  }
   
                 // remove processed command from queue  
                 mutex.Lock();  
                 queue.pop_front();  
                 mutex.Unlock();  
130              }              }
131    
132              // nothing left to do, sleep until new jobs arrive              // nothing left to do, sleep until new jobs arrive
# Line 132  namespace LinuxSampler { Line 137  namespace LinuxSampler {
137              conditionJobsLeft.Unlock();              conditionJobsLeft.Unlock();
138          }          }
139      }      }
140        
141        void InstrumentManagerThread::EventHandler::ChannelToBeRemoved(SamplerChannel* pChannel) {
142            /*
143               Removing from the queue an eventual scheduled loading of an instrument
144               to a sampler channel which is going to be removed.
145            */
146            pThread->mutex.Lock();
147            std::list<command_t>::iterator it;
148            for (it = pThread->queue.begin(); it != pThread->queue.end();){
149                if ((*it).type != command_t::DIRECT_LOAD) { ++it; continue; }
150                if ((*it).pEngineChannel == pChannel->GetEngineChannel()) {
151                    it = pThread->queue.erase(it);
152                    // we don't break here because the same engine channel could
153                    // occur more than once in the queue, so don't make optimizations
154                } else {
155                    ++it;
156                }
157            }
158            pThread->mutex.Unlock();
159        }
160  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.1649  
changed lines
  Added in v.1761

  ViewVC Help
Powered by ViewVC