/[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 730 by iliev, Sat Jul 30 08:18:08 2005 UTC revision 1424 by schoenebeck, Sun Oct 14 22:00:17 2007 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 - 2007 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"
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 47  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          // create new engine channel          // create new engine channel
80          EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType);          EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType);
81          if (!pNewEngineChannel) throw LinuxSamplerException("Unknown engine type");          if (!pNewEngineChannel) throw Exception("Unknown engine type");
82    
83          //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
84          pNewEngineChannel->iSamplerChannelIndex = Index();          pNewEngineChannel->iSamplerChannelIndex = Index();
# Line 70  namespace LinuxSampler { Line 87  namespace LinuxSampler {
87          MidiInputPort* pMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());          MidiInputPort* pMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());
88          // disconnect old engine channel          // disconnect old engine channel
89          if (pEngineChannel) {          if (pEngineChannel) {
90                Engine* engine = pEngineChannel->GetEngine();
91                if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(engine);
92    
93              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);
94              if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();              if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();
95              EngineChannelFactory::Destroy(pEngineChannel);              EngineChannelFactory::Destroy(pEngineChannel);
96    
97                // reconnect engine if it still exists
98                const std::set<Engine*>& engines = EngineFactory::EngineInstances();
99                if (engines.find(engine) != engines.end()) pAudioOutputDevice->Connect(engine);
100          }          }
101    
102          // connect new engine channel          // connect new engine channel
         if (pMidiInputPort) pMidiInputPort->Connect(pNewEngineChannel, GetMidiInputChannel());  
103          if (pAudioOutputDevice) {          if (pAudioOutputDevice) {
104              pNewEngineChannel->Connect(pAudioOutputDevice);              pNewEngineChannel->Connect(pAudioOutputDevice);
105              pAudioOutputDevice->Connect(pNewEngineChannel->GetEngine());              pAudioOutputDevice->Connect(pNewEngineChannel->GetEngine());
106          }          }
107            if (pMidiInputPort) pMidiInputPort->Connect(pNewEngineChannel, GetMidiInputChannel());
108          pEngineChannel = pNewEngineChannel;          pEngineChannel = pNewEngineChannel;
109    
110          // from now on get MIDI device and port from EngineChannel object          // from now on get MIDI device and port from EngineChannel object
# Line 88  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    
119      void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) {      void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) {
120            if(pAudioOutputDevice == pDevice) return;
121    
122          // disconnect old device          // disconnect old device
123          if (pAudioOutputDevice && pEngineChannel) pEngineChannel->DisconnectAudioOutputDevice();          if (pAudioOutputDevice && pEngineChannel) {
124                Engine* engine = pEngineChannel->GetEngine();
125                pAudioOutputDevice->Disconnect(engine);
126    
127                pEngineChannel->DisconnectAudioOutputDevice();
128    
129                // reconnect engine if it still exists
130                const std::set<Engine*>& engines = EngineFactory::EngineInstances();
131                if (engines.find(engine) != engines.end()) pAudioOutputDevice->Connect(engine);
132            }
133    
134          // connect new device          // connect new device
135          pAudioOutputDevice = pDevice;          pAudioOutputDevice = pDevice;
136          if (pEngineChannel) {          if (pEngineChannel) {
# Line 116  namespace LinuxSampler { Line 152  namespace LinuxSampler {
152      }      }
153    
154      void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel) {      void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel) {
155          if (!pDevice) throw LinuxSamplerException("No MIDI input device assigned.");          if (!pDevice) throw Exception("No MIDI input device assigned.");
156    
157          // get old and new midi input port          // get old and new midi input port
158          MidiInputPort* pOldMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());          MidiInputPort* pOldMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());
# Line 135  namespace LinuxSampler { Line 171  namespace LinuxSampler {
171          if (pNewMidiInputPort && pEngineChannel) pNewMidiInputPort->Connect(pEngineChannel, MidiChannel);          if (pNewMidiInputPort && pEngineChannel) pNewMidiInputPort->Connect(pEngineChannel, MidiChannel);
172          // Ooops.          // Ooops.
173          if (pNewMidiInputPort == NULL)          if (pNewMidiInputPort == NULL)
174              throw LinuxSamplerException("There is no MIDI input port with index " + ToString(iMidiPort) + ".");              throw Exception("There is no MIDI input port with index " + ToString(iMidiPort) + ".");
175      }      }
176    
177      EngineChannel* SamplerChannel::GetEngineChannel() {      EngineChannel* SamplerChannel::GetEngineChannel() {
# Line 174  namespace LinuxSampler { Line 210  namespace LinuxSampler {
210              }              }
211          }          }
212    
213          throw LinuxSamplerException("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) {
# Line 191  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 201  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::AddTotalVoiceCountListener(TotalVoiceCountListener* l) {
344            llTotalVoiceCountListeners.AddListener(l);
345        }
346    
347        void Sampler::RemoveTotalVoiceCountListener(TotalVoiceCountListener* l) {
348            llTotalVoiceCountListeners.RemoveListener(l);
349        }
350    
351        void Sampler::fireTotalVoiceCountChanged(int NewCount) {
352            for (int i = 0; i < llTotalVoiceCountListeners.GetListenerCount(); i++) {
353                llTotalVoiceCountListeners.GetListener(i)->TotalVoiceCountChanged(NewCount);
354            }
355        }
356    
357        void Sampler::AddFxSendCountListener(FxSendCountListener* l) {
358            llFxSendCountListeners.AddListener(l);
359        }
360    
361        void Sampler::RemoveFxSendCountListener(FxSendCountListener* l) {
362            llFxSendCountListeners.RemoveListener(l);
363        }
364    
365        void Sampler::fireFxSendCountChanged(int ChannelId, int NewCount) {
366            for (int i = 0; i < llFxSendCountListeners.GetListenerCount(); i++) {
367                llFxSendCountListeners.GetListener(i)->FxSendCountChanged(ChannelId, NewCount);
368            }
369        }
370    
371        void Sampler::EventHandler::EngineChanged(int ChannelId) {
372            EngineChannel* engineChannel = pSampler->GetSamplerChannel(ChannelId)->GetEngineChannel();
373            if(engineChannel == NULL) return;
374            engineChannel->AddFxSendCountListener(this);
375        }
376    
377        void Sampler::EventHandler::FxSendCountChanged(int ChannelId, int NewCount) {
378            pSampler->fireFxSendCountChanged(ChannelId, NewCount);
379        }
380    
381    
382      SamplerChannel* Sampler::AddSamplerChannel() {      SamplerChannel* Sampler::AddSamplerChannel() {
383          // if there's no sampler channel yet          // if there's no sampler channel yet
384          if (!mSamplerChannels.size()) {          if (!mSamplerChannels.size()) {
385              SamplerChannel* pChannel = new SamplerChannel(this);              SamplerChannel* pChannel = new SamplerChannel(this);
386              mSamplerChannels[0] = pChannel;              mSamplerChannels[0] = pChannel;
387              LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, 1));              fireChannelCountChanged(1);
388                pChannel->AddEngineChangeListener(&eventHandler);
389              return pChannel;              return pChannel;
390          }          }
391    
# Line 221  namespace LinuxSampler { Line 400  namespace LinuxSampler {
400                  // we found an unused index, so insert the new channel there                  // we found an unused index, so insert the new channel there
401                  SamplerChannel* pChannel = new SamplerChannel(this);                  SamplerChannel* pChannel = new SamplerChannel(this);
402                  mSamplerChannels[i] = pChannel;                  mSamplerChannels[i] = pChannel;
403                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i));                  fireChannelCountChanged(SamplerChannels());
404                    pChannel->AddEngineChangeListener(&eventHandler);
405                  return pChannel;                  return pChannel;
406              }              }
407              throw LinuxSamplerException("Internal error: could not find unoccupied sampler channel index.");              throw Exception("Internal error: could not find unoccupied sampler channel index.");
408          }          }
409    
410          // 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
411          SamplerChannel* pChannel = new SamplerChannel(this);          SamplerChannel* pChannel = new SamplerChannel(this);
412          mSamplerChannels[lastIndex + 1] = pChannel;          mSamplerChannels[lastIndex + 1] = pChannel;
413          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, lastIndex + 1));          fireChannelCountChanged(SamplerChannels());
414            pChannel->AddEngineChangeListener(&eventHandler);
415          return pChannel;          return pChannel;
416      }      }
417    
# Line 246  namespace LinuxSampler { Line 427  namespace LinuxSampler {
427          SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();          SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();
428          for (; iterChan != mSamplerChannels.end(); iterChan++) {          for (; iterChan != mSamplerChannels.end(); iterChan++) {
429              if (iterChan->second == pSamplerChannel) {              if (iterChan->second == pSamplerChannel) {
430                    pSamplerChannel->RemoveAllEngineChangeListeners();
431                  mSamplerChannels.erase(iterChan);                  mSamplerChannels.erase(iterChan);
432                  delete pSamplerChannel;                  delete pSamplerChannel;
433                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, mSamplerChannels.size()));                  fireChannelCountChanged(SamplerChannels());
434                  return;                  return;
435              }              }
436          }          }
# Line 264  namespace LinuxSampler { Line 446  namespace LinuxSampler {
446          return AudioOutputDeviceFactory::AvailableDrivers();          return AudioOutputDeviceFactory::AvailableDrivers();
447      }      }
448    
449      AudioOutputDevice* Sampler::CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) {      std::vector<String> Sampler::AvailableMidiInputDrivers() {
450            return MidiInputDeviceFactory::AvailableDrivers();
451        }
452    
453        std::vector<String> Sampler::AvailableEngineTypes() {
454            return EngineFactory::AvailableEngineTypes();
455        }
456    
457        AudioOutputDevice* Sampler::CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (Exception) {
458          // create new device          // create new device
459          AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters);          AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters);
460    
# Line 276  namespace LinuxSampler { Line 466  namespace LinuxSampler {
466              }              }
467          }          }
468    
469            fireAudioDeviceCountChanged(AudioOutputDevices());
470          return pDevice;          return pDevice;
471      }      }
472    
# Line 295  namespace LinuxSampler { Line 486  namespace LinuxSampler {
486          return mMidiInputDevices;          return mMidiInputDevices;
487      }      }
488    
489      void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException) {      void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception) {
490          AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin();          AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin();
491          for (; iter != mAudioOutputDevices.end(); iter++) {          for (; iter != mAudioOutputDevices.end(); iter++) {
492              if (iter->second == pDevice) {              if (iter->second == pDevice) {
493                  // check if there are still sampler engines connected to this device                  // check if there are still sampler engines connected to this device
494                  for (uint i = 0; i < SamplerChannels(); i++)                  for (uint i = 0; i < SamplerChannels(); i++)
495                      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.");
496    
497                  // disable device                  // disable device
498                  pDevice->Stop();                  pDevice->Stop();
# Line 311  namespace LinuxSampler { Line 502  namespace LinuxSampler {
502    
503                  // destroy and free device from memory                  // destroy and free device from memory
504                  delete pDevice;                  delete pDevice;
505    
506                    fireAudioDeviceCountChanged(AudioOutputDevices());
507                    break;
508              }              }
509          }          }
510      }      }
511    
512      void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (LinuxSamplerException) {      void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception) {
513          MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin();          MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin();
514          for (; iter != mMidiInputDevices.end(); iter++) {          for (; iter != mMidiInputDevices.end(); iter++) {
515              if (iter->second == pDevice) {              if (iter->second == pDevice) {
516                  // check if there are still sampler engines connected to this device                  // check if there are still sampler engines connected to this device
517                  for (uint i = 0; i < SamplerChannels(); i++)                  for (uint i = 0; i < SamplerChannels(); i++)
518                      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.");
519    
520                  // disable device                  // disable device
521                  pDevice->StopListen();                  pDevice->StopListen();
# Line 331  namespace LinuxSampler { Line 525  namespace LinuxSampler {
525    
526                  // destroy and free device from memory                  // destroy and free device from memory
527                  delete pDevice;                  delete pDevice;
528    
529                    fireMidiDeviceCountChanged(MidiInputDevices());
530                    break;
531              }              }
532          }          }
533      }      }
534    
535      MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) {      MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (Exception) {
536          // create new device          // create new device
537          MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this);          MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this);
538    
# Line 347  namespace LinuxSampler { Line 544  namespace LinuxSampler {
544                  }                  }
545          }          }
546    
547            fireMidiDeviceCountChanged(MidiInputDevices());
548          return pDevice;          return pDevice;
549      }      }
550    
551        int Sampler::GetVoiceCount() {
552            int count = 0;
553            std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin();
554    
555            for(; it != EngineFactory::EngineInstances().end(); it++) {
556                count += (*it)->VoiceCount();
557            }
558    
559            return count;
560        }
561    
562      void Sampler::Reset() {      void Sampler::Reset() {
563          // delete sampler channels          // delete sampler channels
564          try {          try {
# Line 389  namespace LinuxSampler { Line 598  namespace LinuxSampler {
598              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;
599              exit(EXIT_FAILURE);              exit(EXIT_FAILURE);
600          }          }
601    
602            // delete MIDI instrument maps
603            try {
604                MidiInstrumentMapper::RemoveAllMaps();
605            }
606            catch(...) {
607                std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI instrument maps, exiting.\n" << std::flush;
608                exit(EXIT_FAILURE);
609            }
610    
611            // unload all instrument editor DLLs
612            InstrumentEditorFactory::ClosePlugins();
613      }      }
614    
615  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.730  
changed lines
  Added in v.1424

  ViewVC Help
Powered by ViewVC