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 - 2008 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 * |
22 |
***************************************************************************/ |
***************************************************************************/ |
23 |
|
|
24 |
#include <algorithm> |
#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" |
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 |
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 |
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; |
626 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
627 |
} |
} |
628 |
|
|
629 |
|
void LSCPServer::CloseAllConnections() { |
630 |
|
std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); |
631 |
|
while(iter != Sessions.end()) { |
632 |
|
CloseConnection(iter); |
633 |
|
iter = Sessions.begin(); |
634 |
|
} |
635 |
|
} |
636 |
|
|
637 |
void LSCPServer::LockRTNotify() { |
void LSCPServer::LockRTNotify() { |
638 |
RTNotifyMutex.Lock(); |
RTNotifyMutex.Lock(); |
639 |
} |
} |
1164 |
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
1165 |
LSCPResultSet result; |
LSCPResultSet result; |
1166 |
try { |
try { |
1167 |
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"); |
|
1168 |
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"); |
1169 |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
1170 |
} |
} |
1182 |
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
1183 |
LSCPResultSet result; |
LSCPResultSet result; |
1184 |
try { |
try { |
1185 |
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"); |
|
1186 |
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"); |
1187 |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
1188 |
} |
} |
1200 |
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); |
1201 |
LSCPResultSet result; |
LSCPResultSet result; |
1202 |
try { |
try { |
1203 |
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"); |
|
1204 |
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"); |
1205 |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
1206 |
else { |
else { |
1288 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1289 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1290 |
s += iter->first; |
s += iter->first; |
1291 |
|
delete iter->second; |
1292 |
} |
} |
1293 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1294 |
} |
} |
1313 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1314 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1315 |
s += iter->first; |
s += iter->first; |
1316 |
|
delete iter->second; |
1317 |
} |
} |
1318 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1319 |
} |
} |
1344 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1345 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1346 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1347 |
|
delete pParameter; |
1348 |
} |
} |
1349 |
catch (Exception e) { |
catch (Exception e) { |
1350 |
result.Error(e); |
result.Error(e); |
1372 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1373 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1374 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1375 |
|
delete pParameter; |
1376 |
} |
} |
1377 |
catch (Exception e) { |
catch (Exception e) { |
1378 |
result.Error(e); |
result.Error(e); |
1882 |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
1883 |
LSCPResultSet result; |
LSCPResultSet result; |
1884 |
try { |
try { |
1885 |
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"); |
|
1886 |
pEngineChannel->Volume(dVolume); |
pEngineChannel->Volume(dVolume); |
1887 |
} |
} |
1888 |
catch (Exception e) { |
catch (Exception e) { |
1898 |
dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); |
1899 |
LSCPResultSet result; |
LSCPResultSet result; |
1900 |
try { |
try { |
1901 |
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"); |
|
1902 |
|
|
1903 |
if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); |
if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); |
1904 |
else pEngineChannel->SetMute(1); |
else pEngineChannel->SetMute(1); |
1915 |
dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel)); |
1916 |
LSCPResultSet result; |
LSCPResultSet result; |
1917 |
try { |
try { |
1918 |
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"); |
|
1919 |
|
|
1920 |
bool oldSolo = pEngineChannel->GetSolo(); |
bool oldSolo = pEngineChannel->GetSolo(); |
1921 |
bool hadSoloChannel = HasSoloChannel(); |
bool hadSoloChannel = HasSoloChannel(); |
2268 |
dmsg(2,("LSCPServer: SetChannelMap()\n")); |
dmsg(2,("LSCPServer: SetChannelMap()\n")); |
2269 |
LSCPResultSet result; |
LSCPResultSet result; |
2270 |
try { |
try { |
2271 |
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"); |
|
2272 |
|
|
2273 |
if (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone(); |
if (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone(); |
2274 |
else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault(); |
else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault(); |
2447 |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
2448 |
LSCPResultSet result; |
LSCPResultSet result; |
2449 |
try { |
try { |
2450 |
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"); |
|
2451 |
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
2452 |
Engine* pEngine = pEngineChannel->GetEngine(); |
Engine* pEngine = pEngineChannel->GetEngine(); |
2453 |
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
2462 |
return result.Produce(); |
return result.Produce(); |
2463 |
} |
} |
2464 |
|
|
2465 |
|
String LSCPServer::SendChannelMidiData(String MidiMsg, uint uiSamplerChannel, uint Arg1, uint Arg2) { |
2466 |
|
dmsg(2,("LSCPServer: SendChannelMidiData(MidiMsg=%s,uiSamplerChannel=%d,Arg1=%d,Arg2=%d)\n", MidiMsg.c_str(), uiSamplerChannel, Arg1, Arg2)); |
2467 |
|
LSCPResultSet result; |
2468 |
|
try { |
2469 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2470 |
|
|
2471 |
|
if (Arg1 > 127 || Arg2 > 127) { |
2472 |
|
throw Exception("Invalid MIDI message"); |
2473 |
|
} |
2474 |
|
|
2475 |
|
VirtualMidiDevice* pMidiDevice = NULL; |
2476 |
|
std::vector<EventHandler::midi_listener_entry>::iterator iter = eventHandler.channelMidiListeners.begin(); |
2477 |
|
for (; iter != eventHandler.channelMidiListeners.end(); ++iter) { |
2478 |
|
if ((*iter).pEngineChannel == pEngineChannel) { |
2479 |
|
pMidiDevice = (*iter).pMidiListener; |
2480 |
|
break; |
2481 |
|
} |
2482 |
|
} |
2483 |
|
|
2484 |
|
if(pMidiDevice == NULL) throw Exception("Couldn't find virtual MIDI device"); |
2485 |
|
|
2486 |
|
if (MidiMsg == "NOTE_ON") { |
2487 |
|
pMidiDevice->SendNoteOnToDevice(Arg1, Arg2); |
2488 |
|
bool b = pMidiDevice->SendNoteOnToSampler(Arg1, Arg2); |
2489 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2490 |
|
} else if (MidiMsg == "NOTE_OFF") { |
2491 |
|
pMidiDevice->SendNoteOffToDevice(Arg1, Arg2); |
2492 |
|
bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2); |
2493 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2494 |
|
} else { |
2495 |
|
throw Exception("Unknown MIDI message type: " + MidiMsg); |
2496 |
|
} |
2497 |
|
} catch (Exception e) { |
2498 |
|
result.Error(e); |
2499 |
|
} |
2500 |
|
return result.Produce(); |
2501 |
|
} |
2502 |
|
|
2503 |
/** |
/** |
2504 |
* Will be called by the parser to reset a particular sampler channel. |
* Will be called by the parser to reset a particular sampler channel. |
2505 |
*/ |
*/ |
2507 |
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
2508 |
LSCPResultSet result; |
LSCPResultSet result; |
2509 |
try { |
try { |
2510 |
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"); |
|
2511 |
pEngineChannel->Reset(); |
pEngineChannel->Reset(); |
2512 |
} |
} |
2513 |
catch (Exception e) { |
catch (Exception e) { |
2573 |
String LSCPServer::GetTotalVoiceCountMax() { |
String LSCPServer::GetTotalVoiceCountMax() { |
2574 |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
2575 |
LSCPResultSet result; |
LSCPResultSet result; |
2576 |
result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES); |
result.Add(EngineFactory::EngineInstances().size() * GLOBAL_MAX_VOICES); |
2577 |
|
return result.Produce(); |
2578 |
|
} |
2579 |
|
|
2580 |
|
/** |
2581 |
|
* Will be called by the parser to return the sampler global maximum |
2582 |
|
* allowed number of voices. |
2583 |
|
*/ |
2584 |
|
String LSCPServer::GetGlobalMaxVoices() { |
2585 |
|
dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n")); |
2586 |
|
LSCPResultSet result; |
2587 |
|
result.Add(GLOBAL_MAX_VOICES); |
2588 |
|
return result.Produce(); |
2589 |
|
} |
2590 |
|
|
2591 |
|
/** |
2592 |
|
* Will be called by the parser to set the sampler global maximum number of |
2593 |
|
* voices. |
2594 |
|
*/ |
2595 |
|
String LSCPServer::SetGlobalMaxVoices(int iVoices) { |
2596 |
|
dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices)); |
2597 |
|
LSCPResultSet result; |
2598 |
|
try { |
2599 |
|
if (iVoices < 1) throw Exception("Maximum voices may not be less than 1"); |
2600 |
|
GLOBAL_MAX_VOICES = iVoices; // see common/global_private.cpp |
2601 |
|
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
2602 |
|
if (engines.size() > 0) { |
2603 |
|
std::set<Engine*>::iterator iter = engines.begin(); |
2604 |
|
std::set<Engine*>::iterator end = engines.end(); |
2605 |
|
for (; iter != end; ++iter) { |
2606 |
|
(*iter)->SetMaxVoices(iVoices); |
2607 |
|
} |
2608 |
|
} |
2609 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOICES", GLOBAL_MAX_VOICES)); |
2610 |
|
} catch (Exception e) { |
2611 |
|
result.Error(e); |
2612 |
|
} |
2613 |
|
return result.Produce(); |
2614 |
|
} |
2615 |
|
|
2616 |
|
/** |
2617 |
|
* Will be called by the parser to return the sampler global maximum |
2618 |
|
* allowed number of disk streams. |
2619 |
|
*/ |
2620 |
|
String LSCPServer::GetGlobalMaxStreams() { |
2621 |
|
dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n")); |
2622 |
|
LSCPResultSet result; |
2623 |
|
result.Add(GLOBAL_MAX_STREAMS); |
2624 |
|
return result.Produce(); |
2625 |
|
} |
2626 |
|
|
2627 |
|
/** |
2628 |
|
* Will be called by the parser to set the sampler global maximum number of |
2629 |
|
* disk streams. |
2630 |
|
*/ |
2631 |
|
String LSCPServer::SetGlobalMaxStreams(int iStreams) { |
2632 |
|
dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams)); |
2633 |
|
LSCPResultSet result; |
2634 |
|
try { |
2635 |
|
if (iStreams < 0) throw Exception("Maximum disk streams may not be negative"); |
2636 |
|
GLOBAL_MAX_STREAMS = iStreams; // see common/global_private.cpp |
2637 |
|
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
2638 |
|
if (engines.size() > 0) { |
2639 |
|
std::set<Engine*>::iterator iter = engines.begin(); |
2640 |
|
std::set<Engine*>::iterator end = engines.end(); |
2641 |
|
for (; iter != end; ++iter) { |
2642 |
|
(*iter)->SetMaxDiskStreams(iStreams); |
2643 |
|
} |
2644 |
|
} |
2645 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "STREAMS", GLOBAL_MAX_STREAMS)); |
2646 |
|
} catch (Exception e) { |
2647 |
|
result.Error(e); |
2648 |
|
} |
2649 |
return result.Produce(); |
return result.Produce(); |
2650 |
} |
} |
2651 |
|
|
2786 |
result.Add("FORMAT_VERSION", info.FormatVersion); |
result.Add("FORMAT_VERSION", info.FormatVersion); |
2787 |
result.Add("PRODUCT", info.Product); |
result.Add("PRODUCT", info.Product); |
2788 |
result.Add("ARTISTS", info.Artists); |
result.Add("ARTISTS", info.Artists); |
2789 |
|
|
2790 |
|
std::stringstream ss; |
2791 |
|
bool b = false; |
2792 |
|
for (int i = 0; i < 128; i++) { |
2793 |
|
if (info.KeyBindings[i]) { |
2794 |
|
if (b) ss << ','; |
2795 |
|
ss << i; b = true; |
2796 |
|
} |
2797 |
|
} |
2798 |
|
result.Add("KEY_BINDINGS", ss.str()); |
2799 |
|
|
2800 |
|
b = false; |
2801 |
|
std::stringstream ss2; |
2802 |
|
for (int i = 0; i < 128; i++) { |
2803 |
|
if (info.KeySwitchBindings[i]) { |
2804 |
|
if (b) ss2 << ','; |
2805 |
|
ss2 << i; b = true; |
2806 |
|
} |
2807 |
|
} |
2808 |
|
result.Add("KEYSWITCH_BINDINGS", ss2.str()); |
2809 |
// no more need to ask other engine types |
// no more need to ask other engine types |
2810 |
bFound = true; |
bFound = true; |
2811 |
} 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())); |
2833 |
throw Exception("Directory is specified"); |
throw Exception("Directory is specified"); |
2834 |
} |
} |
2835 |
#else |
#else |
2836 |
struct stat statBuf; |
File f(Filename); |
2837 |
int res = stat(Filename.c_str(), &statBuf); |
if(!f.Exist()) throw Exception(f.GetErrorMsg()); |
2838 |
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"); |
|
|
} |
|
2839 |
#endif |
#endif |
2840 |
} |
} |
2841 |
|
|
3030 |
return result.Produce(); |
return result.Produce(); |
3031 |
} |
} |
3032 |
|
|
3033 |
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) { |
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground, bool insDir) { |
3034 |
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)); |
3035 |
LSCPResultSet result; |
LSCPResultSet result; |
3036 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
3037 |
try { |
try { |
3038 |
int id; |
int id; |
3039 |
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
3040 |
if (ScanMode.compare("RECURSIVE") == 0) { |
if (ScanMode.compare("RECURSIVE") == 0) { |
3041 |
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground); |
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground, insDir); |
3042 |
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
3043 |
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground); |
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground, insDir); |
3044 |
} else if (ScanMode.compare("FLAT") == 0) { |
} else if (ScanMode.compare("FLAT") == 0) { |
3045 |
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground); |
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground, insDir); |
3046 |
} else { |
} else { |
3047 |
throw Exception("Unknown scan mode: " + ScanMode); |
throw Exception("Unknown scan mode: " + ScanMode); |
3048 |
} |
} |