/[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 1187 by iliev, Wed May 16 14:22:26 2007 UTC revision 1337 by iliev, Sun Sep 9 23:27:23 2007 UTC
# Line 52  Line 52 
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> >();
# Line 84  LSCPServer::LSCPServer(Sampler* pSampler Line 85  LSCPServer::LSCPServer(Sampler* pSampler
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");
# Line 164  void LSCPServer::DbInstrumentsEventHandl Line 166  void LSCPServer::DbInstrumentsEventHandl
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, Instr));
168  }  }
169    
170  void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) {  void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) {
171      Instr = "'" + Instr + "'";      Instr = "'" + Instr + "'";
172      NewName = "'" + NewName + "'";      NewName = "'" + 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    
# Line 212  int LSCPServer::Main() { Line 219  int LSCPServer::Main() {
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);
# Line 321  int LSCPServer::Main() { Line 328  int LSCPServer::Main() {
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);
# Line 419  extern int GetLSCPCommand( void *buf, in Line 428  extern int GetLSCPCommand( void *buf, in
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.
# Line 606  EngineChannel* LSCPServer::GetEngineChan Line 619  EngineChannel* LSCPServer::GetEngineChan
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  /**  /**
# Line 1993  String LSCPServer::CreateFxSend(uint uiS Line 2006  String LSCPServer::CreateFxSend(uint uiS
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    
# Line 2077  String LSCPServer::GetFxSendInfo(uint ui Line 2090  String LSCPServer::GetFxSendInfo(uint ui
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++) {
# Line 2152  String LSCPServer::SetFxSendLevel(uint u Line 2165  String LSCPServer::SetFxSendLevel(uint u
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   */   */
# Line 2196  String LSCPServer::GetServerInfo() { Line 2231  String LSCPServer::GetServerInfo() {
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    
# Line 2411  String LSCPServer::SetDbInstrumentDirect Line 2446  String LSCPServer::SetDbInstrumentDirect
2446      return result.Produce();      return result.Produce();
2447  }  }
2448    
2449  String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index) {  String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index, bool bBackground) {
2450      dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d)\n", DbDir.c_str(), FilePath.c_str(), Index));      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()->AddInstruments(DbDir, FilePath, Index);          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      }      }
# Line 2426  String LSCPServer::AddDbInstruments(Stri Line 2464  String LSCPServer::AddDbInstruments(Stri
2464      return result.Produce();      return result.Produce();
2465  }  }
2466    
2467  String LSCPServer::AddDbInstrumentsFlat(String DbDir, String FsDir) {  String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) {
2468      dmsg(2,("LSCPServer: AddDbInstrumentsFlat(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()->AddInstrumentsRecursive(DbDir, FsDir, true);          int id;
2473      } catch (Exception e) {          InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();
2474           result.Error(e);          if (ScanMode.compare("RECURSIVE") == 0) {
2475      }             id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground);
2476  #else          } else if (ScanMode.compare("NON_RECURSIVE") == 0) {
2477      result.Error(String(DOESNT_HAVE_SQLITE3), 0);             id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground);
2478  #endif          } else if (ScanMode.compare("FLAT") == 0) {
2479      return result.Produce();             id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground);
2480  }          } else {
2481                throw Exception("Unknown scan mode: " + ScanMode);
2482            }
2483    
2484  String LSCPServer::AddDbInstrumentsNonrecursive(String DbDir, String FsDir) {          if (bBackground) result = id;
     dmsg(2,("LSCPServer: AddDbInstrumentsNonrecursive(DbDir=%s,FilePath=%s)\n", DbDir.c_str(), FsDir.c_str()));  
     LSCPResultSet result;  
 #if HAVE_SQLITE3  
     try {  
         InstrumentsDb::GetInstrumentsDb()->AddInstrumentsNonrecursive(DbDir, FsDir);  
2485      } catch (Exception e) {      } catch (Exception e) {
2486           result.Error(e);           result.Error(e);
2487      }      }
# Line 2537  String LSCPServer::GetDbInstrumentInfo(S Line 2572  String LSCPServer::GetDbInstrumentInfo(S
2572      return result.Produce();      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) {
2587             result.Error(e);
2588        }
2589    #else
2590        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2591    #endif
2592        return result.Produce();
2593    }
2594    
2595  String LSCPServer::SetDbInstrumentName(String Instr, String Name) {  String LSCPServer::SetDbInstrumentName(String Instr, String Name) {
2596      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()));
2597      LSCPResultSet result;      LSCPResultSet result;
# Line 2719  String LSCPServer::FilterEndlines(String Line 2774  String LSCPServer::FilterEndlines(String
2774          if (s2.at(i) == '\r') s2.at(i) = ' ';          if (s2.at(i) == '\r') s2.at(i) = ' ';
2775          else if (s2.at(i) == '\n') s2.at(i) = ' ';          else if (s2.at(i) == '\n') s2.at(i) = ' ';
2776      }      }
2777        
2778      return s2;      return s2;
2779  }  }

Legend:
Removed from v.1187  
changed lines
  Added in v.1337

  ViewVC Help
Powered by ViewVC