131 |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
132 |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
133 |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI"); |
134 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_device_midi, "DEVICE_MIDI"); |
135 |
hSocket = -1; |
hSocket = -1; |
136 |
} |
} |
137 |
|
|
208 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount)); |
209 |
} |
} |
210 |
|
|
211 |
|
void LSCPServer::EventHandler::MidiDeviceToBeDestroyed(MidiInputDevice* pDevice) { |
212 |
|
pDevice->RemoveMidiPortCountListener(this); |
213 |
|
for (int i = 0; i < pDevice->PortCount(); ++i) |
214 |
|
MidiPortToBeRemoved(pDevice->GetPort(i)); |
215 |
|
} |
216 |
|
|
217 |
|
void LSCPServer::EventHandler::MidiDeviceCreated(MidiInputDevice* pDevice) { |
218 |
|
pDevice->AddMidiPortCountListener(this); |
219 |
|
for (int i = 0; i < pDevice->PortCount(); ++i) |
220 |
|
MidiPortAdded(pDevice->GetPort(i)); |
221 |
|
} |
222 |
|
|
223 |
|
void LSCPServer::EventHandler::MidiPortCountChanged(int NewCount) { |
224 |
|
// yet unused |
225 |
|
} |
226 |
|
|
227 |
|
void LSCPServer::EventHandler::MidiPortToBeRemoved(MidiInputPort* pPort) { |
228 |
|
for (std::vector<device_midi_listener_entry>::iterator iter = deviceMidiListeners.begin(); iter != deviceMidiListeners.end(); ++iter) { |
229 |
|
if ((*iter).pPort == pPort) { |
230 |
|
VirtualMidiDevice* pMidiListener = (*iter).pMidiListener; |
231 |
|
pPort->Disconnect(pMidiListener); |
232 |
|
deviceMidiListeners.erase(iter); |
233 |
|
delete pMidiListener; |
234 |
|
return; |
235 |
|
} |
236 |
|
} |
237 |
|
} |
238 |
|
|
239 |
|
void LSCPServer::EventHandler::MidiPortAdded(MidiInputPort* pPort) { |
240 |
|
// find out the device ID |
241 |
|
std::map<uint, MidiInputDevice*> devices = |
242 |
|
pParent->pSampler->GetMidiInputDevices(); |
243 |
|
for ( |
244 |
|
std::map<uint, MidiInputDevice*>::iterator iter = devices.begin(); |
245 |
|
iter != devices.end(); ++iter |
246 |
|
) { |
247 |
|
if (iter->second == pPort->GetDevice()) { // found |
248 |
|
VirtualMidiDevice* pMidiListener = new VirtualMidiDevice; |
249 |
|
pPort->Connect(pMidiListener); |
250 |
|
device_midi_listener_entry entry = { |
251 |
|
pPort, pMidiListener, iter->first |
252 |
|
}; |
253 |
|
deviceMidiListeners.push_back(entry); |
254 |
|
return; |
255 |
|
} |
256 |
|
} |
257 |
|
} |
258 |
|
|
259 |
void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) { |
void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) { |
260 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount)); |
261 |
} |
} |
452 |
std::string(bActive ? "NOTE_ON" : "NOTE_OFF"), |
std::string(bActive ? "NOTE_ON" : "NOTE_OFF"), |
453 |
iNote, |
iNote, |
454 |
bActive ? pMidiListener->NoteOnVelocity(iNote) |
bActive ? pMidiListener->NoteOnVelocity(iNote) |
455 |
|
: pMidiListener->NoteOffVelocity(iNote) |
456 |
|
) |
457 |
|
); |
458 |
|
} |
459 |
|
} |
460 |
|
} |
461 |
|
} |
462 |
|
|
463 |
|
// check if MIDI data arrived on some MIDI device |
464 |
|
for (int i = 0; i < eventHandler.deviceMidiListeners.size(); ++i) { |
465 |
|
const EventHandler::device_midi_listener_entry entry = |
466 |
|
eventHandler.deviceMidiListeners[i]; |
467 |
|
VirtualMidiDevice* pMidiListener = entry.pMidiListener; |
468 |
|
if (pMidiListener->NotesChanged()) { |
469 |
|
for (int iNote = 0; iNote < 128; iNote++) { |
470 |
|
if (pMidiListener->NoteChanged(iNote)) { |
471 |
|
const bool bActive = pMidiListener->NoteIsActive(iNote); |
472 |
|
LSCPServer::SendLSCPNotify( |
473 |
|
LSCPEvent( |
474 |
|
LSCPEvent::event_device_midi, |
475 |
|
entry.uiDeviceID, |
476 |
|
entry.pPort->GetPortNumber(), |
477 |
|
std::string(bActive ? "NOTE_ON" : "NOTE_OFF"), |
478 |
|
iNote, |
479 |
|
bActive ? pMidiListener->NoteOnVelocity(iNote) |
480 |
: pMidiListener->NoteOffVelocity(iNote) |
: pMidiListener->NoteOffVelocity(iNote) |
481 |
) |
) |
482 |
); |
); |