/[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 244 by schoenebeck, Fri Sep 17 01:01:11 2004 UTC revision 411 by schoenebeck, Sat Feb 26 02:01:14 2005 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6     *   Copyright (C) 2005 Christian Schoenebeck                              *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 84  namespace LinuxSampler { Line 85  namespace LinuxSampler {
85      }      }
86    
87      void MidiInputPort::DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel) {      void MidiInputPort::DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel) {
88          std::set<Engine*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();          // dispatch event for engines listening to the same MIDI channel
89          std::set<Engine*>::iterator end        = MidiChannelMap[MidiChannel].end();          {
90          for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity);              std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
91                std::set<EngineChannel*>::iterator end        = MidiChannelMap[MidiChannel].end();
92                for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity);
93            }
94            // dispatch event for engines listening to ALL MIDI channels
95            {
96                std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();
97                std::set<EngineChannel*>::iterator end        = MidiChannelMap[midi_chan_all].end();
98                for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity);
99            }
100      }      }
101    
102      void MidiInputPort::DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel) {      void MidiInputPort::DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel) {
103          std::set<Engine*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();          // dispatch event for engines listening to the same MIDI channel
104          std::set<Engine*>::iterator end        = MidiChannelMap[MidiChannel].end();          {
105          for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity);              std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
106                std::set<EngineChannel*>::iterator end        = MidiChannelMap[MidiChannel].end();
107                for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity);
108            }
109            // dispatch event for engines listening to ALL MIDI channels
110            {
111                std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();
112                std::set<EngineChannel*>::iterator end        = MidiChannelMap[midi_chan_all].end();
113                for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity);
114            }
115      }      }
116    
117      void MidiInputPort::DispatchPitchbend(int Pitch, uint MidiChannel) {      void MidiInputPort::DispatchPitchbend(int Pitch, uint MidiChannel) {
118          std::set<Engine*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();          // dispatch event for engines listening to the same MIDI channel
119          std::set<Engine*>::iterator end        = MidiChannelMap[MidiChannel].end();          {
120          for (; engineiter != end; engineiter++) (*engineiter)->SendPitchbend(Pitch);              std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
121                std::set<EngineChannel*>::iterator end        = MidiChannelMap[MidiChannel].end();
122                for (; engineiter != end; engineiter++) (*engineiter)->SendPitchbend(Pitch);
123            }
124            // dispatch event for engines listening to ALL MIDI channels
125            {
126                std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();
127                std::set<EngineChannel*>::iterator end        = MidiChannelMap[midi_chan_all].end();
128                for (; engineiter != end; engineiter++) (*engineiter)->SendPitchbend(Pitch);
129            }
130      }      }
131    
132      void MidiInputPort::DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel) {      void MidiInputPort::DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel) {
133          std::set<Engine*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();          // dispatch event for engines listening to the same MIDI channel
134          std::set<Engine*>::iterator end        = MidiChannelMap[MidiChannel].end();          {
135          for (; engineiter != end; engineiter++) (*engineiter)->SendControlChange(Controller, Value);              std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
136                std::set<EngineChannel*>::iterator end        = MidiChannelMap[MidiChannel].end();
137                for (; engineiter != end; engineiter++) (*engineiter)->SendControlChange(Controller, Value);
138            }
139            // dispatch event for engines listening to ALL MIDI channels
140            {
141                std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();
142                std::set<EngineChannel*>::iterator end        = MidiChannelMap[midi_chan_all].end();
143                for (; engineiter != end; engineiter++) (*engineiter)->SendControlChange(Controller, Value);
144            }
145      }      }
146    
147      void MidiInputPort::DispatchSysex(void* pData, uint Size) {      void MidiInputPort::DispatchSysex(void* pData, uint Size) {
148          for (uint MidiChannel = 0; MidiChannel <= 16; MidiChannel++) {          // dispatch event for engines listening to the same MIDI channel
149              std::set<Engine*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();          {
150              std::set<Engine*>::iterator end        = MidiChannelMap[MidiChannel].end();              for (uint MidiChannel = 0; MidiChannel <= 16; MidiChannel++) {
151              for (; engineiter != end; engineiter++) (*engineiter)->SendSysex(pData, Size);                  std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[MidiChannel].begin();
152                    std::set<EngineChannel*>::iterator end        = MidiChannelMap[MidiChannel].end();
153                    for (; engineiter != end; engineiter++) {
154                        Engine* pEngine = (*engineiter)->GetEngine();
155                        if (pEngine) pEngine->SendSysex(pData, Size);
156                    }
157                }
158            }
159            // dispatch event for engines listening to ALL MIDI channels
160            {
161                for (uint MidiChannel = 0; MidiChannel <= 16; MidiChannel++) {
162                    std::set<EngineChannel*>::iterator engineiter = MidiChannelMap[midi_chan_all].begin();
163                    std::set<EngineChannel*>::iterator end        = MidiChannelMap[midi_chan_all].end();
164                    for (; engineiter != end; engineiter++) {
165                        Engine* pEngine = (*engineiter)->GetEngine();
166                        if (pEngine) pEngine->SendSysex(pData, Size);
167                    }
168                }
169          }          }
170      }      }
171    
172      void MidiInputPort::Connect(Engine* pEngine, midi_chan_t MidiChannel) {      void MidiInputPort::Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel) {
173          if (MidiChannel < 0 || MidiChannel > 16)          if (MidiChannel < 0 || MidiChannel > 16)
174              throw MidiInputException("MIDI channel index out of bounds");              throw MidiInputException("MIDI channel index out of bounds");
175          Disconnect(pEngine);          Disconnect(pEngineChannel);
176          MidiChannelMap[MidiChannel].insert(pEngine);          MidiChannelMap[MidiChannel].insert(pEngineChannel);
177      }      }
178    
179      void MidiInputPort::Disconnect(Engine* pEngine) {      void MidiInputPort::Disconnect(EngineChannel* pEngineChannel) {
180          try { for (int i = 0; i <= 16; i++) MidiChannelMap[i].erase(pEngine); }          try { for (int i = 0; i <= 16; i++) MidiChannelMap[i].erase(pEngineChannel); }
181          catch(...) { /* NOOP */ }          catch(...) { /* NOOP */ }
182      }      }
183    

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

  ViewVC Help
Powered by ViewVC