52 |
fd_set LSCPServer::fdSet; |
fd_set LSCPServer::fdSet; |
53 |
int LSCPServer::currentSocket = -1; |
int LSCPServer::currentSocket = -1; |
54 |
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
55 |
|
std::vector<yyparse_param_t>::iterator itCurrentSession = std::vector<yyparse_param_t>::iterator(); |
56 |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
57 |
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
58 |
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> >(); |
85 |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_info, "DB_INSTRUMENT_DIRECTORY_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_info, "DB_INSTRUMENT_DIRECTORY_INFO"); |
86 |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_count, "DB_INSTRUMENT_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_count, "DB_INSTRUMENT_COUNT"); |
87 |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO"); |
88 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO"); |
89 |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
90 |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
91 |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
146 |
|
|
147 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
148 |
void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) { |
void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) { |
149 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, Dir)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, InstrumentsDb::toEscapedPath(Dir))); |
150 |
} |
} |
151 |
|
|
152 |
void LSCPServer::DbInstrumentsEventHandler::DirectoryInfoChanged(String Dir) { |
void LSCPServer::DbInstrumentsEventHandler::DirectoryInfoChanged(String Dir) { |
153 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, Dir)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, InstrumentsDb::toEscapedPath(Dir))); |
154 |
} |
} |
155 |
|
|
156 |
void LSCPServer::DbInstrumentsEventHandler::DirectoryNameChanged(String Dir, String NewName) { |
void LSCPServer::DbInstrumentsEventHandler::DirectoryNameChanged(String Dir, String NewName) { |
157 |
Dir = "'" + Dir + "'"; |
Dir = "'" + InstrumentsDb::toEscapedPath(Dir) + "'"; |
158 |
NewName = "'" + NewName + "'"; |
NewName = "'" + InstrumentsDb::toEscapedPath(NewName) + "'"; |
159 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, "NAME", Dir, NewName)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, "NAME", Dir, NewName)); |
160 |
} |
} |
161 |
|
|
162 |
void LSCPServer::DbInstrumentsEventHandler::InstrumentCountChanged(String Dir) { |
void LSCPServer::DbInstrumentsEventHandler::InstrumentCountChanged(String Dir) { |
163 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_count, Dir)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_count, InstrumentsDb::toEscapedPath(Dir))); |
164 |
} |
} |
165 |
|
|
166 |
void LSCPServer::DbInstrumentsEventHandler::InstrumentInfoChanged(String Instr) { |
void LSCPServer::DbInstrumentsEventHandler::InstrumentInfoChanged(String Instr) { |
167 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, Instr)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, InstrumentsDb::toEscapedPath(Instr))); |
168 |
} |
} |
169 |
|
|
170 |
void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) { |
void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) { |
171 |
Instr = "'" + Instr + "'"; |
Instr = "'" + InstrumentsDb::toEscapedPath(Instr) + "'"; |
172 |
NewName = "'" + NewName + "'"; |
NewName = "'" + InstrumentsDb::toEscapedPath(NewName) + "'"; |
173 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, "NAME", Instr, NewName)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, "NAME", Instr, NewName)); |
174 |
} |
} |
175 |
|
|
176 |
|
void LSCPServer::DbInstrumentsEventHandler::JobStatusChanged(int JobId) { |
177 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instrs_job_info, JobId)); |
178 |
|
} |
179 |
#endif // HAVE_SQLITE3 |
#endif // HAVE_SQLITE3 |
180 |
|
|
181 |
|
|
219 |
|
|
220 |
listen(hSocket, 1); |
listen(hSocket, 1); |
221 |
Initialized.Set(true); |
Initialized.Set(true); |
222 |
|
|
223 |
// Registering event listeners |
// Registering event listeners |
224 |
pSampler->AddChannelCountListener(&eventHandler); |
pSampler->AddChannelCountListener(&eventHandler); |
225 |
pSampler->AddAudioDeviceCountListener(&eventHandler); |
pSampler->AddAudioDeviceCountListener(&eventHandler); |
328 |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
329 |
restart(NULL, dummy); // restart the 'scanner' |
restart(NULL, dummy); // restart the 'scanner' |
330 |
currentSocket = (*iter).hSession; //a hack |
currentSocket = (*iter).hSession; //a hack |
331 |
|
itCurrentSession = iter; // another hack |
332 |
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
333 |
if ((*iter).bVerbose) { // if echo mode enabled |
if ((*iter).bVerbose) { // if echo mode enabled |
334 |
AnswerClient(bufferedCommands[currentSocket]); |
AnswerClient(bufferedCommands[currentSocket]); |
335 |
} |
} |
336 |
int result = yyparse(&(*iter)); |
int result = yyparse(&(*iter)); |
337 |
currentSocket = -1; //continuation of a hack |
currentSocket = -1; //continuation of a hack |
338 |
|
itCurrentSession = Sessions.end(); // hack as well |
339 |
dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket)); |
dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket)); |
340 |
if (result == LSCP_QUIT) { //Was it a quit command by any chance? |
if (result == LSCP_QUIT) { //Was it a quit command by any chance? |
341 |
CloseConnection(iter); |
CloseConnection(iter); |
428 |
return command.size(); |
return command.size(); |
429 |
} |
} |
430 |
|
|
431 |
|
extern yyparse_param_t* GetCurrentYaccSession() { |
432 |
|
return &(*itCurrentSession); |
433 |
|
} |
434 |
|
|
435 |
/** |
/** |
436 |
* Will be called to try to read the command from the socket |
* Will be called to try to read the command from the socket |
437 |
* If command is read, it will return true. Otherwise false is returned. |
* If command is read, it will return true. Otherwise false is returned. |
619 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
620 |
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"); |
621 |
|
|
622 |
return pEngineChannel; |
return pEngineChannel; |
623 |
} |
} |
624 |
|
|
625 |
/** |
/** |
2006 |
LSCPResultSet result; |
LSCPResultSet result; |
2007 |
try { |
try { |
2008 |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2009 |
|
|
2010 |
FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name); |
FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name); |
2011 |
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)"); |
2012 |
|
|
2090 |
try { |
try { |
2091 |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2092 |
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2093 |
|
|
2094 |
// gather audio routing informations |
// gather audio routing informations |
2095 |
String AudioRouting; |
String AudioRouting; |
2096 |
for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { |
for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { |
2165 |
return result.Produce(); |
return result.Produce(); |
2166 |
} |
} |
2167 |
|
|
2168 |
|
String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) { |
2169 |
|
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
2170 |
|
LSCPResultSet result; |
2171 |
|
try { |
2172 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
2173 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
2174 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
2175 |
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
2176 |
|
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
2177 |
|
Engine* pEngine = pEngineChannel->GetEngine(); |
2178 |
|
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
2179 |
|
if (!pInstrumentManager) throw Exception("Engine does not provide an instrument manager"); |
2180 |
|
InstrumentManager::instrument_id_t instrumentID; |
2181 |
|
instrumentID.FileName = pEngineChannel->InstrumentFileName(); |
2182 |
|
instrumentID.Index = pEngineChannel->InstrumentIndex(); |
2183 |
|
pInstrumentManager->LaunchInstrumentEditor(instrumentID); |
2184 |
|
} catch (Exception e) { |
2185 |
|
result.Error(e); |
2186 |
|
} |
2187 |
|
return result.Produce(); |
2188 |
|
} |
2189 |
|
|
2190 |
/** |
/** |
2191 |
* Will be called by the parser to reset a particular sampler channel. |
* Will be called by the parser to reset a particular sampler channel. |
2192 |
*/ |
*/ |
2231 |
#else |
#else |
2232 |
result.Add("INSTRUMENTS_DB_SUPPORT", "no"); |
result.Add("INSTRUMENTS_DB_SUPPORT", "no"); |
2233 |
#endif |
#endif |
2234 |
|
|
2235 |
return result.Produce(); |
return result.Produce(); |
2236 |
} |
} |
2237 |
|
|
2329 |
return result.Produce(); |
return result.Produce(); |
2330 |
} |
} |
2331 |
|
|
2332 |
String LSCPServer::GetDbInstrumentDirectoryCount(String Dir) { |
String LSCPServer::GetDbInstrumentDirectoryCount(String Dir, bool Recursive) { |
2333 |
dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s)\n", Dir.c_str())); |
dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2334 |
LSCPResultSet result; |
LSCPResultSet result; |
2335 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2336 |
try { |
try { |
2337 |
result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir)); |
result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir, Recursive)); |
2338 |
} catch (Exception e) { |
} catch (Exception e) { |
2339 |
result.Error(e); |
result.Error(e); |
2340 |
} |
} |
2344 |
return result.Produce(); |
return result.Produce(); |
2345 |
} |
} |
2346 |
|
|
2347 |
String LSCPServer::GetDbInstrumentDirectories(String Dir) { |
String LSCPServer::GetDbInstrumentDirectories(String Dir, bool Recursive) { |
2348 |
dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2349 |
LSCPResultSet result; |
LSCPResultSet result; |
2350 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2351 |
try { |
try { |
2352 |
String list; |
String list; |
2353 |
StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir); |
StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir, Recursive); |
2354 |
|
|
2355 |
for (int i = 0; i < dirs->size(); i++) { |
for (int i = 0; i < dirs->size(); i++) { |
2356 |
if (list != "") list += ","; |
if (list != "") list += ","; |
2357 |
list += "'" + dirs->at(i) + "'"; |
list += "'" + InstrumentsDb::toEscapedPath(dirs->at(i)) + "'"; |
2358 |
} |
} |
2359 |
|
|
2360 |
result.Add(list); |
result.Add(list); |
2374 |
try { |
try { |
2375 |
DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir); |
DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir); |
2376 |
|
|
2377 |
result.Add("DESCRIPTION", info.Description); |
result.Add("DESCRIPTION", InstrumentsDb::toEscapedText(info.Description)); |
2378 |
result.Add("CREATED", info.Created); |
result.Add("CREATED", info.Created); |
2379 |
result.Add("MODIFIED", info.Modified); |
result.Add("MODIFIED", info.Modified); |
2380 |
} catch (Exception e) { |
} catch (Exception e) { |
2416 |
return result.Produce(); |
return result.Produce(); |
2417 |
} |
} |
2418 |
|
|
2419 |
String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) { |
String LSCPServer::CopyDbInstrumentDirectory(String Dir, String Dst) { |
2420 |
dmsg(2,("LSCPServer: SetDbInstrumentDirectoryDescription(Dir=%s,Desc=%s)\n", Dir.c_str(), Desc.c_str())); |
dmsg(2,("LSCPServer: CopyDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str())); |
2421 |
LSCPResultSet result; |
LSCPResultSet result; |
2422 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2423 |
try { |
try { |
2424 |
InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc); |
InstrumentsDb::GetInstrumentsDb()->CopyDirectory(Dir, Dst); |
2425 |
} catch (Exception e) { |
} catch (Exception e) { |
2426 |
result.Error(e); |
result.Error(e); |
2427 |
} |
} |
2431 |
return result.Produce(); |
return result.Produce(); |
2432 |
} |
} |
2433 |
|
|
2434 |
String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index) { |
String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) { |
2435 |
dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d)\n", DbDir.c_str(), FilePath.c_str(), Index)); |
dmsg(2,("LSCPServer: SetDbInstrumentDirectoryDescription(Dir=%s,Desc=%s)\n", Dir.c_str(), Desc.c_str())); |
2436 |
LSCPResultSet result; |
LSCPResultSet result; |
2437 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2438 |
try { |
try { |
2439 |
InstrumentsDb::GetInstrumentsDb()->AddInstruments(DbDir, FilePath, Index); |
InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc); |
2440 |
} catch (Exception e) { |
} catch (Exception e) { |
2441 |
result.Error(e); |
result.Error(e); |
2442 |
} |
} |
2446 |
return result.Produce(); |
return result.Produce(); |
2447 |
} |
} |
2448 |
|
|
2449 |
String LSCPServer::AddDbInstrumentsFlat(String DbDir, String FsDir) { |
String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index, bool bBackground) { |
2450 |
dmsg(2,("LSCPServer: AddDbInstrumentsFlat(DbDir=%s,FilePath=%s)\n", DbDir.c_str(), FsDir.c_str())); |
dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d,bBackground=%d)\n", DbDir.c_str(), FilePath.c_str(), Index, bBackground)); |
2451 |
LSCPResultSet result; |
LSCPResultSet result; |
2452 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2453 |
try { |
try { |
2454 |
InstrumentsDb::GetInstrumentsDb()->AddInstrumentsRecursive(DbDir, FsDir, true); |
int id; |
2455 |
|
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
2456 |
|
id = db->AddInstruments(DbDir, FilePath, Index, bBackground); |
2457 |
|
if (bBackground) result = id; |
2458 |
} catch (Exception e) { |
} catch (Exception e) { |
2459 |
result.Error(e); |
result.Error(e); |
2460 |
} |
} |
2464 |
return result.Produce(); |
return result.Produce(); |
2465 |
} |
} |
2466 |
|
|
2467 |
String LSCPServer::AddDbInstrumentsNonrecursive(String DbDir, String FsDir) { |
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) { |
2468 |
dmsg(2,("LSCPServer: AddDbInstrumentsNonrecursive(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)); |
2469 |
LSCPResultSet result; |
LSCPResultSet result; |
2470 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2471 |
try { |
try { |
2472 |
InstrumentsDb::GetInstrumentsDb()->AddInstrumentsNonrecursive(DbDir, FsDir); |
int id; |
2473 |
|
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
2474 |
|
if (ScanMode.compare("RECURSIVE") == 0) { |
2475 |
|
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground); |
2476 |
|
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
2477 |
|
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground); |
2478 |
|
} else if (ScanMode.compare("FLAT") == 0) { |
2479 |
|
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground); |
2480 |
|
} else { |
2481 |
|
throw Exception("Unknown scan mode: " + ScanMode); |
2482 |
|
} |
2483 |
|
|
2484 |
|
if (bBackground) result = id; |
2485 |
} catch (Exception e) { |
} catch (Exception e) { |
2486 |
result.Error(e); |
result.Error(e); |
2487 |
} |
} |
2506 |
return result.Produce(); |
return result.Produce(); |
2507 |
} |
} |
2508 |
|
|
2509 |
String LSCPServer::GetDbInstrumentCount(String Dir) { |
String LSCPServer::GetDbInstrumentCount(String Dir, bool Recursive) { |
2510 |
dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s)\n", Dir.c_str())); |
dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2511 |
LSCPResultSet result; |
LSCPResultSet result; |
2512 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2513 |
try { |
try { |
2514 |
result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir)); |
result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir, Recursive)); |
2515 |
} catch (Exception e) { |
} catch (Exception e) { |
2516 |
result.Error(e); |
result.Error(e); |
2517 |
} |
} |
2521 |
return result.Produce(); |
return result.Produce(); |
2522 |
} |
} |
2523 |
|
|
2524 |
String LSCPServer::GetDbInstruments(String Dir) { |
String LSCPServer::GetDbInstruments(String Dir, bool Recursive) { |
2525 |
dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s)\n", Dir.c_str())); |
dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2526 |
LSCPResultSet result; |
LSCPResultSet result; |
2527 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2528 |
try { |
try { |
2529 |
String list; |
String list; |
2530 |
StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir); |
StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir, Recursive); |
2531 |
|
|
2532 |
for (int i = 0; i < instrs->size(); i++) { |
for (int i = 0; i < instrs->size(); i++) { |
2533 |
if (list != "") list += ","; |
if (list != "") list += ","; |
2534 |
list += "'" + instrs->at(i) + "'"; |
list += "'" + InstrumentsDb::toEscapedPath(instrs->at(i)) + "'"; |
2535 |
} |
} |
2536 |
|
|
2537 |
result.Add(list); |
result.Add(list); |
2558 |
result.Add("SIZE", (int)info.Size); |
result.Add("SIZE", (int)info.Size); |
2559 |
result.Add("CREATED", info.Created); |
result.Add("CREATED", info.Created); |
2560 |
result.Add("MODIFIED", info.Modified); |
result.Add("MODIFIED", info.Modified); |
2561 |
result.Add("DESCRIPTION", FilterEndlines(info.Description)); |
result.Add("DESCRIPTION", InstrumentsDb::toEscapedText(info.Description)); |
2562 |
result.Add("IS_DRUM", info.IsDrum); |
result.Add("IS_DRUM", info.IsDrum); |
2563 |
result.Add("PRODUCT", FilterEndlines(info.Product)); |
result.Add("PRODUCT", InstrumentsDb::toEscapedText(info.Product)); |
2564 |
result.Add("ARTISTS", FilterEndlines(info.Artists)); |
result.Add("ARTISTS", InstrumentsDb::toEscapedText(info.Artists)); |
2565 |
result.Add("KEYWORDS", FilterEndlines(info.Keywords)); |
result.Add("KEYWORDS", InstrumentsDb::toEscapedText(info.Keywords)); |
2566 |
|
} catch (Exception e) { |
2567 |
|
result.Error(e); |
2568 |
|
} |
2569 |
|
#else |
2570 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2571 |
|
#endif |
2572 |
|
return result.Produce(); |
2573 |
|
} |
2574 |
|
|
2575 |
|
String LSCPServer::GetDbInstrumentsJobInfo(int JobId) { |
2576 |
|
dmsg(2,("LSCPServer: GetDbInstrumentsJobInfo(JobId=%d)\n", JobId)); |
2577 |
|
LSCPResultSet result; |
2578 |
|
#if HAVE_SQLITE3 |
2579 |
|
try { |
2580 |
|
ScanJob job = InstrumentsDb::GetInstrumentsDb()->Jobs.GetJobById(JobId); |
2581 |
|
|
2582 |
|
result.Add("FILES_TOTAL", job.FilesTotal); |
2583 |
|
result.Add("FILES_SCANNED", job.FilesScanned); |
2584 |
|
result.Add("SCANNING", job.Scanning); |
2585 |
|
result.Add("STATUS", job.Status); |
2586 |
} catch (Exception e) { |
} catch (Exception e) { |
2587 |
result.Error(e); |
result.Error(e); |
2588 |
} |
} |
2622 |
return result.Produce(); |
return result.Produce(); |
2623 |
} |
} |
2624 |
|
|
2625 |
|
String LSCPServer::CopyDbInstrument(String Instr, String Dst) { |
2626 |
|
dmsg(2,("LSCPServer: CopyDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str())); |
2627 |
|
LSCPResultSet result; |
2628 |
|
#if HAVE_SQLITE3 |
2629 |
|
try { |
2630 |
|
InstrumentsDb::GetInstrumentsDb()->CopyInstrument(Instr, Dst); |
2631 |
|
} catch (Exception e) { |
2632 |
|
result.Error(e); |
2633 |
|
} |
2634 |
|
#else |
2635 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2636 |
|
#endif |
2637 |
|
return result.Produce(); |
2638 |
|
} |
2639 |
|
|
2640 |
String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) { |
String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) { |
2641 |
dmsg(2,("LSCPServer: SetDbInstrumentDescription(Instr=%s,Desc=%s)\n", Instr.c_str(), Desc.c_str())); |
dmsg(2,("LSCPServer: SetDbInstrumentDescription(Instr=%s,Desc=%s)\n", Instr.c_str(), Desc.c_str())); |
2642 |
LSCPResultSet result; |
LSCPResultSet result; |
2652 |
return result.Produce(); |
return result.Produce(); |
2653 |
} |
} |
2654 |
|
|
2655 |
|
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
2656 |
|
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
2657 |
|
LSCPResultSet result; |
2658 |
|
#if HAVE_SQLITE3 |
2659 |
|
try { |
2660 |
|
SearchQuery Query; |
2661 |
|
std::map<String,String>::iterator iter; |
2662 |
|
for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { |
2663 |
|
if (iter->first.compare("NAME") == 0) { |
2664 |
|
Query.Name = iter->second; |
2665 |
|
} else if (iter->first.compare("CREATED") == 0) { |
2666 |
|
Query.SetCreated(iter->second); |
2667 |
|
} else if (iter->first.compare("MODIFIED") == 0) { |
2668 |
|
Query.SetModified(iter->second); |
2669 |
|
} else if (iter->first.compare("DESCRIPTION") == 0) { |
2670 |
|
Query.Description = iter->second; |
2671 |
|
} else { |
2672 |
|
throw Exception("Unknown search criteria: " + iter->first); |
2673 |
|
} |
2674 |
|
} |
2675 |
|
|
2676 |
|
String list; |
2677 |
|
StringListPtr pDirectories = |
2678 |
|
InstrumentsDb::GetInstrumentsDb()->FindDirectories(Dir, &Query, Recursive); |
2679 |
|
|
2680 |
|
for (int i = 0; i < pDirectories->size(); i++) { |
2681 |
|
if (list != "") list += ","; |
2682 |
|
list += "'" + InstrumentsDb::toEscapedPath(pDirectories->at(i)) + "'"; |
2683 |
|
} |
2684 |
|
|
2685 |
|
result.Add(list); |
2686 |
|
} catch (Exception e) { |
2687 |
|
result.Error(e); |
2688 |
|
} |
2689 |
|
#else |
2690 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2691 |
|
#endif |
2692 |
|
return result.Produce(); |
2693 |
|
} |
2694 |
|
|
2695 |
|
String LSCPServer::FindDbInstruments(String Dir, std::map<String,String> Parameters, bool Recursive) { |
2696 |
|
dmsg(2,("LSCPServer: FindDbInstruments(Dir=%s)\n", Dir.c_str())); |
2697 |
|
LSCPResultSet result; |
2698 |
|
#if HAVE_SQLITE3 |
2699 |
|
try { |
2700 |
|
SearchQuery Query; |
2701 |
|
std::map<String,String>::iterator iter; |
2702 |
|
for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { |
2703 |
|
if (iter->first.compare("NAME") == 0) { |
2704 |
|
Query.Name = iter->second; |
2705 |
|
} else if (iter->first.compare("FORMAT_FAMILIES") == 0) { |
2706 |
|
Query.SetFormatFamilies(iter->second); |
2707 |
|
} else if (iter->first.compare("SIZE") == 0) { |
2708 |
|
Query.SetSize(iter->second); |
2709 |
|
} else if (iter->first.compare("CREATED") == 0) { |
2710 |
|
Query.SetCreated(iter->second); |
2711 |
|
} else if (iter->first.compare("MODIFIED") == 0) { |
2712 |
|
Query.SetModified(iter->second); |
2713 |
|
} else if (iter->first.compare("DESCRIPTION") == 0) { |
2714 |
|
Query.Description = iter->second; |
2715 |
|
} else if (iter->first.compare("IS_DRUM") == 0) { |
2716 |
|
if (!strcasecmp(iter->second.c_str(), "true")) { |
2717 |
|
Query.InstrType = SearchQuery::DRUM; |
2718 |
|
} else { |
2719 |
|
Query.InstrType = SearchQuery::CHROMATIC; |
2720 |
|
} |
2721 |
|
} else if (iter->first.compare("PRODUCT") == 0) { |
2722 |
|
Query.Product = iter->second; |
2723 |
|
} else if (iter->first.compare("ARTISTS") == 0) { |
2724 |
|
Query.Artists = iter->second; |
2725 |
|
} else if (iter->first.compare("KEYWORDS") == 0) { |
2726 |
|
Query.Keywords = iter->second; |
2727 |
|
} else { |
2728 |
|
throw Exception("Unknown search criteria: " + iter->first); |
2729 |
|
} |
2730 |
|
} |
2731 |
|
|
2732 |
|
String list; |
2733 |
|
StringListPtr pInstruments = |
2734 |
|
InstrumentsDb::GetInstrumentsDb()->FindInstruments(Dir, &Query, Recursive); |
2735 |
|
|
2736 |
|
for (int i = 0; i < pInstruments->size(); i++) { |
2737 |
|
if (list != "") list += ","; |
2738 |
|
list += "'" + InstrumentsDb::toEscapedPath(pInstruments->at(i)) + "'"; |
2739 |
|
} |
2740 |
|
|
2741 |
|
result.Add(list); |
2742 |
|
} catch (Exception e) { |
2743 |
|
result.Error(e); |
2744 |
|
} |
2745 |
|
#else |
2746 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2747 |
|
#endif |
2748 |
|
return result.Produce(); |
2749 |
|
} |
2750 |
|
|
2751 |
|
String LSCPServer::FormatInstrumentsDb() { |
2752 |
|
dmsg(2,("LSCPServer: FormatInstrumentsDb()\n")); |
2753 |
|
LSCPResultSet result; |
2754 |
|
#if HAVE_SQLITE3 |
2755 |
|
try { |
2756 |
|
InstrumentsDb::GetInstrumentsDb()->Format(); |
2757 |
|
} catch (Exception e) { |
2758 |
|
result.Error(e); |
2759 |
|
} |
2760 |
|
#else |
2761 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2762 |
|
#endif |
2763 |
|
return result.Produce(); |
2764 |
|
} |
2765 |
|
|
2766 |
|
|
2767 |
/** |
/** |
2768 |
* 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 |
2782 |
} |
} |
2783 |
return result.Produce(); |
return result.Produce(); |
2784 |
} |
} |
|
|
|
|
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; |
|
|
} |
|