/[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 846 by persson, Sun Mar 19 16:38:22 2006 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 Christian Schoenebeck                              *   *   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 64  namespace LinuxSampler { Line 64  namespace LinuxSampler {
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          //FIXME: hack to allow fast retrieval of engine channel's sampler channel index
75          pNewEngineChannel->iSamplerChannelIndex = Index();          pNewEngineChannel->iSamplerChannelIndex = Index();
# Line 108  namespace LinuxSampler { Line 108  namespace LinuxSampler {
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) {          if (pAudioOutputDevice && pEngineChannel) {
115              Engine* engine = pEngineChannel->GetEngine();              Engine* engine = pEngineChannel->GetEngine();
# Line 141  namespace LinuxSampler { Line 143  namespace LinuxSampler {
143      }      }
144    
145      void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel) {      void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel) {
146          if (!pDevice) throw LinuxSamplerException("No MIDI input device assigned.");          if (!pDevice) throw Exception("No MIDI input device assigned.");
147    
148          // get old and new midi input port          // get old and new midi input port
149          MidiInputPort* pOldMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());          MidiInputPort* pOldMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());
# Line 160  namespace LinuxSampler { Line 162  namespace LinuxSampler {
162          if (pNewMidiInputPort && pEngineChannel) pNewMidiInputPort->Connect(pEngineChannel, MidiChannel);          if (pNewMidiInputPort && pEngineChannel) pNewMidiInputPort->Connect(pEngineChannel, MidiChannel);
163          // Ooops.          // Ooops.
164          if (pNewMidiInputPort == 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() {
# Line 199  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      MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) {      MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) {
# Line 249  namespace LinuxSampler { Line 251  namespace LinuxSampler {
251                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i));                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i));
252                  return pChannel;                  return pChannel;
253              }              }
254              throw LinuxSamplerException("Internal error: could not find unoccupied sampler channel index.");              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          // we have not reached the index limit so we just add the channel past the highest index
# Line 289  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    
# Line 301  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 320  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 337  namespace LinuxSampler { Line 348  namespace LinuxSampler {
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;                  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 359  namespace LinuxSampler { Line 371  namespace LinuxSampler {
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;                  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, this);          MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this);
383    
# Line 376  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    

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

  ViewVC Help
Powered by ViewVC