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 * |
* Copyright (C) 2005, 2006 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 * |
51 |
return std::vector<String>(); |
return std::vector<String>(); |
52 |
} |
} |
53 |
|
|
54 |
void MidiInputPort::ParameterName::OnSetValue(String s) throw (LinuxSamplerException) { |
void MidiInputPort::ParameterName::OnSetValue(String s) throw (Exception) { |
55 |
return; /* FIXME: Nothing to do here */ |
return; /* FIXME: Nothing to do here */ |
56 |
} |
} |
57 |
|
|
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); |
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(); |
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::DispatchNoteOn(uint8_t Key, uint8_t Velocity, uint MidiChannel, int32_t FragmentPos) { |
111 |
|
const MidiChannelMap_t& midiChannelMap = MidiChannelMapReader.Lock(); |
112 |
|
// dispatch event for engines listening to the same MIDI channel |
113 |
|
{ |
114 |
|
std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin(); |
115 |
|
std::set<EngineChannel*>::iterator end = midiChannelMap[MidiChannel].end(); |
116 |
|
for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity, FragmentPos); |
117 |
|
} |
118 |
|
// dispatch event for engines listening to ALL MIDI channels |
119 |
|
{ |
120 |
|
std::set<EngineChannel*>::iterator engineiter = midiChannelMap[midi_chan_all].begin(); |
121 |
|
std::set<EngineChannel*>::iterator end = midiChannelMap[midi_chan_all].end(); |
122 |
|
for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOn(Key, Velocity, FragmentPos); |
123 |
|
} |
124 |
|
MidiChannelMapReader.Unlock(); |
125 |
} |
} |
126 |
|
|
127 |
void MidiInputPort::DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel) { |
void MidiInputPort::DispatchNoteOff(uint8_t Key, uint8_t Velocity, 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(); |
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)->SendNoteOff(Key, Velocity); |
for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity); |
140 |
} |
} |
141 |
MidiChannelMap.Unlock(); |
MidiChannelMapReader.Unlock(); |
142 |
|
} |
143 |
|
|
144 |
|
void MidiInputPort::DispatchNoteOff(uint8_t Key, uint8_t Velocity, uint MidiChannel, int32_t FragmentPos) { |
145 |
|
const MidiChannelMap_t& midiChannelMap = MidiChannelMapReader.Lock(); |
146 |
|
// dispatch event for engines listening to the same MIDI channel |
147 |
|
{ |
148 |
|
std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin(); |
149 |
|
std::set<EngineChannel*>::iterator end = midiChannelMap[MidiChannel].end(); |
150 |
|
for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity, FragmentPos); |
151 |
|
} |
152 |
|
// dispatch event for engines listening to ALL MIDI channels |
153 |
|
{ |
154 |
|
std::set<EngineChannel*>::iterator engineiter = midiChannelMap[midi_chan_all].begin(); |
155 |
|
std::set<EngineChannel*>::iterator end = midiChannelMap[midi_chan_all].end(); |
156 |
|
for (; engineiter != end; engineiter++) (*engineiter)->SendNoteOff(Key, Velocity, FragmentPos); |
157 |
|
} |
158 |
|
MidiChannelMapReader.Unlock(); |
159 |
} |
} |
160 |
|
|
161 |
void MidiInputPort::DispatchPitchbend(int Pitch, uint MidiChannel) { |
void MidiInputPort::DispatchPitchbend(int Pitch, uint MidiChannel) { |
162 |
const MidiChannelMap_t& midiChannelMap = MidiChannelMap.Lock(); |
const MidiChannelMap_t& midiChannelMap = MidiChannelMapReader.Lock(); |
163 |
// dispatch event for engines listening to the same MIDI channel |
// dispatch event for engines listening to the same MIDI channel |
164 |
{ |
{ |
165 |
std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin(); |
std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin(); |
172 |
std::set<EngineChannel*>::iterator end = midiChannelMap[midi_chan_all].end(); |
std::set<EngineChannel*>::iterator end = midiChannelMap[midi_chan_all].end(); |
173 |
for (; engineiter != end; engineiter++) (*engineiter)->SendPitchbend(Pitch); |
for (; engineiter != end; engineiter++) (*engineiter)->SendPitchbend(Pitch); |
174 |
} |
} |
175 |
MidiChannelMap.Unlock(); |
MidiChannelMapReader.Unlock(); |
176 |
|
} |
177 |
|
|
178 |
|
void MidiInputPort::DispatchPitchbend(int Pitch, uint MidiChannel, int32_t FragmentPos) { |
179 |
|
const MidiChannelMap_t& midiChannelMap = MidiChannelMapReader.Lock(); |
180 |
|
// dispatch event for engines listening to the same MIDI channel |
181 |
|
{ |
182 |
|
std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin(); |
183 |
|
std::set<EngineChannel*>::iterator end = midiChannelMap[MidiChannel].end(); |
184 |
|
for (; engineiter != end; engineiter++) (*engineiter)->SendPitchbend(Pitch, FragmentPos); |
185 |
|
} |
186 |
|
// dispatch event for engines listening to ALL MIDI channels |
187 |
|
{ |
188 |
|
std::set<EngineChannel*>::iterator engineiter = midiChannelMap[midi_chan_all].begin(); |
189 |
|
std::set<EngineChannel*>::iterator end = midiChannelMap[midi_chan_all].end(); |
190 |
|
for (; engineiter != end; engineiter++) (*engineiter)->SendPitchbend(Pitch, FragmentPos); |
191 |
|
} |
192 |
|
MidiChannelMapReader.Unlock(); |
193 |
} |
} |
194 |
|
|
195 |
void MidiInputPort::DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel) { |
void MidiInputPort::DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel) { |
196 |
const MidiChannelMap_t& midiChannelMap = MidiChannelMap.Lock(); |
const MidiChannelMap_t& midiChannelMap = MidiChannelMapReader.Lock(); |
197 |
// dispatch event for engines listening to the same MIDI channel |
// dispatch event for engines listening to the same MIDI channel |
198 |
{ |
{ |
199 |
std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin(); |
std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin(); |
206 |
std::set<EngineChannel*>::iterator end = midiChannelMap[midi_chan_all].end(); |
std::set<EngineChannel*>::iterator end = midiChannelMap[midi_chan_all].end(); |
207 |
for (; engineiter != end; engineiter++) (*engineiter)->SendControlChange(Controller, Value); |
for (; engineiter != end; engineiter++) (*engineiter)->SendControlChange(Controller, Value); |
208 |
} |
} |
209 |
MidiChannelMap.Unlock(); |
MidiChannelMapReader.Unlock(); |
210 |
|
} |
211 |
|
|
212 |
|
void MidiInputPort::DispatchControlChange(uint8_t Controller, uint8_t Value, uint MidiChannel, int32_t FragmentPos) { |
213 |
|
const MidiChannelMap_t& midiChannelMap = MidiChannelMapReader.Lock(); |
214 |
|
// dispatch event for engines listening to the same MIDI channel |
215 |
|
{ |
216 |
|
std::set<EngineChannel*>::iterator engineiter = midiChannelMap[MidiChannel].begin(); |
217 |
|
std::set<EngineChannel*>::iterator end = midiChannelMap[MidiChannel].end(); |
218 |
|
for (; engineiter != end; engineiter++) (*engineiter)->SendControlChange(Controller, Value, FragmentPos); |
219 |
|
} |
220 |
|
// dispatch event for engines listening to ALL MIDI channels |
221 |
|
{ |
222 |
|
std::set<EngineChannel*>::iterator engineiter = midiChannelMap[midi_chan_all].begin(); |
223 |
|
std::set<EngineChannel*>::iterator end = midiChannelMap[midi_chan_all].end(); |
224 |
|
for (; engineiter != end; engineiter++) (*engineiter)->SendControlChange(Controller, Value, FragmentPos); |
225 |
|
} |
226 |
|
MidiChannelMapReader.Unlock(); |
227 |
} |
} |
228 |
|
|
229 |
void MidiInputPort::DispatchSysex(void* pData, uint Size) { |
void MidiInputPort::DispatchSysex(void* pData, uint Size) { |
230 |
|
const std::set<Engine*> allEngines = SysexListenersReader.Lock(); |
231 |
// dispatch event to all engine instances |
// dispatch event to all engine instances |
232 |
std::set<Engine*>::iterator engineiter = EngineFactory::EngineInstances().begin(); |
std::set<Engine*>::iterator engineiter = allEngines.begin(); |
233 |
std::set<Engine*>::iterator end = EngineFactory::EngineInstances().end(); |
std::set<Engine*>::iterator end = allEngines.end(); |
234 |
for (; engineiter != end; engineiter++) (*engineiter)->SendSysex(pData, Size); |
for (; engineiter != end; engineiter++) (*engineiter)->SendSysex(pData, Size); |
235 |
|
SysexListenersReader.Unlock(); |
236 |
} |
} |
237 |
|
|
238 |
void MidiInputPort::DispatchProgramChange(uint8_t Program, uint MidiChannel) { |
void MidiInputPort::DispatchProgramChange(uint8_t Program, uint MidiChannel) { |
322 |
pEngineChannel->StatusChanged(true); |
pEngineChannel->StatusChanged(true); |
323 |
} |
} |
324 |
|
|
325 |
|
SynchronizedConfig<std::set<LinuxSampler::Engine*> > MidiInputPort::SysexListeners; |
326 |
|
|
327 |
|
void MidiInputPort::AddSysexListener(Engine* engine) { |
328 |
|
std::pair<std::set<Engine*>::iterator, bool> p = SysexListeners.GetConfigForUpdate().insert(engine); |
329 |
|
if (p.second) SysexListeners.SwitchConfig().insert(engine); |
330 |
|
} |
331 |
|
|
332 |
|
bool MidiInputPort::RemoveSysexListener(Engine* engine) { |
333 |
|
int count = SysexListeners.GetConfigForUpdate().erase(engine); |
334 |
|
if (count) SysexListeners.SwitchConfig().erase(engine); |
335 |
|
return count; |
336 |
|
} |
337 |
|
|
338 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |