/[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 675 by schoenebeck, Wed Jun 22 22:09:28 2005 UTC
# Line 38  namespace LinuxSampler { Line 38  namespace LinuxSampler {
38      SamplerChannel::SamplerChannel(Sampler* pS) {      SamplerChannel::SamplerChannel(Sampler* pS) {
39          pSampler           = pS;          pSampler           = pS;
40          pEngineChannel     = NULL;          pEngineChannel     = NULL;
         pMidiInputDevice   = NULL;  
41          pAudioOutputDevice = NULL;          pAudioOutputDevice = NULL;
42          midiPort           = 0;          pMidiInputDevice   = NULL;
43          midiChannel        = MidiInputPort::midi_chan_all;          iMidiPort          = 0;
44            midiChannel        = midi_chan_all;
45          iIndex             = -1;          iIndex             = -1;
46      }      }
47    
48      SamplerChannel::~SamplerChannel() {      SamplerChannel::~SamplerChannel() {
49          if (pEngineChannel) {          if (pEngineChannel) {
50              MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);              MidiInputPort* pMidiInputPort = (pEngineChannel) ? pEngineChannel->GetMidiInputPort() : __GetMidiInputDevicePort(GetMidiInputChannel());
51              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);
52              if (pEngineChannel) {              if (pEngineChannel) {
53                  if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();                  if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();
# Line 67  namespace LinuxSampler { Line 67  namespace LinuxSampler {
67          pNewEngineChannel->iSamplerChannelIndex = Index();          pNewEngineChannel->iSamplerChannelIndex = Index();
68    
69          // dereference midi input port.          // dereference midi input port.
70          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          MidiInputPort* pMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());
71          // disconnect old engine          // disconnect old engine channel
72          if (pEngineChannel) {          if (pEngineChannel) {
73              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);              if (pMidiInputPort) pMidiInputPort->Disconnect(pEngineChannel);
74              if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();              if (pAudioOutputDevice) pEngineChannel->DisconnectAudioOutputDevice();
# Line 76  namespace LinuxSampler { Line 76  namespace LinuxSampler {
76          }          }
77    
78          // connect new engine channel          // connect new engine channel
79          pEngineChannel = pNewEngineChannel;          if (pMidiInputPort) pMidiInputPort->Connect(pNewEngineChannel, GetMidiInputChannel());
         if (pMidiInputPort) pMidiInputPort->Connect(pNewEngineChannel, this->midiChannel);  
80          if (pAudioOutputDevice) {          if (pAudioOutputDevice) {
81              pNewEngineChannel->Connect(pAudioOutputDevice);              pNewEngineChannel->Connect(pAudioOutputDevice);
82              pAudioOutputDevice->Connect(pNewEngineChannel->GetEngine());              pAudioOutputDevice->Connect(pNewEngineChannel->GetEngine());
83          }          }
84            pEngineChannel = pNewEngineChannel;
85    
86            // from now on get MIDI device and port from EngineChannel object
87            this->pMidiInputDevice = NULL;
88            this->iMidiPort        = 0;
89    
90          dmsg(2,("OK\n"));          dmsg(2,("OK\n"));
91      }      }
92    
# Line 97  namespace LinuxSampler { Line 102  namespace LinuxSampler {
102      }      }
103    
104      void SamplerChannel::SetMidiInputDevice(MidiInputDevice* pDevice) {      void SamplerChannel::SetMidiInputDevice(MidiInputDevice* pDevice) {
105         SetMidiInput(pDevice, this->midiPort, this->midiChannel);         SetMidiInput(pDevice, 0, GetMidiInputChannel());
106      }      }
107    
108      void SamplerChannel::SetMidiInputPort(int MidiPort) {      void SamplerChannel::SetMidiInputPort(int MidiPort) {
109         SetMidiInput(pMidiInputDevice, MidiPort, this->midiChannel);         SetMidiInput(GetMidiInputDevice(), MidiPort, GetMidiInputChannel());
110      }      }
111    
112      void SamplerChannel::SetMidiInputChannel(MidiInputPort::midi_chan_t MidiChannel) {      void SamplerChannel::SetMidiInputChannel(midi_chan_t MidiChannel) {
113         SetMidiInput(pMidiInputDevice, this->midiPort, MidiChannel);         SetMidiInput(GetMidiInputDevice(), GetMidiInputPort(), MidiChannel);
114      }      }
115    
116      void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, MidiInputPort::midi_chan_t MidiChannel) {      void SamplerChannel::SetMidiInput(MidiInputDevice* pDevice, int iMidiPort, midi_chan_t MidiChannel) {
117          // dereference old midi input port.          if (!pDevice) throw LinuxSamplerException("No MIDI input device assigned.");
118          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);  
119            // get old and new midi input port
120            MidiInputPort* pOldMidiInputPort = __GetMidiInputDevicePort(GetMidiInputPort());
121            MidiInputPort* pNewMidiInputPort = pDevice->GetPort(iMidiPort);
122    
123          // disconnect old device port          // disconnect old device port
124          if (pMidiInputPort && pEngineChannel) pMidiInputPort->Disconnect(pEngineChannel);          if (pOldMidiInputPort && pEngineChannel) pOldMidiInputPort->Disconnect(pEngineChannel);
125          // new device, port and channel          // remember new device, port and channel if not engine channel yet created
126          pMidiInputDevice = pDevice;          if (!pEngineChannel) {
127          this->midiPort = iMidiPort;              this->pMidiInputDevice = pDevice;
128          this->midiChannel = MidiChannel;              this->iMidiPort        = iMidiPort;
129                this->midiChannel      = MidiChannel;
130            }
131    
132          // connect new device port          // connect new device port
133          pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          if (pNewMidiInputPort && pEngineChannel) pNewMidiInputPort->Connect(pEngineChannel, MidiChannel);
         if (pMidiInputPort && pEngineChannel) pMidiInputPort->Connect(pEngineChannel, MidiChannel);  
134          // Ooops.          // Ooops.
135          if (pMidiInputPort == NULL)          if (pNewMidiInputPort == NULL)
136              throw LinuxSamplerException("There is no MIDI input port with index " + ToString(iMidiPort) + ".");              throw LinuxSamplerException("There is no MIDI input port with index " + ToString(iMidiPort) + ".");
137      }      }
138    
# Line 129  namespace LinuxSampler { Line 140  namespace LinuxSampler {
140          return pEngineChannel;          return pEngineChannel;
141      }      }
142    
143      MidiInputPort::midi_chan_t SamplerChannel::GetMidiInputChannel() {      midi_chan_t SamplerChannel::GetMidiInputChannel() {
144            if (pEngineChannel) this->midiChannel = pEngineChannel->MidiChannel();
145          return this->midiChannel;          return this->midiChannel;
146      }      }
147    
148      int SamplerChannel::GetMidiInputPort() {      int SamplerChannel::GetMidiInputPort() {
149          MidiInputPort* pMidiInputPort = GetMidiInputDevicePort(this->midiPort);          MidiInputPort* pMidiInputPort = (pEngineChannel) ? pEngineChannel->GetMidiInputPort() : NULL;
150          return (pMidiInputPort ? (int) pMidiInputPort->GetPortNumber() : -1);          if (pMidiInputPort) this->iMidiPort = (int) pMidiInputPort->GetPortNumber();
151            return iMidiPort;
152      }      }
153    
154      AudioOutputDevice* SamplerChannel::GetAudioOutputDevice() {      AudioOutputDevice* SamplerChannel::GetAudioOutputDevice() {
# Line 143  namespace LinuxSampler { Line 156  namespace LinuxSampler {
156      }      }
157    
158      MidiInputDevice* SamplerChannel::GetMidiInputDevice() {      MidiInputDevice* SamplerChannel::GetMidiInputDevice() {
159            if (pEngineChannel)
160                pMidiInputDevice = (pEngineChannel->GetMidiInputPort()) ? pEngineChannel->GetMidiInputPort()->GetDevice() : NULL;
161          return pMidiInputDevice;          return pMidiInputDevice;
162      }      }
163    
# Line 160  namespace LinuxSampler { Line 175  namespace LinuxSampler {
175          throw LinuxSamplerException("Internal error: SamplerChannel index not found");          throw LinuxSamplerException("Internal error: SamplerChannel index not found");
176      }      }
177    
178      MidiInputPort* SamplerChannel::GetMidiInputDevicePort(int iMidiPort) {      MidiInputPort* SamplerChannel::__GetMidiInputDevicePort(int iMidiPort) {
179          MidiInputPort* pMidiInputPort = NULL;          MidiInputPort* pMidiInputPort = NULL;
180            MidiInputDevice* pMidiInputDevice = GetMidiInputDevice();
181          if (pMidiInputDevice)          if (pMidiInputDevice)
182              pMidiInputPort = pMidiInputDevice->GetPort(iMidiPort);              pMidiInputPort = pMidiInputDevice->GetPort(iMidiPort);
183          return pMidiInputPort;          return pMidiInputPort;

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

  ViewVC Help
Powered by ViewVC