/[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 660 by schoenebeck, Fri Jun 17 19:49:30 2005 UTC revision 837 by persson, Thu Feb 9 20:03:03 2006 UTC
# Line 25  Line 25 
25    
26  #include "Sampler.h"  #include "Sampler.h"
27    
28    #include "engines/EngineFactory.h"
29  #include "engines/EngineChannelFactory.h"  #include "engines/EngineChannelFactory.h"
30  #include "drivers/audio/AudioOutputDeviceFactory.h"  #include "drivers/audio/AudioOutputDeviceFactory.h"
31  #include "drivers/midi/MidiInputDeviceFactory.h"  #include "drivers/midi/MidiInputDeviceFactory.h"
# Line 38  namespace LinuxSampler { Line 39  namespace LinuxSampler {
39      SamplerChannel::SamplerChannel(Sampler* pS) {      SamplerChannel::SamplerChannel(Sampler* pS) {
40          pSampler           = pS;          pSampler           = pS;
41          pEngineChannel     = NULL;          pEngineChannel     = NULL;
         pMidiInputDevice   = NULL;  
42          pAudioOutputDevice = NULL;          pAudioOutputDevice = NULL;
43          midiPort           = 0;          pMidiInputDevice   = NULL;
44          midiChannel        = 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 (pEngineChannel) {          if (pEngineChannel) {
51              MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);              MidiInputPort* pMidiInputPort = (pEngineChannel) ? pEngineChannel->GetMidiInputPort() : __GetMidiInputDevicePort(GetMidiInputChannel());
52              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);
53              if (pEngineChannel) {              if (pEngineChannel) {
54                  if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();                  if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();
# Line 67  namespace LinuxSampler { Line 68  namespace LinuxSampler {
68          pNewEngineChannel->iSamplerChannelIndex = Index();          pNewEngineChannel->iSamplerChannelIndex = Index();
69    
70          // dereference midi input port.          // dereference midi input port.
71          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          MidiInputPort* pMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());
72          // disconnect old engine          // disconnect old engine channel
73          if (pEngineChannel) {          if (pEngineChannel) {
74              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);
75              if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();              if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();
# Line 76  namespace LinuxSampler { Line 77  namespace LinuxSampler {
77          }          }
78    
79          // connect new engine channel          // connect new engine channel
80          pEngineChannel = pNewEngineChannel;          if (pMidiInputPort) pMidiInputPort->Connect(pNewEngineChannel, GetMidiInputChannel());
         if (pMidiInputPort) pMidiInputPort->Connect(pNewEngineChannel, this->midiChannel);  
81          if (pAudioOutputDevice) {          if (pAudioOutputDevice) {
82              pNewEngineChannel->Connect(pAudioOutputDevice);              pNewEngineChannel->Connect(pAudioOutputDevice);
83              pAudioOutputDevice->Connect(pNewEngineChannel->GetEngine());              pAudioOutputDevice->Connect(pNewEngineChannel->GetEngine());
84          }          }
85            pEngineChannel = pNewEngineChannel;
86    
87            // from now on get MIDI device and port from EngineChannel object
88            this->pMidiInputDevice = NULL;
89            this->iMidiPort        = 0;
90    
91            pEngineChannel->StatusChanged(true);
92    
93          dmsg(2,("OK\n"));          dmsg(2,("OK\n"));
94      }      }
95    
# Line 97  namespace LinuxSampler { Line 105  namespace LinuxSampler {
105      }      }
106    
107      void SamplerChannel::SetMidiInputDevice(MidiInputDevice* pDevice) {      void SamplerChannel::SetMidiInputDevice(MidiInputDevice* pDevice) {
108         SetMidiInput(pDevice, this->midiPort, this->midiChannel);         SetMidiInput(pDevice, 0, GetMidiInputChannel());
109      }      }
110    
111      void SamplerChannel::SetMidiInputPort(int MidiPort) {      void SamplerChannel::SetMidiInputPort(int MidiPort) {
112         SetMidiInput(pMidiInputDevice, MidiPort, this->midiChannel);         SetMidiInput(GetMidiInputDevice(), MidiPort, GetMidiInputChannel());
113      }      }
114    
115      void SamplerChannel::SetMidiInputChannel(MidiInputPort::midi_chan_t MidiChannel) {      void SamplerChannel::SetMidiInputChannel(midi_chan_t MidiChannel) {
116         SetMidiInput(pMidiInputDevice, this->midiPort, MidiChannel);         SetMidiInput(GetMidiInputDevice(), GetMidiInputPort(), MidiChannel);
117      }      }
118    
119      void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, MidiInputPort::midi_chan_t MidiChannel) {      void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel) {
120          // dereference old midi input port.          if (!pDevice) throw LinuxSamplerException("No MIDI input device assigned.");
121          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);  
122            // get old and new midi input port
123            MidiInputPort* pOldMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());
124            MidiInputPort* pNewMidiInputPort = pDevice->GetPort(iMidiPort);
125    
126          // disconnect old device port          // disconnect old device port
127          if (pMidiInputPort && pEngineChannel) pMidiInputPort->Disconnect(pEngineChannel);          if (pOldMidiInputPort && pEngineChannel) pOldMidiInputPort->Disconnect(pEngineChannel);
128          // new device, port and channel          // remember new device, port and channel if not engine channel yet created
129          pMidiInputDevice = pDevice;          if (!pEngineChannel) {
130          this->midiPort = iMidiPort;              this->pMidiInputDevice = pDevice;
131          this->midiChannel = MidiChannel;              this->iMidiPort        = iMidiPort;
132                this->midiChannel      = MidiChannel;
133            }
134    
135          // connect new device port          // connect new device port
136          pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          if (pNewMidiInputPort && pEngineChannel) pNewMidiInputPort->Connect(pEngineChannel, MidiChannel);
         if (pMidiInputPort && pEngineChannel) pMidiInputPort->Connect(pEngineChannel, MidiChannel);  
137          // Ooops.          // Ooops.
138          if (pMidiInputPort == NULL)          if (pNewMidiInputPort == NULL)
139              throw LinuxSamplerException("There is no MIDI input port with index " + ToString(iMidiPort) + ".");              throw LinuxSamplerException("There is no MIDI input port with index " + ToString(iMidiPort) + ".");
140      }      }
141    
# Line 129  namespace LinuxSampler { Line 143  namespace LinuxSampler {
143          return pEngineChannel;          return pEngineChannel;
144      }      }
145    
146      MidiInputPort::midi_chan_t SamplerChannel::GetMidiInputChannel() {      midi_chan_t SamplerChannel::GetMidiInputChannel() {
147            if (pEngineChannel) this->midiChannel = pEngineChannel->MidiChannel();
148          return this->midiChannel;          return this->midiChannel;
149      }      }
150    
151      int SamplerChannel::GetMidiInputPort() {      int SamplerChannel::GetMidiInputPort() {
152          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          MidiInputPort* pMidiInputPort = (pEngineChannel) ? pEngineChannel->GetMidiInputPort() : NULL;
153          return (pMidiInputPort ? (int) pMidiInputPort->GetPortNumber() : -1);          if (pMidiInputPort) this->iMidiPort = (int) pMidiInputPort->GetPortNumber();
154            return iMidiPort;
155      }      }
156    
157      AudioOutputDevice* SamplerChannel::GetAudioOutputDevice() {      AudioOutputDevice* SamplerChannel::GetAudioOutputDevice() {
# Line 143  namespace LinuxSampler { Line 159  namespace LinuxSampler {
159      }      }
160    
161      MidiInputDevice* SamplerChannel::GetMidiInputDevice() {      MidiInputDevice* SamplerChannel::GetMidiInputDevice() {
162            if (pEngineChannel)
163                pMidiInputDevice = (pEngineChannel->GetMidiInputPort()) ? pEngineChannel->GetMidiInputPort()->GetDevice() : NULL;
164          return pMidiInputDevice;          return pMidiInputDevice;
165      }      }
166    
# Line 160  namespace LinuxSampler { Line 178  namespace LinuxSampler {
178          throw LinuxSamplerException("Internal error: SamplerChannel index not found");          throw LinuxSamplerException("Internal error: SamplerChannel index not found");
179      }      }
180    
181      MidiInputPort* SamplerChannel::GetMidiInputDevicePort(int iMidiPort) {      MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) {
182          MidiInputPort* pMidiInputPort = NULL;          MidiInputPort* pMidiInputPort = NULL;
183            MidiInputDevice* pMidiInputDevice = GetMidiInputDevice();
184          if (pMidiInputDevice)          if (pMidiInputDevice)
185              pMidiInputPort = pMidiInputDevice->GetPort(iMidiPort);              pMidiInputPort = pMidiInputDevice->GetPort(iMidiPort);
186          return pMidiInputPort;          return pMidiInputPort;
# Line 293  namespace LinuxSampler { Line 312  namespace LinuxSampler {
312    
313                  // destroy and free device from memory                  // destroy and free device from memory
314                  delete pDevice;                  delete pDevice;
315    
316                    break;
317              }              }
318          }          }
319      }      }
# Line 313  namespace LinuxSampler { Line 334  namespace LinuxSampler {
334    
335                  // destroy and free device from memory                  // destroy and free device from memory
336                  delete pDevice;                  delete pDevice;
337    
338                    break;
339              }              }
340          }          }
341      }      }
# Line 332  namespace LinuxSampler { Line 355  namespace LinuxSampler {
355          return pDevice;          return pDevice;
356      }      }
357    
358        int Sampler::GetVoiceCount() {
359            int count = 0;
360            std::set<Engine*>::iterator it = EngineFactory::EngineInstances().begin();
361    
362            for(; it != EngineFactory::EngineInstances().end(); it++) {
363                count += (*it)->VoiceCount();
364            }
365    
366            return count;
367        }
368    
369      void Sampler::Reset() {      void Sampler::Reset() {
370          // delete sampler channels          // delete sampler channels
371          try {          try {

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

  ViewVC Help
Powered by ViewVC