/[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 556 by schoenebeck, Sat May 21 01:10:12 2005 UTC revision 1130 by iliev, Sun Mar 25 18:59:14 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 "engines/EngineFactory.h"
29  #include "engines/EngineChannelFactory.h"  #include "engines/EngineChannelFactory.h"
30  #include "drivers/audio/AudioOutputDeviceFactory.h"  #include "drivers/audio/AudioOutputDeviceFactory.h"
31  #include "drivers/midi/MidiInputDeviceFactory.h"  #include "drivers/midi/MidiInputDeviceFactory.h"
32  #include "network/lscpserver.h"  #include "drivers/midi/MidiInstrumentMapper.h"
33    
34  namespace LinuxSampler {  namespace LinuxSampler {
35    
# Line 38  namespace LinuxSampler { Line 39  namespace LinuxSampler {
39      SamplerChannel::SamplerChannel(Sampler* pS) {      SamplerChannel::SamplerChannel(Sampler* pS) {
40          pSampler           = pS;          pSampler           = pS;
41          pEngineChannel     = NULL;          pEngineChannel     = NULL;
         pMidiInputDevice   = NULL;  
42          pAudioOutputDevice = NULL;          pAudioOutputDevice = NULL;
43          midiPort           = 0;          pMidiInputDevice   = NULL;
44          midiChannel        = MidiInputPort::midi_chan_all;          iMidiPort          = 0;
45            midiChannel        = midi_chan_all;
46          iIndex             = -1;          iIndex             = -1;
47      }      }
48    
49      SamplerChannel::~SamplerChannel() {      SamplerChannel::~SamplerChannel() {
50          if (pEngineChannel) {          if (pEngineChannel) {
51              MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);              Engine* engine = pEngineChannel->GetEngine();
52                if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(engine);
53    
54                MidiInputPort* pMidiInputPort = (pEngineChannel) ? pEngineChannel->GetMidiInputPort() : __GetMidiInputDevicePort(GetMidiInputChannel());
55              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);
56              if (pEngineChannel) {              if (pEngineChannel) {
57                  if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();                  if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();
58                  delete pEngineChannel;                  EngineChannelFactory::Destroy(pEngineChannel);
59    
60                    // reconnect engine if it still exists
61                    const std::set<Engine*>& engines = EngineFactory::EngineInstances();
62                    if (engines.find(engine) != engines.end()) pAudioOutputDevice->Connect(engine);
63              }              }
64          }          }
65      }      }
66    
67      void SamplerChannel::SetEngineType(String EngineType) throw (LinuxSamplerException) {      void SamplerChannel::SetEngineType(String EngineType) throw (Exception) {
68          dmsg(2,("SamplerChannel: Assigning engine type..."));          dmsg(2,("SamplerChannel: Assigning engine type..."));
69    
70          // create new engine channel          // create new engine channel
71          EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType);          EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType);
72          if (!pNewEngineChannel) throw LinuxSamplerException("Unknown engine type");          if (!pNewEngineChannel) throw Exception("Unknown engine type");
73    
74            //FIXME: hack to allow fast retrieval of engine channel's sampler channel index
75            pNewEngineChannel->iSamplerChannelIndex = Index();
76    
77          // dereference midi input port.          // dereference midi input port.
78          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          MidiInputPort* pMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());
79          // disconnect old engine          // disconnect old engine channel
80          if (pEngineChannel) {          if (pEngineChannel) {
81                Engine* engine = pEngineChannel->GetEngine();
82                if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(engine);
83    
84              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);
85              if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();              if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();
86              delete pEngineChannel;              EngineChannelFactory::Destroy(pEngineChannel);
87    
88                // reconnect engine if it still exists
89                const std::set<Engine*>& engines = EngineFactory::EngineInstances();
90                if (engines.find(engine) != engines.end()) pAudioOutputDevice->Connect(engine);
91          }          }
92    
93          // connect new engine channel          // connect new engine channel
         pEngineChannel = pNewEngineChannel;  
         if (pMidiInputPort) pMidiInputPort->Connect(pNewEngineChannel, this->midiChannel);  
94          if (pAudioOutputDevice) {          if (pAudioOutputDevice) {
95              pNewEngineChannel->Connect(pAudioOutputDevice);              pNewEngineChannel->Connect(pAudioOutputDevice);
96              pAudioOutputDevice->Connect(pNewEngineChannel->GetEngine());              pAudioOutputDevice->Connect(pNewEngineChannel->GetEngine());
97          }          }
98            if (pMidiInputPort) pMidiInputPort->Connect(pNewEngineChannel, GetMidiInputChannel());
99            pEngineChannel = pNewEngineChannel;
100    
101            // from now on get MIDI device and port from EngineChannel object
102            this->pMidiInputDevice = NULL;
103            this->iMidiPort        = 0;
104    
105            pEngineChannel->StatusChanged(true);
106            fireEngineChanged();
107          dmsg(2,("OK\n"));          dmsg(2,("OK\n"));
108      }      }
109    
110      void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) {      void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) {
111            if(pAudioOutputDevice == pDevice) return;
112    
113          // disconnect old device          // disconnect old device
114          if (pAudioOutputDevice && pEngineChannel) pEngineChannel->DisconnectAudioOutputDevice();          if (pAudioOutputDevice && pEngineChannel) {
115                Engine* engine = pEngineChannel->GetEngine();
116                pAudioOutputDevice->Disconnect(engine);
117    
118                pEngineChannel->DisconnectAudioOutputDevice();
119    
120                // reconnect engine if it still exists
121                const std::set<Engine*>& engines = EngineFactory::EngineInstances();
122                if (engines.find(engine) != engines.end()) pAudioOutputDevice->Connect(engine);
123            }
124    
125          // connect new device          // connect new device
126          pAudioOutputDevice = pDevice;          pAudioOutputDevice = pDevice;
127          if (pEngineChannel) {          if (pEngineChannel) {
# Line 94  namespace LinuxSampler { Line 131  namespace LinuxSampler {
131      }      }
132    
133      void SamplerChannel::SetMidiInputDevice(MidiInputDevice* pDevice) {      void SamplerChannel::SetMidiInputDevice(MidiInputDevice* pDevice) {
134         SetMidiInput(pDevice, this->midiPort, this->midiChannel);         SetMidiInput(pDevice, 0, GetMidiInputChannel());
135      }      }
136    
137      void SamplerChannel::SetMidiInputPort(int MidiPort) {      void SamplerChannel::SetMidiInputPort(int MidiPort) {
138         SetMidiInput(pMidiInputDevice, MidiPort, this->midiChannel);         SetMidiInput(GetMidiInputDevice(), MidiPort, GetMidiInputChannel());
139      }      }
140    
141      void SamplerChannel::SetMidiInputChannel(MidiInputPort::midi_chan_t MidiChannel) {      void SamplerChannel::SetMidiInputChannel(midi_chan_t MidiChannel) {
142         SetMidiInput(pMidiInputDevice, this->midiPort, MidiChannel);         SetMidiInput(GetMidiInputDevice(), GetMidiInputPort(), MidiChannel);
143      }      }
144    
145      void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, MidiInputPort::midi_chan_t MidiChannel) {      void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel) {
146          // dereference old midi input port.          if (!pDevice) throw Exception("No MIDI input device assigned.");
147          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);  
148            // get old and new midi input port
149            MidiInputPort* pOldMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());
150            MidiInputPort* pNewMidiInputPort = pDevice->GetPort(iMidiPort);
151    
152          // disconnect old device port          // disconnect old device port
153          if (pMidiInputPort && pEngineChannel) pMidiInputPort->Disconnect(pEngineChannel);          if (pOldMidiInputPort && pEngineChannel) pOldMidiInputPort->Disconnect(pEngineChannel);
154          // new device, port and channel          // remember new device, port and channel if not engine channel yet created
155          pMidiInputDevice = pDevice;          if (!pEngineChannel) {
156          this->midiPort = iMidiPort;              this->pMidiInputDevice = pDevice;
157          this->midiChannel = MidiChannel;              this->iMidiPort        = iMidiPort;
158                this->midiChannel      = MidiChannel;
159            }
160    
161          // connect new device port          // connect new device port
162          pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          if (pNewMidiInputPort && pEngineChannel) pNewMidiInputPort->Connect(pEngineChannel, MidiChannel);
         if (pMidiInputPort && pEngineChannel) pMidiInputPort->Connect(pEngineChannel, MidiChannel);  
163          // Ooops.          // Ooops.
164          if (pMidiInputPort == NULL)          if (pNewMidiInputPort == NULL)
165              throw LinuxSamplerException("There is no MIDI input port with index " + ToString(iMidiPort) + ".");              throw Exception("There is no MIDI input port with index " + ToString(iMidiPort) + ".");
166      }      }
167    
168      EngineChannel* SamplerChannel::GetEngineChannel() {      EngineChannel* SamplerChannel::GetEngineChannel() {
169          return pEngineChannel;          return pEngineChannel;
170      }      }
171    
172      MidiInputPort::midi_chan_t SamplerChannel::GetMidiInputChannel() {      midi_chan_t SamplerChannel::GetMidiInputChannel() {
173            if (pEngineChannel) this->midiChannel = pEngineChannel->MidiChannel();
174          return this->midiChannel;          return this->midiChannel;
175      }      }
176    
177      int SamplerChannel::GetMidiInputPort() {      int SamplerChannel::GetMidiInputPort() {
178          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          MidiInputPort* pMidiInputPort = (pEngineChannel) ? pEngineChannel->GetMidiInputPort() : NULL;
179          return (pMidiInputPort ? (int) pMidiInputPort->GetPortNumber() : -1);          if (pMidiInputPort) this->iMidiPort = (int) pMidiInputPort->GetPortNumber();
180            return iMidiPort;
181      }      }
182    
183      AudioOutputDevice* SamplerChannel::GetAudioOutputDevice() {      AudioOutputDevice* SamplerChannel::GetAudioOutputDevice() {
# Line 140  namespace LinuxSampler { Line 185  namespace LinuxSampler {
185      }      }
186    
187      MidiInputDevice* SamplerChannel::GetMidiInputDevice() {      MidiInputDevice* SamplerChannel::GetMidiInputDevice() {
188            if (pEngineChannel)
189                pMidiInputDevice = (pEngineChannel->GetMidiInputPort()) ? pEngineChannel->GetMidiInputPort()->GetDevice() : NULL;
190          return pMidiInputDevice;          return pMidiInputDevice;
191      }      }
192    
# Line 154  namespace LinuxSampler { Line 201  namespace LinuxSampler {
201              }              }
202          }          }
203    
204          throw LinuxSamplerException("Internal error: SamplerChannel index not found");          throw Exception("Internal error: SamplerChannel index not found");
205        }
206    
207        void SamplerChannel::AddEngineChangeListener(EngineChangeListener* l) {
208            llEngineChangeListeners.AddListener(l);
209        }
210    
211        void SamplerChannel::RemoveEngineChangeListener(EngineChangeListener* l) {
212           llEngineChangeListeners.RemoveListener(l);
213        }
214    
215        void SamplerChannel::RemoveAllEngineChangeListeners() {
216           llEngineChangeListeners.RemoveAllListeners();
217        }
218    
219        void SamplerChannel::fireEngineChanged() {
220            for (int i = 0; i < llEngineChangeListeners.GetListenerCount(); i++) {
221                llEngineChangeListeners.GetListener(i)->EngineChanged(Index());
222            }
223      }      }
224    
225      MidiInputPort* SamplerChannel::GetMidiInputDevicePort(int iMidiPort) {      MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) {
226          MidiInputPort* pMidiInputPort = NULL;          MidiInputPort* pMidiInputPort = NULL;
227            MidiInputDevice* pMidiInputDevice = GetMidiInputDevice();
228          if (pMidiInputDevice)          if (pMidiInputDevice)
229              pMidiInputPort = pMidiInputDevice->GetPort(iMidiPort);              pMidiInputPort = pMidiInputDevice->GetPort(iMidiPort);
230          return pMidiInputPort;          return pMidiInputPort;
# Line 170  namespace LinuxSampler { Line 236  namespace LinuxSampler {
236      // * Sampler      // * Sampler
237    
238      Sampler::Sampler() {      Sampler::Sampler() {
239            eventHandler.SetSampler(this);
240      }      }
241    
242      Sampler::~Sampler() {      Sampler::~Sampler() {
# Line 180  namespace LinuxSampler { Line 247  namespace LinuxSampler {
247          return mSamplerChannels.size();          return mSamplerChannels.size();
248      }      }
249    
250        void Sampler::AddChannelCountListener(ChannelCountListener* l) {
251            llChannelCountListeners.AddListener(l);
252        }
253    
254        void Sampler::RemoveChannelCountListener(ChannelCountListener* l) {
255           llChannelCountListeners.RemoveListener(l);
256        }
257    
258        void Sampler::fireChannelCountChanged(int NewCount) {
259            for (int i = 0; i < llChannelCountListeners.GetListenerCount(); i++) {
260                llChannelCountListeners.GetListener(i)->ChannelCountChanged(NewCount);
261            }
262        }
263    
264        void Sampler::AddAudioDeviceCountListener(AudioDeviceCountListener* l) {
265            llAudioDeviceCountListeners.AddListener(l);
266        }
267    
268        void Sampler::RemoveAudioDeviceCountListener(AudioDeviceCountListener* l) {
269            llAudioDeviceCountListeners.RemoveListener(l);
270        }
271    
272        void Sampler::fireAudioDeviceCountChanged(int NewCount) {
273            for (int i = 0; i < llAudioDeviceCountListeners.GetListenerCount(); i++) {
274                llAudioDeviceCountListeners.GetListener(i)->AudioDeviceCountChanged(NewCount);
275            }
276        }
277    
278        void Sampler::AddMidiDeviceCountListener(MidiDeviceCountListener* l) {
279            llMidiDeviceCountListeners.AddListener(l);
280        }
281    
282        void Sampler::RemoveMidiDeviceCountListener(MidiDeviceCountListener* l) {
283            llMidiDeviceCountListeners.RemoveListener(l);
284        }
285    
286        void Sampler::fireMidiDeviceCountChanged(int NewCount) {
287            for (int i = 0; i < llMidiDeviceCountListeners.GetListenerCount(); i++) {
288                llMidiDeviceCountListeners.GetListener(i)->MidiDeviceCountChanged(NewCount);
289            }
290        }
291    
292        void Sampler::AddVoiceCountListener(VoiceCountListener* l) {
293            llVoiceCountListeners.AddListener(l);
294        }
295    
296        void Sampler::RemoveVoiceCountListener(VoiceCountListener* l) {
297            llVoiceCountListeners.RemoveListener(l);
298        }
299    
300        void Sampler::fireVoiceCountChanged(int ChannelId, int NewCount) {
301            for (int i = 0; i < llVoiceCountListeners.GetListenerCount(); i++) {
302                llVoiceCountListeners.GetListener(i)->VoiceCountChanged(ChannelId, NewCount);
303            }
304        }
305    
306        void Sampler::AddStreamCountListener(StreamCountListener* l) {
307            llStreamCountListeners.AddListener(l);
308        }
309    
310        void Sampler::RemoveStreamCountListener(StreamCountListener* l) {
311            llStreamCountListeners.RemoveListener(l);
312        }
313    
314        void Sampler::fireStreamCountChanged(int ChannelId, int NewCount) {
315            for (int i = 0; i < llStreamCountListeners.GetListenerCount(); i++) {
316                llStreamCountListeners.GetListener(i)->StreamCountChanged(ChannelId, NewCount);
317            }
318        }
319    
320        void Sampler::AddBufferFillListener(BufferFillListener* l) {
321            llBufferFillListeners.AddListener(l);
322        }
323    
324        void Sampler::RemoveBufferFillListener(BufferFillListener* l) {
325            llBufferFillListeners.RemoveListener(l);
326        }
327    
328        void Sampler::fireBufferFillChanged(int ChannelId, String FillData) {
329            for (int i = 0; i < llBufferFillListeners.GetListenerCount(); i++) {
330                llBufferFillListeners.GetListener(i)->BufferFillChanged(ChannelId, FillData);
331            }
332        }
333    
334        void Sampler::AddTotalVoiceCountListener(TotalVoiceCountListener* l) {
335            llTotalVoiceCountListeners.AddListener(l);
336        }
337    
338        void Sampler::RemoveTotalVoiceCountListener(TotalVoiceCountListener* l) {
339            llTotalVoiceCountListeners.RemoveListener(l);
340        }
341    
342        void Sampler::fireTotalVoiceCountChanged(int NewCount) {
343            for (int i = 0; i < llTotalVoiceCountListeners.GetListenerCount(); i++) {
344                llTotalVoiceCountListeners.GetListener(i)->TotalVoiceCountChanged(NewCount);
345            }
346        }
347    
348        void Sampler::AddFxSendCountListener(FxSendCountListener* l) {
349            llFxSendCountListeners.AddListener(l);
350        }
351    
352        void Sampler::RemoveFxSendCountListener(FxSendCountListener* l) {
353            llFxSendCountListeners.RemoveListener(l);
354        }
355    
356        void Sampler::fireFxSendCountChanged(int ChannelId, int NewCount) {
357            for (int i = 0; i < llFxSendCountListeners.GetListenerCount(); i++) {
358                llFxSendCountListeners.GetListener(i)->FxSendCountChanged(ChannelId, NewCount);
359            }
360        }
361    
362        void Sampler::EventHandler::EngineChanged(int ChannelId) {
363            EngineChannel* engineChannel = pSampler->GetSamplerChannel(ChannelId)->GetEngineChannel();
364            if(engineChannel == NULL) return;
365            engineChannel->AddFxSendCountListener(this);
366        }
367    
368        void Sampler::EventHandler::FxSendCountChanged(int ChannelId, int NewCount) {
369            pSampler->fireFxSendCountChanged(ChannelId, NewCount);
370        }
371    
372    
373      SamplerChannel* Sampler::AddSamplerChannel() {      SamplerChannel* Sampler::AddSamplerChannel() {
374          // if there's no sampler channel yet          // if there's no sampler channel yet
375          if (!mSamplerChannels.size()) {          if (!mSamplerChannels.size()) {
376              SamplerChannel* pChannel = new SamplerChannel(this);              SamplerChannel* pChannel = new SamplerChannel(this);
377              mSamplerChannels[0] = pChannel;              mSamplerChannels[0] = pChannel;
378              LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, 1));              fireChannelCountChanged(1);
379                pChannel->AddEngineChangeListener(&eventHandler);
380              return pChannel;              return pChannel;
381          }          }
382    
# Line 200  namespace LinuxSampler { Line 391  namespace LinuxSampler {
391                  // we found an unused index, so insert the new channel there                  // we found an unused index, so insert the new channel there
392                  SamplerChannel* pChannel = new SamplerChannel(this);                  SamplerChannel* pChannel = new SamplerChannel(this);
393                  mSamplerChannels[i] = pChannel;                  mSamplerChannels[i] = pChannel;
394                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i));                  fireChannelCountChanged(SamplerChannels());
395                    pChannel->AddEngineChangeListener(&eventHandler);
396                  return pChannel;                  return pChannel;
397              }              }
398              throw LinuxSamplerException("Internal error: could not find unoccupied sampler channel index.");              throw Exception("Internal error: could not find unoccupied sampler channel index.");
399          }          }
400    
401          // 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
402          SamplerChannel* pChannel = new SamplerChannel(this);          SamplerChannel* pChannel = new SamplerChannel(this);
403          mSamplerChannels[lastIndex + 1] = pChannel;          mSamplerChannels[lastIndex + 1] = pChannel;
404          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, lastIndex + 1));          fireChannelCountChanged(SamplerChannels());
405            pChannel->AddEngineChangeListener(&eventHandler);
406          return pChannel;          return pChannel;
407      }      }
408    
# Line 225  namespace LinuxSampler { Line 418  namespace LinuxSampler {
418          SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();          SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();
419          for (; iterChan != mSamplerChannels.end(); iterChan++) {          for (; iterChan != mSamplerChannels.end(); iterChan++) {
420              if (iterChan->second == pSamplerChannel) {              if (iterChan->second == pSamplerChannel) {
421                    pSamplerChannel->RemoveAllEngineChangeListeners();
422                  mSamplerChannels.erase(iterChan);                  mSamplerChannels.erase(iterChan);
423                  delete pSamplerChannel;                  delete pSamplerChannel;
424                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, mSamplerChannels.size()));                  fireChannelCountChanged(SamplerChannels());
425                  return;                  return;
426              }              }
427          }          }
# Line 243  namespace LinuxSampler { Line 437  namespace LinuxSampler {
437          return AudioOutputDeviceFactory::AvailableDrivers();          return AudioOutputDeviceFactory::AvailableDrivers();
438      }      }
439    
440      AudioOutputDevice* Sampler::CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) {      std::vector<String> Sampler::AvailableMidiInputDrivers() {
441            return MidiInputDeviceFactory::AvailableDrivers();
442        }
443    
444        std::vector<String> Sampler::AvailableEngineTypes() {
445            return EngineFactory::AvailableEngineTypes();
446        }
447    
448        AudioOutputDevice* Sampler::CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (Exception) {
449          // create new device          // create new device
450          AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters);          AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters);
451    
# Line 255  namespace LinuxSampler { Line 457  namespace LinuxSampler {
457              }              }
458          }          }
459    
460            fireAudioDeviceCountChanged(AudioOutputDevices());
461          return pDevice;          return pDevice;
462      }      }
463    
# Line 274  namespace LinuxSampler { Line 477  namespace LinuxSampler {
477          return mMidiInputDevices;          return mMidiInputDevices;
478      }      }
479    
480      void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException) {      void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception) {
481          AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin();          AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin();
482          for (; iter != mAudioOutputDevices.end(); iter++) {          for (; iter != mAudioOutputDevices.end(); iter++) {
483              if (iter->second == pDevice) {              if (iter->second == pDevice) {
484                  // check if there are still sampler engines connected to this device                  // check if there are still sampler engines connected to this device
485                  for (uint i = 0; i < SamplerChannels(); i++)                  for (uint i = 0; i < SamplerChannels(); i++)
486                      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.");
487    
488                  // disable device                  // disable device
489                  pDevice->Stop();                  pDevice->Stop();
# Line 290  namespace LinuxSampler { Line 493  namespace LinuxSampler {
493    
494                  // destroy and free device from memory                  // destroy and free device from memory
495                  delete pDevice;                  delete pDevice;
496    
497                    fireAudioDeviceCountChanged(AudioOutputDevices());
498                    break;
499              }              }
500          }          }
501      }      }
502    
503      void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (LinuxSamplerException) {      void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception) {
504          MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin();          MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin();
505          for (; iter != mMidiInputDevices.end(); iter++) {          for (; iter != mMidiInputDevices.end(); iter++) {
506              if (iter->second == pDevice) {              if (iter->second == pDevice) {
507                  // check if there are still sampler engines connected to this device                  // check if there are still sampler engines connected to this device
508                  for (uint i = 0; i < SamplerChannels(); i++)                  for (uint i = 0; i < SamplerChannels(); i++)
509                      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.");
510    
511                  // disable device                  // disable device
512                  pDevice->StopListen();                  pDevice->StopListen();
# Line 310  namespace LinuxSampler { Line 516  namespace LinuxSampler {
516    
517                  // destroy and free device from memory                  // destroy and free device from memory
518                  delete pDevice;                  delete pDevice;
519    
520                    fireMidiDeviceCountChanged(MidiInputDevices());
521                    break;
522              }              }
523          }          }
524      }      }
525    
526      MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) {      MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (Exception) {
527          // create new device          // create new device
528          MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this);          MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this);
529    
# Line 326  namespace LinuxSampler { Line 535  namespace LinuxSampler {
535                  }                  }
536          }          }
537    
538            fireMidiDeviceCountChanged(MidiInputDevices());
539          return pDevice;          return pDevice;
540      }      }
541    
542        int Sampler::GetVoiceCount() {
543            int count = 0;
544            std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin();
545    
546            for(; it != EngineFactory::EngineInstances().end(); it++) {
547                count += (*it)->VoiceCount();
548            }
549    
550            return count;
551        }
552    
553      void Sampler::Reset() {      void Sampler::Reset() {
554          // delete sampler channels          // delete sampler channels
555          try {          try {
# Line 368  namespace LinuxSampler { Line 589  namespace LinuxSampler {
589              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;
590              exit(EXIT_FAILURE);              exit(EXIT_FAILURE);
591          }          }
592    
593            // delete MIDI instrument maps
594            try {
595                MidiInstrumentMapper::RemoveAllMaps();
596            }
597            catch(...) {
598                std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI instrument maps, exiting.\n" << std::flush;
599                exit(EXIT_FAILURE);
600            }
601      }      }
602    
603  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.556  
changed lines
  Added in v.1130

  ViewVC Help
Powered by ViewVC