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 - 2007 Christian Schoenebeck * |
* Copyright (C) 2005 - 2009 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This library is free software; you can redistribute it and/or modify * |
* This library 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 * |
21 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
***************************************************************************/ |
23 |
|
|
24 |
|
#include <algorithm> |
25 |
|
#include <string> |
26 |
|
|
27 |
|
#include "../common/File.h" |
28 |
#include "lscpserver.h" |
#include "lscpserver.h" |
29 |
#include "lscpresultset.h" |
#include "lscpresultset.h" |
30 |
#include "lscpevent.h" |
#include "lscpevent.h" |
44 |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
45 |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
46 |
|
|
47 |
|
namespace LinuxSampler { |
48 |
|
|
49 |
/** |
/** |
50 |
* Returns a copy of the given string where all special characters are |
* Returns a copy of the given string where all special characters are |
106 |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
107 |
Mutex LSCPServer::RTNotifyMutex = Mutex(); |
Mutex LSCPServer::RTNotifyMutex = Mutex(); |
108 |
|
|
109 |
LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4) { |
LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4), eventHandler(this) { |
110 |
SocketAddress.sin_family = AF_INET; |
SocketAddress.sin_family = AF_INET; |
111 |
SocketAddress.sin_addr.s_addr = addr; |
SocketAddress.sin_addr.s_addr = addr; |
112 |
SocketAddress.sin_port = port; |
SocketAddress.sin_port = port; |
135 |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_stream_count, "TOTAL_STREAM_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_stream_count, "TOTAL_STREAM_COUNT"); |
136 |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
137 |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
138 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI"); |
139 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_device_midi, "DEVICE_MIDI"); |
140 |
hSocket = -1; |
hSocket = -1; |
141 |
} |
} |
142 |
|
|
143 |
LSCPServer::~LSCPServer() { |
LSCPServer::~LSCPServer() { |
144 |
|
CloseAllConnections(); |
145 |
|
InstrumentManager::StopBackgroundThread(); |
146 |
#if defined(WIN32) |
#if defined(WIN32) |
147 |
if (hSocket >= 0) closesocket(hSocket); |
if (hSocket >= 0) closesocket(hSocket); |
148 |
#else |
#else |
150 |
#endif |
#endif |
151 |
} |
} |
152 |
|
|
153 |
|
LSCPServer::EventHandler::EventHandler(LSCPServer* pParent) { |
154 |
|
this->pParent = pParent; |
155 |
|
} |
156 |
|
|
157 |
|
LSCPServer::EventHandler::~EventHandler() { |
158 |
|
std::vector<midi_listener_entry> l = channelMidiListeners; |
159 |
|
channelMidiListeners.clear(); |
160 |
|
for (int i = 0; i < l.size(); i++) |
161 |
|
delete l[i].pMidiListener; |
162 |
|
} |
163 |
|
|
164 |
void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) { |
void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) { |
165 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount)); |
166 |
} |
} |
167 |
|
|
168 |
|
void LSCPServer::EventHandler::ChannelAdded(SamplerChannel* pChannel) { |
169 |
|
pChannel->AddEngineChangeListener(this); |
170 |
|
} |
171 |
|
|
172 |
|
void LSCPServer::EventHandler::ChannelToBeRemoved(SamplerChannel* pChannel) { |
173 |
|
if (!pChannel->GetEngineChannel()) return; |
174 |
|
EngineToBeChanged(pChannel->Index()); |
175 |
|
} |
176 |
|
|
177 |
|
void LSCPServer::EventHandler::EngineToBeChanged(int ChannelId) { |
178 |
|
SamplerChannel* pSamplerChannel = |
179 |
|
pParent->pSampler->GetSamplerChannel(ChannelId); |
180 |
|
if (!pSamplerChannel) return; |
181 |
|
EngineChannel* pEngineChannel = |
182 |
|
pSamplerChannel->GetEngineChannel(); |
183 |
|
if (!pEngineChannel) return; |
184 |
|
for (std::vector<midi_listener_entry>::iterator iter = channelMidiListeners.begin(); iter != channelMidiListeners.end(); ++iter) { |
185 |
|
if ((*iter).pEngineChannel == pEngineChannel) { |
186 |
|
VirtualMidiDevice* pMidiListener = (*iter).pMidiListener; |
187 |
|
pEngineChannel->Disconnect(pMidiListener); |
188 |
|
channelMidiListeners.erase(iter); |
189 |
|
delete pMidiListener; |
190 |
|
return; |
191 |
|
} |
192 |
|
} |
193 |
|
} |
194 |
|
|
195 |
|
void LSCPServer::EventHandler::EngineChanged(int ChannelId) { |
196 |
|
SamplerChannel* pSamplerChannel = |
197 |
|
pParent->pSampler->GetSamplerChannel(ChannelId); |
198 |
|
if (!pSamplerChannel) return; |
199 |
|
EngineChannel* pEngineChannel = |
200 |
|
pSamplerChannel->GetEngineChannel(); |
201 |
|
if (!pEngineChannel) return; |
202 |
|
VirtualMidiDevice* pMidiListener = new VirtualMidiDevice; |
203 |
|
pEngineChannel->Connect(pMidiListener); |
204 |
|
midi_listener_entry entry = { |
205 |
|
pSamplerChannel, pEngineChannel, pMidiListener |
206 |
|
}; |
207 |
|
channelMidiListeners.push_back(entry); |
208 |
|
} |
209 |
|
|
210 |
void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) { |
void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) { |
211 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount)); |
212 |
} |
} |
215 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount)); |
216 |
} |
} |
217 |
|
|
218 |
|
void LSCPServer::EventHandler::MidiDeviceToBeDestroyed(MidiInputDevice* pDevice) { |
219 |
|
pDevice->RemoveMidiPortCountListener(this); |
220 |
|
for (int i = 0; i < pDevice->PortCount(); ++i) |
221 |
|
MidiPortToBeRemoved(pDevice->GetPort(i)); |
222 |
|
} |
223 |
|
|
224 |
|
void LSCPServer::EventHandler::MidiDeviceCreated(MidiInputDevice* pDevice) { |
225 |
|
pDevice->AddMidiPortCountListener(this); |
226 |
|
for (int i = 0; i < pDevice->PortCount(); ++i) |
227 |
|
MidiPortAdded(pDevice->GetPort(i)); |
228 |
|
} |
229 |
|
|
230 |
|
void LSCPServer::EventHandler::MidiPortCountChanged(int NewCount) { |
231 |
|
// yet unused |
232 |
|
} |
233 |
|
|
234 |
|
void LSCPServer::EventHandler::MidiPortToBeRemoved(MidiInputPort* pPort) { |
235 |
|
for (std::vector<device_midi_listener_entry>::iterator iter = deviceMidiListeners.begin(); iter != deviceMidiListeners.end(); ++iter) { |
236 |
|
if ((*iter).pPort == pPort) { |
237 |
|
VirtualMidiDevice* pMidiListener = (*iter).pMidiListener; |
238 |
|
pPort->Disconnect(pMidiListener); |
239 |
|
deviceMidiListeners.erase(iter); |
240 |
|
delete pMidiListener; |
241 |
|
return; |
242 |
|
} |
243 |
|
} |
244 |
|
} |
245 |
|
|
246 |
|
void LSCPServer::EventHandler::MidiPortAdded(MidiInputPort* pPort) { |
247 |
|
// find out the device ID |
248 |
|
std::map<uint, MidiInputDevice*> devices = |
249 |
|
pParent->pSampler->GetMidiInputDevices(); |
250 |
|
for ( |
251 |
|
std::map<uint, MidiInputDevice*>::iterator iter = devices.begin(); |
252 |
|
iter != devices.end(); ++iter |
253 |
|
) { |
254 |
|
if (iter->second == pPort->GetDevice()) { // found |
255 |
|
VirtualMidiDevice* pMidiListener = new VirtualMidiDevice; |
256 |
|
pPort->Connect(pMidiListener); |
257 |
|
device_midi_listener_entry entry = { |
258 |
|
pPort, pMidiListener, iter->first |
259 |
|
}; |
260 |
|
deviceMidiListeners.push_back(entry); |
261 |
|
return; |
262 |
|
} |
263 |
|
} |
264 |
|
} |
265 |
|
|
266 |
void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) { |
void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) { |
267 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount)); |
268 |
} |
} |
337 |
} |
} |
338 |
#endif // HAVE_SQLITE3 |
#endif // HAVE_SQLITE3 |
339 |
|
|
340 |
|
void LSCPServer::RemoveListeners() { |
341 |
|
pSampler->RemoveChannelCountListener(&eventHandler); |
342 |
|
pSampler->RemoveAudioDeviceCountListener(&eventHandler); |
343 |
|
pSampler->RemoveMidiDeviceCountListener(&eventHandler); |
344 |
|
pSampler->RemoveVoiceCountListener(&eventHandler); |
345 |
|
pSampler->RemoveStreamCountListener(&eventHandler); |
346 |
|
pSampler->RemoveBufferFillListener(&eventHandler); |
347 |
|
pSampler->RemoveTotalStreamCountListener(&eventHandler); |
348 |
|
pSampler->RemoveTotalVoiceCountListener(&eventHandler); |
349 |
|
pSampler->RemoveFxSendCountListener(&eventHandler); |
350 |
|
MidiInstrumentMapper::RemoveMidiInstrumentCountListener(&eventHandler); |
351 |
|
MidiInstrumentMapper::RemoveMidiInstrumentInfoListener(&eventHandler); |
352 |
|
MidiInstrumentMapper::RemoveMidiInstrumentMapCountListener(&eventHandler); |
353 |
|
MidiInstrumentMapper::RemoveMidiInstrumentMapInfoListener(&eventHandler); |
354 |
|
#if HAVE_SQLITE3 |
355 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveInstrumentsDbListener(&dbInstrumentsEventHandler); |
356 |
|
#endif |
357 |
|
} |
358 |
|
|
359 |
/** |
/** |
360 |
* Blocks the calling thread until the LSCP Server is initialized and |
* Blocks the calling thread until the LSCP Server is initialized and |
447 |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
448 |
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
449 |
if ((*itEngineChannel)->StatusChanged()) { |
if ((*itEngineChannel)->StatusChanged()) { |
450 |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->GetSamplerChannel()->Index())); |
451 |
} |
} |
452 |
|
|
453 |
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
454 |
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
455 |
if(fxs != NULL && fxs->IsInfoChanged()) { |
if(fxs != NULL && fxs->IsInfoChanged()) { |
456 |
int chn = (*itEngineChannel)->iSamplerChannelIndex; |
int chn = (*itEngineChannel)->GetSamplerChannel()->Index(); |
457 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id())); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id())); |
458 |
fxs->SetInfoChanged(false); |
fxs->SetInfoChanged(false); |
459 |
} |
} |
461 |
} |
} |
462 |
} |
} |
463 |
|
|
464 |
|
// check if MIDI data arrived on some engine channel |
465 |
|
for (int i = 0; i < eventHandler.channelMidiListeners.size(); ++i) { |
466 |
|
const EventHandler::midi_listener_entry entry = |
467 |
|
eventHandler.channelMidiListeners[i]; |
468 |
|
VirtualMidiDevice* pMidiListener = entry.pMidiListener; |
469 |
|
if (pMidiListener->NotesChanged()) { |
470 |
|
for (int iNote = 0; iNote < 128; iNote++) { |
471 |
|
if (pMidiListener->NoteChanged(iNote)) { |
472 |
|
const bool bActive = pMidiListener->NoteIsActive(iNote); |
473 |
|
LSCPServer::SendLSCPNotify( |
474 |
|
LSCPEvent( |
475 |
|
LSCPEvent::event_channel_midi, |
476 |
|
entry.pSamplerChannel->Index(), |
477 |
|
std::string(bActive ? "NOTE_ON" : "NOTE_OFF"), |
478 |
|
iNote, |
479 |
|
bActive ? pMidiListener->NoteOnVelocity(iNote) |
480 |
|
: pMidiListener->NoteOffVelocity(iNote) |
481 |
|
) |
482 |
|
); |
483 |
|
} |
484 |
|
} |
485 |
|
} |
486 |
|
} |
487 |
|
|
488 |
|
// check if MIDI data arrived on some MIDI device |
489 |
|
for (int i = 0; i < eventHandler.deviceMidiListeners.size(); ++i) { |
490 |
|
const EventHandler::device_midi_listener_entry entry = |
491 |
|
eventHandler.deviceMidiListeners[i]; |
492 |
|
VirtualMidiDevice* pMidiListener = entry.pMidiListener; |
493 |
|
if (pMidiListener->NotesChanged()) { |
494 |
|
for (int iNote = 0; iNote < 128; iNote++) { |
495 |
|
if (pMidiListener->NoteChanged(iNote)) { |
496 |
|
const bool bActive = pMidiListener->NoteIsActive(iNote); |
497 |
|
LSCPServer::SendLSCPNotify( |
498 |
|
LSCPEvent( |
499 |
|
LSCPEvent::event_device_midi, |
500 |
|
entry.uiDeviceID, |
501 |
|
entry.pPort->GetPortNumber(), |
502 |
|
std::string(bActive ? "NOTE_ON" : "NOTE_OFF"), |
503 |
|
iNote, |
504 |
|
bActive ? pMidiListener->NoteOnVelocity(iNote) |
505 |
|
: pMidiListener->NoteOffVelocity(iNote) |
506 |
|
) |
507 |
|
); |
508 |
|
} |
509 |
|
} |
510 |
|
} |
511 |
|
} |
512 |
|
|
513 |
//Now let's deliver late notifies (if any) |
//Now let's deliver late notifies (if any) |
514 |
NotifyBufferMutex.Lock(); |
NotifyBufferMutex.Lock(); |
515 |
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++) { |
528 |
|
|
529 |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
530 |
|
|
531 |
if (retval == 0) |
if (retval == 0 || (retval == -1 && errno == EINTR)) |
532 |
continue; //Nothing try again |
continue; //Nothing try again |
533 |
if (retval == -1) { |
if (retval == -1) { |
534 |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
555 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
556 |
} |
} |
557 |
#else |
#else |
558 |
|
struct linger linger; |
559 |
|
linger.l_onoff = 1; |
560 |
|
linger.l_linger = 0; |
561 |
|
if(setsockopt(socket, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger))) { |
562 |
|
std::cerr << "LSCPServer: Failed to set SO_LINGER\n"; |
563 |
|
} |
564 |
|
|
565 |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
566 |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
567 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
633 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
634 |
} |
} |
635 |
|
|
636 |
|
void LSCPServer::CloseAllConnections() { |
637 |
|
std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); |
638 |
|
while(iter != Sessions.end()) { |
639 |
|
CloseConnection(iter); |
640 |
|
iter = Sessions.begin(); |
641 |
|
} |
642 |
|
} |
643 |
|
|
644 |
void LSCPServer::LockRTNotify() { |
void LSCPServer::LockRTNotify() { |
645 |
RTNotifyMutex.Lock(); |
RTNotifyMutex.Lock(); |
646 |
} |
} |
1171 |
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
1172 |
LSCPResultSet result; |
LSCPResultSet result; |
1173 |
try { |
try { |
1174 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine loaded on sampler channel"); |
|
1175 |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
1176 |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
1177 |
} |
} |
1189 |
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
1190 |
LSCPResultSet result; |
LSCPResultSet result; |
1191 |
try { |
try { |
1192 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
1193 |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
1194 |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
1195 |
} |
} |
1207 |
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); |
1208 |
LSCPResultSet result; |
LSCPResultSet result; |
1209 |
try { |
try { |
1210 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
1211 |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
1212 |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
1213 |
else { |
else { |
1295 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1296 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1297 |
s += iter->first; |
s += iter->first; |
1298 |
|
delete iter->second; |
1299 |
} |
} |
1300 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1301 |
} |
} |
1320 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1321 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1322 |
s += iter->first; |
s += iter->first; |
1323 |
|
delete iter->second; |
1324 |
} |
} |
1325 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1326 |
} |
} |
1351 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1352 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1353 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1354 |
|
delete pParameter; |
1355 |
} |
} |
1356 |
catch (Exception e) { |
catch (Exception e) { |
1357 |
result.Error(e); |
result.Error(e); |
1379 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1380 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1381 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1382 |
|
delete pParameter; |
1383 |
} |
} |
1384 |
catch (Exception e) { |
catch (Exception e) { |
1385 |
result.Error(e); |
result.Error(e); |
1846 |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
1847 |
// Make it with at least one initial port. |
// Make it with at least one initial port. |
1848 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
|
parameters["PORTS"]->SetValue("1"); |
|
1849 |
} |
} |
1850 |
// Must have a device... |
// Must have a device... |
1851 |
if (pDevice == NULL) |
if (pDevice == NULL) |
1888 |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
1889 |
LSCPResultSet result; |
LSCPResultSet result; |
1890 |
try { |
try { |
1891 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
1892 |
pEngineChannel->Volume(dVolume); |
pEngineChannel->Volume(dVolume); |
1893 |
} |
} |
1894 |
catch (Exception e) { |
catch (Exception e) { |
1904 |
dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); |
1905 |
LSCPResultSet result; |
LSCPResultSet result; |
1906 |
try { |
try { |
1907 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
|
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
1908 |
|
|
1909 |
if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); |
if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); |
1910 |
else pEngineChannel->SetMute(1); |
else pEngineChannel->SetMute(1); |
1921 |
dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel)); |
1922 |
LSCPResultSet result; |
LSCPResultSet result; |
1923 |
try { |
try { |
1924 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
|
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
1925 |
|
|
1926 |
bool oldSolo = pEngineChannel->GetSolo(); |
bool oldSolo = pEngineChannel->GetSolo(); |
1927 |
bool hadSoloChannel = HasSoloChannel(); |
bool hadSoloChannel = HasSoloChannel(); |
2041 |
dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n")); |
dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n")); |
2042 |
LSCPResultSet result; |
LSCPResultSet result; |
2043 |
try { |
try { |
2044 |
result.Add(MidiInstrumentMapper::Entries(MidiMapID).size()); |
result.Add(MidiInstrumentMapper::GetInstrumentCount(MidiMapID)); |
2045 |
} catch (Exception e) { |
} catch (Exception e) { |
2046 |
result.Error(e); |
result.Error(e); |
2047 |
} |
} |
2052 |
String LSCPServer::GetAllMidiInstrumentMappings() { |
String LSCPServer::GetAllMidiInstrumentMappings() { |
2053 |
dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n")); |
dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n")); |
2054 |
LSCPResultSet result; |
LSCPResultSet result; |
2055 |
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
try { |
2056 |
int totalMappings = 0; |
result.Add(MidiInstrumentMapper::GetInstrumentCount()); |
2057 |
for (int i = 0; i < maps.size(); i++) { |
} catch (Exception e) { |
2058 |
try { |
result.Error(e); |
|
totalMappings += MidiInstrumentMapper::Entries(maps[i]).size(); |
|
|
} catch (Exception e) { /*NOOP*/ } |
|
2059 |
} |
} |
|
result.Add(totalMappings); |
|
2060 |
return result.Produce(); |
return result.Produce(); |
2061 |
} |
} |
2062 |
|
|
2064 |
dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n")); |
dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n")); |
2065 |
LSCPResultSet result; |
LSCPResultSet result; |
2066 |
try { |
try { |
2067 |
midi_prog_index_t idx; |
MidiInstrumentMapper::entry_t entry = MidiInstrumentMapper::GetEntry(MidiMapID, MidiBank, MidiProg); |
2068 |
idx.midi_bank_msb = (MidiBank >> 7) & 0x7f; |
// convert the filename into the correct encoding as defined for LSCP |
2069 |
idx.midi_bank_lsb = MidiBank & 0x7f; |
// (especially in terms of special characters -> escape sequences) |
|
idx.midi_prog = MidiProg; |
|
|
|
|
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID); |
|
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx); |
|
|
if (iter == mappings.end()) result.Error("there is no map entry with that index"); |
|
|
else { // found |
|
|
|
|
|
// convert the filename into the correct encoding as defined for LSCP |
|
|
// (especially in terms of special characters -> escape sequences) |
|
2070 |
#if WIN32 |
#if WIN32 |
2071 |
const String instrumentFileName = Path::fromWindows(iter->second.InstrumentFile).toLscp(); |
const String instrumentFileName = Path::fromWindows(entry.InstrumentFile).toLscp(); |
2072 |
#else |
#else |
2073 |
// assuming POSIX |
// assuming POSIX |
2074 |
const String instrumentFileName = Path::fromPosix(iter->second.InstrumentFile).toLscp(); |
const String instrumentFileName = Path::fromPosix(entry.InstrumentFile).toLscp(); |
2075 |
#endif |
#endif |
2076 |
|
|
2077 |
result.Add("NAME", _escapeLscpResponse(iter->second.Name)); |
result.Add("NAME", _escapeLscpResponse(entry.Name)); |
2078 |
result.Add("ENGINE_NAME", iter->second.EngineName); |
result.Add("ENGINE_NAME", entry.EngineName); |
2079 |
result.Add("INSTRUMENT_FILE", instrumentFileName); |
result.Add("INSTRUMENT_FILE", instrumentFileName); |
2080 |
result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex); |
result.Add("INSTRUMENT_NR", (int) entry.InstrumentIndex); |
2081 |
String instrumentName; |
String instrumentName; |
2082 |
Engine* pEngine = EngineFactory::Create(iter->second.EngineName); |
Engine* pEngine = EngineFactory::Create(entry.EngineName); |
2083 |
if (pEngine) { |
if (pEngine) { |
2084 |
if (pEngine->GetInstrumentManager()) { |
if (pEngine->GetInstrumentManager()) { |
2085 |
InstrumentManager::instrument_id_t instrID; |
InstrumentManager::instrument_id_t instrID; |
2086 |
instrID.FileName = iter->second.InstrumentFile; |
instrID.FileName = entry.InstrumentFile; |
2087 |
instrID.Index = iter->second.InstrumentIndex; |
instrID.Index = entry.InstrumentIndex; |
2088 |
instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID); |
instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID); |
|
} |
|
|
EngineFactory::Destroy(pEngine); |
|
2089 |
} |
} |
2090 |
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName)); |
EngineFactory::Destroy(pEngine); |
|
switch (iter->second.LoadMode) { |
|
|
case MidiInstrumentMapper::ON_DEMAND: |
|
|
result.Add("LOAD_MODE", "ON_DEMAND"); |
|
|
break; |
|
|
case MidiInstrumentMapper::ON_DEMAND_HOLD: |
|
|
result.Add("LOAD_MODE", "ON_DEMAND_HOLD"); |
|
|
break; |
|
|
case MidiInstrumentMapper::PERSISTENT: |
|
|
result.Add("LOAD_MODE", "PERSISTENT"); |
|
|
break; |
|
|
default: |
|
|
throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!"); |
|
|
} |
|
|
result.Add("VOLUME", iter->second.Volume); |
|
2091 |
} |
} |
2092 |
|
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName)); |
2093 |
|
switch (entry.LoadMode) { |
2094 |
|
case MidiInstrumentMapper::ON_DEMAND: |
2095 |
|
result.Add("LOAD_MODE", "ON_DEMAND"); |
2096 |
|
break; |
2097 |
|
case MidiInstrumentMapper::ON_DEMAND_HOLD: |
2098 |
|
result.Add("LOAD_MODE", "ON_DEMAND_HOLD"); |
2099 |
|
break; |
2100 |
|
case MidiInstrumentMapper::PERSISTENT: |
2101 |
|
result.Add("LOAD_MODE", "PERSISTENT"); |
2102 |
|
break; |
2103 |
|
default: |
2104 |
|
throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!"); |
2105 |
|
} |
2106 |
|
result.Add("VOLUME", entry.Volume); |
2107 |
} catch (Exception e) { |
} catch (Exception e) { |
2108 |
result.Error(e); |
result.Error(e); |
2109 |
} |
} |
2274 |
dmsg(2,("LSCPServer: SetChannelMap()\n")); |
dmsg(2,("LSCPServer: SetChannelMap()\n")); |
2275 |
LSCPResultSet result; |
LSCPResultSet result; |
2276 |
try { |
try { |
2277 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
|
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); |
|
2278 |
|
|
2279 |
if (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone(); |
if (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone(); |
2280 |
else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault(); |
else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault(); |
2453 |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
2454 |
LSCPResultSet result; |
LSCPResultSet result; |
2455 |
try { |
try { |
2456 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
2457 |
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
2458 |
Engine* pEngine = pEngineChannel->GetEngine(); |
Engine* pEngine = pEngineChannel->GetEngine(); |
2459 |
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
2468 |
return result.Produce(); |
return result.Produce(); |
2469 |
} |
} |
2470 |
|
|
2471 |
|
String LSCPServer::SendChannelMidiData(String MidiMsg, uint uiSamplerChannel, uint Arg1, uint Arg2) { |
2472 |
|
dmsg(2,("LSCPServer: SendChannelMidiData(MidiMsg=%s,uiSamplerChannel=%d,Arg1=%d,Arg2=%d)\n", MidiMsg.c_str(), uiSamplerChannel, Arg1, Arg2)); |
2473 |
|
LSCPResultSet result; |
2474 |
|
try { |
2475 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2476 |
|
|
2477 |
|
if (Arg1 > 127 || Arg2 > 127) { |
2478 |
|
throw Exception("Invalid MIDI message"); |
2479 |
|
} |
2480 |
|
|
2481 |
|
VirtualMidiDevice* pMidiDevice = NULL; |
2482 |
|
std::vector<EventHandler::midi_listener_entry>::iterator iter = eventHandler.channelMidiListeners.begin(); |
2483 |
|
for (; iter != eventHandler.channelMidiListeners.end(); ++iter) { |
2484 |
|
if ((*iter).pEngineChannel == pEngineChannel) { |
2485 |
|
pMidiDevice = (*iter).pMidiListener; |
2486 |
|
break; |
2487 |
|
} |
2488 |
|
} |
2489 |
|
|
2490 |
|
if(pMidiDevice == NULL) throw Exception("Couldn't find virtual MIDI device"); |
2491 |
|
|
2492 |
|
if (MidiMsg == "NOTE_ON") { |
2493 |
|
pMidiDevice->SendNoteOnToDevice(Arg1, Arg2); |
2494 |
|
bool b = pMidiDevice->SendNoteOnToSampler(Arg1, Arg2); |
2495 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2496 |
|
} else if (MidiMsg == "NOTE_OFF") { |
2497 |
|
pMidiDevice->SendNoteOffToDevice(Arg1, Arg2); |
2498 |
|
bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2); |
2499 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2500 |
|
} else { |
2501 |
|
throw Exception("Unknown MIDI message type: " + MidiMsg); |
2502 |
|
} |
2503 |
|
} catch (Exception e) { |
2504 |
|
result.Error(e); |
2505 |
|
} |
2506 |
|
return result.Produce(); |
2507 |
|
} |
2508 |
|
|
2509 |
/** |
/** |
2510 |
* Will be called by the parser to reset a particular sampler channel. |
* Will be called by the parser to reset a particular sampler channel. |
2511 |
*/ |
*/ |
2513 |
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
2514 |
LSCPResultSet result; |
LSCPResultSet result; |
2515 |
try { |
try { |
2516 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
2517 |
pEngineChannel->Reset(); |
pEngineChannel->Reset(); |
2518 |
} |
} |
2519 |
catch (Exception e) { |
catch (Exception e) { |
2579 |
String LSCPServer::GetTotalVoiceCountMax() { |
String LSCPServer::GetTotalVoiceCountMax() { |
2580 |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
2581 |
LSCPResultSet result; |
LSCPResultSet result; |
2582 |
result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES); |
result.Add(EngineFactory::EngineInstances().size() * GLOBAL_MAX_VOICES); |
2583 |
|
return result.Produce(); |
2584 |
|
} |
2585 |
|
|
2586 |
|
/** |
2587 |
|
* Will be called by the parser to return the sampler global maximum |
2588 |
|
* allowed number of voices. |
2589 |
|
*/ |
2590 |
|
String LSCPServer::GetGlobalMaxVoices() { |
2591 |
|
dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n")); |
2592 |
|
LSCPResultSet result; |
2593 |
|
result.Add(GLOBAL_MAX_VOICES); |
2594 |
|
return result.Produce(); |
2595 |
|
} |
2596 |
|
|
2597 |
|
/** |
2598 |
|
* Will be called by the parser to set the sampler global maximum number of |
2599 |
|
* voices. |
2600 |
|
*/ |
2601 |
|
String LSCPServer::SetGlobalMaxVoices(int iVoices) { |
2602 |
|
dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices)); |
2603 |
|
LSCPResultSet result; |
2604 |
|
try { |
2605 |
|
if (iVoices < 1) throw Exception("Maximum voices may not be less than 1"); |
2606 |
|
GLOBAL_MAX_VOICES = iVoices; // see common/global_private.cpp |
2607 |
|
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
2608 |
|
if (engines.size() > 0) { |
2609 |
|
std::set<Engine*>::iterator iter = engines.begin(); |
2610 |
|
std::set<Engine*>::iterator end = engines.end(); |
2611 |
|
for (; iter != end; ++iter) { |
2612 |
|
(*iter)->SetMaxVoices(iVoices); |
2613 |
|
} |
2614 |
|
} |
2615 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOICES", GLOBAL_MAX_VOICES)); |
2616 |
|
} catch (Exception e) { |
2617 |
|
result.Error(e); |
2618 |
|
} |
2619 |
|
return result.Produce(); |
2620 |
|
} |
2621 |
|
|
2622 |
|
/** |
2623 |
|
* Will be called by the parser to return the sampler global maximum |
2624 |
|
* allowed number of disk streams. |
2625 |
|
*/ |
2626 |
|
String LSCPServer::GetGlobalMaxStreams() { |
2627 |
|
dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n")); |
2628 |
|
LSCPResultSet result; |
2629 |
|
result.Add(GLOBAL_MAX_STREAMS); |
2630 |
|
return result.Produce(); |
2631 |
|
} |
2632 |
|
|
2633 |
|
/** |
2634 |
|
* Will be called by the parser to set the sampler global maximum number of |
2635 |
|
* disk streams. |
2636 |
|
*/ |
2637 |
|
String LSCPServer::SetGlobalMaxStreams(int iStreams) { |
2638 |
|
dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams)); |
2639 |
|
LSCPResultSet result; |
2640 |
|
try { |
2641 |
|
if (iStreams < 0) throw Exception("Maximum disk streams may not be negative"); |
2642 |
|
GLOBAL_MAX_STREAMS = iStreams; // see common/global_private.cpp |
2643 |
|
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
2644 |
|
if (engines.size() > 0) { |
2645 |
|
std::set<Engine*>::iterator iter = engines.begin(); |
2646 |
|
std::set<Engine*>::iterator end = engines.end(); |
2647 |
|
for (; iter != end; ++iter) { |
2648 |
|
(*iter)->SetMaxDiskStreams(iStreams); |
2649 |
|
} |
2650 |
|
} |
2651 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "STREAMS", GLOBAL_MAX_STREAMS)); |
2652 |
|
} catch (Exception e) { |
2653 |
|
result.Error(e); |
2654 |
|
} |
2655 |
return result.Produce(); |
return result.Produce(); |
2656 |
} |
} |
2657 |
|
|
2665 |
LSCPResultSet result; |
LSCPResultSet result; |
2666 |
try { |
try { |
2667 |
if (dVolume < 0) throw Exception("Volume may not be negative"); |
if (dVolume < 0) throw Exception("Volume may not be negative"); |
2668 |
GLOBAL_VOLUME = dVolume; // see common/global.cpp |
GLOBAL_VOLUME = dVolume; // see common/global_private.cpp |
2669 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME)); |
2670 |
} catch (Exception e) { |
} catch (Exception e) { |
2671 |
result.Error(e); |
result.Error(e); |
2792 |
result.Add("FORMAT_VERSION", info.FormatVersion); |
result.Add("FORMAT_VERSION", info.FormatVersion); |
2793 |
result.Add("PRODUCT", info.Product); |
result.Add("PRODUCT", info.Product); |
2794 |
result.Add("ARTISTS", info.Artists); |
result.Add("ARTISTS", info.Artists); |
2795 |
|
|
2796 |
|
std::stringstream ss; |
2797 |
|
bool b = false; |
2798 |
|
for (int i = 0; i < 128; i++) { |
2799 |
|
if (info.KeyBindings[i]) { |
2800 |
|
if (b) ss << ','; |
2801 |
|
ss << i; b = true; |
2802 |
|
} |
2803 |
|
} |
2804 |
|
result.Add("KEY_BINDINGS", ss.str()); |
2805 |
|
|
2806 |
|
b = false; |
2807 |
|
std::stringstream ss2; |
2808 |
|
for (int i = 0; i < 128; i++) { |
2809 |
|
if (info.KeySwitchBindings[i]) { |
2810 |
|
if (b) ss2 << ','; |
2811 |
|
ss2 << i; b = true; |
2812 |
|
} |
2813 |
|
} |
2814 |
|
result.Add("KEYSWITCH_BINDINGS", ss2.str()); |
2815 |
// no more need to ask other engine types |
// no more need to ask other engine types |
2816 |
bFound = true; |
bFound = true; |
2817 |
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
2839 |
throw Exception("Directory is specified"); |
throw Exception("Directory is specified"); |
2840 |
} |
} |
2841 |
#else |
#else |
2842 |
struct stat statBuf; |
File f(Filename); |
2843 |
int res = stat(Filename.c_str(), &statBuf); |
if(!f.Exist()) throw Exception(f.GetErrorMsg()); |
2844 |
if (res) { |
if (f.IsDirectory()) throw Exception("Directory is specified"); |
|
std::stringstream ss; |
|
|
ss << "Fail to stat `" << Filename << "`: " << strerror(errno); |
|
|
throw Exception(ss.str()); |
|
|
} |
|
|
|
|
|
if (S_ISDIR(statBuf.st_mode)) { |
|
|
throw Exception("Directory is specified"); |
|
|
} |
|
2845 |
#endif |
#endif |
2846 |
} |
} |
2847 |
|
|
3036 |
return result.Produce(); |
return result.Produce(); |
3037 |
} |
} |
3038 |
|
|
3039 |
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) { |
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground, bool insDir) { |
3040 |
dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground)); |
dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d,insDir=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground, insDir)); |
3041 |
LSCPResultSet result; |
LSCPResultSet result; |
3042 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
3043 |
try { |
try { |
3044 |
int id; |
int id; |
3045 |
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
3046 |
if (ScanMode.compare("RECURSIVE") == 0) { |
if (ScanMode.compare("RECURSIVE") == 0) { |
3047 |
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground); |
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground, insDir); |
3048 |
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
3049 |
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground); |
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground, insDir); |
3050 |
} else if (ScanMode.compare("FLAT") == 0) { |
} else if (ScanMode.compare("FLAT") == 0) { |
3051 |
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground); |
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground, insDir); |
3052 |
} else { |
} else { |
3053 |
throw Exception("Unknown scan mode: " + ScanMode); |
throw Exception("Unknown scan mode: " + ScanMode); |
3054 |
} |
} |
3224 |
return result.Produce(); |
return result.Produce(); |
3225 |
} |
} |
3226 |
|
|
3227 |
|
String LSCPServer::SetDbInstrumentFilePath(String OldPath, String NewPath) { |
3228 |
|
dmsg(2,("LSCPServer: SetDbInstrumentFilePath(OldPath=%s,NewPath=%s)\n", OldPath.c_str(), NewPath.c_str())); |
3229 |
|
LSCPResultSet result; |
3230 |
|
#if HAVE_SQLITE3 |
3231 |
|
try { |
3232 |
|
InstrumentsDb::GetInstrumentsDb()->SetInstrumentFilePath(OldPath, NewPath); |
3233 |
|
} catch (Exception e) { |
3234 |
|
result.Error(e); |
3235 |
|
} |
3236 |
|
#else |
3237 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3238 |
|
#endif |
3239 |
|
return result.Produce(); |
3240 |
|
} |
3241 |
|
|
3242 |
|
String LSCPServer::FindLostDbInstrumentFiles() { |
3243 |
|
dmsg(2,("LSCPServer: FindLostDbInstrumentFiles()\n")); |
3244 |
|
LSCPResultSet result; |
3245 |
|
#if HAVE_SQLITE3 |
3246 |
|
try { |
3247 |
|
String list; |
3248 |
|
StringListPtr pLostFiles = InstrumentsDb::GetInstrumentsDb()->FindLostInstrumentFiles(); |
3249 |
|
|
3250 |
|
for (int i = 0; i < pLostFiles->size(); i++) { |
3251 |
|
if (list != "") list += ","; |
3252 |
|
list += "'" + pLostFiles->at(i) + "'"; |
3253 |
|
} |
3254 |
|
|
3255 |
|
result.Add(list); |
3256 |
|
} catch (Exception e) { |
3257 |
|
result.Error(e); |
3258 |
|
} |
3259 |
|
#else |
3260 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3261 |
|
#endif |
3262 |
|
return result.Produce(); |
3263 |
|
} |
3264 |
|
|
3265 |
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
3266 |
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
3267 |
LSCPResultSet result; |
LSCPResultSet result; |
3392 |
} |
} |
3393 |
return result.Produce(); |
return result.Produce(); |
3394 |
} |
} |
3395 |
|
|
3396 |
|
} |