/[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 840 by persson, Sun Feb 26 13:00:08 2006 UTC revision 846 by persson, Sun Mar 19 16:38:22 2006 UTC
# Line 69  namespace LinuxSampler { Line 69  namespace LinuxSampler {
69          Parameters.clear();          Parameters.clear();
70      }      }
71    
72      MidiInputPort::MidiInputPort(MidiInputDevice* pDevice, int portNumber) {      MidiInputPort::MidiInputPort(MidiInputDevice* pDevice, int portNumber)
73            : MidiChannelMapReader(MidiChannelMap),
74              SysexListenersReader(SysexListeners) {
75          this->pDevice = pDevice;          this->pDevice = pDevice;
76          this->portNumber = portNumber;          this->portNumber = portNumber;
77          Parameters["NAME"] = new ParameterName(this);          Parameters["NAME"] = new ParameterName(this);
# Line 89  namespace LinuxSampler { Line 91  namespace LinuxSampler {
91      }      }
92    
93      void MidiInputPort::DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel) {      void MidiInputPort::DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel) {
94          const MidiChannelMap_t& midiChannelMap = MidiChannelMap.Lock();          const MidiChannelMap_t& midiChannelMap = MidiChannelMapReader.Lock();
95          // dispatch event for engines listening to the same MIDI channel          // dispatch event for engines listening to the same MIDI channel
96          {          {
97              std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin();              std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin();
# Line 102  namespace LinuxSampler { Line 104  namespace LinuxSampler {
104              std::set<EngineChannel*>::iterator end        = midiChannelMap[midi_chan_all].end();              std::set<EngineChannel*>::iterator end        = midiChannelMap[midi_chan_all].end();
105              for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity);              for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity);
106          }          }
107          MidiChannelMap.Unlock();          MidiChannelMapReader.Unlock();
108      }      }
109    
110      void MidiInputPort::DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel) {      void MidiInputPort::DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel) {
111          const MidiChannelMap_t& midiChannelMap = MidiChannelMap.Lock();          const MidiChannelMap_t& midiChannelMap = MidiChannelMapReader.Lock();
112          // dispatch event for engines listening to the same MIDI channel          // dispatch event for engines listening to the same MIDI channel
113          {          {
114              std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin();              std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin();
# Line 119  namespace LinuxSampler { Line 121  namespace LinuxSampler {
121              std::set<EngineChannel*>::iterator end        = midiChannelMap[midi_chan_all].end();              std::set<EngineChannel*>::iterator end        = midiChannelMap[midi_chan_all].end();
122              for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity);              for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity);
123          }          }
124          MidiChannelMap.Unlock();          MidiChannelMapReader.Unlock();
125      }      }
126    
127      void MidiInputPort::DispatchPitchbend(int Pitch, uint MidiChannel) {      void MidiInputPort::DispatchPitchbend(int Pitch, uint MidiChannel) {
128          const MidiChannelMap_t& midiChannelMap = MidiChannelMap.Lock();          const MidiChannelMap_t& midiChannelMap = MidiChannelMapReader.Lock();
129          // dispatch event for engines listening to the same MIDI channel          // dispatch event for engines listening to the same MIDI channel
130          {          {
131              std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin();              std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin();
# Line 136  namespace LinuxSampler { Line 138  namespace LinuxSampler {
138              std::set<EngineChannel*>::iterator end        = midiChannelMap[midi_chan_all].end();              std::set<EngineChannel*>::iterator end        = midiChannelMap[midi_chan_all].end();
139              for (; engineiter != end; engineiter++) (*engineiter)->SendPitchbend(Pitch);              for (; engineiter != end; engineiter++) (*engineiter)->SendPitchbend(Pitch);
140          }          }
141          MidiChannelMap.Unlock();          MidiChannelMapReader.Unlock();
142      }      }
143    
144      void MidiInputPort::DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel) {      void MidiInputPort::DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel) {
145          const MidiChannelMap_t& midiChannelMap = MidiChannelMap.Lock();          const MidiChannelMap_t& midiChannelMap = MidiChannelMapReader.Lock();
146          // dispatch event for engines listening to the same MIDI channel          // dispatch event for engines listening to the same MIDI channel
147          {          {
148              std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin();              std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin();
# Line 153  namespace LinuxSampler { Line 155  namespace LinuxSampler {
155              std::set<EngineChannel*>::iterator end        = midiChannelMap[midi_chan_all].end();              std::set<EngineChannel*>::iterator end        = midiChannelMap[midi_chan_all].end();
156              for (; engineiter != end; engineiter++) (*engineiter)->SendControlChange(Controller, Value);              for (; engineiter != end; engineiter++) (*engineiter)->SendControlChange(Controller, Value);
157          }          }
158          MidiChannelMap.Unlock();          MidiChannelMapReader.Unlock();
159      }      }
160    
161      void MidiInputPort::DispatchSysex(void* pData, uint Size) {      void MidiInputPort::DispatchSysex(void* pData, uint Size) {
162            const std::set<Engine*> allEngines = SysexListenersReader.Lock();
163          // dispatch event to all engine instances          // dispatch event to all engine instances
164          std::set<Engine*>::iterator engineiter = EngineFactory::EngineInstances().begin();          std::set<Engine*>::iterator engineiter = allEngines.begin();
165          std::set<Engine*>::iterator end        = EngineFactory::EngineInstances().end();          std::set<Engine*>::iterator end        = allEngines.end();
166          for (; engineiter != end; engineiter++) (*engineiter)->SendSysex(pData, Size);          for (; engineiter != end; engineiter++) (*engineiter)->SendSysex(pData, Size);
167            SysexListenersReader.Unlock();
168      }      }
169    
170      void MidiInputPort::DispatchProgramChange(uint8_t Program, uint MidiChannel) {      void MidiInputPort::DispatchProgramChange(uint8_t Program, uint MidiChannel) {
# Line 250  namespace LinuxSampler { Line 254  namespace LinuxSampler {
254          pEngineChannel->StatusChanged(true);          pEngineChannel->StatusChanged(true);
255      }      }
256    
257        SynchronizedConfig<std::set<LinuxSampler::Engine*> > MidiInputPort::SysexListeners;
258    
259        void MidiInputPort::AddSysexListener(Engine* engine) {
260            std::pair<std::set<Engine*>::iterator, bool> p = SysexListeners.GetConfigForUpdate().insert(engine);
261            if (p.second) SysexListeners.SwitchConfig().insert(engine);
262        }
263    
264        bool MidiInputPort::RemoveSysexListener(Engine* engine) {
265            int count = SysexListeners.GetConfigForUpdate().erase(engine);
266            if (count) SysexListeners.SwitchConfig().erase(engine);
267            return count;
268        }
269    
270  } // namespace LinuxSampler  } // namespace LinuxSampler

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

  ViewVC Help
Powered by ViewVC