/[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 839 by persson, Wed Feb 8 20:28:46 2006 UTC revision 840 by persson, Sun Feb 26 13:00:08 2006 UTC
# Line 89  namespace LinuxSampler { Line 89  namespace LinuxSampler {
89      }      }
90    
91      void MidiInputPort::DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel) {      void MidiInputPort::DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel) {
92            const MidiChannelMap_t& midiChannelMap = MidiChannelMap.Lock();
93          // dispatch event for engines listening to the same MIDI channel          // dispatch event for engines listening to the same MIDI channel
94          {          {
95              std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();              std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin();
96              std::set<EngineChannel*>::iterator end        = MidiChannelMap[MidiChannel].end();              std::set<EngineChannel*>::iterator end        = midiChannelMap[MidiChannel].end();
97              for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity);              for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity);
98          }          }
99          // dispatch event for engines listening to ALL MIDI channels          // dispatch event for engines listening to ALL MIDI channels
100          {          {
101              std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();              std::set<EngineChannel*>::iterator engineiter = midiChannelMap[midi_chan_all].begin();
102              std::set<EngineChannel*>::iterator end        = MidiChannelMap[midi_chan_all].end();              std::set<EngineChannel*>::iterator end        = midiChannelMap[midi_chan_all].end();
103              for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity);              for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity);
104          }          }
105            MidiChannelMap.Unlock();
106      }      }
107    
108      void MidiInputPort::DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel) {      void MidiInputPort::DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel) {
109            const MidiChannelMap_t& midiChannelMap = MidiChannelMap.Lock();
110          // dispatch event for engines listening to the same MIDI channel          // dispatch event for engines listening to the same MIDI channel
111          {          {
112              std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();              std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin();
113              std::set<EngineChannel*>::iterator end        = MidiChannelMap[MidiChannel].end();              std::set<EngineChannel*>::iterator end        = midiChannelMap[MidiChannel].end();
114              for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity);              for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity);
115          }          }
116          // dispatch event for engines listening to ALL MIDI channels          // dispatch event for engines listening to ALL MIDI channels
117          {          {
118              std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();              std::set<EngineChannel*>::iterator engineiter = midiChannelMap[midi_chan_all].begin();
119              std::set<EngineChannel*>::iterator end        = MidiChannelMap[midi_chan_all].end();              std::set<EngineChannel*>::iterator end        = midiChannelMap[midi_chan_all].end();
120              for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity);              for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity);
121          }          }
122            MidiChannelMap.Unlock();
123      }      }
124    
125      void MidiInputPort::DispatchPitchbend(int Pitch, uint MidiChannel) {      void MidiInputPort::DispatchPitchbend(int Pitch, uint MidiChannel) {
126            const MidiChannelMap_t& midiChannelMap = MidiChannelMap.Lock();
127          // dispatch event for engines listening to the same MIDI channel          // dispatch event for engines listening to the same MIDI channel
128          {          {
129              std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();              std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin();
130              std::set<EngineChannel*>::iterator end        = MidiChannelMap[MidiChannel].end();              std::set<EngineChannel*>::iterator end        = midiChannelMap[MidiChannel].end();
131              for (; engineiter != end; engineiter++) (*engineiter)->SendPitchbend(Pitch);              for (; engineiter != end; engineiter++) (*engineiter)->SendPitchbend(Pitch);
132          }          }
133          // dispatch event for engines listening to ALL MIDI channels          // dispatch event for engines listening to ALL MIDI channels
134          {          {
135              std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();              std::set<EngineChannel*>::iterator engineiter = midiChannelMap[midi_chan_all].begin();
136              std::set<EngineChannel*>::iterator end        = MidiChannelMap[midi_chan_all].end();              std::set<EngineChannel*>::iterator end        = midiChannelMap[midi_chan_all].end();
137              for (; engineiter != end; engineiter++) (*engineiter)->SendPitchbend(Pitch);              for (; engineiter != end; engineiter++) (*engineiter)->SendPitchbend(Pitch);
138          }          }
139            MidiChannelMap.Unlock();
140      }      }
141    
142      void MidiInputPort::DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel) {      void MidiInputPort::DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel) {
143            const MidiChannelMap_t& midiChannelMap = MidiChannelMap.Lock();
144          // dispatch event for engines listening to the same MIDI channel          // dispatch event for engines listening to the same MIDI channel
145          {          {
146              std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();              std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin();
147              std::set<EngineChannel*>::iterator end        = MidiChannelMap[MidiChannel].end();              std::set<EngineChannel*>::iterator end        = midiChannelMap[MidiChannel].end();
148              for (; engineiter != end; engineiter++) (*engineiter)->SendControlChange(Controller, Value);              for (; engineiter != end; engineiter++) (*engineiter)->SendControlChange(Controller, Value);
149          }          }
150          // dispatch event for engines listening to ALL MIDI channels          // dispatch event for engines listening to ALL MIDI channels
151          {          {
152              std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();              std::set<EngineChannel*>::iterator engineiter = midiChannelMap[midi_chan_all].begin();
153              std::set<EngineChannel*>::iterator end        = MidiChannelMap[midi_chan_all].end();              std::set<EngineChannel*>::iterator end        = midiChannelMap[midi_chan_all].end();
154              for (; engineiter != end; engineiter++) (*engineiter)->SendControlChange(Controller, Value);              for (; engineiter != end; engineiter++) (*engineiter)->SendControlChange(Controller, Value);
155          }          }
156            MidiChannelMap.Unlock();
157      }      }
158    
159      void MidiInputPort::DispatchSysex(void* pData, uint Size) {      void MidiInputPort::DispatchSysex(void* pData, uint Size) {
# Line 185  namespace LinuxSampler { Line 193  namespace LinuxSampler {
193          if (MidiChannel < 0 || MidiChannel > 16)          if (MidiChannel < 0 || MidiChannel > 16)
194              throw MidiInputException("MIDI channel index out of bounds");              throw MidiInputException("MIDI channel index out of bounds");
195    
196          // firt check if desired connection is already established          // first check if desired connection is already established
197          MidiChannelMapMutex.Lock();          MidiChannelMapMutex.Lock();
198          bool bAlreadyDone = MidiChannelMap[MidiChannel].count(pEngineChannel);          MidiChannelMap_t& midiChannelMap = MidiChannelMap.GetConfigForUpdate();
199            bool bAlreadyDone = midiChannelMap[MidiChannel].count(pEngineChannel);
200          MidiChannelMapMutex.Unlock();          MidiChannelMapMutex.Unlock();
201          if (bAlreadyDone) return;          if (bAlreadyDone) return;
202    
# Line 196  namespace LinuxSampler { Line 205  namespace LinuxSampler {
205    
206          // register engine channel on the desired MIDI channel          // register engine channel on the desired MIDI channel
207          MidiChannelMapMutex.Lock();          MidiChannelMapMutex.Lock();
208          MidiChannelMap[MidiChannel].insert(pEngineChannel);          MidiChannelMap.GetConfigForUpdate()[MidiChannel].insert(pEngineChannel);
209            MidiChannelMap.SwitchConfig()[MidiChannel].insert(pEngineChannel);
210          MidiChannelMapMutex.Unlock();          MidiChannelMapMutex.Unlock();
211    
212          // inform engine channel about this connection          // inform engine channel about this connection
# Line 214  namespace LinuxSampler { Line 224  namespace LinuxSampler {
224          // unregister engine channel from all MIDI channels          // unregister engine channel from all MIDI channels
225          MidiChannelMapMutex.Lock();          MidiChannelMapMutex.Lock();
226          try {          try {
227              for (int i = 0; i <= 16; i++) {              {
228                  bChannelFound |= MidiChannelMap[i].count(pEngineChannel);                  MidiChannelMap_t& midiChannelMap = MidiChannelMap.GetConfigForUpdate();
229                  MidiChannelMap[i].erase(pEngineChannel);                  for (int i = 0; i <= 16; i++) {
230                        bChannelFound |= midiChannelMap[i].count(pEngineChannel);
231                        midiChannelMap[i].erase(pEngineChannel);
232                    }
233                }
234                // do the same update again, after switching to the other config
235                {
236                    MidiChannelMap_t& midiChannelMap = MidiChannelMap.SwitchConfig();
237                    for (int i = 0; i <= 16; i++) {
238                        bChannelFound |= midiChannelMap[i].count(pEngineChannel);
239                        midiChannelMap[i].erase(pEngineChannel);
240                    }
241              }              }
242          }          }
243          catch(...) { /* NOOP */ }          catch(...) { /* NOOP */ }

Legend:
Removed from v.839  
changed lines
  Added in v.840

  ViewVC Help
Powered by ViewVC