/[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 2426 by schoenebeck, Fri Mar 1 23:00:17 2013 UTC revision 2427 by persson, Sat Mar 2 07:03:04 2013 UTC
# Line 496  namespace LinuxSampler { Line 496  namespace LinuxSampler {
496                      throw MidiInputException("Invalid note on velocity filter, values must be in range 0 .. 127");                      throw MidiInputException("Invalid note on velocity filter, values must be in range 0 .. 127");
497                    
498          // apply new filter ...          // apply new filter ...
499          noteOnVelocityFilterMutex.Lock();          LockGuard lock(noteOnVelocityFilterMutex);
500          // double buffer ... double work ...          // double buffer ... double work ...
501          {          {
502              std::vector<uint8_t>& config =              std::vector<uint8_t>& config =
# Line 508  namespace LinuxSampler { Line 508  namespace LinuxSampler {
508                  noteOnVelocityFilter.SwitchConfig();                  noteOnVelocityFilter.SwitchConfig();
509              config = filter;              config = filter;
510          }          }
         noteOnVelocityFilterMutex.Unlock();  
511      }      }
512    
513      void MidiInputPort::Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel) {      void MidiInputPort::Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel) {
# Line 516  namespace LinuxSampler { Line 515  namespace LinuxSampler {
515              throw MidiInputException("MIDI channel index out of bounds");              throw MidiInputException("MIDI channel index out of bounds");
516    
517          // first check if desired connection is already established          // first check if desired connection is already established
518          MidiChannelMapMutex.Lock();          {
519          MidiChannelMap_t& midiChannelMap = MidiChannelMap.GetConfigForUpdate();              LockGuard lock(MidiChannelMapMutex);
520          bool bAlreadyDone = midiChannelMap[MidiChannel].count(pEngineChannel);              MidiChannelMap_t& midiChannelMap = MidiChannelMap.GetConfigForUpdate();
521          MidiChannelMapMutex.Unlock();              if (midiChannelMap[MidiChannel].count(pEngineChannel)) return;
522          if (bAlreadyDone) return;          }
523    
524          // remove all other connections of that engine channel (if any)          // remove all other connections of that engine channel (if any)
525          Disconnect(pEngineChannel);          Disconnect(pEngineChannel);
526    
527          // register engine channel on the desired MIDI channel          // register engine channel on the desired MIDI channel
528          MidiChannelMapMutex.Lock();          {
529          MidiChannelMap.GetConfigForUpdate()[MidiChannel].insert(pEngineChannel);              LockGuard lock(MidiChannelMapMutex);
530          MidiChannelMap.SwitchConfig()[MidiChannel].insert(pEngineChannel);              MidiChannelMap.GetConfigForUpdate()[MidiChannel].insert(pEngineChannel);
531          MidiChannelMapMutex.Unlock();              MidiChannelMap.SwitchConfig()[MidiChannel].insert(pEngineChannel);
532            }
533    
534          // inform engine channel about this connection          // inform engine channel about this connection
535          pEngineChannel->Connect(this, MidiChannel);          pEngineChannel->Connect(this, MidiChannel);
# Line 544  namespace LinuxSampler { Line 544  namespace LinuxSampler {
544          bool bChannelFound = false;          bool bChannelFound = false;
545    
546          // unregister engine channel from all MIDI channels          // unregister engine channel from all MIDI channels
         MidiChannelMapMutex.Lock();  
547          try {          try {
548                LockGuard lock(MidiChannelMapMutex);
549              {              {
550                  MidiChannelMap_t& midiChannelMap = MidiChannelMap.GetConfigForUpdate();                  MidiChannelMap_t& midiChannelMap = MidiChannelMap.GetConfigForUpdate();
551                  for (int i = 0; i <= 16; i++) {                  for (int i = 0; i <= 16; i++) {
# Line 563  namespace LinuxSampler { Line 563  namespace LinuxSampler {
563              }              }
564          }          }
565          catch(...) { /* NOOP */ }          catch(...) { /* NOOP */ }
         MidiChannelMapMutex.Unlock();  
566    
567          // inform engine channel about the disconnection (if there is one)          // inform engine channel about the disconnection (if there is one)
568          if (bChannelFound) pEngineChannel->DisconnectMidiInputPort();          if (bChannelFound) pEngineChannel->DisconnectMidiInputPort();
# Line 586  namespace LinuxSampler { Line 585  namespace LinuxSampler {
585      }      }
586    
587      void MidiInputPort::Connect(VirtualMidiDevice* pDevice) {      void MidiInputPort::Connect(VirtualMidiDevice* pDevice) {
588          virtualMidiDevicesMutex.Lock();          LockGuard lock(virtualMidiDevicesMutex);
589          // double buffer ... double work ...          // double buffer ... double work ...
590          {          {
591              std::vector<VirtualMidiDevice*>& devices =              std::vector<VirtualMidiDevice*>& devices =
# Line 598  namespace LinuxSampler { Line 597  namespace LinuxSampler {
597                  virtualMidiDevices.SwitchConfig();                  virtualMidiDevices.SwitchConfig();
598              devices.push_back(pDevice);              devices.push_back(pDevice);
599          }          }
         virtualMidiDevicesMutex.Unlock();  
600      }      }
601    
602      void MidiInputPort::Disconnect(VirtualMidiDevice* pDevice) {      void MidiInputPort::Disconnect(VirtualMidiDevice* pDevice) {
603          virtualMidiDevicesMutex.Lock();          LockGuard lock(virtualMidiDevicesMutex);
604          // double buffer ... double work ...          // double buffer ... double work ...
605          {          {
606              std::vector<VirtualMidiDevice*>& devices =              std::vector<VirtualMidiDevice*>& devices =
# Line 614  namespace LinuxSampler { Line 612  namespace LinuxSampler {
612                  virtualMidiDevices.SwitchConfig();                  virtualMidiDevices.SwitchConfig();
613              devices.erase(std::find(devices.begin(), devices.end(), pDevice));              devices.erase(std::find(devices.begin(), devices.end(), pDevice));
614          }          }
         virtualMidiDevicesMutex.Unlock();  
615      }      }
616    
617  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.2426  
changed lines
  Added in v.2427

  ViewVC Help
Powered by ViewVC