24 |
#include "lscpserver.h" |
#include "lscpserver.h" |
25 |
#include "lscpresultset.h" |
#include "lscpresultset.h" |
26 |
#include "lscpevent.h" |
#include "lscpevent.h" |
|
#include "../common/global.h" |
|
27 |
|
|
28 |
|
#if defined(WIN32) |
29 |
|
#else |
30 |
#include <fcntl.h> |
#include <fcntl.h> |
31 |
|
#endif |
32 |
|
|
33 |
#if HAVE_SQLITE3 |
#if ! HAVE_SQLITE3 |
34 |
# include "sqlite3.h" |
#define DOESNT_HAVE_SQLITE3 "No database support. SQLITE3 was not installed when linuxsampler was built." |
35 |
#endif |
#endif |
36 |
|
|
37 |
#include "../engines/EngineFactory.h" |
#include "../engines/EngineFactory.h" |
39 |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
40 |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
41 |
|
|
42 |
|
|
43 |
|
/** |
44 |
|
* Returns a copy of the given string where all special characters are |
45 |
|
* replaced by LSCP escape sequences ("\xHH"). This function shall be used |
46 |
|
* to escape LSCP response fields in case the respective response field is |
47 |
|
* actually defined as using escape sequences in the LSCP specs. |
48 |
|
* |
49 |
|
* @e Caution: DO NOT use this function for escaping path based responses, |
50 |
|
* use the Path class (src/common/Path.h) for this instead! |
51 |
|
*/ |
52 |
|
static String _escapeLscpResponse(String txt) { |
53 |
|
for (int i = 0; i < txt.length(); i++) { |
54 |
|
const char c = txt.c_str()[i]; |
55 |
|
if ( |
56 |
|
!(c >= '0' && c <= '9') && |
57 |
|
!(c >= 'a' && c <= 'z') && |
58 |
|
!(c >= 'A' && c <= 'Z') && |
59 |
|
!(c == ' ') && !(c == '!') && !(c == '#') && !(c == '$') && |
60 |
|
!(c == '%') && !(c == '&') && !(c == '(') && !(c == ')') && |
61 |
|
!(c == '*') && !(c == '+') && !(c == ',') && !(c == '-') && |
62 |
|
!(c == '.') && !(c == '/') && !(c == ':') && !(c == ';') && |
63 |
|
!(c == '<') && !(c == '=') && !(c == '>') && !(c == '?') && |
64 |
|
!(c == '@') && !(c == '[') && !(c == ']') && |
65 |
|
!(c == '^') && !(c == '_') && !(c == '`') && !(c == '{') && |
66 |
|
!(c == '|') && !(c == '}') && !(c == '~') |
67 |
|
) { |
68 |
|
// convert the "special" character into a "\xHH" LSCP escape sequence |
69 |
|
char buf[5]; |
70 |
|
snprintf(buf, sizeof(buf), "\\x%02x", static_cast<unsigned char>(c)); |
71 |
|
txt.replace(i, 1, buf); |
72 |
|
i += 3; |
73 |
|
} |
74 |
|
} |
75 |
|
return txt; |
76 |
|
} |
77 |
|
|
78 |
/** |
/** |
79 |
* Below are a few static members of the LSCPServer class. |
* Below are a few static members of the LSCPServer class. |
80 |
* 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. |
91 |
fd_set LSCPServer::fdSet; |
fd_set LSCPServer::fdSet; |
92 |
int LSCPServer::currentSocket = -1; |
int LSCPServer::currentSocket = -1; |
93 |
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
94 |
|
std::vector<yyparse_param_t>::iterator itCurrentSession = std::vector<yyparse_param_t>::iterator(); |
95 |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
96 |
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
97 |
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> >(); |
120 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO"); |
121 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT"); |
122 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO"); |
123 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_count, "DB_INSTRUMENT_DIRECTORY_COUNT"); |
124 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_info, "DB_INSTRUMENT_DIRECTORY_INFO"); |
125 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_count, "DB_INSTRUMENT_COUNT"); |
126 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO"); |
127 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO"); |
128 |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
129 |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
130 |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
132 |
} |
} |
133 |
|
|
134 |
LSCPServer::~LSCPServer() { |
LSCPServer::~LSCPServer() { |
135 |
|
#if defined(WIN32) |
136 |
|
if (hSocket >= 0) closesocket(hSocket); |
137 |
|
#else |
138 |
if (hSocket >= 0) close(hSocket); |
if (hSocket >= 0) close(hSocket); |
139 |
|
#endif |
140 |
} |
} |
141 |
|
|
142 |
void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) { |
void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) { |
187 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount)); |
188 |
} |
} |
189 |
|
|
190 |
|
#if HAVE_SQLITE3 |
191 |
|
void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) { |
192 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, InstrumentsDb::toEscapedPath(Dir))); |
193 |
|
} |
194 |
|
|
195 |
|
void LSCPServer::DbInstrumentsEventHandler::DirectoryInfoChanged(String Dir) { |
196 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, InstrumentsDb::toEscapedPath(Dir))); |
197 |
|
} |
198 |
|
|
199 |
|
void LSCPServer::DbInstrumentsEventHandler::DirectoryNameChanged(String Dir, String NewName) { |
200 |
|
Dir = "'" + InstrumentsDb::toEscapedPath(Dir) + "'"; |
201 |
|
NewName = "'" + InstrumentsDb::toEscapedPath(NewName) + "'"; |
202 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, "NAME", Dir, NewName)); |
203 |
|
} |
204 |
|
|
205 |
|
void LSCPServer::DbInstrumentsEventHandler::InstrumentCountChanged(String Dir) { |
206 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_count, InstrumentsDb::toEscapedPath(Dir))); |
207 |
|
} |
208 |
|
|
209 |
|
void LSCPServer::DbInstrumentsEventHandler::InstrumentInfoChanged(String Instr) { |
210 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, InstrumentsDb::toEscapedPath(Instr))); |
211 |
|
} |
212 |
|
|
213 |
|
void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) { |
214 |
|
Instr = "'" + InstrumentsDb::toEscapedPath(Instr) + "'"; |
215 |
|
NewName = "'" + InstrumentsDb::toEscapedPath(NewName) + "'"; |
216 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, "NAME", Instr, NewName)); |
217 |
|
} |
218 |
|
|
219 |
|
void LSCPServer::DbInstrumentsEventHandler::JobStatusChanged(int JobId) { |
220 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instrs_job_info, JobId)); |
221 |
|
} |
222 |
|
#endif // HAVE_SQLITE3 |
223 |
|
|
224 |
|
|
225 |
/** |
/** |
226 |
* Blocks the calling thread until the LSCP Server is initialized and |
* Blocks the calling thread until the LSCP Server is initialized and |
237 |
} |
} |
238 |
|
|
239 |
int LSCPServer::Main() { |
int LSCPServer::Main() { |
240 |
|
#if defined(WIN32) |
241 |
|
WSADATA wsaData; |
242 |
|
int iResult; |
243 |
|
iResult = WSAStartup(MAKEWORD(2,2), &wsaData); |
244 |
|
if (iResult != 0) { |
245 |
|
std::cerr << "LSCPServer: WSAStartup failed: " << iResult << "\n"; |
246 |
|
exit(EXIT_FAILURE); |
247 |
|
} |
248 |
|
#endif |
249 |
hSocket = socket(AF_INET, SOCK_STREAM, 0); |
hSocket = socket(AF_INET, SOCK_STREAM, 0); |
250 |
if (hSocket < 0) { |
if (hSocket < 0) { |
251 |
std::cerr << "LSCPServer: Could not create server socket." << std::endl; |
std::cerr << "LSCPServer: Could not create server socket." << std::endl; |
259 |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
260 |
if (trial > LSCP_SERVER_BIND_TIMEOUT) { |
if (trial > LSCP_SERVER_BIND_TIMEOUT) { |
261 |
std::cerr << "gave up!" << std::endl; |
std::cerr << "gave up!" << std::endl; |
262 |
|
#if defined(WIN32) |
263 |
|
closesocket(hSocket); |
264 |
|
#else |
265 |
close(hSocket); |
close(hSocket); |
266 |
|
#endif |
267 |
//return -1; |
//return -1; |
268 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
269 |
} |
} |
275 |
|
|
276 |
listen(hSocket, 1); |
listen(hSocket, 1); |
277 |
Initialized.Set(true); |
Initialized.Set(true); |
278 |
|
|
279 |
// Registering event listeners |
// Registering event listeners |
280 |
pSampler->AddChannelCountListener(&eventHandler); |
pSampler->AddChannelCountListener(&eventHandler); |
281 |
pSampler->AddAudioDeviceCountListener(&eventHandler); |
pSampler->AddAudioDeviceCountListener(&eventHandler); |
289 |
MidiInstrumentMapper::AddMidiInstrumentInfoListener(&eventHandler); |
MidiInstrumentMapper::AddMidiInstrumentInfoListener(&eventHandler); |
290 |
MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&eventHandler); |
MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&eventHandler); |
291 |
MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(&eventHandler); |
MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(&eventHandler); |
292 |
|
#if HAVE_SQLITE3 |
293 |
|
InstrumentsDb::GetInstrumentsDb()->AddInstrumentsDbListener(&dbInstrumentsEventHandler); |
294 |
|
#endif |
295 |
// now wait for client connections and handle their requests |
// now wait for client connections and handle their requests |
296 |
sockaddr_in client; |
sockaddr_in client; |
297 |
int length = sizeof(client); |
int length = sizeof(client); |
345 |
continue; //Nothing try again |
continue; //Nothing try again |
346 |
if (retval == -1) { |
if (retval == -1) { |
347 |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
348 |
|
#if defined(WIN32) |
349 |
|
closesocket(hSocket); |
350 |
|
#else |
351 |
close(hSocket); |
close(hSocket); |
352 |
|
#endif |
353 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
354 |
} |
} |
355 |
|
|
361 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
362 |
} |
} |
363 |
|
|
364 |
|
#if defined(WIN32) |
365 |
|
u_long nonblock_io = 1; |
366 |
|
if( ioctlsocket(socket, FIONBIO, &nonblock_io) ) { |
367 |
|
std::cerr << "LSCPServer: ioctlsocket: set FIONBIO failed. Error " << WSAGetLastError() << std::endl; |
368 |
|
exit(EXIT_FAILURE); |
369 |
|
} |
370 |
|
#else |
371 |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
372 |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
373 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
374 |
} |
} |
375 |
|
#endif |
376 |
|
|
377 |
// Parser initialization |
// Parser initialization |
378 |
yyparse_param_t yyparse_param; |
yyparse_param_t yyparse_param; |
396 |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
397 |
restart(NULL, dummy); // restart the 'scanner' |
restart(NULL, dummy); // restart the 'scanner' |
398 |
currentSocket = (*iter).hSession; //a hack |
currentSocket = (*iter).hSession; //a hack |
399 |
|
itCurrentSession = iter; // another hack |
400 |
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
401 |
if ((*iter).bVerbose) { // if echo mode enabled |
if ((*iter).bVerbose) { // if echo mode enabled |
402 |
AnswerClient(bufferedCommands[currentSocket]); |
AnswerClient(bufferedCommands[currentSocket]); |
403 |
} |
} |
404 |
int result = yyparse(&(*iter)); |
int result = yyparse(&(*iter)); |
405 |
currentSocket = -1; //continuation of a hack |
currentSocket = -1; //continuation of a hack |
406 |
|
itCurrentSession = Sessions.end(); // hack as well |
407 |
dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket)); |
dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket)); |
408 |
if (result == LSCP_QUIT) { //Was it a quit command by any chance? |
if (result == LSCP_QUIT) { //Was it a quit command by any chance? |
409 |
CloseConnection(iter); |
CloseConnection(iter); |
431 |
NotifyMutex.Lock(); |
NotifyMutex.Lock(); |
432 |
bufferedCommands.erase(socket); |
bufferedCommands.erase(socket); |
433 |
bufferedNotifies.erase(socket); |
bufferedNotifies.erase(socket); |
434 |
|
#if defined(WIN32) |
435 |
|
closesocket(socket); |
436 |
|
#else |
437 |
close(socket); |
close(socket); |
438 |
|
#endif |
439 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
440 |
} |
} |
441 |
|
|
500 |
return command.size(); |
return command.size(); |
501 |
} |
} |
502 |
|
|
503 |
|
extern yyparse_param_t* GetCurrentYaccSession() { |
504 |
|
return &(*itCurrentSession); |
505 |
|
} |
506 |
|
|
507 |
/** |
/** |
508 |
* Will be called to try to read the command from the socket |
* Will be called to try to read the command from the socket |
509 |
* If command is read, it will return true. Otherwise false is returned. |
* If command is read, it will return true. Otherwise false is returned. |
514 |
char c; |
char c; |
515 |
int i = 0; |
int i = 0; |
516 |
while (true) { |
while (true) { |
517 |
|
#if defined(WIN32) |
518 |
|
int result = recv(socket, (char *)&c, 1, 0); //Read one character at a time for now |
519 |
|
#else |
520 |
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 |
521 |
|
#endif |
522 |
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 |
523 |
CloseConnection(iter); |
CloseConnection(iter); |
524 |
break; |
break; |
533 |
} |
} |
534 |
bufferedCommands[socket] += c; |
bufferedCommands[socket] += c; |
535 |
} |
} |
536 |
|
#if defined(WIN32) |
537 |
|
if (result == SOCKET_ERROR) { |
538 |
|
int wsa_lasterror = WSAGetLastError(); |
539 |
|
if (wsa_lasterror == WSAEWOULDBLOCK) //Would block, try again later. |
540 |
|
return false; |
541 |
|
dmsg(2,("LSCPScanner: Socket error after recv() Error %d.\n", wsa_lasterror)); |
542 |
|
CloseConnection(iter); |
543 |
|
break; |
544 |
|
} |
545 |
|
#else |
546 |
if (result == -1) { |
if (result == -1) { |
547 |
if (errno == EAGAIN) //Would block, try again later. |
if (errno == EAGAIN) //Would block, try again later. |
548 |
return false; |
return false; |
581 |
CloseConnection(iter); |
CloseConnection(iter); |
582 |
break; |
break; |
583 |
} |
} |
584 |
|
#endif |
585 |
} |
} |
586 |
return false; |
return false; |
587 |
} |
} |
706 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
707 |
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"); |
708 |
|
|
709 |
return pEngineChannel; |
return pEngineChannel; |
710 |
} |
} |
711 |
|
|
712 |
/** |
/** |
855 |
LockRTNotify(); |
LockRTNotify(); |
856 |
try { |
try { |
857 |
Engine* pEngine = EngineFactory::Create(EngineName); |
Engine* pEngine = EngineFactory::Create(EngineName); |
858 |
result.Add("DESCRIPTION", pEngine->Description()); |
result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description())); |
859 |
result.Add("VERSION", pEngine->Version()); |
result.Add("VERSION", pEngine->Version()); |
860 |
EngineFactory::Destroy(pEngine); |
EngineFactory::Destroy(pEngine); |
861 |
} |
} |
928 |
if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
929 |
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
930 |
|
|
931 |
|
// convert the filename into the correct encoding as defined for LSCP |
932 |
|
// (especially in terms of special characters -> escape sequences) |
933 |
|
if (InstrumentFileName != "NONE" && InstrumentFileName != "") { |
934 |
|
#if WIN32 |
935 |
|
InstrumentFileName = Path::fromWindows(InstrumentFileName).toLscp(); |
936 |
|
#else |
937 |
|
// assuming POSIX |
938 |
|
InstrumentFileName = Path::fromPosix(InstrumentFileName).toLscp(); |
939 |
|
#endif |
940 |
|
} |
941 |
|
|
942 |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
943 |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
944 |
result.Add("INSTRUMENT_NAME", InstrumentName); |
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(InstrumentName)); |
945 |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
946 |
result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false")); |
result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false")); |
947 |
result.Add("SOLO", Solo); |
result.Add("SOLO", Solo); |
1883 |
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); |
1884 |
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"); |
1885 |
else { // found |
else { // found |
1886 |
result.Add("NAME", iter->second.Name); |
|
1887 |
|
// convert the filename into the correct encoding as defined for LSCP |
1888 |
|
// (especially in terms of special characters -> escape sequences) |
1889 |
|
#if WIN32 |
1890 |
|
const String instrumentFileName = Path::fromWindows(iter->second.InstrumentFile).toLscp(); |
1891 |
|
#else |
1892 |
|
// assuming POSIX |
1893 |
|
const String instrumentFileName = Path::fromPosix(iter->second.InstrumentFile).toLscp(); |
1894 |
|
#endif |
1895 |
|
|
1896 |
|
result.Add("NAME", _escapeLscpResponse(iter->second.Name)); |
1897 |
result.Add("ENGINE_NAME", iter->second.EngineName); |
result.Add("ENGINE_NAME", iter->second.EngineName); |
1898 |
result.Add("INSTRUMENT_FILE", iter->second.InstrumentFile); |
result.Add("INSTRUMENT_FILE", instrumentFileName); |
1899 |
result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex); |
result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex); |
1900 |
String instrumentName; |
String instrumentName; |
1901 |
Engine* pEngine = EngineFactory::Create(iter->second.EngineName); |
Engine* pEngine = EngineFactory::Create(iter->second.EngineName); |
1908 |
} |
} |
1909 |
EngineFactory::Destroy(pEngine); |
EngineFactory::Destroy(pEngine); |
1910 |
} |
} |
1911 |
result.Add("INSTRUMENT_NAME", instrumentName); |
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName)); |
1912 |
switch (iter->second.LoadMode) { |
switch (iter->second.LoadMode) { |
1913 |
case MidiInstrumentMapper::ON_DEMAND: |
case MidiInstrumentMapper::ON_DEMAND: |
1914 |
result.Add("LOAD_MODE", "ON_DEMAND"); |
result.Add("LOAD_MODE", "ON_DEMAND"); |
2063 |
dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n")); |
dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n")); |
2064 |
LSCPResultSet result; |
LSCPResultSet result; |
2065 |
try { |
try { |
2066 |
result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID)); |
result.Add("NAME", _escapeLscpResponse(MidiInstrumentMapper::MapName(MidiMapID))); |
2067 |
result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID); |
result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID); |
2068 |
} catch (Exception e) { |
} catch (Exception e) { |
2069 |
result.Error(e); |
result.Error(e); |
2114 |
LSCPResultSet result; |
LSCPResultSet result; |
2115 |
try { |
try { |
2116 |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2117 |
|
|
2118 |
FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name); |
FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name); |
2119 |
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)"); |
2120 |
|
|
2198 |
try { |
try { |
2199 |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2200 |
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2201 |
|
|
2202 |
// gather audio routing informations |
// gather audio routing informations |
2203 |
String AudioRouting; |
String AudioRouting; |
2204 |
for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { |
for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { |
2207 |
} |
} |
2208 |
|
|
2209 |
// success |
// success |
2210 |
result.Add("NAME", pFxSend->Name()); |
result.Add("NAME", _escapeLscpResponse(pFxSend->Name())); |
2211 |
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
2212 |
result.Add("LEVEL", ToString(pFxSend->Level())); |
result.Add("LEVEL", ToString(pFxSend->Level())); |
2213 |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
2273 |
return result.Produce(); |
return result.Produce(); |
2274 |
} |
} |
2275 |
|
|
2276 |
|
String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) { |
2277 |
|
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
2278 |
|
LSCPResultSet result; |
2279 |
|
try { |
2280 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
2281 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
2282 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
2283 |
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
2284 |
|
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
2285 |
|
Engine* pEngine = pEngineChannel->GetEngine(); |
2286 |
|
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
2287 |
|
if (!pInstrumentManager) throw Exception("Engine does not provide an instrument manager"); |
2288 |
|
InstrumentManager::instrument_id_t instrumentID; |
2289 |
|
instrumentID.FileName = pEngineChannel->InstrumentFileName(); |
2290 |
|
instrumentID.Index = pEngineChannel->InstrumentIndex(); |
2291 |
|
pInstrumentManager->LaunchInstrumentEditor(instrumentID); |
2292 |
|
} catch (Exception e) { |
2293 |
|
result.Error(e); |
2294 |
|
} |
2295 |
|
return result.Produce(); |
2296 |
|
} |
2297 |
|
|
2298 |
/** |
/** |
2299 |
* Will be called by the parser to reset a particular sampler channel. |
* Will be called by the parser to reset a particular sampler channel. |
2300 |
*/ |
*/ |
2330 |
*/ |
*/ |
2331 |
String LSCPServer::GetServerInfo() { |
String LSCPServer::GetServerInfo() { |
2332 |
dmsg(2,("LSCPServer: GetServerInfo()\n")); |
dmsg(2,("LSCPServer: GetServerInfo()\n")); |
2333 |
|
const std::string description = |
2334 |
|
_escapeLscpResponse("LinuxSampler - modular, streaming capable sampler"); |
2335 |
LSCPResultSet result; |
LSCPResultSet result; |
2336 |
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
result.Add("DESCRIPTION", description); |
2337 |
result.Add("VERSION", VERSION); |
result.Add("VERSION", VERSION); |
2338 |
result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR)); |
result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR)); |
2339 |
|
#if HAVE_SQLITE3 |
2340 |
|
result.Add("INSTRUMENTS_DB_SUPPORT", "yes"); |
2341 |
|
#else |
2342 |
|
result.Add("INSTRUMENTS_DB_SUPPORT", "no"); |
2343 |
|
#endif |
2344 |
|
|
2345 |
return result.Produce(); |
return result.Produce(); |
2346 |
} |
} |
2347 |
|
|
2383 |
return result.Produce(); |
return result.Produce(); |
2384 |
} |
} |
2385 |
|
|
2386 |
|
String LSCPServer::GetFileInstruments(String Filename) { |
2387 |
|
LSCPResultSet result; |
2388 |
|
// try to find a sampler engine that can handle the file |
2389 |
|
bool bFound = false; |
2390 |
|
std::vector<String> engineTypes = EngineFactory::AvailableEngineTypes(); |
2391 |
|
for (int i = 0; !bFound && i < engineTypes.size(); i++) { |
2392 |
|
Engine* pEngine = NULL; |
2393 |
|
try { |
2394 |
|
pEngine = EngineFactory::Create(engineTypes[i]); |
2395 |
|
if (!pEngine) throw Exception("Internal error: could not create '" + engineTypes[i] + "' engine"); |
2396 |
|
InstrumentManager* pManager = pEngine->GetInstrumentManager(); |
2397 |
|
if (pManager) { |
2398 |
|
std::vector<InstrumentManager::instrument_id_t> IDs = |
2399 |
|
pManager->GetInstrumentFileContent(Filename); |
2400 |
|
// return the amount of instruments in the file |
2401 |
|
result.Add(IDs.size()); |
2402 |
|
// no more need to ask other engine types |
2403 |
|
bFound = true; |
2404 |
|
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
2405 |
|
} catch (Exception e) { |
2406 |
|
// NOOP, as exception is thrown if engine doesn't support file |
2407 |
|
} |
2408 |
|
if (pEngine) EngineFactory::Destroy(pEngine); |
2409 |
|
} |
2410 |
|
return result.Produce(); |
2411 |
|
} |
2412 |
|
|
2413 |
|
String LSCPServer::ListFileInstruments(String Filename) { |
2414 |
|
LSCPResultSet result; |
2415 |
|
// try to find a sampler engine that can handle the file |
2416 |
|
bool bFound = false; |
2417 |
|
std::vector<String> engineTypes = EngineFactory::AvailableEngineTypes(); |
2418 |
|
for (int i = 0; !bFound && i < engineTypes.size(); i++) { |
2419 |
|
Engine* pEngine = NULL; |
2420 |
|
try { |
2421 |
|
pEngine = EngineFactory::Create(engineTypes[i]); |
2422 |
|
if (!pEngine) throw Exception("Internal error: could not create '" + engineTypes[i] + "' engine"); |
2423 |
|
InstrumentManager* pManager = pEngine->GetInstrumentManager(); |
2424 |
|
if (pManager) { |
2425 |
|
std::vector<InstrumentManager::instrument_id_t> IDs = |
2426 |
|
pManager->GetInstrumentFileContent(Filename); |
2427 |
|
// return a list of IDs of the instruments in the file |
2428 |
|
String s; |
2429 |
|
for (int j = 0; j < IDs.size(); j++) { |
2430 |
|
if (s.size()) s += ","; |
2431 |
|
s += ToString(IDs[j].Index); |
2432 |
|
} |
2433 |
|
result.Add(s); |
2434 |
|
// no more need to ask other engine types |
2435 |
|
bFound = true; |
2436 |
|
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
2437 |
|
} catch (Exception e) { |
2438 |
|
// NOOP, as exception is thrown if engine doesn't support file |
2439 |
|
} |
2440 |
|
if (pEngine) EngineFactory::Destroy(pEngine); |
2441 |
|
} |
2442 |
|
return result.Produce(); |
2443 |
|
} |
2444 |
|
|
2445 |
|
String LSCPServer::GetFileInstrumentInfo(String Filename, uint InstrumentID) { |
2446 |
|
LSCPResultSet result; |
2447 |
|
InstrumentManager::instrument_id_t id; |
2448 |
|
id.FileName = Filename; |
2449 |
|
id.Index = InstrumentID; |
2450 |
|
// try to find a sampler engine that can handle the file |
2451 |
|
bool bFound = false; |
2452 |
|
std::vector<String> engineTypes = EngineFactory::AvailableEngineTypes(); |
2453 |
|
for (int i = 0; !bFound && i < engineTypes.size(); i++) { |
2454 |
|
Engine* pEngine = NULL; |
2455 |
|
try { |
2456 |
|
pEngine = EngineFactory::Create(engineTypes[i]); |
2457 |
|
if (!pEngine) throw Exception("Internal error: could not create '" + engineTypes[i] + "' engine"); |
2458 |
|
InstrumentManager* pManager = pEngine->GetInstrumentManager(); |
2459 |
|
if (pManager) { |
2460 |
|
InstrumentManager::instrument_info_t info = |
2461 |
|
pManager->GetInstrumentInfo(id); |
2462 |
|
// return detailed informations about the file |
2463 |
|
result.Add("NAME", info.InstrumentName); |
2464 |
|
result.Add("FORMAT_NAME", engineTypes[i]); |
2465 |
|
result.Add("FORMAT_VERSION", info.FormatVersion); |
2466 |
|
result.Add("PRODUCT", info.Product); |
2467 |
|
result.Add("ARTISTS", info.Artists); |
2468 |
|
// no more need to ask other engine types |
2469 |
|
bFound = true; |
2470 |
|
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
2471 |
|
} catch (Exception e) { |
2472 |
|
// NOOP, as exception is thrown if engine doesn't support file |
2473 |
|
} |
2474 |
|
if (pEngine) EngineFactory::Destroy(pEngine); |
2475 |
|
} |
2476 |
|
return result.Produce(); |
2477 |
|
} |
2478 |
|
|
2479 |
/** |
/** |
2480 |
* 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 |
2481 |
* server for receiving event messages. |
* server for receiving event messages. |
2502 |
return result.Produce(); |
return result.Produce(); |
2503 |
} |
} |
2504 |
|
|
2505 |
static int select_callback(void * lscpResultSet, int argc, |
String LSCPServer::AddDbInstrumentDirectory(String Dir) { |
2506 |
char **argv, char **azColName) |
dmsg(2,("LSCPServer: AddDbInstrumentDirectory(Dir=%s)\n", Dir.c_str())); |
2507 |
{ |
LSCPResultSet result; |
2508 |
LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet; |
#if HAVE_SQLITE3 |
2509 |
resultSet->Add(argc, argv); |
try { |
2510 |
return 0; |
InstrumentsDb::GetInstrumentsDb()->AddDirectory(Dir); |
2511 |
|
} catch (Exception e) { |
2512 |
|
result.Error(e); |
2513 |
|
} |
2514 |
|
#else |
2515 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2516 |
|
#endif |
2517 |
|
return result.Produce(); |
2518 |
|
} |
2519 |
|
|
2520 |
|
String LSCPServer::RemoveDbInstrumentDirectory(String Dir, bool Force) { |
2521 |
|
dmsg(2,("LSCPServer: RemoveDbInstrumentDirectory(Dir=%s,Force=%d)\n", Dir.c_str(), Force)); |
2522 |
|
LSCPResultSet result; |
2523 |
|
#if HAVE_SQLITE3 |
2524 |
|
try { |
2525 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveDirectory(Dir, Force); |
2526 |
|
} catch (Exception e) { |
2527 |
|
result.Error(e); |
2528 |
|
} |
2529 |
|
#else |
2530 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2531 |
|
#endif |
2532 |
|
return result.Produce(); |
2533 |
|
} |
2534 |
|
|
2535 |
|
String LSCPServer::GetDbInstrumentDirectoryCount(String Dir, bool Recursive) { |
2536 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2537 |
|
LSCPResultSet result; |
2538 |
|
#if HAVE_SQLITE3 |
2539 |
|
try { |
2540 |
|
result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir, Recursive)); |
2541 |
|
} catch (Exception e) { |
2542 |
|
result.Error(e); |
2543 |
|
} |
2544 |
|
#else |
2545 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2546 |
|
#endif |
2547 |
|
return result.Produce(); |
2548 |
|
} |
2549 |
|
|
2550 |
|
String LSCPServer::GetDbInstrumentDirectories(String Dir, bool Recursive) { |
2551 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2552 |
|
LSCPResultSet result; |
2553 |
|
#if HAVE_SQLITE3 |
2554 |
|
try { |
2555 |
|
String list; |
2556 |
|
StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir, Recursive); |
2557 |
|
|
2558 |
|
for (int i = 0; i < dirs->size(); i++) { |
2559 |
|
if (list != "") list += ","; |
2560 |
|
list += "'" + InstrumentsDb::toEscapedPath(dirs->at(i)) + "'"; |
2561 |
|
} |
2562 |
|
|
2563 |
|
result.Add(list); |
2564 |
|
} catch (Exception e) { |
2565 |
|
result.Error(e); |
2566 |
|
} |
2567 |
|
#else |
2568 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2569 |
|
#endif |
2570 |
|
return result.Produce(); |
2571 |
|
} |
2572 |
|
|
2573 |
|
String LSCPServer::GetDbInstrumentDirectoryInfo(String Dir) { |
2574 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectoryInfo(Dir=%s)\n", Dir.c_str())); |
2575 |
|
LSCPResultSet result; |
2576 |
|
#if HAVE_SQLITE3 |
2577 |
|
try { |
2578 |
|
DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir); |
2579 |
|
|
2580 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(info.Description)); |
2581 |
|
result.Add("CREATED", info.Created); |
2582 |
|
result.Add("MODIFIED", info.Modified); |
2583 |
|
} catch (Exception e) { |
2584 |
|
result.Error(e); |
2585 |
|
} |
2586 |
|
#else |
2587 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2588 |
|
#endif |
2589 |
|
return result.Produce(); |
2590 |
|
} |
2591 |
|
|
2592 |
|
String LSCPServer::SetDbInstrumentDirectoryName(String Dir, String Name) { |
2593 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDirectoryName(Dir=%s,Name=%s)\n", Dir.c_str(), Name.c_str())); |
2594 |
|
LSCPResultSet result; |
2595 |
|
#if HAVE_SQLITE3 |
2596 |
|
try { |
2597 |
|
InstrumentsDb::GetInstrumentsDb()->RenameDirectory(Dir, Name); |
2598 |
|
} catch (Exception e) { |
2599 |
|
result.Error(e); |
2600 |
|
} |
2601 |
|
#else |
2602 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2603 |
|
#endif |
2604 |
|
return result.Produce(); |
2605 |
|
} |
2606 |
|
|
2607 |
|
String LSCPServer::MoveDbInstrumentDirectory(String Dir, String Dst) { |
2608 |
|
dmsg(2,("LSCPServer: MoveDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str())); |
2609 |
|
LSCPResultSet result; |
2610 |
|
#if HAVE_SQLITE3 |
2611 |
|
try { |
2612 |
|
InstrumentsDb::GetInstrumentsDb()->MoveDirectory(Dir, Dst); |
2613 |
|
} catch (Exception e) { |
2614 |
|
result.Error(e); |
2615 |
|
} |
2616 |
|
#else |
2617 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2618 |
|
#endif |
2619 |
|
return result.Produce(); |
2620 |
|
} |
2621 |
|
|
2622 |
|
String LSCPServer::CopyDbInstrumentDirectory(String Dir, String Dst) { |
2623 |
|
dmsg(2,("LSCPServer: CopyDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str())); |
2624 |
|
LSCPResultSet result; |
2625 |
|
#if HAVE_SQLITE3 |
2626 |
|
try { |
2627 |
|
InstrumentsDb::GetInstrumentsDb()->CopyDirectory(Dir, Dst); |
2628 |
|
} catch (Exception e) { |
2629 |
|
result.Error(e); |
2630 |
|
} |
2631 |
|
#else |
2632 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2633 |
|
#endif |
2634 |
|
return result.Produce(); |
2635 |
|
} |
2636 |
|
|
2637 |
|
String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) { |
2638 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDirectoryDescription(Dir=%s,Desc=%s)\n", Dir.c_str(), Desc.c_str())); |
2639 |
|
LSCPResultSet result; |
2640 |
|
#if HAVE_SQLITE3 |
2641 |
|
try { |
2642 |
|
InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc); |
2643 |
|
} catch (Exception e) { |
2644 |
|
result.Error(e); |
2645 |
|
} |
2646 |
|
#else |
2647 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2648 |
|
#endif |
2649 |
|
return result.Produce(); |
2650 |
} |
} |
2651 |
|
|
2652 |
String LSCPServer::QueryDatabase(String query) { |
String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index, bool bBackground) { |
2653 |
|
dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d,bBackground=%d)\n", DbDir.c_str(), FilePath.c_str(), Index, bBackground)); |
2654 |
LSCPResultSet result; |
LSCPResultSet result; |
2655 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2656 |
char* zErrMsg = NULL; |
try { |
2657 |
sqlite3 *db; |
int id; |
2658 |
String selectStr = "SELECT " + query; |
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
2659 |
|
id = db->AddInstruments(DbDir, FilePath, Index, bBackground); |
2660 |
|
if (bBackground) result = id; |
2661 |
|
} catch (Exception e) { |
2662 |
|
result.Error(e); |
2663 |
|
} |
2664 |
|
#else |
2665 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2666 |
|
#endif |
2667 |
|
return result.Produce(); |
2668 |
|
} |
2669 |
|
|
2670 |
|
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) { |
2671 |
|
dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground)); |
2672 |
|
LSCPResultSet result; |
2673 |
|
#if HAVE_SQLITE3 |
2674 |
|
try { |
2675 |
|
int id; |
2676 |
|
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
2677 |
|
if (ScanMode.compare("RECURSIVE") == 0) { |
2678 |
|
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground); |
2679 |
|
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
2680 |
|
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground); |
2681 |
|
} else if (ScanMode.compare("FLAT") == 0) { |
2682 |
|
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground); |
2683 |
|
} else { |
2684 |
|
throw Exception("Unknown scan mode: " + ScanMode); |
2685 |
|
} |
2686 |
|
|
2687 |
int rc = sqlite3_open("linuxsampler.db", &db); |
if (bBackground) result = id; |
2688 |
if (rc == SQLITE_OK) |
} catch (Exception e) { |
2689 |
{ |
result.Error(e); |
|
rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg); |
|
2690 |
} |
} |
2691 |
if ( rc != SQLITE_OK ) |
#else |
2692 |
{ |
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2693 |
result.Error(String(zErrMsg), rc); |
#endif |
2694 |
|
return result.Produce(); |
2695 |
|
} |
2696 |
|
|
2697 |
|
String LSCPServer::RemoveDbInstrument(String Instr) { |
2698 |
|
dmsg(2,("LSCPServer: RemoveDbInstrument(Instr=%s)\n", Instr.c_str())); |
2699 |
|
LSCPResultSet result; |
2700 |
|
#if HAVE_SQLITE3 |
2701 |
|
try { |
2702 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveInstrument(Instr); |
2703 |
|
} catch (Exception e) { |
2704 |
|
result.Error(e); |
2705 |
|
} |
2706 |
|
#else |
2707 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2708 |
|
#endif |
2709 |
|
return result.Produce(); |
2710 |
|
} |
2711 |
|
|
2712 |
|
String LSCPServer::GetDbInstrumentCount(String Dir, bool Recursive) { |
2713 |
|
dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2714 |
|
LSCPResultSet result; |
2715 |
|
#if HAVE_SQLITE3 |
2716 |
|
try { |
2717 |
|
result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir, Recursive)); |
2718 |
|
} catch (Exception e) { |
2719 |
|
result.Error(e); |
2720 |
} |
} |
|
sqlite3_close(db); |
|
2721 |
#else |
#else |
2722 |
result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0); |
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2723 |
#endif |
#endif |
2724 |
return result.Produce(); |
return result.Produce(); |
2725 |
} |
} |
2726 |
|
|
2727 |
|
String LSCPServer::GetDbInstruments(String Dir, bool Recursive) { |
2728 |
|
dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2729 |
|
LSCPResultSet result; |
2730 |
|
#if HAVE_SQLITE3 |
2731 |
|
try { |
2732 |
|
String list; |
2733 |
|
StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir, Recursive); |
2734 |
|
|
2735 |
|
for (int i = 0; i < instrs->size(); i++) { |
2736 |
|
if (list != "") list += ","; |
2737 |
|
list += "'" + InstrumentsDb::toEscapedPath(instrs->at(i)) + "'"; |
2738 |
|
} |
2739 |
|
|
2740 |
|
result.Add(list); |
2741 |
|
} catch (Exception e) { |
2742 |
|
result.Error(e); |
2743 |
|
} |
2744 |
|
#else |
2745 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2746 |
|
#endif |
2747 |
|
return result.Produce(); |
2748 |
|
} |
2749 |
|
|
2750 |
|
String LSCPServer::GetDbInstrumentInfo(String Instr) { |
2751 |
|
dmsg(2,("LSCPServer: GetDbInstrumentInfo(Instr=%s)\n", Instr.c_str())); |
2752 |
|
LSCPResultSet result; |
2753 |
|
#if HAVE_SQLITE3 |
2754 |
|
try { |
2755 |
|
DbInstrument info = InstrumentsDb::GetInstrumentsDb()->GetInstrumentInfo(Instr); |
2756 |
|
|
2757 |
|
result.Add("INSTRUMENT_FILE", info.InstrFile); |
2758 |
|
result.Add("INSTRUMENT_NR", info.InstrNr); |
2759 |
|
result.Add("FORMAT_FAMILY", info.FormatFamily); |
2760 |
|
result.Add("FORMAT_VERSION", info.FormatVersion); |
2761 |
|
result.Add("SIZE", (int)info.Size); |
2762 |
|
result.Add("CREATED", info.Created); |
2763 |
|
result.Add("MODIFIED", info.Modified); |
2764 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(info.Description)); |
2765 |
|
result.Add("IS_DRUM", info.IsDrum); |
2766 |
|
result.Add("PRODUCT", _escapeLscpResponse(info.Product)); |
2767 |
|
result.Add("ARTISTS", _escapeLscpResponse(info.Artists)); |
2768 |
|
result.Add("KEYWORDS", _escapeLscpResponse(info.Keywords)); |
2769 |
|
} catch (Exception e) { |
2770 |
|
result.Error(e); |
2771 |
|
} |
2772 |
|
#else |
2773 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2774 |
|
#endif |
2775 |
|
return result.Produce(); |
2776 |
|
} |
2777 |
|
|
2778 |
|
String LSCPServer::GetDbInstrumentsJobInfo(int JobId) { |
2779 |
|
dmsg(2,("LSCPServer: GetDbInstrumentsJobInfo(JobId=%d)\n", JobId)); |
2780 |
|
LSCPResultSet result; |
2781 |
|
#if HAVE_SQLITE3 |
2782 |
|
try { |
2783 |
|
ScanJob job = InstrumentsDb::GetInstrumentsDb()->Jobs.GetJobById(JobId); |
2784 |
|
|
2785 |
|
result.Add("FILES_TOTAL", job.FilesTotal); |
2786 |
|
result.Add("FILES_SCANNED", job.FilesScanned); |
2787 |
|
result.Add("SCANNING", job.Scanning); |
2788 |
|
result.Add("STATUS", job.Status); |
2789 |
|
} catch (Exception e) { |
2790 |
|
result.Error(e); |
2791 |
|
} |
2792 |
|
#else |
2793 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2794 |
|
#endif |
2795 |
|
return result.Produce(); |
2796 |
|
} |
2797 |
|
|
2798 |
|
String LSCPServer::SetDbInstrumentName(String Instr, String Name) { |
2799 |
|
dmsg(2,("LSCPServer: SetDbInstrumentName(Instr=%s,Name=%s)\n", Instr.c_str(), Name.c_str())); |
2800 |
|
LSCPResultSet result; |
2801 |
|
#if HAVE_SQLITE3 |
2802 |
|
try { |
2803 |
|
InstrumentsDb::GetInstrumentsDb()->RenameInstrument(Instr, Name); |
2804 |
|
} catch (Exception e) { |
2805 |
|
result.Error(e); |
2806 |
|
} |
2807 |
|
#else |
2808 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2809 |
|
#endif |
2810 |
|
return result.Produce(); |
2811 |
|
} |
2812 |
|
|
2813 |
|
String LSCPServer::MoveDbInstrument(String Instr, String Dst) { |
2814 |
|
dmsg(2,("LSCPServer: MoveDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str())); |
2815 |
|
LSCPResultSet result; |
2816 |
|
#if HAVE_SQLITE3 |
2817 |
|
try { |
2818 |
|
InstrumentsDb::GetInstrumentsDb()->MoveInstrument(Instr, Dst); |
2819 |
|
} catch (Exception e) { |
2820 |
|
result.Error(e); |
2821 |
|
} |
2822 |
|
#else |
2823 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2824 |
|
#endif |
2825 |
|
return result.Produce(); |
2826 |
|
} |
2827 |
|
|
2828 |
|
String LSCPServer::CopyDbInstrument(String Instr, String Dst) { |
2829 |
|
dmsg(2,("LSCPServer: CopyDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str())); |
2830 |
|
LSCPResultSet result; |
2831 |
|
#if HAVE_SQLITE3 |
2832 |
|
try { |
2833 |
|
InstrumentsDb::GetInstrumentsDb()->CopyInstrument(Instr, Dst); |
2834 |
|
} catch (Exception e) { |
2835 |
|
result.Error(e); |
2836 |
|
} |
2837 |
|
#else |
2838 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2839 |
|
#endif |
2840 |
|
return result.Produce(); |
2841 |
|
} |
2842 |
|
|
2843 |
|
String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) { |
2844 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDescription(Instr=%s,Desc=%s)\n", Instr.c_str(), Desc.c_str())); |
2845 |
|
LSCPResultSet result; |
2846 |
|
#if HAVE_SQLITE3 |
2847 |
|
try { |
2848 |
|
InstrumentsDb::GetInstrumentsDb()->SetInstrumentDescription(Instr, Desc); |
2849 |
|
} catch (Exception e) { |
2850 |
|
result.Error(e); |
2851 |
|
} |
2852 |
|
#else |
2853 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2854 |
|
#endif |
2855 |
|
return result.Produce(); |
2856 |
|
} |
2857 |
|
|
2858 |
|
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
2859 |
|
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
2860 |
|
LSCPResultSet result; |
2861 |
|
#if HAVE_SQLITE3 |
2862 |
|
try { |
2863 |
|
SearchQuery Query; |
2864 |
|
std::map<String,String>::iterator iter; |
2865 |
|
for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { |
2866 |
|
if (iter->first.compare("NAME") == 0) { |
2867 |
|
Query.Name = iter->second; |
2868 |
|
} else if (iter->first.compare("CREATED") == 0) { |
2869 |
|
Query.SetCreated(iter->second); |
2870 |
|
} else if (iter->first.compare("MODIFIED") == 0) { |
2871 |
|
Query.SetModified(iter->second); |
2872 |
|
} else if (iter->first.compare("DESCRIPTION") == 0) { |
2873 |
|
Query.Description = iter->second; |
2874 |
|
} else { |
2875 |
|
throw Exception("Unknown search criteria: " + iter->first); |
2876 |
|
} |
2877 |
|
} |
2878 |
|
|
2879 |
|
String list; |
2880 |
|
StringListPtr pDirectories = |
2881 |
|
InstrumentsDb::GetInstrumentsDb()->FindDirectories(Dir, &Query, Recursive); |
2882 |
|
|
2883 |
|
for (int i = 0; i < pDirectories->size(); i++) { |
2884 |
|
if (list != "") list += ","; |
2885 |
|
list += "'" + InstrumentsDb::toEscapedPath(pDirectories->at(i)) + "'"; |
2886 |
|
} |
2887 |
|
|
2888 |
|
result.Add(list); |
2889 |
|
} catch (Exception e) { |
2890 |
|
result.Error(e); |
2891 |
|
} |
2892 |
|
#else |
2893 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2894 |
|
#endif |
2895 |
|
return result.Produce(); |
2896 |
|
} |
2897 |
|
|
2898 |
|
String LSCPServer::FindDbInstruments(String Dir, std::map<String,String> Parameters, bool Recursive) { |
2899 |
|
dmsg(2,("LSCPServer: FindDbInstruments(Dir=%s)\n", Dir.c_str())); |
2900 |
|
LSCPResultSet result; |
2901 |
|
#if HAVE_SQLITE3 |
2902 |
|
try { |
2903 |
|
SearchQuery Query; |
2904 |
|
std::map<String,String>::iterator iter; |
2905 |
|
for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { |
2906 |
|
if (iter->first.compare("NAME") == 0) { |
2907 |
|
Query.Name = iter->second; |
2908 |
|
} else if (iter->first.compare("FORMAT_FAMILIES") == 0) { |
2909 |
|
Query.SetFormatFamilies(iter->second); |
2910 |
|
} else if (iter->first.compare("SIZE") == 0) { |
2911 |
|
Query.SetSize(iter->second); |
2912 |
|
} else if (iter->first.compare("CREATED") == 0) { |
2913 |
|
Query.SetCreated(iter->second); |
2914 |
|
} else if (iter->first.compare("MODIFIED") == 0) { |
2915 |
|
Query.SetModified(iter->second); |
2916 |
|
} else if (iter->first.compare("DESCRIPTION") == 0) { |
2917 |
|
Query.Description = iter->second; |
2918 |
|
} else if (iter->first.compare("IS_DRUM") == 0) { |
2919 |
|
if (!strcasecmp(iter->second.c_str(), "true")) { |
2920 |
|
Query.InstrType = SearchQuery::DRUM; |
2921 |
|
} else { |
2922 |
|
Query.InstrType = SearchQuery::CHROMATIC; |
2923 |
|
} |
2924 |
|
} else if (iter->first.compare("PRODUCT") == 0) { |
2925 |
|
Query.Product = iter->second; |
2926 |
|
} else if (iter->first.compare("ARTISTS") == 0) { |
2927 |
|
Query.Artists = iter->second; |
2928 |
|
} else if (iter->first.compare("KEYWORDS") == 0) { |
2929 |
|
Query.Keywords = iter->second; |
2930 |
|
} else { |
2931 |
|
throw Exception("Unknown search criteria: " + iter->first); |
2932 |
|
} |
2933 |
|
} |
2934 |
|
|
2935 |
|
String list; |
2936 |
|
StringListPtr pInstruments = |
2937 |
|
InstrumentsDb::GetInstrumentsDb()->FindInstruments(Dir, &Query, Recursive); |
2938 |
|
|
2939 |
|
for (int i = 0; i < pInstruments->size(); i++) { |
2940 |
|
if (list != "") list += ","; |
2941 |
|
list += "'" + InstrumentsDb::toEscapedPath(pInstruments->at(i)) + "'"; |
2942 |
|
} |
2943 |
|
|
2944 |
|
result.Add(list); |
2945 |
|
} catch (Exception e) { |
2946 |
|
result.Error(e); |
2947 |
|
} |
2948 |
|
#else |
2949 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2950 |
|
#endif |
2951 |
|
return result.Produce(); |
2952 |
|
} |
2953 |
|
|
2954 |
|
String LSCPServer::FormatInstrumentsDb() { |
2955 |
|
dmsg(2,("LSCPServer: FormatInstrumentsDb()\n")); |
2956 |
|
LSCPResultSet result; |
2957 |
|
#if HAVE_SQLITE3 |
2958 |
|
try { |
2959 |
|
InstrumentsDb::GetInstrumentsDb()->Format(); |
2960 |
|
} catch (Exception e) { |
2961 |
|
result.Error(e); |
2962 |
|
} |
2963 |
|
#else |
2964 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2965 |
|
#endif |
2966 |
|
return result.Produce(); |
2967 |
|
} |
2968 |
|
|
2969 |
|
|
2970 |
/** |
/** |
2971 |
* 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 |
2972 |
* mode is enabled, all commands from the client will (immediately) be |
* mode is enabled, all commands from the client will (immediately) be |