22 |
***************************************************************************/ |
***************************************************************************/ |
23 |
|
|
24 |
#include <algorithm> |
#include <algorithm> |
25 |
|
#include <string> |
26 |
|
|
27 |
#include "lscpserver.h" |
#include "lscpserver.h" |
28 |
#include "lscpresultset.h" |
#include "lscpresultset.h" |
43 |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
44 |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
45 |
|
|
46 |
|
namespace LinuxSampler { |
47 |
|
|
48 |
/** |
/** |
49 |
* Returns a copy of the given string where all special characters are |
* Returns a copy of the given string where all special characters are |
426 |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
427 |
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
428 |
if ((*itEngineChannel)->StatusChanged()) { |
if ((*itEngineChannel)->StatusChanged()) { |
429 |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->GetSamplerChannel()->Index())); |
430 |
} |
} |
431 |
|
|
432 |
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
433 |
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
434 |
if(fxs != NULL && fxs->IsInfoChanged()) { |
if(fxs != NULL && fxs->IsInfoChanged()) { |
435 |
int chn = (*itEngineChannel)->iSamplerChannelIndex; |
int chn = (*itEngineChannel)->GetSamplerChannel()->Index(); |
436 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id())); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id())); |
437 |
fxs->SetInfoChanged(false); |
fxs->SetInfoChanged(false); |
438 |
} |
} |
507 |
|
|
508 |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
509 |
|
|
510 |
if (retval == 0) |
if (retval == 0 || (retval == -1 && errno == EINTR)) |
511 |
continue; //Nothing try again |
continue; //Nothing try again |
512 |
if (retval == -1) { |
if (retval == -1) { |
513 |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
1135 |
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
1136 |
LSCPResultSet result; |
LSCPResultSet result; |
1137 |
try { |
try { |
1138 |
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"); |
|
1139 |
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"); |
1140 |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
1141 |
} |
} |
1153 |
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
1154 |
LSCPResultSet result; |
LSCPResultSet result; |
1155 |
try { |
try { |
1156 |
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"); |
|
1157 |
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"); |
1158 |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
1159 |
} |
} |
1171 |
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, 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 type assigned to 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 |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
1177 |
else { |
else { |
1849 |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
1850 |
LSCPResultSet result; |
LSCPResultSet result; |
1851 |
try { |
try { |
1852 |
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"); |
|
1853 |
pEngineChannel->Volume(dVolume); |
pEngineChannel->Volume(dVolume); |
1854 |
} |
} |
1855 |
catch (Exception e) { |
catch (Exception e) { |
1865 |
dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); |
1866 |
LSCPResultSet result; |
LSCPResultSet result; |
1867 |
try { |
try { |
1868 |
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"); |
|
1869 |
|
|
1870 |
if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); |
if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); |
1871 |
else pEngineChannel->SetMute(1); |
else pEngineChannel->SetMute(1); |
1882 |
dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,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 |
|
|
1887 |
bool oldSolo = pEngineChannel->GetSolo(); |
bool oldSolo = pEngineChannel->GetSolo(); |
1888 |
bool hadSoloChannel = HasSoloChannel(); |
bool hadSoloChannel = HasSoloChannel(); |
2002 |
dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n")); |
dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n")); |
2003 |
LSCPResultSet result; |
LSCPResultSet result; |
2004 |
try { |
try { |
2005 |
result.Add(MidiInstrumentMapper::Entries(MidiMapID).size()); |
result.Add(MidiInstrumentMapper::GetInstrumentCount(MidiMapID)); |
2006 |
} catch (Exception e) { |
} catch (Exception e) { |
2007 |
result.Error(e); |
result.Error(e); |
2008 |
} |
} |
2013 |
String LSCPServer::GetAllMidiInstrumentMappings() { |
String LSCPServer::GetAllMidiInstrumentMappings() { |
2014 |
dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n")); |
dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n")); |
2015 |
LSCPResultSet result; |
LSCPResultSet result; |
2016 |
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
try { |
2017 |
int totalMappings = 0; |
result.Add(MidiInstrumentMapper::GetInstrumentCount()); |
2018 |
for (int i = 0; i < maps.size(); i++) { |
} catch (Exception e) { |
2019 |
try { |
result.Error(e); |
|
totalMappings += MidiInstrumentMapper::Entries(maps[i]).size(); |
|
|
} catch (Exception e) { /*NOOP*/ } |
|
2020 |
} |
} |
|
result.Add(totalMappings); |
|
2021 |
return result.Produce(); |
return result.Produce(); |
2022 |
} |
} |
2023 |
|
|
2025 |
dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n")); |
dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n")); |
2026 |
LSCPResultSet result; |
LSCPResultSet result; |
2027 |
try { |
try { |
2028 |
midi_prog_index_t idx; |
MidiInstrumentMapper::entry_t entry = MidiInstrumentMapper::GetEntry(MidiMapID, MidiBank, MidiProg); |
2029 |
idx.midi_bank_msb = (MidiBank >> 7) & 0x7f; |
// convert the filename into the correct encoding as defined for LSCP |
2030 |
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) |
|
2031 |
#if WIN32 |
#if WIN32 |
2032 |
const String instrumentFileName = Path::fromWindows(iter->second.InstrumentFile).toLscp(); |
const String instrumentFileName = Path::fromWindows(entry.InstrumentFile).toLscp(); |
2033 |
#else |
#else |
2034 |
// assuming POSIX |
// assuming POSIX |
2035 |
const String instrumentFileName = Path::fromPosix(iter->second.InstrumentFile).toLscp(); |
const String instrumentFileName = Path::fromPosix(entry.InstrumentFile).toLscp(); |
2036 |
#endif |
#endif |
2037 |
|
|
2038 |
result.Add("NAME", _escapeLscpResponse(iter->second.Name)); |
result.Add("NAME", _escapeLscpResponse(entry.Name)); |
2039 |
result.Add("ENGINE_NAME", iter->second.EngineName); |
result.Add("ENGINE_NAME", entry.EngineName); |
2040 |
result.Add("INSTRUMENT_FILE", instrumentFileName); |
result.Add("INSTRUMENT_FILE", instrumentFileName); |
2041 |
result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex); |
result.Add("INSTRUMENT_NR", (int) entry.InstrumentIndex); |
2042 |
String instrumentName; |
String instrumentName; |
2043 |
Engine* pEngine = EngineFactory::Create(iter->second.EngineName); |
Engine* pEngine = EngineFactory::Create(entry.EngineName); |
2044 |
if (pEngine) { |
if (pEngine) { |
2045 |
if (pEngine->GetInstrumentManager()) { |
if (pEngine->GetInstrumentManager()) { |
2046 |
InstrumentManager::instrument_id_t instrID; |
InstrumentManager::instrument_id_t instrID; |
2047 |
instrID.FileName = iter->second.InstrumentFile; |
instrID.FileName = entry.InstrumentFile; |
2048 |
instrID.Index = iter->second.InstrumentIndex; |
instrID.Index = entry.InstrumentIndex; |
2049 |
instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID); |
instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID); |
|
} |
|
|
EngineFactory::Destroy(pEngine); |
|
|
} |
|
|
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName)); |
|
|
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!"); |
|
2050 |
} |
} |
2051 |
result.Add("VOLUME", iter->second.Volume); |
EngineFactory::Destroy(pEngine); |
2052 |
|
} |
2053 |
|
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName)); |
2054 |
|
switch (entry.LoadMode) { |
2055 |
|
case MidiInstrumentMapper::ON_DEMAND: |
2056 |
|
result.Add("LOAD_MODE", "ON_DEMAND"); |
2057 |
|
break; |
2058 |
|
case MidiInstrumentMapper::ON_DEMAND_HOLD: |
2059 |
|
result.Add("LOAD_MODE", "ON_DEMAND_HOLD"); |
2060 |
|
break; |
2061 |
|
case MidiInstrumentMapper::PERSISTENT: |
2062 |
|
result.Add("LOAD_MODE", "PERSISTENT"); |
2063 |
|
break; |
2064 |
|
default: |
2065 |
|
throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!"); |
2066 |
} |
} |
2067 |
|
result.Add("VOLUME", entry.Volume); |
2068 |
} catch (Exception e) { |
} catch (Exception e) { |
2069 |
result.Error(e); |
result.Error(e); |
2070 |
} |
} |
2235 |
dmsg(2,("LSCPServer: SetChannelMap()\n")); |
dmsg(2,("LSCPServer: SetChannelMap()\n")); |
2236 |
LSCPResultSet result; |
LSCPResultSet result; |
2237 |
try { |
try { |
2238 |
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"); |
|
2239 |
|
|
2240 |
if (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone(); |
if (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone(); |
2241 |
else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault(); |
else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault(); |
2414 |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
2415 |
LSCPResultSet result; |
LSCPResultSet result; |
2416 |
try { |
try { |
2417 |
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"); |
|
2418 |
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
2419 |
Engine* pEngine = pEngineChannel->GetEngine(); |
Engine* pEngine = pEngineChannel->GetEngine(); |
2420 |
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
2429 |
return result.Produce(); |
return result.Produce(); |
2430 |
} |
} |
2431 |
|
|
2432 |
|
String LSCPServer::SendChannelMidiData(String MidiMsg, uint uiSamplerChannel, uint Arg1, uint Arg2) { |
2433 |
|
dmsg(2,("LSCPServer: SendChannelMidiData(MidiMsg=%s,uiSamplerChannel=%d,Arg1=%d,Arg2=%d)\n", MidiMsg.c_str(), uiSamplerChannel, Arg1, Arg2)); |
2434 |
|
LSCPResultSet result; |
2435 |
|
try { |
2436 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2437 |
|
|
2438 |
|
if (Arg1 > 127 || Arg2 > 127) { |
2439 |
|
throw Exception("Invalid MIDI message"); |
2440 |
|
} |
2441 |
|
|
2442 |
|
VirtualMidiDevice* pMidiDevice = NULL; |
2443 |
|
std::vector<EventHandler::midi_listener_entry>::iterator iter = eventHandler.channelMidiListeners.begin(); |
2444 |
|
for (; iter != eventHandler.channelMidiListeners.end(); ++iter) { |
2445 |
|
if ((*iter).pEngineChannel == pEngineChannel) { |
2446 |
|
pMidiDevice = (*iter).pMidiListener; |
2447 |
|
break; |
2448 |
|
} |
2449 |
|
} |
2450 |
|
|
2451 |
|
if(pMidiDevice == NULL) throw Exception("Couldn't find virtual MIDI device"); |
2452 |
|
|
2453 |
|
if (MidiMsg == "NOTE_ON") { |
2454 |
|
pMidiDevice->SendNoteOnToDevice(Arg1, Arg2); |
2455 |
|
bool b = pMidiDevice->SendNoteOnToSampler(Arg1, Arg2); |
2456 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2457 |
|
} else if (MidiMsg == "NOTE_OFF") { |
2458 |
|
pMidiDevice->SendNoteOffToDevice(Arg1, Arg2); |
2459 |
|
bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2); |
2460 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2461 |
|
} else { |
2462 |
|
throw Exception("Unknown MIDI message type: " + MidiMsg); |
2463 |
|
} |
2464 |
|
} catch (Exception e) { |
2465 |
|
result.Error(e); |
2466 |
|
} |
2467 |
|
return result.Produce(); |
2468 |
|
} |
2469 |
|
|
2470 |
/** |
/** |
2471 |
* Will be called by the parser to reset a particular sampler channel. |
* Will be called by the parser to reset a particular sampler channel. |
2472 |
*/ |
*/ |
2474 |
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
2475 |
LSCPResultSet result; |
LSCPResultSet result; |
2476 |
try { |
try { |
2477 |
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"); |
|
2478 |
pEngineChannel->Reset(); |
pEngineChannel->Reset(); |
2479 |
} |
} |
2480 |
catch (Exception e) { |
catch (Exception e) { |
2540 |
String LSCPServer::GetTotalVoiceCountMax() { |
String LSCPServer::GetTotalVoiceCountMax() { |
2541 |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
2542 |
LSCPResultSet result; |
LSCPResultSet result; |
2543 |
result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES); |
result.Add(EngineFactory::EngineInstances().size() * GLOBAL_MAX_VOICES); |
2544 |
|
return result.Produce(); |
2545 |
|
} |
2546 |
|
|
2547 |
|
/** |
2548 |
|
* Will be called by the parser to return the sampler global maximum |
2549 |
|
* allowed number of voices. |
2550 |
|
*/ |
2551 |
|
String LSCPServer::GetGlobalMaxVoices() { |
2552 |
|
dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n")); |
2553 |
|
LSCPResultSet result; |
2554 |
|
result.Add(GLOBAL_MAX_VOICES); |
2555 |
|
return result.Produce(); |
2556 |
|
} |
2557 |
|
|
2558 |
|
/** |
2559 |
|
* Will be called by the parser to set the sampler global maximum number of |
2560 |
|
* voices. |
2561 |
|
*/ |
2562 |
|
String LSCPServer::SetGlobalMaxVoices(int iVoices) { |
2563 |
|
dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices)); |
2564 |
|
LSCPResultSet result; |
2565 |
|
try { |
2566 |
|
if (iVoices < 1) throw Exception("Maximum voices may not be less than 1"); |
2567 |
|
GLOBAL_MAX_VOICES = iVoices; // see common/global_private.cpp |
2568 |
|
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
2569 |
|
if (engines.size() > 0) { |
2570 |
|
std::set<Engine*>::iterator iter = engines.begin(); |
2571 |
|
std::set<Engine*>::iterator end = engines.end(); |
2572 |
|
for (; iter != end; ++iter) { |
2573 |
|
(*iter)->SetMaxVoices(iVoices); |
2574 |
|
} |
2575 |
|
} |
2576 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOICES", GLOBAL_MAX_VOICES)); |
2577 |
|
} catch (Exception e) { |
2578 |
|
result.Error(e); |
2579 |
|
} |
2580 |
|
return result.Produce(); |
2581 |
|
} |
2582 |
|
|
2583 |
|
/** |
2584 |
|
* Will be called by the parser to return the sampler global maximum |
2585 |
|
* allowed number of disk streams. |
2586 |
|
*/ |
2587 |
|
String LSCPServer::GetGlobalMaxStreams() { |
2588 |
|
dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n")); |
2589 |
|
LSCPResultSet result; |
2590 |
|
result.Add(GLOBAL_MAX_STREAMS); |
2591 |
|
return result.Produce(); |
2592 |
|
} |
2593 |
|
|
2594 |
|
/** |
2595 |
|
* Will be called by the parser to set the sampler global maximum number of |
2596 |
|
* disk streams. |
2597 |
|
*/ |
2598 |
|
String LSCPServer::SetGlobalMaxStreams(int iStreams) { |
2599 |
|
dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams)); |
2600 |
|
LSCPResultSet result; |
2601 |
|
try { |
2602 |
|
if (iStreams < 0) throw Exception("Maximum disk streams may not be negative"); |
2603 |
|
GLOBAL_MAX_STREAMS = iStreams; // see common/global_private.cpp |
2604 |
|
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
2605 |
|
if (engines.size() > 0) { |
2606 |
|
std::set<Engine*>::iterator iter = engines.begin(); |
2607 |
|
std::set<Engine*>::iterator end = engines.end(); |
2608 |
|
for (; iter != end; ++iter) { |
2609 |
|
(*iter)->SetMaxDiskStreams(iStreams); |
2610 |
|
} |
2611 |
|
} |
2612 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "STREAMS", GLOBAL_MAX_STREAMS)); |
2613 |
|
} catch (Exception e) { |
2614 |
|
result.Error(e); |
2615 |
|
} |
2616 |
return result.Produce(); |
return result.Produce(); |
2617 |
} |
} |
2618 |
|
|
2626 |
LSCPResultSet result; |
LSCPResultSet result; |
2627 |
try { |
try { |
2628 |
if (dVolume < 0) throw Exception("Volume may not be negative"); |
if (dVolume < 0) throw Exception("Volume may not be negative"); |
2629 |
GLOBAL_VOLUME = dVolume; // see common/global.cpp |
GLOBAL_VOLUME = dVolume; // see common/global_private.cpp |
2630 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME)); |
2631 |
} catch (Exception e) { |
} catch (Exception e) { |
2632 |
result.Error(e); |
result.Error(e); |
2753 |
result.Add("FORMAT_VERSION", info.FormatVersion); |
result.Add("FORMAT_VERSION", info.FormatVersion); |
2754 |
result.Add("PRODUCT", info.Product); |
result.Add("PRODUCT", info.Product); |
2755 |
result.Add("ARTISTS", info.Artists); |
result.Add("ARTISTS", info.Artists); |
2756 |
|
|
2757 |
|
std::stringstream ss; |
2758 |
|
bool b = false; |
2759 |
|
for (int i = 0; i < 128; i++) { |
2760 |
|
if (info.KeyBindings[i]) { |
2761 |
|
if (b) ss << ','; |
2762 |
|
ss << i; b = true; |
2763 |
|
} |
2764 |
|
} |
2765 |
|
result.Add("KEY_BINDINGS", ss.str()); |
2766 |
|
|
2767 |
|
b = false; |
2768 |
|
std::stringstream ss2; |
2769 |
|
for (int i = 0; i < 128; i++) { |
2770 |
|
if (info.KeySwitchBindings[i]) { |
2771 |
|
if (b) ss2 << ','; |
2772 |
|
ss2 << i; b = true; |
2773 |
|
} |
2774 |
|
} |
2775 |
|
result.Add("KEYSWITCH_BINDINGS", ss2.str()); |
2776 |
// no more need to ask other engine types |
// no more need to ask other engine types |
2777 |
bFound = true; |
bFound = true; |
2778 |
} 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())); |
3005 |
return result.Produce(); |
return result.Produce(); |
3006 |
} |
} |
3007 |
|
|
3008 |
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) { |
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground, bool insDir) { |
3009 |
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)); |
3010 |
LSCPResultSet result; |
LSCPResultSet result; |
3011 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
3012 |
try { |
try { |
3013 |
int id; |
int id; |
3014 |
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
3015 |
if (ScanMode.compare("RECURSIVE") == 0) { |
if (ScanMode.compare("RECURSIVE") == 0) { |
3016 |
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground); |
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground, insDir); |
3017 |
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
3018 |
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground); |
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground, insDir); |
3019 |
} else if (ScanMode.compare("FLAT") == 0) { |
} else if (ScanMode.compare("FLAT") == 0) { |
3020 |
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground); |
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground, insDir); |
3021 |
} else { |
} else { |
3022 |
throw Exception("Unknown scan mode: " + ScanMode); |
throw Exception("Unknown scan mode: " + ScanMode); |
3023 |
} |
} |
3193 |
return result.Produce(); |
return result.Produce(); |
3194 |
} |
} |
3195 |
|
|
3196 |
|
String LSCPServer::SetDbInstrumentFilePath(String OldPath, String NewPath) { |
3197 |
|
dmsg(2,("LSCPServer: SetDbInstrumentFilePath(OldPath=%s,NewPath=%s)\n", OldPath.c_str(), NewPath.c_str())); |
3198 |
|
LSCPResultSet result; |
3199 |
|
#if HAVE_SQLITE3 |
3200 |
|
try { |
3201 |
|
InstrumentsDb::GetInstrumentsDb()->SetInstrumentFilePath(OldPath, NewPath); |
3202 |
|
} catch (Exception e) { |
3203 |
|
result.Error(e); |
3204 |
|
} |
3205 |
|
#else |
3206 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3207 |
|
#endif |
3208 |
|
return result.Produce(); |
3209 |
|
} |
3210 |
|
|
3211 |
|
String LSCPServer::FindLostDbInstrumentFiles() { |
3212 |
|
dmsg(2,("LSCPServer: FindLostDbInstrumentFiles()\n")); |
3213 |
|
LSCPResultSet result; |
3214 |
|
#if HAVE_SQLITE3 |
3215 |
|
try { |
3216 |
|
String list; |
3217 |
|
StringListPtr pLostFiles = InstrumentsDb::GetInstrumentsDb()->FindLostInstrumentFiles(); |
3218 |
|
|
3219 |
|
for (int i = 0; i < pLostFiles->size(); i++) { |
3220 |
|
if (list != "") list += ","; |
3221 |
|
list += "'" + pLostFiles->at(i) + "'"; |
3222 |
|
} |
3223 |
|
|
3224 |
|
result.Add(list); |
3225 |
|
} catch (Exception e) { |
3226 |
|
result.Error(e); |
3227 |
|
} |
3228 |
|
#else |
3229 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3230 |
|
#endif |
3231 |
|
return result.Produce(); |
3232 |
|
} |
3233 |
|
|
3234 |
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
3235 |
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
3236 |
LSCPResultSet result; |
LSCPResultSet result; |
3361 |
} |
} |
3362 |
return result.Produce(); |
return result.Produce(); |
3363 |
} |
} |
3364 |
|
|
3365 |
|
} |