/[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 221 by schoenebeck, Fri Aug 20 17:25:19 2004 UTC revision 411 by schoenebeck, Sat Feb 26 02:01:14 2005 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                              *
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 "engines/EngineChannelFactory.h"
29  #include "drivers/audio/AudioOutputDeviceFactory.h"  #include "drivers/audio/AudioOutputDeviceFactory.h"
30  #include "drivers/midi/MidiInputDeviceFactory.h"  #include "drivers/midi/MidiInputDeviceFactory.h"
31  #include "engines/gig/Engine.h"  #include "network/lscpserver.h"
32    
33  namespace LinuxSampler {  namespace LinuxSampler {
34    
# Line 35  namespace LinuxSampler { Line 37  namespace LinuxSampler {
37    
38      SamplerChannel::SamplerChannel(Sampler* pS) {      SamplerChannel::SamplerChannel(Sampler* pS) {
39          pSampler           = pS;          pSampler           = pS;
40          pEngine            = NULL;          pEngineChannel     = NULL;
41          pMidiInputDevice   = NULL;          pMidiInputDevice   = NULL;
42          pAudioOutputDevice = NULL;          pAudioOutputDevice = NULL;
43          midiPort           = 0;          midiPort           = 0;
# Line 44  namespace LinuxSampler { Line 46  namespace LinuxSampler {
46      }      }
47    
48      SamplerChannel::~SamplerChannel() {      SamplerChannel::~SamplerChannel() {
49          if (pEngine) {          if (pEngineChannel) {
50              MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);              MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);
51              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngine);              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);
52              if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(pEngine);              if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(pEngineChannel);
53              delete pEngine;              delete pEngineChannel;
54          }          }
55      }      }
56    
57      void SamplerChannel::LoadEngine(Engine::type_t EngineType) {      void SamplerChannel::SetEngineType(String EngineType) throw (LinuxSamplerException) {
58          dmsg(2,("SamplerChannel: Loading engine..."));          dmsg(2,("SamplerChannel: Assigning engine type..."));
59    
60          // create new engine          // create new engine channel
61          Engine* pNewEngine = NULL;          EngineChannel* pNewEngineChannel = EngineChannelFactory::Create(EngineType);
62          switch (EngineType) {          if (!pNewEngineChannel) throw LinuxSamplerException("Unknown engine type");
             case Engine::type_gig:  
                 pNewEngine = new gig::Engine;  
                 break;  
             default:  
                 throw LinuxSamplerException("Unknown engine type");  
         }  
63    
64          // dereference midi input port.          // dereference midi input port.
65          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);
66          // disconnect old engine          // disconnect old engine
67          if (pEngine) {          if (pEngineChannel) {
68              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngine);              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);
69              if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(pEngine);              if (pAudioOutputDevice) pAudioOutputDevice->Disconnect(pEngineChannel);
70              delete pEngine;              delete pEngineChannel;
71          }          }
72    
73          // connect new engine          // connect new engine channel
74          pEngine = pNewEngine;          pEngineChannel = pNewEngineChannel;
75          if (pMidiInputPort) pMidiInputPort->Connect(pNewEngine, this->midiChannel);          if (pMidiInputPort) pMidiInputPort->Connect(pNewEngineChannel, this->midiChannel);
76          if (pAudioOutputDevice) pAudioOutputDevice->Connect(pNewEngine);          if (pAudioOutputDevice) pAudioOutputDevice->Connect(pNewEngineChannel);
77          dmsg(2,("OK\n"));          dmsg(2,("OK\n"));
78      }      }
79    
80      void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) {      void SamplerChannel::SetAudioOutputDevice(AudioOutputDevice* pDevice) {
81          // disconnect old device          // disconnect old device
82          if (pAudioOutputDevice && pEngine) pAudioOutputDevice->Disconnect(pEngine);          if (pAudioOutputDevice && pEngineChannel) pAudioOutputDevice->Disconnect(pEngineChannel);
83          // connect new device          // connect new device
84          pAudioOutputDevice = pDevice;          pAudioOutputDevice = pDevice;
85          if (pEngine) pAudioOutputDevice->Connect(pEngine);          if (pEngineChannel) pAudioOutputDevice->Connect(pEngineChannel);
86      }      }
87    
88      void SamplerChannel::SetMidiInputDevice(MidiInputDevice* pDevice) {      void SamplerChannel::SetMidiInputDevice(MidiInputDevice* pDevice) {
# Line 105  namespace LinuxSampler { Line 101  namespace LinuxSampler {
101          // dereference old midi input port.          // dereference old midi input port.
102          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);
103          // disconnect old device port          // disconnect old device port
104          if (pMidiInputPort && pEngine) pMidiInputPort->Disconnect(pEngine);          if (pMidiInputPort && pEngineChannel) pMidiInputPort->Disconnect(pEngineChannel);
105          // new device, port and channel          // new device, port and channel
106          pMidiInputDevice = pDevice;          pMidiInputDevice = pDevice;
107          this->midiPort = iMidiPort;          this->midiPort = iMidiPort;
108          this->midiChannel = MidiChannel;          this->midiChannel = MidiChannel;
109          // connect new device port          // connect new device port
110          pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          pMidiInputPort = GetMidiInputDevicePort(this->midiPort);
111          if (pMidiInputPort && pEngine) pMidiInputPort->Connect(pEngine, MidiChannel);          if (pMidiInputPort && pEngineChannel) pMidiInputPort->Connect(pEngineChannel, MidiChannel);
112          // Ooops.          // Ooops.
113          if (pMidiInputPort == NULL)          if (pMidiInputPort == NULL)
114              throw LinuxSamplerException("There is no MIDI input port with index " + ToString(iMidiPort) + ".");              throw LinuxSamplerException("There is no MIDI input port with index " + ToString(iMidiPort) + ".");
115      }      }
116    
117      Engine* SamplerChannel::GetEngine() {      EngineChannel* SamplerChannel::GetEngineChannel() {
118          return pEngine;          return pEngineChannel;
119      }      }
120    
121      MidiInputPort::midi_chan_t SamplerChannel::GetMidiInputChannel() {      MidiInputPort::midi_chan_t SamplerChannel::GetMidiInputChannel() {
# Line 181  namespace LinuxSampler { Line 177  namespace LinuxSampler {
177          if (!mSamplerChannels.size()) {          if (!mSamplerChannels.size()) {
178              SamplerChannel* pChannel = new SamplerChannel(this);              SamplerChannel* pChannel = new SamplerChannel(this);
179              mSamplerChannels[0] = pChannel;              mSamplerChannels[0] = pChannel;
180                LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, 1));
181              return pChannel;              return pChannel;
182          }          }
183    
# Line 195  namespace LinuxSampler { Line 192  namespace LinuxSampler {
192                  // we found an unused index, so insert the new channel there                  // we found an unused index, so insert the new channel there
193                  SamplerChannel* pChannel = new SamplerChannel(this);                  SamplerChannel* pChannel = new SamplerChannel(this);
194                  mSamplerChannels[i] = pChannel;                  mSamplerChannels[i] = pChannel;
195                    LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, i));
196                  return pChannel;                  return pChannel;
197              }              }
198              throw LinuxSamplerException("Internal error: could not find unoccupied sampler channel index.");              throw LinuxSamplerException("Internal error: could not find unoccupied sampler channel index.");
# Line 203  namespace LinuxSampler { Line 201  namespace LinuxSampler {
201          // 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
202          SamplerChannel* pChannel = new SamplerChannel(this);          SamplerChannel* pChannel = new SamplerChannel(this);
203          mSamplerChannels[lastIndex + 1] = pChannel;          mSamplerChannels[lastIndex + 1] = pChannel;
204            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, lastIndex + 1));
205          return pChannel;          return pChannel;
206      }      }
207    
# Line 220  namespace LinuxSampler { Line 219  namespace LinuxSampler {
219              if (iterChan->second == pSamplerChannel) {              if (iterChan->second == pSamplerChannel) {
220                  mSamplerChannels.erase(iterChan);                  mSamplerChannels.erase(iterChan);
221                  delete pSamplerChannel;                  delete pSamplerChannel;
222                    LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channels, mSamplerChannels.size()));
223                  return;                  return;
224              }              }
225          }          }
# Line 324  namespace LinuxSampler { Line 324  namespace LinuxSampler {
324      void Sampler::Reset() {      void Sampler::Reset() {
325          // delete sampler channels          // delete sampler channels
326          try {          try {
327              SamplerChannelMap::iterator iter = mSamplerChannels.begin();              while (true) {
328              for (; iter != mSamplerChannels.end(); iter++) {                      SamplerChannelMap::iterator iter = mSamplerChannels.begin();
329                  RemoveSamplerChannel(iter->second);                      if (iter == mSamplerChannels.end()) break;
330                        RemoveSamplerChannel(iter->second);
331              }              }
332          }          }
333          catch(...) {          catch(...) {
# Line 336  namespace LinuxSampler { Line 337  namespace LinuxSampler {
337    
338          // delete midi input devices          // delete midi input devices
339          try {          try {
340              MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin();              while (true) {
341              for (; iter != mMidiInputDevices.end(); iter++) {                      MidiInputDeviceMap::iterator iter = mMidiInputDevices.begin();
342                  DestroyMidiInputDevice(iter->second);                      if (iter == mMidiInputDevices.end()) break;
343                        DestroyMidiInputDevice(iter->second);
344              }              }
345          }          }
346          catch(...) {          catch(...) {
# Line 348  namespace LinuxSampler { Line 350  namespace LinuxSampler {
350    
351          // delete audio output devices          // delete audio output devices
352          try {          try {
353              AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin();              while (true) {
354              for (; iter != mAudioOutputDevices.end(); iter++) {                      AudioOutputDeviceMap::iterator iter = mAudioOutputDevices.begin();
355                  DestroyAudioOutputDevice(iter->second);                      if (iter == mAudioOutputDevices.end()) break;
356                        DestroyAudioOutputDevice(iter->second);
357              }              }
358          }          }
359          catch(...) {          catch(...) {

Legend:
Removed from v.221  
changed lines
  Added in v.411

  ViewVC Help
Powered by ViewVC