/[svn]/linuxsampler/trunk/src/Sampler.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/Sampler.cpp

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

revision 1008 by schoenebeck, Wed Jan 3 17:49:44 2007 UTC revision 1541 by iliev, Tue Dec 4 18:09:26 2007 UTC
# Line 25  Line 25 
25    
26  #include "Sampler.h"  #include "Sampler.h"
27    
28    #include "common/global_private.h"
29  #include "engines/EngineFactory.h"  #include "engines/EngineFactory.h"
30  #include "engines/EngineChannelFactory.h"  #include "engines/EngineChannelFactory.h"
31    #include "plugins/InstrumentEditorFactory.h"
32  #include "drivers/audio/AudioOutputDeviceFactory.h"  #include "drivers/audio/AudioOutputDeviceFactory.h"
33  #include "drivers/midi/MidiInputDeviceFactory.h"  #include "drivers/midi/MidiInputDeviceFactory.h"
34  #include "drivers/midi/MidiInstrumentMapper.h"  #include "drivers/midi/MidiInstrumentMapper.h"
 #include "network/lscpserver.h"  
35    
36  namespace LinuxSampler {  namespace LinuxSampler {
37    
# Line 67  namespace LinuxSampler { Line 68  namespace LinuxSampler {
68    
69      void SamplerChannel::SetEngineType(String EngineType) throw (Exception) {      void SamplerChannel::SetEngineType(String EngineType) throw (Exception) {
70          dmsg(2,("SamplerChannel: Assigning engine type..."));          dmsg(2,("SamplerChannel: Assigning engine type..."));
71            
72            if (pEngineChannel) {
73                if (!strcasecmp(pEngineChannel->EngineName().c_str(), EngineType.c_str())) {
74                    dmsg(2,("OK\n"));
75                    return;
76                }
77            }
78    
79          // create new engine channel          // create new engine channel
80          EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType);          EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType);
# Line 104  namespace LinuxSampler { Line 112  namespace LinuxSampler {
112          this->iMidiPort        = 0;          this->iMidiPort        = 0;
113    
114          pEngineChannel->StatusChanged(true);          pEngineChannel->StatusChanged(true);
115            fireEngineChanged();
116          dmsg(2,("OK\n"));          dmsg(2,("OK\n"));
117      }      }
118    
# Line 205  namespace LinuxSampler { Line 213  namespace LinuxSampler {
213          throw Exception("Internal error: SamplerChannel index not found");          throw Exception("Internal error: SamplerChannel index not found");
214      }      }
215    
216        void SamplerChannel::AddEngineChangeListener(EngineChangeListener* l) {
217            llEngineChangeListeners.AddListener(l);
218        }
219    
220        void SamplerChannel::RemoveEngineChangeListener(EngineChangeListener* l) {
221           llEngineChangeListeners.RemoveListener(l);
222        }
223    
224        void SamplerChannel::RemoveAllEngineChangeListeners() {
225           llEngineChangeListeners.RemoveAllListeners();
226        }
227    
228        void SamplerChannel::fireEngineChanged() {
229            for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) {
230                llEngineChangeListeners.GetListener(i)->EngineChanged(Index());
231            }
232        }
233    
234      MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) {      MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) {
235          MidiInputPort* pMidiInputPort = NULL;          MidiInputPort* pMidiInputPort = NULL;
236          MidiInputDevice* pMidiInputDevice = GetMidiInputDevice();          MidiInputDevice* pMidiInputDevice = GetMidiInputDevice();
# Line 219  namespace LinuxSampler { Line 245  namespace LinuxSampler {
245      // * Sampler      // * Sampler
246    
247      Sampler::Sampler() {      Sampler::Sampler() {
248            eventHandler.SetSampler(this);
249      }      }
250    
251      Sampler::~Sampler() {      Sampler::~Sampler() {
# Line 229  namespace LinuxSampler { Line 256  namespace LinuxSampler {
256          return mSamplerChannels.size();          return mSamplerChannels.size();
257      }      }
258    
259        void Sampler::AddChannelCountListener(ChannelCountListener* l) {
260            llChannelCountListeners.AddListener(l);
261        }
262    
263        void Sampler::RemoveChannelCountListener(ChannelCountListener* l) {
264           llChannelCountListeners.RemoveListener(l);
265        }
266    
267        void Sampler::fireChannelCountChanged(int NewCount) {
268            for (int i = 0; i < llChannelCountListeners.GetListenerCount(); i++) {
269                llChannelCountListeners.GetListener(i)->ChannelCountChanged(NewCount);
270            }
271        }
272    
273        void Sampler::AddAudioDeviceCountListener(AudioDeviceCountListener* l) {
274            llAudioDeviceCountListeners.AddListener(l);
275        }
276    
277        void Sampler::RemoveAudioDeviceCountListener(AudioDeviceCountListener* l) {
278            llAudioDeviceCountListeners.RemoveListener(l);
279        }
280    
281        void Sampler::fireAudioDeviceCountChanged(int NewCount) {
282            for (int i = 0; i < llAudioDeviceCountListeners.GetListenerCount(); i++) {
283                llAudioDeviceCountListeners.GetListener(i)->AudioDeviceCountChanged(NewCount);
284            }
285        }
286    
287        void Sampler::AddMidiDeviceCountListener(MidiDeviceCountListener* l) {
288            llMidiDeviceCountListeners.AddListener(l);
289        }
290    
291        void Sampler::RemoveMidiDeviceCountListener(MidiDeviceCountListener* l) {
292            llMidiDeviceCountListeners.RemoveListener(l);
293        }
294    
295        void Sampler::fireMidiDeviceCountChanged(int NewCount) {
296            for (int i = 0; i < llMidiDeviceCountListeners.GetListenerCount(); i++) {
297                llMidiDeviceCountListeners.GetListener(i)->MidiDeviceCountChanged(NewCount);
298            }
299        }
300    
301        void Sampler::AddVoiceCountListener(VoiceCountListener* l) {
302            llVoiceCountListeners.AddListener(l);
303        }
304    
305        void Sampler::RemoveVoiceCountListener(VoiceCountListener* l) {
306            llVoiceCountListeners.RemoveListener(l);
307        }
308    
309        void Sampler::fireVoiceCountChanged(int ChannelId, int NewCount) {
310            for (int i = 0; i < llVoiceCountListeners.GetListenerCount(); i++) {
311                llVoiceCountListeners.GetListener(i)->VoiceCountChanged(ChannelId, NewCount);
312            }
313        }
314    
315        void Sampler::AddStreamCountListener(StreamCountListener* l) {
316            llStreamCountListeners.AddListener(l);
317        }
318    
319        void Sampler::RemoveStreamCountListener(StreamCountListener* l) {
320            llStreamCountListeners.RemoveListener(l);
321        }
322    
323        void Sampler::fireStreamCountChanged(int ChannelId, int NewCount) {
324            for (int i = 0; i < llStreamCountListeners.GetListenerCount(); i++) {
325                llStreamCountListeners.GetListener(i)->StreamCountChanged(ChannelId, NewCount);
326            }
327        }
328    
329        void Sampler::AddBufferFillListener(BufferFillListener* l) {
330            llBufferFillListeners.AddListener(l);
331        }
332    
333        void Sampler::RemoveBufferFillListener(BufferFillListener* l) {
334            llBufferFillListeners.RemoveListener(l);
335        }
336    
337        void Sampler::fireBufferFillChanged(int ChannelId, String FillData) {
338            for (int i = 0; i < llBufferFillListeners.GetListenerCount(); i++) {
339                llBufferFillListeners.GetListener(i)->BufferFillChanged(ChannelId, FillData);
340            }
341        }
342    
343        void Sampler::AddTotalStreamCountListener(TotalStreamCountListener* l) {
344            llTotalStreamCountListeners.AddListener(l);
345        }
346    
347        void Sampler::RemoveTotalStreamCountListener(TotalStreamCountListener* l) {
348            llTotalStreamCountListeners.RemoveListener(l);
349        }
350    
351        void Sampler::fireTotalStreamCountChanged(int NewCount) {
352            for (int i = 0; i < llTotalStreamCountListeners.GetListenerCount(); i++) {
353                llTotalStreamCountListeners.GetListener(i)->TotalStreamCountChanged(NewCount);
354            }
355        }
356    
357        void Sampler::AddTotalVoiceCountListener(TotalVoiceCountListener* l) {
358            llTotalVoiceCountListeners.AddListener(l);
359        }
360    
361        void Sampler::RemoveTotalVoiceCountListener(TotalVoiceCountListener* l) {
362            llTotalVoiceCountListeners.RemoveListener(l);
363        }
364    
365        void Sampler::fireTotalVoiceCountChanged(int NewCount) {
366            for (int i = 0; i < llTotalVoiceCountListeners.GetListenerCount(); i++) {
367                llTotalVoiceCountListeners.GetListener(i)->TotalVoiceCountChanged(NewCount);
368            }
369        }
370    
371        void Sampler::AddFxSendCountListener(FxSendCountListener* l) {
372            llFxSendCountListeners.AddListener(l);
373        }
374    
375        void Sampler::RemoveFxSendCountListener(FxSendCountListener* l) {
376            llFxSendCountListeners.RemoveListener(l);
377        }
378    
379        void Sampler::fireFxSendCountChanged(int ChannelId, int NewCount) {
380            for (int i = 0; i < llFxSendCountListeners.GetListenerCount(); i++) {
381                llFxSendCountListeners.GetListener(i)->FxSendCountChanged(ChannelId, NewCount);
382            }
383        }
384    
385        void Sampler::EventHandler::EngineChanged(int ChannelId) {
386            EngineChannel* engineChannel = pSampler->GetSamplerChannel(ChannelId)->GetEngineChannel();
387            if(engineChannel == NULL) return;
388            engineChannel->AddFxSendCountListener(this);
389        }
390    
391        void Sampler::EventHandler::FxSendCountChanged(int ChannelId, int NewCount) {
392            pSampler->fireFxSendCountChanged(ChannelId, NewCount);
393        }
394    
395    
396      SamplerChannel* Sampler::AddSamplerChannel() {      SamplerChannel* Sampler::AddSamplerChannel() {
397          // if there's no sampler channel yet          // if there's no sampler channel yet
398          if (!mSamplerChannels.size()) {          if (!mSamplerChannels.size()) {
399              SamplerChannel* pChannel = new SamplerChannel(this);              SamplerChannel* pChannel = new SamplerChannel(this);
400              mSamplerChannels[0] = pChannel;              mSamplerChannels[0] = pChannel;
401              LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, 1));              fireChannelCountChanged(1);
402                pChannel->AddEngineChangeListener(&eventHandler);
403              return pChannel;              return pChannel;
404          }          }
405    
# Line 249  namespace LinuxSampler { Line 414  namespace LinuxSampler {
414                  // we found an unused index, so insert the new channel there                  // we found an unused index, so insert the new channel there
415                  SamplerChannel* pChannel = new SamplerChannel(this);                  SamplerChannel* pChannel = new SamplerChannel(this);
416                  mSamplerChannels[i] = pChannel;                  mSamplerChannels[i] = pChannel;
417                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i));                  fireChannelCountChanged(SamplerChannels());
418                    pChannel->AddEngineChangeListener(&eventHandler);
419                  return pChannel;                  return pChannel;
420              }              }
421              throw Exception("Internal error: could not find unoccupied sampler channel index.");              throw Exception("Internal error: could not find unoccupied sampler channel index.");
# Line 258  namespace LinuxSampler { Line 424  namespace LinuxSampler {
424          // we have not reached the index limit so we just add the channel past the highest index          // we have not reached the index limit so we just add the channel past the highest index
425          SamplerChannel* pChannel = new SamplerChannel(this);          SamplerChannel* pChannel = new SamplerChannel(this);
426          mSamplerChannels[lastIndex + 1] = pChannel;          mSamplerChannels[lastIndex + 1] = pChannel;
427          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, lastIndex + 1));          fireChannelCountChanged(SamplerChannels());
428            pChannel->AddEngineChangeListener(&eventHandler);
429          return pChannel;          return pChannel;
430      }      }
431    
# Line 274  namespace LinuxSampler { Line 441  namespace LinuxSampler {
441          SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();          SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();
442          for (; iterChan != mSamplerChannels.end(); iterChan++) {          for (; iterChan != mSamplerChannels.end(); iterChan++) {
443              if (iterChan->second == pSamplerChannel) {              if (iterChan->second == pSamplerChannel) {
444                    pSamplerChannel->RemoveAllEngineChangeListeners();
445                  mSamplerChannels.erase(iterChan);                  mSamplerChannels.erase(iterChan);
446                  delete pSamplerChannel;                  delete pSamplerChannel;
447                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, mSamplerChannels.size()));                  fireChannelCountChanged(SamplerChannels());
448                  return;                  return;
449              }              }
450          }          }
# Line 312  namespace LinuxSampler { Line 480  namespace LinuxSampler {
480              }              }
481          }          }
482    
483          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, AudioOutputDevices()));          fireAudioDeviceCountChanged(AudioOutputDevices());
484          return pDevice;          return pDevice;
485      }      }
486    
# Line 349  namespace LinuxSampler { Line 517  namespace LinuxSampler {
517                  // destroy and free device from memory                  // destroy and free device from memory
518                  delete pDevice;                  delete pDevice;
519    
520                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, AudioOutputDevices()));                  fireAudioDeviceCountChanged(AudioOutputDevices());
521                  break;                  break;
522              }              }
523          }          }
# Line 372  namespace LinuxSampler { Line 540  namespace LinuxSampler {
540                  // destroy and free device from memory                  // destroy and free device from memory
541                  delete pDevice;                  delete pDevice;
542    
543                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, MidiInputDevices()));                  fireMidiDeviceCountChanged(MidiInputDevices());
544                  break;                  break;
545              }              }
546          }          }
# Line 390  namespace LinuxSampler { Line 558  namespace LinuxSampler {
558                  }                  }
559          }          }
560    
561          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, MidiInputDevices()));          fireMidiDeviceCountChanged(MidiInputDevices());
562          return pDevice;          return pDevice;
563      }      }
564    
565        int Sampler::GetDiskStreamCount() {
566            int count = 0;
567            std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin();
568    
569            for(; it != EngineFactory::EngineInstances().end(); it++) {
570                count += (*it)->DiskStreamCount();
571            }
572    
573            return count;
574        }
575    
576      int Sampler::GetVoiceCount() {      int Sampler::GetVoiceCount() {
577          int count = 0;          int count = 0;
578          std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin();          std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin();
# Line 453  namespace LinuxSampler { Line 632  namespace LinuxSampler {
632              std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI instrument maps, exiting.\n" << std::flush;              std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI instrument maps, exiting.\n" << std::flush;
633              exit(EXIT_FAILURE);              exit(EXIT_FAILURE);
634          }          }
635    
636            // unload all instrument editor DLLs
637            InstrumentEditorFactory::ClosePlugins();
638      }      }
639    
640  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.1008  
changed lines
  Added in v.1541

  ViewVC Help
Powered by ViewVC