/[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 551 by schoenebeck, Tue May 17 18:16:54 2005 UTC revision 675 by schoenebeck, Wed Jun 22 22:09:28 2005 UTC
# Line 172  namespace LinuxSampler { Line 172  namespace LinuxSampler {
172          }          }
173      }      }
174    
175      void MidiInputPort::DispatchProgramChange(uint8_t Program, uint MidiChannel) {              void MidiInputPort::DispatchProgramChange(uint8_t Program, uint MidiChannel) {
176          if (!pDevice || !pDevice->pSampler) {          if (!pDevice || !pDevice->pSampler) {
177              std::cerr << "MidiInputPort: ERROR, no sampler instance to handle program change."              std::cerr << "MidiInputPort: ERROR, no sampler instance to handle program change."
178                        << "This is a bug, please report it!\n" << std::flush;                        << "This is a bug, please report it!\n" << std::flush;
# Line 189  namespace LinuxSampler { Line 189  namespace LinuxSampler {
189          // disconnect from the engine channel which was connected by the last PC event          // disconnect from the engine channel which was connected by the last PC event
190          if (pPreviousProgramChangeEngineChannel)          if (pPreviousProgramChangeEngineChannel)
191              Disconnect(pPreviousProgramChangeEngineChannel);              Disconnect(pPreviousProgramChangeEngineChannel);
192                
193          // now connect to the new engine channel and remember it          // now connect to the new engine channel and remember it
194          try {          try {
195              Connect(pEngineChannel, (midi_chan_t) MidiChannel);              Connect(pEngineChannel, (midi_chan_t) MidiChannel);
# Line 201  namespace LinuxSampler { Line 201  namespace LinuxSampler {
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            // firt check if desired connection is already established
206            MidiChannelMapMutex.Lock();
207            bool bAlreadyDone = MidiChannelMap[MidiChannel].count(pEngineChannel);
208            MidiChannelMapMutex.Unlock();
209            if (bAlreadyDone) return;
210    
211            // remove all other connections of that engine channel (if any)
212          Disconnect(pEngineChannel);          Disconnect(pEngineChannel);
213            
214            // register engine channel on the desired MIDI channel
215          MidiChannelMapMutex.Lock();          MidiChannelMapMutex.Lock();
216          MidiChannelMap[MidiChannel].insert(pEngineChannel);          MidiChannelMap[MidiChannel].insert(pEngineChannel);
217          MidiChannelMapMutex.Unlock();          MidiChannelMapMutex.Unlock();
218    
219            // inform engine channel about this connection
220            pEngineChannel->Connect(this, MidiChannel);
221    
222            // mark engine channel as changed
223            pEngineChannel->StatusChanged(true);
224      }      }
225    
226      void MidiInputPort::Disconnect(EngineChannel* pEngineChannel) {      void MidiInputPort::Disconnect(EngineChannel* pEngineChannel) {
227            if (!pEngineChannel) return;
228    
229            bool bChannelFound = false;
230    
231            // unregister engine channel from all MIDI channels
232          MidiChannelMapMutex.Lock();          MidiChannelMapMutex.Lock();
233          try { for (int i = 0; i <= 16; i++) MidiChannelMap[i].erase(pEngineChannel); }          try {
234                for (int i = 0; i <= 16; i++) {
235                    bChannelFound |= MidiChannelMap[i].count(pEngineChannel);
236                    MidiChannelMap[i].erase(pEngineChannel);
237                }
238            }
239          catch(...) { /* NOOP */ }          catch(...) { /* NOOP */ }
240          MidiChannelMapMutex.Unlock();          MidiChannelMapMutex.Unlock();
241    
242            // inform engine channel about the disconnection (if there is one)
243            if (bChannelFound) pEngineChannel->DisconnectMidiInputPort();
244    
245            // mark engine channel as changed
246            pEngineChannel->StatusChanged(true);
247      }      }
248    
249  } // namespace LinuxSampler  } // namespace LinuxSampler

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

  ViewVC Help
Powered by ViewVC