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 |
#include <fcntl.h> |
#include <fcntl.h> |
29 |
|
|
30 |
#if HAVE_SQLITE3 |
#if ! HAVE_SQLITE3 |
31 |
# include "sqlite3.h" |
#define DOESNT_HAVE_SQLITE3 "No database support. SQLITE3 was not installed when linuxsampler was built." |
32 |
#endif |
#endif |
33 |
|
|
34 |
#include "../engines/EngineFactory.h" |
#include "../engines/EngineFactory.h" |
80 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO"); |
81 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT"); |
82 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO"); |
83 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_count, "DB_INSTRUMENT_DIRECTORY_COUNT"); |
84 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_info, "DB_INSTRUMENT_DIRECTORY_INFO"); |
85 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_count, "DB_INSTRUMENT_COUNT"); |
86 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO"); |
87 |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
88 |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
89 |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
142 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount)); |
143 |
} |
} |
144 |
|
|
145 |
|
#if HAVE_SQLITE3 |
146 |
|
void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) { |
147 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, Dir)); |
148 |
|
} |
149 |
|
|
150 |
|
void LSCPServer::DbInstrumentsEventHandler::DirectoryInfoChanged(String Dir) { |
151 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, Dir)); |
152 |
|
} |
153 |
|
|
154 |
|
void LSCPServer::DbInstrumentsEventHandler::DirectoryNameChanged(String Dir, String NewName) { |
155 |
|
Dir = "'" + Dir + "'"; |
156 |
|
NewName = "'" + NewName + "'"; |
157 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, "NAME", Dir, NewName)); |
158 |
|
} |
159 |
|
|
160 |
|
void LSCPServer::DbInstrumentsEventHandler::InstrumentCountChanged(String Dir) { |
161 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_count, Dir)); |
162 |
|
} |
163 |
|
|
164 |
|
void LSCPServer::DbInstrumentsEventHandler::InstrumentInfoChanged(String Instr) { |
165 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, Instr)); |
166 |
|
} |
167 |
|
void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) { |
168 |
|
Instr = "'" + Instr + "'"; |
169 |
|
NewName = "'" + NewName + "'"; |
170 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, "NAME", Instr, NewName)); |
171 |
|
} |
172 |
|
#endif // HAVE_SQLITE3 |
173 |
|
|
174 |
|
|
175 |
/** |
/** |
176 |
* Blocks the calling thread until the LSCP Server is initialized and |
* Blocks the calling thread until the LSCP Server is initialized and |
226 |
MidiInstrumentMapper::AddMidiInstrumentInfoListener(&eventHandler); |
MidiInstrumentMapper::AddMidiInstrumentInfoListener(&eventHandler); |
227 |
MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&eventHandler); |
MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&eventHandler); |
228 |
MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(&eventHandler); |
MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(&eventHandler); |
229 |
|
#if HAVE_SQLITE3 |
230 |
|
InstrumentsDb::GetInstrumentsDb()->AddInstrumentsDbListener(&dbInstrumentsEventHandler); |
231 |
|
#endif |
232 |
// now wait for client connections and handle their requests |
// now wait for client connections and handle their requests |
233 |
sockaddr_in client; |
sockaddr_in client; |
234 |
int length = sizeof(client); |
int length = sizeof(client); |
2191 |
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
2192 |
result.Add("VERSION", VERSION); |
result.Add("VERSION", VERSION); |
2193 |
result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR)); |
result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR)); |
2194 |
|
#if HAVE_SQLITE3 |
2195 |
|
result.Add("INSTRUMENTS_DB_SUPPORT", "yes"); |
2196 |
|
#else |
2197 |
|
result.Add("INSTRUMENTS_DB_SUPPORT", "no"); |
2198 |
|
#endif |
2199 |
|
|
2200 |
return result.Produce(); |
return result.Produce(); |
2201 |
} |
} |
2202 |
|
|
2264 |
return result.Produce(); |
return result.Produce(); |
2265 |
} |
} |
2266 |
|
|
2267 |
static int select_callback(void * lscpResultSet, int argc, |
String LSCPServer::AddDbInstrumentDirectory(String Dir) { |
2268 |
char **argv, char **azColName) |
dmsg(2,("LSCPServer: AddDbInstrumentDirectory(Dir=%s)\n", Dir.c_str())); |
2269 |
{ |
LSCPResultSet result; |
2270 |
LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet; |
#if HAVE_SQLITE3 |
2271 |
resultSet->Add(argc, argv); |
try { |
2272 |
return 0; |
InstrumentsDb::GetInstrumentsDb()->AddDirectory(Dir); |
2273 |
|
} catch (Exception e) { |
2274 |
|
result.Error(e); |
2275 |
|
} |
2276 |
|
#else |
2277 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2278 |
|
#endif |
2279 |
|
return result.Produce(); |
2280 |
|
} |
2281 |
|
|
2282 |
|
String LSCPServer::RemoveDbInstrumentDirectory(String Dir, bool Force) { |
2283 |
|
dmsg(2,("LSCPServer: RemoveDbInstrumentDirectory(Dir=%s,Force=%d)\n", Dir.c_str(), Force)); |
2284 |
|
LSCPResultSet result; |
2285 |
|
#if HAVE_SQLITE3 |
2286 |
|
try { |
2287 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveDirectory(Dir, Force); |
2288 |
|
} catch (Exception e) { |
2289 |
|
result.Error(e); |
2290 |
|
} |
2291 |
|
#else |
2292 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2293 |
|
#endif |
2294 |
|
return result.Produce(); |
2295 |
|
} |
2296 |
|
|
2297 |
|
String LSCPServer::GetDbInstrumentDirectoryCount(String Dir, bool Recursive) { |
2298 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2299 |
|
LSCPResultSet result; |
2300 |
|
#if HAVE_SQLITE3 |
2301 |
|
try { |
2302 |
|
result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir, Recursive)); |
2303 |
|
} catch (Exception e) { |
2304 |
|
result.Error(e); |
2305 |
|
} |
2306 |
|
#else |
2307 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2308 |
|
#endif |
2309 |
|
return result.Produce(); |
2310 |
} |
} |
2311 |
|
|
2312 |
String LSCPServer::QueryDatabase(String query) { |
String LSCPServer::GetDbInstrumentDirectories(String Dir, bool Recursive) { |
2313 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2314 |
LSCPResultSet result; |
LSCPResultSet result; |
2315 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2316 |
char* zErrMsg = NULL; |
try { |
2317 |
sqlite3 *db; |
String list; |
2318 |
String selectStr = "SELECT " + query; |
StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir, Recursive); |
2319 |
|
|
2320 |
|
for (int i = 0; i < dirs->size(); i++) { |
2321 |
|
if (list != "") list += ","; |
2322 |
|
list += "'" + dirs->at(i) + "'"; |
2323 |
|
} |
2324 |
|
|
2325 |
int rc = sqlite3_open("linuxsampler.db", &db); |
result.Add(list); |
2326 |
if (rc == SQLITE_OK) |
} catch (Exception e) { |
2327 |
{ |
result.Error(e); |
|
rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg); |
|
2328 |
} |
} |
2329 |
if ( rc != SQLITE_OK ) |
#else |
2330 |
{ |
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2331 |
result.Error(String(zErrMsg), rc); |
#endif |
2332 |
|
return result.Produce(); |
2333 |
|
} |
2334 |
|
|
2335 |
|
String LSCPServer::GetDbInstrumentDirectoryInfo(String Dir) { |
2336 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectoryInfo(Dir=%s)\n", Dir.c_str())); |
2337 |
|
LSCPResultSet result; |
2338 |
|
#if HAVE_SQLITE3 |
2339 |
|
try { |
2340 |
|
DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir); |
2341 |
|
|
2342 |
|
result.Add("DESCRIPTION", info.Description); |
2343 |
|
result.Add("CREATED", info.Created); |
2344 |
|
result.Add("MODIFIED", info.Modified); |
2345 |
|
} catch (Exception e) { |
2346 |
|
result.Error(e); |
2347 |
} |
} |
|
sqlite3_close(db); |
|
2348 |
#else |
#else |
2349 |
result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0); |
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2350 |
#endif |
#endif |
2351 |
return result.Produce(); |
return result.Produce(); |
2352 |
} |
} |
2353 |
|
|
2354 |
|
String LSCPServer::SetDbInstrumentDirectoryName(String Dir, String Name) { |
2355 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDirectoryName(Dir=%s,Name=%s)\n", Dir.c_str(), Name.c_str())); |
2356 |
|
LSCPResultSet result; |
2357 |
|
#if HAVE_SQLITE3 |
2358 |
|
try { |
2359 |
|
InstrumentsDb::GetInstrumentsDb()->RenameDirectory(Dir, Name); |
2360 |
|
} catch (Exception e) { |
2361 |
|
result.Error(e); |
2362 |
|
} |
2363 |
|
#else |
2364 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2365 |
|
#endif |
2366 |
|
return result.Produce(); |
2367 |
|
} |
2368 |
|
|
2369 |
|
String LSCPServer::MoveDbInstrumentDirectory(String Dir, String Dst) { |
2370 |
|
dmsg(2,("LSCPServer: MoveDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str())); |
2371 |
|
LSCPResultSet result; |
2372 |
|
#if HAVE_SQLITE3 |
2373 |
|
try { |
2374 |
|
InstrumentsDb::GetInstrumentsDb()->MoveDirectory(Dir, Dst); |
2375 |
|
} catch (Exception e) { |
2376 |
|
result.Error(e); |
2377 |
|
} |
2378 |
|
#else |
2379 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2380 |
|
#endif |
2381 |
|
return result.Produce(); |
2382 |
|
} |
2383 |
|
|
2384 |
|
String LSCPServer::CopyDbInstrumentDirectory(String Dir, String Dst) { |
2385 |
|
dmsg(2,("LSCPServer: CopyDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str())); |
2386 |
|
LSCPResultSet result; |
2387 |
|
#if HAVE_SQLITE3 |
2388 |
|
try { |
2389 |
|
InstrumentsDb::GetInstrumentsDb()->CopyDirectory(Dir, Dst); |
2390 |
|
} catch (Exception e) { |
2391 |
|
result.Error(e); |
2392 |
|
} |
2393 |
|
#else |
2394 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2395 |
|
#endif |
2396 |
|
return result.Produce(); |
2397 |
|
} |
2398 |
|
|
2399 |
|
String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) { |
2400 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDirectoryDescription(Dir=%s,Desc=%s)\n", Dir.c_str(), Desc.c_str())); |
2401 |
|
LSCPResultSet result; |
2402 |
|
#if HAVE_SQLITE3 |
2403 |
|
try { |
2404 |
|
InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc); |
2405 |
|
} catch (Exception e) { |
2406 |
|
result.Error(e); |
2407 |
|
} |
2408 |
|
#else |
2409 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2410 |
|
#endif |
2411 |
|
return result.Produce(); |
2412 |
|
} |
2413 |
|
|
2414 |
|
String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index) { |
2415 |
|
dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d)\n", DbDir.c_str(), FilePath.c_str(), Index)); |
2416 |
|
LSCPResultSet result; |
2417 |
|
#if HAVE_SQLITE3 |
2418 |
|
try { |
2419 |
|
InstrumentsDb::GetInstrumentsDb()->AddInstruments(DbDir, FilePath, Index); |
2420 |
|
} catch (Exception e) { |
2421 |
|
result.Error(e); |
2422 |
|
} |
2423 |
|
#else |
2424 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2425 |
|
#endif |
2426 |
|
return result.Produce(); |
2427 |
|
} |
2428 |
|
|
2429 |
|
String LSCPServer::AddDbInstrumentsFlat(String DbDir, String FsDir) { |
2430 |
|
dmsg(2,("LSCPServer: AddDbInstrumentsFlat(DbDir=%s,FilePath=%s)\n", DbDir.c_str(), FsDir.c_str())); |
2431 |
|
LSCPResultSet result; |
2432 |
|
#if HAVE_SQLITE3 |
2433 |
|
try { |
2434 |
|
InstrumentsDb::GetInstrumentsDb()->AddInstrumentsRecursive(DbDir, FsDir, true); |
2435 |
|
} catch (Exception e) { |
2436 |
|
result.Error(e); |
2437 |
|
} |
2438 |
|
#else |
2439 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2440 |
|
#endif |
2441 |
|
return result.Produce(); |
2442 |
|
} |
2443 |
|
|
2444 |
|
String LSCPServer::AddDbInstrumentsNonrecursive(String DbDir, String FsDir) { |
2445 |
|
dmsg(2,("LSCPServer: AddDbInstrumentsNonrecursive(DbDir=%s,FilePath=%s)\n", DbDir.c_str(), FsDir.c_str())); |
2446 |
|
LSCPResultSet result; |
2447 |
|
#if HAVE_SQLITE3 |
2448 |
|
try { |
2449 |
|
InstrumentsDb::GetInstrumentsDb()->AddInstrumentsNonrecursive(DbDir, FsDir); |
2450 |
|
} catch (Exception e) { |
2451 |
|
result.Error(e); |
2452 |
|
} |
2453 |
|
#else |
2454 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2455 |
|
#endif |
2456 |
|
return result.Produce(); |
2457 |
|
} |
2458 |
|
|
2459 |
|
String LSCPServer::RemoveDbInstrument(String Instr) { |
2460 |
|
dmsg(2,("LSCPServer: RemoveDbInstrument(Instr=%s)\n", Instr.c_str())); |
2461 |
|
LSCPResultSet result; |
2462 |
|
#if HAVE_SQLITE3 |
2463 |
|
try { |
2464 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveInstrument(Instr); |
2465 |
|
} catch (Exception e) { |
2466 |
|
result.Error(e); |
2467 |
|
} |
2468 |
|
#else |
2469 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2470 |
|
#endif |
2471 |
|
return result.Produce(); |
2472 |
|
} |
2473 |
|
|
2474 |
|
String LSCPServer::GetDbInstrumentCount(String Dir, bool Recursive) { |
2475 |
|
dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2476 |
|
LSCPResultSet result; |
2477 |
|
#if HAVE_SQLITE3 |
2478 |
|
try { |
2479 |
|
result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir, Recursive)); |
2480 |
|
} catch (Exception e) { |
2481 |
|
result.Error(e); |
2482 |
|
} |
2483 |
|
#else |
2484 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2485 |
|
#endif |
2486 |
|
return result.Produce(); |
2487 |
|
} |
2488 |
|
|
2489 |
|
String LSCPServer::GetDbInstruments(String Dir, bool Recursive) { |
2490 |
|
dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2491 |
|
LSCPResultSet result; |
2492 |
|
#if HAVE_SQLITE3 |
2493 |
|
try { |
2494 |
|
String list; |
2495 |
|
StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir, Recursive); |
2496 |
|
|
2497 |
|
for (int i = 0; i < instrs->size(); i++) { |
2498 |
|
if (list != "") list += ","; |
2499 |
|
list += "'" + instrs->at(i) + "'"; |
2500 |
|
} |
2501 |
|
|
2502 |
|
result.Add(list); |
2503 |
|
} catch (Exception e) { |
2504 |
|
result.Error(e); |
2505 |
|
} |
2506 |
|
#else |
2507 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2508 |
|
#endif |
2509 |
|
return result.Produce(); |
2510 |
|
} |
2511 |
|
|
2512 |
|
String LSCPServer::GetDbInstrumentInfo(String Instr) { |
2513 |
|
dmsg(2,("LSCPServer: GetDbInstrumentInfo(Instr=%s)\n", Instr.c_str())); |
2514 |
|
LSCPResultSet result; |
2515 |
|
#if HAVE_SQLITE3 |
2516 |
|
try { |
2517 |
|
DbInstrument info = InstrumentsDb::GetInstrumentsDb()->GetInstrumentInfo(Instr); |
2518 |
|
|
2519 |
|
result.Add("INSTRUMENT_FILE", info.InstrFile); |
2520 |
|
result.Add("INSTRUMENT_NR", info.InstrNr); |
2521 |
|
result.Add("FORMAT_FAMILY", info.FormatFamily); |
2522 |
|
result.Add("FORMAT_VERSION", info.FormatVersion); |
2523 |
|
result.Add("SIZE", (int)info.Size); |
2524 |
|
result.Add("CREATED", info.Created); |
2525 |
|
result.Add("MODIFIED", info.Modified); |
2526 |
|
result.Add("DESCRIPTION", FilterEndlines(info.Description)); |
2527 |
|
result.Add("IS_DRUM", info.IsDrum); |
2528 |
|
result.Add("PRODUCT", FilterEndlines(info.Product)); |
2529 |
|
result.Add("ARTISTS", FilterEndlines(info.Artists)); |
2530 |
|
result.Add("KEYWORDS", FilterEndlines(info.Keywords)); |
2531 |
|
} catch (Exception e) { |
2532 |
|
result.Error(e); |
2533 |
|
} |
2534 |
|
#else |
2535 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2536 |
|
#endif |
2537 |
|
return result.Produce(); |
2538 |
|
} |
2539 |
|
|
2540 |
|
String LSCPServer::SetDbInstrumentName(String Instr, String Name) { |
2541 |
|
dmsg(2,("LSCPServer: SetDbInstrumentName(Instr=%s,Name=%s)\n", Instr.c_str(), Name.c_str())); |
2542 |
|
LSCPResultSet result; |
2543 |
|
#if HAVE_SQLITE3 |
2544 |
|
try { |
2545 |
|
InstrumentsDb::GetInstrumentsDb()->RenameInstrument(Instr, Name); |
2546 |
|
} catch (Exception e) { |
2547 |
|
result.Error(e); |
2548 |
|
} |
2549 |
|
#else |
2550 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2551 |
|
#endif |
2552 |
|
return result.Produce(); |
2553 |
|
} |
2554 |
|
|
2555 |
|
String LSCPServer::MoveDbInstrument(String Instr, String Dst) { |
2556 |
|
dmsg(2,("LSCPServer: MoveDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str())); |
2557 |
|
LSCPResultSet result; |
2558 |
|
#if HAVE_SQLITE3 |
2559 |
|
try { |
2560 |
|
InstrumentsDb::GetInstrumentsDb()->MoveInstrument(Instr, Dst); |
2561 |
|
} catch (Exception e) { |
2562 |
|
result.Error(e); |
2563 |
|
} |
2564 |
|
#else |
2565 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2566 |
|
#endif |
2567 |
|
return result.Produce(); |
2568 |
|
} |
2569 |
|
|
2570 |
|
String LSCPServer::CopyDbInstrument(String Instr, String Dst) { |
2571 |
|
dmsg(2,("LSCPServer: CopyDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str())); |
2572 |
|
LSCPResultSet result; |
2573 |
|
#if HAVE_SQLITE3 |
2574 |
|
try { |
2575 |
|
InstrumentsDb::GetInstrumentsDb()->CopyInstrument(Instr, Dst); |
2576 |
|
} catch (Exception e) { |
2577 |
|
result.Error(e); |
2578 |
|
} |
2579 |
|
#else |
2580 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2581 |
|
#endif |
2582 |
|
return result.Produce(); |
2583 |
|
} |
2584 |
|
|
2585 |
|
String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) { |
2586 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDescription(Instr=%s,Desc=%s)\n", Instr.c_str(), Desc.c_str())); |
2587 |
|
LSCPResultSet result; |
2588 |
|
#if HAVE_SQLITE3 |
2589 |
|
try { |
2590 |
|
InstrumentsDb::GetInstrumentsDb()->SetInstrumentDescription(Instr, Desc); |
2591 |
|
} catch (Exception e) { |
2592 |
|
result.Error(e); |
2593 |
|
} |
2594 |
|
#else |
2595 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2596 |
|
#endif |
2597 |
|
return result.Produce(); |
2598 |
|
} |
2599 |
|
|
2600 |
|
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
2601 |
|
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
2602 |
|
LSCPResultSet result; |
2603 |
|
#if HAVE_SQLITE3 |
2604 |
|
try { |
2605 |
|
SearchQuery Query; |
2606 |
|
std::map<String,String>::iterator iter; |
2607 |
|
for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { |
2608 |
|
if (iter->first.compare("NAME") == 0) { |
2609 |
|
Query.Name = iter->second; |
2610 |
|
} else if (iter->first.compare("CREATED") == 0) { |
2611 |
|
Query.SetCreated(iter->second); |
2612 |
|
} else if (iter->first.compare("MODIFIED") == 0) { |
2613 |
|
Query.SetModified(iter->second); |
2614 |
|
} else if (iter->first.compare("DESCRIPTION") == 0) { |
2615 |
|
Query.Description = iter->second; |
2616 |
|
} else { |
2617 |
|
throw Exception("Unknown search criteria: " + iter->first); |
2618 |
|
} |
2619 |
|
} |
2620 |
|
|
2621 |
|
String list; |
2622 |
|
StringListPtr pDirectories = |
2623 |
|
InstrumentsDb::GetInstrumentsDb()->FindDirectories(Dir, &Query, Recursive); |
2624 |
|
|
2625 |
|
for (int i = 0; i < pDirectories->size(); i++) { |
2626 |
|
if (list != "") list += ","; |
2627 |
|
list += "'" + pDirectories->at(i) + "'"; |
2628 |
|
} |
2629 |
|
|
2630 |
|
result.Add(list); |
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::FindDbInstruments(String Dir, std::map<String,String> Parameters, bool Recursive) { |
2641 |
|
dmsg(2,("LSCPServer: FindDbInstruments(Dir=%s)\n", Dir.c_str())); |
2642 |
|
LSCPResultSet result; |
2643 |
|
#if HAVE_SQLITE3 |
2644 |
|
try { |
2645 |
|
SearchQuery Query; |
2646 |
|
std::map<String,String>::iterator iter; |
2647 |
|
for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { |
2648 |
|
if (iter->first.compare("NAME") == 0) { |
2649 |
|
Query.Name = iter->second; |
2650 |
|
} else if (iter->first.compare("FORMAT_FAMILIES") == 0) { |
2651 |
|
Query.SetFormatFamilies(iter->second); |
2652 |
|
} else if (iter->first.compare("SIZE") == 0) { |
2653 |
|
Query.SetSize(iter->second); |
2654 |
|
} else if (iter->first.compare("CREATED") == 0) { |
2655 |
|
Query.SetCreated(iter->second); |
2656 |
|
} else if (iter->first.compare("MODIFIED") == 0) { |
2657 |
|
Query.SetModified(iter->second); |
2658 |
|
} else if (iter->first.compare("DESCRIPTION") == 0) { |
2659 |
|
Query.Description = iter->second; |
2660 |
|
} else if (iter->first.compare("IS_DRUM") == 0) { |
2661 |
|
if (!strcasecmp(iter->second.c_str(), "true")) { |
2662 |
|
Query.InstrType = SearchQuery::DRUM; |
2663 |
|
} else { |
2664 |
|
Query.InstrType = SearchQuery::CHROMATIC; |
2665 |
|
} |
2666 |
|
} else if (iter->first.compare("PRODUCT") == 0) { |
2667 |
|
Query.Product = iter->second; |
2668 |
|
} else if (iter->first.compare("ARTISTS") == 0) { |
2669 |
|
Query.Artists = iter->second; |
2670 |
|
} else if (iter->first.compare("KEYWORDS") == 0) { |
2671 |
|
Query.Keywords = iter->second; |
2672 |
|
} else { |
2673 |
|
throw Exception("Unknown search criteria: " + iter->first); |
2674 |
|
} |
2675 |
|
} |
2676 |
|
|
2677 |
|
String list; |
2678 |
|
StringListPtr pInstruments = |
2679 |
|
InstrumentsDb::GetInstrumentsDb()->FindInstruments(Dir, &Query, Recursive); |
2680 |
|
|
2681 |
|
for (int i = 0; i < pInstruments->size(); i++) { |
2682 |
|
if (list != "") list += ","; |
2683 |
|
list += "'" + pInstruments->at(i) + "'"; |
2684 |
|
} |
2685 |
|
|
2686 |
|
result.Add(list); |
2687 |
|
} catch (Exception e) { |
2688 |
|
result.Error(e); |
2689 |
|
} |
2690 |
|
#else |
2691 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2692 |
|
#endif |
2693 |
|
return result.Produce(); |
2694 |
|
} |
2695 |
|
|
2696 |
|
|
2697 |
/** |
/** |
2698 |
* 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 |
2699 |
* mode is enabled, all commands from the client will (immediately) be |
* mode is enabled, all commands from the client will (immediately) be |
2712 |
} |
} |
2713 |
return result.Produce(); |
return result.Produce(); |
2714 |
} |
} |
2715 |
|
|
2716 |
|
String LSCPServer::FilterEndlines(String s) { |
2717 |
|
String s2 = s; |
2718 |
|
for (int i = 0; i < s2.length(); i++) { |
2719 |
|
if (s2.at(i) == '\r') s2.at(i) = ' '; |
2720 |
|
else if (s2.at(i) == '\n') s2.at(i) = ' '; |
2721 |
|
} |
2722 |
|
|
2723 |
|
return s2; |
2724 |
|
} |