21 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
***************************************************************************/ |
23 |
|
|
24 |
|
#include <algorithm> |
25 |
|
|
26 |
#include "lscpserver.h" |
#include "lscpserver.h" |
27 |
#include "lscpresultset.h" |
#include "lscpresultset.h" |
28 |
#include "lscpevent.h" |
#include "lscpevent.h" |
133 |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
134 |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
135 |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI"); |
136 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_device_midi, "DEVICE_MIDI"); |
137 |
hSocket = -1; |
hSocket = -1; |
138 |
} |
} |
139 |
|
|
210 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount)); |
211 |
} |
} |
212 |
|
|
213 |
|
void LSCPServer::EventHandler::MidiDeviceToBeDestroyed(MidiInputDevice* pDevice) { |
214 |
|
pDevice->RemoveMidiPortCountListener(this); |
215 |
|
for (int i = 0; i < pDevice->PortCount(); ++i) |
216 |
|
MidiPortToBeRemoved(pDevice->GetPort(i)); |
217 |
|
} |
218 |
|
|
219 |
|
void LSCPServer::EventHandler::MidiDeviceCreated(MidiInputDevice* pDevice) { |
220 |
|
pDevice->AddMidiPortCountListener(this); |
221 |
|
for (int i = 0; i < pDevice->PortCount(); ++i) |
222 |
|
MidiPortAdded(pDevice->GetPort(i)); |
223 |
|
} |
224 |
|
|
225 |
|
void LSCPServer::EventHandler::MidiPortCountChanged(int NewCount) { |
226 |
|
// yet unused |
227 |
|
} |
228 |
|
|
229 |
|
void LSCPServer::EventHandler::MidiPortToBeRemoved(MidiInputPort* pPort) { |
230 |
|
for (std::vector<device_midi_listener_entry>::iterator iter = deviceMidiListeners.begin(); iter != deviceMidiListeners.end(); ++iter) { |
231 |
|
if ((*iter).pPort == pPort) { |
232 |
|
VirtualMidiDevice* pMidiListener = (*iter).pMidiListener; |
233 |
|
pPort->Disconnect(pMidiListener); |
234 |
|
deviceMidiListeners.erase(iter); |
235 |
|
delete pMidiListener; |
236 |
|
return; |
237 |
|
} |
238 |
|
} |
239 |
|
} |
240 |
|
|
241 |
|
void LSCPServer::EventHandler::MidiPortAdded(MidiInputPort* pPort) { |
242 |
|
// find out the device ID |
243 |
|
std::map<uint, MidiInputDevice*> devices = |
244 |
|
pParent->pSampler->GetMidiInputDevices(); |
245 |
|
for ( |
246 |
|
std::map<uint, MidiInputDevice*>::iterator iter = devices.begin(); |
247 |
|
iter != devices.end(); ++iter |
248 |
|
) { |
249 |
|
if (iter->second == pPort->GetDevice()) { // found |
250 |
|
VirtualMidiDevice* pMidiListener = new VirtualMidiDevice; |
251 |
|
pPort->Connect(pMidiListener); |
252 |
|
device_midi_listener_entry entry = { |
253 |
|
pPort, pMidiListener, iter->first |
254 |
|
}; |
255 |
|
deviceMidiListeners.push_back(entry); |
256 |
|
return; |
257 |
|
} |
258 |
|
} |
259 |
|
} |
260 |
|
|
261 |
void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) { |
void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) { |
262 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount)); |
263 |
} |
} |
424 |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
425 |
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
426 |
if ((*itEngineChannel)->StatusChanged()) { |
if ((*itEngineChannel)->StatusChanged()) { |
427 |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->GetSamplerChannel()->Index())); |
428 |
} |
} |
429 |
|
|
430 |
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
431 |
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
432 |
if(fxs != NULL && fxs->IsInfoChanged()) { |
if(fxs != NULL && fxs->IsInfoChanged()) { |
433 |
int chn = (*itEngineChannel)->iSamplerChannelIndex; |
int chn = (*itEngineChannel)->GetSamplerChannel()->Index(); |
434 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id())); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id())); |
435 |
fxs->SetInfoChanged(false); |
fxs->SetInfoChanged(false); |
436 |
} |
} |
462 |
} |
} |
463 |
} |
} |
464 |
|
|
465 |
|
// check if MIDI data arrived on some MIDI device |
466 |
|
for (int i = 0; i < eventHandler.deviceMidiListeners.size(); ++i) { |
467 |
|
const EventHandler::device_midi_listener_entry entry = |
468 |
|
eventHandler.deviceMidiListeners[i]; |
469 |
|
VirtualMidiDevice* pMidiListener = entry.pMidiListener; |
470 |
|
if (pMidiListener->NotesChanged()) { |
471 |
|
for (int iNote = 0; iNote < 128; iNote++) { |
472 |
|
if (pMidiListener->NoteChanged(iNote)) { |
473 |
|
const bool bActive = pMidiListener->NoteIsActive(iNote); |
474 |
|
LSCPServer::SendLSCPNotify( |
475 |
|
LSCPEvent( |
476 |
|
LSCPEvent::event_device_midi, |
477 |
|
entry.uiDeviceID, |
478 |
|
entry.pPort->GetPortNumber(), |
479 |
|
std::string(bActive ? "NOTE_ON" : "NOTE_OFF"), |
480 |
|
iNote, |
481 |
|
bActive ? pMidiListener->NoteOnVelocity(iNote) |
482 |
|
: pMidiListener->NoteOffVelocity(iNote) |
483 |
|
) |
484 |
|
); |
485 |
|
} |
486 |
|
} |
487 |
|
} |
488 |
|
} |
489 |
|
|
490 |
//Now let's deliver late notifies (if any) |
//Now let's deliver late notifies (if any) |
491 |
NotifyBufferMutex.Lock(); |
NotifyBufferMutex.Lock(); |
492 |
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
2557 |
LSCPResultSet result; |
LSCPResultSet result; |
2558 |
try { |
try { |
2559 |
if (dVolume < 0) throw Exception("Volume may not be negative"); |
if (dVolume < 0) throw Exception("Volume may not be negative"); |
2560 |
GLOBAL_VOLUME = dVolume; // see common/global.cpp |
GLOBAL_VOLUME = dVolume; // see common/global_private.cpp |
2561 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME)); |
2562 |
} catch (Exception e) { |
} catch (Exception e) { |
2563 |
result.Error(e); |
result.Error(e); |
3098 |
} catch (Exception e) { |
} catch (Exception e) { |
3099 |
result.Error(e); |
result.Error(e); |
3100 |
} |
} |
3101 |
|
#else |
3102 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3103 |
|
#endif |
3104 |
|
return result.Produce(); |
3105 |
|
} |
3106 |
|
|
3107 |
|
String LSCPServer::SetDbInstrumentFilePath(String OldPath, String NewPath) { |
3108 |
|
dmsg(2,("LSCPServer: SetDbInstrumentFilePath(OldPath=%s,NewPath=%s)\n", OldPath.c_str(), NewPath.c_str())); |
3109 |
|
LSCPResultSet result; |
3110 |
|
#if HAVE_SQLITE3 |
3111 |
|
try { |
3112 |
|
InstrumentsDb::GetInstrumentsDb()->SetInstrumentFilePath(OldPath, NewPath); |
3113 |
|
} catch (Exception e) { |
3114 |
|
result.Error(e); |
3115 |
|
} |
3116 |
|
#else |
3117 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3118 |
|
#endif |
3119 |
|
return result.Produce(); |
3120 |
|
} |
3121 |
|
|
3122 |
|
String LSCPServer::FindLostDbInstrumentFiles() { |
3123 |
|
dmsg(2,("LSCPServer: FindLostDbInstrumentFiles()\n")); |
3124 |
|
LSCPResultSet result; |
3125 |
|
#if HAVE_SQLITE3 |
3126 |
|
try { |
3127 |
|
String list; |
3128 |
|
StringListPtr pLostFiles = InstrumentsDb::GetInstrumentsDb()->FindLostInstrumentFiles(); |
3129 |
|
|
3130 |
|
for (int i = 0; i < pLostFiles->size(); i++) { |
3131 |
|
if (list != "") list += ","; |
3132 |
|
list += "'" + pLostFiles->at(i) + "'"; |
3133 |
|
} |
3134 |
|
|
3135 |
|
result.Add(list); |
3136 |
|
} catch (Exception e) { |
3137 |
|
result.Error(e); |
3138 |
|
} |
3139 |
#else |
#else |
3140 |
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3141 |
#endif |
#endif |