/[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 1212 by schoenebeck, Tue May 29 23:59:36 2007 UTC revision 1761 by iliev, Fri Aug 29 15:42:06 2008 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 - 2007 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2008 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This library is free software; you can redistribute it and/or modify  *   *   This library 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 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 "engines/InstrumentEditorFactory.h"  #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"
35    #include "common/Features.h"
36    
37  namespace LinuxSampler {  namespace LinuxSampler {
38    
# Line 67  namespace LinuxSampler { Line 69  namespace LinuxSampler {
69    
70      void SamplerChannel::SetEngineType(String EngineType) throw (Exception) {      void SamplerChannel::SetEngineType(String EngineType) throw (Exception) {
71          dmsg(2,("SamplerChannel: Assigning engine type..."));          dmsg(2,("SamplerChannel: Assigning engine type..."));
72            
73            if (pEngineChannel) {
74                if (!strcasecmp(pEngineChannel->EngineName().c_str(), EngineType.c_str())) {
75                    dmsg(2,("OK\n"));
76                    return;
77                }
78            }
79    
80            fireEngineToBeChanged();
81    
82          // create new engine channel          // create new engine channel
83          EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType);          EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType);
84          if (!pNewEngineChannel) throw Exception("Unknown engine type");          if (!pNewEngineChannel) throw Exception("Unknown engine type");
85    
86          //FIXME: hack to allow fast retrieval of engine channel's sampler channel index          pNewEngineChannel->SetSamplerChannel(this);
         pNewEngineChannel->iSamplerChannelIndex = Index();  
87    
88          // dereference midi input port.          // dereference midi input port.
89          MidiInputPort* pMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());          MidiInputPort* pMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());
# Line 205  namespace LinuxSampler { Line 215  namespace LinuxSampler {
215          throw Exception("Internal error: SamplerChannel index not found");          throw Exception("Internal error: SamplerChannel index not found");
216      }      }
217    
218        Sampler* SamplerChannel::GetSampler() {
219            return pSampler;
220        }
221    
222      void SamplerChannel::AddEngineChangeListener(EngineChangeListener* l) {      void SamplerChannel::AddEngineChangeListener(EngineChangeListener* l) {
223          llEngineChangeListeners.AddListener(l);          llEngineChangeListeners.AddListener(l);
224      }      }
# Line 217  namespace LinuxSampler { Line 231  namespace LinuxSampler {
231         llEngineChangeListeners.RemoveAllListeners();         llEngineChangeListeners.RemoveAllListeners();
232      }      }
233    
234        void SamplerChannel::fireEngineToBeChanged() {
235            for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) {
236                llEngineChangeListeners.GetListener(i)->EngineToBeChanged(Index());
237            }
238        }
239    
240      void SamplerChannel::fireEngineChanged() {      void SamplerChannel::fireEngineChanged() {
241          for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) {          for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) {
242              llEngineChangeListeners.GetListener(i)->EngineChanged(Index());              llEngineChangeListeners.GetListener(i)->EngineChanged(Index());
# Line 262  namespace LinuxSampler { Line 282  namespace LinuxSampler {
282          }          }
283      }      }
284    
285        void Sampler::fireChannelAdded(SamplerChannel* pChannel) {
286            for (int i = 0; i < llChannelCountListeners.GetListenerCount(); i++) {
287                llChannelCountListeners.GetListener(i)->ChannelAdded(pChannel);
288            }
289        }
290    
291        void Sampler::fireChannelToBeRemoved(SamplerChannel* pChannel) {
292            for (int i = 0; i < llChannelCountListeners.GetListenerCount(); i++) {
293                llChannelCountListeners.GetListener(i)->ChannelToBeRemoved(pChannel);
294            }
295        }
296    
297      void Sampler::AddAudioDeviceCountListener(AudioDeviceCountListener* l) {      void Sampler::AddAudioDeviceCountListener(AudioDeviceCountListener* l) {
298          llAudioDeviceCountListeners.AddListener(l);          llAudioDeviceCountListeners.AddListener(l);
299      }      }
# Line 290  namespace LinuxSampler { Line 322  namespace LinuxSampler {
322          }          }
323      }      }
324    
325        void Sampler::fireMidiDeviceToBeDestroyed(MidiInputDevice* pDevice) {
326            for (int i = 0; i < llMidiDeviceCountListeners.GetListenerCount(); i++) {
327                llMidiDeviceCountListeners.GetListener(i)->MidiDeviceToBeDestroyed(pDevice);
328            }
329        }
330    
331        void Sampler::fireMidiDeviceCreated(MidiInputDevice* pDevice) {
332            for (int i = 0; i < llMidiDeviceCountListeners.GetListenerCount(); i++) {
333                llMidiDeviceCountListeners.GetListener(i)->MidiDeviceCreated(pDevice);
334            }
335        }
336    
337      void Sampler::AddVoiceCountListener(VoiceCountListener* l) {      void Sampler::AddVoiceCountListener(VoiceCountListener* l) {
338          llVoiceCountListeners.AddListener(l);          llVoiceCountListeners.AddListener(l);
339      }      }
# Line 332  namespace LinuxSampler { Line 376  namespace LinuxSampler {
376          }          }
377      }      }
378    
379        void Sampler::AddTotalStreamCountListener(TotalStreamCountListener* l) {
380            llTotalStreamCountListeners.AddListener(l);
381        }
382    
383        void Sampler::RemoveTotalStreamCountListener(TotalStreamCountListener* l) {
384            llTotalStreamCountListeners.RemoveListener(l);
385        }
386    
387        void Sampler::fireTotalStreamCountChanged(int NewCount) {
388            for (int i = 0; i < llTotalStreamCountListeners.GetListenerCount(); i++) {
389                llTotalStreamCountListeners.GetListener(i)->TotalStreamCountChanged(NewCount);
390            }
391        }
392    
393      void Sampler::AddTotalVoiceCountListener(TotalVoiceCountListener* l) {      void Sampler::AddTotalVoiceCountListener(TotalVoiceCountListener* l) {
394          llTotalVoiceCountListeners.AddListener(l);          llTotalVoiceCountListeners.AddListener(l);
395      }      }
# Line 360  namespace LinuxSampler { Line 418  namespace LinuxSampler {
418          }          }
419      }      }
420    
421        void Sampler::EventHandler::EngineToBeChanged(int ChannelId) {
422            // nothing to do here
423        }
424    
425      void Sampler::EventHandler::EngineChanged(int ChannelId) {      void Sampler::EventHandler::EngineChanged(int ChannelId) {
426          EngineChannel* engineChannel = pSampler->GetSamplerChannel(ChannelId)->GetEngineChannel();          EngineChannel* engineChannel = pSampler->GetSamplerChannel(ChannelId)->GetEngineChannel();
427          if(engineChannel == NULL) return;          if(engineChannel == NULL) return;
# Line 376  namespace LinuxSampler { Line 438  namespace LinuxSampler {
438          if (!mSamplerChannels.size()) {          if (!mSamplerChannels.size()) {
439              SamplerChannel* pChannel = new SamplerChannel(this);              SamplerChannel* pChannel = new SamplerChannel(this);
440              mSamplerChannels[0] = pChannel;              mSamplerChannels[0] = pChannel;
441                fireChannelAdded(pChannel);
442              fireChannelCountChanged(1);              fireChannelCountChanged(1);
443              pChannel->AddEngineChangeListener(&eventHandler);              pChannel->AddEngineChangeListener(&eventHandler);
444              return pChannel;              return pChannel;
# Line 392  namespace LinuxSampler { Line 455  namespace LinuxSampler {
455                  // we found an unused index, so insert the new channel there                  // we found an unused index, so insert the new channel there
456                  SamplerChannel* pChannel = new SamplerChannel(this);                  SamplerChannel* pChannel = new SamplerChannel(this);
457                  mSamplerChannels[i] = pChannel;                  mSamplerChannels[i] = pChannel;
458                    fireChannelAdded(pChannel);
459                  fireChannelCountChanged(SamplerChannels());                  fireChannelCountChanged(SamplerChannels());
460                  pChannel->AddEngineChangeListener(&eventHandler);                  pChannel->AddEngineChangeListener(&eventHandler);
461                  return pChannel;                  return pChannel;
# Line 402  namespace LinuxSampler { Line 466  namespace LinuxSampler {
466          // 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
467          SamplerChannel* pChannel = new SamplerChannel(this);          SamplerChannel* pChannel = new SamplerChannel(this);
468          mSamplerChannels[lastIndex + 1] = pChannel;          mSamplerChannels[lastIndex + 1] = pChannel;
469            fireChannelAdded(pChannel);
470          fireChannelCountChanged(SamplerChannels());          fireChannelCountChanged(SamplerChannels());
471          pChannel->AddEngineChangeListener(&eventHandler);          pChannel->AddEngineChangeListener(&eventHandler);
472          return pChannel;          return pChannel;
# Line 419  namespace LinuxSampler { Line 484  namespace LinuxSampler {
484          SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();          SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();
485          for (; iterChan != mSamplerChannels.end(); iterChan++) {          for (; iterChan != mSamplerChannels.end(); iterChan++) {
486              if (iterChan->second == pSamplerChannel) {              if (iterChan->second == pSamplerChannel) {
487                    fireChannelToBeRemoved(pSamplerChannel);
488                  pSamplerChannel->RemoveAllEngineChangeListeners();                  pSamplerChannel->RemoveAllEngineChangeListeners();
489                  mSamplerChannels.erase(iterChan);                  mSamplerChannels.erase(iterChan);
490                  delete pSamplerChannel;                  delete pSamplerChannel;
# Line 509  namespace LinuxSampler { Line 575  namespace LinuxSampler {
575                  for (uint i = 0; i < SamplerChannels(); i++)                  for (uint i = 0; i < SamplerChannels(); i++)
576                      if (GetSamplerChannel(i)->GetMidiInputDevice() == pDevice) throw Exception("Sampler channel " + ToString(i) + " is still connected to the midi input device.");                      if (GetSamplerChannel(i)->GetMidiInputDevice() == pDevice) throw Exception("Sampler channel " + ToString(i) + " is still connected to the midi input device.");
577    
578                    fireMidiDeviceToBeDestroyed(pDevice);
579    
580                  // disable device                  // disable device
581                  pDevice->StopListen();                  pDevice->StopListen();
582    
# Line 536  namespace LinuxSampler { Line 604  namespace LinuxSampler {
604                  }                  }
605          }          }
606    
607            fireMidiDeviceCreated(pDevice);
608          fireMidiDeviceCountChanged(MidiInputDevices());          fireMidiDeviceCountChanged(MidiInputDevices());
609          return pDevice;          return pDevice;
610      }      }
611    
612        int Sampler::GetDiskStreamCount() {
613            int count = 0;
614            std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin();
615    
616            for(; it != EngineFactory::EngineInstances().end(); it++) {
617                count += (*it)->DiskStreamCount();
618            }
619    
620            return count;
621        }
622    
623      int Sampler::GetVoiceCount() {      int Sampler::GetVoiceCount() {
624          int count = 0;          int count = 0;
625          std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin();          std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin();
# Line 604  namespace LinuxSampler { Line 684  namespace LinuxSampler {
684          InstrumentEditorFactory::ClosePlugins();          InstrumentEditorFactory::ClosePlugins();
685      }      }
686    
687        bool Sampler::EnableDenormalsAreZeroMode() {
688            Features::detect();
689            return Features::enableDenormalsAreZeroMode();
690        }
691    
692  } // namespace LinuxSampler  } // namespace LinuxSampler

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

  ViewVC Help
Powered by ViewVC