/[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 475 by schoenebeck, Thu Mar 17 23:56:56 2005 UTC revision 1481 by senoner, Wed Nov 14 23:42:15 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 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    #if defined(WIN32)
29    #else
30  #include <fcntl.h>  #include <fcntl.h>
31    #endif
32    
33  #if HAVE_SQLITE3  #if ! HAVE_SQLITE3
34  # include "sqlite3.h"  #define DOESNT_HAVE_SQLITE3 "No database support. SQLITE3 was not installed when linuxsampler was built."
35  #endif  #endif
36    
37  #include "../engines/EngineFactory.h"  #include "../engines/EngineFactory.h"
38    #include "../engines/EngineChannelFactory.h"
39  #include "../drivers/audio/AudioOutputDeviceFactory.h"  #include "../drivers/audio/AudioOutputDeviceFactory.h"
40  #include "../drivers/midi/MidiInputDeviceFactory.h"  #include "../drivers/midi/MidiInputDeviceFactory.h"
41    
42    
43    /**
44     * Returns a copy of the given string where all special characters are
45     * replaced by LSCP escape sequences ("\xHH"). This function shall be used
46     * to escape LSCP response fields in case the respective response field is
47     * actually defined as using escape sequences in the LSCP specs.
48     *
49     * @e Caution: DO NOT use this function for escaping path based responses,
50     * use the Path class (src/common/Path.h) for this instead!
51     */
52    static String _escapeLscpResponse(String txt) {
53        for (int i = 0; i < txt.length(); i++) {
54            const char c = txt.c_str()[i];
55            if (
56                !(c >= '0' && c <= '9') &&
57                !(c >= 'a' && c <= 'z') &&
58                !(c >= 'A' && c <= 'Z') &&
59                !(c == ' ') && !(c == '!') && !(c == '#') && !(c == '$') &&
60                !(c == '%') && !(c == '&') && !(c == '(') && !(c == ')') &&
61                !(c == '*') && !(c == '+') && !(c == ',') && !(c == '-') &&
62                !(c == '.') && !(c == '/') && !(c == ':') && !(c == ';') &&
63                !(c == '<') && !(c == '=') && !(c == '>') && !(c == '?') &&
64                !(c == '@') && !(c == '[') && !(c == ']') &&
65                !(c == '^') && !(c == '_') && !(c == '`') && !(c == '{') &&
66                !(c == '|') && !(c == '}') && !(c == '~')
67            ) {
68                // convert the "special" character into a "\xHH" LSCP escape sequence
69                char buf[5];
70                snprintf(buf, sizeof(buf), "\\x%02x", static_cast<unsigned char>(c));
71                txt.replace(i, 1, buf);
72                i += 3;
73            }
74        }
75        return txt;
76    }
77    
78  /**  /**
79   * Below are a few static members of the LSCPServer class.   * Below are a few static members of the LSCPServer class.
80   * 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 52  Line 91 
91  fd_set LSCPServer::fdSet;  fd_set LSCPServer::fdSet;
92  int LSCPServer::currentSocket = -1;  int LSCPServer::currentSocket = -1;
93  std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>();  std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>();
94    std::vector<yyparse_param_t>::iterator itCurrentSession = std::vector<yyparse_param_t>::iterator();
95  std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>();  std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>();
96  std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>();  std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>();
97  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 60  Mutex LSCPServer::NotifyBufferMutex = Mu Line 100  Mutex LSCPServer::NotifyBufferMutex = Mu
100  Mutex LSCPServer::SubscriptionMutex = Mutex();  Mutex LSCPServer::SubscriptionMutex = Mutex();
101  Mutex LSCPServer::RTNotifyMutex = Mutex();  Mutex LSCPServer::RTNotifyMutex = Mutex();
102    
103  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(true, false, 0, -4) {  LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4) {
104        SocketAddress.sin_family      = AF_INET;
105        SocketAddress.sin_addr.s_addr = addr;
106        SocketAddress.sin_port        = port;
107      this->pSampler = pSampler;      this->pSampler = pSampler;
108      LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS");      LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_count, "AUDIO_OUTPUT_DEVICE_COUNT");
109        LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_info, "AUDIO_OUTPUT_DEVICE_INFO");
110        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_device_count, "MIDI_INPUT_DEVICE_COUNT");
111        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_device_info, "MIDI_INPUT_DEVICE_INFO");
112        LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT");
113      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");
114      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");
115      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");
116      LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");
117        LSCPEvent::RegisterEvent(LSCPEvent::event_fx_send_count, "FX_SEND_COUNT");
118        LSCPEvent::RegisterEvent(LSCPEvent::event_fx_send_info, "FX_SEND_INFO");
119        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_count, "MIDI_INSTRUMENT_MAP_COUNT");
120        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO");
121        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT");
122        LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO");
123        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_count, "DB_INSTRUMENT_DIRECTORY_COUNT");
124        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_info, "DB_INSTRUMENT_DIRECTORY_INFO");
125        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_count, "DB_INSTRUMENT_COUNT");
126        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO");
127        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO");
128      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
129        LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");
130        LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO");
131      hSocket = -1;      hSocket = -1;
132  }  }
133    
134  LSCPServer::~LSCPServer() {  LSCPServer::~LSCPServer() {
135    #if defined(WIN32)
136        if (hSocket >= 0) closesocket(hSocket);
137    #else
138      if (hSocket >= 0) close(hSocket);      if (hSocket >= 0) close(hSocket);
139    #endif
140    }
141    
142    void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) {
143        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount));
144    }
145    
146    void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) {
147        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount));
148    }
149    
150    void LSCPServer::EventHandler::MidiDeviceCountChanged(int NewCount) {
151        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount));
152    }
153    
154    void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) {
155        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount));
156    }
157    
158    void LSCPServer::EventHandler::MidiInstrumentInfoChanged(int MapId, int Bank, int Program) {
159        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_info, MapId, Bank, Program));
160    }
161    
162    void LSCPServer::EventHandler::MidiInstrumentMapCountChanged(int NewCount) {
163        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_count, NewCount));
164    }
165    
166    void LSCPServer::EventHandler::MidiInstrumentMapInfoChanged(int MapId) {
167        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_info, MapId));
168    }
169    
170    void LSCPServer::EventHandler::FxSendCountChanged(int ChannelId, int NewCount) {
171        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_count, ChannelId, NewCount));
172    }
173    
174    void LSCPServer::EventHandler::VoiceCountChanged(int ChannelId, int NewCount) {
175        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_voice_count, ChannelId, NewCount));
176  }  }
177    
178    void LSCPServer::EventHandler::StreamCountChanged(int ChannelId, int NewCount) {
179        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_stream_count, ChannelId, NewCount));
180    }
181    
182    void LSCPServer::EventHandler::BufferFillChanged(int ChannelId, String FillData) {
183        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_buffer_fill, ChannelId, FillData));
184    }
185    
186    void LSCPServer::EventHandler::TotalVoiceCountChanged(int NewCount) {
187        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount));
188    }
189    
190    #if HAVE_SQLITE3
191    void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) {
192        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, InstrumentsDb::toEscapedPath(Dir)));
193    }
194    
195    void LSCPServer::DbInstrumentsEventHandler::DirectoryInfoChanged(String Dir) {
196        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, InstrumentsDb::toEscapedPath(Dir)));
197    }
198    
199    void LSCPServer::DbInstrumentsEventHandler::DirectoryNameChanged(String Dir, String NewName) {
200        Dir = "'" + InstrumentsDb::toEscapedPath(Dir) + "'";
201        NewName = "'" + InstrumentsDb::toEscapedPath(NewName) + "'";
202        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, "NAME", Dir, NewName));
203    }
204    
205    void LSCPServer::DbInstrumentsEventHandler::InstrumentCountChanged(String Dir) {
206        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_count, InstrumentsDb::toEscapedPath(Dir)));
207    }
208    
209    void LSCPServer::DbInstrumentsEventHandler::InstrumentInfoChanged(String Instr) {
210        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, InstrumentsDb::toEscapedPath(Instr)));
211    }
212    
213    void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) {
214        Instr = "'" + InstrumentsDb::toEscapedPath(Instr) + "'";
215        NewName = "'" + InstrumentsDb::toEscapedPath(NewName) + "'";
216        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, "NAME", Instr, NewName));
217    }
218    
219    void LSCPServer::DbInstrumentsEventHandler::JobStatusChanged(int JobId) {
220        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instrs_job_info, JobId));
221    }
222    #endif // HAVE_SQLITE3
223    
224    
225  /**  /**
226   * Blocks the calling thread until the LSCP Server is initialized and   * Blocks the calling thread until the LSCP Server is initialized and
227   * accepting socket connections, if the server is already initialized then   * accepting socket connections, if the server is already initialized then
# Line 90  int LSCPServer::WaitUntilInitialized(lon Line 237  int LSCPServer::WaitUntilInitialized(lon
237  }  }
238    
239  int LSCPServer::Main() {  int LSCPServer::Main() {
240            #if defined(WIN32)
241            WSADATA wsaData;
242            int iResult;
243            iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
244            if (iResult != 0) {
245                    std::cerr << "LSCPServer: WSAStartup failed: " << iResult << "\n";
246                    exit(EXIT_FAILURE);
247            }
248            #endif
249      hSocket = socket(AF_INET, SOCK_STREAM, 0);      hSocket = socket(AF_INET, SOCK_STREAM, 0);
250      if (hSocket < 0) {      if (hSocket < 0) {
251          std::cerr << "LSCPServer: Could not create server socket." << std::endl;          std::cerr << "LSCPServer: Could not create server socket." << std::endl;
# Line 97  int LSCPServer::Main() { Line 253  int LSCPServer::Main() {
253          exit(EXIT_FAILURE);          exit(EXIT_FAILURE);
254      }      }
255    
     SocketAddress.sin_family      = AF_INET;  
     SocketAddress.sin_port        = htons(LSCP_PORT);  
     SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);  
   
256      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
257          std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds...";          std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds...";
258          for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds          for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds
259              if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {              if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
260                  if (trial > LSCP_SERVER_BIND_TIMEOUT) {                  if (trial > LSCP_SERVER_BIND_TIMEOUT) {
261                      std::cerr << "gave up!" << std::endl;                      std::cerr << "gave up!" << std::endl;
262                        #if defined(WIN32)
263                        closesocket(hSocket);
264                        #else
265                      close(hSocket);                      close(hSocket);
266                        #endif
267                      //return -1;                      //return -1;
268                      exit(EXIT_FAILURE);                      exit(EXIT_FAILURE);
269                  }                  }
# Line 120  int LSCPServer::Main() { Line 276  int LSCPServer::Main() {
276      listen(hSocket, 1);      listen(hSocket, 1);
277      Initialized.Set(true);      Initialized.Set(true);
278    
279        // Registering event listeners
280        pSampler->AddChannelCountListener(&eventHandler);
281        pSampler->AddAudioDeviceCountListener(&eventHandler);
282        pSampler->AddMidiDeviceCountListener(&eventHandler);
283        pSampler->AddVoiceCountListener(&eventHandler);
284        pSampler->AddStreamCountListener(&eventHandler);
285        pSampler->AddBufferFillListener(&eventHandler);
286        pSampler->AddTotalVoiceCountListener(&eventHandler);
287        pSampler->AddFxSendCountListener(&eventHandler);
288        MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler);
289        MidiInstrumentMapper::AddMidiInstrumentInfoListener(&eventHandler);
290        MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&eventHandler);
291        MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(&eventHandler);
292    #if HAVE_SQLITE3
293        InstrumentsDb::GetInstrumentsDb()->AddInstrumentsDbListener(&dbInstrumentsEventHandler);
294    #endif
295      // now wait for client connections and handle their requests      // now wait for client connections and handle their requests
296      sockaddr_in client;      sockaddr_in client;
297      int length = sizeof(client);      int length = sizeof(client);
# Line 127  int LSCPServer::Main() { Line 299  int LSCPServer::Main() {
299      FD_SET(hSocket, &fdSet);      FD_SET(hSocket, &fdSet);
300      int maxSessions = hSocket;      int maxSessions = hSocket;
301    
302        timeval timeout;
303    
304      while (true) {      while (true) {
305          fd_set selectSet = fdSet;          // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers
306          int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL);          {
307                std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
308                std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
309                std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
310                for (; itEngineChannel != itEnd; ++itEngineChannel) {
311                    if ((*itEngineChannel)->StatusChanged()) {
312                        SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));
313                    }
314    
315                    for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {
316                        FxSend* fxs = (*itEngineChannel)->GetFxSend(i);
317                        if(fxs != NULL && fxs->IsInfoChanged()) {
318                            int chn = (*itEngineChannel)->iSamplerChannelIndex;
319                            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id()));
320                            fxs->SetInfoChanged(false);
321                        }
322                    }
323                }
324            }
325    
326            //Now let's deliver late notifies (if any)
327            NotifyBufferMutex.Lock();
328            for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {
329    #ifdef MSG_NOSIGNAL
330                    send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL);
331    #else
332                    send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0);
333    #endif
334            }
335            bufferedNotifies.clear();
336            NotifyBufferMutex.Unlock();
337    
338            fd_set selectSet = fdSet;
339            timeout.tv_sec  = 0;
340            timeout.tv_usec = 100000;
341    
342            int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout);
343    
344          if (retval == 0)          if (retval == 0)
345                  continue; //Nothing try again                  continue; //Nothing try again
346          if (retval == -1) {          if (retval == -1) {
347                  std::cerr << "LSCPServer: Socket select error." << std::endl;                  std::cerr << "LSCPServer: Socket select error." << std::endl;
348                    #if defined(WIN32)
349                    closesocket(hSocket);
350                    #else
351                  close(hSocket);                  close(hSocket);
352                    #endif
353                  exit(EXIT_FAILURE);                  exit(EXIT_FAILURE);
354          }          }
355    
# Line 146  int LSCPServer::Main() { Line 361  int LSCPServer::Main() {
361                          exit(EXIT_FAILURE);                          exit(EXIT_FAILURE);
362                  }                  }
363    
364                    #if defined(WIN32)
365                    u_long nonblock_io = 1;
366                    if( ioctlsocket(socket, FIONBIO, &nonblock_io) ) {
367                      std::cerr << "LSCPServer: ioctlsocket: set FIONBIO failed. Error " << WSAGetLastError() << std::endl;
368                      exit(EXIT_FAILURE);
369                    }
370            #else          
371                  if (fcntl(socket, F_SETFL, O_NONBLOCK)) {                  if (fcntl(socket, F_SETFL, O_NONBLOCK)) {
372                          std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl;                          std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl;
373                          exit(EXIT_FAILURE);                          exit(EXIT_FAILURE);
374                  }                  }
375                    #endif
376    
377                  // Parser initialization                  // Parser initialization
378                  yyparse_param_t yyparse_param;                  yyparse_param_t yyparse_param;
# Line 173  int LSCPServer::Main() { Line 396  int LSCPServer::Main() {
396                                  int dummy; // just a temporary hack to fulfill the restart() function prototype                                  int dummy; // just a temporary hack to fulfill the restart() function prototype
397                                  restart(NULL, dummy); // restart the 'scanner'                                  restart(NULL, dummy); // restart the 'scanner'
398                                  currentSocket = (*iter).hSession;  //a hack                                  currentSocket = (*iter).hSession;  //a hack
399                                    itCurrentSession = iter; // another hack
400                                  dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str()));                                  dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str()));
401                                  if ((*iter).bVerbose) { // if echo mode enabled                                  if ((*iter).bVerbose) { // if echo mode enabled
402                                      AnswerClient(bufferedCommands[currentSocket]);                                      AnswerClient(bufferedCommands[currentSocket]);
403                                  }                                  }
404                                  int result = yyparse(&(*iter));                                  int result = yyparse(&(*iter));
405                                  currentSocket = -1;     //continuation of a hack                                  currentSocket = -1;     //continuation of a hack
406                                    itCurrentSession = Sessions.end(); // hack as well
407                                  dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket));                                  dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket));
408                                  if (result == LSCP_QUIT) { //Was it a quit command by any chance?                                  if (result == LSCP_QUIT) { //Was it a quit command by any chance?
409                                          CloseConnection(iter);                                          CloseConnection(iter);
# Line 189  int LSCPServer::Main() { Line 414  int LSCPServer::Main() {
414                          break;                          break;
415                  }                  }
416          }          }
   
         //Now let's deliver late notifies (if any)  
         NotifyBufferMutex.Lock();  
         for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {  
                 send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0);  
                 bufferedNotifies.erase(iterNotify);  
         }  
         NotifyBufferMutex.Unlock();  
417      }      }
418  }  }
419    
# Line 214  void LSCPServer::CloseConnection( std::v Line 431  void LSCPServer::CloseConnection( std::v
431          NotifyMutex.Lock();          NotifyMutex.Lock();
432          bufferedCommands.erase(socket);          bufferedCommands.erase(socket);
433          bufferedNotifies.erase(socket);          bufferedNotifies.erase(socket);
434            #if defined(WIN32)
435            closesocket(socket);
436            #else
437          close(socket);          close(socket);
438            #endif
439          NotifyMutex.Unlock();          NotifyMutex.Unlock();
440  }  }
441    
# Line 243  void LSCPServer::SendLSCPNotify( LSCPEve Line 464  void LSCPServer::SendLSCPNotify( LSCPEve
464          while (true) {          while (true) {
465                  if (NotifyMutex.Trylock()) {                  if (NotifyMutex.Trylock()) {
466                          for(;iter != end; iter++)                          for(;iter != end; iter++)
467    #ifdef MSG_NOSIGNAL
468                                    send(*iter, notify.c_str(), notify.size(), MSG_NOSIGNAL);
469    #else
470                                  send(*iter, notify.c_str(), notify.size(), 0);                                  send(*iter, notify.c_str(), notify.size(), 0);
471    #endif
472                          NotifyMutex.Unlock();                          NotifyMutex.Unlock();
473                          break;                          break;
474                  } else {                  } else {
# Line 275  extern int GetLSCPCommand( void *buf, in Line 500  extern int GetLSCPCommand( void *buf, in
500          return command.size();          return command.size();
501  }  }
502    
503    extern yyparse_param_t* GetCurrentYaccSession() {
504        return &(*itCurrentSession);
505    }
506    
507  /**  /**
508   * Will be called to try to read the command from the socket   * Will be called to try to read the command from the socket
509   * 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 285  bool LSCPServer::GetLSCPCommand( std::ve Line 514  bool LSCPServer::GetLSCPCommand( std::ve
514          char c;          char c;
515          int i = 0;          int i = 0;
516          while (true) {          while (true) {
517                    #if defined(WIN32)
518                    int result = recv(socket, (char *)&c, 1, 0); //Read one character at a time for now
519                    #else
520                  int result = recv(socket, (void *)&c, 1, 0); //Read one character at a time for now                  int result = recv(socket, (void *)&c, 1, 0); //Read one character at a time for now
521                    #endif
522                  if (result == 0) { //socket was selected, so 0 here means client has closed the connection                  if (result == 0) { //socket was selected, so 0 here means client has closed the connection
523                          CloseConnection(iter);                          CloseConnection(iter);
524                          break;                          break;
# Line 295  bool LSCPServer::GetLSCPCommand( std::ve Line 528  bool LSCPServer::GetLSCPCommand( std::ve
528                                  continue; //Ignore CR                                  continue; //Ignore CR
529                          if (c == '\n') {                          if (c == '\n') {
530                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));
531                                  bufferedCommands[socket] += "\n";                                  bufferedCommands[socket] += "\r\n";
532                                  return true; //Complete command was read                                  return true; //Complete command was read
533                          }                          }
534                          bufferedCommands[socket] += c;                          bufferedCommands[socket] += c;
535                  }                  }
536                    #if defined(WIN32)
537                    if (result == SOCKET_ERROR) {
538                        int wsa_lasterror = WSAGetLastError();
539                            if (wsa_lasterror == WSAEWOULDBLOCK) //Would block, try again later.
540                                    return false;
541                            dmsg(2,("LSCPScanner: Socket error after recv() Error %d.\n", wsa_lasterror));  
542                            CloseConnection(iter);
543                            break;
544                    }
545                    #else
546                  if (result == -1) {                  if (result == -1) {
547                          if (errno == EAGAIN) //Would block, try again later.                          if (errno == EAGAIN) //Would block, try again later.
548                                  return false;                                  return false;
# Line 338  bool LSCPServer::GetLSCPCommand( std::ve Line 581  bool LSCPServer::GetLSCPCommand( std::ve
581                          CloseConnection(iter);                          CloseConnection(iter);
582                          break;                          break;
583                  }                  }
584                    #endif
585          }          }
586          return false;          return false;
587  }  }
# Line 352  void LSCPServer::AnswerClient(String Ret Line 596  void LSCPServer::AnswerClient(String Ret
596      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));
597      if (currentSocket != -1) {      if (currentSocket != -1) {
598              NotifyMutex.Lock();              NotifyMutex.Lock();
599    #ifdef MSG_NOSIGNAL
600                send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL);
601    #else
602              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);
603    #endif
604              NotifyMutex.Unlock();              NotifyMutex.Unlock();
605      }      }
606  }  }
# Line 396  String LSCPServer::CreateAudioOutputDevi Line 644  String LSCPServer::CreateAudioOutputDevi
644          AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);          AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);
645          // search for the created device to get its index          // search for the created device to get its index
646          int index = GetAudioOutputDeviceIndex(pDevice);          int index = GetAudioOutputDeviceIndex(pDevice);
647          if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device.");          if (index == -1) throw Exception("Internal error: could not find created audio output device.");
648          result = index; // success          result = index; // success
649      }      }
650      catch (LinuxSamplerException e) {      catch (Exception e) {
651          result.Error(e);          result.Error(e);
652      }      }
653      return result.Produce();      return result.Produce();
# Line 412  String LSCPServer::CreateMidiInputDevice Line 660  String LSCPServer::CreateMidiInputDevice
660          MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters);          MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters);
661          // search for the created device to get its index          // search for the created device to get its index
662          int index = GetMidiInputDeviceIndex(pDevice);          int index = GetMidiInputDeviceIndex(pDevice);
663          if (index == -1) throw LinuxSamplerException("Internal error: could not find created midi input device.");          if (index == -1) throw Exception("Internal error: could not find created midi input device.");
664          result = index; // success          result = index; // success
665      }      }
666      catch (LinuxSamplerException e) {      catch (Exception e) {
667          result.Error(e);          result.Error(e);
668      }      }
669      return result.Produce();      return result.Produce();
# Line 426  String LSCPServer::DestroyAudioOutputDev Line 674  String LSCPServer::DestroyAudioOutputDev
674      LSCPResultSet result;      LSCPResultSet result;
675      try {      try {
676          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
677          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + ".");
678          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
679          pSampler->DestroyAudioOutputDevice(pDevice);          pSampler->DestroyAudioOutputDevice(pDevice);
680      }      }
681      catch (LinuxSamplerException e) {      catch (Exception e) {
682          result.Error(e);          result.Error(e);
683      }      }
684      return result.Produce();      return result.Produce();
# Line 441  String LSCPServer::DestroyMidiInputDevic Line 689  String LSCPServer::DestroyMidiInputDevic
689      LSCPResultSet result;      LSCPResultSet result;
690      try {      try {
691          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
692          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + ".");
693          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
694          pSampler->DestroyMidiInputDevice(pDevice);          pSampler->DestroyMidiInputDevice(pDevice);
695      }      }
696      catch (LinuxSamplerException e) {      catch (Exception e) {
697          result.Error(e);          result.Error(e);
698      }      }
699      return result.Produce();      return result.Produce();
700  }  }
701    
702    EngineChannel* LSCPServer::GetEngineChannel(uint uiSamplerChannel) {
703        SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
704        if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
705    
706        EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
707        if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
708    
709        return pEngineChannel;
710    }
711    
712  /**  /**
713   * Will be called by the parser to load an instrument.   * Will be called by the parser to load an instrument.
714   */   */
# Line 459  String LSCPServer::LoadInstrument(String Line 717  String LSCPServer::LoadInstrument(String
717      LSCPResultSet result;      LSCPResultSet result;
718      try {      try {
719          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
720          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
721          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
722          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel yet");
723          if (!pSamplerChannel->GetAudioOutputDevice())          if (!pSamplerChannel->GetAudioOutputDevice())
724              throw LinuxSamplerException("No audio output device connected to sampler channel");              throw Exception("No audio output device connected to sampler channel");
725          if (bBackground) {          if (bBackground) {
726              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel);              InstrumentManager::instrument_id_t id;
727                id.FileName = Filename;
728                id.Index    = uiInstrument;
729                InstrumentManager::LoadInstrumentInBackground(id, pEngineChannel);
730          }          }
731          else {          else {
732              // tell the engine channel which instrument to load              // tell the engine channel which instrument to load
# Line 474  String LSCPServer::LoadInstrument(String Line 735  String LSCPServer::LoadInstrument(String
735              pEngineChannel->LoadInstrument();              pEngineChannel->LoadInstrument();
736          }          }
737      }      }
738      catch (LinuxSamplerException e) {      catch (Exception e) {
739           result.Error(e);           result.Error(e);
740      }      }
741      return result.Produce();      return result.Produce();
# Line 485  String LSCPServer::LoadInstrument(String Line 746  String LSCPServer::LoadInstrument(String
746   * sampler channel.   * sampler channel.
747   */   */
748  String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) {  String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) {
749      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));      dmsg(2,("LSCPServer: SetEngineType(EngineName=%s,uiSamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));
750      LSCPResultSet result;      LSCPResultSet result;
751      try {      try {
752          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
753          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
754          LockRTNotify();          LockRTNotify();
755          pSamplerChannel->SetEngineType(EngineName);          pSamplerChannel->SetEngineType(EngineName);
756            if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1);
757          UnlockRTNotify();          UnlockRTNotify();
758      }      }
759      catch (LinuxSamplerException e) {      catch (Exception e) {
760           result.Error(e);           result.Error(e);
761      }      }
762      return result.Produce();      return result.Produce();
# Line 532  String LSCPServer::ListChannels() { Line 794  String LSCPServer::ListChannels() {
794   */   */
795  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
796      dmsg(2,("LSCPServer: AddChannel()\n"));      dmsg(2,("LSCPServer: AddChannel()\n"));
797        LockRTNotify();
798      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();
799        UnlockRTNotify();
800      LSCPResultSet result(pSamplerChannel->Index());      LSCPResultSet result(pSamplerChannel->Index());
801      return result.Produce();      return result.Produce();
802  }  }
# Line 550  String LSCPServer::RemoveChannel(uint ui Line 814  String LSCPServer::RemoveChannel(uint ui
814  }  }
815    
816  /**  /**
817   * Will be called by the parser to get all available engines.   * Will be called by the parser to get the amount of all available engines.
818   */   */
819  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
820      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
821      LSCPResultSet result("GigEngine");      LSCPResultSet result;
822        try {
823            int n = EngineFactory::AvailableEngineTypes().size();
824            result.Add(n);
825        }
826        catch (Exception e) {
827            result.Error(e);
828        }
829        return result.Produce();
830    }
831    
832    /**
833     * Will be called by the parser to get a list of all available engines.
834     */
835    String LSCPServer::ListAvailableEngines() {
836        dmsg(2,("LSCPServer: ListAvailableEngines()\n"));
837        LSCPResultSet result;
838        try {
839            String s = EngineFactory::AvailableEngineTypesAsString();
840            result.Add(s);
841        }
842        catch (Exception e) {
843            result.Error(e);
844        }
845      return result.Produce();      return result.Produce();
846  }  }
847    
# Line 565  String LSCPServer::GetAvailableEngines() Line 852  String LSCPServer::GetAvailableEngines()
852  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
853      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
854      LSCPResultSet result;      LSCPResultSet result;
855        LockRTNotify();
856      try {      try {
857          Engine* pEngine = EngineFactory::Create(EngineName);          Engine* pEngine = EngineFactory::Create(EngineName);
858          result.Add("DESCRIPTION", pEngine->Description());          result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description()));
859          result.Add("VERSION",     pEngine->Version());          result.Add("VERSION",     pEngine->Version());
860          delete pEngine;          EngineFactory::Destroy(pEngine);
861      }      }
862      catch (LinuxSamplerException e) {      catch (Exception e) {
863           result.Error(e);           result.Error(e);
864      }      }
865        UnlockRTNotify();
866      return result.Produce();      return result.Produce();
867  }  }
868    
# Line 586  String LSCPServer::GetChannelInfo(uint u Line 875  String LSCPServer::GetChannelInfo(uint u
875      LSCPResultSet result;      LSCPResultSet result;
876      try {      try {
877          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
878          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
879          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
880    
881          //Defaults values          //Defaults values
# Line 598  String LSCPServer::GetChannelInfo(uint u Line 887  String LSCPServer::GetChannelInfo(uint u
887          int InstrumentStatus = -1;          int InstrumentStatus = -1;
888          int AudioOutputChannels = 0;          int AudioOutputChannels = 0;
889          String AudioRouting;          String AudioRouting;
890            int Mute = 0;
891            bool Solo = false;
892            String MidiInstrumentMap = "NONE";
893    
894          if (pEngineChannel) {          if (pEngineChannel) {
895              EngineName          = pEngineChannel->EngineName();              EngineName          = pEngineChannel->EngineName();
# Line 613  String LSCPServer::GetChannelInfo(uint u Line 905  String LSCPServer::GetChannelInfo(uint u
905                  if (AudioRouting != "") AudioRouting += ",";                  if (AudioRouting != "") AudioRouting += ",";
906                  AudioRouting += ToString(pEngineChannel->OutputChannel(chan));                  AudioRouting += ToString(pEngineChannel->OutputChannel(chan));
907              }              }
908                Mute = pEngineChannel->GetMute();
909                Solo = pEngineChannel->GetSolo();
910                if (pEngineChannel->UsesNoMidiInstrumentMap())
911                    MidiInstrumentMap = "NONE";
912                else if (pEngineChannel->UsesDefaultMidiInstrumentMap())
913                    MidiInstrumentMap = "DEFAULT";
914                else
915                    MidiInstrumentMap = ToString(pEngineChannel->GetMidiInstrumentMap());
916          }          }
917    
918          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 625  String LSCPServer::GetChannelInfo(uint u Line 925  String LSCPServer::GetChannelInfo(uint u
925    
926          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));
927          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());
928          if (pSamplerChannel->GetMidiInputChannel() == MidiInputPort::midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL");          if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL");
929          else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());          else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
930    
931            // convert the filename into the correct encoding as defined for LSCP
932            // (especially in terms of special characters -> escape sequences)
933            if (InstrumentFileName != "NONE" && InstrumentFileName != "") {
934    #if WIN32
935                InstrumentFileName = Path::fromWindows(InstrumentFileName).toLscp();
936    #else
937                // assuming POSIX
938                InstrumentFileName = Path::fromPosix(InstrumentFileName).toLscp();
939    #endif
940            }
941    
942          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
943          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
944          result.Add("INSTRUMENT_NAME", InstrumentName);          result.Add("INSTRUMENT_NAME", _escapeLscpResponse(InstrumentName));
945          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
946            result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));
947            result.Add("SOLO", Solo);
948            result.Add("MIDI_INSTRUMENT_MAP", MidiInstrumentMap);
949      }      }
950      catch (LinuxSamplerException e) {      catch (Exception e) {
951           result.Error(e);           result.Error(e);
952      }      }
953      return result.Produce();      return result.Produce();
# Line 648  String LSCPServer::GetVoiceCount(uint ui Line 962  String LSCPServer::GetVoiceCount(uint ui
962      LSCPResultSet result;      LSCPResultSet result;
963      try {      try {
964          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
965          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
966          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
967          if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel");          if (!pEngineChannel) throw Exception("No engine loaded on sampler channel");
968            if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
969          result.Add(pEngineChannel->GetEngine()->VoiceCount());          result.Add(pEngineChannel->GetEngine()->VoiceCount());
970      }      }
971      catch (LinuxSamplerException e) {      catch (Exception e) {
972           result.Error(e);           result.Error(e);
973      }      }
974      return result.Produce();      return result.Produce();
# Line 668  String LSCPServer::GetStreamCount(uint u Line 983  String LSCPServer::GetStreamCount(uint u
983      LSCPResultSet result;      LSCPResultSet result;
984      try {      try {
985          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
986          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
987          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
988          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
989            if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
990          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
991      }      }
992      catch (LinuxSamplerException e) {      catch (Exception e) {
993           result.Error(e);           result.Error(e);
994      }      }
995      return result.Produce();      return result.Produce();
# Line 688  String LSCPServer::GetBufferFill(fill_re Line 1004  String LSCPServer::GetBufferFill(fill_re
1004      LSCPResultSet result;      LSCPResultSet result;
1005      try {      try {
1006          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1007          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1008          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1009          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1010            if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
1011          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
1012          else {          else {
1013              switch (ResponseType) {              switch (ResponseType) {
# Line 701  String LSCPServer::GetBufferFill(fill_re Line 1018  String LSCPServer::GetBufferFill(fill_re
1018                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());
1019                      break;                      break;
1020                  default:                  default:
1021                      throw LinuxSamplerException("Unknown fill response type");                      throw Exception("Unknown fill response type");
1022              }              }
1023          }          }
1024      }      }
1025      catch (LinuxSamplerException e) {      catch (Exception e) {
1026           result.Error(e);           result.Error(e);
1027      }      }
1028      return result.Produce();      return result.Produce();
# Line 715  String LSCPServer::GetAvailableAudioOutp Line 1032  String LSCPServer::GetAvailableAudioOutp
1032      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));
1033      LSCPResultSet result;      LSCPResultSet result;
1034      try {      try {
1035            int n = AudioOutputDeviceFactory::AvailableDrivers().size();
1036            result.Add(n);
1037        }
1038        catch (Exception e) {
1039            result.Error(e);
1040        }
1041        return result.Produce();
1042    }
1043    
1044    String LSCPServer::ListAvailableAudioOutputDrivers() {
1045        dmsg(2,("LSCPServer: ListAvailableAudioOutputDrivers()\n"));
1046        LSCPResultSet result;
1047        try {
1048          String s = AudioOutputDeviceFactory::AvailableDriversAsString();          String s = AudioOutputDeviceFactory::AvailableDriversAsString();
1049          result.Add(s);          result.Add(s);
1050      }      }
1051      catch (LinuxSamplerException e) {      catch (Exception e) {
1052          result.Error(e);          result.Error(e);
1053      }      }
1054      return result.Produce();      return result.Produce();
# Line 728  String LSCPServer::GetAvailableMidiInput Line 1058  String LSCPServer::GetAvailableMidiInput
1058      dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));      dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));
1059      LSCPResultSet result;      LSCPResultSet result;
1060      try {      try {
1061            int n = MidiInputDeviceFactory::AvailableDrivers().size();
1062            result.Add(n);
1063        }
1064        catch (Exception e) {
1065            result.Error(e);
1066        }
1067        return result.Produce();
1068    }
1069    
1070    String LSCPServer::ListAvailableMidiInputDrivers() {
1071        dmsg(2,("LSCPServer: ListAvailableMidiInputDrivers()\n"));
1072        LSCPResultSet result;
1073        try {
1074          String s = MidiInputDeviceFactory::AvailableDriversAsString();          String s = MidiInputDeviceFactory::AvailableDriversAsString();
1075          result.Add(s);          result.Add(s);
1076      }      }
1077      catch (LinuxSamplerException e) {      catch (Exception e) {
1078          result.Error(e);          result.Error(e);
1079      }      }
1080      return result.Produce();      return result.Produce();
# Line 755  String LSCPServer::GetMidiInputDriverInf Line 1098  String LSCPServer::GetMidiInputDriverInf
1098              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
1099          }          }
1100      }      }
1101      catch (LinuxSamplerException e) {      catch (Exception e) {
1102          result.Error(e);          result.Error(e);
1103      }      }
1104      return result.Produce();      return result.Produce();
# Line 779  String LSCPServer::GetAudioOutputDriverI Line 1122  String LSCPServer::GetAudioOutputDriverI
1122              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
1123          }          }
1124      }      }
1125      catch (LinuxSamplerException e) {      catch (Exception e) {
1126          result.Error(e);          result.Error(e);
1127      }      }
1128      return result.Produce();      return result.Produce();
# Line 806  String LSCPServer::GetMidiInputDriverPar Line 1149  String LSCPServer::GetMidiInputDriverPar
1149          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
1150          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
1151      }      }
1152      catch (LinuxSamplerException e) {      catch (Exception e) {
1153          result.Error(e);          result.Error(e);
1154      }      }
1155      return result.Produce();      return result.Produce();
# Line 833  String LSCPServer::GetAudioOutputDriverP Line 1176  String LSCPServer::GetAudioOutputDriverP
1176          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
1177          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
1178      }      }
1179      catch (LinuxSamplerException e) {      catch (Exception e) {
1180          result.Error(e);          result.Error(e);
1181      }      }
1182      return result.Produce();      return result.Produce();
# Line 846  String LSCPServer::GetAudioOutputDeviceC Line 1189  String LSCPServer::GetAudioOutputDeviceC
1189          uint count = pSampler->AudioOutputDevices();          uint count = pSampler->AudioOutputDevices();
1190          result.Add(count); // success          result.Add(count); // success
1191      }      }
1192      catch (LinuxSamplerException e) {      catch (Exception e) {
1193          result.Error(e);          result.Error(e);
1194      }      }
1195      return result.Produce();      return result.Produce();
# Line 859  String LSCPServer::GetMidiInputDeviceCou Line 1202  String LSCPServer::GetMidiInputDeviceCou
1202          uint count = pSampler->MidiInputDevices();          uint count = pSampler->MidiInputDevices();
1203          result.Add(count); // success          result.Add(count); // success
1204      }      }
1205      catch (LinuxSamplerException e) {      catch (Exception e) {
1206          result.Error(e);          result.Error(e);
1207      }      }
1208      return result.Produce();      return result.Produce();
# Line 878  String LSCPServer::GetAudioOutputDevices Line 1221  String LSCPServer::GetAudioOutputDevices
1221          }          }
1222          result.Add(s);          result.Add(s);
1223      }      }
1224      catch (LinuxSamplerException e) {      catch (Exception e) {
1225          result.Error(e);          result.Error(e);
1226      }      }
1227      return result.Produce();      return result.Produce();
# Line 897  String LSCPServer::GetMidiInputDevices() Line 1240  String LSCPServer::GetMidiInputDevices()
1240          }          }
1241          result.Add(s);          result.Add(s);
1242      }      }
1243      catch (LinuxSamplerException e) {      catch (Exception e) {
1244          result.Error(e);          result.Error(e);
1245      }      }
1246      return result.Produce();      return result.Produce();
# Line 908  String LSCPServer::GetAudioOutputDeviceI Line 1251  String LSCPServer::GetAudioOutputDeviceI
1251      LSCPResultSet result;      LSCPResultSet result;
1252      try {      try {
1253          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1254          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + ".");
1255          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1256          result.Add("DRIVER", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
1257          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
# Line 917  String LSCPServer::GetAudioOutputDeviceI Line 1260  String LSCPServer::GetAudioOutputDeviceI
1260              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1261          }          }
1262      }      }
1263      catch (LinuxSamplerException e) {      catch (Exception e) {
1264          result.Error(e);          result.Error(e);
1265      }      }
1266      return result.Produce();      return result.Produce();
# Line 928  String LSCPServer::GetMidiInputDeviceInf Line 1271  String LSCPServer::GetMidiInputDeviceInf
1271      LSCPResultSet result;      LSCPResultSet result;
1272      try {      try {
1273          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1274          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1275          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1276          result.Add("DRIVER", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
1277          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
# Line 937  String LSCPServer::GetMidiInputDeviceInf Line 1280  String LSCPServer::GetMidiInputDeviceInf
1280              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1281          }          }
1282      }      }
1283      catch (LinuxSamplerException e) {      catch (Exception e) {
1284          result.Error(e);          result.Error(e);
1285      }      }
1286      return result.Produce();      return result.Produce();
# Line 948  String LSCPServer::GetMidiInputPortInfo( Line 1291  String LSCPServer::GetMidiInputPortInfo(
1291      try {      try {
1292          // get MIDI input device          // get MIDI input device
1293          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1294          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1295          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1296    
1297          // get MIDI port          // get MIDI port
1298          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1299          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          if (!pMidiInputPort) throw Exception("There is no MIDI input port with index " + ToString(PortIndex) + ".");
1300    
1301          // return the values of all MIDI port parameters          // return the values of all MIDI port parameters
1302          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
# Line 962  String LSCPServer::GetMidiInputPortInfo( Line 1305  String LSCPServer::GetMidiInputPortInfo(
1305              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1306          }          }
1307      }      }
1308      catch (LinuxSamplerException e) {      catch (Exception e) {
1309          result.Error(e);          result.Error(e);
1310      }      }
1311      return result.Produce();      return result.Produce();
# Line 974  String LSCPServer::GetAudioOutputChannel Line 1317  String LSCPServer::GetAudioOutputChannel
1317      try {      try {
1318          // get audio output device          // get audio output device
1319          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1320          if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw Exception("There is no audio output device with index " + ToString(DeviceId) + ".");
1321          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1322    
1323          // get audio channel          // get audio channel
1324          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1325          if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + ".");          if (!pChannel) throw Exception("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
1326    
1327          // return the values of all audio channel parameters          // return the values of all audio channel parameters
1328          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 988  String LSCPServer::GetAudioOutputChannel Line 1331  String LSCPServer::GetAudioOutputChannel
1331              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1332          }          }
1333      }      }
1334      catch (LinuxSamplerException e) {      catch (Exception e) {
1335          result.Error(e);          result.Error(e);
1336      }      }
1337      return result.Produce();      return result.Produce();
# Line 1000  String LSCPServer::GetMidiInputPortParam Line 1343  String LSCPServer::GetMidiInputPortParam
1343      try {      try {
1344          // get MIDI input device          // get MIDI input device
1345          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1346          if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw Exception("There is no midi input device with index " + ToString(DeviceId) + ".");
1347          MidiInputDevice* pDevice = devices[DeviceId];          MidiInputDevice* pDevice = devices[DeviceId];
1348    
1349          // get midi port          // get midi port
1350          MidiInputPort* pPort = pDevice->GetPort(PortId);          MidiInputPort* pPort = pDevice->GetPort(PortId);
1351          if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + ".");          if (!pPort) throw Exception("Midi input device does not have port " + ToString(PortId) + ".");
1352    
1353          // get desired port parameter          // get desired port parameter
1354          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();
1355          if (!parameters.count(ParameterName)) throw LinuxSamplerException("Midi port does not provide a parameter '" + ParameterName + "'.");          if (!parameters.count(ParameterName)) throw Exception("Midi port does not provide a parameter '" + ParameterName + "'.");
1356          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1357    
1358          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 1021  String LSCPServer::GetMidiInputPortParam Line 1364  String LSCPServer::GetMidiInputPortParam
1364          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1365          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1366      }      }
1367      catch (LinuxSamplerException e) {      catch (Exception e) {
1368          result.Error(e);          result.Error(e);
1369      }      }
1370      return result.Produce();      return result.Produce();
# Line 1033  String LSCPServer::GetAudioOutputChannel Line 1376  String LSCPServer::GetAudioOutputChannel
1376      try {      try {
1377          // get audio output device          // get audio output device
1378          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1379          if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw Exception("There is no audio output device with index " + ToString(DeviceId) + ".");
1380          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1381    
1382          // get audio channel          // get audio channel
1383          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1384          if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + ".");          if (!pChannel) throw Exception("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
1385    
1386          // get desired audio channel parameter          // get desired audio channel parameter
1387          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1388          if (!parameters.count(ParameterName)) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'.");          if (!parameters.count(ParameterName)) throw Exception("Audio channel does not provide a parameter '" + ParameterName + "'.");
1389          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1390    
1391          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 1054  String LSCPServer::GetAudioOutputChannel Line 1397  String LSCPServer::GetAudioOutputChannel
1397          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1398          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1399      }      }
1400      catch (LinuxSamplerException e) {      catch (Exception e) {
1401          result.Error(e);          result.Error(e);
1402      }      }
1403      return result.Produce();      return result.Produce();
# Line 1066  String LSCPServer::SetAudioOutputChannel Line 1409  String LSCPServer::SetAudioOutputChannel
1409      try {      try {
1410          // get audio output device          // get audio output device
1411          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1412          if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw Exception("There is no audio output device with index " + ToString(DeviceId) + ".");
1413          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1414    
1415          // get audio channel          // get audio channel
1416          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1417          if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + ".");          if (!pChannel) throw Exception("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
1418    
1419          // get desired audio channel parameter          // get desired audio channel parameter
1420          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1421          if (!parameters.count(ParamKey)) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'.");          if (!parameters.count(ParamKey)) throw Exception("Audio channel does not provide a parameter '" + ParamKey + "'.");
1422          DeviceRuntimeParameter* pParameter = parameters[ParamKey];          DeviceRuntimeParameter* pParameter = parameters[ParamKey];
1423    
1424          // set new channel parameter value          // set new channel parameter value
1425          pParameter->SetValue(ParamVal);          pParameter->SetValue(ParamVal);
1426            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceId));
1427      }      }
1428      catch (LinuxSamplerException e) {      catch (Exception e) {
1429          result.Error(e);          result.Error(e);
1430      }      }
1431      return result.Produce();      return result.Produce();
# Line 1092  String LSCPServer::SetAudioOutputDeviceP Line 1436  String LSCPServer::SetAudioOutputDeviceP
1436      LSCPResultSet result;      LSCPResultSet result;
1437      try {      try {
1438          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1439          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + ".");
1440          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1441          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1442          if (!parameters.count(ParamKey)) throw LinuxSamplerException("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 + "'");
1443          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1444            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceIndex));
1445      }      }
1446      catch (LinuxSamplerException e) {      catch (Exception e) {
1447          result.Error(e);          result.Error(e);
1448      }      }
1449      return result.Produce();      return result.Produce();
# Line 1109  String LSCPServer::SetMidiInputDevicePar Line 1454  String LSCPServer::SetMidiInputDevicePar
1454      LSCPResultSet result;      LSCPResultSet result;
1455      try {      try {
1456          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1457          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1458          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1459          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1460          if (!parameters.count(ParamKey)) throw LinuxSamplerException("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 + "'");
1461          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1462            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex));
1463      }      }
1464      catch (LinuxSamplerException e) {      catch (Exception e) {
1465          result.Error(e);          result.Error(e);
1466      }      }
1467      return result.Produce();      return result.Produce();
# Line 1127  String LSCPServer::SetMidiInputPortParam Line 1473  String LSCPServer::SetMidiInputPortParam
1473      try {      try {
1474          // get MIDI input device          // get MIDI input device
1475          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1476          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1477          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1478    
1479          // get MIDI port          // get MIDI port
1480          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1481          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          if (!pMidiInputPort) throw Exception("There is no MIDI input port with index " + ToString(PortIndex) + ".");
1482    
1483          // set port parameter value          // set port parameter value
1484          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1485          if (!parameters.count(ParamKey)) throw LinuxSamplerException("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 + "'");
1486          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1487            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex));
1488      }      }
1489      catch (LinuxSamplerException e) {      catch (Exception e) {
1490          result.Error(e);          result.Error(e);
1491      }      }
1492      return result.Produce();      return result.Produce();
# Line 1154  String LSCPServer::SetAudioOutputChannel Line 1501  String LSCPServer::SetAudioOutputChannel
1501      LSCPResultSet result;      LSCPResultSet result;
1502      try {      try {
1503          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1504          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1505          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1506          if (!pEngineChannel) throw LinuxSamplerException("No engine type yet assigned to sampler channel " + ToString(uiSamplerChannel));          if (!pEngineChannel) throw Exception("No engine type yet assigned to sampler channel " + ToString(uiSamplerChannel));
1507          if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel));          if (!pSamplerChannel->GetAudioOutputDevice()) throw Exception("No audio output device connected to sampler channel " + ToString(uiSamplerChannel));
1508          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1509      }      }
1510      catch (LinuxSamplerException e) {      catch (Exception e) {
1511           result.Error(e);           result.Error(e);
1512      }      }
1513      return result.Produce();      return result.Produce();
# Line 1169  String LSCPServer::SetAudioOutputChannel Line 1516  String LSCPServer::SetAudioOutputChannel
1516  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
1517      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));
1518      LSCPResultSet result;      LSCPResultSet result;
1519        LockRTNotify();
1520      try {      try {
1521          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1522          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1523          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1524          if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));          if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId));
1525          AudioOutputDevice* pDevice = devices[AudioDeviceId];          AudioOutputDevice* pDevice = devices[AudioDeviceId];
1526          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1527      }      }
1528      catch (LinuxSamplerException e) {      catch (Exception e) {
1529           result.Error(e);           result.Error(e);
1530      }      }
1531        UnlockRTNotify();
1532      return result.Produce();      return result.Produce();
1533  }  }
1534    
1535  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {
1536      dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel));
1537      LSCPResultSet result;      LSCPResultSet result;
1538        LockRTNotify();
1539      try {      try {
1540          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1541          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1542          // Driver type name aliasing...          // Driver type name aliasing...
1543          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1544          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
# Line 1210  String LSCPServer::SetAudioOutputType(St Line 1560  String LSCPServer::SetAudioOutputType(St
1560          }          }
1561          // Must have a device...          // Must have a device...
1562          if (pDevice == NULL)          if (pDevice == NULL)
1563              throw LinuxSamplerException("Internal error: could not create audio output device.");              throw Exception("Internal error: could not create audio output device.");
1564          // Set it as the current channel device...          // Set it as the current channel device...
1565          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1566      }      }
1567      catch (LinuxSamplerException e) {      catch (Exception e) {
1568           result.Error(e);           result.Error(e);
1569      }      }
1570        UnlockRTNotify();
1571      return result.Produce();      return result.Produce();
1572  }  }
1573    
# Line 1225  String LSCPServer::SetMIDIInputPort(uint Line 1576  String LSCPServer::SetMIDIInputPort(uint
1576      LSCPResultSet result;      LSCPResultSet result;
1577      try {      try {
1578          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1579          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1580          pSamplerChannel->SetMidiInputPort(MIDIPort);          pSamplerChannel->SetMidiInputPort(MIDIPort);
1581      }      }
1582      catch (LinuxSamplerException e) {      catch (Exception e) {
1583           result.Error(e);           result.Error(e);
1584      }      }
1585      return result.Produce();      return result.Produce();
# Line 1239  String LSCPServer::SetMIDIInputChannel(u Line 1590  String LSCPServer::SetMIDIInputChannel(u
1590      LSCPResultSet result;      LSCPResultSet result;
1591      try {      try {
1592          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1593          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1594          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel);
1595      }      }
1596      catch (LinuxSamplerException e) {      catch (Exception e) {
1597           result.Error(e);           result.Error(e);
1598      }      }
1599      return result.Produce();      return result.Produce();
# Line 1253  String LSCPServer::SetMIDIInputDevice(ui Line 1604  String LSCPServer::SetMIDIInputDevice(ui
1604      LSCPResultSet result;      LSCPResultSet result;
1605      try {      try {
1606          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1607          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1608          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1609          if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));          if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1610          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1611          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1612      }      }
1613      catch (LinuxSamplerException e) {      catch (Exception e) {
1614           result.Error(e);           result.Error(e);
1615      }      }
1616      return result.Produce();      return result.Produce();
# Line 1270  String LSCPServer::SetMIDIInputType(Stri Line 1621  String LSCPServer::SetMIDIInputType(Stri
1621      LSCPResultSet result;      LSCPResultSet result;
1622      try {      try {
1623          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1624          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1625          // Driver type name aliasing...          // Driver type name aliasing...
1626          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1627          // Check if there's one MIDI input device already created          // Check if there's one MIDI input device already created
# Line 1294  String LSCPServer::SetMIDIInputType(Stri Line 1645  String LSCPServer::SetMIDIInputType(Stri
1645          }          }
1646          // Must have a device...          // Must have a device...
1647          if (pDevice == NULL)          if (pDevice == NULL)
1648              throw LinuxSamplerException("Internal error: could not create MIDI input device.");              throw Exception("Internal error: could not create MIDI input device.");
1649          // Set it as the current channel device...          // Set it as the current channel device...
1650          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1651      }      }
1652      catch (LinuxSamplerException e) {      catch (Exception e) {
1653           result.Error(e);           result.Error(e);
1654      }      }
1655      return result.Produce();      return result.Produce();
# Line 1313  String LSCPServer::SetMIDIInput(uint MID Line 1664  String LSCPServer::SetMIDIInput(uint MID
1664      LSCPResultSet result;      LSCPResultSet result;
1665      try {      try {
1666          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1667          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1668          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1669          if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));          if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1670          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1671          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel);
1672      }      }
1673      catch (LinuxSamplerException e) {      catch (Exception e) {
1674           result.Error(e);           result.Error(e);
1675      }      }
1676      return result.Produce();      return result.Produce();
# Line 1334  String LSCPServer::SetVolume(double dVol Line 1685  String LSCPServer::SetVolume(double dVol
1685      LSCPResultSet result;      LSCPResultSet result;
1686      try {      try {
1687          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1688          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1689          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1690          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1691          pEngineChannel->Volume(dVolume);          pEngineChannel->Volume(dVolume);
1692      }      }
1693      catch (LinuxSamplerException e) {      catch (Exception e) {
1694           result.Error(e);           result.Error(e);
1695      }      }
1696      return result.Produce();      return result.Produce();
1697  }  }
1698    
1699  /**  /**
1700     * Will be called by the parser to mute/unmute particular sampler channel.
1701     */
1702    String LSCPServer::SetChannelMute(bool bMute, uint uiSamplerChannel) {
1703        dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel));
1704        LSCPResultSet result;
1705        try {
1706            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1707            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1708    
1709            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1710            if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1711    
1712            if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);
1713            else pEngineChannel->SetMute(1);
1714        } catch (Exception e) {
1715            result.Error(e);
1716        }
1717        return result.Produce();
1718    }
1719    
1720    /**
1721     * Will be called by the parser to solo particular sampler channel.
1722     */
1723    String LSCPServer::SetChannelSolo(bool bSolo, uint uiSamplerChannel) {
1724        dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel));
1725        LSCPResultSet result;
1726        try {
1727            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1728            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1729    
1730            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1731            if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1732    
1733            bool oldSolo = pEngineChannel->GetSolo();
1734            bool hadSoloChannel = HasSoloChannel();
1735    
1736            pEngineChannel->SetSolo(bSolo);
1737    
1738            if(!oldSolo && bSolo) {
1739                if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0);
1740                if(!hadSoloChannel) MuteNonSoloChannels();
1741            }
1742    
1743            if(oldSolo && !bSolo) {
1744                if(!HasSoloChannel()) UnmuteChannels();
1745                else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1);
1746            }
1747        } catch (Exception e) {
1748            result.Error(e);
1749        }
1750        return result.Produce();
1751    }
1752    
1753    /**
1754     * Determines whether there is at least one solo channel in the channel list.
1755     *
1756     * @returns true if there is at least one solo channel in the channel list,
1757     * false otherwise.
1758     */
1759    bool LSCPServer::HasSoloChannel() {
1760        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
1761        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
1762        for (; iter != channels.end(); iter++) {
1763            EngineChannel* c = iter->second->GetEngineChannel();
1764            if(c && c->GetSolo()) return true;
1765        }
1766    
1767        return false;
1768    }
1769    
1770    /**
1771     * Mutes all unmuted non-solo channels. Notice that the channels are muted
1772     * with -1 which indicates that they are muted because of the presence
1773     * of a solo channel(s). Channels muted with -1 will be automatically unmuted
1774     * when there are no solo channels left.
1775     */
1776    void LSCPServer::MuteNonSoloChannels() {
1777        dmsg(2,("LSCPServer: MuteNonSoloChannels()\n"));
1778        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
1779        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
1780        for (; iter != channels.end(); iter++) {
1781            EngineChannel* c = iter->second->GetEngineChannel();
1782            if(c && !c->GetSolo() && !c->GetMute()) c->SetMute(-1);
1783        }
1784    }
1785    
1786    /**
1787     * Unmutes all channels that are muted because of the presence
1788     * of a solo channel(s).
1789     */
1790    void  LSCPServer::UnmuteChannels() {
1791        dmsg(2,("LSCPServer: UnmuteChannels()\n"));
1792        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
1793        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
1794        for (; iter != channels.end(); iter++) {
1795            EngineChannel* c = iter->second->GetEngineChannel();
1796            if(c && c->GetMute() == -1) c->SetMute(0);
1797        }
1798    }
1799    
1800    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) {
1801        dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n"));
1802    
1803        midi_prog_index_t idx;
1804        idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1805        idx.midi_bank_lsb = MidiBank & 0x7f;
1806        idx.midi_prog     = MidiProg;
1807    
1808        MidiInstrumentMapper::entry_t entry;
1809        entry.EngineName      = EngineType;
1810        entry.InstrumentFile  = InstrumentFile;
1811        entry.InstrumentIndex = InstrumentIndex;
1812        entry.LoadMode        = LoadMode;
1813        entry.Volume          = Volume;
1814        entry.Name            = Name;
1815    
1816        LSCPResultSet result;
1817        try {
1818            // PERSISTENT mapping commands might block for a long time, so in
1819            // that case we add/replace the mapping in another thread in case
1820            // the NON_MODAL argument was supplied, non persistent mappings
1821            // should return immediately, so we don't need to do that for them
1822            bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT && !bModal);
1823            MidiInstrumentMapper::AddOrReplaceEntry(MidiMapID, idx, entry, bInBackground);
1824        } catch (Exception e) {
1825            result.Error(e);
1826        }
1827        return result.Produce();
1828    }
1829    
1830    String LSCPServer::RemoveMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) {
1831        dmsg(2,("LSCPServer: RemoveMIDIInstrumentMapping()\n"));
1832    
1833        midi_prog_index_t idx;
1834        idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1835        idx.midi_bank_lsb = MidiBank & 0x7f;
1836        idx.midi_prog     = MidiProg;
1837    
1838        LSCPResultSet result;
1839        try {
1840            MidiInstrumentMapper::RemoveEntry(MidiMapID, idx);
1841        } catch (Exception e) {
1842            result.Error(e);
1843        }
1844        return result.Produce();
1845    }
1846    
1847    String LSCPServer::GetMidiInstrumentMappings(uint MidiMapID) {
1848        dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n"));
1849        LSCPResultSet result;
1850        try {
1851            result.Add(MidiInstrumentMapper::Entries(MidiMapID).size());
1852        } catch (Exception e) {
1853            result.Error(e);
1854        }
1855        return result.Produce();
1856    }
1857    
1858    
1859    String LSCPServer::GetAllMidiInstrumentMappings() {
1860        dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n"));
1861        LSCPResultSet result;
1862        std::vector<int> maps = MidiInstrumentMapper::Maps();
1863        int totalMappings = 0;
1864        for (int i = 0; i < maps.size(); i++) {
1865            try {
1866                totalMappings += MidiInstrumentMapper::Entries(maps[i]).size();
1867            } catch (Exception e) { /*NOOP*/ }
1868        }
1869        result.Add(totalMappings);
1870        return result.Produce();
1871    }
1872    
1873    String LSCPServer::GetMidiInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) {
1874        dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n"));
1875        LSCPResultSet result;
1876        try {
1877            midi_prog_index_t idx;
1878            idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;
1879            idx.midi_bank_lsb = MidiBank & 0x7f;
1880            idx.midi_prog     = MidiProg;
1881    
1882            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID);
1883            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx);
1884            if (iter == mappings.end()) result.Error("there is no map entry with that index");
1885            else { // found
1886    
1887                // convert the filename into the correct encoding as defined for LSCP
1888                // (especially in terms of special characters -> escape sequences)
1889    #if WIN32
1890                const String instrumentFileName = Path::fromWindows(iter->second.InstrumentFile).toLscp();
1891    #else
1892                // assuming POSIX
1893                const String instrumentFileName = Path::fromPosix(iter->second.InstrumentFile).toLscp();
1894    #endif
1895    
1896                result.Add("NAME", _escapeLscpResponse(iter->second.Name));
1897                result.Add("ENGINE_NAME", iter->second.EngineName);
1898                result.Add("INSTRUMENT_FILE", instrumentFileName);
1899                result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex);
1900                String instrumentName;
1901                Engine* pEngine = EngineFactory::Create(iter->second.EngineName);
1902                if (pEngine) {
1903                    if (pEngine->GetInstrumentManager()) {
1904                        InstrumentManager::instrument_id_t instrID;
1905                        instrID.FileName = iter->second.InstrumentFile;
1906                        instrID.Index    = iter->second.InstrumentIndex;
1907                        instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID);
1908                    }
1909                    EngineFactory::Destroy(pEngine);
1910                }
1911                result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName));
1912                switch (iter->second.LoadMode) {
1913                    case MidiInstrumentMapper::ON_DEMAND:
1914                        result.Add("LOAD_MODE", "ON_DEMAND");
1915                        break;
1916                    case MidiInstrumentMapper::ON_DEMAND_HOLD:
1917                        result.Add("LOAD_MODE", "ON_DEMAND_HOLD");
1918                        break;
1919                    case MidiInstrumentMapper::PERSISTENT:
1920                        result.Add("LOAD_MODE", "PERSISTENT");
1921                        break;
1922                    default:
1923                        throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!");
1924                }
1925                result.Add("VOLUME", iter->second.Volume);
1926            }
1927        } catch (Exception e) {
1928            result.Error(e);
1929        }
1930        return result.Produce();
1931    }
1932    
1933    String LSCPServer::ListMidiInstrumentMappings(uint MidiMapID) {
1934        dmsg(2,("LSCPServer: ListMidiInstrumentMappings()\n"));
1935        LSCPResultSet result;
1936        try {
1937            String s;
1938            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID);
1939            std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();
1940            for (; iter != mappings.end(); iter++) {
1941                if (s.size()) s += ",";
1942                s += "{" + ToString(MidiMapID) + ","
1943                         + ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + ","
1944                         + ToString(int(iter->first.midi_prog)) + "}";
1945            }
1946            result.Add(s);
1947        } catch (Exception e) {
1948            result.Error(e);
1949        }
1950        return result.Produce();
1951    }
1952    
1953    String LSCPServer::ListAllMidiInstrumentMappings() {
1954        dmsg(2,("LSCPServer: ListAllMidiInstrumentMappings()\n"));
1955        LSCPResultSet result;
1956        try {
1957            std::vector<int> maps = MidiInstrumentMapper::Maps();
1958            String s;
1959            for (int i = 0; i < maps.size(); i++) {
1960                std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(maps[i]);
1961                std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin();
1962                for (; iter != mappings.end(); iter++) {
1963                    if (s.size()) s += ",";
1964                    s += "{" + ToString(maps[i]) + ","
1965                             + ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + ","
1966                             + ToString(int(iter->first.midi_prog)) + "}";
1967                }
1968            }
1969            result.Add(s);
1970        } catch (Exception e) {
1971            result.Error(e);
1972        }
1973        return result.Produce();
1974    }
1975    
1976    String LSCPServer::ClearMidiInstrumentMappings(uint MidiMapID) {
1977        dmsg(2,("LSCPServer: ClearMidiInstrumentMappings()\n"));
1978        LSCPResultSet result;
1979        try {
1980            MidiInstrumentMapper::RemoveAllEntries(MidiMapID);
1981        } catch (Exception e) {
1982            result.Error(e);
1983        }
1984        return result.Produce();
1985    }
1986    
1987    String LSCPServer::ClearAllMidiInstrumentMappings() {
1988        dmsg(2,("LSCPServer: ClearAllMidiInstrumentMappings()\n"));
1989        LSCPResultSet result;
1990        try {
1991            std::vector<int> maps = MidiInstrumentMapper::Maps();
1992            for (int i = 0; i < maps.size(); i++)
1993                MidiInstrumentMapper::RemoveAllEntries(maps[i]);
1994        } catch (Exception e) {
1995            result.Error(e);
1996        }
1997        return result.Produce();
1998    }
1999    
2000    String LSCPServer::AddMidiInstrumentMap(String MapName) {
2001        dmsg(2,("LSCPServer: AddMidiInstrumentMap()\n"));
2002        LSCPResultSet result;
2003        try {
2004            int MapID = MidiInstrumentMapper::AddMap(MapName);
2005            result = LSCPResultSet(MapID);
2006        } catch (Exception e) {
2007            result.Error(e);
2008        }
2009        return result.Produce();
2010    }
2011    
2012    String LSCPServer::RemoveMidiInstrumentMap(uint MidiMapID) {
2013        dmsg(2,("LSCPServer: RemoveMidiInstrumentMap()\n"));
2014        LSCPResultSet result;
2015        try {
2016            MidiInstrumentMapper::RemoveMap(MidiMapID);
2017        } catch (Exception e) {
2018            result.Error(e);
2019        }
2020        return result.Produce();
2021    }
2022    
2023    String LSCPServer::RemoveAllMidiInstrumentMaps() {
2024        dmsg(2,("LSCPServer: RemoveAllMidiInstrumentMaps()\n"));
2025        LSCPResultSet result;
2026        try {
2027            MidiInstrumentMapper::RemoveAllMaps();
2028        } catch (Exception e) {
2029            result.Error(e);
2030        }
2031        return result.Produce();
2032    }
2033    
2034    String LSCPServer::GetMidiInstrumentMaps() {
2035        dmsg(2,("LSCPServer: GetMidiInstrumentMaps()\n"));
2036        LSCPResultSet result;
2037        try {
2038            result.Add(MidiInstrumentMapper::Maps().size());
2039        } catch (Exception e) {
2040            result.Error(e);
2041        }
2042        return result.Produce();
2043    }
2044    
2045    String LSCPServer::ListMidiInstrumentMaps() {
2046        dmsg(2,("LSCPServer: ListMidiInstrumentMaps()\n"));
2047        LSCPResultSet result;
2048        try {
2049            std::vector<int> maps = MidiInstrumentMapper::Maps();
2050            String sList;
2051            for (int i = 0; i < maps.size(); i++) {
2052                if (sList != "") sList += ",";
2053                sList += ToString(maps[i]);
2054            }
2055            result.Add(sList);
2056        } catch (Exception e) {
2057            result.Error(e);
2058        }
2059        return result.Produce();
2060    }
2061    
2062    String LSCPServer::GetMidiInstrumentMap(uint MidiMapID) {
2063        dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n"));
2064        LSCPResultSet result;
2065        try {
2066            result.Add("NAME", _escapeLscpResponse(MidiInstrumentMapper::MapName(MidiMapID)));
2067            result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID);
2068        } catch (Exception e) {
2069            result.Error(e);
2070        }
2071        return result.Produce();
2072    }
2073    
2074    String LSCPServer::SetMidiInstrumentMapName(uint MidiMapID, String NewName) {
2075        dmsg(2,("LSCPServer: SetMidiInstrumentMapName()\n"));
2076        LSCPResultSet result;
2077        try {
2078            MidiInstrumentMapper::RenameMap(MidiMapID, NewName);
2079        } catch (Exception e) {
2080            result.Error(e);
2081        }
2082        return result.Produce();
2083    }
2084    
2085    /**
2086     * Set the MIDI instrument map the given sampler channel shall use for
2087     * handling MIDI program change messages. There are the following two
2088     * special (negative) values:
2089     *
2090     *    - (-1) :  set to NONE (ignore program changes)
2091     *    - (-2) :  set to DEFAULT map
2092     */
2093    String LSCPServer::SetChannelMap(uint uiSamplerChannel, int MidiMapID) {
2094        dmsg(2,("LSCPServer: SetChannelMap()\n"));
2095        LSCPResultSet result;
2096        try {
2097            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2098            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2099    
2100            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2101            if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
2102    
2103            if      (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone();
2104            else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault();
2105            else                      pEngineChannel->SetMidiInstrumentMap(MidiMapID);
2106        } catch (Exception e) {
2107            result.Error(e);
2108        }
2109        return result.Produce();
2110    }
2111    
2112    String LSCPServer::CreateFxSend(uint uiSamplerChannel, uint MidiCtrl, String Name) {
2113        dmsg(2,("LSCPServer: CreateFxSend()\n"));
2114        LSCPResultSet result;
2115        try {
2116            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2117    
2118            FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name);
2119            if (!pFxSend) throw Exception("Could not add FxSend, don't ask, I don't know why (probably a bug)");
2120    
2121            result = LSCPResultSet(pFxSend->Id()); // success
2122        } catch (Exception e) {
2123            result.Error(e);
2124        }
2125        return result.Produce();
2126    }
2127    
2128    String LSCPServer::DestroyFxSend(uint uiSamplerChannel, uint FxSendID) {
2129        dmsg(2,("LSCPServer: DestroyFxSend()\n"));
2130        LSCPResultSet result;
2131        try {
2132            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2133    
2134            FxSend* pFxSend = NULL;
2135            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2136                if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2137                    pFxSend = pEngineChannel->GetFxSend(i);
2138                    break;
2139                }
2140            }
2141            if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2142            pEngineChannel->RemoveFxSend(pFxSend);
2143        } catch (Exception e) {
2144            result.Error(e);
2145        }
2146        return result.Produce();
2147    }
2148    
2149    String LSCPServer::GetFxSends(uint uiSamplerChannel) {
2150        dmsg(2,("LSCPServer: GetFxSends()\n"));
2151        LSCPResultSet result;
2152        try {
2153            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2154    
2155            result.Add(pEngineChannel->GetFxSendCount());
2156        } catch (Exception e) {
2157            result.Error(e);
2158        }
2159        return result.Produce();
2160    }
2161    
2162    String LSCPServer::ListFxSends(uint uiSamplerChannel) {
2163        dmsg(2,("LSCPServer: ListFxSends()\n"));
2164        LSCPResultSet result;
2165        String list;
2166        try {
2167            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2168    
2169            for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2170                FxSend* pFxSend = pEngineChannel->GetFxSend(i);
2171                if (list != "") list += ",";
2172                list += ToString(pFxSend->Id());
2173            }
2174            result.Add(list);
2175        } catch (Exception e) {
2176            result.Error(e);
2177        }
2178        return result.Produce();
2179    }
2180    
2181    FxSend* LSCPServer::GetFxSend(uint uiSamplerChannel, uint FxSendID) {
2182        EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2183    
2184        FxSend* pFxSend = NULL;
2185        for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2186            if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2187                pFxSend = pEngineChannel->GetFxSend(i);
2188                break;
2189            }
2190        }
2191        if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2192        return pFxSend;
2193    }
2194    
2195    String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) {
2196        dmsg(2,("LSCPServer: GetFxSendInfo()\n"));
2197        LSCPResultSet result;
2198        try {
2199            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2200            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2201    
2202            // gather audio routing informations
2203            String AudioRouting;
2204            for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
2205                if (AudioRouting != "") AudioRouting += ",";
2206                AudioRouting += ToString(pFxSend->DestinationChannel(chan));
2207            }
2208    
2209            // success
2210            result.Add("NAME", _escapeLscpResponse(pFxSend->Name()));
2211            result.Add("MIDI_CONTROLLER", pFxSend->MidiController());
2212            result.Add("LEVEL", ToString(pFxSend->Level()));
2213            result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
2214        } catch (Exception e) {
2215            result.Error(e);
2216        }
2217        return result.Produce();
2218    }
2219    
2220    String LSCPServer::SetFxSendName(uint uiSamplerChannel, uint FxSendID, String Name) {
2221        dmsg(2,("LSCPServer: SetFxSendName()\n"));
2222        LSCPResultSet result;
2223        try {
2224            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2225    
2226            pFxSend->SetName(Name);
2227            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2228        } catch (Exception e) {
2229            result.Error(e);
2230        }
2231        return result.Produce();
2232    }
2233    
2234    String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) {
2235        dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n"));
2236        LSCPResultSet result;
2237        try {
2238            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2239    
2240            pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel);
2241            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2242        } catch (Exception e) {
2243            result.Error(e);
2244        }
2245        return result.Produce();
2246    }
2247    
2248    String LSCPServer::SetFxSendMidiController(uint uiSamplerChannel, uint FxSendID, uint MidiController) {
2249        dmsg(2,("LSCPServer: SetFxSendMidiController()\n"));
2250        LSCPResultSet result;
2251        try {
2252            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2253    
2254            pFxSend->SetMidiController(MidiController);
2255            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2256        } catch (Exception e) {
2257            result.Error(e);
2258        }
2259        return result.Produce();
2260    }
2261    
2262    String LSCPServer::SetFxSendLevel(uint uiSamplerChannel, uint FxSendID, double dLevel) {
2263        dmsg(2,("LSCPServer: SetFxSendLevel()\n"));
2264        LSCPResultSet result;
2265        try {
2266            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2267    
2268            pFxSend->SetLevel((float)dLevel);
2269            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2270        } catch (Exception e) {
2271            result.Error(e);
2272        }
2273        return result.Produce();
2274    }
2275    
2276    String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) {
2277        dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel));
2278        LSCPResultSet result;
2279        try {
2280            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2281            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2282            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2283            if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
2284            if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel");
2285            Engine* pEngine = pEngineChannel->GetEngine();
2286            InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager();
2287            if (!pInstrumentManager) throw Exception("Engine does not provide an instrument manager");
2288            InstrumentManager::instrument_id_t instrumentID;
2289            instrumentID.FileName = pEngineChannel->InstrumentFileName();
2290            instrumentID.Index    = pEngineChannel->InstrumentIndex();
2291            pInstrumentManager->LaunchInstrumentEditor(instrumentID);
2292        } catch (Exception e) {
2293            result.Error(e);
2294        }
2295        return result.Produce();
2296    }
2297    
2298    /**
2299   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
2300   */   */
2301  String LSCPServer::ResetChannel(uint uiSamplerChannel) {  String LSCPServer::ResetChannel(uint uiSamplerChannel) {
# Line 1353  String LSCPServer::ResetChannel(uint uiS Line 2303  String LSCPServer::ResetChannel(uint uiS
2303      LSCPResultSet result;      LSCPResultSet result;
2304      try {      try {
2305          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2306          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2307          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2308          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
2309          pEngineChannel->GetEngine()->Reset();          pEngineChannel->Reset();
2310      }      }
2311      catch (LinuxSamplerException e) {      catch (Exception e) {
2312           result.Error(e);           result.Error(e);
2313      }      }
2314      return result.Produce();      return result.Produce();
# Line 1375  String LSCPServer::ResetSampler() { Line 2325  String LSCPServer::ResetSampler() {
2325  }  }
2326    
2327  /**  /**
2328     * Will be called by the parser to return general informations about this
2329     * sampler.
2330     */
2331    String LSCPServer::GetServerInfo() {
2332        dmsg(2,("LSCPServer: GetServerInfo()\n"));
2333        const std::string description =
2334            _escapeLscpResponse("LinuxSampler - modular, streaming capable sampler");
2335        LSCPResultSet result;
2336        result.Add("DESCRIPTION", description);
2337        result.Add("VERSION", VERSION);
2338        result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR));
2339    #if HAVE_SQLITE3
2340        result.Add("INSTRUMENTS_DB_SUPPORT", "yes");
2341    #else
2342        result.Add("INSTRUMENTS_DB_SUPPORT", "no");
2343    #endif
2344    
2345        return result.Produce();
2346    }
2347    
2348    /**
2349     * Will be called by the parser to return the current number of all active voices.
2350     */
2351    String LSCPServer::GetTotalVoiceCount() {
2352        dmsg(2,("LSCPServer: GetTotalVoiceCount()\n"));
2353        LSCPResultSet result;
2354        result.Add(pSampler->GetVoiceCount());
2355        return result.Produce();
2356    }
2357    
2358    /**
2359     * Will be called by the parser to return the maximum number of voices.
2360     */
2361    String LSCPServer::GetTotalVoiceCountMax() {
2362        dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));
2363        LSCPResultSet result;
2364        result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES);
2365        return result.Produce();
2366    }
2367    
2368    String LSCPServer::GetGlobalVolume() {
2369        LSCPResultSet result;
2370        result.Add(ToString(GLOBAL_VOLUME)); // see common/global.cpp
2371        return result.Produce();
2372    }
2373    
2374    String LSCPServer::SetGlobalVolume(double dVolume) {
2375        LSCPResultSet result;
2376        try {
2377            if (dVolume < 0) throw Exception("Volume may not be negative");
2378            GLOBAL_VOLUME = dVolume; // see common/global.cpp
2379            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME));
2380        } catch (Exception e) {
2381            result.Error(e);
2382        }
2383        return result.Produce();
2384    }
2385    
2386    /**
2387   * 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
2388   * server for receiving event messages.   * server for receiving event messages.
2389   */   */
# Line 1400  String LSCPServer::UnsubscribeNotificati Line 2409  String LSCPServer::UnsubscribeNotificati
2409      return result.Produce();      return result.Produce();
2410  }  }
2411    
2412  static int select_callback(void * lscpResultSet, int argc,  String LSCPServer::AddDbInstrumentDirectory(String Dir) {
2413                          char **argv, char **azColName)      dmsg(2,("LSCPServer: AddDbInstrumentDirectory(Dir=%s)\n", Dir.c_str()));
2414  {      LSCPResultSet result;
2415      LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet;  #if HAVE_SQLITE3
2416      resultSet->Add(argc, argv);      try {
2417      return 0;          InstrumentsDb::GetInstrumentsDb()->AddDirectory(Dir);
2418        } catch (Exception e) {
2419             result.Error(e);
2420        }
2421    #else
2422        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2423    #endif
2424        return result.Produce();
2425    }
2426    
2427    String LSCPServer::RemoveDbInstrumentDirectory(String Dir, bool Force) {
2428        dmsg(2,("LSCPServer: RemoveDbInstrumentDirectory(Dir=%s,Force=%d)\n", Dir.c_str(), Force));
2429        LSCPResultSet result;
2430    #if HAVE_SQLITE3
2431        try {
2432            InstrumentsDb::GetInstrumentsDb()->RemoveDirectory(Dir, Force);
2433        } catch (Exception e) {
2434             result.Error(e);
2435        }
2436    #else
2437        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2438    #endif
2439        return result.Produce();
2440  }  }
2441    
2442  String LSCPServer::QueryDatabase(String query) {  String LSCPServer::GetDbInstrumentDirectoryCount(String Dir, bool Recursive) {
2443        dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2444      LSCPResultSet result;      LSCPResultSet result;
2445  #if HAVE_SQLITE3  #if HAVE_SQLITE3
2446      char* zErrMsg = NULL;      try {
2447      sqlite3 *db;          result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir, Recursive));
2448      String selectStr = "SELECT " + query;      } catch (Exception e) {
2449             result.Error(e);
2450        }
2451    #else
2452        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2453    #endif
2454        return result.Produce();
2455    }
2456    
2457      int rc = sqlite3_open("linuxsampler.db", &db);  String LSCPServer::GetDbInstrumentDirectories(String Dir, bool Recursive) {
2458      if (rc == SQLITE_OK)      dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2459      {      LSCPResultSet result;
2460              rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg);  #if HAVE_SQLITE3
2461        try {
2462            String list;
2463            StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir, Recursive);
2464    
2465            for (int i = 0; i < dirs->size(); i++) {
2466                if (list != "") list += ",";
2467                list += "'" + InstrumentsDb::toEscapedPath(dirs->at(i)) + "'";
2468            }
2469    
2470            result.Add(list);
2471        } catch (Exception e) {
2472             result.Error(e);
2473      }      }
2474      if ( rc != SQLITE_OK )  #else
2475      {      result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2476              result.Error(String(zErrMsg), rc);  #endif
2477        return result.Produce();
2478    }
2479    
2480    String LSCPServer::GetDbInstrumentDirectoryInfo(String Dir) {
2481        dmsg(2,("LSCPServer: GetDbInstrumentDirectoryInfo(Dir=%s)\n", Dir.c_str()));
2482        LSCPResultSet result;
2483    #if HAVE_SQLITE3
2484        try {
2485            DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir);
2486    
2487            result.Add("DESCRIPTION", _escapeLscpResponse(info.Description));
2488            result.Add("CREATED", info.Created);
2489            result.Add("MODIFIED", info.Modified);
2490        } catch (Exception e) {
2491             result.Error(e);
2492        }
2493    #else
2494        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2495    #endif
2496        return result.Produce();
2497    }
2498    
2499    String LSCPServer::SetDbInstrumentDirectoryName(String Dir, String Name) {
2500        dmsg(2,("LSCPServer: SetDbInstrumentDirectoryName(Dir=%s,Name=%s)\n", Dir.c_str(), Name.c_str()));
2501        LSCPResultSet result;
2502    #if HAVE_SQLITE3
2503        try {
2504            InstrumentsDb::GetInstrumentsDb()->RenameDirectory(Dir, Name);
2505        } catch (Exception e) {
2506             result.Error(e);
2507      }      }
     sqlite3_close(db);  
2508  #else  #else
2509      result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0);      result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2510  #endif  #endif
2511      return result.Produce();      return result.Produce();
2512  }  }
2513    
2514    String LSCPServer::MoveDbInstrumentDirectory(String Dir, String Dst) {
2515        dmsg(2,("LSCPServer: MoveDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str()));
2516        LSCPResultSet result;
2517    #if HAVE_SQLITE3
2518        try {
2519            InstrumentsDb::GetInstrumentsDb()->MoveDirectory(Dir, Dst);
2520        } catch (Exception e) {
2521             result.Error(e);
2522        }
2523    #else
2524        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2525    #endif
2526        return result.Produce();
2527    }
2528    
2529    String LSCPServer::CopyDbInstrumentDirectory(String Dir, String Dst) {
2530        dmsg(2,("LSCPServer: CopyDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str()));
2531        LSCPResultSet result;
2532    #if HAVE_SQLITE3
2533        try {
2534            InstrumentsDb::GetInstrumentsDb()->CopyDirectory(Dir, Dst);
2535        } catch (Exception e) {
2536             result.Error(e);
2537        }
2538    #else
2539        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2540    #endif
2541        return result.Produce();
2542    }
2543    
2544    String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) {
2545        dmsg(2,("LSCPServer: SetDbInstrumentDirectoryDescription(Dir=%s,Desc=%s)\n", Dir.c_str(), Desc.c_str()));
2546        LSCPResultSet result;
2547    #if HAVE_SQLITE3
2548        try {
2549            InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc);
2550        } catch (Exception e) {
2551             result.Error(e);
2552        }
2553    #else
2554        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2555    #endif
2556        return result.Produce();
2557    }
2558    
2559    String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index, bool bBackground) {
2560        dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d,bBackground=%d)\n", DbDir.c_str(), FilePath.c_str(), Index, bBackground));
2561        LSCPResultSet result;
2562    #if HAVE_SQLITE3
2563        try {
2564            int id;
2565            InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();
2566            id = db->AddInstruments(DbDir, FilePath, Index, bBackground);
2567            if (bBackground) result = id;
2568        } catch (Exception e) {
2569             result.Error(e);
2570        }
2571    #else
2572        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2573    #endif
2574        return result.Produce();
2575    }
2576    
2577    String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) {
2578        dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground));
2579        LSCPResultSet result;
2580    #if HAVE_SQLITE3
2581        try {
2582            int id;
2583            InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();
2584            if (ScanMode.compare("RECURSIVE") == 0) {
2585               id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground);
2586            } else if (ScanMode.compare("NON_RECURSIVE") == 0) {
2587               id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground);
2588            } else if (ScanMode.compare("FLAT") == 0) {
2589               id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground);
2590            } else {
2591                throw Exception("Unknown scan mode: " + ScanMode);
2592            }
2593    
2594            if (bBackground) result = id;
2595        } catch (Exception e) {
2596             result.Error(e);
2597        }
2598    #else
2599        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2600    #endif
2601        return result.Produce();
2602    }
2603    
2604    String LSCPServer::RemoveDbInstrument(String Instr) {
2605        dmsg(2,("LSCPServer: RemoveDbInstrument(Instr=%s)\n", Instr.c_str()));
2606        LSCPResultSet result;
2607    #if HAVE_SQLITE3
2608        try {
2609            InstrumentsDb::GetInstrumentsDb()->RemoveInstrument(Instr);
2610        } catch (Exception e) {
2611             result.Error(e);
2612        }
2613    #else
2614        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2615    #endif
2616        return result.Produce();
2617    }
2618    
2619    String LSCPServer::GetDbInstrumentCount(String Dir, bool Recursive) {
2620        dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2621        LSCPResultSet result;
2622    #if HAVE_SQLITE3
2623        try {
2624            result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir, Recursive));
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::GetDbInstruments(String Dir, bool Recursive) {
2635        dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2636        LSCPResultSet result;
2637    #if HAVE_SQLITE3
2638        try {
2639            String list;
2640            StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir, Recursive);
2641    
2642            for (int i = 0; i < instrs->size(); i++) {
2643                if (list != "") list += ",";
2644                list += "'" + InstrumentsDb::toEscapedPath(instrs->at(i)) + "'";
2645            }
2646    
2647            result.Add(list);
2648        } catch (Exception e) {
2649             result.Error(e);
2650        }
2651    #else
2652        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2653    #endif
2654        return result.Produce();
2655    }
2656    
2657    String LSCPServer::GetDbInstrumentInfo(String Instr) {
2658        dmsg(2,("LSCPServer: GetDbInstrumentInfo(Instr=%s)\n", Instr.c_str()));
2659        LSCPResultSet result;
2660    #if HAVE_SQLITE3
2661        try {
2662            DbInstrument info = InstrumentsDb::GetInstrumentsDb()->GetInstrumentInfo(Instr);
2663    
2664            result.Add("INSTRUMENT_FILE", info.InstrFile);
2665            result.Add("INSTRUMENT_NR", info.InstrNr);
2666            result.Add("FORMAT_FAMILY", info.FormatFamily);
2667            result.Add("FORMAT_VERSION", info.FormatVersion);
2668            result.Add("SIZE", (int)info.Size);
2669            result.Add("CREATED", info.Created);
2670            result.Add("MODIFIED", info.Modified);
2671            result.Add("DESCRIPTION", _escapeLscpResponse(info.Description));
2672            result.Add("IS_DRUM", info.IsDrum);
2673            result.Add("PRODUCT", _escapeLscpResponse(info.Product));
2674            result.Add("ARTISTS", _escapeLscpResponse(info.Artists));
2675            result.Add("KEYWORDS", _escapeLscpResponse(info.Keywords));
2676        } catch (Exception e) {
2677             result.Error(e);
2678        }
2679    #else
2680        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2681    #endif
2682        return result.Produce();
2683    }
2684    
2685    String LSCPServer::GetDbInstrumentsJobInfo(int JobId) {
2686        dmsg(2,("LSCPServer: GetDbInstrumentsJobInfo(JobId=%d)\n", JobId));
2687        LSCPResultSet result;
2688    #if HAVE_SQLITE3
2689        try {
2690            ScanJob job = InstrumentsDb::GetInstrumentsDb()->Jobs.GetJobById(JobId);
2691    
2692            result.Add("FILES_TOTAL", job.FilesTotal);
2693            result.Add("FILES_SCANNED", job.FilesScanned);
2694            result.Add("SCANNING", job.Scanning);
2695            result.Add("STATUS", job.Status);
2696        } catch (Exception e) {
2697             result.Error(e);
2698        }
2699    #else
2700        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2701    #endif
2702        return result.Produce();
2703    }
2704    
2705    String LSCPServer::SetDbInstrumentName(String Instr, String Name) {
2706        dmsg(2,("LSCPServer: SetDbInstrumentName(Instr=%s,Name=%s)\n", Instr.c_str(), Name.c_str()));
2707        LSCPResultSet result;
2708    #if HAVE_SQLITE3
2709        try {
2710            InstrumentsDb::GetInstrumentsDb()->RenameInstrument(Instr, Name);
2711        } catch (Exception e) {
2712             result.Error(e);
2713        }
2714    #else
2715        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2716    #endif
2717        return result.Produce();
2718    }
2719    
2720    String LSCPServer::MoveDbInstrument(String Instr, String Dst) {
2721        dmsg(2,("LSCPServer: MoveDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str()));
2722        LSCPResultSet result;
2723    #if HAVE_SQLITE3
2724        try {
2725            InstrumentsDb::GetInstrumentsDb()->MoveInstrument(Instr, Dst);
2726        } catch (Exception e) {
2727             result.Error(e);
2728        }
2729    #else
2730        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2731    #endif
2732        return result.Produce();
2733    }
2734    
2735    String LSCPServer::CopyDbInstrument(String Instr, String Dst) {
2736        dmsg(2,("LSCPServer: CopyDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str()));
2737        LSCPResultSet result;
2738    #if HAVE_SQLITE3
2739        try {
2740            InstrumentsDb::GetInstrumentsDb()->CopyInstrument(Instr, Dst);
2741        } catch (Exception e) {
2742             result.Error(e);
2743        }
2744    #else
2745        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2746    #endif
2747        return result.Produce();
2748    }
2749    
2750    String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) {
2751        dmsg(2,("LSCPServer: SetDbInstrumentDescription(Instr=%s,Desc=%s)\n", Instr.c_str(), Desc.c_str()));
2752        LSCPResultSet result;
2753    #if HAVE_SQLITE3
2754        try {
2755            InstrumentsDb::GetInstrumentsDb()->SetInstrumentDescription(Instr, Desc);
2756        } catch (Exception e) {
2757             result.Error(e);
2758        }
2759    #else
2760        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2761    #endif
2762        return result.Produce();
2763    }
2764    
2765    String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) {
2766        dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str()));
2767        LSCPResultSet result;
2768    #if HAVE_SQLITE3
2769        try {
2770            SearchQuery Query;
2771            std::map<String,String>::iterator iter;
2772            for (iter = Parameters.begin(); iter != Parameters.end(); iter++) {
2773                if (iter->first.compare("NAME") == 0) {
2774                    Query.Name = iter->second;
2775                } else if (iter->first.compare("CREATED") == 0) {
2776                    Query.SetCreated(iter->second);
2777                } else if (iter->first.compare("MODIFIED") == 0) {
2778                    Query.SetModified(iter->second);
2779                } else if (iter->first.compare("DESCRIPTION") == 0) {
2780                    Query.Description = iter->second;
2781                } else {
2782                    throw Exception("Unknown search criteria: " + iter->first);
2783                }
2784            }
2785    
2786            String list;
2787            StringListPtr pDirectories =
2788                InstrumentsDb::GetInstrumentsDb()->FindDirectories(Dir, &Query, Recursive);
2789    
2790            for (int i = 0; i < pDirectories->size(); i++) {
2791                if (list != "") list += ",";
2792                list += "'" + InstrumentsDb::toEscapedPath(pDirectories->at(i)) + "'";
2793            }
2794    
2795            result.Add(list);
2796        } catch (Exception e) {
2797             result.Error(e);
2798        }
2799    #else
2800        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2801    #endif
2802        return result.Produce();
2803    }
2804    
2805    String LSCPServer::FindDbInstruments(String Dir, std::map<String,String> Parameters, bool Recursive) {
2806        dmsg(2,("LSCPServer: FindDbInstruments(Dir=%s)\n", Dir.c_str()));
2807        LSCPResultSet result;
2808    #if HAVE_SQLITE3
2809        try {
2810            SearchQuery Query;
2811            std::map<String,String>::iterator iter;
2812            for (iter = Parameters.begin(); iter != Parameters.end(); iter++) {
2813                if (iter->first.compare("NAME") == 0) {
2814                    Query.Name = iter->second;
2815                } else if (iter->first.compare("FORMAT_FAMILIES") == 0) {
2816                    Query.SetFormatFamilies(iter->second);
2817                } else if (iter->first.compare("SIZE") == 0) {
2818                    Query.SetSize(iter->second);
2819                } else if (iter->first.compare("CREATED") == 0) {
2820                    Query.SetCreated(iter->second);
2821                } else if (iter->first.compare("MODIFIED") == 0) {
2822                    Query.SetModified(iter->second);
2823                } else if (iter->first.compare("DESCRIPTION") == 0) {
2824                    Query.Description = iter->second;
2825                } else if (iter->first.compare("IS_DRUM") == 0) {
2826                    if (!strcasecmp(iter->second.c_str(), "true")) {
2827                        Query.InstrType = SearchQuery::DRUM;
2828                    } else {
2829                        Query.InstrType = SearchQuery::CHROMATIC;
2830                    }
2831                } else if (iter->first.compare("PRODUCT") == 0) {
2832                     Query.Product = iter->second;
2833                } else if (iter->first.compare("ARTISTS") == 0) {
2834                     Query.Artists = iter->second;
2835                } else if (iter->first.compare("KEYWORDS") == 0) {
2836                     Query.Keywords = iter->second;
2837                } else {
2838                    throw Exception("Unknown search criteria: " + iter->first);
2839                }
2840            }
2841    
2842            String list;
2843            StringListPtr pInstruments =
2844                InstrumentsDb::GetInstrumentsDb()->FindInstruments(Dir, &Query, Recursive);
2845    
2846            for (int i = 0; i < pInstruments->size(); i++) {
2847                if (list != "") list += ",";
2848                list += "'" + InstrumentsDb::toEscapedPath(pInstruments->at(i)) + "'";
2849            }
2850    
2851            result.Add(list);
2852        } catch (Exception e) {
2853             result.Error(e);
2854        }
2855    #else
2856        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2857    #endif
2858        return result.Produce();
2859    }
2860    
2861    String LSCPServer::FormatInstrumentsDb() {
2862        dmsg(2,("LSCPServer: FormatInstrumentsDb()\n"));
2863        LSCPResultSet result;
2864    #if HAVE_SQLITE3
2865        try {
2866            InstrumentsDb::GetInstrumentsDb()->Format();
2867        } catch (Exception e) {
2868             result.Error(e);
2869        }
2870    #else
2871        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2872    #endif
2873        return result.Produce();
2874    }
2875    
2876    
2877  /**  /**
2878   * 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
2879   * mode is enabled, all commands from the client will (immediately) be   * mode is enabled, all commands from the client will (immediately) be
# Line 1442  String LSCPServer::SetEcho(yyparse_param Line 2885  String LSCPServer::SetEcho(yyparse_param
2885      try {      try {
2886          if      (boolean_value == 0) pSession->bVerbose = false;          if      (boolean_value == 0) pSession->bVerbose = false;
2887          else if (boolean_value == 1) pSession->bVerbose = true;          else if (boolean_value == 1) pSession->bVerbose = true;
2888          else throw LinuxSamplerException("Not a boolean value, must either be 0 or 1");          else throw Exception("Not a boolean value, must either be 0 or 1");
2889      }      }
2890      catch (LinuxSamplerException e) {      catch (Exception e) {
2891           result.Error(e);           result.Error(e);
2892      }      }
2893      return result.Produce();      return result.Produce();

Legend:
Removed from v.475  
changed lines
  Added in v.1481

  ViewVC Help
Powered by ViewVC