--- linuxsampler/trunk/src/network/lscpserver.cpp 2007/04/16 15:51:18 1161 +++ linuxsampler/trunk/src/network/lscpserver.cpp 2007/05/29 23:59:36 1212 @@ -84,6 +84,7 @@ LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_info, "DB_INSTRUMENT_DIRECTORY_INFO"); LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_count, "DB_INSTRUMENT_COUNT"); LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO"); + LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO"); LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); @@ -164,11 +165,16 @@ void LSCPServer::DbInstrumentsEventHandler::InstrumentInfoChanged(String Instr) { LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, Instr)); } + void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) { Instr = "'" + Instr + "'"; NewName = "'" + NewName + "'"; LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, "NAME", Instr, NewName)); } + +void LSCPServer::DbInstrumentsEventHandler::JobStatusChanged(int JobId) { + LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instrs_job_info, JobId)); +} #endif // HAVE_SQLITE3 @@ -2152,6 +2158,27 @@ return result.Produce(); } +String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) { + dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); + LSCPResultSet result; + try { + SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); + if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); + EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); + if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); + Engine* pEngine = pEngineChannel->GetEngine(); + InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); + if (!pInstrumentManager) throw Exception("Engine does not provide an instrument manager"); + InstrumentManager::instrument_id_t instrumentID; + instrumentID.FileName = pEngineChannel->InstrumentFileName(); + instrumentID.Index = pEngineChannel->InstrumentIndex(); + pInstrumentManager->LaunchInstrumentEditor(instrumentID); + } catch (Exception e) { + result.Error(e); + } + return result.Produce(); +} + /** * Will be called by the parser to reset a particular sampler channel. */ @@ -2294,12 +2321,12 @@ return result.Produce(); } -String LSCPServer::GetDbInstrumentDirectoryCount(String Dir) { - dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s)\n", Dir.c_str())); +String LSCPServer::GetDbInstrumentDirectoryCount(String Dir, bool Recursive) { + dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); LSCPResultSet result; #if HAVE_SQLITE3 try { - result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir)); + result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir, Recursive)); } catch (Exception e) { result.Error(e); } @@ -2309,13 +2336,13 @@ return result.Produce(); } -String LSCPServer::GetDbInstrumentDirectories(String Dir) { - dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); +String LSCPServer::GetDbInstrumentDirectories(String Dir, bool Recursive) { + dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); LSCPResultSet result; #if HAVE_SQLITE3 try { String list; - StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir); + StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir, Recursive); for (int i = 0; i < dirs->size(); i++) { if (list != "") list += ","; @@ -2381,12 +2408,12 @@ return result.Produce(); } -String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) { - dmsg(2,("LSCPServer: SetDbInstrumentDirectoryDescription(Dir=%s,Desc=%s)\n", Dir.c_str(), Desc.c_str())); +String LSCPServer::CopyDbInstrumentDirectory(String Dir, String Dst) { + dmsg(2,("LSCPServer: CopyDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str())); LSCPResultSet result; #if HAVE_SQLITE3 try { - InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc); + InstrumentsDb::GetInstrumentsDb()->CopyDirectory(Dir, Dst); } catch (Exception e) { result.Error(e); } @@ -2396,12 +2423,12 @@ return result.Produce(); } -String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index) { - dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d)\n", DbDir.c_str(), FilePath.c_str(), Index)); +String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) { + dmsg(2,("LSCPServer: SetDbInstrumentDirectoryDescription(Dir=%s,Desc=%s)\n", Dir.c_str(), Desc.c_str())); LSCPResultSet result; #if HAVE_SQLITE3 try { - InstrumentsDb::GetInstrumentsDb()->AddInstruments(DbDir, FilePath, Index); + InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc); } catch (Exception e) { result.Error(e); } @@ -2411,12 +2438,15 @@ return result.Produce(); } -String LSCPServer::AddDbInstrumentsFlat(String DbDir, String FsDir) { - dmsg(2,("LSCPServer: AddDbInstrumentsFlat(DbDir=%s,FilePath=%s)\n", DbDir.c_str(), FsDir.c_str())); +String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index, bool bBackground) { + dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d,bBackground=%d)\n", DbDir.c_str(), FilePath.c_str(), Index, bBackground)); LSCPResultSet result; #if HAVE_SQLITE3 try { - InstrumentsDb::GetInstrumentsDb()->AddInstrumentsRecursive(DbDir, FsDir, true); + int id; + InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); + id = db->AddInstruments(DbDir, FilePath, Index, bBackground); + if (bBackground) result = id; } catch (Exception e) { result.Error(e); } @@ -2426,12 +2456,24 @@ return result.Produce(); } -String LSCPServer::AddDbInstrumentsNonrecursive(String DbDir, String FsDir) { - dmsg(2,("LSCPServer: AddDbInstrumentsNonrecursive(DbDir=%s,FilePath=%s)\n", DbDir.c_str(), FsDir.c_str())); +String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) { + dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground)); LSCPResultSet result; #if HAVE_SQLITE3 try { - InstrumentsDb::GetInstrumentsDb()->AddInstrumentsNonrecursive(DbDir, FsDir); + int id; + InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); + if (ScanMode.compare("RECURSIVE") == 0) { + id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground); + } else if (ScanMode.compare("NON_RECURSIVE") == 0) { + id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground); + } else if (ScanMode.compare("FLAT") == 0) { + id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground); + } else { + throw Exception("Unknown scan mode: " + ScanMode); + } + + if (bBackground) result = id; } catch (Exception e) { result.Error(e); } @@ -2456,12 +2498,12 @@ return result.Produce(); } -String LSCPServer::GetDbInstrumentCount(String Dir) { - dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s)\n", Dir.c_str())); +String LSCPServer::GetDbInstrumentCount(String Dir, bool Recursive) { + dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); LSCPResultSet result; #if HAVE_SQLITE3 try { - result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir)); + result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir, Recursive)); } catch (Exception e) { result.Error(e); } @@ -2471,13 +2513,13 @@ return result.Produce(); } -String LSCPServer::GetDbInstruments(String Dir) { - dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s)\n", Dir.c_str())); +String LSCPServer::GetDbInstruments(String Dir, bool Recursive) { + dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); LSCPResultSet result; #if HAVE_SQLITE3 try { String list; - StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir); + StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir, Recursive); for (int i = 0; i < instrs->size(); i++) { if (list != "") list += ","; @@ -2522,6 +2564,26 @@ return result.Produce(); } +String LSCPServer::GetDbInstrumentsJobInfo(int JobId) { + dmsg(2,("LSCPServer: GetDbInstrumentsJobInfo(JobId=%d)\n", JobId)); + LSCPResultSet result; +#if HAVE_SQLITE3 + try { + ScanJob job = InstrumentsDb::GetInstrumentsDb()->Jobs.GetJobById(JobId); + + result.Add("FILES_TOTAL", job.FilesTotal); + result.Add("FILES_SCANNED", job.FilesScanned); + result.Add("SCANNING", job.Scanning); + result.Add("STATUS", job.Status); + } catch (Exception e) { + result.Error(e); + } +#else + result.Error(String(DOESNT_HAVE_SQLITE3), 0); +#endif + return result.Produce(); +} + String LSCPServer::SetDbInstrumentName(String Instr, String Name) { dmsg(2,("LSCPServer: SetDbInstrumentName(Instr=%s,Name=%s)\n", Instr.c_str(), Name.c_str())); LSCPResultSet result; @@ -2552,6 +2614,21 @@ return result.Produce(); } +String LSCPServer::CopyDbInstrument(String Instr, String Dst) { + dmsg(2,("LSCPServer: CopyDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str())); + LSCPResultSet result; +#if HAVE_SQLITE3 + try { + InstrumentsDb::GetInstrumentsDb()->CopyInstrument(Instr, Dst); + } catch (Exception e) { + result.Error(e); + } +#else + result.Error(String(DOESNT_HAVE_SQLITE3), 0); +#endif + return result.Produce(); +} + String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) { dmsg(2,("LSCPServer: SetDbInstrumentDescription(Instr=%s,Desc=%s)\n", Instr.c_str(), Desc.c_str())); LSCPResultSet result; @@ -2561,6 +2638,102 @@ } catch (Exception e) { result.Error(e); } +#else + result.Error(String(DOESNT_HAVE_SQLITE3), 0); +#endif + return result.Produce(); +} + +String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map Parameters, bool Recursive) { + dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); + LSCPResultSet result; +#if HAVE_SQLITE3 + try { + SearchQuery Query; + std::map::iterator iter; + for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { + if (iter->first.compare("NAME") == 0) { + Query.Name = iter->second; + } else if (iter->first.compare("CREATED") == 0) { + Query.SetCreated(iter->second); + } else if (iter->first.compare("MODIFIED") == 0) { + Query.SetModified(iter->second); + } else if (iter->first.compare("DESCRIPTION") == 0) { + Query.Description = iter->second; + } else { + throw Exception("Unknown search criteria: " + iter->first); + } + } + + String list; + StringListPtr pDirectories = + InstrumentsDb::GetInstrumentsDb()->FindDirectories(Dir, &Query, Recursive); + + for (int i = 0; i < pDirectories->size(); i++) { + if (list != "") list += ","; + list += "'" + pDirectories->at(i) + "'"; + } + + result.Add(list); + } catch (Exception e) { + result.Error(e); + } +#else + result.Error(String(DOESNT_HAVE_SQLITE3), 0); +#endif + return result.Produce(); +} + +String LSCPServer::FindDbInstruments(String Dir, std::map Parameters, bool Recursive) { + dmsg(2,("LSCPServer: FindDbInstruments(Dir=%s)\n", Dir.c_str())); + LSCPResultSet result; +#if HAVE_SQLITE3 + try { + SearchQuery Query; + std::map::iterator iter; + for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { + if (iter->first.compare("NAME") == 0) { + Query.Name = iter->second; + } else if (iter->first.compare("FORMAT_FAMILIES") == 0) { + Query.SetFormatFamilies(iter->second); + } else if (iter->first.compare("SIZE") == 0) { + Query.SetSize(iter->second); + } else if (iter->first.compare("CREATED") == 0) { + Query.SetCreated(iter->second); + } else if (iter->first.compare("MODIFIED") == 0) { + Query.SetModified(iter->second); + } else if (iter->first.compare("DESCRIPTION") == 0) { + Query.Description = iter->second; + } else if (iter->first.compare("IS_DRUM") == 0) { + if (!strcasecmp(iter->second.c_str(), "true")) { + Query.InstrType = SearchQuery::DRUM; + } else { + Query.InstrType = SearchQuery::CHROMATIC; + } + } else if (iter->first.compare("PRODUCT") == 0) { + Query.Product = iter->second; + } else if (iter->first.compare("ARTISTS") == 0) { + Query.Artists = iter->second; + } else if (iter->first.compare("KEYWORDS") == 0) { + Query.Keywords = iter->second; + } else { + throw Exception("Unknown search criteria: " + iter->first); + } + } + + String list; + StringListPtr pInstruments = + InstrumentsDb::GetInstrumentsDb()->FindInstruments(Dir, &Query, Recursive); + + for (int i = 0; i < pInstruments->size(); i++) { + if (list != "") list += ","; + list += "'" + pInstruments->at(i) + "'"; + } + + result.Add(list); + } catch (Exception e) { + result.Error(e); + } #else result.Error(String(DOESNT_HAVE_SQLITE3), 0); #endif