/[svn]/linuxsampler/branches/v0_2_0/src/Sampler.cpp
ViewVC logotype

Diff of /linuxsampler/branches/v0_2_0/src/Sampler.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

linuxsampler/trunk/src/Sampler.cpp revision 209 by schoenebeck, Sun Jul 18 00:29:39 2004 UTC linuxsampler/branches/v0_2_0/src/Sampler.cpp revision 408, Wed Feb 23 19:14:15 2005 UTC
# Line 27  Line 27 
27  #include "drivers/audio/AudioOutputDeviceFactory.h"  #include "drivers/audio/AudioOutputDeviceFactory.h"
28  #include "drivers/midi/MidiInputDeviceFactory.h"  #include "drivers/midi/MidiInputDeviceFactory.h"
29  #include "engines/gig/Engine.h"  #include "engines/gig/Engine.h"
30    #include "network/lscpserver.h"
31    
32  namespace LinuxSampler {  namespace LinuxSampler {
33    
# Line 39  namespace LinuxSampler { Line 40  namespace LinuxSampler {
40          pMidiInputDevice   = NULL;          pMidiInputDevice   = NULL;
41          pAudioOutputDevice = NULL;          pAudioOutputDevice = NULL;
42          midiPort           = 0;          midiPort           = 0;
43          midiChannel        = MidiInputDevice::MidiInputPort::midi_chan_all;          midiChannel        = MidiInputPort::midi_chan_all;
44          iIndex             = -1;          iIndex             = -1;
45      }      }
46    
47      SamplerChannel::~SamplerChannel() {      SamplerChannel::~SamplerChannel() {
48          if (pEngine) {          if (pEngine) {
49              MidiInputDevice::MidiInputPort *pMidiInputPort = GetMidiInputDevicePort(this->midiPort);              MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);
50              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngine);              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngine);
51              if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(pEngine);              if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(pEngine);
52              delete pEngine;              delete pEngine;
# Line 66  namespace LinuxSampler { Line 67  namespace LinuxSampler {
67          }          }
68    
69          // dereference midi input port.          // dereference midi input port.
70          MidiInputDevice::MidiInputPort *pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);
71          // disconnect old engine          // disconnect old engine
72          if (pEngine) {          if (pEngine) {
73              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngine);              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngine);
# Line 97  namespace LinuxSampler { Line 98  namespace LinuxSampler {
98         SetMidiInput(pMidiInputDevice, MidiPort, this->midiChannel);         SetMidiInput(pMidiInputDevice, MidiPort, this->midiChannel);
99      }      }
100    
101      void SamplerChannel::SetMidiInputChannel(MidiInputDevice::MidiInputPort::midi_chan_t MidiChannel) {      void SamplerChannel::SetMidiInputChannel(MidiInputPort::midi_chan_t MidiChannel) {
102         SetMidiInput(pMidiInputDevice, this->midiPort, MidiChannel);         SetMidiInput(pMidiInputDevice, this->midiPort, MidiChannel);
103      }      }
104    
105      void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int MidiPort, MidiInputDevice::MidiInputPort::midi_chan_t MidiChannel) {      void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, MidiInputPort::midi_chan_t MidiChannel) {
106          // dereference old midi input port.          // dereference old midi input port.
107          MidiInputDevice::MidiInputPort *pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);
108          // disconnect old device port          // disconnect old device port
109          if (pMidiInputPort && pEngine) pMidiInputPort->Disconnect(pEngine);          if (pMidiInputPort && pEngine) pMidiInputPort->Disconnect(pEngine);
110          // new device, port and channel          // new device, port and channel
111          pMidiInputDevice = pDevice;          pMidiInputDevice = pDevice;
112          this->midiPort = MidiPort;          this->midiPort = iMidiPort;
113          this->midiChannel = MidiChannel;          this->midiChannel = MidiChannel;
114          // connect new device port          // connect new device port
115          pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          pMidiInputPort = GetMidiInputDevicePort(this->midiPort);
116          if (pMidiInputPort && pEngine) pMidiInputPort->Connect(pEngine, MidiChannel);          if (pMidiInputPort && pEngine) pMidiInputPort->Connect(pEngine, MidiChannel);
117          // Ooops.          // Ooops.
118          if (pMidiInputPort == NULL)          if (pMidiInputPort == NULL)
119              throw LinuxSamplerException("There is no MIDI input port with index " + ToString(MidiPort) + ".");              throw LinuxSamplerException("There is no MIDI input port with index " + ToString(iMidiPort) + ".");
120      }      }
121    
122      Engine* SamplerChannel::GetEngine() {      Engine* SamplerChannel::GetEngine() {
123          return pEngine;          return pEngine;
124      }      }
125    
126      MidiInputDevice::MidiInputPort::midi_chan_t SamplerChannel::GetMidiInputChannel() {      MidiInputPort::midi_chan_t SamplerChannel::GetMidiInputChannel() {
127          return this->midiChannel;          return this->midiChannel;
128      }      }
129    
130      int SamplerChannel::GetMidiInputPort() {      int SamplerChannel::GetMidiInputPort() {
131          MidiInputDevice::MidiInputPort *pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);
132          return (pMidiInputPort ? (int) pMidiInputPort->GetPortNumber() : -1);          return (pMidiInputPort ? (int) pMidiInputPort->GetPortNumber() : -1);
133      }      }
134    
# Line 153  namespace LinuxSampler { Line 154  namespace LinuxSampler {
154          throw LinuxSamplerException("Internal error: SamplerChannel index not found");          throw LinuxSamplerException("Internal error: SamplerChannel index not found");
155      }      }
156    
157      MidiInputDevice::MidiInputPort* SamplerChannel::GetMidiInputDevicePort(int MidiPort) {      MidiInputPort* SamplerChannel::GetMidiInputDevicePort(int iMidiPort) {
158          MidiInputDevice::MidiInputPort *pMidiInputPort = NULL;          MidiInputPort* pMidiInputPort = NULL;
159          if (pMidiInputDevice)          if (pMidiInputDevice)
160              pMidiInputPort = pMidiInputDevice->GetPort(MidiPort);              pMidiInputPort = pMidiInputDevice->GetPort(iMidiPort);
161          return pMidiInputPort;          return pMidiInputPort;
162      }      }
163    
164    
165    
166      // ******************************************************************      // ******************************************************************
167      // * Sampler      // * Sampler
168    
# Line 167  namespace LinuxSampler { Line 170  namespace LinuxSampler {
170      }      }
171    
172      Sampler::~Sampler() {      Sampler::~Sampler() {
173          // delete sampler channels          Reset();
         {  
             SamplerChannelMap::iterator iter = mSamplerChannels.begin();  
             for (; iter != mSamplerChannels.end(); iter++) delete iter->second;  
         }  
   
         // 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;  
             }  
         }  
174      }      }
175    
176      uint Sampler::SamplerChannels() {      uint Sampler::SamplerChannels() {
# Line 203  namespace LinuxSampler { Line 182  namespace LinuxSampler {
182          if (!mSamplerChannels.size()) {          if (!mSamplerChannels.size()) {
183              SamplerChannel* pChannel = new SamplerChannel(this);              SamplerChannel* pChannel = new SamplerChannel(this);
184              mSamplerChannels[0] = pChannel;              mSamplerChannels[0] = pChannel;
185                LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, 1));
186              return pChannel;              return pChannel;
187          }          }
188    
# Line 217  namespace LinuxSampler { Line 197  namespace LinuxSampler {
197                  // we found an unused index, so insert the new channel there                  // we found an unused index, so insert the new channel there
198                  SamplerChannel* pChannel = new SamplerChannel(this);                  SamplerChannel* pChannel = new SamplerChannel(this);
199                  mSamplerChannels[i] = pChannel;                  mSamplerChannels[i] = pChannel;
200                    LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, i));
201                  return pChannel;                  return pChannel;
202              }              }
203              throw LinuxSamplerException("Internal error: could not find unoccupied sampler channel index.");              throw LinuxSamplerException("Internal error: could not find unoccupied sampler channel index.");
# Line 225  namespace LinuxSampler { Line 206  namespace LinuxSampler {
206          // 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
207          SamplerChannel* pChannel = new SamplerChannel(this);          SamplerChannel* pChannel = new SamplerChannel(this);
208          mSamplerChannels[lastIndex + 1] = pChannel;          mSamplerChannels[lastIndex + 1] = pChannel;
209            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, lastIndex + 1));
210          return pChannel;          return pChannel;
211      }      }
212    
# Line 242  namespace LinuxSampler { Line 224  namespace LinuxSampler {
224              if (iterChan->second == pSamplerChannel) {              if (iterChan->second == pSamplerChannel) {
225                  mSamplerChannels.erase(iterChan);                  mSamplerChannels.erase(iterChan);
226                  delete pSamplerChannel;                  delete pSamplerChannel;
227                    LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, mSamplerChannels.size()));
228                  return;                  return;
229              }              }
230          }          }
# Line 343  namespace LinuxSampler { Line 326  namespace LinuxSampler {
326          return pDevice;          return pDevice;
327      }      }
328    
329        void Sampler::Reset() {
330            // delete sampler channels
331            try {
332                while (true) {
333                        SamplerChannelMap::iterator iter = mSamplerChannels.begin();
334                        if (iter == mSamplerChannels.end()) break;
335                        RemoveSamplerChannel(iter->second);
336                }
337            }
338            catch(...) {
339                std::cerr << "Sampler::Reset(): Exception occured while trying to delete all sampler channels, exiting.\n" << std::flush;
340                exit(EXIT_FAILURE);
341            }
342    
343            // delete midi input devices
344            try {
345                while (true) {
346                        MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin();
347                        if (iter == mMidiInputDevices.end()) break;
348                        DestroyMidiInputDevice(iter->second);
349                }
350            }
351            catch(...) {
352                std::cerr << "Sampler::Reset(): Exception occured while trying to delete all MIDI input devices, exiting.\n" << std::flush;
353                exit(EXIT_FAILURE);
354            }
355    
356            // delete audio output devices
357            try {
358                while (true) {
359                        AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin();
360                        if (iter == mAudioOutputDevices.end()) break;
361                        DestroyAudioOutputDevice(iter->second);
362                }
363            }
364            catch(...) {
365                std::cerr << "Sampler::Reset(): Exception occured while trying to delete all audio output devices, exiting.\n" << std::flush;
366                exit(EXIT_FAILURE);
367            }
368        }
369    
370  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.209  
changed lines
  Added in v.408

  ViewVC Help
Powered by ViewVC