/[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 837 by persson, Thu Feb 9 20:03:03 2006 UTC revision 880 by schoenebeck, Tue Jun 27 22:57:37 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 48  namespace LinuxSampler { Line 48  namespace LinuxSampler {
48    
49      SamplerChannel::~SamplerChannel() {      SamplerChannel::~SamplerChannel() {
50          if (pEngineChannel) {          if (pEngineChannel) {
51                Engine* engine = pEngineChannel->GetEngine();
52                if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(engine);
53    
54              MidiInputPort* pMidiInputPort = (pEngineChannel) ? pEngineChannel->GetMidiInputPort() : __GetMidiInputDevicePort(GetMidiInputChannel());              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                  EngineChannelFactory::Destroy(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          //FIXME: hack to allow fast retrieval of engine channel's sampler channel index
75          pNewEngineChannel->iSamplerChannelIndex = Index();          pNewEngineChannel->iSamplerChannelIndex = Index();
# Line 71  namespace LinuxSampler { Line 78  namespace LinuxSampler {
78          MidiInputPort* pMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());          MidiInputPort* pMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());
79          // disconnect old engine channel          // 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              EngineChannelFactory::Destroy(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
         if (pMidiInputPort) pMidiInputPort->Connect(pNewEngineChannel, GetMidiInputChannel());  
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;          pEngineChannel = pNewEngineChannel;
100    
101          // from now on get MIDI device and port from EngineChannel object          // from now on get MIDI device and port from EngineChannel object
# Line 95  namespace LinuxSampler { Line 109  namespace LinuxSampler {
109    
110      void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) {      void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) {
111          // disconnect old device          // disconnect old device
112          if (pAudioOutputDevice && pEngineChannel) pEngineChannel->DisconnectAudioOutputDevice();          if (pAudioOutputDevice && pEngineChannel) {
113                Engine* engine = pEngineChannel->GetEngine();
114                pAudioOutputDevice->Disconnect(engine);
115    
116                pEngineChannel->DisconnectAudioOutputDevice();
117    
118                // reconnect engine if it still exists
119                const std::set<Engine*>& engines = EngineFactory::EngineInstances();
120                if (engines.find(engine) != engines.end()) pAudioOutputDevice->Connect(engine);
121            }
122    
123          // connect new device          // connect new device
124          pAudioOutputDevice = pDevice;          pAudioOutputDevice = pDevice;
125          if (pEngineChannel) {          if (pEngineChannel) {
# Line 117  namespace LinuxSampler { Line 141  namespace LinuxSampler {
141      }      }
142    
143      void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel) {      void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel) {
144          if (!pDevice) throw LinuxSamplerException("No MIDI input device assigned.");          if (!pDevice) throw Exception("No MIDI input device assigned.");
145    
146          // get old and new midi input port          // get old and new midi input port
147          MidiInputPort* pOldMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());          MidiInputPort* pOldMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());
# Line 136  namespace LinuxSampler { Line 160  namespace LinuxSampler {
160          if (pNewMidiInputPort && pEngineChannel) pNewMidiInputPort->Connect(pEngineChannel, MidiChannel);          if (pNewMidiInputPort && pEngineChannel) pNewMidiInputPort->Connect(pEngineChannel, MidiChannel);
161          // Ooops.          // Ooops.
162          if (pNewMidiInputPort == NULL)          if (pNewMidiInputPort == NULL)
163              throw LinuxSamplerException("There is no MIDI input port with index " + ToString(iMidiPort) + ".");              throw Exception("There is no MIDI input port with index " + ToString(iMidiPort) + ".");
164      }      }
165    
166      EngineChannel* SamplerChannel::GetEngineChannel() {      EngineChannel* SamplerChannel::GetEngineChannel() {
# Line 175  namespace LinuxSampler { Line 199  namespace LinuxSampler {
199              }              }
200          }          }
201    
202          throw LinuxSamplerException("Internal error: SamplerChannel index not found");          throw Exception("Internal error: SamplerChannel index not found");
203      }      }
204    
205      MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) {      MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) {
# Line 225  namespace LinuxSampler { Line 249  namespace LinuxSampler {
249                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i));                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, i));
250                  return pChannel;                  return pChannel;
251              }              }
252              throw LinuxSamplerException("Internal error: could not find unoccupied sampler channel index.");              throw Exception("Internal error: could not find unoccupied sampler channel index.");
253          }          }
254    
255          // 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 265  namespace LinuxSampler { Line 289  namespace LinuxSampler {
289          return AudioOutputDeviceFactory::AvailableDrivers();          return AudioOutputDeviceFactory::AvailableDrivers();
290      }      }
291    
292      AudioOutputDevice* Sampler::CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) {      AudioOutputDevice* Sampler::CreateAudioOutputDevice(String AudioDriver, std::map<String,String> Parameters) throw (Exception) {
293          // create new device          // create new device
294          AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters);          AudioOutputDevice* pDevice = AudioOutputDeviceFactory::Create(AudioDriver, Parameters);
295    
# Line 296  namespace LinuxSampler { Line 320  namespace LinuxSampler {
320          return mMidiInputDevices;          return mMidiInputDevices;
321      }      }
322    
323      void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (LinuxSamplerException) {      void Sampler::DestroyAudioOutputDevice(AudioOutputDevice* pDevice) throw (Exception) {
324          AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin();          AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin();
325          for (; iter != mAudioOutputDevices.end(); iter++) {          for (; iter != mAudioOutputDevices.end(); iter++) {
326              if (iter->second == pDevice) {              if (iter->second == pDevice) {
327                  // check if there are still sampler engines connected to this device                  // check if there are still sampler engines connected to this device
328                  for (uint i = 0; i < SamplerChannels(); i++)                  for (uint i = 0; i < SamplerChannels(); i++)
329                      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.");
330    
331                  // disable device                  // disable device
332                  pDevice->Stop();                  pDevice->Stop();
# Line 318  namespace LinuxSampler { Line 342  namespace LinuxSampler {
342          }          }
343      }      }
344    
345      void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (LinuxSamplerException) {      void Sampler::DestroyMidiInputDevice(MidiInputDevice* pDevice) throw (Exception) {
346          MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin();          MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin();
347          for (; iter != mMidiInputDevices.end(); iter++) {          for (; iter != mMidiInputDevices.end(); iter++) {
348              if (iter->second == pDevice) {              if (iter->second == pDevice) {
349                  // check if there are still sampler engines connected to this device                  // check if there are still sampler engines connected to this device
350                  for (uint i = 0; i < SamplerChannels(); i++)                  for (uint i = 0; i < SamplerChannels(); i++)
351                      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.");
352    
353                  // disable device                  // disable device
354                  pDevice->StopListen();                  pDevice->StopListen();
# Line 340  namespace LinuxSampler { Line 364  namespace LinuxSampler {
364          }          }
365      }      }
366    
367      MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (LinuxSamplerException) {      MidiInputDevice* Sampler::CreateMidiInputDevice(String MidiDriver, std::map<String,String> Parameters) throw (Exception) {
368          // create new device          // create new device
369          MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this);          MidiInputDevice* pDevice = MidiInputDeviceFactory::Create(MidiDriver, Parameters, this);
370    

Legend:
Removed from v.837  
changed lines
  Added in v.880

  ViewVC Help
Powered by ViewVC