/[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 1133 by iliev, Mon Mar 26 08:27:06 2007 UTC revision 1471 by schoenebeck, Mon Nov 5 13:56:26 2007 UTC
# Line 24  Line 24 
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"
# Line 37  Line 36 
36  #include "../drivers/audio/AudioOutputDeviceFactory.h"  #include "../drivers/audio/AudioOutputDeviceFactory.h"
37  #include "../drivers/midi/MidiInputDeviceFactory.h"  #include "../drivers/midi/MidiInputDeviceFactory.h"
38    
39    
40    /**
41     * Returns a copy of the given string where all special characters are
42     * replaced by LSCP escape sequences ("\xHH"). This function shall be used
43     * to escape LSCP response fields in case the respective response field is
44     * actually defined as using escape sequences in the LSCP specs.
45     *
46     * @e Caution: DO NOT use this function for escaping path based responses,
47     * use the Path class (src/common/Path.h) for this instead!
48     */
49    static String _escapeLscpResponse(String txt) {
50        for (int i = 0; i < txt.length(); i++) {
51            const char c = txt.c_str()[i];
52            if (
53                !(c >= '0' && c <= '9') &&
54                !(c >= 'a' && c <= 'z') &&
55                !(c >= 'A' && c <= 'Z') &&
56                !(c == ' ') && !(c == '!') && !(c == '#') && !(c == '$') &&
57                !(c == '%') && !(c == '&') && !(c == '(') && !(c == ')') &&
58                !(c == '*') && !(c == '+') && !(c == ',') && !(c == '-') &&
59                !(c == '.') && !(c == '/') && !(c == ':') && !(c == ';') &&
60                !(c == '<') && !(c == '=') && !(c == '>') && !(c == '?') &&
61                !(c == '@') && !(c == '[') && !(c == ']') &&
62                !(c == '^') && !(c == '_') && !(c == '`') && !(c == '{') &&
63                !(c == '|') && !(c == '}') && !(c == '~')
64            ) {
65                // convert the "special" character into a "\xHH" LSCP escape sequence
66                char buf[5];
67                snprintf(buf, sizeof(buf), "\\x%02x", static_cast<unsigned char>(c));
68                txt.replace(i, 1, buf);
69                i += 3;
70            }
71        }
72        return txt;
73    }
74    
75  /**  /**
76   * Below are a few static members of the LSCPServer class.   * Below are a few static members of the LSCPServer class.
77   * The big assumption here is that LSCPServer is going to remain a singleton.   * The big assumption here is that LSCPServer is going to remain a singleton.
# Line 53  Line 88 
88  fd_set LSCPServer::fdSet;  fd_set LSCPServer::fdSet;
89  int LSCPServer::currentSocket = -1;  int LSCPServer::currentSocket = -1;
90  std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>();  std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>();
91    std::vector<yyparse_param_t>::iterator itCurrentSession = std::vector<yyparse_param_t>::iterator();
92  std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>();  std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>();
93  std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>();  std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>();
94  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 81  LSCPServer::LSCPServer(Sampler* pSampler Line 117  LSCPServer::LSCPServer(Sampler* pSampler
117      LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO");
118      LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT");
119      LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO");
120        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_count, "DB_INSTRUMENT_DIRECTORY_COUNT");
121        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_info, "DB_INSTRUMENT_DIRECTORY_INFO");
122        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_count, "DB_INSTRUMENT_COUNT");
123        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO");
124        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO");
125      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
126      LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");
127      LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO");
# Line 139  void LSCPServer::EventHandler::TotalVoic Line 180  void LSCPServer::EventHandler::TotalVoic
180      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount));
181  }  }
182    
183    #if HAVE_SQLITE3
184    void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) {
185        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, InstrumentsDb::toEscapedPath(Dir)));
186    }
187    
188    void LSCPServer::DbInstrumentsEventHandler::DirectoryInfoChanged(String Dir) {
189        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, InstrumentsDb::toEscapedPath(Dir)));
190    }
191    
192    void LSCPServer::DbInstrumentsEventHandler::DirectoryNameChanged(String Dir, String NewName) {
193        Dir = "'" + InstrumentsDb::toEscapedPath(Dir) + "'";
194        NewName = "'" + InstrumentsDb::toEscapedPath(NewName) + "'";
195        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, "NAME", Dir, NewName));
196    }
197    
198    void LSCPServer::DbInstrumentsEventHandler::InstrumentCountChanged(String Dir) {
199        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_count, InstrumentsDb::toEscapedPath(Dir)));
200    }
201    
202    void LSCPServer::DbInstrumentsEventHandler::InstrumentInfoChanged(String Instr) {
203        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, InstrumentsDb::toEscapedPath(Instr)));
204    }
205    
206    void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) {
207        Instr = "'" + InstrumentsDb::toEscapedPath(Instr) + "'";
208        NewName = "'" + InstrumentsDb::toEscapedPath(NewName) + "'";
209        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, "NAME", Instr, NewName));
210    }
211    
212    void LSCPServer::DbInstrumentsEventHandler::JobStatusChanged(int JobId) {
213        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instrs_job_info, JobId));
214    }
215    #endif // HAVE_SQLITE3
216    
217    
218  /**  /**
219   * Blocks the calling thread until the LSCP Server is initialized and   * Blocks the calling thread until the LSCP Server is initialized and
# Line 180  int LSCPServer::Main() { Line 255  int LSCPServer::Main() {
255    
256      listen(hSocket, 1);      listen(hSocket, 1);
257      Initialized.Set(true);      Initialized.Set(true);
258        
259      // Registering event listeners      // Registering event listeners
260      pSampler->AddChannelCountListener(&eventHandler);      pSampler->AddChannelCountListener(&eventHandler);
261      pSampler->AddAudioDeviceCountListener(&eventHandler);      pSampler->AddAudioDeviceCountListener(&eventHandler);
# Line 194  int LSCPServer::Main() { Line 269  int LSCPServer::Main() {
269      MidiInstrumentMapper::AddMidiInstrumentInfoListener(&eventHandler);      MidiInstrumentMapper::AddMidiInstrumentInfoListener(&eventHandler);
270      MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&eventHandler);      MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&eventHandler);
271      MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(&eventHandler);      MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(&eventHandler);
272    #if HAVE_SQLITE3
273        InstrumentsDb::GetInstrumentsDb()->AddInstrumentsDbListener(&dbInstrumentsEventHandler);
274    #endif
275      // now wait for client connections and handle their requests      // now wait for client connections and handle their requests
276      sockaddr_in client;      sockaddr_in client;
277      int length = sizeof(client);      int length = sizeof(client);
# Line 287  int LSCPServer::Main() { Line 364  int LSCPServer::Main() {
364                                  int dummy; // just a temporary hack to fulfill the restart() function prototype                                  int dummy; // just a temporary hack to fulfill the restart() function prototype
365                                  restart(NULL, dummy); // restart the 'scanner'                                  restart(NULL, dummy); // restart the 'scanner'
366                                  currentSocket = (*iter).hSession;  //a hack                                  currentSocket = (*iter).hSession;  //a hack
367                                    itCurrentSession = iter; // another hack
368                                  dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str()));                                  dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str()));
369                                  if ((*iter).bVerbose) { // if echo mode enabled                                  if ((*iter).bVerbose) { // if echo mode enabled
370                                      AnswerClient(bufferedCommands[currentSocket]);                                      AnswerClient(bufferedCommands[currentSocket]);
371                                  }                                  }
372                                  int result = yyparse(&(*iter));                                  int result = yyparse(&(*iter));
373                                  currentSocket = -1;     //continuation of a hack                                  currentSocket = -1;     //continuation of a hack
374                                    itCurrentSession = Sessions.end(); // hack as well
375                                  dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket));                                  dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket));
376                                  if (result == LSCP_QUIT) { //Was it a quit command by any chance?                                  if (result == LSCP_QUIT) { //Was it a quit command by any chance?
377                                          CloseConnection(iter);                                          CloseConnection(iter);
# Line 385  extern int GetLSCPCommand( void *buf, in Line 464  extern int GetLSCPCommand( void *buf, in
464          return command.size();          return command.size();
465  }  }
466    
467    extern yyparse_param_t* GetCurrentYaccSession() {
468        return &(*itCurrentSession);
469    }
470    
471  /**  /**
472   * Will be called to try to read the command from the socket   * Will be called to try to read the command from the socket
473   * 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 565  String LSCPServer::DestroyMidiInputDevic Line 648  String LSCPServer::DestroyMidiInputDevic
648      return result.Produce();      return result.Produce();
649  }  }
650    
651    EngineChannel* LSCPServer::GetEngineChannel(uint uiSamplerChannel) {
652        SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
653        if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
654    
655        EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
656        if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
657    
658        return pEngineChannel;
659    }
660    
661  /**  /**
662   * Will be called by the parser to load an instrument.   * Will be called by the parser to load an instrument.
663   */   */
# Line 711  String LSCPServer::GetEngineInfo(String Line 804  String LSCPServer::GetEngineInfo(String
804      LockRTNotify();      LockRTNotify();
805      try {      try {
806          Engine* pEngine = EngineFactory::Create(EngineName);          Engine* pEngine = EngineFactory::Create(EngineName);
807          result.Add("DESCRIPTION", pEngine->Description());          result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description()));
808          result.Add("VERSION",     pEngine->Version());          result.Add("VERSION",     pEngine->Version());
809          EngineFactory::Destroy(pEngine);          EngineFactory::Destroy(pEngine);
810      }      }
# Line 784  String LSCPServer::GetChannelInfo(uint u Line 877  String LSCPServer::GetChannelInfo(uint u
877          if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL");          if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL");
878          else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());          else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
879    
880            // convert the filename into the correct encoding as defined for LSCP
881            // (especially in terms of special characters -> escape sequences)
882            if (InstrumentFileName != "NONE" && InstrumentFileName != "") {
883    #if WIN32
884                InstrumentFileName = Path::fromWindows(InstrumentFileName).toLscp();
885    #else
886                // assuming POSIX
887                InstrumentFileName = Path::fromPosix(InstrumentFileName).toLscp();
888    #endif
889            }
890    
891          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
892          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
893          result.Add("INSTRUMENT_NAME", InstrumentName);          result.Add("INSTRUMENT_NAME", _escapeLscpResponse(InstrumentName));
894          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
895          result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));          result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));
896          result.Add("SOLO", Solo);          result.Add("SOLO", Solo);
# Line 1728  String LSCPServer::GetMidiInstrumentMapp Line 1832  String LSCPServer::GetMidiInstrumentMapp
1832          std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx);          std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx);
1833          if (iter == mappings.end()) result.Error("there is no map entry with that index");          if (iter == mappings.end()) result.Error("there is no map entry with that index");
1834          else { // found          else { // found
1835              result.Add("NAME", iter->second.Name);  
1836                // convert the filename into the correct encoding as defined for LSCP
1837                // (especially in terms of special characters -> escape sequences)
1838    #if WIN32
1839                const String instrumentFileName = Path::fromWindows(iter->second.InstrumentFile).toLscp();
1840    #else
1841                // assuming POSIX
1842                const String instrumentFileName = Path::fromPosix(iter->second.InstrumentFile).toLscp();
1843    #endif
1844    
1845                result.Add("NAME", _escapeLscpResponse(iter->second.Name));
1846              result.Add("ENGINE_NAME", iter->second.EngineName);              result.Add("ENGINE_NAME", iter->second.EngineName);
1847              result.Add("INSTRUMENT_FILE", iter->second.InstrumentFile);              result.Add("INSTRUMENT_FILE", instrumentFileName);
1848              result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex);              result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex);
1849              String instrumentName;              String instrumentName;
1850              Engine* pEngine = EngineFactory::Create(iter->second.EngineName);              Engine* pEngine = EngineFactory::Create(iter->second.EngineName);
# Line 1743  String LSCPServer::GetMidiInstrumentMapp Line 1857  String LSCPServer::GetMidiInstrumentMapp
1857                  }                  }
1858                  EngineFactory::Destroy(pEngine);                  EngineFactory::Destroy(pEngine);
1859              }              }
1860              result.Add("INSTRUMENT_NAME", instrumentName);              result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName));
1861              switch (iter->second.LoadMode) {              switch (iter->second.LoadMode) {
1862                  case MidiInstrumentMapper::ON_DEMAND:                  case MidiInstrumentMapper::ON_DEMAND:
1863                      result.Add("LOAD_MODE", "ON_DEMAND");                      result.Add("LOAD_MODE", "ON_DEMAND");
# Line 1898  String LSCPServer::GetMidiInstrumentMap( Line 2012  String LSCPServer::GetMidiInstrumentMap(
2012      dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n"));      dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n"));
2013      LSCPResultSet result;      LSCPResultSet result;
2014      try {      try {
2015          result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID));          result.Add("NAME", _escapeLscpResponse(MidiInstrumentMapper::MapName(MidiMapID)));
2016            result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID);
2017      } catch (Exception e) {      } catch (Exception e) {
2018          result.Error(e);          result.Error(e);
2019      }      }
# Line 1947  String LSCPServer::CreateFxSend(uint uiS Line 2062  String LSCPServer::CreateFxSend(uint uiS
2062      dmsg(2,("LSCPServer: CreateFxSend()\n"));      dmsg(2,("LSCPServer: CreateFxSend()\n"));
2063      LSCPResultSet result;      LSCPResultSet result;
2064      try {      try {
2065          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
   
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");  
2066    
2067          FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name);          FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name);
2068          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)");
# Line 1967  String LSCPServer::DestroyFxSend(uint ui Line 2078  String LSCPServer::DestroyFxSend(uint ui
2078      dmsg(2,("LSCPServer: DestroyFxSend()\n"));      dmsg(2,("LSCPServer: DestroyFxSend()\n"));
2079      LSCPResultSet result;      LSCPResultSet result;
2080      try {      try {
2081          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
   
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");  
2082    
2083          FxSend* pFxSend = NULL;          FxSend* pFxSend = NULL;
2084          for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {          for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
# Line 1992  String LSCPServer::GetFxSends(uint uiSam Line 2099  String LSCPServer::GetFxSends(uint uiSam
2099      dmsg(2,("LSCPServer: GetFxSends()\n"));      dmsg(2,("LSCPServer: GetFxSends()\n"));
2100      LSCPResultSet result;      LSCPResultSet result;
2101      try {      try {
2102          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
   
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");  
2103    
2104          result.Add(pEngineChannel->GetFxSendCount());          result.Add(pEngineChannel->GetFxSendCount());
2105      } catch (Exception e) {      } catch (Exception e) {
# Line 2010  String LSCPServer::ListFxSends(uint uiSa Line 2113  String LSCPServer::ListFxSends(uint uiSa
2113      LSCPResultSet result;      LSCPResultSet result;
2114      String list;      String list;
2115      try {      try {
2116          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
   
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");  
2117    
2118          for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {          for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2119              FxSend* pFxSend = pEngineChannel->GetFxSend(i);              FxSend* pFxSend = pEngineChannel->GetFxSend(i);
# Line 2028  String LSCPServer::ListFxSends(uint uiSa Line 2127  String LSCPServer::ListFxSends(uint uiSa
2127      return result.Produce();      return result.Produce();
2128  }  }
2129    
2130    FxSend* LSCPServer::GetFxSend(uint uiSamplerChannel, uint FxSendID) {
2131        EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2132    
2133        FxSend* pFxSend = NULL;
2134        for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2135            if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2136                pFxSend = pEngineChannel->GetFxSend(i);
2137                break;
2138            }
2139        }
2140        if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2141        return pFxSend;
2142    }
2143    
2144  String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) {  String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) {
2145      dmsg(2,("LSCPServer: GetFxSendInfo()\n"));      dmsg(2,("LSCPServer: GetFxSendInfo()\n"));
2146      LSCPResultSet result;      LSCPResultSet result;
2147      try {      try {
2148          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2149          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));          FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
   
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");  
   
         FxSend* pFxSend = NULL;  
         for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {  
             if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {  
                 pFxSend = pEngineChannel->GetFxSend(i);  
                 break;  
             }  
         }  
         if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");  
2150    
2151          // gather audio routing informations          // gather audio routing informations
2152          String AudioRouting;          String AudioRouting;
# Line 2055  String LSCPServer::GetFxSendInfo(uint ui Line 2156  String LSCPServer::GetFxSendInfo(uint ui
2156          }          }
2157    
2158          // success          // success
2159          result.Add("NAME", pFxSend->Name());          result.Add("NAME", _escapeLscpResponse(pFxSend->Name()));
2160          result.Add("MIDI_CONTROLLER", pFxSend->MidiController());          result.Add("MIDI_CONTROLLER", pFxSend->MidiController());
2161          result.Add("LEVEL", ToString(pFxSend->Level()));          result.Add("LEVEL", ToString(pFxSend->Level()));
2162          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
# Line 2065  String LSCPServer::GetFxSendInfo(uint ui Line 2166  String LSCPServer::GetFxSendInfo(uint ui
2166      return result.Produce();      return result.Produce();
2167  }  }
2168    
2169  String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) {  String LSCPServer::SetFxSendName(uint uiSamplerChannel, uint FxSendID, String Name) {
2170      dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n"));      dmsg(2,("LSCPServer: SetFxSendName()\n"));
2171      LSCPResultSet result;      LSCPResultSet result;
2172      try {      try {
2173          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
2174    
2175          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          pFxSend->SetName(Name);
2176          if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2177        } catch (Exception e) {
2178            result.Error(e);
2179        }
2180        return result.Produce();
2181    }
2182    
2183          FxSend* pFxSend = NULL;  String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) {
2184          for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {      dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n"));
2185              if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {      LSCPResultSet result;
2186                  pFxSend = pEngineChannel->GetFxSend(i);      try {
2187                  break;          FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
             }  
         }  
         if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");  
2188    
2189          pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel);          pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel);
2190          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
# Line 2096  String LSCPServer::SetFxSendMidiControll Line 2198  String LSCPServer::SetFxSendMidiControll
2198      dmsg(2,("LSCPServer: SetFxSendMidiController()\n"));      dmsg(2,("LSCPServer: SetFxSendMidiController()\n"));
2199      LSCPResultSet result;      LSCPResultSet result;
2200      try {      try {
2201          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
   
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");  
   
         FxSend* pFxSend = NULL;  
         for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {  
             if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {  
                 pFxSend = pEngineChannel->GetFxSend(i);  
                 break;  
             }  
         }  
         if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");  
2202    
2203          pFxSend->SetMidiController(MidiController);          pFxSend->SetMidiController(MidiController);
2204          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
# Line 2123  String LSCPServer::SetFxSendLevel(uint u Line 2212  String LSCPServer::SetFxSendLevel(uint u
2212      dmsg(2,("LSCPServer: SetFxSendLevel()\n"));      dmsg(2,("LSCPServer: SetFxSendLevel()\n"));
2213      LSCPResultSet result;      LSCPResultSet result;
2214      try {      try {
2215          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
   
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");  
   
         FxSend* pFxSend = NULL;  
         for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {  
             if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {  
                 pFxSend = pEngineChannel->GetFxSend(i);  
                 break;  
             }  
         }  
         if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");  
2216    
2217          pFxSend->SetLevel((float)dLevel);          pFxSend->SetLevel((float)dLevel);
2218          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
# Line 2146  String LSCPServer::SetFxSendLevel(uint u Line 2222  String LSCPServer::SetFxSendLevel(uint u
2222      return result.Produce();      return result.Produce();
2223  }  }
2224    
2225    String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) {
2226        dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel));
2227        LSCPResultSet result;
2228        try {
2229            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2230            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2231            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2232            if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
2233            if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel");
2234            Engine* pEngine = pEngineChannel->GetEngine();
2235            InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager();
2236            if (!pInstrumentManager) throw Exception("Engine does not provide an instrument manager");
2237            InstrumentManager::instrument_id_t instrumentID;
2238            instrumentID.FileName = pEngineChannel->InstrumentFileName();
2239            instrumentID.Index    = pEngineChannel->InstrumentIndex();
2240            pInstrumentManager->LaunchInstrumentEditor(instrumentID);
2241        } catch (Exception e) {
2242            result.Error(e);
2243        }
2244        return result.Produce();
2245    }
2246    
2247  /**  /**
2248   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
2249   */   */
# Line 2181  String LSCPServer::ResetSampler() { Line 2279  String LSCPServer::ResetSampler() {
2279   */   */
2280  String LSCPServer::GetServerInfo() {  String LSCPServer::GetServerInfo() {
2281      dmsg(2,("LSCPServer: GetServerInfo()\n"));      dmsg(2,("LSCPServer: GetServerInfo()\n"));
2282        const std::string description =
2283            _escapeLscpResponse("LinuxSampler - modular, streaming capable sampler");
2284      LSCPResultSet result;      LSCPResultSet result;
2285      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");      result.Add("DESCRIPTION", description);
2286      result.Add("VERSION", VERSION);      result.Add("VERSION", VERSION);
2287      result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR));      result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR));
2288    #if HAVE_SQLITE3
2289        result.Add("INSTRUMENTS_DB_SUPPORT", "yes");
2290    #else
2291        result.Add("INSTRUMENTS_DB_SUPPORT", "no");
2292    #endif
2293    
2294      return result.Produce();      return result.Produce();
2295  }  }
2296    
# Line 2252  String LSCPServer::UnsubscribeNotificati Line 2358  String LSCPServer::UnsubscribeNotificati
2358      return result.Produce();      return result.Produce();
2359  }  }
2360    
2361  static int select_callback(void * lscpResultSet, int argc,  String LSCPServer::AddDbInstrumentDirectory(String Dir) {
2362                          char **argv, char **azColName)      dmsg(2,("LSCPServer: AddDbInstrumentDirectory(Dir=%s)\n", Dir.c_str()));
2363  {      LSCPResultSet result;
2364      LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet;  #if HAVE_SQLITE3
2365      resultSet->Add(argc, argv);      try {
2366      return 0;          InstrumentsDb::GetInstrumentsDb()->AddDirectory(Dir);
2367        } catch (Exception e) {
2368             result.Error(e);
2369        }
2370    #else
2371        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2372    #endif
2373        return result.Produce();
2374    }
2375    
2376    String LSCPServer::RemoveDbInstrumentDirectory(String Dir, bool Force) {
2377        dmsg(2,("LSCPServer: RemoveDbInstrumentDirectory(Dir=%s,Force=%d)\n", Dir.c_str(), Force));
2378        LSCPResultSet result;
2379    #if HAVE_SQLITE3
2380        try {
2381            InstrumentsDb::GetInstrumentsDb()->RemoveDirectory(Dir, Force);
2382        } catch (Exception e) {
2383             result.Error(e);
2384        }
2385    #else
2386        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2387    #endif
2388        return result.Produce();
2389    }
2390    
2391    String LSCPServer::GetDbInstrumentDirectoryCount(String Dir, bool Recursive) {
2392        dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2393        LSCPResultSet result;
2394    #if HAVE_SQLITE3
2395        try {
2396            result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir, Recursive));
2397        } catch (Exception e) {
2398             result.Error(e);
2399        }
2400    #else
2401        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2402    #endif
2403        return result.Produce();
2404    }
2405    
2406    String LSCPServer::GetDbInstrumentDirectories(String Dir, bool Recursive) {
2407        dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2408        LSCPResultSet result;
2409    #if HAVE_SQLITE3
2410        try {
2411            String list;
2412            StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir, Recursive);
2413    
2414            for (int i = 0; i < dirs->size(); i++) {
2415                if (list != "") list += ",";
2416                list += "'" + InstrumentsDb::toEscapedPath(dirs->at(i)) + "'";
2417            }
2418    
2419            result.Add(list);
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::GetDbInstrumentDirectoryInfo(String Dir) {
2430        dmsg(2,("LSCPServer: GetDbInstrumentDirectoryInfo(Dir=%s)\n", Dir.c_str()));
2431        LSCPResultSet result;
2432    #if HAVE_SQLITE3
2433        try {
2434            DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir);
2435    
2436            result.Add("DESCRIPTION", _escapeLscpResponse(info.Description));
2437            result.Add("CREATED", info.Created);
2438            result.Add("MODIFIED", info.Modified);
2439        } catch (Exception e) {
2440             result.Error(e);
2441        }
2442    #else
2443        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2444    #endif
2445        return result.Produce();
2446    }
2447    
2448    String LSCPServer::SetDbInstrumentDirectoryName(String Dir, String Name) {
2449        dmsg(2,("LSCPServer: SetDbInstrumentDirectoryName(Dir=%s,Name=%s)\n", Dir.c_str(), Name.c_str()));
2450        LSCPResultSet result;
2451    #if HAVE_SQLITE3
2452        try {
2453            InstrumentsDb::GetInstrumentsDb()->RenameDirectory(Dir, Name);
2454        } catch (Exception e) {
2455             result.Error(e);
2456        }
2457    #else
2458        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2459    #endif
2460        return result.Produce();
2461    }
2462    
2463    String LSCPServer::MoveDbInstrumentDirectory(String Dir, String Dst) {
2464        dmsg(2,("LSCPServer: MoveDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str()));
2465        LSCPResultSet result;
2466    #if HAVE_SQLITE3
2467        try {
2468            InstrumentsDb::GetInstrumentsDb()->MoveDirectory(Dir, Dst);
2469        } catch (Exception e) {
2470             result.Error(e);
2471        }
2472    #else
2473        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2474    #endif
2475        return result.Produce();
2476    }
2477    
2478    String LSCPServer::CopyDbInstrumentDirectory(String Dir, String Dst) {
2479        dmsg(2,("LSCPServer: CopyDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str()));
2480        LSCPResultSet result;
2481    #if HAVE_SQLITE3
2482        try {
2483            InstrumentsDb::GetInstrumentsDb()->CopyDirectory(Dir, Dst);
2484        } catch (Exception e) {
2485             result.Error(e);
2486        }
2487    #else
2488        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2489    #endif
2490        return result.Produce();
2491    }
2492    
2493    String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) {
2494        dmsg(2,("LSCPServer: SetDbInstrumentDirectoryDescription(Dir=%s,Desc=%s)\n", Dir.c_str(), Desc.c_str()));
2495        LSCPResultSet result;
2496    #if HAVE_SQLITE3
2497        try {
2498            InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc);
2499        } catch (Exception e) {
2500             result.Error(e);
2501        }
2502    #else
2503        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2504    #endif
2505        return result.Produce();
2506    }
2507    
2508    String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index, bool bBackground) {
2509        dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d,bBackground=%d)\n", DbDir.c_str(), FilePath.c_str(), Index, bBackground));
2510        LSCPResultSet result;
2511    #if HAVE_SQLITE3
2512        try {
2513            int id;
2514            InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();
2515            id = db->AddInstruments(DbDir, FilePath, Index, bBackground);
2516            if (bBackground) result = id;
2517        } catch (Exception e) {
2518             result.Error(e);
2519        }
2520    #else
2521        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2522    #endif
2523        return result.Produce();
2524    }
2525    
2526    String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) {
2527        dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground));
2528        LSCPResultSet result;
2529    #if HAVE_SQLITE3
2530        try {
2531            int id;
2532            InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();
2533            if (ScanMode.compare("RECURSIVE") == 0) {
2534               id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground);
2535            } else if (ScanMode.compare("NON_RECURSIVE") == 0) {
2536               id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground);
2537            } else if (ScanMode.compare("FLAT") == 0) {
2538               id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground);
2539            } else {
2540                throw Exception("Unknown scan mode: " + ScanMode);
2541            }
2542    
2543            if (bBackground) result = id;
2544        } catch (Exception e) {
2545             result.Error(e);
2546        }
2547    #else
2548        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2549    #endif
2550        return result.Produce();
2551    }
2552    
2553    String LSCPServer::RemoveDbInstrument(String Instr) {
2554        dmsg(2,("LSCPServer: RemoveDbInstrument(Instr=%s)\n", Instr.c_str()));
2555        LSCPResultSet result;
2556    #if HAVE_SQLITE3
2557        try {
2558            InstrumentsDb::GetInstrumentsDb()->RemoveInstrument(Instr);
2559        } catch (Exception e) {
2560             result.Error(e);
2561        }
2562    #else
2563        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2564    #endif
2565        return result.Produce();
2566    }
2567    
2568    String LSCPServer::GetDbInstrumentCount(String Dir, bool Recursive) {
2569        dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2570        LSCPResultSet result;
2571    #if HAVE_SQLITE3
2572        try {
2573            result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir, Recursive));
2574        } catch (Exception e) {
2575             result.Error(e);
2576        }
2577    #else
2578        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2579    #endif
2580        return result.Produce();
2581    }
2582    
2583    String LSCPServer::GetDbInstruments(String Dir, bool Recursive) {
2584        dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2585        LSCPResultSet result;
2586    #if HAVE_SQLITE3
2587        try {
2588            String list;
2589            StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir, Recursive);
2590    
2591            for (int i = 0; i < instrs->size(); i++) {
2592                if (list != "") list += ",";
2593                list += "'" + InstrumentsDb::toEscapedPath(instrs->at(i)) + "'";
2594            }
2595    
2596            result.Add(list);
2597        } catch (Exception e) {
2598             result.Error(e);
2599        }
2600    #else
2601        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2602    #endif
2603        return result.Produce();
2604    }
2605    
2606    String LSCPServer::GetDbInstrumentInfo(String Instr) {
2607        dmsg(2,("LSCPServer: GetDbInstrumentInfo(Instr=%s)\n", Instr.c_str()));
2608        LSCPResultSet result;
2609    #if HAVE_SQLITE3
2610        try {
2611            DbInstrument info = InstrumentsDb::GetInstrumentsDb()->GetInstrumentInfo(Instr);
2612    
2613            result.Add("INSTRUMENT_FILE", info.InstrFile);
2614            result.Add("INSTRUMENT_NR", info.InstrNr);
2615            result.Add("FORMAT_FAMILY", info.FormatFamily);
2616            result.Add("FORMAT_VERSION", info.FormatVersion);
2617            result.Add("SIZE", (int)info.Size);
2618            result.Add("CREATED", info.Created);
2619            result.Add("MODIFIED", info.Modified);
2620            result.Add("DESCRIPTION", _escapeLscpResponse(info.Description));
2621            result.Add("IS_DRUM", info.IsDrum);
2622            result.Add("PRODUCT", _escapeLscpResponse(info.Product));
2623            result.Add("ARTISTS", _escapeLscpResponse(info.Artists));
2624            result.Add("KEYWORDS", _escapeLscpResponse(info.Keywords));
2625        } catch (Exception e) {
2626             result.Error(e);
2627        }
2628    #else
2629        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2630    #endif
2631        return result.Produce();
2632    }
2633    
2634    String LSCPServer::GetDbInstrumentsJobInfo(int JobId) {
2635        dmsg(2,("LSCPServer: GetDbInstrumentsJobInfo(JobId=%d)\n", JobId));
2636        LSCPResultSet result;
2637    #if HAVE_SQLITE3
2638        try {
2639            ScanJob job = InstrumentsDb::GetInstrumentsDb()->Jobs.GetJobById(JobId);
2640    
2641            result.Add("FILES_TOTAL", job.FilesTotal);
2642            result.Add("FILES_SCANNED", job.FilesScanned);
2643            result.Add("SCANNING", job.Scanning);
2644            result.Add("STATUS", job.Status);
2645        } catch (Exception e) {
2646             result.Error(e);
2647        }
2648    #else
2649        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2650    #endif
2651        return result.Produce();
2652    }
2653    
2654    String LSCPServer::SetDbInstrumentName(String Instr, String Name) {
2655        dmsg(2,("LSCPServer: SetDbInstrumentName(Instr=%s,Name=%s)\n", Instr.c_str(), Name.c_str()));
2656        LSCPResultSet result;
2657    #if HAVE_SQLITE3
2658        try {
2659            InstrumentsDb::GetInstrumentsDb()->RenameInstrument(Instr, Name);
2660        } catch (Exception e) {
2661             result.Error(e);
2662        }
2663    #else
2664        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2665    #endif
2666        return result.Produce();
2667    }
2668    
2669    String LSCPServer::MoveDbInstrument(String Instr, String Dst) {
2670        dmsg(2,("LSCPServer: MoveDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str()));
2671        LSCPResultSet result;
2672    #if HAVE_SQLITE3
2673        try {
2674            InstrumentsDb::GetInstrumentsDb()->MoveInstrument(Instr, Dst);
2675        } catch (Exception e) {
2676             result.Error(e);
2677        }
2678    #else
2679        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2680    #endif
2681        return result.Produce();
2682    }
2683    
2684    String LSCPServer::CopyDbInstrument(String Instr, String Dst) {
2685        dmsg(2,("LSCPServer: CopyDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str()));
2686        LSCPResultSet result;
2687    #if HAVE_SQLITE3
2688        try {
2689            InstrumentsDb::GetInstrumentsDb()->CopyInstrument(Instr, Dst);
2690        } catch (Exception e) {
2691             result.Error(e);
2692        }
2693    #else
2694        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2695    #endif
2696        return result.Produce();
2697  }  }
2698    
2699  String LSCPServer::QueryDatabase(String query) {  String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) {
2700        dmsg(2,("LSCPServer: SetDbInstrumentDescription(Instr=%s,Desc=%s)\n", Instr.c_str(), Desc.c_str()));
2701      LSCPResultSet result;      LSCPResultSet result;
2702  #if HAVE_SQLITE3  #if HAVE_SQLITE3
2703      char* zErrMsg = NULL;      try {
2704      sqlite3 *db;          InstrumentsDb::GetInstrumentsDb()->SetInstrumentDescription(Instr, Desc);
2705      String selectStr = "SELECT " + query;      } catch (Exception e) {
2706             result.Error(e);
2707        }
2708    #else
2709        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2710    #endif
2711        return result.Produce();
2712    }
2713    
2714      int rc = sqlite3_open("linuxsampler.db", &db);  String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) {
2715      if (rc == SQLITE_OK)      dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str()));
2716      {      LSCPResultSet result;
2717              rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg);  #if HAVE_SQLITE3
2718        try {
2719            SearchQuery Query;
2720            std::map<String,String>::iterator iter;
2721            for (iter = Parameters.begin(); iter != Parameters.end(); iter++) {
2722                if (iter->first.compare("NAME") == 0) {
2723                    Query.Name = iter->second;
2724                } else if (iter->first.compare("CREATED") == 0) {
2725                    Query.SetCreated(iter->second);
2726                } else if (iter->first.compare("MODIFIED") == 0) {
2727                    Query.SetModified(iter->second);
2728                } else if (iter->first.compare("DESCRIPTION") == 0) {
2729                    Query.Description = iter->second;
2730                } else {
2731                    throw Exception("Unknown search criteria: " + iter->first);
2732                }
2733            }
2734    
2735            String list;
2736            StringListPtr pDirectories =
2737                InstrumentsDb::GetInstrumentsDb()->FindDirectories(Dir, &Query, Recursive);
2738    
2739            for (int i = 0; i < pDirectories->size(); i++) {
2740                if (list != "") list += ",";
2741                list += "'" + InstrumentsDb::toEscapedPath(pDirectories->at(i)) + "'";
2742            }
2743    
2744            result.Add(list);
2745        } catch (Exception e) {
2746             result.Error(e);
2747      }      }
2748      if ( rc != SQLITE_OK )  #else
2749      {      result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2750              result.Error(String(zErrMsg), rc);  #endif
2751        return result.Produce();
2752    }
2753    
2754    String LSCPServer::FindDbInstruments(String Dir, std::map<String,String> Parameters, bool Recursive) {
2755        dmsg(2,("LSCPServer: FindDbInstruments(Dir=%s)\n", Dir.c_str()));
2756        LSCPResultSet result;
2757    #if HAVE_SQLITE3
2758        try {
2759            SearchQuery Query;
2760            std::map<String,String>::iterator iter;
2761            for (iter = Parameters.begin(); iter != Parameters.end(); iter++) {
2762                if (iter->first.compare("NAME") == 0) {
2763                    Query.Name = iter->second;
2764                } else if (iter->first.compare("FORMAT_FAMILIES") == 0) {
2765                    Query.SetFormatFamilies(iter->second);
2766                } else if (iter->first.compare("SIZE") == 0) {
2767                    Query.SetSize(iter->second);
2768                } else if (iter->first.compare("CREATED") == 0) {
2769                    Query.SetCreated(iter->second);
2770                } else if (iter->first.compare("MODIFIED") == 0) {
2771                    Query.SetModified(iter->second);
2772                } else if (iter->first.compare("DESCRIPTION") == 0) {
2773                    Query.Description = iter->second;
2774                } else if (iter->first.compare("IS_DRUM") == 0) {
2775                    if (!strcasecmp(iter->second.c_str(), "true")) {
2776                        Query.InstrType = SearchQuery::DRUM;
2777                    } else {
2778                        Query.InstrType = SearchQuery::CHROMATIC;
2779                    }
2780                } else if (iter->first.compare("PRODUCT") == 0) {
2781                     Query.Product = iter->second;
2782                } else if (iter->first.compare("ARTISTS") == 0) {
2783                     Query.Artists = iter->second;
2784                } else if (iter->first.compare("KEYWORDS") == 0) {
2785                     Query.Keywords = iter->second;
2786                } else {
2787                    throw Exception("Unknown search criteria: " + iter->first);
2788                }
2789            }
2790    
2791            String list;
2792            StringListPtr pInstruments =
2793                InstrumentsDb::GetInstrumentsDb()->FindInstruments(Dir, &Query, Recursive);
2794    
2795            for (int i = 0; i < pInstruments->size(); i++) {
2796                if (list != "") list += ",";
2797                list += "'" + InstrumentsDb::toEscapedPath(pInstruments->at(i)) + "'";
2798            }
2799    
2800            result.Add(list);
2801        } catch (Exception e) {
2802             result.Error(e);
2803      }      }
     sqlite3_close(db);  
2804  #else  #else
2805      result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0);      result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2806  #endif  #endif
2807      return result.Produce();      return result.Produce();
2808  }  }
2809    
2810    String LSCPServer::FormatInstrumentsDb() {
2811        dmsg(2,("LSCPServer: FormatInstrumentsDb()\n"));
2812        LSCPResultSet result;
2813    #if HAVE_SQLITE3
2814        try {
2815            InstrumentsDb::GetInstrumentsDb()->Format();
2816        } catch (Exception e) {
2817             result.Error(e);
2818        }
2819    #else
2820        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2821    #endif
2822        return result.Produce();
2823    }
2824    
2825    
2826  /**  /**
2827   * 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
2828   * mode is enabled, all commands from the client will (immediately) be   * mode is enabled, all commands from the client will (immediately) be

Legend:
Removed from v.1133  
changed lines
  Added in v.1471

  ViewVC Help
Powered by ViewVC