172 |
} |
} |
173 |
} |
} |
174 |
|
|
175 |
void MidiInputPort::DispatchProgramChange(uint8_t Program, uint MidiChannel) { |
void MidiInputPort::DispatchProgramChange(uint8_t Program, uint MidiChannel) { |
176 |
if (!pDevice || !pDevice->pSampler) { |
if (!pDevice || !pDevice->pSampler) { |
177 |
std::cerr << "MidiInputPort: ERROR, no sampler instance to handle program change." |
std::cerr << "MidiInputPort: ERROR, no sampler instance to handle program change." |
178 |
<< "This is a bug, please report it!\n" << std::flush; |
<< "This is a bug, please report it!\n" << std::flush; |
189 |
// disconnect from the engine channel which was connected by the last PC event |
// disconnect from the engine channel which was connected by the last PC event |
190 |
if (pPreviousProgramChangeEngineChannel) |
if (pPreviousProgramChangeEngineChannel) |
191 |
Disconnect(pPreviousProgramChangeEngineChannel); |
Disconnect(pPreviousProgramChangeEngineChannel); |
192 |
|
|
193 |
// now connect to the new engine channel and remember it |
// now connect to the new engine channel and remember it |
194 |
try { |
try { |
195 |
Connect(pEngineChannel, (midi_chan_t) MidiChannel); |
Connect(pEngineChannel, (midi_chan_t) MidiChannel); |
201 |
void MidiInputPort::Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel) { |
void MidiInputPort::Connect(EngineChannel* pEngineChannel, midi_chan_t MidiChannel) { |
202 |
if (MidiChannel < 0 || MidiChannel > 16) |
if (MidiChannel < 0 || MidiChannel > 16) |
203 |
throw MidiInputException("MIDI channel index out of bounds"); |
throw MidiInputException("MIDI channel index out of bounds"); |
204 |
|
|
205 |
Disconnect(pEngineChannel); |
Disconnect(pEngineChannel); |
206 |
|
|
207 |
MidiChannelMapMutex.Lock(); |
MidiChannelMapMutex.Lock(); |
208 |
MidiChannelMap[MidiChannel].insert(pEngineChannel); |
MidiChannelMap[MidiChannel].insert(pEngineChannel); |
209 |
MidiChannelMapMutex.Unlock(); |
MidiChannelMapMutex.Unlock(); |
210 |
|
|
211 |
|
// mark engine channel as changed |
212 |
|
pEngineChannel->StatusChanged(true); |
213 |
} |
} |
214 |
|
|
215 |
void MidiInputPort::Disconnect(EngineChannel* pEngineChannel) { |
void MidiInputPort::Disconnect(EngineChannel* pEngineChannel) { |
217 |
try { for (int i = 0; i <= 16; i++) MidiChannelMap[i].erase(pEngineChannel); } |
try { for (int i = 0; i <= 16; i++) MidiChannelMap[i].erase(pEngineChannel); } |
218 |
catch(...) { /* NOOP */ } |
catch(...) { /* NOOP */ } |
219 |
MidiChannelMapMutex.Unlock(); |
MidiChannelMapMutex.Unlock(); |
220 |
|
// mark engine channel as changed |
221 |
|
pEngineChannel->StatusChanged(true); |
222 |
} |
} |
223 |
|
|
224 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |