/[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 211 by schoenebeck, Sun Jul 25 23:27:41 2004 UTC revision 905 by schoenebeck, Sun Jul 23 16:23:13 2006 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6     *   Copyright (C) 2005, 2006 Christian Schoenebeck                        *
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    
31    #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"  #include "../drivers/audio/AudioOutputDeviceFactory.h"
38  #include "../drivers/midi/MidiInputDeviceFactory.h"  #include "../drivers/midi/MidiInputDeviceFactory.h"
39    
# Line 50  std::map< LSCPEvent::event_t, std::list< Line 59  std::map< LSCPEvent::event_t, std::list<
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, long int addr, short int port) : Thread(true, false, 0, -4) {
65        SocketAddress.sin_family      = AF_INET;
66        SocketAddress.sin_addr.s_addr = addr;
67        SocketAddress.sin_port        = port;
68      this->pSampler = pSampler;      this->pSampler = pSampler;
69      LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT");
70      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");
71      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");
72      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");
73      LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");
74      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
75        LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");
76        hSocket = -1;
77    }
78    
79    LSCPServer::~LSCPServer() {
80        if (hSocket >= 0) close(hSocket);
81  }  }
82    
83  /**  /**
# Line 76  int LSCPServer::WaitUntilInitialized(lon Line 95  int LSCPServer::WaitUntilInitialized(lon
95  }  }
96    
97  int LSCPServer::Main() {  int LSCPServer::Main() {
98      int hSocket = socket(AF_INET, SOCK_STREAM, 0);      hSocket = socket(AF_INET, SOCK_STREAM, 0);
99      if (hSocket < 0) {      if (hSocket < 0) {
100          std::cerr << "LSCPServer: Could not create server socket." << std::endl;          std::cerr << "LSCPServer: Could not create server socket." << std::endl;
101          //return -1;          //return -1;
102          exit(EXIT_FAILURE);          exit(EXIT_FAILURE);
103      }      }
104    
     SocketAddress.sin_family      = AF_INET;  
     SocketAddress.sin_port        = htons(LSCP_PORT);  
     SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY);  
   
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);
# Line 104  int LSCPServer::Main() { Line 128  int LSCPServer::Main() {
128      FD_SET(hSocket, &fdSet);      FD_SET(hSocket, &fdSet);
129      int maxSessions = hSocket;      int maxSessions = hSocket;
130    
131        timeval timeout;
132    
133      while (true) {      while (true) {
134          fd_set selectSet = fdSet;          // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers
135          int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL);          {
136                std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
137                std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
138                std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
139                for (; itEngineChannel != itEnd; ++itEngineChannel) {
140                    if ((*itEngineChannel)->StatusChanged()) {
141                        SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));
142                    }
143                }
144            }
145    
146            //Now let's deliver late notifies (if any)
147            NotifyBufferMutex.Lock();
148            for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {
149    #ifdef MSG_NOSIGNAL
150                    send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL);
151    #else
152                    send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0);
153    #endif
154            }
155            bufferedNotifies.clear();
156            NotifyBufferMutex.Unlock();
157    
158            fd_set selectSet = fdSet;
159            timeout.tv_sec  = 0;
160            timeout.tv_usec = 100000;
161    
162            int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout);
163    
164          if (retval == 0)          if (retval == 0)
165                  continue; //Nothing try again                  continue; //Nothing try again
166          if (retval == -1) {          if (retval == -1) {
# Line 147  int LSCPServer::Main() { Line 201  int LSCPServer::Main() {
201                  if (FD_ISSET((*iter).hSession, &selectSet)) {   //Was it this socket?                  if (FD_ISSET((*iter).hSession, &selectSet)) {   //Was it this socket?
202                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?                          if (GetLSCPCommand(iter)) {     //Have we read the entire command?
203                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));                                  dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));
204                                  yylex_init(&((*iter).pScanner)); //FIXME: should me moved out of this loop and initialized only when a new session is created                                  int dummy; // just a temporary hack to fulfill the restart() function prototype
205                                    restart(NULL, dummy); // restart the 'scanner'
206                                  currentSocket = (*iter).hSession;  //a hack                                  currentSocket = (*iter).hSession;  //a hack
207                                    dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str()));
208                                  if ((*iter).bVerbose) { // if echo mode enabled                                  if ((*iter).bVerbose) { // if echo mode enabled
209                                      AnswerClient(bufferedCommands[currentSocket]);                                      AnswerClient(bufferedCommands[currentSocket]);
210                                  }                                  }
# Line 164  int LSCPServer::Main() { Line 220  int LSCPServer::Main() {
220                          break;                          break;
221                  }                  }
222          }          }
   
         //Now let's deliver late notifies (if any)  
         NotifyBufferMutex.Lock();  
         for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {  
                 send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0);  
                 bufferedNotifies.erase(iterNotify);  
         }  
         NotifyBufferMutex.Unlock();  
223      }      }
     //It will never get here anyway  
     //yylex_destroy(yyparse_param.pScanner);  
224  }  }
225    
226  void LSCPServer::CloseConnection( std::vector<yyparse_param_t>::iterator iter ) {  void LSCPServer::CloseConnection( std::vector<yyparse_param_t>::iterator iter ) {
# Line 193  void LSCPServer::CloseConnection( std::v Line 239  void LSCPServer::CloseConnection( std::v
239          bufferedNotifies.erase(socket);          bufferedNotifies.erase(socket);
240          close(socket);          close(socket);
241          NotifyMutex.Unlock();          NotifyMutex.Unlock();
242          //yylex_destroy((*iter).pScanner);  }
243    
244    int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) {
245            int subs = 0;
246            SubscriptionMutex.Lock();
247            for( std::list<LSCPEvent::event_t>::iterator iter = events.begin();
248                            iter != events.end(); iter++)
249            {
250                    subs += eventSubscriptions.count(*iter);
251            }
252            SubscriptionMutex.Unlock();
253            return subs;
254  }  }
255    
256  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {  void LSCPServer::SendLSCPNotify( LSCPEvent event ) {
# Line 209  void LSCPServer::SendLSCPNotify( LSCPEve Line 266  void LSCPServer::SendLSCPNotify( LSCPEve
266          while (true) {          while (true) {
267                  if (NotifyMutex.Trylock()) {                  if (NotifyMutex.Trylock()) {
268                          for(;iter != end; iter++)                          for(;iter != end; iter++)
269    #ifdef MSG_NOSIGNAL
270                                    send(*iter, notify.c_str(), notify.size(), MSG_NOSIGNAL);
271    #else
272                                  send(*iter, notify.c_str(), notify.size(), 0);                                  send(*iter, notify.c_str(), notify.size(), 0);
273    #endif
274                          NotifyMutex.Unlock();                          NotifyMutex.Unlock();
275                          break;                          break;
276                  } else {                  } else {
# Line 318  void LSCPServer::AnswerClient(String Ret Line 379  void LSCPServer::AnswerClient(String Ret
379      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));
380      if (currentSocket != -1) {      if (currentSocket != -1) {
381              NotifyMutex.Lock();              NotifyMutex.Lock();
382    #ifdef MSG_NOSIGNAL
383                send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL);
384    #else
385              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);              send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);
386    #endif
387              NotifyMutex.Unlock();              NotifyMutex.Unlock();
388      }      }
389  }  }
# Line 362  String LSCPServer::CreateAudioOutputDevi Line 427  String LSCPServer::CreateAudioOutputDevi
427          AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);          AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);
428          // search for the created device to get its index          // search for the created device to get its index
429          int index = GetAudioOutputDeviceIndex(pDevice);          int index = GetAudioOutputDeviceIndex(pDevice);
430          if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device.");          if (index == -1) throw Exception("Internal error: could not find created audio output device.");
431          result = index; // success          result = index; // success
432      }      }
433      catch (LinuxSamplerException e) {      catch (Exception e) {
434          result.Error(e);          result.Error(e);
435      }      }
436      return result.Produce();      return result.Produce();
# Line 378  String LSCPServer::CreateMidiInputDevice Line 443  String LSCPServer::CreateMidiInputDevice
443          MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters);          MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters);
444          // search for the created device to get its index          // search for the created device to get its index
445          int index = GetMidiInputDeviceIndex(pDevice);          int index = GetMidiInputDeviceIndex(pDevice);
446          if (index == -1) throw LinuxSamplerException("Internal error: could not find created midi input device.");          if (index == -1) throw Exception("Internal error: could not find created midi input device.");
447          result = index; // success          result = index; // success
448      }      }
449      catch (LinuxSamplerException e) {      catch (Exception e) {
450          result.Error(e);          result.Error(e);
451      }      }
452      return result.Produce();      return result.Produce();
# Line 392  String LSCPServer::DestroyAudioOutputDev Line 457  String LSCPServer::DestroyAudioOutputDev
457      LSCPResultSet result;      LSCPResultSet result;
458      try {      try {
459          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
460          if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + ".");
461          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
462          pSampler->DestroyAudioOutputDevice(pDevice);          pSampler->DestroyAudioOutputDevice(pDevice);
463      }      }
464      catch (LinuxSamplerException e) {      catch (Exception e) {
465          result.Error(e);          result.Error(e);
466      }      }
467      return result.Produce();      return result.Produce();
# Line 407  String LSCPServer::DestroyMidiInputDevic Line 472  String LSCPServer::DestroyMidiInputDevic
472      LSCPResultSet result;      LSCPResultSet result;
473      try {      try {
474          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
475            if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + ".");
476          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
         if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");  
477          pSampler->DestroyMidiInputDevice(pDevice);          pSampler->DestroyMidiInputDevice(pDevice);
478      }      }
479      catch (LinuxSamplerException e) {      catch (Exception e) {
480          result.Error(e);          result.Error(e);
481      }      }
482      return result.Produce();      return result.Produce();
# Line 425  String LSCPServer::LoadInstrument(String Line 490  String LSCPServer::LoadInstrument(String
490      LSCPResultSet result;      LSCPResultSet result;
491      try {      try {
492          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
493          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
494          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
495          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel yet");
496          if (pSamplerChannel->GetAudioOutputDevice() == NULL)          if (!pSamplerChannel->GetAudioOutputDevice())
497              throw LinuxSamplerException("No audio output device on channel");              throw Exception("No audio output device connected to sampler channel");
498          if (bBackground) {          if (bBackground) {
499              LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel);
500              pLoadInstrument->StartThread();          }
501            else {
502                // tell the engine channel which instrument to load
503                pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument);
504                // actually start to load the instrument (blocks until completed)
505                pEngineChannel->LoadInstrument();
506          }          }
         else pEngine->LoadInstrument(Filename.c_str(), uiInstrument);  
507      }      }
508      catch (LinuxSamplerException e) {      catch (Exception e) {
509           result.Error(e);           result.Error(e);
510      }      }
511      return result.Produce();      return result.Produce();
512  }  }
513    
514  /**  /**
515   * 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
516     * sampler channel.
517   */   */
518  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {  String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) {
519      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));      dmsg(2,("LSCPServer: SetEngineType(EngineName=%s,uiSamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));
520      LSCPResultSet result;      LSCPResultSet result;
521      try {      try {
         Engine::type_t type;  
         if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig;  
         else throw LinuxSamplerException("Unknown engine type");  
522          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
523          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
524          pSamplerChannel->LoadEngine(type);          LockRTNotify();
525            pSamplerChannel->SetEngineType(EngineName);
526            if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1);
527            UnlockRTNotify();
528      }      }
529      catch (LinuxSamplerException e) {      catch (Exception e) {
530           result.Error(e);           result.Error(e);
531      }      }
532      return result.Produce();      return result.Produce();
# Line 494  String LSCPServer::ListChannels() { Line 564  String LSCPServer::ListChannels() {
564   */   */
565  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
566      dmsg(2,("LSCPServer: AddChannel()\n"));      dmsg(2,("LSCPServer: AddChannel()\n"));
567        LockRTNotify();
568      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();
569        UnlockRTNotify();
570      LSCPResultSet result(pSamplerChannel->Index());      LSCPResultSet result(pSamplerChannel->Index());
571      return result.Produce();      return result.Produce();
572  }  }
# Line 505  String LSCPServer::AddChannel() { Line 577  String LSCPServer::AddChannel() {
577  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {
578      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));
579      LSCPResultSet result;      LSCPResultSet result;
580        LockRTNotify();
581      pSampler->RemoveSamplerChannel(uiSamplerChannel);      pSampler->RemoveSamplerChannel(uiSamplerChannel);
582        UnlockRTNotify();
583      return result.Produce();      return result.Produce();
584  }  }
585    
586  /**  /**
587   * 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.
588   */   */
589  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
590      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
591      LSCPResultSet result("GigEngine");      LSCPResultSet result;
592        try {
593            int n = EngineFactory::AvailableEngineTypes().size();
594            result.Add(n);
595        }
596        catch (Exception e) {
597            result.Error(e);
598        }
599        return result.Produce();
600    }
601    
602    /**
603     * Will be called by the parser to get a list of all available engines.
604     */
605    String LSCPServer::ListAvailableEngines() {
606        dmsg(2,("LSCPServer: ListAvailableEngines()\n"));
607        LSCPResultSet result;
608        try {
609            String s = EngineFactory::AvailableEngineTypesAsString();
610            result.Add(s);
611        }
612        catch (Exception e) {
613            result.Error(e);
614        }
615      return result.Produce();      return result.Produce();
616  }  }
617    
618  /**  /**
619   * 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
620     * sampler engine.
621   */   */
622  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
623      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
624      LSCPResultSet result;      LSCPResultSet result;
625        LockRTNotify();
626      try {      try {
627          if ((EngineName == "GigEngine") || (EngineName == "gig")) {          Engine* pEngine = EngineFactory::Create(EngineName);
628              Engine* pEngine = new LinuxSampler::gig::Engine;          result.Add("DESCRIPTION", pEngine->Description());
629              result.Add(pEngine->Description());          result.Add("VERSION",     pEngine->Version());
630              result.Add(pEngine->Version());          EngineFactory::Destroy(pEngine);
             delete pEngine;  
         }  
         else throw LinuxSamplerException("Unknown engine type");  
631      }      }
632      catch (LinuxSamplerException e) {      catch (Exception e) {
633           result.Error(e);           result.Error(e);
634      }      }
635        UnlockRTNotify();
636      return result.Produce();      return result.Produce();
637  }  }
638    
# Line 548  String LSCPServer::GetChannelInfo(uint u Line 645  String LSCPServer::GetChannelInfo(uint u
645      LSCPResultSet result;      LSCPResultSet result;
646      try {      try {
647          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
648          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
649          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
650    
651          //Defaults values          //Defaults values
652          String EngineName = "NONE";          String EngineName = "NONE";
653          float Volume = 0;          float Volume = 0.0f;
654          String InstrumentFileName = "NONE";          String InstrumentFileName = "NONE";
655            String InstrumentName = "NONE";
656          int InstrumentIndex = -1;          int InstrumentIndex = -1;
657          int InstrumentStatus = -1;          int InstrumentStatus = -1;
658            int AudioOutputChannels = 0;
659          if (pEngine) {          String AudioRouting;
660              EngineName =  pEngine->EngineName();          int Mute = 0;
661              Volume = pEngine->Volume();          bool Solo = false;
662              InstrumentStatus = pEngine->InstrumentStatus();  
663              InstrumentIndex = pEngine->InstrumentIndex();          if (pEngineChannel) {
664              if (InstrumentIndex != -1)              EngineName          = pEngineChannel->EngineName();
665                  InstrumentFileName = pEngine->InstrumentFileName();              AudioOutputChannels = pEngineChannel->Channels();
666                Volume              = pEngineChannel->Volume();
667                InstrumentStatus    = pEngineChannel->InstrumentStatus();
668                InstrumentIndex     = pEngineChannel->InstrumentIndex();
669                if (InstrumentIndex != -1) {
670                    InstrumentFileName = pEngineChannel->InstrumentFileName();
671                    InstrumentName     = pEngineChannel->InstrumentName();
672                }
673                for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
674                    if (AudioRouting != "") AudioRouting += ",";
675                    AudioRouting += ToString(pEngineChannel->OutputChannel(chan));
676                }
677                Mute = pEngineChannel->GetMute();
678                Solo = pEngineChannel->GetSolo();
679          }          }
680    
681          result.Add("ENGINE_NAME", EngineName);          result.Add("ENGINE_NAME", EngineName);
# Line 572  String LSCPServer::GetChannelInfo(uint u Line 683  String LSCPServer::GetChannelInfo(uint u
683    
684          //Some not-so-hardcoded stuff to make GUI look good          //Some not-so-hardcoded stuff to make GUI look good
685          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));          result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));
686          result.Add("AUDIO_OUTPUT_CHANNELS", "2");          result.Add("AUDIO_OUTPUT_CHANNELS", AudioOutputChannels);
687          result.Add("AUDIO_OUTPUT_ROUTING", "0,1");          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
688    
689          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));
690          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());
691          result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());          if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL");
692            else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
693    
694          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
695          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
696            result.Add("INSTRUMENT_NAME", InstrumentName);
697          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
698            result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false"));
699            result.Add("SOLO", Solo);
700      }      }
701      catch (LinuxSamplerException e) {      catch (Exception e) {
702           result.Error(e);           result.Error(e);
703      }      }
704      return result.Produce();      return result.Produce();
# Line 598  String LSCPServer::GetVoiceCount(uint ui Line 713  String LSCPServer::GetVoiceCount(uint ui
713      LSCPResultSet result;      LSCPResultSet result;
714      try {      try {
715          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
716          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
717          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
718          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw Exception("No engine loaded on sampler channel");
719          result.Add(pEngine->VoiceCount());          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
720            result.Add(pEngineChannel->GetEngine()->VoiceCount());
721      }      }
722      catch (LinuxSamplerException e) {      catch (Exception e) {
723           result.Error(e);           result.Error(e);
724      }      }
725      return result.Produce();      return result.Produce();
# Line 618  String LSCPServer::GetStreamCount(uint u Line 734  String LSCPServer::GetStreamCount(uint u
734      LSCPResultSet result;      LSCPResultSet result;
735      try {      try {
736          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
737          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
738          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
739          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
740          result.Add(pEngine->DiskStreamCount());          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
741            result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
742      }      }
743      catch (LinuxSamplerException e) {      catch (Exception e) {
744           result.Error(e);           result.Error(e);
745      }      }
746      return result.Produce();      return result.Produce();
# Line 638  String LSCPServer::GetBufferFill(fill_re Line 755  String LSCPServer::GetBufferFill(fill_re
755      LSCPResultSet result;      LSCPResultSet result;
756      try {      try {
757          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
758          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
759          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
760          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
761          if (!pEngine->DiskStreamSupported())          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
762              result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
763          else {          else {
764              switch (ResponseType) {              switch (ResponseType) {
765                  case fill_response_bytes:                  case fill_response_bytes:
766                      result.Add(pEngine->DiskStreamBufferFillBytes());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillBytes());
767                      break;                      break;
768                  case fill_response_percentage:                  case fill_response_percentage:
769                      result.Add(pEngine->DiskStreamBufferFillPercentage());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());
770                      break;                      break;
771                  default:                  default:
772                      throw LinuxSamplerException("Unknown fill response type");                      throw Exception("Unknown fill response type");
773              }              }
774          }          }
775      }      }
776      catch (LinuxSamplerException e) {      catch (Exception e) {
777           result.Error(e);           result.Error(e);
778      }      }
779      return result.Produce();      return result.Produce();
# Line 666  String LSCPServer::GetAvailableAudioOutp Line 783  String LSCPServer::GetAvailableAudioOutp
783      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));      dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));
784      LSCPResultSet result;      LSCPResultSet result;
785      try {      try {
786            int n = AudioOutputDeviceFactory::AvailableDrivers().size();
787            result.Add(n);
788        }
789        catch (Exception e) {
790            result.Error(e);
791        }
792        return result.Produce();
793    }
794    
795    String LSCPServer::ListAvailableAudioOutputDrivers() {
796        dmsg(2,("LSCPServer: ListAvailableAudioOutputDrivers()\n"));
797        LSCPResultSet result;
798        try {
799          String s = AudioOutputDeviceFactory::AvailableDriversAsString();          String s = AudioOutputDeviceFactory::AvailableDriversAsString();
800          result.Add(s);          result.Add(s);
801      }      }
802      catch (LinuxSamplerException e) {      catch (Exception e) {
803          result.Error(e);          result.Error(e);
804      }      }
805      return result.Produce();      return result.Produce();
# Line 679  String LSCPServer::GetAvailableMidiInput Line 809  String LSCPServer::GetAvailableMidiInput
809      dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));      dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));
810      LSCPResultSet result;      LSCPResultSet result;
811      try {      try {
812            int n = MidiInputDeviceFactory::AvailableDrivers().size();
813            result.Add(n);
814        }
815        catch (Exception e) {
816            result.Error(e);
817        }
818        return result.Produce();
819    }
820    
821    String LSCPServer::ListAvailableMidiInputDrivers() {
822        dmsg(2,("LSCPServer: ListAvailableMidiInputDrivers()\n"));
823        LSCPResultSet result;
824        try {
825          String s = MidiInputDeviceFactory::AvailableDriversAsString();          String s = MidiInputDeviceFactory::AvailableDriversAsString();
826          result.Add(s);          result.Add(s);
827      }      }
828      catch (LinuxSamplerException e) {      catch (Exception e) {
829          result.Error(e);          result.Error(e);
830      }      }
831      return result.Produce();      return result.Produce();
# Line 706  String LSCPServer::GetMidiInputDriverInf Line 849  String LSCPServer::GetMidiInputDriverInf
849              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
850          }          }
851      }      }
852      catch (LinuxSamplerException e) {      catch (Exception e) {
853          result.Error(e);          result.Error(e);
854      }      }
855      return result.Produce();      return result.Produce();
# Line 730  String LSCPServer::GetAudioOutputDriverI Line 873  String LSCPServer::GetAudioOutputDriverI
873              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
874          }          }
875      }      }
876      catch (LinuxSamplerException e) {      catch (Exception e) {
877          result.Error(e);          result.Error(e);
878      }      }
879      return result.Produce();      return result.Produce();
880  }  }
881    
882  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
883      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()));
884      LSCPResultSet result;      LSCPResultSet result;
885      try {      try {
886          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);
# Line 746  String LSCPServer::GetMidiInputDriverPar Line 889  String LSCPServer::GetMidiInputDriverPar
889          result.Add("MANDATORY",    pParameter->Mandatory());          result.Add("MANDATORY",    pParameter->Mandatory());
890          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
891          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
892          if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());          optional<String> oDepends       = pParameter->Depends();
893          if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());          optional<String> oDefault       = pParameter->Default(DependencyList);
894          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          optional<String> oRangeMin      = pParameter->RangeMin(DependencyList);
895          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          optional<String> oRangeMax      = pParameter->RangeMax(DependencyList);
896          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          optional<String> oPossibilities = pParameter->Possibilities(DependencyList);
897            if (oDepends)       result.Add("DEPENDS",       *oDepends);
898            if (oDefault)       result.Add("DEFAULT",       *oDefault);
899            if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
900            if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
901            if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
902      }      }
903      catch (LinuxSamplerException e) {      catch (Exception e) {
904          result.Error(e);          result.Error(e);
905      }      }
906      return result.Produce();      return result.Produce();
907  }  }
908    
909  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {  String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
910      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()));
911      LSCPResultSet result;      LSCPResultSet result;
912      try {      try {
913          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);          DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);
# Line 768  String LSCPServer::GetAudioOutputDriverP Line 916  String LSCPServer::GetAudioOutputDriverP
916          result.Add("MANDATORY",    pParameter->Mandatory());          result.Add("MANDATORY",    pParameter->Mandatory());
917          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
918          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
919          if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());          optional<String> oDepends       = pParameter->Depends();
920          if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());          optional<String> oDefault       = pParameter->Default(DependencyList);
921          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          optional<String> oRangeMin      = pParameter->RangeMin(DependencyList);
922          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          optional<String> oRangeMax      = pParameter->RangeMax(DependencyList);
923          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          optional<String> oPossibilities = pParameter->Possibilities(DependencyList);
924            if (oDepends)       result.Add("DEPENDS",       *oDepends);
925            if (oDefault)       result.Add("DEFAULT",       *oDefault);
926            if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
927            if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
928            if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
929      }      }
930      catch (LinuxSamplerException e) {      catch (Exception e) {
931          result.Error(e);          result.Error(e);
932      }      }
933      return result.Produce();      return result.Produce();
# Line 787  String LSCPServer::GetAudioOutputDeviceC Line 940  String LSCPServer::GetAudioOutputDeviceC
940          uint count = pSampler->AudioOutputDevices();          uint count = pSampler->AudioOutputDevices();
941          result.Add(count); // success          result.Add(count); // success
942      }      }
943      catch (LinuxSamplerException e) {      catch (Exception e) {
944          result.Error(e);          result.Error(e);
945      }      }
946      return result.Produce();      return result.Produce();
# Line 800  String LSCPServer::GetMidiInputDeviceCou Line 953  String LSCPServer::GetMidiInputDeviceCou
953          uint count = pSampler->MidiInputDevices();          uint count = pSampler->MidiInputDevices();
954          result.Add(count); // success          result.Add(count); // success
955      }      }
956      catch (LinuxSamplerException e) {      catch (Exception e) {
957          result.Error(e);          result.Error(e);
958      }      }
959      return result.Produce();      return result.Produce();
# Line 819  String LSCPServer::GetAudioOutputDevices Line 972  String LSCPServer::GetAudioOutputDevices
972          }          }
973          result.Add(s);          result.Add(s);
974      }      }
975      catch (LinuxSamplerException e) {      catch (Exception e) {
976          result.Error(e);          result.Error(e);
977      }      }
978      return result.Produce();      return result.Produce();
# Line 838  String LSCPServer::GetMidiInputDevices() Line 991  String LSCPServer::GetMidiInputDevices()
991          }          }
992          result.Add(s);          result.Add(s);
993      }      }
994      catch (LinuxSamplerException e) {      catch (Exception e) {
995          result.Error(e);          result.Error(e);
996      }      }
997      return result.Produce();      return result.Produce();
# Line 849  String LSCPServer::GetAudioOutputDeviceI Line 1002  String LSCPServer::GetAudioOutputDeviceI
1002      LSCPResultSet result;      LSCPResultSet result;
1003      try {      try {
1004          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1005          if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + ".");
1006          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1007          result.Add("driver", pDevice->Driver());          result.Add("DRIVER", pDevice->Driver());
1008          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1009          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
1010          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
1011              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1012          }          }
1013      }      }
1014      catch (LinuxSamplerException e) {      catch (Exception e) {
1015          result.Error(e);          result.Error(e);
1016      }      }
1017      return result.Produce();      return result.Produce();
# Line 869  String LSCPServer::GetMidiInputDeviceInf Line 1022  String LSCPServer::GetMidiInputDeviceInf
1022      LSCPResultSet result;      LSCPResultSet result;
1023      try {      try {
1024          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1025            if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1026          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1027          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          result.Add("DRIVER", pDevice->Driver());
         result.Add("driver", pDevice->Driver());  
1028          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1029          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
1030          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
1031              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1032          }          }
1033      }      }
1034      catch (LinuxSamplerException e) {      catch (Exception e) {
1035          result.Error(e);          result.Error(e);
1036      }      }
1037      return result.Produce();      return result.Produce();
# Line 887  String LSCPServer::GetMidiInputPortInfo( Line 1040  String LSCPServer::GetMidiInputPortInfo(
1040      dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));      dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));
1041      LSCPResultSet result;      LSCPResultSet result;
1042      try {      try {
1043            // get MIDI input device
1044          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1045            if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1046          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1047          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");  
1048          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          // get MIDI port
1049          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1050          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();          if (!pMidiInputPort) throw Exception("There is no MIDI input port with index " + ToString(PortIndex) + ".");
1051          std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();  
1052            // return the values of all MIDI port parameters
1053            std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1054            std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin();
1055          for (; iter != parameters.end(); iter++) {          for (; iter != parameters.end(); iter++) {
1056              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1057          }          }
1058      }      }
1059      catch (LinuxSamplerException e) {      catch (Exception e) {
1060          result.Error(e);          result.Error(e);
1061      }      }
1062      return result.Produce();      return result.Produce();
# Line 910  String LSCPServer::GetAudioOutputChannel Line 1068  String LSCPServer::GetAudioOutputChannel
1068      try {      try {
1069          // get audio output device          // get audio output device
1070          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1071          if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw Exception("There is no audio output device with index " + ToString(DeviceId) + ".");
1072          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1073    
1074          // get audio channel          // get audio channel
1075          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1076          if (!pChannel) throw LinuxSamplerException("Audio ouotput device does not have channel " + ToString(ChannelId) + ".");          if (!pChannel) throw Exception("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
1077    
1078          // return the values of all audio channel parameters          // return the values of all audio channel parameters
1079          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 924  String LSCPServer::GetAudioOutputChannel Line 1082  String LSCPServer::GetAudioOutputChannel
1082              result.Add(iter->first, iter->second->Value());              result.Add(iter->first, iter->second->Value());
1083          }          }
1084      }      }
1085      catch (LinuxSamplerException e) {      catch (Exception e) {
1086          result.Error(e);          result.Error(e);
1087      }      }
1088      return result.Produce();      return result.Produce();
# Line 934  String LSCPServer::GetMidiInputPortParam Line 1092  String LSCPServer::GetMidiInputPortParam
1092      dmsg(2,("LSCPServer: GetMidiInputPortParameterInfo(DeviceId=%d,PortId=%d,ParameterName=%s)\n",DeviceId,PortId,ParameterName.c_str()));      dmsg(2,("LSCPServer: GetMidiInputPortParameterInfo(DeviceId=%d,PortId=%d,ParameterName=%s)\n",DeviceId,PortId,ParameterName.c_str()));
1093      LSCPResultSet result;      LSCPResultSet result;
1094      try {      try {
1095          // get audio output device          // get MIDI input device
1096          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1097          if (!devices[DeviceId]) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw Exception("There is no midi input device with index " + ToString(DeviceId) + ".");
1098          MidiInputDevice* pDevice = devices[DeviceId];          MidiInputDevice* pDevice = devices[DeviceId];
1099    
1100          // get midi port          // get midi port
1101          MidiInputDevice::MidiInputPort* pPort = pDevice->GetPort(PortId);          MidiInputPort* pPort = pDevice->GetPort(PortId);
1102          if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + ".");          if (!pPort) throw Exception("Midi input device does not have port " + ToString(PortId) + ".");
1103    
1104          // get desired port parameter          // get desired port parameter
1105          std::map<String,DeviceCreationParameter*> parameters = pPort->DeviceParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters();
1106          if (!parameters[ParameterName]) throw LinuxSamplerException("Midi port does not provice a parameters '" + ParameterName + "'.");          if (!parameters.count(ParameterName)) throw Exception("Midi port does not provide a parameter '" + ParameterName + "'.");
1107          DeviceCreationParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1108    
1109          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
1110          result.Add("TYPE",         pParameter->Type());          result.Add("TYPE",         pParameter->Type());
1111          result.Add("DESCRIPTION",  pParameter->Description());          result.Add("DESCRIPTION",  pParameter->Description());
1112          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
1113          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
1114          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());
1115          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1116          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1117      }      }
1118      catch (LinuxSamplerException e) {      catch (Exception e) {
1119          result.Error(e);          result.Error(e);
1120      }      }
1121      return result.Produce();      return result.Produce();
# Line 969  String LSCPServer::GetAudioOutputChannel Line 1127  String LSCPServer::GetAudioOutputChannel
1127      try {      try {
1128          // get audio output device          // get audio output device
1129          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1130          if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw Exception("There is no audio output device with index " + ToString(DeviceId) + ".");
1131          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1132    
1133          // get audio channel          // get audio channel
1134          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1135          if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");          if (!pChannel) throw Exception("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
1136    
1137          // get desired audio channel parameter          // get desired audio channel parameter
1138          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1139          if (!parameters[ParameterName]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'.");          if (!parameters.count(ParameterName)) throw Exception("Audio channel does not provide a parameter '" + ParameterName + "'.");
1140          DeviceRuntimeParameter* pParameter = parameters[ParameterName];          DeviceRuntimeParameter* pParameter = parameters[ParameterName];
1141    
1142          // return all fields of this audio channel parameter          // return all fields of this audio channel parameter
# Line 986  String LSCPServer::GetAudioOutputChannel Line 1144  String LSCPServer::GetAudioOutputChannel
1144          result.Add("DESCRIPTION",  pParameter->Description());          result.Add("DESCRIPTION",  pParameter->Description());
1145          result.Add("FIX",          pParameter->Fix());          result.Add("FIX",          pParameter->Fix());
1146          result.Add("MULTIPLICITY", pParameter->Multiplicity());          result.Add("MULTIPLICITY", pParameter->Multiplicity());
1147          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());          if (pParameter->RangeMin())      result.Add("RANGE_MIN",     *pParameter->RangeMin());
1148          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());          if (pParameter->RangeMax())      result.Add("RANGE_MAX",     *pParameter->RangeMax());
1149          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());          if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities());
1150      }      }
1151      catch (LinuxSamplerException e) {      catch (Exception e) {
1152          result.Error(e);          result.Error(e);
1153      }      }
1154      return result.Produce();      return result.Produce();
# Line 1002  String LSCPServer::SetAudioOutputChannel Line 1160  String LSCPServer::SetAudioOutputChannel
1160      try {      try {
1161          // get audio output device          // get audio output device
1162          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1163          if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");          if (!devices.count(DeviceId)) throw Exception("There is no audio output device with index " + ToString(DeviceId) + ".");
1164          AudioOutputDevice* pDevice = devices[DeviceId];          AudioOutputDevice* pDevice = devices[DeviceId];
1165    
1166          // get audio channel          // get audio channel
1167          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1168          if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");          if (!pChannel) throw Exception("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
1169    
1170          // get desired audio channel parameter          // get desired audio channel parameter
1171          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
1172          if (!parameters[ParamKey]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'.");          if (!parameters.count(ParamKey)) throw Exception("Audio channel does not provide a parameter '" + ParamKey + "'.");
1173          DeviceRuntimeParameter* pParameter = parameters[ParamKey];          DeviceRuntimeParameter* pParameter = parameters[ParamKey];
1174    
1175          // set new channel parameter value          // set new channel parameter value
1176          pParameter->SetValue(ParamVal);          pParameter->SetValue(ParamVal);
1177      }      }
1178      catch (LinuxSamplerException e) {      catch (Exception e) {
1179          result.Error(e);          result.Error(e);
1180      }      }
1181      return result.Produce();      return result.Produce();
# Line 1028  String LSCPServer::SetAudioOutputDeviceP Line 1186  String LSCPServer::SetAudioOutputDeviceP
1186      LSCPResultSet result;      LSCPResultSet result;
1187      try {      try {
1188          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1189          if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + ".");
1190          AudioOutputDevice* pDevice = devices[DeviceIndex];          AudioOutputDevice* pDevice = devices[DeviceIndex];
1191          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1192          if (!parameters[ParamKey]) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");          if (!parameters.count(ParamKey)) throw Exception("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
1193          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1194      }      }
1195      catch (LinuxSamplerException e) {      catch (Exception e) {
1196          result.Error(e);          result.Error(e);
1197      }      }
1198      return result.Produce();      return result.Produce();
# Line 1045  String LSCPServer::SetMidiInputDevicePar Line 1203  String LSCPServer::SetMidiInputDevicePar
1203      LSCPResultSet result;      LSCPResultSet result;
1204      try {      try {
1205          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1206          if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");          if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1207          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1208          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();          std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1209          if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");          if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
1210          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1211      }      }
1212      catch (LinuxSamplerException e) {      catch (Exception e) {
1213          result.Error(e);          result.Error(e);
1214      }      }
1215      return result.Produce();      return result.Produce();
# Line 1061  String LSCPServer::SetMidiInputPortParam Line 1219  String LSCPServer::SetMidiInputPortParam
1219      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()));
1220      LSCPResultSet result;      LSCPResultSet result;
1221      try {      try {
1222            // get MIDI input device
1223          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1224            if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1225          MidiInputDevice* pDevice = devices[DeviceIndex];          MidiInputDevice* pDevice = devices[DeviceIndex];
1226          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");  
1227          MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);          // get MIDI port
1228          if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");          MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1229          std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();          if (!pMidiInputPort) throw Exception("There is no MIDI input port with index " + ToString(PortIndex) + ".");
1230          if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");  
1231            // set port parameter value
1232            std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters();
1233            if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");
1234          parameters[ParamKey]->SetValue(ParamVal);          parameters[ParamKey]->SetValue(ParamVal);
1235      }      }
1236      catch (LinuxSamplerException e) {      catch (Exception e) {
1237          result.Error(e);          result.Error(e);
1238      }      }
1239      return result.Produce();      return result.Produce();
# Line 1082  String LSCPServer::SetMidiInputPortParam Line 1245  String LSCPServer::SetMidiInputPortParam
1245   */   */
1246  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {
1247      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));
1248      return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class?      LSCPResultSet result;
1249        try {
1250            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1251            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1252            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1253            if (!pEngineChannel) throw Exception("No engine type yet assigned to sampler channel " + ToString(uiSamplerChannel));
1254            if (!pSamplerChannel->GetAudioOutputDevice()) throw Exception("No audio output device connected to sampler channel " + ToString(uiSamplerChannel));
1255            pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1256        }
1257        catch (Exception e) {
1258             result.Error(e);
1259        }
1260        return result.Produce();
1261  }  }
1262    
1263  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
1264      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));
1265      LSCPResultSet result;      LSCPResultSet result;
1266        LockRTNotify();
1267      try {      try {
1268          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1269          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1270          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1271            if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId));
1272          AudioOutputDevice* pDevice = devices[AudioDeviceId];          AudioOutputDevice* pDevice = devices[AudioDeviceId];
         if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));  
1273          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1274      }      }
1275      catch (LinuxSamplerException e) {      catch (Exception e) {
1276           result.Error(e);           result.Error(e);
1277      }      }
1278        UnlockRTNotify();
1279      return result.Produce();      return result.Produce();
1280  }  }
1281    
1282  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {
1283      dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel));
1284      LSCPResultSet result;      LSCPResultSet result;
1285        LockRTNotify();
1286      try {      try {
1287          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1288          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1289          // Driver type name aliasing...          // Driver type name aliasing...
1290          if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1291          if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack";          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
1292          // Check if there's one audio output device already created          // Check if there's one audio output device already created
1293          // for the intended audio driver type (AudioOutputDriver)...          // for the intended audio driver type (AudioOutputDriver)...
1294          AudioOutputDevice *pDevice = NULL;          AudioOutputDevice *pDevice = NULL;
# Line 1129  String LSCPServer::SetAudioOutputType(St Line 1307  String LSCPServer::SetAudioOutputType(St
1307          }          }
1308          // Must have a device...          // Must have a device...
1309          if (pDevice == NULL)          if (pDevice == NULL)
1310              throw LinuxSamplerException("Internal error: could not create audio output device.");              throw Exception("Internal error: could not create audio output device.");
1311          // Set it as the current channel device...          // Set it as the current channel device...
1312          pSamplerChannel->SetAudioOutputDevice(pDevice);          pSamplerChannel->SetAudioOutputDevice(pDevice);
1313      }      }
1314      catch (LinuxSamplerException e) {      catch (Exception e) {
1315           result.Error(e);           result.Error(e);
1316      }      }
1317        UnlockRTNotify();
1318      return result.Produce();      return result.Produce();
1319  }  }
1320    
# Line 1144  String LSCPServer::SetMIDIInputPort(uint Line 1323  String LSCPServer::SetMIDIInputPort(uint
1323      LSCPResultSet result;      LSCPResultSet result;
1324      try {      try {
1325          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1326          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1327          pSamplerChannel->SetMidiInputPort(MIDIPort);          pSamplerChannel->SetMidiInputPort(MIDIPort);
1328      }      }
1329      catch (LinuxSamplerException e) {      catch (Exception e) {
1330           result.Error(e);           result.Error(e);
1331      }      }
1332      return result.Produce();      return result.Produce();
# Line 1158  String LSCPServer::SetMIDIInputChannel(u Line 1337  String LSCPServer::SetMIDIInputChannel(u
1337      LSCPResultSet result;      LSCPResultSet result;
1338      try {      try {
1339          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1340          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1341          pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel);
1342      }      }
1343      catch (LinuxSamplerException e) {      catch (Exception e) {
1344           result.Error(e);           result.Error(e);
1345      }      }
1346      return result.Produce();      return result.Produce();
# Line 1172  String LSCPServer::SetMIDIInputDevice(ui Line 1351  String LSCPServer::SetMIDIInputDevice(ui
1351      LSCPResultSet result;      LSCPResultSet result;
1352      try {      try {
1353          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1354          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1355          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1356            if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1357          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
         if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));  
1358          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1359      }      }
1360      catch (LinuxSamplerException e) {      catch (Exception e) {
1361           result.Error(e);           result.Error(e);
1362      }      }
1363      return result.Produce();      return result.Produce();
# Line 1189  String LSCPServer::SetMIDIInputType(Stri Line 1368  String LSCPServer::SetMIDIInputType(Stri
1368      LSCPResultSet result;      LSCPResultSet result;
1369      try {      try {
1370          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1371          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1372          // Driver type name aliasing...          // Driver type name aliasing...
1373          if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1374          // Check if there's one MIDI input device already created          // Check if there's one MIDI input device already created
1375          // for the intended MIDI driver type (MidiInputDriver)...          // for the intended MIDI driver type (MidiInputDriver)...
1376          MidiInputDevice *pDevice = NULL;          MidiInputDevice *pDevice = NULL;
# Line 1209  String LSCPServer::SetMIDIInputType(Stri Line 1388  String LSCPServer::SetMIDIInputType(Stri
1388              pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);              pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);
1389              // Make it with at least one initial port.              // Make it with at least one initial port.
1390              std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();              std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1391              parameters["ports"]->SetValue("1");              parameters["PORTS"]->SetValue("1");
1392          }          }
1393          // Must have a device...          // Must have a device...
1394          if (pDevice == NULL)          if (pDevice == NULL)
1395              throw LinuxSamplerException("Internal error: could not create MIDI input device.");              throw Exception("Internal error: could not create MIDI input device.");
1396          // Set it as the current channel device...          // Set it as the current channel device...
1397          pSamplerChannel->SetMidiInputDevice(pDevice);          pSamplerChannel->SetMidiInputDevice(pDevice);
1398      }      }
1399      catch (LinuxSamplerException e) {      catch (Exception e) {
1400           result.Error(e);           result.Error(e);
1401      }      }
1402      return result.Produce();      return result.Produce();
# Line 1232  String LSCPServer::SetMIDIInput(uint MID Line 1411  String LSCPServer::SetMIDIInput(uint MID
1411      LSCPResultSet result;      LSCPResultSet result;
1412      try {      try {
1413          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1414          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1415          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1416            if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1417          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1418          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));          pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel);
         pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);  
1419      }      }
1420      catch (LinuxSamplerException e) {      catch (Exception e) {
1421           result.Error(e);           result.Error(e);
1422      }      }
1423      return result.Produce();      return result.Produce();
# Line 1248  String LSCPServer::SetMIDIInput(uint MID Line 1427  String LSCPServer::SetMIDIInput(uint MID
1427   * 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
1428   * particular sampler channel.   * particular sampler channel.
1429   */   */
1430  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {  String LSCPServer::SetVolume(double dVolume, uint uiSamplerChannel) {
1431      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel));
1432      LSCPResultSet result;      LSCPResultSet result;
1433      try {      try {
1434          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1435          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1436          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1437          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1438          pEngine->Volume(Volume);          pEngineChannel->Volume(dVolume);
1439      }      }
1440      catch (LinuxSamplerException e) {      catch (Exception e) {
1441           result.Error(e);           result.Error(e);
1442      }      }
1443      return result.Produce();      return result.Produce();
1444  }  }
1445    
1446  /**  /**
1447     * Will be called by the parser to mute/unmute particular sampler channel.
1448     */
1449    String LSCPServer::SetChannelMute(bool bMute, uint uiSamplerChannel) {
1450        dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel));
1451        LSCPResultSet result;
1452        try {
1453            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1454            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1455    
1456            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1457            if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1458    
1459            if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);
1460            else pEngineChannel->SetMute(1);
1461        } catch (Exception e) {
1462            result.Error(e);
1463        }
1464        return result.Produce();
1465    }
1466    
1467    /**
1468     * Will be called by the parser to solo particular sampler channel.
1469     */
1470    String LSCPServer::SetChannelSolo(bool bSolo, uint uiSamplerChannel) {
1471        dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel));
1472        LSCPResultSet result;
1473        try {
1474            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1475            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1476    
1477            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1478            if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1479    
1480            bool oldSolo = pEngineChannel->GetSolo();
1481            bool hadSoloChannel = HasSoloChannel();
1482            
1483            pEngineChannel->SetSolo(bSolo);
1484            
1485            if(!oldSolo && bSolo) {
1486                if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0);
1487                if(!hadSoloChannel) MuteNonSoloChannels();
1488            }
1489            
1490            if(oldSolo && !bSolo) {
1491                if(!HasSoloChannel()) UnmuteChannels();
1492                else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1);
1493            }
1494        } catch (Exception e) {
1495            result.Error(e);
1496        }
1497        return result.Produce();
1498    }
1499    
1500    /**
1501     * Determines whether there is at least one solo channel in the channel list.
1502     *
1503     * @returns true if there is at least one solo channel in the channel list,
1504     * false otherwise.
1505     */
1506    bool LSCPServer::HasSoloChannel() {
1507        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
1508        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
1509        for (; iter != channels.end(); iter++) {
1510            EngineChannel* c = iter->second->GetEngineChannel();
1511            if(c && c->GetSolo()) return true;
1512        }
1513    
1514        return false;
1515    }
1516    
1517    /**
1518     * Mutes all unmuted non-solo channels. Notice that the channels are muted
1519     * with -1 which indicates that they are muted because of the presence
1520     * of a solo channel(s). Channels muted with -1 will be automatically unmuted
1521     * when there are no solo channels left.
1522     */
1523    void LSCPServer::MuteNonSoloChannels() {
1524        dmsg(2,("LSCPServer: MuteNonSoloChannels()\n"));
1525        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
1526        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
1527        for (; iter != channels.end(); iter++) {
1528            EngineChannel* c = iter->second->GetEngineChannel();
1529            if(c && !c->GetSolo() && !c->GetMute()) c->SetMute(-1);
1530        }
1531    }
1532    
1533    /**
1534     * Unmutes all channels that are muted because of the presence
1535     * of a solo channel(s).
1536     */
1537    void  LSCPServer::UnmuteChannels() {
1538        dmsg(2,("LSCPServer: UnmuteChannels()\n"));
1539        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
1540        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
1541        for (; iter != channels.end(); iter++) {
1542            EngineChannel* c = iter->second->GetEngineChannel();
1543            if(c && c->GetMute() == -1) c->SetMute(0);
1544        }
1545    }
1546    
1547    /**
1548   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
1549   */   */
1550  String LSCPServer::ResetChannel(uint uiSamplerChannel) {  String LSCPServer::ResetChannel(uint uiSamplerChannel) {
# Line 1272  String LSCPServer::ResetChannel(uint uiS Line 1552  String LSCPServer::ResetChannel(uint uiS
1552      LSCPResultSet result;      LSCPResultSet result;
1553      try {      try {
1554          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1555          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
1556          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1557          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
1558          pEngine->Reset();          pEngineChannel->Reset();
1559      }      }
1560      catch (LinuxSamplerException e) {      catch (Exception e) {
1561           result.Error(e);           result.Error(e);
1562      }      }
1563      return result.Produce();      return result.Produce();
1564  }  }
1565    
1566  /**  /**
1567     * Will be called by the parser to reset the whole sampler.
1568     */
1569    String LSCPServer::ResetSampler() {
1570        dmsg(2,("LSCPServer: ResetSampler()\n"));
1571        pSampler->Reset();
1572        LSCPResultSet result;
1573        return result.Produce();
1574    }
1575    
1576    /**
1577     * Will be called by the parser to return general informations about this
1578     * sampler.
1579     */
1580    String LSCPServer::GetServerInfo() {
1581        dmsg(2,("LSCPServer: GetServerInfo()\n"));
1582        LSCPResultSet result;
1583        result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");
1584        result.Add("VERSION", VERSION);
1585        result.Add("PROTOCOL_VERSION", "1.0");
1586        return result.Produce();
1587    }
1588    
1589    /**
1590     * Will be called by the parser to return the current number of all active voices.
1591     */
1592    String LSCPServer::GetTotalVoiceCount() {
1593        dmsg(2,("LSCPServer: GetTotalVoiceCount()\n"));
1594        LSCPResultSet result;
1595        result.Add(pSampler->GetVoiceCount());
1596        return result.Produce();
1597    }
1598    
1599    /**
1600     * Will be called by the parser to return the maximum number of voices.
1601     */
1602    String LSCPServer::GetTotalVoiceCountMax() {
1603        dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));
1604        LSCPResultSet result;
1605        result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES);
1606        return result.Produce();
1607    }
1608    
1609    /**
1610   * 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
1611   * server for receiving event messages.   * server for receiving event messages.
1612   */   */
# Line 1309  String LSCPServer::UnsubscribeNotificati Line 1632  String LSCPServer::UnsubscribeNotificati
1632      return result.Produce();      return result.Produce();
1633  }  }
1634    
1635    static int select_callback(void * lscpResultSet, int argc,
1636                            char **argv, char **azColName)
1637    {
1638        LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet;
1639        resultSet->Add(argc, argv);
1640        return 0;
1641    }
1642    
1643    String LSCPServer::QueryDatabase(String query) {
1644        LSCPResultSet result;
1645    #if HAVE_SQLITE3
1646        char* zErrMsg = NULL;
1647        sqlite3 *db;
1648        String selectStr = "SELECT " + query;
1649    
1650        int rc = sqlite3_open("linuxsampler.db", &db);
1651        if (rc == SQLITE_OK)
1652        {
1653                rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg);
1654        }
1655        if ( rc != SQLITE_OK )
1656        {
1657                result.Error(String(zErrMsg), rc);
1658        }
1659        sqlite3_close(db);
1660    #else
1661        result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0);
1662    #endif
1663        return result.Produce();
1664    }
1665    
1666  /**  /**
1667   * Will be called by the parser to enable or disable echo mode; if echo   * Will be called by the parser to enable or disable echo mode; if echo
1668   * mode is enabled, all commands from the client will (immediately) be   * mode is enabled, all commands from the client will (immediately) be
# Line 1320  String LSCPServer::SetEcho(yyparse_param Line 1674  String LSCPServer::SetEcho(yyparse_param
1674      try {      try {
1675          if      (boolean_value == 0) pSession->bVerbose = false;          if      (boolean_value == 0) pSession->bVerbose = false;
1676          else if (boolean_value == 1) pSession->bVerbose = true;          else if (boolean_value == 1) pSession->bVerbose = true;
1677          else throw LinuxSamplerException("Not a boolean value, must either be 0 or 1");          else throw Exception("Not a boolean value, must either be 0 or 1");
1678      }      }
1679      catch (LinuxSamplerException e) {      catch (Exception e) {
1680           result.Error(e);           result.Error(e);
1681      }      }
1682      return result.Produce();      return result.Produce();
1683  }  }
   
 // Instrument loader constructor.  
 LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument)  
     : Thread(false, 0, -4)  
 {  
     this->pEngine = pEngine;  
     this->Filename = Filename;  
     this->uiInstrument = uiInstrument;  
 }  
   
 // Instrument loader process.  
 int LSCPLoadInstrument::Main()  
 {  
     try {  
         pEngine->LoadInstrument(Filename.c_str(), uiInstrument);  
     }  
   
     catch (LinuxSamplerException e) {  
         e.PrintMessage();  
     }  
   
     // Always re-enable the engine.  
     pEngine->Enable();  
   
     // FIXME: Shoot ourselves on the foot?  
     delete this;  
 }  

Legend:
Removed from v.211  
changed lines
  Added in v.905

  ViewVC Help
Powered by ViewVC