25 |
#include "lscpresultset.h" |
#include "lscpresultset.h" |
26 |
#include "lscpevent.h" |
#include "lscpevent.h" |
27 |
|
|
28 |
|
#if defined(WIN32) |
29 |
|
#include <windows.h> |
30 |
|
#else |
31 |
#include <fcntl.h> |
#include <fcntl.h> |
32 |
|
#endif |
33 |
|
|
34 |
#if ! HAVE_SQLITE3 |
#if ! HAVE_SQLITE3 |
35 |
#define DOESNT_HAVE_SQLITE3 "No database support. SQLITE3 was not installed when linuxsampler was built." |
#define DOESNT_HAVE_SQLITE3 "No database support. SQLITE3 was not installed when linuxsampler was built." |
40 |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
41 |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
42 |
|
|
43 |
|
|
44 |
|
/** |
45 |
|
* Returns a copy of the given string where all special characters are |
46 |
|
* replaced by LSCP escape sequences ("\xHH"). This function shall be used |
47 |
|
* to escape LSCP response fields in case the respective response field is |
48 |
|
* actually defined as using escape sequences in the LSCP specs. |
49 |
|
* |
50 |
|
* @e Caution: DO NOT use this function for escaping path based responses, |
51 |
|
* use the Path class (src/common/Path.h) for this instead! |
52 |
|
*/ |
53 |
|
static String _escapeLscpResponse(String txt) { |
54 |
|
for (int i = 0; i < txt.length(); i++) { |
55 |
|
const char c = txt.c_str()[i]; |
56 |
|
if ( |
57 |
|
!(c >= '0' && c <= '9') && |
58 |
|
!(c >= 'a' && c <= 'z') && |
59 |
|
!(c >= 'A' && c <= 'Z') && |
60 |
|
!(c == ' ') && !(c == '!') && !(c == '#') && !(c == '$') && |
61 |
|
!(c == '%') && !(c == '&') && !(c == '(') && !(c == ')') && |
62 |
|
!(c == '*') && !(c == '+') && !(c == ',') && !(c == '-') && |
63 |
|
!(c == '.') && !(c == '/') && !(c == ':') && !(c == ';') && |
64 |
|
!(c == '<') && !(c == '=') && !(c == '>') && !(c == '?') && |
65 |
|
!(c == '@') && !(c == '[') && !(c == ']') && |
66 |
|
!(c == '^') && !(c == '_') && !(c == '`') && !(c == '{') && |
67 |
|
!(c == '|') && !(c == '}') && !(c == '~') |
68 |
|
) { |
69 |
|
// convert the "special" character into a "\xHH" LSCP escape sequence |
70 |
|
char buf[5]; |
71 |
|
snprintf(buf, sizeof(buf), "\\x%02x", static_cast<unsigned char>(c)); |
72 |
|
txt.replace(i, 1, buf); |
73 |
|
i += 3; |
74 |
|
} |
75 |
|
} |
76 |
|
return txt; |
77 |
|
} |
78 |
|
|
79 |
/** |
/** |
80 |
* Below are a few static members of the LSCPServer class. |
* Below are a few static members of the LSCPServer class. |
81 |
* 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. |
92 |
fd_set LSCPServer::fdSet; |
fd_set LSCPServer::fdSet; |
93 |
int LSCPServer::currentSocket = -1; |
int LSCPServer::currentSocket = -1; |
94 |
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
95 |
|
std::vector<yyparse_param_t>::iterator itCurrentSession = std::vector<yyparse_param_t>::iterator(); |
96 |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
97 |
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
98 |
std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions = std::map< LSCPEvent::event_t, std::list<int> >(); |
std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions = std::map< LSCPEvent::event_t, std::list<int> >(); |
125 |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_info, "DB_INSTRUMENT_DIRECTORY_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_info, "DB_INSTRUMENT_DIRECTORY_INFO"); |
126 |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_count, "DB_INSTRUMENT_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_count, "DB_INSTRUMENT_COUNT"); |
127 |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO"); |
128 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO"); |
129 |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
130 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_total_stream_count, "TOTAL_STREAM_COUNT"); |
131 |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
132 |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
133 |
hSocket = -1; |
hSocket = -1; |
134 |
} |
} |
135 |
|
|
136 |
LSCPServer::~LSCPServer() { |
LSCPServer::~LSCPServer() { |
137 |
|
#if defined(WIN32) |
138 |
|
if (hSocket >= 0) closesocket(hSocket); |
139 |
|
#else |
140 |
if (hSocket >= 0) close(hSocket); |
if (hSocket >= 0) close(hSocket); |
141 |
|
#endif |
142 |
} |
} |
143 |
|
|
144 |
void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) { |
void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) { |
189 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount)); |
190 |
} |
} |
191 |
|
|
192 |
|
void LSCPServer::EventHandler::TotalStreamCountChanged(int NewCount) { |
193 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_stream_count, NewCount)); |
194 |
|
} |
195 |
|
|
196 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
197 |
void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) { |
void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) { |
198 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, Dir)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, InstrumentsDb::toEscapedPath(Dir))); |
199 |
} |
} |
200 |
|
|
201 |
void LSCPServer::DbInstrumentsEventHandler::DirectoryInfoChanged(String Dir) { |
void LSCPServer::DbInstrumentsEventHandler::DirectoryInfoChanged(String Dir) { |
202 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, Dir)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, InstrumentsDb::toEscapedPath(Dir))); |
203 |
} |
} |
204 |
|
|
205 |
void LSCPServer::DbInstrumentsEventHandler::DirectoryNameChanged(String Dir, String NewName) { |
void LSCPServer::DbInstrumentsEventHandler::DirectoryNameChanged(String Dir, String NewName) { |
206 |
Dir = "'" + Dir + "'"; |
Dir = "'" + InstrumentsDb::toEscapedPath(Dir) + "'"; |
207 |
NewName = "'" + NewName + "'"; |
NewName = "'" + InstrumentsDb::toEscapedPath(NewName) + "'"; |
208 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, "NAME", Dir, NewName)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, "NAME", Dir, NewName)); |
209 |
} |
} |
210 |
|
|
211 |
void LSCPServer::DbInstrumentsEventHandler::InstrumentCountChanged(String Dir) { |
void LSCPServer::DbInstrumentsEventHandler::InstrumentCountChanged(String Dir) { |
212 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_count, Dir)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_count, InstrumentsDb::toEscapedPath(Dir))); |
213 |
} |
} |
214 |
|
|
215 |
void LSCPServer::DbInstrumentsEventHandler::InstrumentInfoChanged(String Instr) { |
void LSCPServer::DbInstrumentsEventHandler::InstrumentInfoChanged(String Instr) { |
216 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, Instr)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, InstrumentsDb::toEscapedPath(Instr))); |
217 |
} |
} |
218 |
|
|
219 |
void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) { |
void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) { |
220 |
Instr = "'" + Instr + "'"; |
Instr = "'" + InstrumentsDb::toEscapedPath(Instr) + "'"; |
221 |
NewName = "'" + NewName + "'"; |
NewName = "'" + InstrumentsDb::toEscapedPath(NewName) + "'"; |
222 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, "NAME", Instr, NewName)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, "NAME", Instr, NewName)); |
223 |
} |
} |
224 |
|
|
225 |
|
void LSCPServer::DbInstrumentsEventHandler::JobStatusChanged(int JobId) { |
226 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instrs_job_info, JobId)); |
227 |
|
} |
228 |
#endif // HAVE_SQLITE3 |
#endif // HAVE_SQLITE3 |
229 |
|
|
230 |
|
|
243 |
} |
} |
244 |
|
|
245 |
int LSCPServer::Main() { |
int LSCPServer::Main() { |
246 |
|
#if defined(WIN32) |
247 |
|
WSADATA wsaData; |
248 |
|
int iResult; |
249 |
|
iResult = WSAStartup(MAKEWORD(2,2), &wsaData); |
250 |
|
if (iResult != 0) { |
251 |
|
std::cerr << "LSCPServer: WSAStartup failed: " << iResult << "\n"; |
252 |
|
exit(EXIT_FAILURE); |
253 |
|
} |
254 |
|
#endif |
255 |
hSocket = socket(AF_INET, SOCK_STREAM, 0); |
hSocket = socket(AF_INET, SOCK_STREAM, 0); |
256 |
if (hSocket < 0) { |
if (hSocket < 0) { |
257 |
std::cerr << "LSCPServer: Could not create server socket." << std::endl; |
std::cerr << "LSCPServer: Could not create server socket." << std::endl; |
265 |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
266 |
if (trial > LSCP_SERVER_BIND_TIMEOUT) { |
if (trial > LSCP_SERVER_BIND_TIMEOUT) { |
267 |
std::cerr << "gave up!" << std::endl; |
std::cerr << "gave up!" << std::endl; |
268 |
|
#if defined(WIN32) |
269 |
|
closesocket(hSocket); |
270 |
|
#else |
271 |
close(hSocket); |
close(hSocket); |
272 |
|
#endif |
273 |
//return -1; |
//return -1; |
274 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
275 |
} |
} |
281 |
|
|
282 |
listen(hSocket, 1); |
listen(hSocket, 1); |
283 |
Initialized.Set(true); |
Initialized.Set(true); |
284 |
|
|
285 |
// Registering event listeners |
// Registering event listeners |
286 |
pSampler->AddChannelCountListener(&eventHandler); |
pSampler->AddChannelCountListener(&eventHandler); |
287 |
pSampler->AddAudioDeviceCountListener(&eventHandler); |
pSampler->AddAudioDeviceCountListener(&eventHandler); |
289 |
pSampler->AddVoiceCountListener(&eventHandler); |
pSampler->AddVoiceCountListener(&eventHandler); |
290 |
pSampler->AddStreamCountListener(&eventHandler); |
pSampler->AddStreamCountListener(&eventHandler); |
291 |
pSampler->AddBufferFillListener(&eventHandler); |
pSampler->AddBufferFillListener(&eventHandler); |
292 |
|
pSampler->AddTotalStreamCountListener(&eventHandler); |
293 |
pSampler->AddTotalVoiceCountListener(&eventHandler); |
pSampler->AddTotalVoiceCountListener(&eventHandler); |
294 |
pSampler->AddFxSendCountListener(&eventHandler); |
pSampler->AddFxSendCountListener(&eventHandler); |
295 |
MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler); |
MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler); |
352 |
continue; //Nothing try again |
continue; //Nothing try again |
353 |
if (retval == -1) { |
if (retval == -1) { |
354 |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
355 |
|
#if defined(WIN32) |
356 |
|
closesocket(hSocket); |
357 |
|
#else |
358 |
close(hSocket); |
close(hSocket); |
359 |
|
#endif |
360 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
361 |
} |
} |
362 |
|
|
368 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
369 |
} |
} |
370 |
|
|
371 |
|
#if defined(WIN32) |
372 |
|
u_long nonblock_io = 1; |
373 |
|
if( ioctlsocket(socket, FIONBIO, &nonblock_io) ) { |
374 |
|
std::cerr << "LSCPServer: ioctlsocket: set FIONBIO failed. Error " << WSAGetLastError() << std::endl; |
375 |
|
exit(EXIT_FAILURE); |
376 |
|
} |
377 |
|
#else |
378 |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
379 |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
380 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
381 |
} |
} |
382 |
|
#endif |
383 |
|
|
384 |
// Parser initialization |
// Parser initialization |
385 |
yyparse_param_t yyparse_param; |
yyparse_param_t yyparse_param; |
403 |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
404 |
restart(NULL, dummy); // restart the 'scanner' |
restart(NULL, dummy); // restart the 'scanner' |
405 |
currentSocket = (*iter).hSession; //a hack |
currentSocket = (*iter).hSession; //a hack |
406 |
|
itCurrentSession = iter; // another hack |
407 |
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
408 |
if ((*iter).bVerbose) { // if echo mode enabled |
if ((*iter).bVerbose) { // if echo mode enabled |
409 |
AnswerClient(bufferedCommands[currentSocket]); |
AnswerClient(bufferedCommands[currentSocket]); |
410 |
} |
} |
411 |
int result = yyparse(&(*iter)); |
int result = yyparse(&(*iter)); |
412 |
currentSocket = -1; //continuation of a hack |
currentSocket = -1; //continuation of a hack |
413 |
|
itCurrentSession = Sessions.end(); // hack as well |
414 |
dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket)); |
dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket)); |
415 |
if (result == LSCP_QUIT) { //Was it a quit command by any chance? |
if (result == LSCP_QUIT) { //Was it a quit command by any chance? |
416 |
CloseConnection(iter); |
CloseConnection(iter); |
438 |
NotifyMutex.Lock(); |
NotifyMutex.Lock(); |
439 |
bufferedCommands.erase(socket); |
bufferedCommands.erase(socket); |
440 |
bufferedNotifies.erase(socket); |
bufferedNotifies.erase(socket); |
441 |
|
#if defined(WIN32) |
442 |
|
closesocket(socket); |
443 |
|
#else |
444 |
close(socket); |
close(socket); |
445 |
|
#endif |
446 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
447 |
} |
} |
448 |
|
|
507 |
return command.size(); |
return command.size(); |
508 |
} |
} |
509 |
|
|
510 |
|
extern yyparse_param_t* GetCurrentYaccSession() { |
511 |
|
return &(*itCurrentSession); |
512 |
|
} |
513 |
|
|
514 |
/** |
/** |
515 |
* Will be called to try to read the command from the socket |
* Will be called to try to read the command from the socket |
516 |
* If command is read, it will return true. Otherwise false is returned. |
* If command is read, it will return true. Otherwise false is returned. |
521 |
char c; |
char c; |
522 |
int i = 0; |
int i = 0; |
523 |
while (true) { |
while (true) { |
524 |
|
#if defined(WIN32) |
525 |
|
int result = recv(socket, (char *)&c, 1, 0); //Read one character at a time for now |
526 |
|
#else |
527 |
int result = recv(socket, (void *)&c, 1, 0); //Read one character at a time for now |
int result = recv(socket, (void *)&c, 1, 0); //Read one character at a time for now |
528 |
|
#endif |
529 |
if (result == 0) { //socket was selected, so 0 here means client has closed the connection |
if (result == 0) { //socket was selected, so 0 here means client has closed the connection |
530 |
CloseConnection(iter); |
CloseConnection(iter); |
531 |
break; |
break; |
540 |
} |
} |
541 |
bufferedCommands[socket] += c; |
bufferedCommands[socket] += c; |
542 |
} |
} |
543 |
|
#if defined(WIN32) |
544 |
|
if (result == SOCKET_ERROR) { |
545 |
|
int wsa_lasterror = WSAGetLastError(); |
546 |
|
if (wsa_lasterror == WSAEWOULDBLOCK) //Would block, try again later. |
547 |
|
return false; |
548 |
|
dmsg(2,("LSCPScanner: Socket error after recv() Error %d.\n", wsa_lasterror)); |
549 |
|
CloseConnection(iter); |
550 |
|
break; |
551 |
|
} |
552 |
|
#else |
553 |
if (result == -1) { |
if (result == -1) { |
554 |
if (errno == EAGAIN) //Would block, try again later. |
if (errno == EAGAIN) //Would block, try again later. |
555 |
return false; |
return false; |
588 |
CloseConnection(iter); |
CloseConnection(iter); |
589 |
break; |
break; |
590 |
} |
} |
591 |
|
#endif |
592 |
} |
} |
593 |
return false; |
return false; |
594 |
} |
} |
713 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
714 |
if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); |
if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); |
715 |
|
|
716 |
return pEngineChannel; |
return pEngineChannel; |
717 |
} |
} |
718 |
|
|
719 |
/** |
/** |
862 |
LockRTNotify(); |
LockRTNotify(); |
863 |
try { |
try { |
864 |
Engine* pEngine = EngineFactory::Create(EngineName); |
Engine* pEngine = EngineFactory::Create(EngineName); |
865 |
result.Add("DESCRIPTION", pEngine->Description()); |
result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description())); |
866 |
result.Add("VERSION", pEngine->Version()); |
result.Add("VERSION", pEngine->Version()); |
867 |
EngineFactory::Destroy(pEngine); |
EngineFactory::Destroy(pEngine); |
868 |
} |
} |
935 |
if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
936 |
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
937 |
|
|
938 |
|
// convert the filename into the correct encoding as defined for LSCP |
939 |
|
// (especially in terms of special characters -> escape sequences) |
940 |
|
if (InstrumentFileName != "NONE" && InstrumentFileName != "") { |
941 |
|
#if WIN32 |
942 |
|
InstrumentFileName = Path::fromWindows(InstrumentFileName).toLscp(); |
943 |
|
#else |
944 |
|
// assuming POSIX |
945 |
|
InstrumentFileName = Path::fromPosix(InstrumentFileName).toLscp(); |
946 |
|
#endif |
947 |
|
} |
948 |
|
|
949 |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
950 |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
951 |
result.Add("INSTRUMENT_NAME", InstrumentName); |
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(InstrumentName)); |
952 |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
953 |
result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false")); |
result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false")); |
954 |
result.Add("SOLO", Solo); |
result.Add("SOLO", Solo); |
1890 |
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); |
1891 |
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"); |
1892 |
else { // found |
else { // found |
1893 |
result.Add("NAME", iter->second.Name); |
|
1894 |
|
// convert the filename into the correct encoding as defined for LSCP |
1895 |
|
// (especially in terms of special characters -> escape sequences) |
1896 |
|
#if WIN32 |
1897 |
|
const String instrumentFileName = Path::fromWindows(iter->second.InstrumentFile).toLscp(); |
1898 |
|
#else |
1899 |
|
// assuming POSIX |
1900 |
|
const String instrumentFileName = Path::fromPosix(iter->second.InstrumentFile).toLscp(); |
1901 |
|
#endif |
1902 |
|
|
1903 |
|
result.Add("NAME", _escapeLscpResponse(iter->second.Name)); |
1904 |
result.Add("ENGINE_NAME", iter->second.EngineName); |
result.Add("ENGINE_NAME", iter->second.EngineName); |
1905 |
result.Add("INSTRUMENT_FILE", iter->second.InstrumentFile); |
result.Add("INSTRUMENT_FILE", instrumentFileName); |
1906 |
result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex); |
result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex); |
1907 |
String instrumentName; |
String instrumentName; |
1908 |
Engine* pEngine = EngineFactory::Create(iter->second.EngineName); |
Engine* pEngine = EngineFactory::Create(iter->second.EngineName); |
1915 |
} |
} |
1916 |
EngineFactory::Destroy(pEngine); |
EngineFactory::Destroy(pEngine); |
1917 |
} |
} |
1918 |
result.Add("INSTRUMENT_NAME", instrumentName); |
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName)); |
1919 |
switch (iter->second.LoadMode) { |
switch (iter->second.LoadMode) { |
1920 |
case MidiInstrumentMapper::ON_DEMAND: |
case MidiInstrumentMapper::ON_DEMAND: |
1921 |
result.Add("LOAD_MODE", "ON_DEMAND"); |
result.Add("LOAD_MODE", "ON_DEMAND"); |
2070 |
dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n")); |
dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n")); |
2071 |
LSCPResultSet result; |
LSCPResultSet result; |
2072 |
try { |
try { |
2073 |
result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID)); |
result.Add("NAME", _escapeLscpResponse(MidiInstrumentMapper::MapName(MidiMapID))); |
2074 |
result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID); |
result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID); |
2075 |
} catch (Exception e) { |
} catch (Exception e) { |
2076 |
result.Error(e); |
result.Error(e); |
2121 |
LSCPResultSet result; |
LSCPResultSet result; |
2122 |
try { |
try { |
2123 |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2124 |
|
|
2125 |
FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name); |
FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name); |
2126 |
if (!pFxSend) throw Exception("Could not add FxSend, don't ask, I don't know why (probably a bug)"); |
if (!pFxSend) throw Exception("Could not add FxSend, don't ask, I don't know why (probably a bug)"); |
2127 |
|
|
2205 |
try { |
try { |
2206 |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2207 |
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2208 |
|
|
2209 |
// gather audio routing informations |
// gather audio routing informations |
2210 |
String AudioRouting; |
String AudioRouting; |
2211 |
for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { |
for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { |
2214 |
} |
} |
2215 |
|
|
2216 |
// success |
// success |
2217 |
result.Add("NAME", pFxSend->Name()); |
result.Add("NAME", _escapeLscpResponse(pFxSend->Name())); |
2218 |
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
2219 |
result.Add("LEVEL", ToString(pFxSend->Level())); |
result.Add("LEVEL", ToString(pFxSend->Level())); |
2220 |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
2280 |
return result.Produce(); |
return result.Produce(); |
2281 |
} |
} |
2282 |
|
|
2283 |
|
String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) { |
2284 |
|
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
2285 |
|
LSCPResultSet result; |
2286 |
|
try { |
2287 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
2288 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
2289 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
2290 |
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
2291 |
|
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
2292 |
|
Engine* pEngine = pEngineChannel->GetEngine(); |
2293 |
|
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
2294 |
|
if (!pInstrumentManager) throw Exception("Engine does not provide an instrument manager"); |
2295 |
|
InstrumentManager::instrument_id_t instrumentID; |
2296 |
|
instrumentID.FileName = pEngineChannel->InstrumentFileName(); |
2297 |
|
instrumentID.Index = pEngineChannel->InstrumentIndex(); |
2298 |
|
pInstrumentManager->LaunchInstrumentEditor(instrumentID); |
2299 |
|
} catch (Exception e) { |
2300 |
|
result.Error(e); |
2301 |
|
} |
2302 |
|
return result.Produce(); |
2303 |
|
} |
2304 |
|
|
2305 |
/** |
/** |
2306 |
* Will be called by the parser to reset a particular sampler channel. |
* Will be called by the parser to reset a particular sampler channel. |
2307 |
*/ |
*/ |
2337 |
*/ |
*/ |
2338 |
String LSCPServer::GetServerInfo() { |
String LSCPServer::GetServerInfo() { |
2339 |
dmsg(2,("LSCPServer: GetServerInfo()\n")); |
dmsg(2,("LSCPServer: GetServerInfo()\n")); |
2340 |
|
const std::string description = |
2341 |
|
_escapeLscpResponse("LinuxSampler - modular, streaming capable sampler"); |
2342 |
LSCPResultSet result; |
LSCPResultSet result; |
2343 |
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
result.Add("DESCRIPTION", description); |
2344 |
result.Add("VERSION", VERSION); |
result.Add("VERSION", VERSION); |
2345 |
result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR)); |
result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR)); |
2346 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2348 |
#else |
#else |
2349 |
result.Add("INSTRUMENTS_DB_SUPPORT", "no"); |
result.Add("INSTRUMENTS_DB_SUPPORT", "no"); |
2350 |
#endif |
#endif |
2351 |
|
|
2352 |
|
return result.Produce(); |
2353 |
|
} |
2354 |
|
|
2355 |
|
/** |
2356 |
|
* Will be called by the parser to return the current number of all active streams. |
2357 |
|
*/ |
2358 |
|
String LSCPServer::GetTotalStreamCount() { |
2359 |
|
dmsg(2,("LSCPServer: GetTotalStreamCount()\n")); |
2360 |
|
LSCPResultSet result; |
2361 |
|
result.Add(pSampler->GetDiskStreamCount()); |
2362 |
return result.Produce(); |
return result.Produce(); |
2363 |
} |
} |
2364 |
|
|
2400 |
return result.Produce(); |
return result.Produce(); |
2401 |
} |
} |
2402 |
|
|
2403 |
|
String LSCPServer::GetFileInstruments(String Filename) { |
2404 |
|
dmsg(2,("LSCPServer: GetFileInstruments(String Filename=%s)\n",Filename.c_str())); |
2405 |
|
LSCPResultSet result; |
2406 |
|
try { |
2407 |
|
VerifyFile(Filename); |
2408 |
|
} catch (Exception e) { |
2409 |
|
result.Error(e); |
2410 |
|
return result.Produce(); |
2411 |
|
} |
2412 |
|
// try to find a sampler engine that can handle the file |
2413 |
|
bool bFound = false; |
2414 |
|
std::vector<String> engineTypes = EngineFactory::AvailableEngineTypes(); |
2415 |
|
for (int i = 0; !bFound && i < engineTypes.size(); i++) { |
2416 |
|
Engine* pEngine = NULL; |
2417 |
|
try { |
2418 |
|
pEngine = EngineFactory::Create(engineTypes[i]); |
2419 |
|
if (!pEngine) throw Exception("Internal error: could not create '" + engineTypes[i] + "' engine"); |
2420 |
|
InstrumentManager* pManager = pEngine->GetInstrumentManager(); |
2421 |
|
if (pManager) { |
2422 |
|
std::vector<InstrumentManager::instrument_id_t> IDs = |
2423 |
|
pManager->GetInstrumentFileContent(Filename); |
2424 |
|
// return the amount of instruments in the file |
2425 |
|
result.Add(IDs.size()); |
2426 |
|
// no more need to ask other engine types |
2427 |
|
bFound = true; |
2428 |
|
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
2429 |
|
} catch (Exception e) { |
2430 |
|
// NOOP, as exception is thrown if engine doesn't support file |
2431 |
|
} |
2432 |
|
if (pEngine) EngineFactory::Destroy(pEngine); |
2433 |
|
} |
2434 |
|
|
2435 |
|
if (!bFound) result.Error("Unknown file format"); |
2436 |
|
return result.Produce(); |
2437 |
|
} |
2438 |
|
|
2439 |
|
String LSCPServer::ListFileInstruments(String Filename) { |
2440 |
|
dmsg(2,("LSCPServer: ListFileInstruments(String Filename=%s)\n",Filename.c_str())); |
2441 |
|
LSCPResultSet result; |
2442 |
|
try { |
2443 |
|
VerifyFile(Filename); |
2444 |
|
} catch (Exception e) { |
2445 |
|
result.Error(e); |
2446 |
|
return result.Produce(); |
2447 |
|
} |
2448 |
|
// try to find a sampler engine that can handle the file |
2449 |
|
bool bFound = false; |
2450 |
|
std::vector<String> engineTypes = EngineFactory::AvailableEngineTypes(); |
2451 |
|
for (int i = 0; !bFound && i < engineTypes.size(); i++) { |
2452 |
|
Engine* pEngine = NULL; |
2453 |
|
try { |
2454 |
|
pEngine = EngineFactory::Create(engineTypes[i]); |
2455 |
|
if (!pEngine) throw Exception("Internal error: could not create '" + engineTypes[i] + "' engine"); |
2456 |
|
InstrumentManager* pManager = pEngine->GetInstrumentManager(); |
2457 |
|
if (pManager) { |
2458 |
|
std::vector<InstrumentManager::instrument_id_t> IDs = |
2459 |
|
pManager->GetInstrumentFileContent(Filename); |
2460 |
|
// return a list of IDs of the instruments in the file |
2461 |
|
String s; |
2462 |
|
for (int j = 0; j < IDs.size(); j++) { |
2463 |
|
if (s.size()) s += ","; |
2464 |
|
s += ToString(IDs[j].Index); |
2465 |
|
} |
2466 |
|
result.Add(s); |
2467 |
|
// no more need to ask other engine types |
2468 |
|
bFound = true; |
2469 |
|
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
2470 |
|
} catch (Exception e) { |
2471 |
|
// NOOP, as exception is thrown if engine doesn't support file |
2472 |
|
} |
2473 |
|
if (pEngine) EngineFactory::Destroy(pEngine); |
2474 |
|
} |
2475 |
|
|
2476 |
|
if (!bFound) result.Error("Unknown file format"); |
2477 |
|
return result.Produce(); |
2478 |
|
} |
2479 |
|
|
2480 |
|
String LSCPServer::GetFileInstrumentInfo(String Filename, uint InstrumentID) { |
2481 |
|
dmsg(2,("LSCPServer: GetFileInstrumentInfo(String Filename=%s, InstrumentID=%d)\n",Filename.c_str(),InstrumentID)); |
2482 |
|
LSCPResultSet result; |
2483 |
|
try { |
2484 |
|
VerifyFile(Filename); |
2485 |
|
} catch (Exception e) { |
2486 |
|
result.Error(e); |
2487 |
|
return result.Produce(); |
2488 |
|
} |
2489 |
|
InstrumentManager::instrument_id_t id; |
2490 |
|
id.FileName = Filename; |
2491 |
|
id.Index = InstrumentID; |
2492 |
|
// try to find a sampler engine that can handle the file |
2493 |
|
bool bFound = false; |
2494 |
|
bool bFatalErr = false; |
2495 |
|
std::vector<String> engineTypes = EngineFactory::AvailableEngineTypes(); |
2496 |
|
for (int i = 0; !bFound && !bFatalErr && i < engineTypes.size(); i++) { |
2497 |
|
Engine* pEngine = NULL; |
2498 |
|
try { |
2499 |
|
pEngine = EngineFactory::Create(engineTypes[i]); |
2500 |
|
if (!pEngine) throw Exception("Internal error: could not create '" + engineTypes[i] + "' engine"); |
2501 |
|
InstrumentManager* pManager = pEngine->GetInstrumentManager(); |
2502 |
|
if (pManager) { |
2503 |
|
// check if the instrument index is valid |
2504 |
|
// FIXME: this won't work if an engine only supports parts of the instrument file |
2505 |
|
std::vector<InstrumentManager::instrument_id_t> IDs = |
2506 |
|
pManager->GetInstrumentFileContent(Filename); |
2507 |
|
if (std::find(IDs.begin(), IDs.end(), id) == IDs.end()) { |
2508 |
|
std::stringstream ss; |
2509 |
|
ss << "Invalid instrument index " << InstrumentID << " for instrument file '" << Filename << "'"; |
2510 |
|
bFatalErr = true; |
2511 |
|
throw Exception(ss.str()); |
2512 |
|
} |
2513 |
|
// get the info of the requested instrument |
2514 |
|
InstrumentManager::instrument_info_t info = |
2515 |
|
pManager->GetInstrumentInfo(id); |
2516 |
|
// return detailed informations about the file |
2517 |
|
result.Add("NAME", info.InstrumentName); |
2518 |
|
result.Add("FORMAT_FAMILY", engineTypes[i]); |
2519 |
|
result.Add("FORMAT_VERSION", info.FormatVersion); |
2520 |
|
result.Add("PRODUCT", info.Product); |
2521 |
|
result.Add("ARTISTS", info.Artists); |
2522 |
|
// no more need to ask other engine types |
2523 |
|
bFound = true; |
2524 |
|
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
2525 |
|
} catch (Exception e) { |
2526 |
|
// usually NOOP, as exception is thrown if engine doesn't support file |
2527 |
|
if (bFatalErr) result.Error(e); |
2528 |
|
} |
2529 |
|
if (pEngine) EngineFactory::Destroy(pEngine); |
2530 |
|
} |
2531 |
|
|
2532 |
|
if (!bFound && !bFatalErr) result.Error("Unknown file format"); |
2533 |
|
return result.Produce(); |
2534 |
|
} |
2535 |
|
|
2536 |
|
void LSCPServer::VerifyFile(String Filename) { |
2537 |
|
#if WIN32 |
2538 |
|
WIN32_FIND_DATA win32FileAttributeData; |
2539 |
|
BOOL res = GetFileAttributesEx( Filename.c_str(), GetFileExInfoStandard, &win32FileAttributeData ); |
2540 |
|
if (!res) { |
2541 |
|
std::stringstream ss; |
2542 |
|
ss << "File does not exist, GetFileAttributesEx failed `" << Filename << "`: Error " << GetLastError(); |
2543 |
|
throw Exception(ss.str()); |
2544 |
|
} |
2545 |
|
if ( win32FileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { |
2546 |
|
throw Exception("Directory is specified"); |
2547 |
|
} |
2548 |
|
#else |
2549 |
|
struct stat statBuf; |
2550 |
|
int res = stat(Filename.c_str(), &statBuf); |
2551 |
|
if (res) { |
2552 |
|
std::stringstream ss; |
2553 |
|
ss << "Fail to stat `" << Filename << "`: " << strerror(errno); |
2554 |
|
throw Exception(ss.str()); |
2555 |
|
} |
2556 |
|
|
2557 |
|
if (S_ISDIR(statBuf.st_mode)) { |
2558 |
|
throw Exception("Directory is specified"); |
2559 |
|
} |
2560 |
|
#endif |
2561 |
|
} |
2562 |
|
|
2563 |
/** |
/** |
2564 |
* Will be called by the parser to subscribe a client (frontend) on the |
* Will be called by the parser to subscribe a client (frontend) on the |
2565 |
* server for receiving event messages. |
* server for receiving event messages. |
2641 |
|
|
2642 |
for (int i = 0; i < dirs->size(); i++) { |
for (int i = 0; i < dirs->size(); i++) { |
2643 |
if (list != "") list += ","; |
if (list != "") list += ","; |
2644 |
list += "'" + dirs->at(i) + "'"; |
list += "'" + InstrumentsDb::toEscapedPath(dirs->at(i)) + "'"; |
2645 |
} |
} |
2646 |
|
|
2647 |
result.Add(list); |
result.Add(list); |
2661 |
try { |
try { |
2662 |
DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir); |
DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir); |
2663 |
|
|
2664 |
result.Add("DESCRIPTION", info.Description); |
result.Add("DESCRIPTION", _escapeLscpResponse(info.Description)); |
2665 |
result.Add("CREATED", info.Created); |
result.Add("CREATED", info.Created); |
2666 |
result.Add("MODIFIED", info.Modified); |
result.Add("MODIFIED", info.Modified); |
2667 |
} catch (Exception e) { |
} catch (Exception e) { |
2733 |
return result.Produce(); |
return result.Produce(); |
2734 |
} |
} |
2735 |
|
|
2736 |
String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index) { |
String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index, bool bBackground) { |
2737 |
dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d)\n", DbDir.c_str(), FilePath.c_str(), Index)); |
dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d,bBackground=%d)\n", DbDir.c_str(), FilePath.c_str(), Index, bBackground)); |
2738 |
LSCPResultSet result; |
LSCPResultSet result; |
2739 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2740 |
try { |
try { |
2741 |
InstrumentsDb::GetInstrumentsDb()->AddInstruments(DbDir, FilePath, Index); |
int id; |
2742 |
|
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
2743 |
|
id = db->AddInstruments(DbDir, FilePath, Index, bBackground); |
2744 |
|
if (bBackground) result = id; |
2745 |
} catch (Exception e) { |
} catch (Exception e) { |
2746 |
result.Error(e); |
result.Error(e); |
2747 |
} |
} |
2751 |
return result.Produce(); |
return result.Produce(); |
2752 |
} |
} |
2753 |
|
|
2754 |
String LSCPServer::AddDbInstrumentsFlat(String DbDir, String FsDir) { |
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) { |
2755 |
dmsg(2,("LSCPServer: AddDbInstrumentsFlat(DbDir=%s,FilePath=%s)\n", DbDir.c_str(), FsDir.c_str())); |
dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground)); |
2756 |
LSCPResultSet result; |
LSCPResultSet result; |
2757 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2758 |
try { |
try { |
2759 |
InstrumentsDb::GetInstrumentsDb()->AddInstrumentsRecursive(DbDir, FsDir, true); |
int id; |
2760 |
} catch (Exception e) { |
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
2761 |
result.Error(e); |
if (ScanMode.compare("RECURSIVE") == 0) { |
2762 |
} |
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground); |
2763 |
#else |
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
2764 |
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground); |
2765 |
#endif |
} else if (ScanMode.compare("FLAT") == 0) { |
2766 |
return result.Produce(); |
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground); |
2767 |
} |
} else { |
2768 |
|
throw Exception("Unknown scan mode: " + ScanMode); |
2769 |
|
} |
2770 |
|
|
2771 |
String LSCPServer::AddDbInstrumentsNonrecursive(String DbDir, String FsDir) { |
if (bBackground) result = id; |
|
dmsg(2,("LSCPServer: AddDbInstrumentsNonrecursive(DbDir=%s,FilePath=%s)\n", DbDir.c_str(), FsDir.c_str())); |
|
|
LSCPResultSet result; |
|
|
#if HAVE_SQLITE3 |
|
|
try { |
|
|
InstrumentsDb::GetInstrumentsDb()->AddInstrumentsNonrecursive(DbDir, FsDir); |
|
2772 |
} catch (Exception e) { |
} catch (Exception e) { |
2773 |
result.Error(e); |
result.Error(e); |
2774 |
} |
} |
2818 |
|
|
2819 |
for (int i = 0; i < instrs->size(); i++) { |
for (int i = 0; i < instrs->size(); i++) { |
2820 |
if (list != "") list += ","; |
if (list != "") list += ","; |
2821 |
list += "'" + instrs->at(i) + "'"; |
list += "'" + InstrumentsDb::toEscapedPath(instrs->at(i)) + "'"; |
2822 |
} |
} |
2823 |
|
|
2824 |
result.Add(list); |
result.Add(list); |
2845 |
result.Add("SIZE", (int)info.Size); |
result.Add("SIZE", (int)info.Size); |
2846 |
result.Add("CREATED", info.Created); |
result.Add("CREATED", info.Created); |
2847 |
result.Add("MODIFIED", info.Modified); |
result.Add("MODIFIED", info.Modified); |
2848 |
result.Add("DESCRIPTION", FilterEndlines(info.Description)); |
result.Add("DESCRIPTION", _escapeLscpResponse(info.Description)); |
2849 |
result.Add("IS_DRUM", info.IsDrum); |
result.Add("IS_DRUM", info.IsDrum); |
2850 |
result.Add("PRODUCT", FilterEndlines(info.Product)); |
result.Add("PRODUCT", _escapeLscpResponse(info.Product)); |
2851 |
result.Add("ARTISTS", FilterEndlines(info.Artists)); |
result.Add("ARTISTS", _escapeLscpResponse(info.Artists)); |
2852 |
result.Add("KEYWORDS", FilterEndlines(info.Keywords)); |
result.Add("KEYWORDS", _escapeLscpResponse(info.Keywords)); |
2853 |
|
} catch (Exception e) { |
2854 |
|
result.Error(e); |
2855 |
|
} |
2856 |
|
#else |
2857 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2858 |
|
#endif |
2859 |
|
return result.Produce(); |
2860 |
|
} |
2861 |
|
|
2862 |
|
String LSCPServer::GetDbInstrumentsJobInfo(int JobId) { |
2863 |
|
dmsg(2,("LSCPServer: GetDbInstrumentsJobInfo(JobId=%d)\n", JobId)); |
2864 |
|
LSCPResultSet result; |
2865 |
|
#if HAVE_SQLITE3 |
2866 |
|
try { |
2867 |
|
ScanJob job = InstrumentsDb::GetInstrumentsDb()->Jobs.GetJobById(JobId); |
2868 |
|
|
2869 |
|
result.Add("FILES_TOTAL", job.FilesTotal); |
2870 |
|
result.Add("FILES_SCANNED", job.FilesScanned); |
2871 |
|
result.Add("SCANNING", job.Scanning); |
2872 |
|
result.Add("STATUS", job.Status); |
2873 |
} catch (Exception e) { |
} catch (Exception e) { |
2874 |
result.Error(e); |
result.Error(e); |
2875 |
} |
} |
2966 |
|
|
2967 |
for (int i = 0; i < pDirectories->size(); i++) { |
for (int i = 0; i < pDirectories->size(); i++) { |
2968 |
if (list != "") list += ","; |
if (list != "") list += ","; |
2969 |
list += "'" + pDirectories->at(i) + "'"; |
list += "'" + InstrumentsDb::toEscapedPath(pDirectories->at(i)) + "'"; |
2970 |
} |
} |
2971 |
|
|
2972 |
result.Add(list); |
result.Add(list); |
3022 |
|
|
3023 |
for (int i = 0; i < pInstruments->size(); i++) { |
for (int i = 0; i < pInstruments->size(); i++) { |
3024 |
if (list != "") list += ","; |
if (list != "") list += ","; |
3025 |
list += "'" + pInstruments->at(i) + "'"; |
list += "'" + InstrumentsDb::toEscapedPath(pInstruments->at(i)) + "'"; |
3026 |
} |
} |
3027 |
|
|
3028 |
result.Add(list); |
result.Add(list); |
3035 |
return result.Produce(); |
return result.Produce(); |
3036 |
} |
} |
3037 |
|
|
3038 |
|
String LSCPServer::FormatInstrumentsDb() { |
3039 |
|
dmsg(2,("LSCPServer: FormatInstrumentsDb()\n")); |
3040 |
|
LSCPResultSet result; |
3041 |
|
#if HAVE_SQLITE3 |
3042 |
|
try { |
3043 |
|
InstrumentsDb::GetInstrumentsDb()->Format(); |
3044 |
|
} catch (Exception e) { |
3045 |
|
result.Error(e); |
3046 |
|
} |
3047 |
|
#else |
3048 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3049 |
|
#endif |
3050 |
|
return result.Produce(); |
3051 |
|
} |
3052 |
|
|
3053 |
|
|
3054 |
/** |
/** |
3055 |
* Will be called by the parser to enable or disable echo mode; if echo |
* Will be called by the parser to enable or disable echo mode; if echo |
3069 |
} |
} |
3070 |
return result.Produce(); |
return result.Produce(); |
3071 |
} |
} |
|
|
|
|
String LSCPServer::FilterEndlines(String s) { |
|
|
String s2 = s; |
|
|
for (int i = 0; i < s2.length(); i++) { |
|
|
if (s2.at(i) == '\r') s2.at(i) = ' '; |
|
|
else if (s2.at(i) == '\n') s2.at(i) = ' '; |
|
|
} |
|
|
|
|
|
return s2; |
|
|
} |
|