/[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 1200 by iliev, Thu May 24 14:04:18 2007 UTC revision 1353 by iliev, Mon Sep 17 23:15:25 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 145  void LSCPServer::EventHandler::TotalVoic Line 146  void LSCPServer::EventHandler::TotalVoic
146    
147  #if HAVE_SQLITE3  #if HAVE_SQLITE3
148  void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) {  void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) {
149      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, Dir));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, InstrumentsDb::toEscapedPath(Dir)));
150  }  }
151    
152  void LSCPServer::DbInstrumentsEventHandler::DirectoryInfoChanged(String Dir) {  void LSCPServer::DbInstrumentsEventHandler::DirectoryInfoChanged(String Dir) {
153      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, Dir));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, InstrumentsDb::toEscapedPath(Dir)));
154  }  }
155    
156  void LSCPServer::DbInstrumentsEventHandler::DirectoryNameChanged(String Dir, String NewName) {  void LSCPServer::DbInstrumentsEventHandler::DirectoryNameChanged(String Dir, String NewName) {
157      Dir = "'" + Dir + "'";      Dir = "'" + InstrumentsDb::toEscapedPath(Dir) + "'";
158      NewName = "'" + NewName + "'";      NewName = "'" + InstrumentsDb::toEscapedPath(NewName) + "'";
159      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, "NAME", Dir, NewName));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, "NAME", Dir, NewName));
160  }  }
161    
162  void LSCPServer::DbInstrumentsEventHandler::InstrumentCountChanged(String Dir) {  void LSCPServer::DbInstrumentsEventHandler::InstrumentCountChanged(String Dir) {
163      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_count, Dir));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_count, InstrumentsDb::toEscapedPath(Dir)));
164  }  }
165    
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, InstrumentsDb::toEscapedPath(Instr)));
168  }  }
169    
170  void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) {  void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) {
171      Instr = "'" + Instr + "'";      Instr = "'" + InstrumentsDb::toEscapedPath(Instr) + "'";
172      NewName = "'" + NewName + "'";      NewName = "'" + InstrumentsDb::toEscapedPath(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    
# Line 218  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 327  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 425  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 612  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 1999  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 2083  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 2158  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 2202  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 2325  String LSCPServer::GetDbInstrumentDirect Line 2354  String LSCPServer::GetDbInstrumentDirect
2354    
2355          for (int i = 0; i < dirs->size(); i++) {          for (int i = 0; i < dirs->size(); i++) {
2356              if (list != "") list += ",";              if (list != "") list += ",";
2357              list += "'" + dirs->at(i) + "'";              list += "'" + InstrumentsDb::toEscapedPath(dirs->at(i)) + "'";
2358          }          }
2359    
2360          result.Add(list);          result.Add(list);
# Line 2345  String LSCPServer::GetDbInstrumentDirect Line 2374  String LSCPServer::GetDbInstrumentDirect
2374      try {      try {
2375          DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir);          DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir);
2376    
2377          result.Add("DESCRIPTION", info.Description);          result.Add("DESCRIPTION", InstrumentsDb::toEscapedText(info.Description));
2378          result.Add("CREATED", info.Created);          result.Add("CREATED", info.Created);
2379          result.Add("MODIFIED", info.Modified);          result.Add("MODIFIED", info.Modified);
2380      } catch (Exception e) {      } catch (Exception e) {
# Line 2451  String LSCPServer::AddDbInstruments(Stri Line 2480  String LSCPServer::AddDbInstruments(Stri
2480          } else {          } else {
2481              throw Exception("Unknown scan mode: " + ScanMode);              throw Exception("Unknown scan mode: " + ScanMode);
2482          }          }
2483            
2484          if (bBackground) result = id;          if (bBackground) result = id;
2485      } catch (Exception e) {      } catch (Exception e) {
2486           result.Error(e);           result.Error(e);
# Line 2502  String LSCPServer::GetDbInstruments(Stri Line 2531  String LSCPServer::GetDbInstruments(Stri
2531    
2532          for (int i = 0; i < instrs->size(); i++) {          for (int i = 0; i < instrs->size(); i++) {
2533              if (list != "") list += ",";              if (list != "") list += ",";
2534              list += "'" + instrs->at(i) + "'";              list += "'" + InstrumentsDb::toEscapedPath(instrs->at(i)) + "'";
2535          }          }
2536    
2537          result.Add(list);          result.Add(list);
# Line 2529  String LSCPServer::GetDbInstrumentInfo(S Line 2558  String LSCPServer::GetDbInstrumentInfo(S
2558          result.Add("SIZE", (int)info.Size);          result.Add("SIZE", (int)info.Size);
2559          result.Add("CREATED", info.Created);          result.Add("CREATED", info.Created);
2560          result.Add("MODIFIED", info.Modified);          result.Add("MODIFIED", info.Modified);
2561          result.Add("DESCRIPTION", FilterEndlines(info.Description));          result.Add("DESCRIPTION", InstrumentsDb::toEscapedText(info.Description));
2562          result.Add("IS_DRUM", info.IsDrum);          result.Add("IS_DRUM", info.IsDrum);
2563          result.Add("PRODUCT", FilterEndlines(info.Product));          result.Add("PRODUCT", InstrumentsDb::toEscapedText(info.Product));
2564          result.Add("ARTISTS", FilterEndlines(info.Artists));          result.Add("ARTISTS", InstrumentsDb::toEscapedText(info.Artists));
2565          result.Add("KEYWORDS", FilterEndlines(info.Keywords));          result.Add("KEYWORDS", InstrumentsDb::toEscapedText(info.Keywords));
2566      } catch (Exception e) {      } catch (Exception e) {
2567           result.Error(e);           result.Error(e);
2568      }      }
# Line 2650  String LSCPServer::FindDbInstrumentDirec Line 2679  String LSCPServer::FindDbInstrumentDirec
2679    
2680          for (int i = 0; i < pDirectories->size(); i++) {          for (int i = 0; i < pDirectories->size(); i++) {
2681              if (list != "") list += ",";              if (list != "") list += ",";
2682              list += "'" + pDirectories->at(i) + "'";              list += "'" + InstrumentsDb::toEscapedPath(pDirectories->at(i)) + "'";
2683          }          }
2684    
2685          result.Add(list);          result.Add(list);
# Line 2706  String LSCPServer::FindDbInstruments(Str Line 2735  String LSCPServer::FindDbInstruments(Str
2735    
2736          for (int i = 0; i < pInstruments->size(); i++) {          for (int i = 0; i < pInstruments->size(); i++) {
2737              if (list != "") list += ",";              if (list != "") list += ",";
2738              list += "'" + pInstruments->at(i) + "'";              list += "'" + InstrumentsDb::toEscapedPath(pInstruments->at(i)) + "'";
2739          }          }
2740    
2741          result.Add(list);          result.Add(list);
# Line 2719  String LSCPServer::FindDbInstruments(Str Line 2748  String LSCPServer::FindDbInstruments(Str
2748      return result.Produce();      return result.Produce();
2749  }  }
2750    
2751    String LSCPServer::FormatInstrumentsDb() {
2752        dmsg(2,("LSCPServer: FormatInstrumentsDb()\n"));
2753        LSCPResultSet result;
2754    #if HAVE_SQLITE3
2755        try {
2756            InstrumentsDb::GetInstrumentsDb()->Format();
2757        } catch (Exception e) {
2758             result.Error(e);
2759        }
2760    #else
2761        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2762    #endif
2763        return result.Produce();
2764    }
2765    
2766    
2767  /**  /**
2768   * 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
# Line 2738  String LSCPServer::SetEcho(yyparse_param Line 2782  String LSCPServer::SetEcho(yyparse_param
2782      }      }
2783      return result.Produce();      return result.Produce();
2784  }  }
   
 String LSCPServer::FilterEndlines(String s) {  
     String s2 = s;  
     for (int i = 0; i < s2.length(); i++) {  
         if (s2.at(i) == '\r') s2.at(i) = ' ';  
         else if (s2.at(i) == '\n') s2.at(i) = ' ';  
     }  
       
     return s2;  
 }  

Legend:
Removed from v.1200  
changed lines
  Added in v.1353

  ViewVC Help
Powered by ViewVC