/[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 475 by schoenebeck, Thu Mar 17 23:56:56 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 "../drivers/audio/AudioOutputDeviceFactory.h"
37    #include "../drivers/midi/MidiInputDeviceFactory.h"
38    
39  /**  /**
40   * Below are a few static members of the LSCPServer class.   * Below are a few static members of the LSCPServer class.
# Line 43  Line 51 
51   */   */
52  fd_set LSCPServer::fdSet;  fd_set LSCPServer::fdSet;
53  int LSCPServer::currentSocket = -1;  int LSCPServer::currentSocket = -1;
54  std::vector<int> LSCPServer::hSessions = std::vector<int>();  std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>();
55  std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>();  std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>();
56  std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>();  std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>();
57  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> >();
58  Mutex LSCPServer::NotifyMutex = Mutex();  Mutex LSCPServer::NotifyMutex = Mutex();
59  Mutex LSCPServer::NotifyBufferMutex = Mutex();  Mutex LSCPServer::NotifyBufferMutex = Mutex();
60  Mutex LSCPServer::SubscriptionMutex = Mutex();  Mutex LSCPServer::SubscriptionMutex = Mutex();
61    Mutex LSCPServer::RTNotifyMutex = Mutex();
62    
63  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(true, false, 0, -4) {
64      this->pSampler = pSampler;      this->pSampler = pSampler;
65      LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS");      LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS");
66      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");
# Line 59  LSCPServer::LSCPServer(Sampler* pSampler Line 68  LSCPServer::LSCPServer(Sampler* pSampler
68      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");
69      LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO");
70      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
71        hSocket = -1;
72    }
73    
74    LSCPServer::~LSCPServer() {
75        if (hSocket >= 0) close(hSocket);
76    }
77    
78    /**
79     * Blocks the calling thread until the LSCP Server is initialized and
80     * accepting socket connections, if the server is already initialized then
81     * this method will return immediately.
82     * @param TimeoutSeconds     - optional: max. wait time in seconds
83     *                             (default: 0s)
84     * @param TimeoutNanoSeconds - optional: max wait time in nano seconds
85     *                             (default: 0ns)
86     * @returns  0 on success, a value less than 0 if timeout exceeded
87     */
88    int LSCPServer::WaitUntilInitialized(long TimeoutSeconds, long TimeoutNanoSeconds) {
89        return Initialized.WaitAndUnlockIf(false, TimeoutSeconds, TimeoutNanoSeconds);
90  }  }
91    
92  int LSCPServer::Main() {  int LSCPServer::Main() {
93      int hSocket = socket(AF_INET, SOCK_STREAM, 0);      hSocket = socket(AF_INET, SOCK_STREAM, 0);
94      if (hSocket < 0) {      if (hSocket < 0) {
95          std::cerr << "LSCPServer: Could not create server socket." << std::endl;          std::cerr << "LSCPServer: Could not create server socket." << std::endl;
96          //return -1;          //return -1;
# Line 74  int LSCPServer::Main() { Line 102  int LSCPServer::Main() {
102      SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);      SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);
103    
104      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {      if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
105          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...";
106          close(hSocket);          for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds
107          //return -1;              if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) {
108          exit(EXIT_FAILURE);                  if (trial > LSCP_SERVER_BIND_TIMEOUT) {
109                        std::cerr << "gave up!" << std::endl;
110                        close(hSocket);
111                        //return -1;
112                        exit(EXIT_FAILURE);
113                    }
114                    else sleep(1); // sleep 1s
115                }
116                else break; // success
117            }
118      }      }
119    
120      listen(hSocket, 1);      listen(hSocket, 1);
121      dmsg(1,("LSCPServer: Server running.\n")); // server running      Initialized.Set(true);
122    
123      // now wait for client connections and handle their requests      // now wait for client connections and handle their requests
124      sockaddr_in client;      sockaddr_in client;
125      int length = sizeof(client);      int length = sizeof(client);
     struct timeval tv;  
     tv.tv_sec = 30;  
     tv.tv_usec = 0;  
126      FD_ZERO(&fdSet);      FD_ZERO(&fdSet);
127      FD_SET(hSocket, &fdSet);      FD_SET(hSocket, &fdSet);
128      int maxSessions = hSocket;      int maxSessions = hSocket;
   
     // Parser initialization  
     yyparse_param_t yyparse_param;  
     yyparse_param.pServer = this;  
129    
130      while (true) {      while (true) {
131          fd_set selectSet = fdSet;          fd_set selectSet = fdSet;
132          int retval = select(maxSessions+1, &selectSet, NULL, NULL, &tv);          int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL);
133          if (retval == 0)          if (retval == 0)
134                  continue; //Nothing in 30 seconds, try again                  continue; //Nothing try again
135          if (retval == -1) {          if (retval == -1) {
136                  std::cerr << "LSCPServer: Socket select error." << std::endl;                  std::cerr << "LSCPServer: Socket select error." << std::endl;
137                  close(hSocket);                  close(hSocket);
138                  exit(EXIT_FAILURE);                  exit(EXIT_FAILURE);
139          }          }
140            
141          //Accept new connections now (if any)          //Accept new connections now (if any)
142          if (FD_ISSET(hSocket, &selectSet)) {          if (FD_ISSET(hSocket, &selectSet)) {
143                  int socket = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length);                  int socket = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length);
# Line 121  int LSCPServer::Main() { Line 151  int LSCPServer::Main() {
151                          exit(EXIT_FAILURE);                          exit(EXIT_FAILURE);
152                  }                  }
153    
154                  hSessions.push_back(socket);                  // Parser initialization
155                    yyparse_param_t yyparse_param;
156                    yyparse_param.pServer  = this;
157                    yyparse_param.hSession = socket;
158    
159                    Sessions.push_back(yyparse_param);
160                  FD_SET(socket, &fdSet);                  FD_SET(socket, &fdSet);
161                  if (socket > maxSessions)                  if (socket > maxSessions)
162                          maxSessions = socket;                          maxSessions = socket;
# Line 131  int LSCPServer::Main() { Line 166  int LSCPServer::Main() {
166          }          }
167    
168          //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.
169          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++) {
170                  if (FD_ISSET(*iter, &selectSet)) {      //Was it this socket?                  if (FD_ISSET((*iter).hSession, &selectSet)) {   //Was it this socket?
171                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?
172                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));
173                                  yylex_init(&yyparse_param.pScanner);                                  int dummy; // just a temporary hack to fulfill the restart() function prototype
174                                  currentSocket = *iter;  //a hack                                  restart(NULL, dummy); // restart the 'scanner'
175                                  int result = yyparse(&yyparse_param);                                  currentSocket = (*iter).hSession;  //a hack
176                                    dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str()));
177                                    if ((*iter).bVerbose) { // if echo mode enabled
178                                        AnswerClient(bufferedCommands[currentSocket]);
179                                    }
180                                    int result = yyparse(&(*iter));
181                                  currentSocket = -1;     //continuation of a hack                                  currentSocket = -1;     //continuation of a hack
182                                  dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket));                                  dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket));
183                                  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 186  int LSCPServer::Main() {
186                          }                          }
187                          //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.
188                          //we'll be back if there is data.                          //we'll be back if there is data.
189                          break;                          break;
190                  }                  }
191          }          }
192    
# Line 158  int LSCPServer::Main() { Line 198  int LSCPServer::Main() {
198          }          }
199          NotifyBufferMutex.Unlock();          NotifyBufferMutex.Unlock();
200      }      }
     //It will never get here anyway  
     //yylex_destroy(yyparse_param.pScanner);  
201  }  }
202    
203  void LSCPServer::CloseConnection( std::vector<int>::iterator iter ) {  void LSCPServer::CloseConnection( std::vector<yyparse_param_t>::iterator iter ) {
204          int socket = *iter;          int socket = (*iter).hSession;
205          dmsg(1,("LSCPServer: Client connection terminated on socket:%d.\n",socket));          dmsg(1,("LSCPServer: Client connection terminated on socket:%d.\n",socket));
206          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket));          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket));
207          hSessions.erase(iter);          Sessions.erase(iter);
208          FD_CLR(socket,  &fdSet);          FD_CLR(socket,  &fdSet);
209          SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any)          SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any)
210          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 218  void LSCPServer::CloseConnection( std::v
218          NotifyMutex.Unlock();          NotifyMutex.Unlock();
219  }  }
220    
221    int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) {
222            int subs = 0;
223            SubscriptionMutex.Lock();
224            for( std::list<LSCPEvent::event_t>::iterator iter = events.begin();
225                            iter != events.end(); iter++)
226            {
227                    subs += eventSubscriptions.count(*iter);
228            }
229            SubscriptionMutex.Unlock();
230            return subs;
231    }
232    
233  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {
234          SubscriptionMutex.Lock();          SubscriptionMutex.Lock();
235          if (eventSubscriptions.count(event.GetType()) == 0) {          if (eventSubscriptions.count(event.GetType()) == 0) {
# Line 230  extern int GetLSCPCommand( void *buf, in Line 280  extern int GetLSCPCommand( void *buf, in
280   * If command is read, it will return true. Otherwise false is returned.   * If command is read, it will return true. Otherwise false is returned.
281   * 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.
282   */   */
283  bool LSCPServer::GetLSCPCommand( std::vector<int>::iterator iter ) {  bool LSCPServer::GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ) {
284          int socket = *iter;          int socket = (*iter).hSession;
285          char c;          char c;
286          int i = 0;          int i = 0;
287          while (true) {          while (true) {
# Line 241  bool LSCPServer::GetLSCPCommand( std::ve Line 291  bool LSCPServer::GetLSCPCommand( std::ve
291                          break;                          break;
292                  }                  }
293                  if (result == 1) {                  if (result == 1) {
294                          if (c == '\r')                          if (c == '\r')
295                                  continue; //Ignore CR                                  continue; //Ignore CR
296                          if (c == '\n') {                          if (c == '\n') {
297                                  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 318  bool LSCPServer::GetLSCPCommand( std::ve
318                                          break;                                          break;
319                                  case EAGAIN:                                  case EAGAIN:
320                                          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"));
321                                          break;                                          break;
322                                  case EINTR:                                  case EINTR:
323                                          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"));
324                                          break;                                          break;
325                                  case EFAULT:                                  case EFAULT:
326                                          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"));
327                                          break;                                          break;
328                                  case EINVAL:                                  case EINVAL:
329                                          dmsg(2,("LSCPScanner: Invalid argument passed.\n"));                                          dmsg(2,("LSCPScanner: Invalid argument passed.\n"));
330                                          break;                                          break;
331                                  case ENOMEM:                                  case ENOMEM:
332                                          dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n"));                                          dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n"));
333                                          break;                                          break;
334                                  default:                                  default:
335                                          dmsg(2,("LSCPScanner: Unknown recv() error.\n"));                                          dmsg(2,("LSCPScanner: Unknown recv() error.\n"));
336                                          break;                                          break;
337                          }                          }
338                          CloseConnection(iter);                          CloseConnection(iter);
339                          break;                          break;
340                  }                  }
# Line 376  String LSCPServer::DestroyAudioOutputDev Line 426  String LSCPServer::DestroyAudioOutputDev
426      LSCPResultSet result;      LSCPResultSet result;
427      try {      try {
428          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
429          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) + ".");
430          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
431          pSampler->DestroyAudioOutputDevice(pDevice);          pSampler->DestroyAudioOutputDevice(pDevice);
432      }      }
# Line 391  String LSCPServer::DestroyMidiInputDevic Line 441  String LSCPServer::DestroyMidiInputDevic
441      LSCPResultSet result;      LSCPResultSet result;
442      try {      try {
443          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
444            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
445          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
         if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");  
446          pSampler->DestroyMidiInputDevice(pDevice);          pSampler->DestroyMidiInputDevice(pDevice);
447      }      }
448      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 409  String LSCPServer::LoadInstrument(String Line 459  String LSCPServer::LoadInstrument(String
459      LSCPResultSet result;      LSCPResultSet result;
460      try {      try {
461          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
462          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
463          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
464          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet");
465          if (pSamplerChannel->GetAudioOutputDevice() == NULL)          if (!pSamplerChannel->GetAudioOutputDevice())
466              throw LinuxSamplerException("No audio output device on channel");              throw LinuxSamplerException("No audio output device connected to sampler channel");
467          if (bBackground) {          if (bBackground) {
468              LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel);
469              pLoadInstrument->StartThread();          }
470            else {
471                // tell the engine channel which instrument to load
472                pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument);
473                // actually start to load the instrument (blocks until completed)
474                pEngineChannel->LoadInstrument();
475          }          }
         else pEngine->LoadInstrument(Filename.c_str(), uiInstrument);  
476      }      }
477      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
478           result.Error(e);           result.Error(e);
# Line 427  String LSCPServer::LoadInstrument(String Line 481  String LSCPServer::LoadInstrument(String
481  }  }
482    
483  /**  /**
484   * 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
485     * sampler channel.
486   */   */
487  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {  String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) {
488      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));
489      LSCPResultSet result;      LSCPResultSet result;
490      try {      try {
         Engine::type_t type;  
         if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig;  
         else throw LinuxSamplerException("Unknown engine type");  
491          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
492          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
493          pSamplerChannel->LoadEngine(type);          LockRTNotify();
494            pSamplerChannel->SetEngineType(EngineName);
495            UnlockRTNotify();
496      }      }
497      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
498           result.Error(e);           result.Error(e);
# Line 457  String LSCPServer::GetChannels() { Line 511  String LSCPServer::GetChannels() {
511  }  }
512    
513  /**  /**
514     * Will be called by the parser to get the list of sampler channels.
515     */
516    String LSCPServer::ListChannels() {
517        dmsg(2,("LSCPServer: ListChannels()\n"));
518        String list;
519        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
520        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
521        for (; iter != channels.end(); iter++) {
522            if (list != "") list += ",";
523            list += ToString(iter->first);
524        }
525        LSCPResultSet result;
526        result.Add(list);
527        return result.Produce();
528    }
529    
530    /**
531   * Will be called by the parser to add a sampler channel.   * Will be called by the parser to add a sampler channel.
532   */   */
533  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
# Line 472  String LSCPServer::AddChannel() { Line 543  String LSCPServer::AddChannel() {
543  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {
544      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));
545      LSCPResultSet result;      LSCPResultSet result;
546        LockRTNotify();
547      pSampler->RemoveSamplerChannel(uiSamplerChannel);      pSampler->RemoveSamplerChannel(uiSamplerChannel);
548        UnlockRTNotify();
549      return result.Produce();      return result.Produce();
550  }  }
551    
# Line 486  String LSCPServer::GetAvailableEngines() Line 559  String LSCPServer::GetAvailableEngines()
559  }  }
560    
561  /**  /**
562   * 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
563     * sampler engine.
564   */   */
565  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
566      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
567      LSCPResultSet result;      LSCPResultSet result;
568      try {      try {
569          if ((EngineName == "GigEngine") || (EngineName == "gig")) {          Engine* pEngine = EngineFactory::Create(EngineName);
570              Engine* pEngine = new LinuxSampler::gig::Engine;          result.Add("DESCRIPTION", pEngine->Description());
571              result.Add(pEngine->Description());          result.Add("VERSION",     pEngine->Version());
572              result.Add(pEngine->Version());          delete pEngine;
             delete pEngine;  
         }  
         else throw LinuxSamplerException("Unknown engine type");  
573      }      }
574      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
575           result.Error(e);           result.Error(e);
# Line 515  String LSCPServer::GetChannelInfo(uint u Line 586  String LSCPServer::GetChannelInfo(uint u
586      LSCPResultSet result;      LSCPResultSet result;
587      try {      try {
588          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
589          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
590          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
591    
592          //Defaults values          //Defaults values
593          String EngineName = "NONE";          String EngineName = "NONE";
594          float Volume = 0;          float Volume = 0.0f;
595          String InstrumentFileName = "NONE";          String InstrumentFileName = "NONE";
596            String InstrumentName = "NONE";
597          int InstrumentIndex = -1;          int InstrumentIndex = -1;
598          int InstrumentStatus = -1;          int InstrumentStatus = -1;
599            int AudioOutputChannels = 0;
600            String AudioRouting;
601    
602          if (pEngine) {          if (pEngineChannel) {
603              EngineName =  pEngine->EngineName();              EngineName          = pEngineChannel->EngineName();
604              Volume = pEngine->Volume();              AudioOutputChannels = pEngineChannel->Channels();
605              InstrumentStatus = pEngine->InstrumentStatus();              Volume              = pEngineChannel->Volume();
606              InstrumentIndex = pEngine->InstrumentIndex();              InstrumentStatus    = pEngineChannel->InstrumentStatus();
607              if (InstrumentIndex != -1)              InstrumentIndex     = pEngineChannel->InstrumentIndex();
608                  InstrumentFileName = pEngine->InstrumentFileName();              if (InstrumentIndex != -1) {
609                    InstrumentFileName = pEngineChannel->InstrumentFileName();
610                    InstrumentName     = pEngineChannel->InstrumentName();
611                }
612                for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
613                    if (AudioRouting != "") AudioRouting += ",";
614                    AudioRouting += ToString(pEngineChannel->OutputChannel(chan));
615                }
616          }          }
617    
618          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 539  String LSCPServer::GetChannelInfo(uint u Line 620  String LSCPServer::GetChannelInfo(uint u
620    
621          //Some not-so-hardcoded stuff to make GUI look good          //Some not-so-hardcoded stuff to make GUI look good
622          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));
623          result.Add("AUDIO_OUTPUT_CHANNELS", "2");          result.Add("AUDIO_OUTPUT_CHANNELS", AudioOutputChannels);
624          result.Add("AUDIO_OUTPUT_ROUTING", "0,1");          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
625    
626          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));
627          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());
628          result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());          if (pSamplerChannel->GetMidiInputChannel() == MidiInputPort::midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL");
629            else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
630    
631          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
632          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
633            result.Add("INSTRUMENT_NAME", InstrumentName);
634          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
635      }      }
636      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 565  String LSCPServer::GetVoiceCount(uint ui Line 648  String LSCPServer::GetVoiceCount(uint ui
648      LSCPResultSet result;      LSCPResultSet result;
649      try {      try {
650          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
651          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
652          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
653          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel");
654          result.Add(pEngine->VoiceCount());          result.Add(pEngineChannel->GetEngine()->VoiceCount());
655      }      }
656      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
657           result.Error(e);           result.Error(e);
# Line 585  String LSCPServer::GetStreamCount(uint u Line 668  String LSCPServer::GetStreamCount(uint u
668      LSCPResultSet result;      LSCPResultSet result;
669      try {      try {
670          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
671          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
672          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
673          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
674          result.Add(pEngine->DiskStreamCount());          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
675      }      }
676      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
677           result.Error(e);           result.Error(e);
# Line 605  String LSCPServer::GetBufferFill(fill_re Line 688  String LSCPServer::GetBufferFill(fill_re
688      LSCPResultSet result;      LSCPResultSet result;
689      try {      try {
690          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
691          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
692          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
693          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
694          if (!pEngine->DiskStreamSupported())          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
             result.Add("NA");  
695          else {          else {
696              switch (ResponseType) {              switch (ResponseType) {
697                  case fill_response_bytes:                  case fill_response_bytes:
698                      result.Add(pEngine->DiskStreamBufferFillBytes());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillBytes());
699                      break;                      break;
700                  case fill_response_percentage:                  case fill_response_percentage:
701                      result.Add(pEngine->DiskStreamBufferFillPercentage());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());
702                      break;                      break;
703                  default:                  default:
704                      throw LinuxSamplerException("Unknown fill response type");                      throw LinuxSamplerException("Unknown fill response type");
705              }              }
# Line 704  String LSCPServer::GetAudioOutputDriverI Line 786  String LSCPServer::GetAudioOutputDriverI
786  }  }
787    
788  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
789      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()));
790      LSCPResultSet result;      LSCPResultSet result;
791      try {      try {
792          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);
# Line 713  String LSCPServer::GetMidiInputDriverPar Line 795  String LSCPServer::GetMidiInputDriverPar
795          result.Add("MANDATORY",    pParameter->Mandatory());          result.Add("MANDATORY",    pParameter->Mandatory());
796          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
797          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
798          if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());          optional<String> oDepends       = pParameter->Depends();
799          if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());          optional<String> oDefault       = pParameter->Default(DependencyList);
800          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          optional<String> oRangeMin      = pParameter->RangeMin(DependencyList);
801          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          optional<String> oRangeMax      = pParameter->RangeMax(DependencyList);
802          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          optional<String> oPossibilities = pParameter->Possibilities(DependencyList);
803            if (oDepends)       result.Add("DEPENDS",       *oDepends);
804            if (oDefault)       result.Add("DEFAULT",       *oDefault);
805            if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
806            if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
807            if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
808      }      }
809      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
810          result.Error(e);          result.Error(e);
# Line 726  String LSCPServer::GetMidiInputDriverPar Line 813  String LSCPServer::GetMidiInputDriverPar
813  }  }
814    
815  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
816      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()));
817      LSCPResultSet result;      LSCPResultSet result;
818      try {      try {
819          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);
# Line 735  String LSCPServer::GetAudioOutputDriverP Line 822  String LSCPServer::GetAudioOutputDriverP
822          result.Add("MANDATORY",    pParameter->Mandatory());          result.Add("MANDATORY",    pParameter->Mandatory());
823          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
824          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
825          if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());          optional<String> oDepends       = pParameter->Depends();
826          if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());          optional<String> oDefault       = pParameter->Default(DependencyList);
827          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          optional<String> oRangeMin      = pParameter->RangeMin(DependencyList);
828          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          optional<String> oRangeMax      = pParameter->RangeMax(DependencyList);
829          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          optional<String> oPossibilities = pParameter->Possibilities(DependencyList);
830            if (oDepends)       result.Add("DEPENDS",       *oDepends);
831            if (oDefault)       result.Add("DEFAULT",       *oDefault);
832            if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
833            if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
834            if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
835      }      }
836      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
837          result.Error(e);          result.Error(e);
# Line 816  String LSCPServer::GetAudioOutputDeviceI Line 908  String LSCPServer::GetAudioOutputDeviceI
908      LSCPResultSet result;      LSCPResultSet result;
909      try {      try {
910          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
911          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) + ".");
912          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
913          result.Add("driver", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
914          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
915          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
916          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
# Line 836  String LSCPServer::GetMidiInputDeviceInf Line 928  String LSCPServer::GetMidiInputDeviceInf
928      LSCPResultSet result;      LSCPResultSet result;
929      try {      try {
930          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
931            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
932          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
933          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          result.Add("DRIVER", pDevice->Driver());
         result.Add("driver", pDevice->Driver());  
934          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
935          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
936          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
# Line 854  String LSCPServer::GetMidiInputPortInfo( Line 946  String LSCPServer::GetMidiInputPortInfo(
946      dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));      dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));
947      LSCPResultSet result;      LSCPResultSet result;
948      try {      try {
949            // get MIDI input device
950          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
951            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
952          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
953          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");  
954          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          // get MIDI port
955          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
956          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
957          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();  
958            // return the values of all MIDI port parameters
959            std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
960            std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin();
961          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
962              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
963          }          }
# Line 877  String LSCPServer::GetAudioOutputChannel Line 974  String LSCPServer::GetAudioOutputChannel
974      try {      try {
975          // get audio output device          // get audio output device
976          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
977          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) + ".");
978          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
979    
980          // get audio channel          // get audio channel
981          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
982          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) + ".");
983    
984          // return the values of all audio channel parameters          // return the values of all audio channel parameters
985          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 897  String LSCPServer::GetAudioOutputChannel Line 994  String LSCPServer::GetAudioOutputChannel
994      return result.Produce();      return result.Produce();
995  }  }
996    
997    String LSCPServer::GetMidiInputPortParameterInfo(uint DeviceId, uint PortId, String ParameterName) {
998        dmsg(2,("LSCPServer: GetMidiInputPortParameterInfo(DeviceId=%d,PortId=%d,ParameterName=%s)\n",DeviceId,PortId,ParameterName.c_str()));
999        LSCPResultSet result;
1000        try {
1001            // get MIDI input device
1002            std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1003            if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + ".");
1004            MidiInputDevice* pDevice = devices[DeviceId];
1005    
1006            // get midi port
1007            MidiInputPort* pPort = pDevice->GetPort(PortId);
1008            if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + ".");
1009    
1010            // get desired port parameter
1011            std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();
1012            if (!parameters.count(ParameterName)) throw LinuxSamplerException("Midi port does not provide a parameter '" + ParameterName + "'.");
1013            DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1014    
1015            // return all fields of this audio channel parameter
1016            result.Add("TYPE",         pParameter->Type());
1017            result.Add("DESCRIPTION",  pParameter->Description());
1018            result.Add("FIX",          pParameter->Fix());
1019            result.Add("MULTIPLICITY", pParameter->Multiplicity());
1020            if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());
1021            if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1022            if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1023        }
1024        catch (LinuxSamplerException e) {
1025            result.Error(e);
1026        }
1027        return result.Produce();
1028    }
1029    
1030  String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) {  String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) {
1031      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()));
1032      LSCPResultSet result;      LSCPResultSet result;
1033      try {      try {
1034          // get audio output device          // get audio output device
1035          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1036          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) + ".");
1037          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1038    
1039          // get audio channel          // get audio channel
1040          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1041          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) + ".");
1042    
1043          // get desired audio channel parameter          // get desired audio channel parameter
1044          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1045          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 + "'.");
1046          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1047    
1048          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 920  String LSCPServer::GetAudioOutputChannel Line 1050  String LSCPServer::GetAudioOutputChannel
1050          result.Add("DESCRIPTION",  pParameter->Description());          result.Add("DESCRIPTION",  pParameter->Description());
1051          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
1052          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
1053          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());
1054          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1055          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1056      }      }
1057      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1058          result.Error(e);          result.Error(e);
# Line 936  String LSCPServer::SetAudioOutputChannel Line 1066  String LSCPServer::SetAudioOutputChannel
1066      try {      try {
1067          // get audio output device          // get audio output device
1068          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1069          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) + ".");
1070          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1071    
1072          // get audio channel          // get audio channel
1073          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1074          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) + ".");
1075    
1076          // get desired audio channel parameter          // get desired audio channel parameter
1077          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1078          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 + "'.");
1079          DeviceRuntimeParameter* pParameter = parameters[ParamKey];          DeviceRuntimeParameter* pParameter = parameters[ParamKey];
1080    
1081          // set new channel parameter value          // set new channel parameter value
# Line 962  String LSCPServer::SetAudioOutputDeviceP Line 1092  String LSCPServer::SetAudioOutputDeviceP
1092      LSCPResultSet result;      LSCPResultSet result;
1093      try {      try {
1094          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1095          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) + ".");
1096          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1097          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1098          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 + "'");
1099          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1100      }      }
1101      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 979  String LSCPServer::SetMidiInputDevicePar Line 1109  String LSCPServer::SetMidiInputDevicePar
1109      LSCPResultSet result;      LSCPResultSet result;
1110      try {      try {
1111          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1112          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) + ".");
1113          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1114          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1115          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 + "'");
1116          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1117      }      }
1118      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 995  String LSCPServer::SetMidiInputPortParam Line 1125  String LSCPServer::SetMidiInputPortParam
1125      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()));
1126      LSCPResultSet result;      LSCPResultSet result;
1127      try {      try {
1128            // get MIDI input device
1129          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1130            if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1131          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1132          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");  
1133          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          // get MIDI port
1134          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1135          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
1136          if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");  
1137            // set port parameter value
1138            std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1139            if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");
1140          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1141      }      }
1142      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1016  String LSCPServer::SetMidiInputPortParam Line 1151  String LSCPServer::SetMidiInputPortParam
1151   */   */
1152  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {
1153      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));
1154      return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class?      LSCPResultSet result;
1155        try {
1156            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1157            if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1158            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1159            if (!pEngineChannel) throw LinuxSamplerException("No engine type yet assigned to sampler channel " + ToString(uiSamplerChannel));
1160            if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel));
1161            pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1162        }
1163        catch (LinuxSamplerException e) {
1164             result.Error(e);
1165        }
1166        return result.Produce();
1167  }  }
1168    
1169  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
# Line 1024  String LSCPServer::SetAudioOutputDevice( Line 1171  String LSCPServer::SetAudioOutputDevice(
1171      LSCPResultSet result;      LSCPResultSet result;
1172      try {      try {
1173          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1174          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1175          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1176            if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));
1177          AudioOutputDevice* pDevice = devices[AudioDeviceId];          AudioOutputDevice* pDevice = devices[AudioDeviceId];
         if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));  
1178          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1179      }      }
1180      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1041  String LSCPServer::SetAudioOutputType(St Line 1188  String LSCPServer::SetAudioOutputType(St
1188      LSCPResultSet result;      LSCPResultSet result;
1189      try {      try {
1190          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1191          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1192          // Driver type name aliasing...          // Driver type name aliasing...
1193          if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1194          if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack";                  if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
1195          // Check if there's one audio output device already created          // Check if there's one audio output device already created
1196          // for the intended audio driver type (AudioOutputDriver)...          // for the intended audio driver type (AudioOutputDriver)...
1197          AudioOutputDevice *pDevice = NULL;          AudioOutputDevice *pDevice = NULL;
# Line 1078  String LSCPServer::SetMIDIInputPort(uint Line 1225  String LSCPServer::SetMIDIInputPort(uint
1225      LSCPResultSet result;      LSCPResultSet result;
1226      try {      try {
1227          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1228          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1229          pSamplerChannel->SetMidiInputPort(MIDIPort);          pSamplerChannel->SetMidiInputPort(MIDIPort);
1230      }      }
1231      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1092  String LSCPServer::SetMIDIInputChannel(u Line 1239  String LSCPServer::SetMIDIInputChannel(u
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          pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);
1244      }      }
1245      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1246           result.Error(e);           result.Error(e);
# Line 1106  String LSCPServer::SetMIDIInputDevice(ui Line 1253  String LSCPServer::SetMIDIInputDevice(ui
1253      LSCPResultSet result;      LSCPResultSet result;
1254      try {      try {
1255          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1256          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1257          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1258            if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1259          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
         if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));  
1260          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1261      }      }
1262      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1123  String LSCPServer::SetMIDIInputType(Stri Line 1270  String LSCPServer::SetMIDIInputType(Stri
1270      LSCPResultSet result;      LSCPResultSet result;
1271      try {      try {
1272          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1273          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1274          // Driver type name aliasing...          // Driver type name aliasing...
1275          if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1276          // Check if there's one MIDI input device already created          // Check if there's one MIDI input device already created
1277          // for the intended MIDI driver type (MidiInputDriver)...          // for the intended MIDI driver type (MidiInputDriver)...
1278          MidiInputDevice *pDevice = NULL;          MidiInputDevice *pDevice = NULL;
# Line 1143  String LSCPServer::SetMIDIInputType(Stri Line 1290  String LSCPServer::SetMIDIInputType(Stri
1290              pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);              pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);
1291              // Make it with at least one initial port.              // Make it with at least one initial port.
1292              std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();              std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1293              parameters["ports"]->SetValue("1");              parameters["PORTS"]->SetValue("1");
1294          }          }
1295          // Must have a device...          // Must have a device...
1296          if (pDevice == NULL)          if (pDevice == NULL)
# Line 1166  String LSCPServer::SetMIDIInput(uint MID Line 1313  String LSCPServer::SetMIDIInput(uint MID
1313      LSCPResultSet result;      LSCPResultSet result;
1314      try {      try {
1315          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1316          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1317          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1318            if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1319          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1320          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);  
1321      }      }
1322      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1323           result.Error(e);           result.Error(e);
# Line 1182  String LSCPServer::SetMIDIInput(uint MID Line 1329  String LSCPServer::SetMIDIInput(uint MID
1329   * 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
1330   * particular sampler channel.   * particular sampler channel.
1331   */   */
1332  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {  String LSCPServer::SetVolume(double dVolume, uint uiSamplerChannel) {
1333      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel));
1334      LSCPResultSet result;      LSCPResultSet result;
1335      try {      try {
1336          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1337          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1338          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1339          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1340          pEngine->Volume(Volume);          pEngineChannel->Volume(dVolume);
1341      }      }
1342      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1343           result.Error(e);           result.Error(e);
# Line 1206  String LSCPServer::ResetChannel(uint uiS Line 1353  String LSCPServer::ResetChannel(uint uiS
1353      LSCPResultSet result;      LSCPResultSet result;
1354      try {      try {
1355          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1356          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1357          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1358          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1359          pEngine->Reset();          pEngineChannel->GetEngine()->Reset();
1360      }      }
1361      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1362           result.Error(e);           result.Error(e);
# Line 1218  String LSCPServer::ResetChannel(uint uiS Line 1365  String LSCPServer::ResetChannel(uint uiS
1365  }  }
1366    
1367  /**  /**
1368     * Will be called by the parser to reset the whole sampler.
1369     */
1370    String LSCPServer::ResetSampler() {
1371        dmsg(2,("LSCPServer: ResetSampler()\n"));
1372        pSampler->Reset();
1373        LSCPResultSet result;
1374        return result.Produce();
1375    }
1376    
1377    /**
1378   * 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
1379   * server for receiving event messages.   * server for receiving event messages.
1380   */   */
# Line 1243  String LSCPServer::UnsubscribeNotificati Line 1400  String LSCPServer::UnsubscribeNotificati
1400      return result.Produce();      return result.Produce();
1401  }  }
1402    
1403    static int select_callback(void * lscpResultSet, int argc,
1404  // Instrument loader constructor.                          char **argv, char **azColName)
 LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument)  
     : Thread(false, 0, -4)  
1405  {  {
1406      this->pEngine = pEngine;      LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet;
1407      this->Filename = Filename;      resultSet->Add(argc, argv);
1408      this->uiInstrument = uiInstrument;      return 0;
1409  }  }
1410    
1411  // Instrument loader process.  String LSCPServer::QueryDatabase(String query) {
1412  int LSCPLoadInstrument::Main()      LSCPResultSet result;
1413  {  #if HAVE_SQLITE3
1414      try {      char* zErrMsg = NULL;
1415          pEngine->LoadInstrument(Filename.c_str(), uiInstrument);      sqlite3 *db;
1416        String selectStr = "SELECT " + query;
1417    
1418        int rc = sqlite3_open("linuxsampler.db", &db);
1419        if (rc == SQLITE_OK)
1420        {
1421                rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg);
1422        }
1423        if ( rc != SQLITE_OK )
1424        {
1425                result.Error(String(zErrMsg), rc);
1426      }      }
1427        sqlite3_close(db);
1428    #else
1429        result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0);
1430    #endif
1431        return result.Produce();
1432    }
1433    
1434    /**
1435     * Will be called by the parser to enable or disable echo mode; if echo
1436     * mode is enabled, all commands from the client will (immediately) be
1437     * echoed back to the client.
1438     */
1439    String LSCPServer::SetEcho(yyparse_param_t* pSession, double boolean_value) {
1440        dmsg(2,("LSCPServer: SetEcho(val=%f)\n", boolean_value));
1441        LSCPResultSet result;
1442        try {
1443            if      (boolean_value == 0) pSession->bVerbose = false;
1444            else if (boolean_value == 1) pSession->bVerbose = true;
1445            else throw LinuxSamplerException("Not a boolean value, must either be 0 or 1");
1446        }
1447      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1448          e.PrintMessage();           result.Error(e);
1449      }      }
1450        return result.Produce();
     // Always re-enable the engine.  
     pEngine->Enable();  
   
     // FIXME: Shoot ourselves on the foot?  
     delete this;  
1451  }  }

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

  ViewVC Help
Powered by ViewVC