/[svn]/linuxsampler/trunk/src/drivers/midi/MidiInputPort.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/drivers/midi/MidiInputPort.cpp

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

revision 411 by schoenebeck, Sat Feb 26 02:01:14 2005 UTC revision 551 by schoenebeck, Tue May 17 18:16:54 2005 UTC
# Line 23  Line 23 
23    
24  #include "MidiInputPort.h"  #include "MidiInputPort.h"
25    
26    #include "../../Sampler.h"
27    
28  namespace LinuxSampler {  namespace LinuxSampler {
29    
30  // *************** ParameterName ***************  // *************** ParameterName ***************
# Line 70  namespace LinuxSampler { Line 72  namespace LinuxSampler {
72          this->pDevice = pDevice;          this->pDevice = pDevice;
73          this->portNumber = portNumber;          this->portNumber = portNumber;
74          Parameters["NAME"] = new ParameterName(this);          Parameters["NAME"] = new ParameterName(this);
75            pPreviousProgramChangeEngineChannel = NULL;
76      }      }
77    
78      MidiInputDevice* MidiInputPort::GetDevice() {      MidiInputDevice* MidiInputPort::GetDevice() {
# Line 169  namespace LinuxSampler { Line 172  namespace LinuxSampler {
172          }          }
173      }      }
174    
175        void MidiInputPort::DispatchProgramChange(uint8_t Program, uint MidiChannel) {        
176            if (!pDevice || !pDevice->pSampler) {
177                std::cerr << "MidiInputPort: ERROR, no sampler instance to handle program change."
178                          << "This is a bug, please report it!\n" << std::flush;
179                return;
180            }
181    
182            Sampler*        pSampler        = (Sampler*) pDevice->pSampler;
183            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(Program);
184            if (!pSamplerChannel) return;
185    
186            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
187            if (!pEngineChannel) return;
188    
189            // disconnect from the engine channel which was connected by the last PC event
190            if (pPreviousProgramChangeEngineChannel)
191                Disconnect(pPreviousProgramChangeEngineChannel);
192                
193            // now connect to the new engine channel and remember it
194            try {
195                Connect(pEngineChannel, (midi_chan_t) MidiChannel);
196                pPreviousProgramChangeEngineChannel = pEngineChannel;
197            }
198            catch (...) { /* NOOP */ }
199        }
200    
201      void MidiInputPort::Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel) {      void MidiInputPort::Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel) {
202          if (MidiChannel < 0 || MidiChannel > 16)          if (MidiChannel < 0 || MidiChannel > 16)
203              throw MidiInputException("MIDI channel index out of bounds");              throw MidiInputException("MIDI channel index out of bounds");
204                
205          Disconnect(pEngineChannel);          Disconnect(pEngineChannel);
206            
207            MidiChannelMapMutex.Lock();
208          MidiChannelMap[MidiChannel].insert(pEngineChannel);          MidiChannelMap[MidiChannel].insert(pEngineChannel);
209            MidiChannelMapMutex.Unlock();
210      }      }
211    
212      void MidiInputPort::Disconnect(EngineChannel* pEngineChannel) {      void MidiInputPort::Disconnect(EngineChannel* pEngineChannel) {
213            MidiChannelMapMutex.Lock();
214          try { for (int i = 0; i <= 16; i++) MidiChannelMap[i].erase(pEngineChannel); }          try { for (int i = 0; i <= 16; i++) MidiChannelMap[i].erase(pEngineChannel); }
215          catch(...) { /* NOOP */ }          catch(...) { /* NOOP */ }
216            MidiChannelMapMutex.Unlock();
217      }      }
218    
219  } // namespace LinuxSampler  } // namespace LinuxSampler

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

  ViewVC Help
Powered by ViewVC