/[svn]/linuxsampler/trunk/src/network/lscpserver.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/network/lscpserver.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1161 by iliev, Mon Apr 16 15:51:18 2007 UTC revision 1212 by schoenebeck, Tue May 29 23:59:36 2007 UTC
# Line 84  LSCPServer::LSCPServer(Sampler* pSampler Line 84  LSCPServer::LSCPServer(Sampler* pSampler
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");
# Line 164  void LSCPServer::DbInstrumentsEventHandl Line 165  void LSCPServer::DbInstrumentsEventHandl
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    
# Line 2152  String LSCPServer::SetFxSendLevel(uint u Line 2158  String LSCPServer::SetFxSendLevel(uint u
2158      return result.Produce();      return result.Produce();
2159  }  }
2160    
2161    String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) {
2162        dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel));
2163        LSCPResultSet result;
2164        try {
2165            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2166            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2167            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2168            if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
2169            Engine* pEngine = pEngineChannel->GetEngine();
2170            InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager();
2171            if (!pInstrumentManager) throw Exception("Engine does not provide an instrument manager");
2172            InstrumentManager::instrument_id_t instrumentID;
2173            instrumentID.FileName = pEngineChannel->InstrumentFileName();
2174            instrumentID.Index    = pEngineChannel->InstrumentIndex();
2175            pInstrumentManager->LaunchInstrumentEditor(instrumentID);
2176        } catch (Exception e) {
2177            result.Error(e);
2178        }
2179        return result.Produce();
2180    }
2181    
2182  /**  /**
2183   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
2184   */   */
# Line 2294  String LSCPServer::RemoveDbInstrumentDir Line 2321  String LSCPServer::RemoveDbInstrumentDir
2321      return result.Produce();      return result.Produce();
2322  }  }
2323    
2324  String LSCPServer::GetDbInstrumentDirectoryCount(String Dir) {  String LSCPServer::GetDbInstrumentDirectoryCount(String Dir, bool Recursive) {
2325      dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s)\n", Dir.c_str()));      dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2326      LSCPResultSet result;      LSCPResultSet result;
2327  #if HAVE_SQLITE3  #if HAVE_SQLITE3
2328      try {      try {
2329          result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir));          result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir, Recursive));
2330      } catch (Exception e) {      } catch (Exception e) {
2331           result.Error(e);           result.Error(e);
2332      }      }
# Line 2309  String LSCPServer::GetDbInstrumentDirect Line 2336  String LSCPServer::GetDbInstrumentDirect
2336      return result.Produce();      return result.Produce();
2337  }  }
2338    
2339  String LSCPServer::GetDbInstrumentDirectories(String Dir) {  String LSCPServer::GetDbInstrumentDirectories(String Dir, bool Recursive) {
2340      dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s)\n", Dir.c_str()));      dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2341      LSCPResultSet result;      LSCPResultSet result;
2342  #if HAVE_SQLITE3  #if HAVE_SQLITE3
2343      try {      try {
2344          String list;          String list;
2345          StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir);          StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir, Recursive);
2346    
2347          for (int i = 0; i < dirs->size(); i++) {          for (int i = 0; i < dirs->size(); i++) {
2348              if (list != "") list += ",";              if (list != "") list += ",";
# Line 2381  String LSCPServer::MoveDbInstrumentDirec Line 2408  String LSCPServer::MoveDbInstrumentDirec
2408      return result.Produce();      return result.Produce();
2409  }  }
2410    
2411  String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) {  String LSCPServer::CopyDbInstrumentDirectory(String Dir, String Dst) {
2412      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()));
2413      LSCPResultSet result;      LSCPResultSet result;
2414  #if HAVE_SQLITE3  #if HAVE_SQLITE3
2415      try {      try {
2416          InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc);          InstrumentsDb::GetInstrumentsDb()->CopyDirectory(Dir, Dst);
2417      } catch (Exception e) {      } catch (Exception e) {
2418           result.Error(e);           result.Error(e);
2419      }      }
# Line 2396  String LSCPServer::SetDbInstrumentDirect Line 2423  String LSCPServer::SetDbInstrumentDirect
2423      return result.Produce();      return result.Produce();
2424  }  }
2425    
2426  String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index) {  String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) {
2427      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()));
2428      LSCPResultSet result;      LSCPResultSet result;
2429  #if HAVE_SQLITE3  #if HAVE_SQLITE3
2430      try {      try {
2431          InstrumentsDb::GetInstrumentsDb()->AddInstruments(DbDir, FilePath, Index);          InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc);
2432      } catch (Exception e) {      } catch (Exception e) {
2433           result.Error(e);           result.Error(e);
2434      }      }
# Line 2411  String LSCPServer::AddDbInstruments(Stri Line 2438  String LSCPServer::AddDbInstruments(Stri
2438      return result.Produce();      return result.Produce();
2439  }  }
2440    
2441  String LSCPServer::AddDbInstrumentsFlat(String DbDir, String FsDir) {  String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index, bool bBackground) {
2442      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));
2443      LSCPResultSet result;      LSCPResultSet result;
2444  #if HAVE_SQLITE3  #if HAVE_SQLITE3
2445      try {      try {
2446          InstrumentsDb::GetInstrumentsDb()->AddInstrumentsRecursive(DbDir, FsDir, true);          int id;
2447            InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();
2448            id = db->AddInstruments(DbDir, FilePath, Index, bBackground);
2449            if (bBackground) result = id;
2450      } catch (Exception e) {      } catch (Exception e) {
2451           result.Error(e);           result.Error(e);
2452      }      }
# Line 2426  String LSCPServer::AddDbInstrumentsFlat( Line 2456  String LSCPServer::AddDbInstrumentsFlat(
2456      return result.Produce();      return result.Produce();
2457  }  }
2458    
2459  String LSCPServer::AddDbInstrumentsNonrecursive(String DbDir, String FsDir) {  String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) {
2460      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));
2461      LSCPResultSet result;      LSCPResultSet result;
2462  #if HAVE_SQLITE3  #if HAVE_SQLITE3
2463      try {      try {
2464          InstrumentsDb::GetInstrumentsDb()->AddInstrumentsNonrecursive(DbDir, FsDir);          int id;
2465            InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();
2466            if (ScanMode.compare("RECURSIVE") == 0) {
2467               id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground);
2468            } else if (ScanMode.compare("NON_RECURSIVE") == 0) {
2469               id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground);
2470            } else if (ScanMode.compare("FLAT") == 0) {
2471               id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground);
2472            } else {
2473                throw Exception("Unknown scan mode: " + ScanMode);
2474            }
2475            
2476            if (bBackground) result = id;
2477      } catch (Exception e) {      } catch (Exception e) {
2478           result.Error(e);           result.Error(e);
2479      }      }
# Line 2456  String LSCPServer::RemoveDbInstrument(St Line 2498  String LSCPServer::RemoveDbInstrument(St
2498      return result.Produce();      return result.Produce();
2499  }  }
2500    
2501  String LSCPServer::GetDbInstrumentCount(String Dir) {  String LSCPServer::GetDbInstrumentCount(String Dir, bool Recursive) {
2502      dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s)\n", Dir.c_str()));      dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2503      LSCPResultSet result;      LSCPResultSet result;
2504  #if HAVE_SQLITE3  #if HAVE_SQLITE3
2505      try {      try {
2506          result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir));          result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir, Recursive));
2507      } catch (Exception e) {      } catch (Exception e) {
2508           result.Error(e);           result.Error(e);
2509      }      }
# Line 2471  String LSCPServer::GetDbInstrumentCount( Line 2513  String LSCPServer::GetDbInstrumentCount(
2513      return result.Produce();      return result.Produce();
2514  }  }
2515    
2516  String LSCPServer::GetDbInstruments(String Dir) {  String LSCPServer::GetDbInstruments(String Dir, bool Recursive) {
2517      dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s)\n", Dir.c_str()));      dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2518      LSCPResultSet result;      LSCPResultSet result;
2519  #if HAVE_SQLITE3  #if HAVE_SQLITE3
2520      try {      try {
2521          String list;          String list;
2522          StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir);          StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir, Recursive);
2523    
2524          for (int i = 0; i < instrs->size(); i++) {          for (int i = 0; i < instrs->size(); i++) {
2525              if (list != "") list += ",";              if (list != "") list += ",";
# Line 2522  String LSCPServer::GetDbInstrumentInfo(S Line 2564  String LSCPServer::GetDbInstrumentInfo(S
2564      return result.Produce();      return result.Produce();
2565  }  }
2566    
2567    String LSCPServer::GetDbInstrumentsJobInfo(int JobId) {
2568        dmsg(2,("LSCPServer: GetDbInstrumentsJobInfo(JobId=%d)\n", JobId));
2569        LSCPResultSet result;
2570    #if HAVE_SQLITE3
2571        try {
2572            ScanJob job = InstrumentsDb::GetInstrumentsDb()->Jobs.GetJobById(JobId);
2573    
2574            result.Add("FILES_TOTAL", job.FilesTotal);
2575            result.Add("FILES_SCANNED", job.FilesScanned);
2576            result.Add("SCANNING", job.Scanning);
2577            result.Add("STATUS", job.Status);
2578        } catch (Exception e) {
2579             result.Error(e);
2580        }
2581    #else
2582        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2583    #endif
2584        return result.Produce();
2585    }
2586    
2587  String LSCPServer::SetDbInstrumentName(String Instr, String Name) {  String LSCPServer::SetDbInstrumentName(String Instr, String Name) {
2588      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()));
2589      LSCPResultSet result;      LSCPResultSet result;
# Line 2552  String LSCPServer::MoveDbInstrument(Stri Line 2614  String LSCPServer::MoveDbInstrument(Stri
2614      return result.Produce();      return result.Produce();
2615  }  }
2616    
2617    String LSCPServer::CopyDbInstrument(String Instr, String Dst) {
2618        dmsg(2,("LSCPServer: CopyDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str()));
2619        LSCPResultSet result;
2620    #if HAVE_SQLITE3
2621        try {
2622            InstrumentsDb::GetInstrumentsDb()->CopyInstrument(Instr, Dst);
2623        } catch (Exception e) {
2624             result.Error(e);
2625        }
2626    #else
2627        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2628    #endif
2629        return result.Produce();
2630    }
2631    
2632  String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) {  String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) {
2633      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()));
2634      LSCPResultSet result;      LSCPResultSet result;
# Line 2561  String LSCPServer::SetDbInstrumentDescri Line 2638  String LSCPServer::SetDbInstrumentDescri
2638      } catch (Exception e) {      } catch (Exception e) {
2639           result.Error(e);           result.Error(e);
2640      }      }
2641    #else
2642        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2643    #endif
2644        return result.Produce();
2645    }
2646    
2647    String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) {
2648        dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str()));
2649        LSCPResultSet result;
2650    #if HAVE_SQLITE3
2651        try {
2652            SearchQuery Query;
2653            std::map<String,String>::iterator iter;
2654            for (iter = Parameters.begin(); iter != Parameters.end(); iter++) {
2655                if (iter->first.compare("NAME") == 0) {
2656                    Query.Name = iter->second;
2657                } else if (iter->first.compare("CREATED") == 0) {
2658                    Query.SetCreated(iter->second);
2659                } else if (iter->first.compare("MODIFIED") == 0) {
2660                    Query.SetModified(iter->second);
2661                } else if (iter->first.compare("DESCRIPTION") == 0) {
2662                    Query.Description = iter->second;
2663                } else {
2664                    throw Exception("Unknown search criteria: " + iter->first);
2665                }
2666            }
2667    
2668            String list;
2669            StringListPtr pDirectories =
2670                InstrumentsDb::GetInstrumentsDb()->FindDirectories(Dir, &Query, Recursive);
2671    
2672            for (int i = 0; i < pDirectories->size(); i++) {
2673                if (list != "") list += ",";
2674                list += "'" + pDirectories->at(i) + "'";
2675            }
2676    
2677            result.Add(list);
2678        } catch (Exception e) {
2679             result.Error(e);
2680        }
2681    #else
2682        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2683    #endif
2684        return result.Produce();
2685    }
2686    
2687    String LSCPServer::FindDbInstruments(String Dir, std::map<String,String> Parameters, bool Recursive) {
2688        dmsg(2,("LSCPServer: FindDbInstruments(Dir=%s)\n", Dir.c_str()));
2689        LSCPResultSet result;
2690    #if HAVE_SQLITE3
2691        try {
2692            SearchQuery Query;
2693            std::map<String,String>::iterator iter;
2694            for (iter = Parameters.begin(); iter != Parameters.end(); iter++) {
2695                if (iter->first.compare("NAME") == 0) {
2696                    Query.Name = iter->second;
2697                } else if (iter->first.compare("FORMAT_FAMILIES") == 0) {
2698                    Query.SetFormatFamilies(iter->second);
2699                } else if (iter->first.compare("SIZE") == 0) {
2700                    Query.SetSize(iter->second);
2701                } else if (iter->first.compare("CREATED") == 0) {
2702                    Query.SetCreated(iter->second);
2703                } else if (iter->first.compare("MODIFIED") == 0) {
2704                    Query.SetModified(iter->second);
2705                } else if (iter->first.compare("DESCRIPTION") == 0) {
2706                    Query.Description = iter->second;
2707                } else if (iter->first.compare("IS_DRUM") == 0) {
2708                    if (!strcasecmp(iter->second.c_str(), "true")) {
2709                        Query.InstrType = SearchQuery::DRUM;
2710                    } else {
2711                        Query.InstrType = SearchQuery::CHROMATIC;
2712                    }
2713                } else if (iter->first.compare("PRODUCT") == 0) {
2714                     Query.Product = iter->second;
2715                } else if (iter->first.compare("ARTISTS") == 0) {
2716                     Query.Artists = iter->second;
2717                } else if (iter->first.compare("KEYWORDS") == 0) {
2718                     Query.Keywords = iter->second;
2719                } else {
2720                    throw Exception("Unknown search criteria: " + iter->first);
2721                }
2722            }
2723    
2724            String list;
2725            StringListPtr pInstruments =
2726                InstrumentsDb::GetInstrumentsDb()->FindInstruments(Dir, &Query, Recursive);
2727    
2728            for (int i = 0; i < pInstruments->size(); i++) {
2729                if (list != "") list += ",";
2730                list += "'" + pInstruments->at(i) + "'";
2731            }
2732    
2733            result.Add(list);
2734        } catch (Exception e) {
2735             result.Error(e);
2736        }
2737  #else  #else
2738      result.Error(String(DOESNT_HAVE_SQLITE3), 0);      result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2739  #endif  #endif

Legend:
Removed from v.1161  
changed lines
  Added in v.1212

  ViewVC Help
Powered by ViewVC