/[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 778 by iliev, Fri Sep 23 06:58:26 2005 UTC revision 1695 by schoenebeck, Sat Feb 16 01:09:33 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 Christian Schoenebeck                              *   *   Copyright (C) 2005 - 2008 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This program 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  *
10   *   the Free Software Foundation; either version 2 of the License, or     *   *   the Free Software Foundation; either version 2 of the License, or     *
11   *   (at your option) any later version.                                   *   *   (at your option) any later version.                                   *
12   *                                                                         *   *                                                                         *
13   *   This program is distributed in the hope that it will be useful,       *   *   This library is distributed in the hope that it will be useful,       *
14   *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *   *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16   *   GNU General Public License for more details.                          *   *   GNU General Public License for more details.                          *
17   *                                                                         *   *                                                                         *
18   *   You should have received a copy of the GNU General Public License     *   *   You should have received a copy of the GNU General Public License     *
19   *   along with this program; if not, write to the Free Software           *   *   along with this library; if not, write to the Free Software           *
20   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
21   *   MA  02111-1307  USA                                                   *   *   MA  02111-1307  USA                                                   *
22   ***************************************************************************/   ***************************************************************************/
# 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 "network/lscpserver.h"  #include "drivers/midi/MidiInstrumentMapper.h"
35    
36  namespace LinuxSampler {  namespace LinuxSampler {
37    
# Line 48  namespace LinuxSampler { Line 50  namespace LinuxSampler {
50    
51      SamplerChannel::~SamplerChannel() {      SamplerChannel::~SamplerChannel() {
52          if (pEngineChannel) {          if (pEngineChannel) {
53                Engine* engine = pEngineChannel->GetEngine();
54                if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(engine);
55    
56              MidiInputPort* pMidiInputPort = (pEngineChannel) ? pEngineChannel->GetMidiInputPort() : __GetMidiInputDevicePort(GetMidiInputChannel());              MidiInputPort* pMidiInputPort = (pEngineChannel) ? pEngineChannel->GetMidiInputPort() : __GetMidiInputDevicePort(GetMidiInputChannel());
57              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);
58              if (pEngineChannel) {              if (pEngineChannel) {
59                  if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();                  if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();
60                  EngineChannelFactory::Destroy(pEngineChannel);                  EngineChannelFactory::Destroy(pEngineChannel);
61    
62                    // reconnect engine if it still exists
63                    const std::set<Engine*>& engines = EngineFactory::EngineInstances();
64                    if (engines.find(engine) != engines.end()) pAudioOutputDevice->Connect(engine);
65              }              }
66          }          }
67      }      }
68    
69      void SamplerChannel::SetEngineType(String EngineType) throw (LinuxSamplerException) {      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            fireEngineToBeChanged();
80    
81          // create new engine channel          // create new engine channel
82          EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType);          EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType);
83          if (!pNewEngineChannel) throw LinuxSamplerException("Unknown engine type");          if (!pNewEngineChannel) throw Exception("Unknown engine type");
84    
85          //FIXME: hack to allow fast retrieval of engine channel's sampler channel index          //FIXME: hack to allow fast retrieval of engine channel's sampler channel index
86          pNewEngineChannel->iSamplerChannelIndex = Index();          pNewEngineChannel->iSamplerChannelIndex = Index();
# Line 71  namespace LinuxSampler { Line 89  namespace LinuxSampler {
89          MidiInputPort* pMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());          MidiInputPort* pMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());
90          // disconnect old engine channel          // disconnect old engine channel
91          if (pEngineChannel) {          if (pEngineChannel) {
92                Engine* engine = pEngineChannel->GetEngine();
93                if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(engine);
94    
95              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);
96              if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();              if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();
97              EngineChannelFactory::Destroy(pEngineChannel);              EngineChannelFactory::Destroy(pEngineChannel);
98    
99                // reconnect engine if it still exists
100                const std::set<Engine*>& engines = EngineFactory::EngineInstances();
101                if (engines.find(engine) != engines.end()) pAudioOutputDevice->Connect(engine);
102          }          }
103    
104          // connect new engine channel          // connect new engine channel
         if (pMidiInputPort) pMidiInputPort->Connect(pNewEngineChannel, GetMidiInputChannel());  
105          if (pAudioOutputDevice) {          if (pAudioOutputDevice) {
106              pNewEngineChannel->Connect(pAudioOutputDevice);              pNewEngineChannel->Connect(pAudioOutputDevice);
107              pAudioOutputDevice->Connect(pNewEngineChannel->GetEngine());              pAudioOutputDevice->Connect(pNewEngineChannel->GetEngine());
108          }          }
109            if (pMidiInputPort) pMidiInputPort->Connect(pNewEngineChannel, GetMidiInputChannel());
110          pEngineChannel = pNewEngineChannel;          pEngineChannel = pNewEngineChannel;
111    
112          // from now on get MIDI device and port from EngineChannel object          // from now on get MIDI device and port from EngineChannel object
# Line 89  namespace LinuxSampler { Line 114  namespace LinuxSampler {
114          this->iMidiPort        = 0;          this->iMidiPort        = 0;
115    
116          pEngineChannel->StatusChanged(true);          pEngineChannel->StatusChanged(true);
117            fireEngineChanged();
118          dmsg(2,("OK\n"));          dmsg(2,("OK\n"));
119      }      }
120    
121      void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) {      void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) {
122            if(pAudioOutputDevice == pDevice) return;
123    
124          // disconnect old device          // disconnect old device
125          if (pAudioOutputDevice && pEngineChannel) pEngineChannel->DisconnectAudioOutputDevice();          if (pAudioOutputDevice && pEngineChannel) {
126                Engine* engine = pEngineChannel->GetEngine();
127                pAudioOutputDevice->Disconnect(engine);
128    
129                pEngineChannel->DisconnectAudioOutputDevice();
130    
131                // reconnect engine if it still exists
132                const std::set<Engine*>& engines = EngineFactory::EngineInstances();
133                if (engines.find(engine) != engines.end()) pAudioOutputDevice->Connect(engine);
134            }
135    
136          // connect new device          // connect new device
137          pAudioOutputDevice = pDevice;          pAudioOutputDevice = pDevice;
138          if (pEngineChannel) {          if (pEngineChannel) {
# Line 117  namespace LinuxSampler { Line 154  namespace LinuxSampler {
154      }      }
155    
156      void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel) {      void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel) {
157          if (!pDevice) throw LinuxSamplerException("No MIDI input device assigned.");          if (!pDevice) throw Exception("No MIDI input device assigned.");
158    
159          // get old and new midi input port          // get old and new midi input port
160          MidiInputPort* pOldMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());          MidiInputPort* pOldMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());
# Line 136  namespace LinuxSampler { Line 173  namespace LinuxSampler {
173          if (pNewMidiInputPort && pEngineChannel) pNewMidiInputPort->Connect(pEngineChannel, MidiChannel);          if (pNewMidiInputPort && pEngineChannel) pNewMidiInputPort->Connect(pEngineChannel, MidiChannel);
174          // Ooops.          // Ooops.
175          if (pNewMidiInputPort == NULL)          if (pNewMidiInputPort == NULL)
176              throw LinuxSamplerException("There is no MIDI input port with index " + ToString(iMidiPort) + ".");              throw Exception("There is no MIDI input port with index " + ToString(iMidiPort) + ".");
177      }      }
178    
179      EngineChannel* SamplerChannel::GetEngineChannel() {      EngineChannel* SamplerChannel::GetEngineChannel() {
# Line 175  namespace LinuxSampler { Line 212  namespace LinuxSampler {
212              }              }
213          }          }
214    
215          throw LinuxSamplerException("Internal error: SamplerChannel index not found");          throw Exception("Internal error: SamplerChannel index not found");
216        }
217    
218        void SamplerChannel::AddEngineChangeListener(EngineChangeListener* l) {
219            llEngineChangeListeners.AddListener(l);
220        }
221    
222        void SamplerChannel::RemoveEngineChangeListener(EngineChangeListener* l) {
223           llEngineChangeListeners.RemoveListener(l);
224        }
225    
226        void SamplerChannel::RemoveAllEngineChangeListeners() {
227           llEngineChangeListeners.RemoveAllListeners();
228        }
229    
230        void SamplerChannel::fireEngineToBeChanged() {
231            for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) {
232                llEngineChangeListeners.GetListener(i)->EngineToBeChanged(Index());
233            }
234        }
235    
236        void SamplerChannel::fireEngineChanged() {
237            for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) {
238                llEngineChangeListeners.GetListener(i)->EngineChanged(Index());
239            }
240      }      }
241    
242      MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) {      MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) {
# Line 192  namespace LinuxSampler { Line 253  namespace LinuxSampler {
253      // * Sampler      // * Sampler
254    
255      Sampler::Sampler() {      Sampler::Sampler() {
256            eventHandler.SetSampler(this);
257      }      }
258    
259      Sampler::~Sampler() {      Sampler::~Sampler() {
# Line 202  namespace LinuxSampler { Line 264  namespace LinuxSampler {
264          return mSamplerChannels.size();          return mSamplerChannels.size();
265      }      }
266    
267        void Sampler::AddChannelCountListener(ChannelCountListener* l) {
268            llChannelCountListeners.AddListener(l);
269        }
270    
271        void Sampler::RemoveChannelCountListener(ChannelCountListener* l) {
272           llChannelCountListeners.RemoveListener(l);
273        }
274    
275        void Sampler::fireChannelCountChanged(int NewCount) {
276            for (int i = 0; i < llChannelCountListeners.GetListenerCount(); i++) {
277                llChannelCountListeners.GetListener(i)->ChannelCountChanged(NewCount);
278            }
279        }
280    
281        void Sampler::fireChannelAdded(SamplerChannel* pChannel) {
282            for (int i = 0; i < llChannelCountListeners.GetListenerCount(); i++) {
283                llChannelCountListeners.GetListener(i)->ChannelAdded(pChannel);
284            }
285        }
286    
287        void Sampler::fireChannelToBeRemoved(SamplerChannel* pChannel) {
288            for (int i = 0; i < llChannelCountListeners.GetListenerCount(); i++) {
289                llChannelCountListeners.GetListener(i)->ChannelToBeRemoved(pChannel);
290            }
291        }
292    
293        void Sampler::AddAudioDeviceCountListener(AudioDeviceCountListener* l) {
294            llAudioDeviceCountListeners.AddListener(l);
295        }
296    
297        void Sampler::RemoveAudioDeviceCountListener(AudioDeviceCountListener* l) {
298            llAudioDeviceCountListeners.RemoveListener(l);
299        }
300    
301        void Sampler::fireAudioDeviceCountChanged(int NewCount) {
302            for (int i = 0; i < llAudioDeviceCountListeners.GetListenerCount(); i++) {
303                llAudioDeviceCountListeners.GetListener(i)->AudioDeviceCountChanged(NewCount);
304            }
305        }
306    
307        void Sampler::AddMidiDeviceCountListener(MidiDeviceCountListener* l) {
308            llMidiDeviceCountListeners.AddListener(l);
309        }
310    
311        void Sampler::RemoveMidiDeviceCountListener(MidiDeviceCountListener* l) {
312            llMidiDeviceCountListeners.RemoveListener(l);
313        }
314    
315        void Sampler::fireMidiDeviceCountChanged(int NewCount) {
316            for (int i = 0; i < llMidiDeviceCountListeners.GetListenerCount(); i++) {
317                llMidiDeviceCountListeners.GetListener(i)->MidiDeviceCountChanged(NewCount);
318            }
319        }
320    
321        void Sampler::fireMidiDeviceToBeDestroyed(MidiInputDevice* pDevice) {
322            for (int i = 0; i < llMidiDeviceCountListeners.GetListenerCount(); i++) {
323                llMidiDeviceCountListeners.GetListener(i)->MidiDeviceToBeDestroyed(pDevice);
324            }
325        }
326    
327        void Sampler::fireMidiDeviceCreated(MidiInputDevice* pDevice) {
328            for (int i = 0; i < llMidiDeviceCountListeners.GetListenerCount(); i++) {
329                llMidiDeviceCountListeners.GetListener(i)->MidiDeviceCreated(pDevice);
330            }
331        }
332    
333        void Sampler::AddVoiceCountListener(VoiceCountListener* l) {
334            llVoiceCountListeners.AddListener(l);
335        }
336    
337        void Sampler::RemoveVoiceCountListener(VoiceCountListener* l) {
338            llVoiceCountListeners.RemoveListener(l);
339        }
340    
341        void Sampler::fireVoiceCountChanged(int ChannelId, int NewCount) {
342            for (int i = 0; i < llVoiceCountListeners.GetListenerCount(); i++) {
343                llVoiceCountListeners.GetListener(i)->VoiceCountChanged(ChannelId, NewCount);
344            }
345        }
346    
347        void Sampler::AddStreamCountListener(StreamCountListener* l) {
348            llStreamCountListeners.AddListener(l);
349        }
350    
351        void Sampler::RemoveStreamCountListener(StreamCountListener* l) {
352            llStreamCountListeners.RemoveListener(l);
353        }
354    
355        void Sampler::fireStreamCountChanged(int ChannelId, int NewCount) {
356            for (int i = 0; i < llStreamCountListeners.GetListenerCount(); i++) {
357                llStreamCountListeners.GetListener(i)->StreamCountChanged(ChannelId, NewCount);
358            }
359        }
360    
361        void Sampler::AddBufferFillListener(BufferFillListener* l) {
362            llBufferFillListeners.AddListener(l);
363        }
364    
365        void Sampler::RemoveBufferFillListener(BufferFillListener* l) {
366            llBufferFillListeners.RemoveListener(l);
367        }
368    
369        void Sampler::fireBufferFillChanged(int ChannelId, String FillData) {
370            for (int i = 0; i < llBufferFillListeners.GetListenerCount(); i++) {
371                llBufferFillListeners.GetListener(i)->BufferFillChanged(ChannelId, FillData);
372            }
373        }
374    
375        void Sampler::AddTotalStreamCountListener(TotalStreamCountListener* l) {
376            llTotalStreamCountListeners.AddListener(l);
377        }
378    
379        void Sampler::RemoveTotalStreamCountListener(TotalStreamCountListener* l) {
380            llTotalStreamCountListeners.RemoveListener(l);
381        }
382    
383        void Sampler::fireTotalStreamCountChanged(int NewCount) {
384            for (int i = 0; i < llTotalStreamCountListeners.GetListenerCount(); i++) {
385                llTotalStreamCountListeners.GetListener(i)->TotalStreamCountChanged(NewCount);
386            }
387        }
388    
389        void Sampler::AddTotalVoiceCountListener(TotalVoiceCountListener* l) {
390            llTotalVoiceCountListeners.AddListener(l);
391        }
392    
393        void Sampler::RemoveTotalVoiceCountListener(TotalVoiceCountListener* l) {
394            llTotalVoiceCountListeners.RemoveListener(l);
395        }
396    
397        void Sampler::fireTotalVoiceCountChanged(int NewCount) {
398            for (int i = 0; i < llTotalVoiceCountListeners.GetListenerCount(); i++) {
399                llTotalVoiceCountListeners.GetListener(i)->TotalVoiceCountChanged(NewCount);
400            }
401        }
402    
403        void Sampler::AddFxSendCountListener(FxSendCountListener* l) {
404            llFxSendCountListeners.AddListener(l);
405        }
406    
407        void Sampler::RemoveFxSendCountListener(FxSendCountListener* l) {
408            llFxSendCountListeners.RemoveListener(l);
409        }
410    
411        void Sampler::fireFxSendCountChanged(int ChannelId, int NewCount) {
412            for (int i = 0; i < llFxSendCountListeners.GetListenerCount(); i++) {
413                llFxSendCountListeners.GetListener(i)->FxSendCountChanged(ChannelId, NewCount);
414            }
415        }
416    
417        void Sampler::EventHandler::EngineToBeChanged(int ChannelId) {
418            // nothing to do here
419        }
420    
421        void Sampler::EventHandler::EngineChanged(int ChannelId) {
422            EngineChannel* engineChannel = pSampler->GetSamplerChannel(ChannelId)->GetEngineChannel();
423            if(engineChannel == NULL) return;
424            engineChannel->AddFxSendCountListener(this);
425        }
426    
427        void Sampler::EventHandler::FxSendCountChanged(int ChannelId, int NewCount) {
428            pSampler->fireFxSendCountChanged(ChannelId, NewCount);
429        }
430    
431    
432      SamplerChannel* Sampler::AddSamplerChannel() {      SamplerChannel* Sampler::AddSamplerChannel() {
433          // if there's no sampler channel yet          // if there's no sampler channel yet
434          if (!mSamplerChannels.size()) {          if (!mSamplerChannels.size()) {
435              SamplerChannel* pChannel = new SamplerChannel(this);              SamplerChannel* pChannel = new SamplerChannel(this);
436              mSamplerChannels[0] = pChannel;              mSamplerChannels[0] = pChannel;
437              LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, 1));              fireChannelAdded(pChannel);
438                fireChannelCountChanged(1);
439                pChannel->AddEngineChangeListener(&eventHandler);
440              return pChannel;              return pChannel;
441          }          }
442    
# Line 222  namespace LinuxSampler { Line 451  namespace LinuxSampler {
451                  // we found an unused index, so insert the new channel there                  // we found an unused index, so insert the new channel there
452                  SamplerChannel* pChannel = new SamplerChannel(this);                  SamplerChannel* pChannel = new SamplerChannel(this);
453                  mSamplerChannels[i] = pChannel;                  mSamplerChannels[i] = pChannel;
454                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i));                  fireChannelAdded(pChannel);
455                    fireChannelCountChanged(SamplerChannels());
456                    pChannel->AddEngineChangeListener(&eventHandler);
457                  return pChannel;                  return pChannel;
458              }              }
459              throw LinuxSamplerException("Internal error: could not find unoccupied sampler channel index.");              throw Exception("Internal error: could not find unoccupied sampler channel index.");
460          }          }
461    
462          // 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
463          SamplerChannel* pChannel = new SamplerChannel(this);          SamplerChannel* pChannel = new SamplerChannel(this);
464          mSamplerChannels[lastIndex + 1] = pChannel;          mSamplerChannels[lastIndex + 1] = pChannel;
465          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, lastIndex + 1));          fireChannelAdded(pChannel);
466            fireChannelCountChanged(SamplerChannels());
467            pChannel->AddEngineChangeListener(&eventHandler);
468          return pChannel;          return pChannel;
469      }      }
470    
# Line 247  namespace LinuxSampler { Line 480  namespace LinuxSampler {
480          SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();          SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();
481          for (; iterChan != mSamplerChannels.end(); iterChan++) {          for (; iterChan != mSamplerChannels.end(); iterChan++) {
482              if (iterChan->second == pSamplerChannel) {              if (iterChan->second == pSamplerChannel) {
483                    fireChannelToBeRemoved(pSamplerChannel);
484                    pSamplerChannel->RemoveAllEngineChangeListeners();
485                  mSamplerChannels.erase(iterChan);                  mSamplerChannels.erase(iterChan);
486                  delete pSamplerChannel;                  delete pSamplerChannel;
487                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, mSamplerChannels.size()));                  fireChannelCountChanged(SamplerChannels());
488                  return;                  return;
489              }              }
490          }          }
# Line 265  namespace LinuxSampler { Line 500  namespace LinuxSampler {
500          return AudioOutputDeviceFactory::AvailableDrivers();          return AudioOutputDeviceFactory::AvailableDrivers();
501      }      }
502    
503      AudioOutputDevice* Sampler::CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) {      std::vector<String> Sampler::AvailableMidiInputDrivers() {
504            return MidiInputDeviceFactory::AvailableDrivers();
505        }
506    
507        std::vector<String> Sampler::AvailableEngineTypes() {
508            return EngineFactory::AvailableEngineTypes();
509        }
510    
511        AudioOutputDevice* Sampler::CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (Exception) {
512          // create new device          // create new device
513          AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters);          AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters);
514    
# Line 277  namespace LinuxSampler { Line 520  namespace LinuxSampler {
520              }              }
521          }          }
522    
523            fireAudioDeviceCountChanged(AudioOutputDevices());
524          return pDevice;          return pDevice;
525      }      }
526    
# Line 296  namespace LinuxSampler { Line 540  namespace LinuxSampler {
540          return mMidiInputDevices;          return mMidiInputDevices;
541      }      }
542    
543      void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException) {      void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception) {
544          AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin();          AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin();
545          for (; iter != mAudioOutputDevices.end(); iter++) {          for (; iter != mAudioOutputDevices.end(); iter++) {
546              if (iter->second == pDevice) {              if (iter->second == pDevice) {
547                  // check if there are still sampler engines connected to this device                  // check if there are still sampler engines connected to this device
548                  for (uint i = 0; i < SamplerChannels(); i++)                  for (uint i = 0; i < SamplerChannels(); i++)
549                      if (GetSamplerChannel(i)->GetAudioOutputDevice() == pDevice) throw LinuxSamplerException("Sampler channel " + ToString(i) + " is still connected to the audio output device.");                      if (GetSamplerChannel(i)->GetAudioOutputDevice() == pDevice) throw Exception("Sampler channel " + ToString(i) + " is still connected to the audio output device.");
550    
551                  // disable device                  // disable device
552                  pDevice->Stop();                  pDevice->Stop();
# Line 312  namespace LinuxSampler { Line 556  namespace LinuxSampler {
556    
557                  // destroy and free device from memory                  // destroy and free device from memory
558                  delete pDevice;                  delete pDevice;
559    
560                    fireAudioDeviceCountChanged(AudioOutputDevices());
561                    break;
562              }              }
563          }          }
564      }      }
565    
566      void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (LinuxSamplerException) {      void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception) {
567          MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin();          MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin();
568          for (; iter != mMidiInputDevices.end(); iter++) {          for (; iter != mMidiInputDevices.end(); iter++) {
569              if (iter->second == pDevice) {              if (iter->second == pDevice) {
570                  // check if there are still sampler engines connected to this device                  // check if there are still sampler engines connected to this device
571                  for (uint i = 0; i < SamplerChannels(); i++)                  for (uint i = 0; i < SamplerChannels(); i++)
572                      if (GetSamplerChannel(i)->GetMidiInputDevice() == pDevice) throw LinuxSamplerException("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.");
573    
574                    fireMidiDeviceToBeDestroyed(pDevice);
575    
576                  // disable device                  // disable device
577                  pDevice->StopListen();                  pDevice->StopListen();
# Line 332  namespace LinuxSampler { Line 581  namespace LinuxSampler {
581    
582                  // destroy and free device from memory                  // destroy and free device from memory
583                  delete pDevice;                  delete pDevice;
584    
585                    fireMidiDeviceCountChanged(MidiInputDevices());
586                    break;
587              }              }
588          }          }
589      }      }
590    
591      MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) {      MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (Exception) {
592          // create new device          // create new device
593          MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this);          MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this);
594    
# Line 348  namespace LinuxSampler { Line 600  namespace LinuxSampler {
600                  }                  }
601          }          }
602    
603            fireMidiDeviceCreated(pDevice);
604            fireMidiDeviceCountChanged(MidiInputDevices());
605          return pDevice;          return pDevice;
606      }      }
607    
608        int Sampler::GetDiskStreamCount() {
609            int count = 0;
610            std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin();
611    
612            for(; it != EngineFactory::EngineInstances().end(); it++) {
613                count += (*it)->DiskStreamCount();
614            }
615    
616            return count;
617        }
618    
619      int Sampler::GetVoiceCount() {      int Sampler::GetVoiceCount() {
620          int count = 0;          int count = 0;
621          std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin();          std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin();
# Line 401  namespace LinuxSampler { Line 666  namespace LinuxSampler {
666              std::cerr << "Sampler::Reset(): Exception occured while trying to delete all audio output devices, exiting.\n" << std::flush;              std::cerr << "Sampler::Reset(): Exception occured while trying to delete all audio output devices, exiting.\n" << std::flush;
667              exit(EXIT_FAILURE);              exit(EXIT_FAILURE);
668          }          }
669    
670            // delete MIDI instrument maps
671            try {
672                MidiInstrumentMapper::RemoveAllMaps();
673            }
674            catch(...) {
675                std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI instrument maps, exiting.\n" << std::flush;
676                exit(EXIT_FAILURE);
677            }
678    
679            // unload all instrument editor DLLs
680            InstrumentEditorFactory::ClosePlugins();
681      }      }
682    
683  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.778  
changed lines
  Added in v.1695

  ViewVC Help
Powered by ViewVC