/[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 184 by senkov, Wed Jul 7 02:00:37 2004 UTC revision 660 by schoenebeck, Fri Jun 17 19:49:30 2005 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                              *
7   *                                                                         *   *                                                                         *
8   *   This program 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  *
10   *   the Free Software Foundation; either version 2 of the License, or     *   *   the Free Software Foundation; either version 2 of the License, or     *
11   *   (at your option) any later version.                                   *   *   (at your option) any later version.                                   *
12   *                                                                         *   *                                                                         *
13   *   This program is distributed in the hope that it will be useful,       *   *   This library is distributed in the hope that it will be useful,       *
14   *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *   *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16   *   GNU General Public License for more details.                          *   *   GNU General Public License for more details.                          *
17   *                                                                         *   *                                                                         *
18   *   You should have received a copy of the GNU General Public License     *   *   You should have received a copy of the GNU General Public License     *
19   *   along with this program; if not, write to the Free Software           *   *   along with this library; if not, write to the Free Software           *
20   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
21   *   MA  02111-1307  USA                                                   *   *   MA  02111-1307  USA                                                   *
22   ***************************************************************************/   ***************************************************************************/
# Line 23  Line 24 
24  #include "lscpserver.h"  #include "lscpserver.h"
25  #include "lscpresultset.h"  #include "lscpresultset.h"
26  #include "lscpevent.h"  #include "lscpevent.h"
27    //#include "../common/global.h"
28    
29  #include "../engines/gig/Engine.h"  #include <fcntl.h>
30  #include "../audiodriver/AudioOutputDeviceFactory.h"  
31  #include "../mididriver/MidiInputDeviceFactory.h"  #if HAVE_SQLITE3
32    # include "sqlite3.h"
33    #endif
34    
35    #include "../engines/EngineFactory.h"
36    #include "../engines/EngineChannelFactory.h"
37    #include "../drivers/audio/AudioOutputDeviceFactory.h"
38    #include "../drivers/midi/MidiInputDeviceFactory.h"
39    
40  /**  /**
41   * Below are a few static members of the LSCPServer class.   * Below are a few static members of the LSCPServer class.
# Line 43  Line 52 
52   */   */
53  fd_set LSCPServer::fdSet;  fd_set LSCPServer::fdSet;
54  int LSCPServer::currentSocket = -1;  int LSCPServer::currentSocket = -1;
55  std::vector<int> LSCPServer::hSessions = std::vector<int>();  std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>();
56  std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>();  std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>();
57  std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>();  std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>();
58  std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions = std::map< LSCPEvent::event_t, std::list<int> >();  std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions = std::map< LSCPEvent::event_t, std::list<int> >();
59  Mutex LSCPServer::NotifyMutex = Mutex();  Mutex LSCPServer::NotifyMutex = Mutex();
60  Mutex LSCPServer::NotifyBufferMutex = Mutex();  Mutex LSCPServer::NotifyBufferMutex = Mutex();
61  Mutex LSCPServer::SubscriptionMutex = Mutex();  Mutex LSCPServer::SubscriptionMutex = Mutex();
62    Mutex LSCPServer::RTNotifyMutex = Mutex();
63    
64  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(true, false, 0, -4) {
65      this->pSampler = pSampler;      this->pSampler = pSampler;
66      LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT");
67      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");
68      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");
69      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");
70      LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");
71      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
72        hSocket = -1;
73    }
74    
75    LSCPServer::~LSCPServer() {
76        if (hSocket >= 0) close(hSocket);
77    }
78    
79    /**
80     * Blocks the calling thread until the LSCP Server is initialized and
81     * accepting socket connections, if the server is already initialized then
82     * this method will return immediately.
83     * @param TimeoutSeconds     - optional: max. wait time in seconds
84     *                             (default: 0s)
85     * @param TimeoutNanoSeconds - optional: max wait time in nano seconds
86     *                             (default: 0ns)
87     * @returns  0 on success, a value less than 0 if timeout exceeded
88     */
89    int LSCPServer::WaitUntilInitialized(long TimeoutSeconds, long TimeoutNanoSeconds) {
90        return Initialized.WaitAndUnlockIf(false, TimeoutSeconds, TimeoutNanoSeconds);
91  }  }
92    
93  int LSCPServer::Main() {  int LSCPServer::Main() {
94      int hSocket = socket(AF_INET, SOCK_STREAM, 0);      hSocket = socket(AF_INET, SOCK_STREAM, 0);
95      if (hSocket < 0) {      if (hSocket < 0) {
96          std::cerr << "LSCPServer: Could not create server socket." << std::endl;          std::cerr << "LSCPServer: Could not create server socket." << std::endl;
97          //return -1;          //return -1;
# Line 74  int LSCPServer::Main() { Line 103  int LSCPServer::Main() {
103      SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);      SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);
104    
105      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
106          std::cerr << "LSCPServer: Could not bind server socket." << std::endl;          std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds...";
107          close(hSocket);          for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds
108          //return -1;              if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
109          exit(EXIT_FAILURE);                  if (trial > LSCP_SERVER_BIND_TIMEOUT) {
110                        std::cerr << "gave up!" << std::endl;
111                        close(hSocket);
112                        //return -1;
113                        exit(EXIT_FAILURE);
114                    }
115                    else sleep(1); // sleep 1s
116                }
117                else break; // success
118            }
119      }      }
120    
121      listen(hSocket, 1);      listen(hSocket, 1);
122      dmsg(1,("LSCPServer: Server running.\n")); // server running      Initialized.Set(true);
123    
124      // now wait for client connections and handle their requests      // now wait for client connections and handle their requests
125      sockaddr_in client;      sockaddr_in client;
126      int length = sizeof(client);      int length = sizeof(client);
     struct timeval tv;  
     tv.tv_sec = 30;  
     tv.tv_usec = 0;  
127      FD_ZERO(&fdSet);      FD_ZERO(&fdSet);
128      FD_SET(hSocket, &fdSet);      FD_SET(hSocket, &fdSet);
129      int maxSessions = hSocket;      int maxSessions = hSocket;
   
     // Parser initialization  
     yyparse_param_t yyparse_param;  
     yyparse_param.pServer = this;  
130    
131      while (true) {      while (true) {
132          fd_set selectSet = fdSet;          fd_set selectSet = fdSet;
133          int retval = select(maxSessions+1, &selectSet, NULL, NULL, &tv);          int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL);
134          if (retval == 0)          if (retval == 0)
135                  continue; //Nothing in 30 seconds, try again                  continue; //Nothing try again
136          if (retval == -1) {          if (retval == -1) {
137                  std::cerr << "LSCPServer: Socket select error." << std::endl;                  std::cerr << "LSCPServer: Socket select error." << std::endl;
138                  close(hSocket);                  close(hSocket);
139                  exit(EXIT_FAILURE);                  exit(EXIT_FAILURE);
140          }          }
141            
142          //Accept new connections now (if any)          //Accept new connections now (if any)
143          if (FD_ISSET(hSocket, &selectSet)) {          if (FD_ISSET(hSocket, &selectSet)) {
144                  int socket = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length);                  int socket = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length);
# Line 121  int LSCPServer::Main() { Line 152  int LSCPServer::Main() {
152                          exit(EXIT_FAILURE);                          exit(EXIT_FAILURE);
153                  }                  }
154    
155                  hSessions.push_back(socket);                  // Parser initialization
156                    yyparse_param_t yyparse_param;
157                    yyparse_param.pServer  = this;
158                    yyparse_param.hSession = socket;
159    
160                    Sessions.push_back(yyparse_param);
161                  FD_SET(socket, &fdSet);                  FD_SET(socket, &fdSet);
162                  if (socket > maxSessions)                  if (socket > maxSessions)
163                          maxSessions = socket;                          maxSessions = socket;
# Line 131  int LSCPServer::Main() { Line 167  int LSCPServer::Main() {
167          }          }
168    
169          //Something was selected and it was not the hSocket, so it must be some command(s) coming.          //Something was selected and it was not the hSocket, so it must be some command(s) coming.
170          for (std::vector<int>::iterator iter = hSessions.begin(); iter !=  hSessions.end(); iter++) {          for (std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); iter != Sessions.end(); iter++) {
171                  if (FD_ISSET(*iter, &selectSet)) {      //Was it this socket?                  if (FD_ISSET((*iter).hSession, &selectSet)) {   //Was it this socket?
172                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?
173                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));
174                                  yylex_init(&yyparse_param.pScanner);                                  int dummy; // just a temporary hack to fulfill the restart() function prototype
175                                  currentSocket = *iter;  //a hack                                  restart(NULL, dummy); // restart the 'scanner'
176                                  int result = yyparse(&yyparse_param);                                  currentSocket = (*iter).hSession;  //a hack
177                                    dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str()));
178                                    if ((*iter).bVerbose) { // if echo mode enabled
179                                        AnswerClient(bufferedCommands[currentSocket]);
180                                    }
181                                    int result = yyparse(&(*iter));
182                                  currentSocket = -1;     //continuation of a hack                                  currentSocket = -1;     //continuation of a hack
183                                  dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket));                                  dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket));
184                                  if (result == LSCP_QUIT) { //Was it a quit command by any chance?                                  if (result == LSCP_QUIT) { //Was it a quit command by any chance?
# Line 146  int LSCPServer::Main() { Line 187  int LSCPServer::Main() {
187                          }                          }
188                          //socket may have been closed, iter may be invalid, get out of the loop for now.                          //socket may have been closed, iter may be invalid, get out of the loop for now.
189                          //we'll be back if there is data.                          //we'll be back if there is data.
190                          break;                          break;
191                  }                  }
192          }          }
193    
194            // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers
195            {
196                std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
197                std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
198                std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
199                for (; itEngineChannel != itEnd; ++itEngineChannel) {
200                    if ((*itEngineChannel)->StatusChanged()) {
201                        SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));
202                    }
203                }
204            }
205    
206          //Now let's deliver late notifies (if any)          //Now let's deliver late notifies (if any)
207          NotifyBufferMutex.Lock();          NotifyBufferMutex.Lock();
208          for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {          for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {
# Line 158  int LSCPServer::Main() { Line 211  int LSCPServer::Main() {
211          }          }
212          NotifyBufferMutex.Unlock();          NotifyBufferMutex.Unlock();
213      }      }
     //It will never get here anyway  
     //yylex_destroy(yyparse_param.pScanner);  
214  }  }
215    
216  void LSCPServer::CloseConnection( std::vector<int>::iterator iter ) {  void LSCPServer::CloseConnection( std::vector<yyparse_param_t>::iterator iter ) {
217          int socket = *iter;          int socket = (*iter).hSession;
218          dmsg(1,("LSCPServer: Client connection terminated on socket:%d.\n",socket));          dmsg(1,("LSCPServer: Client connection terminated on socket:%d.\n",socket));
219          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket));          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket));
220          hSessions.erase(iter);          Sessions.erase(iter);
221          FD_CLR(socket,  &fdSet);          FD_CLR(socket,  &fdSet);
222          SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any)          SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any)
223          for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) {          for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) {
# Line 180  void LSCPServer::CloseConnection( std::v Line 231  void LSCPServer::CloseConnection( std::v
231          NotifyMutex.Unlock();          NotifyMutex.Unlock();
232  }  }
233    
234    int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) {
235            int subs = 0;
236            SubscriptionMutex.Lock();
237            for( std::list<LSCPEvent::event_t>::iterator iter = events.begin();
238                            iter != events.end(); iter++)
239            {
240                    subs += eventSubscriptions.count(*iter);
241            }
242            SubscriptionMutex.Unlock();
243            return subs;
244    }
245    
246  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {
247          SubscriptionMutex.Lock();          SubscriptionMutex.Lock();
248          if (eventSubscriptions.count(event.GetType()) == 0) {          if (eventSubscriptions.count(event.GetType()) == 0) {
# Line 230  extern int GetLSCPCommand( void *buf, in Line 293  extern int GetLSCPCommand( void *buf, in
293   * If command is read, it will return true. Otherwise false is returned.   * If command is read, it will return true. Otherwise false is returned.
294   * In any case the received portion (complete or incomplete) is saved into bufferedCommand map.   * In any case the received portion (complete or incomplete) is saved into bufferedCommand map.
295   */   */
296  bool LSCPServer::GetLSCPCommand( std::vector<int>::iterator iter ) {  bool LSCPServer::GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ) {
297          int socket = *iter;          int socket = (*iter).hSession;
298          char c;          char c;
299          int i = 0;          int i = 0;
300          while (true) {          while (true) {
# Line 241  bool LSCPServer::GetLSCPCommand( std::ve Line 304  bool LSCPServer::GetLSCPCommand( std::ve
304                          break;                          break;
305                  }                  }
306                  if (result == 1) {                  if (result == 1) {
307                          if (c == '\r')                          if (c == '\r')
308                                  continue; //Ignore CR                                  continue; //Ignore CR
309                          if (c == '\n') {                          if (c == '\n') {
310                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));
# Line 268  bool LSCPServer::GetLSCPCommand( std::ve Line 331  bool LSCPServer::GetLSCPCommand( std::ve
331                                          break;                                          break;
332                                  case EAGAIN:                                  case EAGAIN:
333                                          dmsg(2,("LSCPScanner: The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.\n"));                                          dmsg(2,("LSCPScanner: The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.\n"));
334                                          break;                                          break;
335                                  case EINTR:                                  case EINTR:
336                                          dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n"));                                          dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n"));
337                                          break;                                          break;
338                                  case EFAULT:                                  case EFAULT:
339                                          dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n"));                                          dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n"));
340                                          break;                                          break;
341                                  case EINVAL:                                  case EINVAL:
342                                          dmsg(2,("LSCPScanner: Invalid argument passed.\n"));                                          dmsg(2,("LSCPScanner: Invalid argument passed.\n"));
343                                          break;                                          break;
344                                  case ENOMEM:                                  case ENOMEM:
345                                          dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n"));                                          dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n"));
346                                          break;                                          break;
347                                  default:                                  default:
348                                          dmsg(2,("LSCPScanner: Unknown recv() error.\n"));                                          dmsg(2,("LSCPScanner: Unknown recv() error.\n"));
349                                          break;                                          break;
350                          }                          }
351                          CloseConnection(iter);                          CloseConnection(iter);
352                          break;                          break;
353                  }                  }
# Line 376  String LSCPServer::DestroyAudioOutputDev Line 439  String LSCPServer::DestroyAudioOutputDev
439      LSCPResultSet result;      LSCPResultSet result;
440      try {      try {
441          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
442          if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
443          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
444          pSampler->DestroyAudioOutputDevice(pDevice);          pSampler->DestroyAudioOutputDevice(pDevice);
445      }      }
# Line 391  String LSCPServer::DestroyMidiInputDevic Line 454  String LSCPServer::DestroyMidiInputDevic
454      LSCPResultSet result;      LSCPResultSet result;
455      try {      try {
456          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
457            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
458          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
         if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");  
459          pSampler->DestroyMidiInputDevice(pDevice);          pSampler->DestroyMidiInputDevice(pDevice);
460      }      }
461      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 409  String LSCPServer::LoadInstrument(String Line 472  String LSCPServer::LoadInstrument(String
472      LSCPResultSet result;      LSCPResultSet result;
473      try {      try {
474          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
475          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
476          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
477          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet");
478          if (pSamplerChannel->GetAudioOutputDevice() == NULL)          if (!pSamplerChannel->GetAudioOutputDevice())
479              throw LinuxSamplerException("No audio output device on channel");              throw LinuxSamplerException("No audio output device connected to sampler channel");
480          if (bBackground) {          if (bBackground) {
481              LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel);
482              pLoadInstrument->StartThread();          }
483            else {
484                // tell the engine channel which instrument to load
485                pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument);
486                // actually start to load the instrument (blocks until completed)
487                pEngineChannel->LoadInstrument();
488          }          }
         else pEngine->LoadInstrument(Filename.c_str(), uiInstrument);  
489      }      }
490      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
491           result.Error(e);           result.Error(e);
# Line 427  String LSCPServer::LoadInstrument(String Line 494  String LSCPServer::LoadInstrument(String
494  }  }
495    
496  /**  /**
497   * Will be called by the parser to load and deploy an engine.   * Will be called by the parser to assign a sampler engine type to a
498     * sampler channel.
499   */   */
500  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {  String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) {
501      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));
502      LSCPResultSet result;      LSCPResultSet result;
503      try {      try {
         Engine::type_t type;  
         if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig;  
         else throw LinuxSamplerException("Unknown engine type");  
504          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
505          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
506          pSamplerChannel->LoadEngine(type);          LockRTNotify();
507            pSamplerChannel->SetEngineType(EngineName);
508            UnlockRTNotify();
509      }      }
510      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
511           result.Error(e);           result.Error(e);
# Line 457  String LSCPServer::GetChannels() { Line 524  String LSCPServer::GetChannels() {
524  }  }
525    
526  /**  /**
527     * Will be called by the parser to get the list of sampler channels.
528     */
529    String LSCPServer::ListChannels() {
530        dmsg(2,("LSCPServer: ListChannels()\n"));
531        String list;
532        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
533        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
534        for (; iter != channels.end(); iter++) {
535            if (list != "") list += ",";
536            list += ToString(iter->first);
537        }
538        LSCPResultSet result;
539        result.Add(list);
540        return result.Produce();
541    }
542    
543    /**
544   * Will be called by the parser to add a sampler channel.   * Will be called by the parser to add a sampler channel.
545   */   */
546  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
# Line 472  String LSCPServer::AddChannel() { Line 556  String LSCPServer::AddChannel() {
556  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {
557      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));
558      LSCPResultSet result;      LSCPResultSet result;
559        LockRTNotify();
560      pSampler->RemoveSamplerChannel(uiSamplerChannel);      pSampler->RemoveSamplerChannel(uiSamplerChannel);
561        UnlockRTNotify();
562      return result.Produce();      return result.Produce();
563  }  }
564    
565  /**  /**
566   * 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.
567   */   */
568  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
569      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
570      LSCPResultSet result("GigEngine");      LSCPResultSet result("1");
571        return result.Produce();
572    }
573    
574    /**
575     * Will be called by the parser to get a list of all available engines.
576     */
577    String LSCPServer::ListAvailableEngines() {
578        dmsg(2,("LSCPServer: ListAvailableEngines()\n"));
579        LSCPResultSet result("\'GIG\'");
580      return result.Produce();      return result.Produce();
581  }  }
582    
583  /**  /**
584   * Will be called by the parser to get descriptions for a particular engine.   * Will be called by the parser to get descriptions for a particular
585     * sampler engine.
586   */   */
587  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
588      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
589      LSCPResultSet result;      LSCPResultSet result;
590      try {      try {
591          if ((EngineName == "GigEngine") || (EngineName == "gig")) {          Engine* pEngine = EngineFactory::Create(EngineName);
592              Engine* pEngine = new LinuxSampler::gig::Engine;          result.Add("DESCRIPTION", pEngine->Description());
593              result.Add(pEngine->Description());          result.Add("VERSION",     pEngine->Version());
594              result.Add(pEngine->Version());          EngineFactory::Destroy(pEngine);
             delete pEngine;  
         }  
         else throw LinuxSamplerException("Unknown engine type");  
595      }      }
596      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
597           result.Error(e);           result.Error(e);
# Line 515  String LSCPServer::GetChannelInfo(uint u Line 608  String LSCPServer::GetChannelInfo(uint u
608      LSCPResultSet result;      LSCPResultSet result;
609      try {      try {
610          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
611          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
612          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
613    
614          //Defaults values          //Defaults values
615          String EngineName = "NONE";          String EngineName = "NONE";
616          float Volume = 0;          float Volume = 0.0f;
617          String InstrumentFileName = "NONE";          String InstrumentFileName = "NONE";
618            String InstrumentName = "NONE";
619          int InstrumentIndex = -1;          int InstrumentIndex = -1;
620          int InstrumentStatus = -1;          int InstrumentStatus = -1;
621            int AudioOutputChannels = 0;
622            String AudioRouting;
623    
624          if (pEngine) {          if (pEngineChannel) {
625              EngineName =  pEngine->EngineName();              EngineName          = pEngineChannel->EngineName();
626              Volume = pEngine->Volume();              AudioOutputChannels = pEngineChannel->Channels();
627              InstrumentStatus = pEngine->InstrumentStatus();              Volume              = pEngineChannel->Volume();
628              InstrumentIndex = pEngine->InstrumentIndex();              InstrumentStatus    = pEngineChannel->InstrumentStatus();
629              if (InstrumentIndex != -1)              InstrumentIndex     = pEngineChannel->InstrumentIndex();
630                  InstrumentFileName = pEngine->InstrumentFileName();              if (InstrumentIndex != -1) {
631                    InstrumentFileName = pEngineChannel->InstrumentFileName();
632                    InstrumentName     = pEngineChannel->InstrumentName();
633                }
634                for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
635                    if (AudioRouting != "") AudioRouting += ",";
636                    AudioRouting += ToString(pEngineChannel->OutputChannel(chan));
637                }
638          }          }
639    
640          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 539  String LSCPServer::GetChannelInfo(uint u Line 642  String LSCPServer::GetChannelInfo(uint u
642    
643          //Some not-so-hardcoded stuff to make GUI look good          //Some not-so-hardcoded stuff to make GUI look good
644          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));
645          result.Add("AUDIO_OUTPUT_CHANNELS", "2");          result.Add("AUDIO_OUTPUT_CHANNELS", AudioOutputChannels);
646          result.Add("AUDIO_OUTPUT_ROUTING", "0,1");          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
647    
648          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));
649          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());
650          result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());          if (pSamplerChannel->GetMidiInputChannel() == MidiInputPort::midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL");
651            else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
652    
653          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
654          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
655            result.Add("INSTRUMENT_NAME", InstrumentName);
656          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
657      }      }
658      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 565  String LSCPServer::GetVoiceCount(uint ui Line 670  String LSCPServer::GetVoiceCount(uint ui
670      LSCPResultSet result;      LSCPResultSet result;
671      try {      try {
672          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
673          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
674          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
675          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel");
676          result.Add(pEngine->VoiceCount());          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
677            result.Add(pEngineChannel->GetEngine()->VoiceCount());
678      }      }
679      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
680           result.Error(e);           result.Error(e);
# Line 585  String LSCPServer::GetStreamCount(uint u Line 691  String LSCPServer::GetStreamCount(uint u
691      LSCPResultSet result;      LSCPResultSet result;
692      try {      try {
693          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
694          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
695          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
696          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
697          result.Add(pEngine->DiskStreamCount());          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
698            result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
699      }      }
700      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
701           result.Error(e);           result.Error(e);
# Line 605  String LSCPServer::GetBufferFill(fill_re Line 712  String LSCPServer::GetBufferFill(fill_re
712      LSCPResultSet result;      LSCPResultSet result;
713      try {      try {
714          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
715          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
716          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
717          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
718          if (!pEngine->DiskStreamSupported())          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
719              result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
720          else {          else {
721              switch (ResponseType) {              switch (ResponseType) {
722                  case fill_response_bytes:                  case fill_response_bytes:
723                      result.Add(pEngine->DiskStreamBufferFillBytes());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillBytes());
724                      break;                      break;
725                  case fill_response_percentage:                  case fill_response_percentage:
726                      result.Add(pEngine->DiskStreamBufferFillPercentage());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());
727                      break;                      break;
728                  default:                  default:
729                      throw LinuxSamplerException("Unknown fill response type");                      throw LinuxSamplerException("Unknown fill response type");
730              }              }
# Line 633  String LSCPServer::GetAvailableAudioOutp Line 740  String LSCPServer::GetAvailableAudioOutp
740      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));
741      LSCPResultSet result;      LSCPResultSet result;
742      try {      try {
743            int n = AudioOutputDeviceFactory::AvailableDrivers().size();
744            result.Add(n);
745        }
746        catch (LinuxSamplerException e) {
747            result.Error(e);
748        }
749        return result.Produce();
750    }
751    
752    String LSCPServer::ListAvailableAudioOutputDrivers() {
753        dmsg(2,("LSCPServer: ListAvailableAudioOutputDrivers()\n"));
754        LSCPResultSet result;
755        try {
756          String s = AudioOutputDeviceFactory::AvailableDriversAsString();          String s = AudioOutputDeviceFactory::AvailableDriversAsString();
757          result.Add(s);          result.Add(s);
758      }      }
# Line 646  String LSCPServer::GetAvailableMidiInput Line 766  String LSCPServer::GetAvailableMidiInput
766      dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));      dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));
767      LSCPResultSet result;      LSCPResultSet result;
768      try {      try {
769            int n = MidiInputDeviceFactory::AvailableDrivers().size();
770            result.Add(n);
771        }
772        catch (LinuxSamplerException e) {
773            result.Error(e);
774        }
775        return result.Produce();
776    }
777    
778    String LSCPServer::ListAvailableMidiInputDrivers() {
779        dmsg(2,("LSCPServer: ListAvailableMidiInputDrivers()\n"));
780        LSCPResultSet result;
781        try {
782          String s = MidiInputDeviceFactory::AvailableDriversAsString();          String s = MidiInputDeviceFactory::AvailableDriversAsString();
783          result.Add(s);          result.Add(s);
784      }      }
# Line 704  String LSCPServer::GetAudioOutputDriverI Line 837  String LSCPServer::GetAudioOutputDriverI
837  }  }
838    
839  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
840      dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str()));      dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size()));
841      LSCPResultSet result;      LSCPResultSet result;
842      try {      try {
843          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);
# Line 713  String LSCPServer::GetMidiInputDriverPar Line 846  String LSCPServer::GetMidiInputDriverPar
846          result.Add("MANDATORY",    pParameter->Mandatory());          result.Add("MANDATORY",    pParameter->Mandatory());
847          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
848          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
849          if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());          optional<String> oDepends       = pParameter->Depends();
850          if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());          optional<String> oDefault       = pParameter->Default(DependencyList);
851          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          optional<String> oRangeMin      = pParameter->RangeMin(DependencyList);
852          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          optional<String> oRangeMax      = pParameter->RangeMax(DependencyList);
853          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          optional<String> oPossibilities = pParameter->Possibilities(DependencyList);
854            if (oDepends)       result.Add("DEPENDS",       *oDepends);
855            if (oDefault)       result.Add("DEFAULT",       *oDefault);
856            if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
857            if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
858            if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
859      }      }
860      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
861          result.Error(e);          result.Error(e);
# Line 726  String LSCPServer::GetMidiInputDriverPar Line 864  String LSCPServer::GetMidiInputDriverPar
864  }  }
865    
866  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
867      dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str()));      dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size()));
868      LSCPResultSet result;      LSCPResultSet result;
869      try {      try {
870          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);
# Line 735  String LSCPServer::GetAudioOutputDriverP Line 873  String LSCPServer::GetAudioOutputDriverP
873          result.Add("MANDATORY",    pParameter->Mandatory());          result.Add("MANDATORY",    pParameter->Mandatory());
874          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
875          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
876          if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());          optional<String> oDepends       = pParameter->Depends();
877          if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());          optional<String> oDefault       = pParameter->Default(DependencyList);
878          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          optional<String> oRangeMin      = pParameter->RangeMin(DependencyList);
879          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          optional<String> oRangeMax      = pParameter->RangeMax(DependencyList);
880          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          optional<String> oPossibilities = pParameter->Possibilities(DependencyList);
881            if (oDepends)       result.Add("DEPENDS",       *oDepends);
882            if (oDefault)       result.Add("DEFAULT",       *oDefault);
883            if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
884            if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
885            if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
886      }      }
887      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
888          result.Error(e);          result.Error(e);
# Line 816  String LSCPServer::GetAudioOutputDeviceI Line 959  String LSCPServer::GetAudioOutputDeviceI
959      LSCPResultSet result;      LSCPResultSet result;
960      try {      try {
961          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
962          if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
963          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
964          result.Add("driver", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
965          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
966          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
967          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
# Line 836  String LSCPServer::GetMidiInputDeviceInf Line 979  String LSCPServer::GetMidiInputDeviceInf
979      LSCPResultSet result;      LSCPResultSet result;
980      try {      try {
981          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
982            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
983          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
984          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          result.Add("DRIVER", pDevice->Driver());
         result.Add("driver", pDevice->Driver());  
985          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
986          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
987          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
# Line 854  String LSCPServer::GetMidiInputPortInfo( Line 997  String LSCPServer::GetMidiInputPortInfo(
997      dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));      dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));
998      LSCPResultSet result;      LSCPResultSet result;
999      try {      try {
1000            // get MIDI input device
1001          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1002            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1003          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1004          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");  
1005          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          // get MIDI port
1006          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1007          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
1008          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();  
1009            // return the values of all MIDI port parameters
1010            std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1011            std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin();
1012          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
1013              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1014          }          }
# Line 877  String LSCPServer::GetAudioOutputChannel Line 1025  String LSCPServer::GetAudioOutputChannel
1025      try {      try {
1026          // get audio output device          // get audio output device
1027          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1028          if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
1029          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1030    
1031          // get audio channel          // get audio channel
1032          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1033          if (!pChannel) throw LinuxSamplerException("Audio ouotput device does not have channel " + ToString(ChannelId) + ".");          if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
1034    
1035          // return the values of all audio channel parameters          // return the values of all audio channel parameters
1036          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 897  String LSCPServer::GetAudioOutputChannel Line 1045  String LSCPServer::GetAudioOutputChannel
1045      return result.Produce();      return result.Produce();
1046  }  }
1047    
1048    String LSCPServer::GetMidiInputPortParameterInfo(uint DeviceId, uint PortId, String ParameterName) {
1049        dmsg(2,("LSCPServer: GetMidiInputPortParameterInfo(DeviceId=%d,PortId=%d,ParameterName=%s)\n",DeviceId,PortId,ParameterName.c_str()));
1050        LSCPResultSet result;
1051        try {
1052            // get MIDI input device
1053            std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1054            if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + ".");
1055            MidiInputDevice* pDevice = devices[DeviceId];
1056    
1057            // get midi port
1058            MidiInputPort* pPort = pDevice->GetPort(PortId);
1059            if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + ".");
1060    
1061            // get desired port parameter
1062            std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();
1063            if (!parameters.count(ParameterName)) throw LinuxSamplerException("Midi port does not provide a parameter '" + ParameterName + "'.");
1064            DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1065    
1066            // return all fields of this audio channel parameter
1067            result.Add("TYPE",         pParameter->Type());
1068            result.Add("DESCRIPTION",  pParameter->Description());
1069            result.Add("FIX",          pParameter->Fix());
1070            result.Add("MULTIPLICITY", pParameter->Multiplicity());
1071            if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());
1072            if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1073            if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1074        }
1075        catch (LinuxSamplerException e) {
1076            result.Error(e);
1077        }
1078        return result.Produce();
1079    }
1080    
1081  String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) {  String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) {
1082      dmsg(2,("LSCPServer: GetAudioOutputChannelParameterInfo(DeviceId=%d,ChannelId=%d,ParameterName=%s)\n",DeviceId,ChannelId,ParameterName.c_str()));      dmsg(2,("LSCPServer: GetAudioOutputChannelParameterInfo(DeviceId=%d,ChannelId=%d,ParameterName=%s)\n",DeviceId,ChannelId,ParameterName.c_str()));
1083      LSCPResultSet result;      LSCPResultSet result;
1084      try {      try {
1085          // get audio output device          // get audio output device
1086          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1087          if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
1088          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1089    
1090          // get audio channel          // get audio channel
1091          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1092          if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");          if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
1093    
1094          // get desired audio channel parameter          // get desired audio channel parameter
1095          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1096          if (!parameters[ParameterName]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'.");          if (!parameters.count(ParameterName)) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'.");
1097          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1098    
1099          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 920  String LSCPServer::GetAudioOutputChannel Line 1101  String LSCPServer::GetAudioOutputChannel
1101          result.Add("DESCRIPTION",  pParameter->Description());          result.Add("DESCRIPTION",  pParameter->Description());
1102          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
1103          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
1104          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());
1105          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1106          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1107      }      }
1108      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1109          result.Error(e);          result.Error(e);
# Line 936  String LSCPServer::SetAudioOutputChannel Line 1117  String LSCPServer::SetAudioOutputChannel
1117      try {      try {
1118          // get audio output device          // get audio output device
1119          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1120          if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
1121          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1122    
1123          // get audio channel          // get audio channel
1124          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1125          if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");          if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
1126    
1127          // get desired audio channel parameter          // get desired audio channel parameter
1128          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1129          if (!parameters[ParamKey]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'.");          if (!parameters.count(ParamKey)) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'.");
1130          DeviceRuntimeParameter* pParameter = parameters[ParamKey];          DeviceRuntimeParameter* pParameter = parameters[ParamKey];
1131    
1132          // set new channel parameter value          // set new channel parameter value
# Line 962  String LSCPServer::SetAudioOutputDeviceP Line 1143  String LSCPServer::SetAudioOutputDeviceP
1143      LSCPResultSet result;      LSCPResultSet result;
1144      try {      try {
1145          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1146          if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
1147          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1148          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1149          if (!parameters[ParamKey]) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");          if (!parameters.count(ParamKey)) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
1150          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1151      }      }
1152      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 979  String LSCPServer::SetMidiInputDevicePar Line 1160  String LSCPServer::SetMidiInputDevicePar
1160      LSCPResultSet result;      LSCPResultSet result;
1161      try {      try {
1162          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1163          if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1164          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1165          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1166          if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");          if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
1167          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1168      }      }
1169      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 995  String LSCPServer::SetMidiInputPortParam Line 1176  String LSCPServer::SetMidiInputPortParam
1176      dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str()));      dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str()));
1177      LSCPResultSet result;      LSCPResultSet result;
1178      try {      try {
1179            // get MIDI input device
1180          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1181            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1182          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1183          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");  
1184          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          // get MIDI port
1185          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1186          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
1187          if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");  
1188            // set port parameter value
1189            std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1190            if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");
1191          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1192      }      }
1193      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1016  String LSCPServer::SetMidiInputPortParam Line 1202  String LSCPServer::SetMidiInputPortParam
1202   */   */
1203  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {
1204      dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel));
1205      return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class?      LSCPResultSet result;
1206        try {
1207            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1208            if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1209            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1210            if (!pEngineChannel) throw LinuxSamplerException("No engine type yet assigned to sampler channel " + ToString(uiSamplerChannel));
1211            if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel));
1212            pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1213        }
1214        catch (LinuxSamplerException e) {
1215             result.Error(e);
1216        }
1217        return result.Produce();
1218  }  }
1219    
1220  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
# Line 1024  String LSCPServer::SetAudioOutputDevice( Line 1222  String LSCPServer::SetAudioOutputDevice(
1222      LSCPResultSet result;      LSCPResultSet result;
1223      try {      try {
1224          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1225          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1226          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1227            if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));
1228          AudioOutputDevice* pDevice = devices[AudioDeviceId];          AudioOutputDevice* pDevice = devices[AudioDeviceId];
         if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));  
1229          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1230      }      }
1231      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1041  String LSCPServer::SetAudioOutputType(St Line 1239  String LSCPServer::SetAudioOutputType(St
1239      LSCPResultSet result;      LSCPResultSet result;
1240      try {      try {
1241          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1242          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1243          // Driver type name aliasing...          // Driver type name aliasing...
1244          if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1245          if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack";                  if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
1246          // Check if there's one audio output device already created          // Check if there's one audio output device already created
1247          // for the intended audio driver type (AudioOutputDriver)...          // for the intended audio driver type (AudioOutputDriver)...
1248          AudioOutputDevice *pDevice = NULL;          AudioOutputDevice *pDevice = NULL;
# Line 1078  String LSCPServer::SetMIDIInputPort(uint Line 1276  String LSCPServer::SetMIDIInputPort(uint
1276      LSCPResultSet result;      LSCPResultSet result;
1277      try {      try {
1278          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1279          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1280          pSamplerChannel->SetMidiInputPort(MIDIPort);          pSamplerChannel->SetMidiInputPort(MIDIPort);
1281      }      }
1282      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1092  String LSCPServer::SetMIDIInputChannel(u Line 1290  String LSCPServer::SetMIDIInputChannel(u
1290      LSCPResultSet result;      LSCPResultSet result;
1291      try {      try {
1292          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1293          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1294          pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);
1295      }      }
1296      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1297           result.Error(e);           result.Error(e);
# Line 1106  String LSCPServer::SetMIDIInputDevice(ui Line 1304  String LSCPServer::SetMIDIInputDevice(ui
1304      LSCPResultSet result;      LSCPResultSet result;
1305      try {      try {
1306          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1307          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1308          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1309            if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1310          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
         if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));  
1311          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1312      }      }
1313      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1123  String LSCPServer::SetMIDIInputType(Stri Line 1321  String LSCPServer::SetMIDIInputType(Stri
1321      LSCPResultSet result;      LSCPResultSet result;
1322      try {      try {
1323          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1324          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1325          // Driver type name aliasing...          // Driver type name aliasing...
1326          if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1327          // Check if there's one MIDI input device already created          // Check if there's one MIDI input device already created
1328          // for the intended MIDI driver type (MidiInputDriver)...          // for the intended MIDI driver type (MidiInputDriver)...
1329          MidiInputDevice *pDevice = NULL;          MidiInputDevice *pDevice = NULL;
# Line 1143  String LSCPServer::SetMIDIInputType(Stri Line 1341  String LSCPServer::SetMIDIInputType(Stri
1341              pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);              pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);
1342              // Make it with at least one initial port.              // Make it with at least one initial port.
1343              std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();              std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1344              parameters["ports"]->SetValue("1");              parameters["PORTS"]->SetValue("1");
1345          }          }
1346          // Must have a device...          // Must have a device...
1347          if (pDevice == NULL)          if (pDevice == NULL)
# Line 1166  String LSCPServer::SetMIDIInput(uint MID Line 1364  String LSCPServer::SetMIDIInput(uint MID
1364      LSCPResultSet result;      LSCPResultSet result;
1365      try {      try {
1366          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1367          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1368          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1369            if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1370          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1371          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel);
         pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);  
1372      }      }
1373      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1374           result.Error(e);           result.Error(e);
# Line 1182  String LSCPServer::SetMIDIInput(uint MID Line 1380  String LSCPServer::SetMIDIInput(uint MID
1380   * Will be called by the parser to change the global volume factor on a   * Will be called by the parser to change the global volume factor on a
1381   * particular sampler channel.   * particular sampler channel.
1382   */   */
1383  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {  String LSCPServer::SetVolume(double dVolume, uint uiSamplerChannel) {
1384      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel));
1385      LSCPResultSet result;      LSCPResultSet result;
1386      try {      try {
1387          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1388          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1389          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1390          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1391          pEngine->Volume(Volume);          pEngineChannel->Volume(dVolume);
1392      }      }
1393      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1394           result.Error(e);           result.Error(e);
# Line 1206  String LSCPServer::ResetChannel(uint uiS Line 1404  String LSCPServer::ResetChannel(uint uiS
1404      LSCPResultSet result;      LSCPResultSet result;
1405      try {      try {
1406          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1407          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1408          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1409          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1410          pEngine->Reset();          if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel");
1411            pEngineChannel->GetEngine()->Reset();
1412      }      }
1413      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1414           result.Error(e);           result.Error(e);
# Line 1218  String LSCPServer::ResetChannel(uint uiS Line 1417  String LSCPServer::ResetChannel(uint uiS
1417  }  }
1418    
1419  /**  /**
1420     * Will be called by the parser to reset the whole sampler.
1421     */
1422    String LSCPServer::ResetSampler() {
1423        dmsg(2,("LSCPServer: ResetSampler()\n"));
1424        pSampler->Reset();
1425        LSCPResultSet result;
1426        return result.Produce();
1427    }
1428    
1429    /**
1430     * Will be called by the parser to return general informations about this
1431     * sampler.
1432     */
1433    String LSCPServer::GetServerInfo() {
1434        dmsg(2,("LSCPServer: GetServerInfo()\n"));
1435        LSCPResultSet result;
1436        result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");
1437        result.Add("VERSION", VERSION);
1438        result.Add("PROTOCOL_VERSION", "1.0");
1439        return result.Produce();
1440    }
1441    
1442    /**
1443   * 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
1444   * server for receiving event messages.   * server for receiving event messages.
1445   */   */
# Line 1243  String LSCPServer::UnsubscribeNotificati Line 1465  String LSCPServer::UnsubscribeNotificati
1465      return result.Produce();      return result.Produce();
1466  }  }
1467    
1468    static int select_callback(void * lscpResultSet, int argc,
1469  // Instrument loader constructor.                          char **argv, char **azColName)
 LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument)  
     : Thread(false, 0, -4)  
1470  {  {
1471      this->pEngine = pEngine;      LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet;
1472      this->Filename = Filename;      resultSet->Add(argc, argv);
1473      this->uiInstrument = uiInstrument;      return 0;
1474  }  }
1475    
1476  // Instrument loader process.  String LSCPServer::QueryDatabase(String query) {
1477  int LSCPLoadInstrument::Main()      LSCPResultSet result;
1478  {  #if HAVE_SQLITE3
1479      try {      char* zErrMsg = NULL;
1480          pEngine->LoadInstrument(Filename.c_str(), uiInstrument);      sqlite3 *db;
1481        String selectStr = "SELECT " + query;
1482    
1483        int rc = sqlite3_open("linuxsampler.db", &db);
1484        if (rc == SQLITE_OK)
1485        {
1486                rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg);
1487        }
1488        if ( rc != SQLITE_OK )
1489        {
1490                result.Error(String(zErrMsg), rc);
1491      }      }
1492        sqlite3_close(db);
1493    #else
1494        result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0);
1495    #endif
1496        return result.Produce();
1497    }
1498    
1499    /**
1500     * Will be called by the parser to enable or disable echo mode; if echo
1501     * mode is enabled, all commands from the client will (immediately) be
1502     * echoed back to the client.
1503     */
1504    String LSCPServer::SetEcho(yyparse_param_t* pSession, double boolean_value) {
1505        dmsg(2,("LSCPServer: SetEcho(val=%f)\n", boolean_value));
1506        LSCPResultSet result;
1507        try {
1508            if      (boolean_value == 0) pSession->bVerbose = false;
1509            else if (boolean_value == 1) pSession->bVerbose = true;
1510            else throw LinuxSamplerException("Not a boolean value, must either be 0 or 1");
1511        }
1512      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1513          e.PrintMessage();           result.Error(e);
1514      }      }
1515        return result.Produce();
     // Always re-enable the engine.  
     pEngine->Enable();  
   
     // FIXME: Shoot ourselves on the foot?  
     delete this;  
1516  }  }

Legend:
Removed from v.184  
changed lines
  Added in v.660

  ViewVC Help
Powered by ViewVC