/[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 905 by schoenebeck, Sun Jul 23 16:23:13 2006 UTC revision 1403 by iliev, Fri Oct 12 09:12:22 2007 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005, 2006 Christian Schoenebeck                        *   *   Copyright (C) 2005 - 2007 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This library is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# 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 66  LSCPServer::LSCPServer(Sampler* pSampler Line 102  LSCPServer::LSCPServer(Sampler* pSampler
102      SocketAddress.sin_addr.s_addr = addr;      SocketAddress.sin_addr.s_addr = addr;
103      SocketAddress.sin_port        = port;      SocketAddress.sin_port        = port;
104      this->pSampler = pSampler;      this->pSampler = pSampler;
105        LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_count, "AUDIO_OUTPUT_DEVICE_COUNT");
106        LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_info, "AUDIO_OUTPUT_DEVICE_INFO");
107        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_device_count, "MIDI_INPUT_DEVICE_COUNT");
108        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_device_info, "MIDI_INPUT_DEVICE_INFO");
109      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT");
110      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");
111      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");
112      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");
113      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");
114        LSCPEvent::RegisterEvent(LSCPEvent::event_fx_send_count, "FX_SEND_COUNT");
115        LSCPEvent::RegisterEvent(LSCPEvent::event_fx_send_info, "FX_SEND_INFO");
116        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_count, "MIDI_INSTRUMENT_MAP_COUNT");
117        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO");
118        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT");
119        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");
128      hSocket = -1;      hSocket = -1;
129  }  }
130    
# Line 80  LSCPServer::~LSCPServer() { Line 132  LSCPServer::~LSCPServer() {
132      if (hSocket >= 0) close(hSocket);      if (hSocket >= 0) close(hSocket);
133  }  }
134    
135    void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) {
136        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount));
137    }
138    
139    void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) {
140        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount));
141    }
142    
143    void LSCPServer::EventHandler::MidiDeviceCountChanged(int NewCount) {
144        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount));
145    }
146    
147    void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) {
148        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount));
149    }
150    
151    void LSCPServer::EventHandler::MidiInstrumentInfoChanged(int MapId, int Bank, int Program) {
152        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_info, MapId, Bank, Program));
153    }
154    
155    void LSCPServer::EventHandler::MidiInstrumentMapCountChanged(int NewCount) {
156        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_count, NewCount));
157    }
158    
159    void LSCPServer::EventHandler::MidiInstrumentMapInfoChanged(int MapId) {
160        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_info, MapId));
161    }
162    
163    void LSCPServer::EventHandler::FxSendCountChanged(int ChannelId, int NewCount) {
164        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_count, ChannelId, NewCount));
165    }
166    
167    void LSCPServer::EventHandler::VoiceCountChanged(int ChannelId, int NewCount) {
168        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_voice_count, ChannelId, NewCount));
169    }
170    
171    void LSCPServer::EventHandler::StreamCountChanged(int ChannelId, int NewCount) {
172        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_stream_count, ChannelId, NewCount));
173    }
174    
175    void LSCPServer::EventHandler::BufferFillChanged(int ChannelId, String FillData) {
176        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_buffer_fill, ChannelId, FillData));
177    }
178    
179    void LSCPServer::EventHandler::TotalVoiceCountChanged(int NewCount) {
180        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
220   * accepting socket connections, if the server is already initialized then   * accepting socket connections, if the server is already initialized then
# Line 121  int LSCPServer::Main() { Line 256  int LSCPServer::Main() {
256      listen(hSocket, 1);      listen(hSocket, 1);
257      Initialized.Set(true);      Initialized.Set(true);
258    
259        // Registering event listeners
260        pSampler->AddChannelCountListener(&eventHandler);
261        pSampler->AddAudioDeviceCountListener(&eventHandler);
262        pSampler->AddMidiDeviceCountListener(&eventHandler);
263        pSampler->AddVoiceCountListener(&eventHandler);
264        pSampler->AddStreamCountListener(&eventHandler);
265        pSampler->AddBufferFillListener(&eventHandler);
266        pSampler->AddTotalVoiceCountListener(&eventHandler);
267        pSampler->AddFxSendCountListener(&eventHandler);
268        MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler);
269        MidiInstrumentMapper::AddMidiInstrumentInfoListener(&eventHandler);
270        MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&eventHandler);
271        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 140  int LSCPServer::Main() { Line 291  int LSCPServer::Main() {
291                  if ((*itEngineChannel)->StatusChanged()) {                  if ((*itEngineChannel)->StatusChanged()) {
292                      SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));                      SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));
293                  }                  }
294    
295                    for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {
296                        FxSend* fxs = (*itEngineChannel)->GetFxSend(i);
297                        if(fxs != NULL && fxs->IsInfoChanged()) {
298                            int chn = (*itEngineChannel)->iSamplerChannelIndex;
299                            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id()));
300                            fxs->SetInfoChanged(false);
301                        }
302                    }
303              }              }
304          }          }
305    
# Line 204  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 302  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 322  bool LSCPServer::GetLSCPCommand( std::ve Line 488  bool LSCPServer::GetLSCPCommand( std::ve
488                                  continue; //Ignore CR                                  continue; //Ignore CR
489                          if (c == '\n') {                          if (c == '\n') {
490                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));
491                                  bufferedCommands[socket] += "\n";                                  bufferedCommands[socket] += "\r\n";
492                                  return true; //Complete command was read                                  return true; //Complete command was read
493                          }                          }
494                          bufferedCommands[socket] += c;                          bufferedCommands[socket] += c;
# Line 482  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 496  String LSCPServer::LoadInstrument(String Line 672  String LSCPServer::LoadInstrument(String
672          if (!pSamplerChannel->GetAudioOutputDevice())          if (!pSamplerChannel->GetAudioOutputDevice())
673              throw Exception("No audio output device connected to sampler channel");              throw Exception("No audio output device connected to sampler channel");
674          if (bBackground) {          if (bBackground) {
675              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel);              InstrumentManager::instrument_id_t id;
676                id.FileName = Filename;
677                id.Index    = uiInstrument;
678                InstrumentManager::LoadInstrumentInBackground(id, pEngineChannel);
679          }          }
680          else {          else {
681              // tell the engine channel which instrument to load              // tell the engine channel which instrument to load
# Line 625  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 659  String LSCPServer::GetChannelInfo(uint u Line 838  String LSCPServer::GetChannelInfo(uint u
838          String AudioRouting;          String AudioRouting;
839          int Mute = 0;          int Mute = 0;
840          bool Solo = false;          bool Solo = false;
841            String MidiInstrumentMap = "NONE";
842    
843          if (pEngineChannel) {          if (pEngineChannel) {
844              EngineName          = pEngineChannel->EngineName();              EngineName          = pEngineChannel->EngineName();
# Line 676  String LSCPServer::GetChannelInfo(uint u Line 856  String LSCPServer::GetChannelInfo(uint u
856              }              }
857              Mute = pEngineChannel->GetMute();              Mute = pEngineChannel->GetMute();
858              Solo = pEngineChannel->GetSolo();              Solo = pEngineChannel->GetSolo();
859                if (pEngineChannel->UsesNoMidiInstrumentMap())
860                    MidiInstrumentMap = "NONE";
861                else if (pEngineChannel->UsesDefaultMidiInstrumentMap())
862                    MidiInstrumentMap = "DEFAULT";
863                else
864                    MidiInstrumentMap = ToString(pEngineChannel->GetMidiInstrumentMap());
865          }          }
866    
867          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 691  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          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE",
881                       (InstrumentFileName != "NONE" && InstrumentFileName != "") ?
882                            Path::fromPosix(InstrumentFileName).toLscp() : // TODO: assuming POSIX
883                            InstrumentFileName
884            );
885          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
886          result.Add("INSTRUMENT_NAME", InstrumentName);          result.Add("INSTRUMENT_NAME", _escapeLscpResponse(InstrumentName));
887          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
888          result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));          result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));
889          result.Add("SOLO", Solo);          result.Add("SOLO", Solo);
890            result.Add("MIDI_INSTRUMENT_MAP", MidiInstrumentMap);
891      }      }
892      catch (Exception e) {      catch (Exception e) {
893           result.Error(e);           result.Error(e);
# Line 1174  String LSCPServer::SetAudioOutputChannel Line 1365  String LSCPServer::SetAudioOutputChannel
1365    
1366          // set new channel parameter value          // set new channel parameter value
1367          pParameter->SetValue(ParamVal);          pParameter->SetValue(ParamVal);
1368            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceId));
1369      }      }
1370      catch (Exception e) {      catch (Exception e) {
1371          result.Error(e);          result.Error(e);
# Line 1191  String LSCPServer::SetAudioOutputDeviceP Line 1383  String LSCPServer::SetAudioOutputDeviceP
1383          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1384          if (!parameters.count(ParamKey)) throw Exception("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");          if (!parameters.count(ParamKey)) throw Exception("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
1385          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1386            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceIndex));
1387      }      }
1388      catch (Exception e) {      catch (Exception e) {
1389          result.Error(e);          result.Error(e);
# Line 1208  String LSCPServer::SetMidiInputDevicePar Line 1401  String LSCPServer::SetMidiInputDevicePar
1401          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1402          if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");          if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
1403          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1404            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex));
1405      }      }
1406      catch (Exception e) {      catch (Exception e) {
1407          result.Error(e);          result.Error(e);
# Line 1232  String LSCPServer::SetMidiInputPortParam Line 1426  String LSCPServer::SetMidiInputPortParam
1426          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1427          if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");          if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");
1428          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1429            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex));
1430      }      }
1431      catch (Exception e) {      catch (Exception e) {
1432          result.Error(e);          result.Error(e);
# Line 1479  String LSCPServer::SetChannelSolo(bool b Line 1674  String LSCPServer::SetChannelSolo(bool b
1674    
1675          bool oldSolo = pEngineChannel->GetSolo();          bool oldSolo = pEngineChannel->GetSolo();
1676          bool hadSoloChannel = HasSoloChannel();          bool hadSoloChannel = HasSoloChannel();
1677            
1678          pEngineChannel->SetSolo(bSolo);          pEngineChannel->SetSolo(bSolo);
1679            
1680          if(!oldSolo && bSolo) {          if(!oldSolo && bSolo) {
1681              if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0);              if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0);
1682              if(!hadSoloChannel) MuteNonSoloChannels();              if(!hadSoloChannel) MuteNonSoloChannels();
1683          }          }
1684            
1685          if(oldSolo && !bSolo) {          if(oldSolo && !bSolo) {
1686              if(!HasSoloChannel()) UnmuteChannels();              if(!HasSoloChannel()) UnmuteChannels();
1687              else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1);              else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1);
# Line 1544  void  LSCPServer::UnmuteChannels() { Line 1739  void  LSCPServer::UnmuteChannels() {
1739      }      }
1740  }  }
1741    
1742    String LSCPServer::AddOrReplaceMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg, String EngineType, String InstrumentFile, uint InstrumentIndex, float Volume, MidiInstrumentMapper::mode_t LoadMode, String Name, bool bModal) {
1743        dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n"));
1744    
1745        midi_prog_index_t idx;
1746        idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1747        idx.midi_bank_lsb = MidiBank & 0x7f;
1748        idx.midi_prog     = MidiProg;
1749    
1750        MidiInstrumentMapper::entry_t entry;
1751        entry.EngineName      = EngineType;
1752        entry.InstrumentFile  = InstrumentFile;
1753        entry.InstrumentIndex = InstrumentIndex;
1754        entry.LoadMode        = LoadMode;
1755        entry.Volume          = Volume;
1756        entry.Name            = Name;
1757    
1758        LSCPResultSet result;
1759        try {
1760            // PERSISTENT mapping commands might block for a long time, so in
1761            // that case we add/replace the mapping in another thread in case
1762            // the NON_MODAL argument was supplied, non persistent mappings
1763            // should return immediately, so we don't need to do that for them
1764            bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT && !bModal);
1765            MidiInstrumentMapper::AddOrReplaceEntry(MidiMapID, idx, entry, bInBackground);
1766        } catch (Exception e) {
1767            result.Error(e);
1768        }
1769        return result.Produce();
1770    }
1771    
1772    String LSCPServer::RemoveMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) {
1773        dmsg(2,("LSCPServer: RemoveMIDIInstrumentMapping()\n"));
1774    
1775        midi_prog_index_t idx;
1776        idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1777        idx.midi_bank_lsb = MidiBank & 0x7f;
1778        idx.midi_prog     = MidiProg;
1779    
1780        LSCPResultSet result;
1781        try {
1782            MidiInstrumentMapper::RemoveEntry(MidiMapID, idx);
1783        } catch (Exception e) {
1784            result.Error(e);
1785        }
1786        return result.Produce();
1787    }
1788    
1789    String LSCPServer::GetMidiInstrumentMappings(uint MidiMapID) {
1790        dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n"));
1791        LSCPResultSet result;
1792        try {
1793            result.Add(MidiInstrumentMapper::Entries(MidiMapID).size());
1794        } catch (Exception e) {
1795            result.Error(e);
1796        }
1797        return result.Produce();
1798    }
1799    
1800    
1801    String LSCPServer::GetAllMidiInstrumentMappings() {
1802        dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n"));
1803        LSCPResultSet result;
1804        std::vector<int> maps = MidiInstrumentMapper::Maps();
1805        int totalMappings = 0;
1806        for (int i = 0; i < maps.size(); i++) {
1807            try {
1808                totalMappings += MidiInstrumentMapper::Entries(maps[i]).size();
1809            } catch (Exception e) { /*NOOP*/ }
1810        }
1811        result.Add(totalMappings);
1812        return result.Produce();
1813    }
1814    
1815    String LSCPServer::GetMidiInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) {
1816        dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n"));
1817        LSCPResultSet result;
1818        try {
1819            midi_prog_index_t idx;
1820            idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1821            idx.midi_bank_lsb = MidiBank & 0x7f;
1822            idx.midi_prog     = MidiProg;
1823    
1824            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID);
1825            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx);
1826            if (iter == mappings.end()) result.Error("there is no map entry with that index");
1827            else { // found
1828                result.Add("NAME", _escapeLscpResponse(iter->second.Name));
1829                result.Add("ENGINE_NAME", iter->second.EngineName);
1830                result.Add("INSTRUMENT_FILE", Path::fromPosix(iter->second.InstrumentFile).toLscp()); //TODO: assuming POSIX
1831                result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex);
1832                String instrumentName;
1833                Engine* pEngine = EngineFactory::Create(iter->second.EngineName);
1834                if (pEngine) {
1835                    if (pEngine->GetInstrumentManager()) {
1836                        InstrumentManager::instrument_id_t instrID;
1837                        instrID.FileName = iter->second.InstrumentFile;
1838                        instrID.Index    = iter->second.InstrumentIndex;
1839                        instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID);
1840                    }
1841                    EngineFactory::Destroy(pEngine);
1842                }
1843                result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName));
1844                switch (iter->second.LoadMode) {
1845                    case MidiInstrumentMapper::ON_DEMAND:
1846                        result.Add("LOAD_MODE", "ON_DEMAND");
1847                        break;
1848                    case MidiInstrumentMapper::ON_DEMAND_HOLD:
1849                        result.Add("LOAD_MODE", "ON_DEMAND_HOLD");
1850                        break;
1851                    case MidiInstrumentMapper::PERSISTENT:
1852                        result.Add("LOAD_MODE", "PERSISTENT");
1853                        break;
1854                    default:
1855                        throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!");
1856                }
1857                result.Add("VOLUME", iter->second.Volume);
1858            }
1859        } catch (Exception e) {
1860            result.Error(e);
1861        }
1862        return result.Produce();
1863    }
1864    
1865    String LSCPServer::ListMidiInstrumentMappings(uint MidiMapID) {
1866        dmsg(2,("LSCPServer: ListMidiInstrumentMappings()\n"));
1867        LSCPResultSet result;
1868        try {
1869            String s;
1870            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID);
1871            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();
1872            for (; iter != mappings.end(); iter++) {
1873                if (s.size()) s += ",";
1874                s += "{" + ToString(MidiMapID) + ","
1875                         + ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + ","
1876                         + ToString(int(iter->first.midi_prog)) + "}";
1877            }
1878            result.Add(s);
1879        } catch (Exception e) {
1880            result.Error(e);
1881        }
1882        return result.Produce();
1883    }
1884    
1885    String LSCPServer::ListAllMidiInstrumentMappings() {
1886        dmsg(2,("LSCPServer: ListAllMidiInstrumentMappings()\n"));
1887        LSCPResultSet result;
1888        try {
1889            std::vector<int> maps = MidiInstrumentMapper::Maps();
1890            String s;
1891            for (int i = 0; i < maps.size(); i++) {
1892                std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(maps[i]);
1893                std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();
1894                for (; iter != mappings.end(); iter++) {
1895                    if (s.size()) s += ",";
1896                    s += "{" + ToString(maps[i]) + ","
1897                             + ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + ","
1898                             + ToString(int(iter->first.midi_prog)) + "}";
1899                }
1900            }
1901            result.Add(s);
1902        } catch (Exception e) {
1903            result.Error(e);
1904        }
1905        return result.Produce();
1906    }
1907    
1908    String LSCPServer::ClearMidiInstrumentMappings(uint MidiMapID) {
1909        dmsg(2,("LSCPServer: ClearMidiInstrumentMappings()\n"));
1910        LSCPResultSet result;
1911        try {
1912            MidiInstrumentMapper::RemoveAllEntries(MidiMapID);
1913        } catch (Exception e) {
1914            result.Error(e);
1915        }
1916        return result.Produce();
1917    }
1918    
1919    String LSCPServer::ClearAllMidiInstrumentMappings() {
1920        dmsg(2,("LSCPServer: ClearAllMidiInstrumentMappings()\n"));
1921        LSCPResultSet result;
1922        try {
1923            std::vector<int> maps = MidiInstrumentMapper::Maps();
1924            for (int i = 0; i < maps.size(); i++)
1925                MidiInstrumentMapper::RemoveAllEntries(maps[i]);
1926        } catch (Exception e) {
1927            result.Error(e);
1928        }
1929        return result.Produce();
1930    }
1931    
1932    String LSCPServer::AddMidiInstrumentMap(String MapName) {
1933        dmsg(2,("LSCPServer: AddMidiInstrumentMap()\n"));
1934        LSCPResultSet result;
1935        try {
1936            int MapID = MidiInstrumentMapper::AddMap(MapName);
1937            result = LSCPResultSet(MapID);
1938        } catch (Exception e) {
1939            result.Error(e);
1940        }
1941        return result.Produce();
1942    }
1943    
1944    String LSCPServer::RemoveMidiInstrumentMap(uint MidiMapID) {
1945        dmsg(2,("LSCPServer: RemoveMidiInstrumentMap()\n"));
1946        LSCPResultSet result;
1947        try {
1948            MidiInstrumentMapper::RemoveMap(MidiMapID);
1949        } catch (Exception e) {
1950            result.Error(e);
1951        }
1952        return result.Produce();
1953    }
1954    
1955    String LSCPServer::RemoveAllMidiInstrumentMaps() {
1956        dmsg(2,("LSCPServer: RemoveAllMidiInstrumentMaps()\n"));
1957        LSCPResultSet result;
1958        try {
1959            MidiInstrumentMapper::RemoveAllMaps();
1960        } catch (Exception e) {
1961            result.Error(e);
1962        }
1963        return result.Produce();
1964    }
1965    
1966    String LSCPServer::GetMidiInstrumentMaps() {
1967        dmsg(2,("LSCPServer: GetMidiInstrumentMaps()\n"));
1968        LSCPResultSet result;
1969        try {
1970            result.Add(MidiInstrumentMapper::Maps().size());
1971        } catch (Exception e) {
1972            result.Error(e);
1973        }
1974        return result.Produce();
1975    }
1976    
1977    String LSCPServer::ListMidiInstrumentMaps() {
1978        dmsg(2,("LSCPServer: ListMidiInstrumentMaps()\n"));
1979        LSCPResultSet result;
1980        try {
1981            std::vector<int> maps = MidiInstrumentMapper::Maps();
1982            String sList;
1983            for (int i = 0; i < maps.size(); i++) {
1984                if (sList != "") sList += ",";
1985                sList += ToString(maps[i]);
1986            }
1987            result.Add(sList);
1988        } catch (Exception e) {
1989            result.Error(e);
1990        }
1991        return result.Produce();
1992    }
1993    
1994    String LSCPServer::GetMidiInstrumentMap(uint MidiMapID) {
1995        dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n"));
1996        LSCPResultSet result;
1997        try {
1998            result.Add("NAME", _escapeLscpResponse(MidiInstrumentMapper::MapName(MidiMapID)));
1999            result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID);
2000        } catch (Exception e) {
2001            result.Error(e);
2002        }
2003        return result.Produce();
2004    }
2005    
2006    String LSCPServer::SetMidiInstrumentMapName(uint MidiMapID, String NewName) {
2007        dmsg(2,("LSCPServer: SetMidiInstrumentMapName()\n"));
2008        LSCPResultSet result;
2009        try {
2010            MidiInstrumentMapper::RenameMap(MidiMapID, NewName);
2011        } catch (Exception e) {
2012            result.Error(e);
2013        }
2014        return result.Produce();
2015    }
2016    
2017    /**
2018     * Set the MIDI instrument map the given sampler channel shall use for
2019     * handling MIDI program change messages. There are the following two
2020     * special (negative) values:
2021     *
2022     *    - (-1) :  set to NONE (ignore program changes)
2023     *    - (-2) :  set to DEFAULT map
2024     */
2025    String LSCPServer::SetChannelMap(uint uiSamplerChannel, int MidiMapID) {
2026        dmsg(2,("LSCPServer: SetChannelMap()\n"));
2027        LSCPResultSet result;
2028        try {
2029            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2030            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2031    
2032            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2033            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
2034    
2035            if      (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone();
2036            else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault();
2037            else                      pEngineChannel->SetMidiInstrumentMap(MidiMapID);
2038        } catch (Exception e) {
2039            result.Error(e);
2040        }
2041        return result.Produce();
2042    }
2043    
2044    String LSCPServer::CreateFxSend(uint uiSamplerChannel, uint MidiCtrl, String Name) {
2045        dmsg(2,("LSCPServer: CreateFxSend()\n"));
2046        LSCPResultSet result;
2047        try {
2048            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2049    
2050            FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name);
2051            if (!pFxSend) throw Exception("Could not add FxSend, don't ask, I don't know why (probably a bug)");
2052    
2053            result = LSCPResultSet(pFxSend->Id()); // success
2054        } catch (Exception e) {
2055            result.Error(e);
2056        }
2057        return result.Produce();
2058    }
2059    
2060    String LSCPServer::DestroyFxSend(uint uiSamplerChannel, uint FxSendID) {
2061        dmsg(2,("LSCPServer: DestroyFxSend()\n"));
2062        LSCPResultSet result;
2063        try {
2064            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2065    
2066            FxSend* pFxSend = NULL;
2067            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2068                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2069                    pFxSend = pEngineChannel->GetFxSend(i);
2070                    break;
2071                }
2072            }
2073            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2074            pEngineChannel->RemoveFxSend(pFxSend);
2075        } catch (Exception e) {
2076            result.Error(e);
2077        }
2078        return result.Produce();
2079    }
2080    
2081    String LSCPServer::GetFxSends(uint uiSamplerChannel) {
2082        dmsg(2,("LSCPServer: GetFxSends()\n"));
2083        LSCPResultSet result;
2084        try {
2085            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2086    
2087            result.Add(pEngineChannel->GetFxSendCount());
2088        } catch (Exception e) {
2089            result.Error(e);
2090        }
2091        return result.Produce();
2092    }
2093    
2094    String LSCPServer::ListFxSends(uint uiSamplerChannel) {
2095        dmsg(2,("LSCPServer: ListFxSends()\n"));
2096        LSCPResultSet result;
2097        String list;
2098        try {
2099            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2100    
2101            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2102                FxSend* pFxSend = pEngineChannel->GetFxSend(i);
2103                if (list != "") list += ",";
2104                list += ToString(pFxSend->Id());
2105            }
2106            result.Add(list);
2107        } catch (Exception e) {
2108            result.Error(e);
2109        }
2110        return result.Produce();
2111    }
2112    
2113    FxSend* LSCPServer::GetFxSend(uint uiSamplerChannel, uint FxSendID) {
2114        EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2115    
2116        FxSend* pFxSend = NULL;
2117        for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2118            if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2119                pFxSend = pEngineChannel->GetFxSend(i);
2120                break;
2121            }
2122        }
2123        if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2124        return pFxSend;
2125    }
2126    
2127    String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) {
2128        dmsg(2,("LSCPServer: GetFxSendInfo()\n"));
2129        LSCPResultSet result;
2130        try {
2131            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2132            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2133    
2134            // gather audio routing informations
2135            String AudioRouting;
2136            for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
2137                if (AudioRouting != "") AudioRouting += ",";
2138                AudioRouting += ToString(pFxSend->DestinationChannel(chan));
2139            }
2140    
2141            // success
2142            result.Add("NAME", _escapeLscpResponse(pFxSend->Name()));
2143            result.Add("MIDI_CONTROLLER", pFxSend->MidiController());
2144            result.Add("LEVEL", ToString(pFxSend->Level()));
2145            result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
2146        } catch (Exception e) {
2147            result.Error(e);
2148        }
2149        return result.Produce();
2150    }
2151    
2152    String LSCPServer::SetFxSendName(uint uiSamplerChannel, uint FxSendID, String Name) {
2153        dmsg(2,("LSCPServer: SetFxSendName()\n"));
2154        LSCPResultSet result;
2155        try {
2156            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2157    
2158            pFxSend->SetName(Name);
2159            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2160        } catch (Exception e) {
2161            result.Error(e);
2162        }
2163        return result.Produce();
2164    }
2165    
2166    String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) {
2167        dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n"));
2168        LSCPResultSet result;
2169        try {
2170            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2171    
2172            pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel);
2173            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2174        } catch (Exception e) {
2175            result.Error(e);
2176        }
2177        return result.Produce();
2178    }
2179    
2180    String LSCPServer::SetFxSendMidiController(uint uiSamplerChannel, uint FxSendID, uint MidiController) {
2181        dmsg(2,("LSCPServer: SetFxSendMidiController()\n"));
2182        LSCPResultSet result;
2183        try {
2184            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2185    
2186            pFxSend->SetMidiController(MidiController);
2187            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2188        } catch (Exception e) {
2189            result.Error(e);
2190        }
2191        return result.Produce();
2192    }
2193    
2194    String LSCPServer::SetFxSendLevel(uint uiSamplerChannel, uint FxSendID, double dLevel) {
2195        dmsg(2,("LSCPServer: SetFxSendLevel()\n"));
2196        LSCPResultSet result;
2197        try {
2198            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2199    
2200            pFxSend->SetLevel((float)dLevel);
2201            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2202        } catch (Exception e) {
2203            result.Error(e);
2204        }
2205        return result.Produce();
2206    }
2207    
2208    String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) {
2209        dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel));
2210        LSCPResultSet result;
2211        try {
2212            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2213            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2214            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2215            if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
2216            if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel");
2217            Engine* pEngine = pEngineChannel->GetEngine();
2218            InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager();
2219            if (!pInstrumentManager) throw Exception("Engine does not provide an instrument manager");
2220            InstrumentManager::instrument_id_t instrumentID;
2221            instrumentID.FileName = pEngineChannel->InstrumentFileName();
2222            instrumentID.Index    = pEngineChannel->InstrumentIndex();
2223            pInstrumentManager->LaunchInstrumentEditor(instrumentID);
2224        } catch (Exception e) {
2225            result.Error(e);
2226        }
2227        return result.Produce();
2228    }
2229    
2230  /**  /**
2231   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
2232   */   */
# Line 1579  String LSCPServer::ResetSampler() { Line 2262  String LSCPServer::ResetSampler() {
2262   */   */
2263  String LSCPServer::GetServerInfo() {  String LSCPServer::GetServerInfo() {
2264      dmsg(2,("LSCPServer: GetServerInfo()\n"));      dmsg(2,("LSCPServer: GetServerInfo()\n"));
2265        const std::string description =
2266            _escapeLscpResponse("LinuxSampler - modular, streaming capable sampler");
2267      LSCPResultSet result;      LSCPResultSet result;
2268      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");      result.Add("DESCRIPTION", description);
2269      result.Add("VERSION", VERSION);      result.Add("VERSION", VERSION);
2270      result.Add("PROTOCOL_VERSION", "1.0");      result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR));
2271    #if HAVE_SQLITE3
2272        result.Add("INSTRUMENTS_DB_SUPPORT", "yes");
2273    #else
2274        result.Add("INSTRUMENTS_DB_SUPPORT", "no");
2275    #endif
2276    
2277      return result.Produce();      return result.Produce();
2278  }  }
2279    
# Line 1606  String LSCPServer::GetTotalVoiceCountMax Line 2297  String LSCPServer::GetTotalVoiceCountMax
2297      return result.Produce();      return result.Produce();
2298  }  }
2299    
2300    String LSCPServer::GetGlobalVolume() {
2301        LSCPResultSet result;
2302        result.Add(ToString(GLOBAL_VOLUME)); // see common/global.cpp
2303        return result.Produce();
2304    }
2305    
2306    String LSCPServer::SetGlobalVolume(double dVolume) {
2307        LSCPResultSet result;
2308        try {
2309            if (dVolume < 0) throw Exception("Volume may not be negative");
2310            GLOBAL_VOLUME = dVolume; // see common/global.cpp
2311            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME));
2312        } catch (Exception e) {
2313            result.Error(e);
2314        }
2315        return result.Produce();
2316    }
2317    
2318  /**  /**
2319   * Will be called by the parser to subscribe a client (frontend) on the   * Will be called by the parser to subscribe a client (frontend) on the
2320   * server for receiving event messages.   * server for receiving event messages.
# Line 1632  String LSCPServer::UnsubscribeNotificati Line 2341  String LSCPServer::UnsubscribeNotificati
2341      return result.Produce();      return result.Produce();
2342  }  }
2343    
2344  static int select_callback(void * lscpResultSet, int argc,  String LSCPServer::AddDbInstrumentDirectory(String Dir) {
2345                          char **argv, char **azColName)      dmsg(2,("LSCPServer: AddDbInstrumentDirectory(Dir=%s)\n", Dir.c_str()));
2346  {      LSCPResultSet result;
2347      LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet;  #if HAVE_SQLITE3
2348      resultSet->Add(argc, argv);      try {
2349      return 0;          InstrumentsDb::GetInstrumentsDb()->AddDirectory(Dir);
2350        } catch (Exception e) {
2351             result.Error(e);
2352        }
2353    #else
2354        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2355    #endif
2356        return result.Produce();
2357  }  }
2358    
2359  String LSCPServer::QueryDatabase(String query) {  String LSCPServer::RemoveDbInstrumentDirectory(String Dir, bool Force) {
2360        dmsg(2,("LSCPServer: RemoveDbInstrumentDirectory(Dir=%s,Force=%d)\n", Dir.c_str(), Force));
2361      LSCPResultSet result;      LSCPResultSet result;
2362  #if HAVE_SQLITE3  #if HAVE_SQLITE3
2363      char* zErrMsg = NULL;      try {
2364      sqlite3 *db;          InstrumentsDb::GetInstrumentsDb()->RemoveDirectory(Dir, Force);
2365      String selectStr = "SELECT " + query;      } catch (Exception e) {
2366             result.Error(e);
2367        }
2368    #else
2369        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2370    #endif
2371        return result.Produce();
2372    }
2373    
2374      int rc = sqlite3_open("linuxsampler.db", &db);  String LSCPServer::GetDbInstrumentDirectoryCount(String Dir, bool Recursive) {
2375      if (rc == SQLITE_OK)      dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2376      {      LSCPResultSet result;
2377              rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg);  #if HAVE_SQLITE3
2378        try {
2379            result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir, Recursive));
2380        } catch (Exception e) {
2381             result.Error(e);
2382      }      }
2383      if ( rc != SQLITE_OK )  #else
2384      {      result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2385              result.Error(String(zErrMsg), rc);  #endif
2386        return result.Produce();
2387    }
2388    
2389    String LSCPServer::GetDbInstrumentDirectories(String Dir, bool Recursive) {
2390        dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2391        LSCPResultSet result;
2392    #if HAVE_SQLITE3
2393        try {
2394            String list;
2395            StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir, Recursive);
2396    
2397            for (int i = 0; i < dirs->size(); i++) {
2398                if (list != "") list += ",";
2399                list += "'" + InstrumentsDb::toEscapedPath(dirs->at(i)) + "'";
2400            }
2401    
2402            result.Add(list);
2403        } catch (Exception e) {
2404             result.Error(e);
2405      }      }
     sqlite3_close(db);  
2406  #else  #else
2407      result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0);      result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2408  #endif  #endif
2409      return result.Produce();      return result.Produce();
2410  }  }
2411    
2412    String LSCPServer::GetDbInstrumentDirectoryInfo(String Dir) {
2413        dmsg(2,("LSCPServer: GetDbInstrumentDirectoryInfo(Dir=%s)\n", Dir.c_str()));
2414        LSCPResultSet result;
2415    #if HAVE_SQLITE3
2416        try {
2417            DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir);
2418    
2419            result.Add("DESCRIPTION", _escapeLscpResponse(info.Description));
2420            result.Add("CREATED", info.Created);
2421            result.Add("MODIFIED", info.Modified);
2422        } catch (Exception e) {
2423             result.Error(e);
2424        }
2425    #else
2426        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2427    #endif
2428        return result.Produce();
2429    }
2430    
2431    String LSCPServer::SetDbInstrumentDirectoryName(String Dir, String Name) {
2432        dmsg(2,("LSCPServer: SetDbInstrumentDirectoryName(Dir=%s,Name=%s)\n", Dir.c_str(), Name.c_str()));
2433        LSCPResultSet result;
2434    #if HAVE_SQLITE3
2435        try {
2436            InstrumentsDb::GetInstrumentsDb()->RenameDirectory(Dir, Name);
2437        } catch (Exception e) {
2438             result.Error(e);
2439        }
2440    #else
2441        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2442    #endif
2443        return result.Produce();
2444    }
2445    
2446    String LSCPServer::MoveDbInstrumentDirectory(String Dir, String Dst) {
2447        dmsg(2,("LSCPServer: MoveDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str()));
2448        LSCPResultSet result;
2449    #if HAVE_SQLITE3
2450        try {
2451            InstrumentsDb::GetInstrumentsDb()->MoveDirectory(Dir, Dst);
2452        } catch (Exception e) {
2453             result.Error(e);
2454        }
2455    #else
2456        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2457    #endif
2458        return result.Produce();
2459    }
2460    
2461    String LSCPServer::CopyDbInstrumentDirectory(String Dir, String Dst) {
2462        dmsg(2,("LSCPServer: CopyDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str()));
2463        LSCPResultSet result;
2464    #if HAVE_SQLITE3
2465        try {
2466            InstrumentsDb::GetInstrumentsDb()->CopyDirectory(Dir, Dst);
2467        } catch (Exception e) {
2468             result.Error(e);
2469        }
2470    #else
2471        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2472    #endif
2473        return result.Produce();
2474    }
2475    
2476    String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) {
2477        dmsg(2,("LSCPServer: SetDbInstrumentDirectoryDescription(Dir=%s,Desc=%s)\n", Dir.c_str(), Desc.c_str()));
2478        LSCPResultSet result;
2479    #if HAVE_SQLITE3
2480        try {
2481            InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc);
2482        } catch (Exception e) {
2483             result.Error(e);
2484        }
2485    #else
2486        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2487    #endif
2488        return result.Produce();
2489    }
2490    
2491    String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index, bool bBackground) {
2492        dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d,bBackground=%d)\n", DbDir.c_str(), FilePath.c_str(), Index, bBackground));
2493        LSCPResultSet result;
2494    #if HAVE_SQLITE3
2495        try {
2496            int id;
2497            InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();
2498            id = db->AddInstruments(DbDir, FilePath, Index, bBackground);
2499            if (bBackground) result = id;
2500        } catch (Exception e) {
2501             result.Error(e);
2502        }
2503    #else
2504        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2505    #endif
2506        return result.Produce();
2507    }
2508    
2509    String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) {
2510        dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground));
2511        LSCPResultSet result;
2512    #if HAVE_SQLITE3
2513        try {
2514            int id;
2515            InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();
2516            if (ScanMode.compare("RECURSIVE") == 0) {
2517               id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground);
2518            } else if (ScanMode.compare("NON_RECURSIVE") == 0) {
2519               id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground);
2520            } else if (ScanMode.compare("FLAT") == 0) {
2521               id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground);
2522            } else {
2523                throw Exception("Unknown scan mode: " + ScanMode);
2524            }
2525    
2526            if (bBackground) result = id;
2527        } catch (Exception e) {
2528             result.Error(e);
2529        }
2530    #else
2531        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2532    #endif
2533        return result.Produce();
2534    }
2535    
2536    String LSCPServer::RemoveDbInstrument(String Instr) {
2537        dmsg(2,("LSCPServer: RemoveDbInstrument(Instr=%s)\n", Instr.c_str()));
2538        LSCPResultSet result;
2539    #if HAVE_SQLITE3
2540        try {
2541            InstrumentsDb::GetInstrumentsDb()->RemoveInstrument(Instr);
2542        } catch (Exception e) {
2543             result.Error(e);
2544        }
2545    #else
2546        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2547    #endif
2548        return result.Produce();
2549    }
2550    
2551    String LSCPServer::GetDbInstrumentCount(String Dir, bool Recursive) {
2552        dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2553        LSCPResultSet result;
2554    #if HAVE_SQLITE3
2555        try {
2556            result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir, Recursive));
2557        } catch (Exception e) {
2558             result.Error(e);
2559        }
2560    #else
2561        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2562    #endif
2563        return result.Produce();
2564    }
2565    
2566    String LSCPServer::GetDbInstruments(String Dir, bool Recursive) {
2567        dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2568        LSCPResultSet result;
2569    #if HAVE_SQLITE3
2570        try {
2571            String list;
2572            StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir, Recursive);
2573    
2574            for (int i = 0; i < instrs->size(); i++) {
2575                if (list != "") list += ",";
2576                list += "'" + InstrumentsDb::toEscapedPath(instrs->at(i)) + "'";
2577            }
2578    
2579            result.Add(list);
2580        } catch (Exception e) {
2581             result.Error(e);
2582        }
2583    #else
2584        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2585    #endif
2586        return result.Produce();
2587    }
2588    
2589    String LSCPServer::GetDbInstrumentInfo(String Instr) {
2590        dmsg(2,("LSCPServer: GetDbInstrumentInfo(Instr=%s)\n", Instr.c_str()));
2591        LSCPResultSet result;
2592    #if HAVE_SQLITE3
2593        try {
2594            DbInstrument info = InstrumentsDb::GetInstrumentsDb()->GetInstrumentInfo(Instr);
2595    
2596            result.Add("INSTRUMENT_FILE", info.InstrFile);
2597            result.Add("INSTRUMENT_NR", info.InstrNr);
2598            result.Add("FORMAT_FAMILY", info.FormatFamily);
2599            result.Add("FORMAT_VERSION", info.FormatVersion);
2600            result.Add("SIZE", (int)info.Size);
2601            result.Add("CREATED", info.Created);
2602            result.Add("MODIFIED", info.Modified);
2603            result.Add("DESCRIPTION", _escapeLscpResponse(info.Description));
2604            result.Add("IS_DRUM", info.IsDrum);
2605            result.Add("PRODUCT", _escapeLscpResponse(info.Product));
2606            result.Add("ARTISTS", _escapeLscpResponse(info.Artists));
2607            result.Add("KEYWORDS", _escapeLscpResponse(info.Keywords));
2608        } catch (Exception e) {
2609             result.Error(e);
2610        }
2611    #else
2612        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2613    #endif
2614        return result.Produce();
2615    }
2616    
2617    String LSCPServer::GetDbInstrumentsJobInfo(int JobId) {
2618        dmsg(2,("LSCPServer: GetDbInstrumentsJobInfo(JobId=%d)\n", JobId));
2619        LSCPResultSet result;
2620    #if HAVE_SQLITE3
2621        try {
2622            ScanJob job = InstrumentsDb::GetInstrumentsDb()->Jobs.GetJobById(JobId);
2623    
2624            result.Add("FILES_TOTAL", job.FilesTotal);
2625            result.Add("FILES_SCANNED", job.FilesScanned);
2626            result.Add("SCANNING", job.Scanning);
2627            result.Add("STATUS", job.Status);
2628        } catch (Exception e) {
2629             result.Error(e);
2630        }
2631    #else
2632        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2633    #endif
2634        return result.Produce();
2635    }
2636    
2637    String LSCPServer::SetDbInstrumentName(String Instr, String Name) {
2638        dmsg(2,("LSCPServer: SetDbInstrumentName(Instr=%s,Name=%s)\n", Instr.c_str(), Name.c_str()));
2639        LSCPResultSet result;
2640    #if HAVE_SQLITE3
2641        try {
2642            InstrumentsDb::GetInstrumentsDb()->RenameInstrument(Instr, Name);
2643        } catch (Exception e) {
2644             result.Error(e);
2645        }
2646    #else
2647        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2648    #endif
2649        return result.Produce();
2650    }
2651    
2652    String LSCPServer::MoveDbInstrument(String Instr, String Dst) {
2653        dmsg(2,("LSCPServer: MoveDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str()));
2654        LSCPResultSet result;
2655    #if HAVE_SQLITE3
2656        try {
2657            InstrumentsDb::GetInstrumentsDb()->MoveInstrument(Instr, Dst);
2658        } catch (Exception e) {
2659             result.Error(e);
2660        }
2661    #else
2662        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2663    #endif
2664        return result.Produce();
2665    }
2666    
2667    String LSCPServer::CopyDbInstrument(String Instr, String Dst) {
2668        dmsg(2,("LSCPServer: CopyDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str()));
2669        LSCPResultSet result;
2670    #if HAVE_SQLITE3
2671        try {
2672            InstrumentsDb::GetInstrumentsDb()->CopyInstrument(Instr, Dst);
2673        } catch (Exception e) {
2674             result.Error(e);
2675        }
2676    #else
2677        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2678    #endif
2679        return result.Produce();
2680    }
2681    
2682    String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) {
2683        dmsg(2,("LSCPServer: SetDbInstrumentDescription(Instr=%s,Desc=%s)\n", Instr.c_str(), Desc.c_str()));
2684        LSCPResultSet result;
2685    #if HAVE_SQLITE3
2686        try {
2687            InstrumentsDb::GetInstrumentsDb()->SetInstrumentDescription(Instr, Desc);
2688        } catch (Exception e) {
2689             result.Error(e);
2690        }
2691    #else
2692        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2693    #endif
2694        return result.Produce();
2695    }
2696    
2697    String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) {
2698        dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str()));
2699        LSCPResultSet result;
2700    #if HAVE_SQLITE3
2701        try {
2702            SearchQuery Query;
2703            std::map<String,String>::iterator iter;
2704            for (iter = Parameters.begin(); iter != Parameters.end(); iter++) {
2705                if (iter->first.compare("NAME") == 0) {
2706                    Query.Name = iter->second;
2707                } else if (iter->first.compare("CREATED") == 0) {
2708                    Query.SetCreated(iter->second);
2709                } else if (iter->first.compare("MODIFIED") == 0) {
2710                    Query.SetModified(iter->second);
2711                } else if (iter->first.compare("DESCRIPTION") == 0) {
2712                    Query.Description = iter->second;
2713                } else {
2714                    throw Exception("Unknown search criteria: " + iter->first);
2715                }
2716            }
2717    
2718            String list;
2719            StringListPtr pDirectories =
2720                InstrumentsDb::GetInstrumentsDb()->FindDirectories(Dir, &Query, Recursive);
2721    
2722            for (int i = 0; i < pDirectories->size(); i++) {
2723                if (list != "") list += ",";
2724                list += "'" + InstrumentsDb::toEscapedPath(pDirectories->at(i)) + "'";
2725            }
2726    
2727            result.Add(list);
2728        } catch (Exception e) {
2729             result.Error(e);
2730        }
2731    #else
2732        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2733    #endif
2734        return result.Produce();
2735    }
2736    
2737    String LSCPServer::FindDbInstruments(String Dir, std::map<String,String> Parameters, bool Recursive) {
2738        dmsg(2,("LSCPServer: FindDbInstruments(Dir=%s)\n", Dir.c_str()));
2739        LSCPResultSet result;
2740    #if HAVE_SQLITE3
2741        try {
2742            SearchQuery Query;
2743            std::map<String,String>::iterator iter;
2744            for (iter = Parameters.begin(); iter != Parameters.end(); iter++) {
2745                if (iter->first.compare("NAME") == 0) {
2746                    Query.Name = iter->second;
2747                } else if (iter->first.compare("FORMAT_FAMILIES") == 0) {
2748                    Query.SetFormatFamilies(iter->second);
2749                } else if (iter->first.compare("SIZE") == 0) {
2750                    Query.SetSize(iter->second);
2751                } else if (iter->first.compare("CREATED") == 0) {
2752                    Query.SetCreated(iter->second);
2753                } else if (iter->first.compare("MODIFIED") == 0) {
2754                    Query.SetModified(iter->second);
2755                } else if (iter->first.compare("DESCRIPTION") == 0) {
2756                    Query.Description = iter->second;
2757                } else if (iter->first.compare("IS_DRUM") == 0) {
2758                    if (!strcasecmp(iter->second.c_str(), "true")) {
2759                        Query.InstrType = SearchQuery::DRUM;
2760                    } else {
2761                        Query.InstrType = SearchQuery::CHROMATIC;
2762                    }
2763                } else if (iter->first.compare("PRODUCT") == 0) {
2764                     Query.Product = iter->second;
2765                } else if (iter->first.compare("ARTISTS") == 0) {
2766                     Query.Artists = iter->second;
2767                } else if (iter->first.compare("KEYWORDS") == 0) {
2768                     Query.Keywords = iter->second;
2769                } else {
2770                    throw Exception("Unknown search criteria: " + iter->first);
2771                }
2772            }
2773    
2774            String list;
2775            StringListPtr pInstruments =
2776                InstrumentsDb::GetInstrumentsDb()->FindInstruments(Dir, &Query, Recursive);
2777    
2778            for (int i = 0; i < pInstruments->size(); i++) {
2779                if (list != "") list += ",";
2780                list += "'" + InstrumentsDb::toEscapedPath(pInstruments->at(i)) + "'";
2781            }
2782    
2783            result.Add(list);
2784        } catch (Exception e) {
2785             result.Error(e);
2786        }
2787    #else
2788        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2789    #endif
2790        return result.Produce();
2791    }
2792    
2793    String LSCPServer::FormatInstrumentsDb() {
2794        dmsg(2,("LSCPServer: FormatInstrumentsDb()\n"));
2795        LSCPResultSet result;
2796    #if HAVE_SQLITE3
2797        try {
2798            InstrumentsDb::GetInstrumentsDb()->Format();
2799        } catch (Exception e) {
2800             result.Error(e);
2801        }
2802    #else
2803        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2804    #endif
2805        return result.Produce();
2806    }
2807    
2808    
2809  /**  /**
2810   * 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
2811   * 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.905  
changed lines
  Added in v.1403

  ViewVC Help
Powered by ViewVC