36 |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
37 |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
38 |
|
|
39 |
|
|
40 |
|
/** |
41 |
|
* Returns a copy of the given string where all special characters are |
42 |
|
* replaced by LSCP escape sequences ("\xHH"). This function shall be used |
43 |
|
* to escape LSCP response fields in case the respective response field is |
44 |
|
* actually defined as using escape sequences in the LSCP specs. |
45 |
|
* |
46 |
|
* @e Caution: DO NOT use this function for escaping path based responses, |
47 |
|
* use the Path class (src/common/Path.h) for this instead! |
48 |
|
*/ |
49 |
|
static String _escapeLscpResponse(String txt) { |
50 |
|
for (int i = 0; i < txt.length(); i++) { |
51 |
|
const char c = txt.c_str()[i]; |
52 |
|
if ( |
53 |
|
!(c >= '0' && c <= '9') && |
54 |
|
!(c >= 'a' && c <= 'z') && |
55 |
|
!(c >= 'A' && c <= 'Z') && |
56 |
|
!(c == ' ') && !(c == '!') && !(c == '#') && !(c == '$') && |
57 |
|
!(c == '%') && !(c == '&') && !(c == '(') && !(c == ')') && |
58 |
|
!(c == '*') && !(c == '+') && !(c == ',') && !(c == '-') && |
59 |
|
!(c == '.') && !(c == '/') && !(c == ':') && !(c == ';') && |
60 |
|
!(c == '<') && !(c == '=') && !(c == '>') && !(c == '?') && |
61 |
|
!(c == '@') && !(c == '[') && !(c == ']') && |
62 |
|
!(c == '^') && !(c == '_') && !(c == '`') && !(c == '{') && |
63 |
|
!(c == '|') && !(c == '}') && !(c == '~') |
64 |
|
) { |
65 |
|
// convert the "special" character into a "\xHH" LSCP escape sequence |
66 |
|
char buf[5]; |
67 |
|
snprintf(buf, sizeof(buf), "\\x%02x", static_cast<unsigned char>(c)); |
68 |
|
txt.replace(i, 1, buf); |
69 |
|
i += 3; |
70 |
|
} |
71 |
|
} |
72 |
|
return txt; |
73 |
|
} |
74 |
|
|
75 |
/** |
/** |
76 |
* Below are a few static members of the LSCPServer class. |
* Below are a few static members of the LSCPServer class. |
77 |
* The big assumption here is that LSCPServer is going to remain a singleton. |
* The big assumption here is that LSCPServer is going to remain a singleton. |
804 |
LockRTNotify(); |
LockRTNotify(); |
805 |
try { |
try { |
806 |
Engine* pEngine = EngineFactory::Create(EngineName); |
Engine* pEngine = EngineFactory::Create(EngineName); |
807 |
result.Add("DESCRIPTION", pEngine->Description()); |
result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description())); |
808 |
result.Add("VERSION", pEngine->Version()); |
result.Add("VERSION", pEngine->Version()); |
809 |
EngineFactory::Destroy(pEngine); |
EngineFactory::Destroy(pEngine); |
810 |
} |
} |
877 |
if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
878 |
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
879 |
|
|
880 |
|
// convert the filename into the correct encoding as defined for LSCP |
881 |
|
// (especially in terms of special characters -> escape sequences) |
882 |
|
if (InstrumentFileName != "NONE" && InstrumentFileName != "") { |
883 |
|
#if WIN32 |
884 |
|
InstrumentFileName = Path::fromWindows(InstrumentFileName).toLscp(); |
885 |
|
#else |
886 |
|
// assuming POSIX |
887 |
|
InstrumentFileName = Path::fromPosix(InstrumentFileName).toLscp(); |
888 |
|
#endif |
889 |
|
} |
890 |
|
|
891 |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
892 |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
893 |
result.Add("INSTRUMENT_NAME", InstrumentName); |
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(InstrumentName)); |
894 |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
895 |
result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false")); |
result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false")); |
896 |
result.Add("SOLO", Solo); |
result.Add("SOLO", Solo); |
1832 |
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx); |
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx); |
1833 |
if (iter == mappings.end()) result.Error("there is no map entry with that index"); |
if (iter == mappings.end()) result.Error("there is no map entry with that index"); |
1834 |
else { // found |
else { // found |
1835 |
result.Add("NAME", iter->second.Name); |
|
1836 |
|
// convert the filename into the correct encoding as defined for LSCP |
1837 |
|
// (especially in terms of special characters -> escape sequences) |
1838 |
|
#if WIN32 |
1839 |
|
const String instrumentFileName = Path::fromWindows(iter->second.InstrumentFile).toLscp(); |
1840 |
|
#else |
1841 |
|
// assuming POSIX |
1842 |
|
const String instrumentFileName = Path::fromPosix(iter->second.InstrumentFile).toLscp(); |
1843 |
|
#endif |
1844 |
|
|
1845 |
|
result.Add("NAME", _escapeLscpResponse(iter->second.Name)); |
1846 |
result.Add("ENGINE_NAME", iter->second.EngineName); |
result.Add("ENGINE_NAME", iter->second.EngineName); |
1847 |
result.Add("INSTRUMENT_FILE", iter->second.InstrumentFile); |
result.Add("INSTRUMENT_FILE", instrumentFileName); |
1848 |
result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex); |
result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex); |
1849 |
String instrumentName; |
String instrumentName; |
1850 |
Engine* pEngine = EngineFactory::Create(iter->second.EngineName); |
Engine* pEngine = EngineFactory::Create(iter->second.EngineName); |
1857 |
} |
} |
1858 |
EngineFactory::Destroy(pEngine); |
EngineFactory::Destroy(pEngine); |
1859 |
} |
} |
1860 |
result.Add("INSTRUMENT_NAME", instrumentName); |
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName)); |
1861 |
switch (iter->second.LoadMode) { |
switch (iter->second.LoadMode) { |
1862 |
case MidiInstrumentMapper::ON_DEMAND: |
case MidiInstrumentMapper::ON_DEMAND: |
1863 |
result.Add("LOAD_MODE", "ON_DEMAND"); |
result.Add("LOAD_MODE", "ON_DEMAND"); |
2012 |
dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n")); |
dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n")); |
2013 |
LSCPResultSet result; |
LSCPResultSet result; |
2014 |
try { |
try { |
2015 |
result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID)); |
result.Add("NAME", _escapeLscpResponse(MidiInstrumentMapper::MapName(MidiMapID))); |
2016 |
result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID); |
result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID); |
2017 |
} catch (Exception e) { |
} catch (Exception e) { |
2018 |
result.Error(e); |
result.Error(e); |
2156 |
} |
} |
2157 |
|
|
2158 |
// success |
// success |
2159 |
result.Add("NAME", pFxSend->Name()); |
result.Add("NAME", _escapeLscpResponse(pFxSend->Name())); |
2160 |
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
2161 |
result.Add("LEVEL", ToString(pFxSend->Level())); |
result.Add("LEVEL", ToString(pFxSend->Level())); |
2162 |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
2279 |
*/ |
*/ |
2280 |
String LSCPServer::GetServerInfo() { |
String LSCPServer::GetServerInfo() { |
2281 |
dmsg(2,("LSCPServer: GetServerInfo()\n")); |
dmsg(2,("LSCPServer: GetServerInfo()\n")); |
2282 |
|
const std::string description = |
2283 |
|
_escapeLscpResponse("LinuxSampler - modular, streaming capable sampler"); |
2284 |
LSCPResultSet result; |
LSCPResultSet result; |
2285 |
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
result.Add("DESCRIPTION", description); |
2286 |
result.Add("VERSION", VERSION); |
result.Add("VERSION", VERSION); |
2287 |
result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR)); |
result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR)); |
2288 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2433 |
try { |
try { |
2434 |
DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir); |
DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir); |
2435 |
|
|
2436 |
result.Add("DESCRIPTION", InstrumentsDb::toEscapedText(info.Description)); |
result.Add("DESCRIPTION", _escapeLscpResponse(info.Description)); |
2437 |
result.Add("CREATED", info.Created); |
result.Add("CREATED", info.Created); |
2438 |
result.Add("MODIFIED", info.Modified); |
result.Add("MODIFIED", info.Modified); |
2439 |
} catch (Exception e) { |
} catch (Exception e) { |
2617 |
result.Add("SIZE", (int)info.Size); |
result.Add("SIZE", (int)info.Size); |
2618 |
result.Add("CREATED", info.Created); |
result.Add("CREATED", info.Created); |
2619 |
result.Add("MODIFIED", info.Modified); |
result.Add("MODIFIED", info.Modified); |
2620 |
result.Add("DESCRIPTION", InstrumentsDb::toEscapedText(info.Description)); |
result.Add("DESCRIPTION", _escapeLscpResponse(info.Description)); |
2621 |
result.Add("IS_DRUM", info.IsDrum); |
result.Add("IS_DRUM", info.IsDrum); |
2622 |
result.Add("PRODUCT", InstrumentsDb::toEscapedText(info.Product)); |
result.Add("PRODUCT", _escapeLscpResponse(info.Product)); |
2623 |
result.Add("ARTISTS", InstrumentsDb::toEscapedText(info.Artists)); |
result.Add("ARTISTS", _escapeLscpResponse(info.Artists)); |
2624 |
result.Add("KEYWORDS", InstrumentsDb::toEscapedText(info.Keywords)); |
result.Add("KEYWORDS", _escapeLscpResponse(info.Keywords)); |
2625 |
} catch (Exception e) { |
} catch (Exception e) { |
2626 |
result.Error(e); |
result.Error(e); |
2627 |
} |
} |