84 |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_info, "DB_INSTRUMENT_DIRECTORY_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_info, "DB_INSTRUMENT_DIRECTORY_INFO"); |
85 |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_count, "DB_INSTRUMENT_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_count, "DB_INSTRUMENT_COUNT"); |
86 |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO"); |
87 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO"); |
88 |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
89 |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
90 |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
165 |
void LSCPServer::DbInstrumentsEventHandler::InstrumentInfoChanged(String Instr) { |
void LSCPServer::DbInstrumentsEventHandler::InstrumentInfoChanged(String Instr) { |
166 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, Instr)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, Instr)); |
167 |
} |
} |
168 |
|
|
169 |
void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) { |
void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) { |
170 |
Instr = "'" + Instr + "'"; |
Instr = "'" + Instr + "'"; |
171 |
NewName = "'" + NewName + "'"; |
NewName = "'" + NewName + "'"; |
172 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, "NAME", Instr, NewName)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, "NAME", Instr, NewName)); |
173 |
} |
} |
174 |
|
|
175 |
|
void LSCPServer::DbInstrumentsEventHandler::JobStatusChanged(int JobId) { |
176 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instrs_job_info, JobId)); |
177 |
|
} |
178 |
#endif // HAVE_SQLITE3 |
#endif // HAVE_SQLITE3 |
179 |
|
|
180 |
|
|
2300 |
return result.Produce(); |
return result.Produce(); |
2301 |
} |
} |
2302 |
|
|
2303 |
String LSCPServer::GetDbInstrumentDirectoryCount(String Dir) { |
String LSCPServer::GetDbInstrumentDirectoryCount(String Dir, bool Recursive) { |
2304 |
dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s)\n", Dir.c_str())); |
dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2305 |
LSCPResultSet result; |
LSCPResultSet result; |
2306 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2307 |
try { |
try { |
2308 |
result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir)); |
result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir, Recursive)); |
2309 |
} catch (Exception e) { |
} catch (Exception e) { |
2310 |
result.Error(e); |
result.Error(e); |
2311 |
} |
} |
2315 |
return result.Produce(); |
return result.Produce(); |
2316 |
} |
} |
2317 |
|
|
2318 |
String LSCPServer::GetDbInstrumentDirectories(String Dir) { |
String LSCPServer::GetDbInstrumentDirectories(String Dir, bool Recursive) { |
2319 |
dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2320 |
LSCPResultSet result; |
LSCPResultSet result; |
2321 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2322 |
try { |
try { |
2323 |
String list; |
String list; |
2324 |
StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir); |
StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir, Recursive); |
2325 |
|
|
2326 |
for (int i = 0; i < dirs->size(); i++) { |
for (int i = 0; i < dirs->size(); i++) { |
2327 |
if (list != "") list += ","; |
if (list != "") list += ","; |
2387 |
return result.Produce(); |
return result.Produce(); |
2388 |
} |
} |
2389 |
|
|
2390 |
String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) { |
String LSCPServer::CopyDbInstrumentDirectory(String Dir, String Dst) { |
2391 |
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())); |
2392 |
LSCPResultSet result; |
LSCPResultSet result; |
2393 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2394 |
try { |
try { |
2395 |
InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc); |
InstrumentsDb::GetInstrumentsDb()->CopyDirectory(Dir, Dst); |
2396 |
} catch (Exception e) { |
} catch (Exception e) { |
2397 |
result.Error(e); |
result.Error(e); |
2398 |
} |
} |
2402 |
return result.Produce(); |
return result.Produce(); |
2403 |
} |
} |
2404 |
|
|
2405 |
String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index) { |
String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) { |
2406 |
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())); |
2407 |
LSCPResultSet result; |
LSCPResultSet result; |
2408 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2409 |
try { |
try { |
2410 |
InstrumentsDb::GetInstrumentsDb()->AddInstruments(DbDir, FilePath, Index); |
InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc); |
2411 |
} catch (Exception e) { |
} catch (Exception e) { |
2412 |
result.Error(e); |
result.Error(e); |
2413 |
} |
} |
2417 |
return result.Produce(); |
return result.Produce(); |
2418 |
} |
} |
2419 |
|
|
2420 |
String LSCPServer::AddDbInstrumentsFlat(String DbDir, String FsDir) { |
String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index, bool bBackground) { |
2421 |
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)); |
2422 |
LSCPResultSet result; |
LSCPResultSet result; |
2423 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2424 |
try { |
try { |
2425 |
InstrumentsDb::GetInstrumentsDb()->AddInstrumentsRecursive(DbDir, FsDir, true); |
int id; |
2426 |
|
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
2427 |
|
id = db->AddInstruments(DbDir, FilePath, Index, bBackground); |
2428 |
|
if (bBackground) result = id; |
2429 |
} catch (Exception e) { |
} catch (Exception e) { |
2430 |
result.Error(e); |
result.Error(e); |
2431 |
} |
} |
2435 |
return result.Produce(); |
return result.Produce(); |
2436 |
} |
} |
2437 |
|
|
2438 |
String LSCPServer::AddDbInstrumentsNonrecursive(String DbDir, String FsDir) { |
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) { |
2439 |
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)); |
2440 |
LSCPResultSet result; |
LSCPResultSet result; |
2441 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2442 |
try { |
try { |
2443 |
InstrumentsDb::GetInstrumentsDb()->AddInstrumentsNonrecursive(DbDir, FsDir); |
int id; |
2444 |
|
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
2445 |
|
if (ScanMode.compare("RECURSIVE") == 0) { |
2446 |
|
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground); |
2447 |
|
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
2448 |
|
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground); |
2449 |
|
} else if (ScanMode.compare("FLAT") == 0) { |
2450 |
|
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground); |
2451 |
|
} else { |
2452 |
|
throw Exception("Unknown scan mode: " + ScanMode); |
2453 |
|
} |
2454 |
|
|
2455 |
|
if (bBackground) result = id; |
2456 |
} catch (Exception e) { |
} catch (Exception e) { |
2457 |
result.Error(e); |
result.Error(e); |
2458 |
} |
} |
2477 |
return result.Produce(); |
return result.Produce(); |
2478 |
} |
} |
2479 |
|
|
2480 |
String LSCPServer::GetDbInstrumentCount(String Dir) { |
String LSCPServer::GetDbInstrumentCount(String Dir, bool Recursive) { |
2481 |
dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s)\n", Dir.c_str())); |
dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2482 |
LSCPResultSet result; |
LSCPResultSet result; |
2483 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2484 |
try { |
try { |
2485 |
result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir)); |
result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir, Recursive)); |
2486 |
} catch (Exception e) { |
} catch (Exception e) { |
2487 |
result.Error(e); |
result.Error(e); |
2488 |
} |
} |
2492 |
return result.Produce(); |
return result.Produce(); |
2493 |
} |
} |
2494 |
|
|
2495 |
String LSCPServer::GetDbInstruments(String Dir) { |
String LSCPServer::GetDbInstruments(String Dir, bool Recursive) { |
2496 |
dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s)\n", Dir.c_str())); |
dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2497 |
LSCPResultSet result; |
LSCPResultSet result; |
2498 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2499 |
try { |
try { |
2500 |
String list; |
String list; |
2501 |
StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir); |
StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir, Recursive); |
2502 |
|
|
2503 |
for (int i = 0; i < instrs->size(); i++) { |
for (int i = 0; i < instrs->size(); i++) { |
2504 |
if (list != "") list += ","; |
if (list != "") list += ","; |
2543 |
return result.Produce(); |
return result.Produce(); |
2544 |
} |
} |
2545 |
|
|
2546 |
|
String LSCPServer::GetDbInstrumentsJobInfo(int JobId) { |
2547 |
|
dmsg(2,("LSCPServer: GetDbInstrumentsJobInfo(JobId=%d)\n", JobId)); |
2548 |
|
LSCPResultSet result; |
2549 |
|
#if HAVE_SQLITE3 |
2550 |
|
try { |
2551 |
|
ScanJob job = InstrumentsDb::GetInstrumentsDb()->Jobs.GetJobById(JobId); |
2552 |
|
|
2553 |
|
result.Add("FILES_TOTAL", job.FilesTotal); |
2554 |
|
result.Add("FILES_SCANNED", job.FilesScanned); |
2555 |
|
result.Add("SCANNING", job.Scanning); |
2556 |
|
result.Add("STATUS", job.Status); |
2557 |
|
} catch (Exception e) { |
2558 |
|
result.Error(e); |
2559 |
|
} |
2560 |
|
#else |
2561 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2562 |
|
#endif |
2563 |
|
return result.Produce(); |
2564 |
|
} |
2565 |
|
|
2566 |
String LSCPServer::SetDbInstrumentName(String Instr, String Name) { |
String LSCPServer::SetDbInstrumentName(String Instr, String Name) { |
2567 |
dmsg(2,("LSCPServer: SetDbInstrumentName(Instr=%s,Name=%s)\n", Instr.c_str(), Name.c_str())); |
dmsg(2,("LSCPServer: SetDbInstrumentName(Instr=%s,Name=%s)\n", Instr.c_str(), Name.c_str())); |
2568 |
LSCPResultSet result; |
LSCPResultSet result; |
2593 |
return result.Produce(); |
return result.Produce(); |
2594 |
} |
} |
2595 |
|
|
2596 |
|
String LSCPServer::CopyDbInstrument(String Instr, String Dst) { |
2597 |
|
dmsg(2,("LSCPServer: CopyDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str())); |
2598 |
|
LSCPResultSet result; |
2599 |
|
#if HAVE_SQLITE3 |
2600 |
|
try { |
2601 |
|
InstrumentsDb::GetInstrumentsDb()->CopyInstrument(Instr, Dst); |
2602 |
|
} catch (Exception e) { |
2603 |
|
result.Error(e); |
2604 |
|
} |
2605 |
|
#else |
2606 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2607 |
|
#endif |
2608 |
|
return result.Produce(); |
2609 |
|
} |
2610 |
|
|
2611 |
String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) { |
String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) { |
2612 |
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())); |
2613 |
LSCPResultSet result; |
LSCPResultSet result; |
2617 |
} catch (Exception e) { |
} catch (Exception e) { |
2618 |
result.Error(e); |
result.Error(e); |
2619 |
} |
} |
2620 |
|
#else |
2621 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2622 |
|
#endif |
2623 |
|
return result.Produce(); |
2624 |
|
} |
2625 |
|
|
2626 |
|
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
2627 |
|
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
2628 |
|
LSCPResultSet result; |
2629 |
|
#if HAVE_SQLITE3 |
2630 |
|
try { |
2631 |
|
SearchQuery Query; |
2632 |
|
std::map<String,String>::iterator iter; |
2633 |
|
for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { |
2634 |
|
if (iter->first.compare("NAME") == 0) { |
2635 |
|
Query.Name = iter->second; |
2636 |
|
} else if (iter->first.compare("CREATED") == 0) { |
2637 |
|
Query.SetCreated(iter->second); |
2638 |
|
} else if (iter->first.compare("MODIFIED") == 0) { |
2639 |
|
Query.SetModified(iter->second); |
2640 |
|
} else if (iter->first.compare("DESCRIPTION") == 0) { |
2641 |
|
Query.Description = iter->second; |
2642 |
|
} else { |
2643 |
|
throw Exception("Unknown search criteria: " + iter->first); |
2644 |
|
} |
2645 |
|
} |
2646 |
|
|
2647 |
|
String list; |
2648 |
|
StringListPtr pDirectories = |
2649 |
|
InstrumentsDb::GetInstrumentsDb()->FindDirectories(Dir, &Query, Recursive); |
2650 |
|
|
2651 |
|
for (int i = 0; i < pDirectories->size(); i++) { |
2652 |
|
if (list != "") list += ","; |
2653 |
|
list += "'" + pDirectories->at(i) + "'"; |
2654 |
|
} |
2655 |
|
|
2656 |
|
result.Add(list); |
2657 |
|
} catch (Exception e) { |
2658 |
|
result.Error(e); |
2659 |
|
} |
2660 |
|
#else |
2661 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2662 |
|
#endif |
2663 |
|
return result.Produce(); |
2664 |
|
} |
2665 |
|
|
2666 |
|
String LSCPServer::FindDbInstruments(String Dir, std::map<String,String> Parameters, bool Recursive) { |
2667 |
|
dmsg(2,("LSCPServer: FindDbInstruments(Dir=%s)\n", Dir.c_str())); |
2668 |
|
LSCPResultSet result; |
2669 |
|
#if HAVE_SQLITE3 |
2670 |
|
try { |
2671 |
|
SearchQuery Query; |
2672 |
|
std::map<String,String>::iterator iter; |
2673 |
|
for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { |
2674 |
|
if (iter->first.compare("NAME") == 0) { |
2675 |
|
Query.Name = iter->second; |
2676 |
|
} else if (iter->first.compare("FORMAT_FAMILIES") == 0) { |
2677 |
|
Query.SetFormatFamilies(iter->second); |
2678 |
|
} else if (iter->first.compare("SIZE") == 0) { |
2679 |
|
Query.SetSize(iter->second); |
2680 |
|
} else if (iter->first.compare("CREATED") == 0) { |
2681 |
|
Query.SetCreated(iter->second); |
2682 |
|
} else if (iter->first.compare("MODIFIED") == 0) { |
2683 |
|
Query.SetModified(iter->second); |
2684 |
|
} else if (iter->first.compare("DESCRIPTION") == 0) { |
2685 |
|
Query.Description = iter->second; |
2686 |
|
} else if (iter->first.compare("IS_DRUM") == 0) { |
2687 |
|
if (!strcasecmp(iter->second.c_str(), "true")) { |
2688 |
|
Query.InstrType = SearchQuery::DRUM; |
2689 |
|
} else { |
2690 |
|
Query.InstrType = SearchQuery::CHROMATIC; |
2691 |
|
} |
2692 |
|
} else if (iter->first.compare("PRODUCT") == 0) { |
2693 |
|
Query.Product = iter->second; |
2694 |
|
} else if (iter->first.compare("ARTISTS") == 0) { |
2695 |
|
Query.Artists = iter->second; |
2696 |
|
} else if (iter->first.compare("KEYWORDS") == 0) { |
2697 |
|
Query.Keywords = iter->second; |
2698 |
|
} else { |
2699 |
|
throw Exception("Unknown search criteria: " + iter->first); |
2700 |
|
} |
2701 |
|
} |
2702 |
|
|
2703 |
|
String list; |
2704 |
|
StringListPtr pInstruments = |
2705 |
|
InstrumentsDb::GetInstrumentsDb()->FindInstruments(Dir, &Query, Recursive); |
2706 |
|
|
2707 |
|
for (int i = 0; i < pInstruments->size(); i++) { |
2708 |
|
if (list != "") list += ","; |
2709 |
|
list += "'" + pInstruments->at(i) + "'"; |
2710 |
|
} |
2711 |
|
|
2712 |
|
result.Add(list); |
2713 |
|
} catch (Exception e) { |
2714 |
|
result.Error(e); |
2715 |
|
} |
2716 |
#else |
#else |
2717 |
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2718 |
#endif |
#endif |