/[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 159 by capela, Tue Jun 29 21:11:50 2004 UTC revision 981 by iliev, Sun Dec 17 22:35:01 2006 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, 2006 Christian Schoenebeck                        *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 24  Line 25 
25    
26  #include "Sampler.h"  #include "Sampler.h"
27    
28  #include "audiodriver/AudioOutputDeviceFactory.h"  #include "engines/EngineFactory.h"
29  #include "mididriver/MidiInputDeviceFactory.h"  #include "engines/EngineChannelFactory.h"
30  #include "engines/gig/Engine.h"  #include "drivers/audio/AudioOutputDeviceFactory.h"
31    #include "drivers/midi/MidiInputDeviceFactory.h"
32    #include "network/lscpserver.h"
33    
34  namespace LinuxSampler {  namespace LinuxSampler {
35    
# Line 35  namespace LinuxSampler { Line 38  namespace LinuxSampler {
38    
39      SamplerChannel::SamplerChannel(Sampler* pS) {      SamplerChannel::SamplerChannel(Sampler* pS) {
40          pSampler           = pS;          pSampler           = pS;
41          pEngine            = NULL;          pEngineChannel     = NULL;
         pMidiInputDevice   = NULL;  
42          pAudioOutputDevice = NULL;          pAudioOutputDevice = NULL;
43          midiPort           = 0;          pMidiInputDevice   = NULL;
44          midiChannel        = MidiInputDevice::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 (pEngine) {          if (pEngineChannel) {
51              MidiInputDevice::MidiInputPort *pMidiInputPort = GetMidiInputDevicePort(this->midiPort);              Engine* engine = pEngineChannel->GetEngine();
52              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngine);              if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(engine);
53              if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(pEngine);  
54              delete pEngine;              MidiInputPort* pMidiInputPort = (pEngineChannel) ? pEngineChannel->GetMidiInputPort() : __GetMidiInputDevicePort(GetMidiInputChannel());
55                if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);
56                if (pEngineChannel) {
57                    if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();
58                    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::LoadEngine(Engine::type_t EngineType) {      void SamplerChannel::SetEngineType(String EngineType) throw (Exception) {
68          dmsg(2,("SamplerChannel: Loading engine..."));          dmsg(2,("SamplerChannel: Assigning engine type..."));
69    
70          // create new engine          // create new engine channel
71          Engine* pNewEngine = NULL;          EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType);
72          switch (EngineType) {          if (!pNewEngineChannel) throw Exception("Unknown engine type");
73              case Engine::type_gig:  
74                  pNewEngine = new gig::Engine;          //FIXME: hack to allow fast retrieval of engine channel's sampler channel index
75                  break;          pNewEngineChannel->iSamplerChannelIndex = Index();
             default:  
                 throw LinuxSamplerException("Unknown engine type");  
         }  
76    
77          // dereference midi input port.          // dereference midi input port.
78          MidiInputDevice::MidiInputPort *pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          MidiInputPort* pMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());
79          // disconnect old engine          // disconnect old engine channel
80          if (pEngine) {          if (pEngineChannel) {
81              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngine);              Engine* engine = pEngineChannel->GetEngine();
82              if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(pEngine);              if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(engine);
83              delete pEngine;  
84          }              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);
85                if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();
86                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
94            if (pAudioOutputDevice) {
95                pNewEngineChannel->Connect(pAudioOutputDevice);
96                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    
         // connect new engine  
         pEngine = pNewEngine;  
         if (pMidiInputPort) pMidiInputPort->Connect(pNewEngine, this->midiChannel);  
         if (pAudioOutputDevice) pAudioOutputDevice->Connect(pNewEngine);  
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 && pEngine) pAudioOutputDevice->Disconnect(pEngine);          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 (pEngine) pAudioOutputDevice->Connect(pEngine);          if (pEngineChannel) {
128                pEngineChannel->Connect(pAudioOutputDevice);
129                pAudioOutputDevice->Connect(pEngineChannel->GetEngine());
130            }
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(MidiInputDevice::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 MidiPort, MidiInputDevice::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          MidiInputDevice::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 && pEngine) pMidiInputPort->Disconnect(pEngine);          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 = MidiPort;              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 && pEngine) pMidiInputPort->Connect(pEngine, MidiChannel);  
163          // Ooops.          // Ooops.
164          if (pMidiInputPort == NULL)          if (pNewMidiInputPort == NULL)
165              throw LinuxSamplerException("There is no MIDI input port with index " + ToString(MidiPort) + ".");              throw Exception("There is no MIDI input port with index " + ToString(iMidiPort) + ".");
166      }      }
167    
168      Engine* SamplerChannel::GetEngine() {      EngineChannel* SamplerChannel::GetEngineChannel() {
169          return pEngine;          return pEngineChannel;
170      }      }
171    
172      MidiInputDevice::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          MidiInputDevice::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 136  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    
193      uint SamplerChannel::Index() {      uint SamplerChannel::Index() {
194          if (iIndex >= 0) return iIndex;          if (iIndex >= 0) return iIndex;
195    
196          std::vector<SamplerChannel*>::iterator iter = pSampler->vSamplerChannels.begin();          Sampler::SamplerChannelMap::iterator iter = pSampler->mSamplerChannels.begin();
197          for (int i = 0; iter != pSampler->vSamplerChannels.end(); i++, iter++) {          for (; iter != pSampler->mSamplerChannels.end(); iter++) {
198              if (*iter == this) {              if (iter->second == this) {
199                  iIndex = i;                  iIndex = iter->first;
200                  return i;                  return iIndex;
201              }              }
202          }          }
203    
204          throw LinuxSamplerException("SamplerChannel index not found");          throw Exception("Internal error: SamplerChannel index not found");
205      }      }
206    
207      MidiInputDevice::MidiInputPort* SamplerChannel::GetMidiInputDevicePort(int MidiPort) {      MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) {
208          MidiInputDevice::MidiInputPort *pMidiInputPort = NULL;          MidiInputPort* pMidiInputPort = NULL;
209            MidiInputDevice* pMidiInputDevice = GetMidiInputDevice();
210          if (pMidiInputDevice)          if (pMidiInputDevice)
211              pMidiInputPort = pMidiInputDevice->GetPort(MidiPort);              pMidiInputPort = pMidiInputDevice->GetPort(iMidiPort);
212          return pMidiInputPort;          return pMidiInputPort;
213      }      }
214    
215    
216    
217      // ******************************************************************      // ******************************************************************
218      // * Sampler      // * Sampler
219    
# Line 167  namespace LinuxSampler { Line 221  namespace LinuxSampler {
221      }      }
222    
223      Sampler::~Sampler() {      Sampler::~Sampler() {
224          // delete sampler channels          Reset();
         {  
             std::vector<SamplerChannel*>::iterator iter = vSamplerChannels.begin();  
             for (; iter != vSamplerChannels.end(); iter++) delete *iter;  
         }  
   
         // delete midi input devices  
         {  
             MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin();  
             for (; iter != mMidiInputDevices.end(); iter++) {  
                 MidiInputDevice* pDevice = iter->second;  
                 pDevice->StopListen();  
                 delete pDevice;  
             }  
         }  
   
         // delete audio output devices  
         {  
             AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin();  
             for (; iter != mAudioOutputDevices.end(); iter++) {  
                 AudioOutputDevice* pDevice = iter->second;  
                 pDevice->Stop();  
                 delete pDevice;  
             }  
         }  
225      }      }
226    
227      uint Sampler::SamplerChannels() {      uint Sampler::SamplerChannels() {
228          return vSamplerChannels.size();          return mSamplerChannels.size();
229      }      }
230    
231      SamplerChannel* Sampler::AddSamplerChannel() {      SamplerChannel* Sampler::AddSamplerChannel() {
232            // if there's no sampler channel yet
233            if (!mSamplerChannels.size()) {
234                SamplerChannel* pChannel = new SamplerChannel(this);
235                mSamplerChannels[0] = pChannel;
236                LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, 1));
237                return pChannel;
238            }
239    
240            // get the highest used sampler channel index
241            uint lastIndex = (--(mSamplerChannels.end()))->first;
242    
243            // check if we reached the index limit
244            if (lastIndex + 1 < lastIndex) {
245                // search for an unoccupied sampler channel index starting from 0
246                for (uint i = 0; i < lastIndex; i++) {
247                    if (mSamplerChannels.find(i) != mSamplerChannels.end()) continue;
248                    // we found an unused index, so insert the new channel there
249                    SamplerChannel* pChannel = new SamplerChannel(this);
250                    mSamplerChannels[i] = pChannel;
251                    LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i));
252                    return pChannel;
253                }
254                throw Exception("Internal error: could not find unoccupied sampler channel index.");
255            }
256    
257            // we have not reached the index limit so we just add the channel past the highest index
258          SamplerChannel* pChannel = new SamplerChannel(this);          SamplerChannel* pChannel = new SamplerChannel(this);
259          vSamplerChannels.push_back(pChannel);          mSamplerChannels[lastIndex + 1] = pChannel;
260            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, lastIndex + 1));
261          return pChannel;          return pChannel;
262      }      }
263    
264      SamplerChannel* Sampler::GetSamplerChannel(uint uiSamplerChannel) {      SamplerChannel* Sampler::GetSamplerChannel(uint uiSamplerChannel) {
265          if (uiSamplerChannel >= SamplerChannels()) return NULL;          return (mSamplerChannels.find(uiSamplerChannel) != mSamplerChannels.end()) ? mSamplerChannels[uiSamplerChannel] : NULL;
266          return vSamplerChannels[uiSamplerChannel];      }
267    
268        std::map<uint, SamplerChannel*> Sampler::GetSamplerChannels() {
269            return mSamplerChannels;
270      }      }
271    
272      void Sampler::RemoveSamplerChannel(SamplerChannel* pSamplerChannel) {      void Sampler::RemoveSamplerChannel(SamplerChannel* pSamplerChannel) {
273          std::vector<SamplerChannel*>::iterator iterChan = vSamplerChannels.begin();          SamplerChannelMap::iterator iterChan = mSamplerChannels.begin();
274          for (; iterChan != vSamplerChannels.end(); iterChan++) {          for (; iterChan != mSamplerChannels.end(); iterChan++) {
275              if (*iterChan == pSamplerChannel) {              if (iterChan->second == pSamplerChannel) {
276                  vSamplerChannels.erase(iterChan);                  mSamplerChannels.erase(iterChan);
277                  delete pSamplerChannel;                  delete pSamplerChannel;
278                    LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, mSamplerChannels.size()));
279                  return;                  return;
280              }              }
281          }          }
# Line 230  namespace LinuxSampler { Line 291  namespace LinuxSampler {
291          return AudioOutputDeviceFactory::AvailableDrivers();          return AudioOutputDeviceFactory::AvailableDrivers();
292      }      }
293    
294      AudioOutputDevice* Sampler::CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) {      std::vector<String> Sampler::AvailableMidiInputDrivers() {
295            return MidiInputDeviceFactory::AvailableDrivers();
296        }
297    
298        std::vector<String> Sampler::AvailableEngineTypes() {
299            return EngineFactory::AvailableEngineTypes();
300        }
301    
302        AudioOutputDevice* Sampler::CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (Exception) {
303          // create new device          // create new device
304          AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters);          AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters);
305    
         // activate device  
         pDevice->Play();  
   
306          // add new audio device to the audio device list          // add new audio device to the audio device list
307          for (uint i = 0; ; i++) { // seek for a free place starting from the beginning          for (uint i = 0; ; i++) { // seek for a free place starting from the beginning
308              if (!mAudioOutputDevices[i]) {              if (!mAudioOutputDevices[i]) {
# Line 245  namespace LinuxSampler { Line 311  namespace LinuxSampler {
311              }              }
312          }          }
313    
314            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, AudioOutputDevices()));
315          return pDevice;          return pDevice;
316      }      }
317    
# Line 264  namespace LinuxSampler { Line 331  namespace LinuxSampler {
331          return mMidiInputDevices;          return mMidiInputDevices;
332      }      }
333    
334      void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException) {      void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception) {
335          AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin();          AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin();
336          for (; iter != mAudioOutputDevices.end(); iter++) {          for (; iter != mAudioOutputDevices.end(); iter++) {
337              if (iter->second == pDevice) {              if (iter->second == pDevice) {
338                  // check if there are still sampler engines connected to this device                  // check if there are still sampler engines connected to this device
339                  for (uint i = 0; i < SamplerChannels(); i++)                  for (uint i = 0; i < SamplerChannels(); i++)
340                      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.");
341    
342                  // disable device                  // disable device
343                  pDevice->Stop();                  pDevice->Stop();
# Line 280  namespace LinuxSampler { Line 347  namespace LinuxSampler {
347    
348                  // destroy and free device from memory                  // destroy and free device from memory
349                  delete pDevice;                  delete pDevice;
350    
351                    LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, AudioOutputDevices()));
352                    break;
353              }              }
354          }          }
355      }      }
356    
357      void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (LinuxSamplerException) {      void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception) {
358          MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin();          MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin();
359          for (; iter != mMidiInputDevices.end(); iter++) {          for (; iter != mMidiInputDevices.end(); iter++) {
360              if (iter->second == pDevice) {              if (iter->second == pDevice) {
361                  // check if there are still sampler engines connected to this device                  // check if there are still sampler engines connected to this device
362                  for (uint i = 0; i < SamplerChannels(); i++)                  for (uint i = 0; i < SamplerChannels(); i++)
363                      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.");
364    
365                  // disable device                  // disable device
366                  pDevice->StopListen();                  pDevice->StopListen();
# Line 300  namespace LinuxSampler { Line 370  namespace LinuxSampler {
370    
371                  // destroy and free device from memory                  // destroy and free device from memory
372                  delete pDevice;                  delete pDevice;
373    
374                    LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, MidiInputDevices()));
375                    break;
376              }              }
377          }          }
378      }      }
379    
380      MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) {      MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (Exception) {
381          // create new device          // create new device
382          MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters);          MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this);
   
         // activate device  
         pDevice->Listen();  
383    
384          // add new device to the midi device list          // add new device to the midi device list
385          for (uint i = 0; ; i++) { // seek for a free place starting from the beginning          for (uint i = 0; ; i++) { // seek for a free place starting from the beginning
# Line 319  namespace LinuxSampler { Line 389  namespace LinuxSampler {
389                  }                  }
390          }          }
391    
392            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, MidiInputDevices()));
393          return pDevice;          return pDevice;
394      }      }
395    
396        int Sampler::GetVoiceCount() {
397            int count = 0;
398            std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin();
399    
400            for(; it != EngineFactory::EngineInstances().end(); it++) {
401                count += (*it)->VoiceCount();
402            }
403    
404            return count;
405        }
406    
407        void Sampler::Reset() {
408            // delete sampler channels
409            try {
410                while (true) {
411                        SamplerChannelMap::iterator iter = mSamplerChannels.begin();
412                        if (iter == mSamplerChannels.end()) break;
413                        RemoveSamplerChannel(iter->second);
414                }
415            }
416            catch(...) {
417                std::cerr << "Sampler::Reset(): Exception occured while trying to delete all sampler channels, exiting.\n" << std::flush;
418                exit(EXIT_FAILURE);
419            }
420    
421            // delete midi input devices
422            try {
423                while (true) {
424                        MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin();
425                        if (iter == mMidiInputDevices.end()) break;
426                        DestroyMidiInputDevice(iter->second);
427                }
428            }
429            catch(...) {
430                std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI input devices, exiting.\n" << std::flush;
431                exit(EXIT_FAILURE);
432            }
433    
434            // delete audio output devices
435            try {
436                while (true) {
437                        AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin();
438                        if (iter == mAudioOutputDevices.end()) break;
439                        DestroyAudioOutputDevice(iter->second);
440                }
441            }
442            catch(...) {
443                std::cerr << "Sampler::Reset(): Exception occured while trying to delete all audio output devices, exiting.\n" << std::flush;
444                exit(EXIT_FAILURE);
445            }
446        }
447    
448  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.159  
changed lines
  Added in v.981

  ViewVC Help
Powered by ViewVC