/[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 113 by senkov, Sun Jun 6 20:59:49 2004 UTC revision 185 by senkov, Wed Jul 7 02:49:51 2004 UTC
# Line 22  Line 22 
22    
23  #include "lscpserver.h"  #include "lscpserver.h"
24  #include "lscpresultset.h"  #include "lscpresultset.h"
25    #include "lscpevent.h"
26    
27  #include "../engines/gig/Engine.h"  #include "../engines/gig/Engine.h"
28    #include "../audiodriver/AudioOutputDeviceFactory.h"
29    #include "../mididriver/MidiInputDeviceFactory.h"
30    
31    /**
32     * Below are a few static members of the LSCPServer class.
33     * The big assumption here is that LSCPServer is going to remain a singleton.
34     * These members are used to support client connections.
35     * Class handles multiple connections at the same time using select() and non-blocking recv()
36     * Commands are processed by a single LSCPServer thread.
37     * Notifications are delivered either by the thread that originated them
38     * or (if the resultset is currently in progress) by the LSCPServer thread
39     * after the resultset was sent out.
40     * This makes sure that resultsets can not be interrupted by notifications.
41     * This also makes sure that the thread sending notification is not blocked
42     * by the LSCPServer thread.
43     */
44    fd_set LSCPServer::fdSet;
45    int LSCPServer::currentSocket = -1;
46    std::vector<int> LSCPServer::hSessions = std::vector<int>();
47    std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>();
48    std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>();
49    std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions = std::map< LSCPEvent::event_t, std::list<int> >();
50    Mutex LSCPServer::NotifyMutex = Mutex();
51    Mutex LSCPServer::NotifyBufferMutex = Mutex();
52    Mutex LSCPServer::SubscriptionMutex = Mutex();
53    
54  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {
55      this->pSampler = pSampler;      this->pSampler = pSampler;
56        LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS");
57        LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");
58        LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");
59        LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");
60        LSCPEvent::RegisterEvent(LSCPEvent::event_info, "INFO");
61        LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
62  }  }
63    
64  int LSCPServer::Main() {  int LSCPServer::Main() {
65      hSocket = socket(AF_INET, SOCK_STREAM, 0);      int hSocket = socket(AF_INET, SOCK_STREAM, 0);
66      if (hSocket < 0) {      if (hSocket < 0) {
67          std::cerr << "LSCPServer: Could not create server socket." << std::endl;          std::cerr << "LSCPServer: Could not create server socket." << std::endl;
68          //return -1;          //return -1;
# Line 54  int LSCPServer::Main() { Line 86  int LSCPServer::Main() {
86      // now wait for client connections and handle their requests      // now wait for client connections and handle their requests
87      sockaddr_in client;      sockaddr_in client;
88      int length = sizeof(client);      int length = sizeof(client);
89        struct timeval tv;
90        tv.tv_sec = 30;
91        tv.tv_usec = 0;
92        FD_ZERO(&fdSet);
93        FD_SET(hSocket, &fdSet);
94        int maxSessions = hSocket;
95    
96        // Parser initialization
97        yyparse_param_t yyparse_param;
98        yyparse_param.pServer = this;
99    
100      while (true) {      while (true) {
101          hSession = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length);          fd_set selectSet = fdSet;
102          if (hSession < 0) {          int retval = select(maxSessions+1, &selectSet, NULL, NULL, &tv);
103              std::cerr << "LSCPServer: Client connection failed." << std::endl;          if (retval == 0)
104              close(hSocket);                  continue; //Nothing in 30 seconds, try again
105              //return -1;          if (retval == -1) {
106              exit(EXIT_FAILURE);                  std::cerr << "LSCPServer: Socket select error." << std::endl;
107          }                  close(hSocket);
108                    exit(EXIT_FAILURE);
109          dmsg(1,("LSCPServer: Client connection established.\n"));          }
110          //send(hSession, "Welcome!\r\n", 10, 0);          
111            //Accept new connections now (if any)
112          // Parser invocation          if (FD_ISSET(hSocket, &selectSet)) {
113          yyparse_param_t yyparse_param;                  int socket = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length);
114          yyparse_param.pServer = this;                  if (socket < 0) {
115          yylex_init(&yyparse_param.pScanner);                          std::cerr << "LSCPServer: Client connection failed." << std::endl;
116          while (yyparse(&yyparse_param) == LSCP_SYNTAX_ERROR); // recall parser in case of syntax error                          exit(EXIT_FAILURE);
117          yylex_destroy(yyparse_param.pScanner);                  }
118    
119                    if (fcntl(socket, F_SETFL, O_NONBLOCK)) {
120                            std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl;
121                            exit(EXIT_FAILURE);
122                    }
123    
124                    hSessions.push_back(socket);
125                    FD_SET(socket, &fdSet);
126                    if (socket > maxSessions)
127                            maxSessions = socket;
128                    dmsg(1,("LSCPServer: Client connection established on socket:%d.\n", socket));
129                    LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection established on socket", socket));
130                    continue; //Maybe this was the only selected socket, better select again
131            }
132    
133            //Something was selected and it was not the hSocket, so it must be some command(s) coming.
134            for (std::vector<int>::iterator iter = hSessions.begin(); iter !=  hSessions.end(); iter++) {
135                    if (FD_ISSET(*iter, &selectSet)) {      //Was it this socket?
136                            if (GetLSCPCommand(iter)) {     //Have we read the entire command?
137                                    dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket));
138                                    yylex_init(&yyparse_param.pScanner);
139                                    currentSocket = *iter;  //a hack
140                                    int result = yyparse(&yyparse_param);
141                                    currentSocket = -1;     //continuation of a hack
142                                    dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket));
143                                    if (result == LSCP_QUIT) { //Was it a quit command by any chance?
144                                            CloseConnection(iter);
145                                    }
146                            }
147                            //socket may have been closed, iter may be invalid, get out of the loop for now.
148                            //we'll be back if there is data.
149                            break;
150                    }
151            }
152    
153          close(hSession);          //Now let's deliver late notifies (if any)
154          dmsg(1,("LSCPServer: Client connection terminated.\n"));          NotifyBufferMutex.Lock();
155            for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {
156                    send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0);
157                    bufferedNotifies.erase(iterNotify);
158            }
159            NotifyBufferMutex.Unlock();
160      }      }
161        //It will never get here anyway
162        //yylex_destroy(yyparse_param.pScanner);
163    }
164    
165    void LSCPServer::CloseConnection( std::vector<int>::iterator iter ) {
166            int socket = *iter;
167            dmsg(1,("LSCPServer: Client connection terminated on socket:%d.\n",socket));
168            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket));
169            hSessions.erase(iter);
170            FD_CLR(socket,  &fdSet);
171            SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any)
172            for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) {
173                    iter->second.remove(socket);
174            }
175            SubscriptionMutex.Unlock();
176            NotifyMutex.Lock();
177            bufferedCommands.erase(socket);
178            bufferedNotifies.erase(socket);
179            close(socket);
180            NotifyMutex.Unlock();
181    }
182    
183    void LSCPServer::SendLSCPNotify( LSCPEvent event ) {
184            SubscriptionMutex.Lock();
185            if (eventSubscriptions.count(event.GetType()) == 0) {
186                    SubscriptionMutex.Unlock();     //Nobody is subscribed to this event
187                    return;
188            }
189            std::list<int>::iterator iter = eventSubscriptions[event.GetType()].begin();
190            std::list<int>::iterator end = eventSubscriptions[event.GetType()].end();
191            String notify = event.Produce();
192    
193            while (true) {
194                    if (NotifyMutex.Trylock()) {
195                            for(;iter != end; iter++)
196                                    send(*iter, notify.c_str(), notify.size(), 0);
197                            NotifyMutex.Unlock();
198                            break;
199                    } else {
200                            if (NotifyBufferMutex.Trylock()) {
201                                    for(;iter != end; iter++)
202                                            bufferedNotifies[*iter] += notify;
203                                    NotifyBufferMutex.Unlock();
204                                    break;
205                            }
206                    }
207            }
208            SubscriptionMutex.Unlock();
209    }
210    
211    extern int GetLSCPCommand( void *buf, int max_size ) {
212            String command = LSCPServer::bufferedCommands[LSCPServer::currentSocket];
213            if (command.size() == 0) {              //Parser wants input but we have nothing.
214                    strcpy((char*) buf, "\n");      //So give it an empty command
215                    return 1;                       //to keep it happy.
216            }
217    
218            if (max_size < command.size()) {
219                    std::cerr << "getLSCPCommand: Flex buffer too small, ignoring the command." << std::endl;
220                    return 0;       //This will never happen
221            }
222    
223            strcpy((char*) buf, command.c_str());
224            LSCPServer::bufferedCommands.erase(LSCPServer::currentSocket);
225            return command.size();
226    }
227    
228    /**
229     * Will be called to try to read the command from the socket
230     * If command is read, it will return true. Otherwise false is returned.
231     * In any case the received portion (complete or incomplete) is saved into bufferedCommand map.
232     */
233    bool LSCPServer::GetLSCPCommand( std::vector<int>::iterator iter ) {
234            int socket = *iter;
235            char c;
236            int i = 0;
237            while (true) {
238                    int result = recv(socket, (void *)&c, 1, 0); //Read one character at a time for now
239                    if (result == 0) { //socket was selected, so 0 here means client has closed the connection
240                            CloseConnection(iter);
241                            break;
242                    }
243                    if (result == 1) {
244                            if (c == '\r')
245                                    continue; //Ignore CR
246                            if (c == '\n') {
247                                    LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));
248                                    bufferedCommands[socket] += "\n";
249                                    return true; //Complete command was read
250                            }
251                            bufferedCommands[socket] += c;
252                    }
253                    if (result == -1) {
254                            if (errno == EAGAIN) //Would block, try again later.
255                                    return false;
256                            switch(errno) {
257                                    case EBADF:
258                                            dmsg(2,("LSCPScanner: The argument s is an invalid descriptor.\n"));
259                                            break;
260                                    case ECONNREFUSED:
261                                            dmsg(2,("LSCPScanner: A remote host refused to allow the network connection (typically because it is not running the requested service).\n"));
262                                            break;
263                                    case ENOTCONN:
264                                            dmsg(2,("LSCPScanner: The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2)).\n"));
265                                            break;
266                                    case ENOTSOCK:
267                                            dmsg(2,("LSCPScanner: The argument s does not refer to a socket.\n"));
268                                            break;
269                                    case EAGAIN:
270                                            dmsg(2,("LSCPScanner: The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.\n"));
271                                            break;
272                                    case EINTR:
273                                            dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n"));
274                                            break;
275                                    case EFAULT:
276                                            dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n"));
277                                            break;
278                                    case EINVAL:
279                                            dmsg(2,("LSCPScanner: Invalid argument passed.\n"));
280                                            break;
281                                    case ENOMEM:
282                                            dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n"));
283                                            break;
284                                    default:
285                                            dmsg(2,("LSCPScanner: Unknown recv() error.\n"));
286                                            break;
287                            }
288                            CloseConnection(iter);
289                            break;
290                    }
291            }
292            return false;
293  }  }
294    
295  /**  /**
# Line 86  int LSCPServer::Main() { Line 300  int LSCPServer::Main() {
300   */   */
301  void LSCPServer::AnswerClient(String ReturnMessage) {  void LSCPServer::AnswerClient(String ReturnMessage) {
302      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));      dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str()));
303      send(hSession, ReturnMessage.c_str(), ReturnMessage.size(), 0);      if (currentSocket != -1) {
304                NotifyMutex.Lock();
305                send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0);
306                NotifyMutex.Unlock();
307        }
308    }
309    
310    /**
311     * Find a created audio output device index.
312     */
313    int LSCPServer::GetAudioOutputDeviceIndex ( AudioOutputDevice *pDevice )
314    {
315        // Search for the created device to get its index
316        std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
317        std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();
318        for (; iter != devices.end(); iter++) {
319            if (iter->second == pDevice)
320                return iter->first;
321        }
322        // Not found.
323        return -1;
324    }
325    
326    /**
327     * Find a created midi input device index.
328     */
329    int LSCPServer::GetMidiInputDeviceIndex ( MidiInputDevice *pDevice )
330    {
331        // Search for the created device to get its index
332        std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
333        std::map<uint, MidiInputDevice*>::iterator iter = devices.begin();
334        for (; iter != devices.end(); iter++) {
335            if (iter->second == pDevice)
336                return iter->first;
337        }
338        // Not found.
339        return -1;
340    }
341    
342    String LSCPServer::CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters) {
343        dmsg(2,("LSCPServer: CreateAudioOutputDevice(Driver=%s)\n", Driver.c_str()));
344        LSCPResultSet result;
345        try {
346            AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters);
347            // search for the created device to get its index
348            int index = GetAudioOutputDeviceIndex(pDevice);
349            if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device.");
350            result = index; // success
351        }
352        catch (LinuxSamplerException e) {
353            result.Error(e);
354        }
355        return result.Produce();
356    }
357    
358    String LSCPServer::CreateMidiInputDevice(String Driver, std::map<String,String> Parameters) {
359        dmsg(2,("LSCPServer: CreateMidiInputDevice(Driver=%s)\n", Driver.c_str()));
360        LSCPResultSet result;
361        try {
362            MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters);
363            // search for the created device to get its index
364            int index = GetMidiInputDeviceIndex(pDevice);
365            if (index == -1) throw LinuxSamplerException("Internal error: could not find created midi input device.");
366            result = index; // success
367        }
368        catch (LinuxSamplerException e) {
369            result.Error(e);
370        }
371        return result.Produce();
372    }
373    
374    String LSCPServer::DestroyAudioOutputDevice(uint DeviceIndex) {
375        dmsg(2,("LSCPServer: DestroyAudioOutputDevice(DeviceIndex=%d)\n", DeviceIndex));
376        LSCPResultSet result;
377        try {
378            std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
379            if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
380            AudioOutputDevice* pDevice = devices[DeviceIndex];
381            pSampler->DestroyAudioOutputDevice(pDevice);
382        }
383        catch (LinuxSamplerException e) {
384            result.Error(e);
385        }
386        return result.Produce();
387    }
388    
389    String LSCPServer::DestroyMidiInputDevice(uint DeviceIndex) {
390        dmsg(2,("LSCPServer: DestroyMidiInputDevice(DeviceIndex=%d)\n", DeviceIndex));
391        LSCPResultSet result;
392        try {
393            std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
394            MidiInputDevice* pDevice = devices[DeviceIndex];
395            if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
396            pSampler->DestroyMidiInputDevice(pDevice);
397        }
398        catch (LinuxSamplerException e) {
399            result.Error(e);
400        }
401        return result.Produce();
402  }  }
403    
404  /**  /**
405   * Will be called by the parser to load an instrument.   * Will be called by the parser to load an instrument.
406   */   */
407  String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel) {  String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground) {
408      dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), uiInstrument, uiSamplerChannel));      dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), uiInstrument, uiSamplerChannel));
409      result_t result;      LSCPResultSet result;
410      try {      try {
411          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
412          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
413          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
414          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
415          pEngine->LoadInstrument(Filename.c_str(), uiInstrument);          if (pSamplerChannel->GetAudioOutputDevice() == NULL)
416          result.type = result_type_success;              throw LinuxSamplerException("No audio output device on channel");
417            if (bBackground) {
418                LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);
419                pLoadInstrument->StartThread();
420            }
421            else pEngine->LoadInstrument(Filename.c_str(), uiInstrument);
422      }      }
423      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
424           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
425      }      }
426      return ConvertResult(result);      return result.Produce();
427  }  }
428    
429  /**  /**
# Line 117  String LSCPServer::LoadInstrument(String Line 431  String LSCPServer::LoadInstrument(String
431   */   */
432  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {
433      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));
434      result_t result;      LSCPResultSet result;
435      try {      try {
436          Engine::type_t type;          Engine::type_t type;
437          if (EngineName == "gig") type = Engine::type_gig;          if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig;
438          else throw LinuxSamplerException("Unknown engine type");          else throw LinuxSamplerException("Unknown engine type");
439          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
440          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
441          pSamplerChannel->LoadEngine(type);          pSamplerChannel->LoadEngine(type);
         result.type = result_type_success;  
442      }      }
443      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
444           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
445      }      }
446      return ConvertResult(result);      return result.Produce();
447  }  }
448    
449  /**  /**
# Line 141  String LSCPServer::LoadEngine(String Eng Line 451  String LSCPServer::LoadEngine(String Eng
451   */   */
452  String LSCPServer::GetChannels() {  String LSCPServer::GetChannels() {
453      dmsg(2,("LSCPServer: GetChannels()\n"));      dmsg(2,("LSCPServer: GetChannels()\n"));
454      return ToString(pSampler->SamplerChannels()) + "\r\n";      LSCPResultSet result;
455        result.Add(pSampler->SamplerChannels());
456        return result.Produce();
457  }  }
458    
459  /**  /**
# Line 150  String LSCPServer::GetChannels() { Line 462  String LSCPServer::GetChannels() {
462  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
463      dmsg(2,("LSCPServer: AddChannel()\n"));      dmsg(2,("LSCPServer: AddChannel()\n"));
464      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();      SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel();
465      return "OK[" + ToString(pSamplerChannel->Index()) + "]\r\n";      LSCPResultSet result(pSamplerChannel->Index());
466        return result.Produce();
467  }  }
468    
469  /**  /**
# Line 158  String LSCPServer::AddChannel() { Line 471  String LSCPServer::AddChannel() {
471   */   */
472  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {  String LSCPServer::RemoveChannel(uint uiSamplerChannel) {
473      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel));
474        LSCPResultSet result;
475      pSampler->RemoveSamplerChannel(uiSamplerChannel);      pSampler->RemoveSamplerChannel(uiSamplerChannel);
476      return "OK\r\n";      return result.Produce();
477  }  }
478    
479  /**  /**
# Line 167  String LSCPServer::RemoveChannel(uint ui Line 481  String LSCPServer::RemoveChannel(uint ui
481   */   */
482  String LSCPServer::GetAvailableEngines() {  String LSCPServer::GetAvailableEngines() {
483      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));      dmsg(2,("LSCPServer: GetAvailableEngines()\n"));
484      return "gig\r\n";      LSCPResultSet result("GigEngine");
485        return result.Produce();
486  }  }
487    
488  /**  /**
# Line 175  String LSCPServer::GetAvailableEngines() Line 490  String LSCPServer::GetAvailableEngines()
490   */   */
491  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
492      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
493      result_t result;      LSCPResultSet result;
494      try {      try {
495          if (EngineName == "gig") {          if ((EngineName == "GigEngine") || (EngineName == "gig")) {
496              Engine* pEngine = new LinuxSampler::gig::Engine;              Engine* pEngine = new LinuxSampler::gig::Engine;
497              String info = pEngine->Description() + "\r\n";              result.Add(pEngine->Description());
498                result.Add(pEngine->Version());
499              delete pEngine;              delete pEngine;
             return info; // success  
500          }          }
501          else throw LinuxSamplerException("Unknown engine type");          else throw LinuxSamplerException("Unknown engine type");
502      }      }
503      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
504           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
505      }      }
506      return ConvertResult(result);      return result.Produce();
507  }  }
508    
509  /**  /**
# Line 200  String LSCPServer::GetEngineInfo(String Line 512  String LSCPServer::GetEngineInfo(String
512   */   */
513  String LSCPServer::GetChannelInfo(uint uiSamplerChannel) {  String LSCPServer::GetChannelInfo(uint uiSamplerChannel) {
514      dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", uiSamplerChannel));
515        LSCPResultSet result;
516      try {      try {
         LSCPResultSet result;  
517          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
518          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
519          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
520    
521            //Defaults values
522            String EngineName = "NONE";
523            float Volume = 0;
524            String InstrumentFileName = "NONE";
525            int InstrumentIndex = -1;
526            int InstrumentStatus = -1;
527    
528          if (pEngine) {          if (pEngine) {
529              result.Add("ENGINE_NAME", pEngine->EngineName());              EngineName =  pEngine->EngineName();
530              result.Add("VOLUME", pEngine->Volume());              Volume = pEngine->Volume();
531                InstrumentStatus = pEngine->InstrumentStatus();
532                InstrumentIndex = pEngine->InstrumentIndex();
533                if (InstrumentIndex != -1)
534                    InstrumentFileName = pEngine->InstrumentFileName();
535          }          }
536          //Some hardcoded stuff for now to make GUI look good  
537          result.Add("AUDIO_OUTPUT_DEVICE", "0");          result.Add("ENGINE_NAME", EngineName);
538            result.Add("VOLUME", Volume);
539    
540            //Some not-so-hardcoded stuff to make GUI look good
541            result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice()));
542          result.Add("AUDIO_OUTPUT_CHANNELS", "2");          result.Add("AUDIO_OUTPUT_CHANNELS", "2");
543          result.Add("AUDIO_OUTPUT_ROUTING", "0,1");          result.Add("AUDIO_OUTPUT_ROUTING", "0,1");
544    
545          if (pEngine) {          result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice()));
546              int iIdx = pEngine->InstrumentIndex();          result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort());
547              if (iIdx != -1) {          result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel());
548                  result.Add("INSTRUMENT_FILE", pEngine->InstrumentFileName());  
549                  result.Add("INSTRUMENT_NR", iIdx);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
550              }          result.Add("INSTRUMENT_NR", InstrumentIndex);
551          }          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
         //Some hardcoded stuff for now to make GUI look good  
         result.Add("MIDI_INPUT_DEVICE", "0");  
         result.Add("MIDI_INPUT_PORT", "0");  
         result.Add("MIDI_INPUT_CHANNEL", "1");  
   
         return result.Produce();  
552      }      }
553      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
554           result_t result;           result.Error(e);
          e.PrintMessage();  
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
          return ConvertResult(result);  
555      }      }
556        return result.Produce();
557  }  }
558    
559  /**  /**
# Line 244  String LSCPServer::GetChannelInfo(uint u Line 562  String LSCPServer::GetChannelInfo(uint u
562   */   */
563  String LSCPServer::GetVoiceCount(uint uiSamplerChannel) {  String LSCPServer::GetVoiceCount(uint uiSamplerChannel) {
564      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel));
565      result_t result;      LSCPResultSet result;
566      try {      try {
567          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
568          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
569          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
570          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
571          return ToString(pEngine->VoiceCount()) + "\r\n"; // success          result.Add(pEngine->VoiceCount());
572      }      }
573      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
574           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
575      }      }
576      return ConvertResult(result);      return result.Produce();
577  }  }
578    
579  /**  /**
# Line 267  String LSCPServer::GetVoiceCount(uint ui Line 582  String LSCPServer::GetVoiceCount(uint ui
582   */   */
583  String LSCPServer::GetStreamCount(uint uiSamplerChannel) {  String LSCPServer::GetStreamCount(uint uiSamplerChannel) {
584      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel));
585      result_t result;      LSCPResultSet result;
586      try {      try {
587          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
588          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
589          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
590          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
591          return ToString(pEngine->DiskStreamCount()) + "\r\n"; // success          result.Add(pEngine->DiskStreamCount());
592      }      }
593      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
594           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
595      }      }
596      return ConvertResult(result);      return result.Produce();
597  }  }
598    
599  /**  /**
# Line 290  String LSCPServer::GetStreamCount(uint u Line 602  String LSCPServer::GetStreamCount(uint u
602   */   */
603  String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel) {  String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel) {
604      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel));      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel));
605      result_t result;      LSCPResultSet result;
606      try {      try {
607          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
608          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
609          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
610          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
611          if (!pEngine->DiskStreamSupported()) return "NA\r\n";          if (!pEngine->DiskStreamSupported())
612          switch (ResponseType) {              result.Add("NA");
613              case fill_response_bytes:          else {
614                  return ToString(pEngine->DiskStreamBufferFillBytes()) + "\r\n"; // success              switch (ResponseType) {
615              case fill_response_percentage:                  case fill_response_bytes:
616                  return ToString(pEngine->DiskStreamBufferFillPercentage()) + "\r\n"; // success                      result.Add(pEngine->DiskStreamBufferFillBytes());
617              default:                      break;
618                  throw LinuxSamplerException("Unknown fill response type");                  case fill_response_percentage:
619                        result.Add(pEngine->DiskStreamBufferFillPercentage());
620                        break;
621                    default:
622                        throw LinuxSamplerException("Unknown fill response type");
623                }
624            }
625        }
626        catch (LinuxSamplerException e) {
627             result.Error(e);
628        }
629        return result.Produce();
630    }
631    
632    String LSCPServer::GetAvailableAudioOutputDrivers() {
633        dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n"));
634        LSCPResultSet result;
635        try {
636            String s = AudioOutputDeviceFactory::AvailableDriversAsString();
637            result.Add(s);
638        }
639        catch (LinuxSamplerException e) {
640            result.Error(e);
641        }
642        return result.Produce();
643    }
644    
645    String LSCPServer::GetAvailableMidiInputDrivers() {
646        dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n"));
647        LSCPResultSet result;
648        try {
649            String s = MidiInputDeviceFactory::AvailableDriversAsString();
650            result.Add(s);
651        }
652        catch (LinuxSamplerException e) {
653            result.Error(e);
654        }
655        return result.Produce();
656    }
657    
658    String LSCPServer::GetMidiInputDriverInfo(String Driver) {
659        dmsg(2,("LSCPServer: GetMidiInputDriverInfo(Driver=%s)\n",Driver.c_str()));
660        LSCPResultSet result;
661        try {
662            result.Add("DESCRIPTION", MidiInputDeviceFactory::GetDriverDescription(Driver));
663            result.Add("VERSION",     MidiInputDeviceFactory::GetDriverVersion(Driver));
664    
665            std::map<String,DeviceCreationParameter*> parameters = MidiInputDeviceFactory::GetAvailableDriverParameters(Driver);
666            if (parameters.size()) { // if there are parameters defined for this driver
667                String s;
668                std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
669                for (;iter != parameters.end(); iter++) {
670                    if (s != "") s += ",";
671                    s += iter->first;
672                }
673                result.Add("PARAMETERS", s);
674          }          }
675      }      }
676      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
677           e.PrintMessage();          result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
678      }      }
679      return ConvertResult(result);      return result.Produce();
680  }  }
681    
682  /**  String LSCPServer::GetAudioOutputDriverInfo(String Driver) {
683   * Will be called by the parser to change the audio output type on a      dmsg(2,("LSCPServer: GetAudioOutputDriverInfo(Driver=%s)\n",Driver.c_str()));
684   * particular sampler channel.      LSCPResultSet result;
  */  
 String LSCPServer::SetAudioOutputType(AudioOutputDevice::type_t AudioOutputType, uint uiSamplerChannel) {  
     dmsg(2,("LSCPServer: SetAudioOutputType(AudioOutputType=%d, SamplerChannel=%d)\n", AudioOutputType, uiSamplerChannel));  
     result_t result;  
685      try {      try {
686          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          result.Add("DESCRIPTION", AudioOutputDeviceFactory::GetDriverDescription(Driver));
687          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          result.Add("VERSION",     AudioOutputDeviceFactory::GetDriverVersion(Driver));
688          pSamplerChannel->SetAudioOutputDevice(AudioOutputType);  
689          result.type = result_type_success;          std::map<String,DeviceCreationParameter*> parameters = AudioOutputDeviceFactory::GetAvailableDriverParameters(Driver);
690            if (parameters.size()) { // if there are parameters defined for this driver
691                String s;
692                std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
693                for (;iter != parameters.end(); iter++) {
694                    if (s != "") s += ",";
695                    s += iter->first;
696                }
697                result.Add("PARAMETERS", s);
698            }
699        }
700        catch (LinuxSamplerException e) {
701            result.Error(e);
702        }
703        return result.Produce();
704    }
705    
706    String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
707        dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str()));
708        LSCPResultSet result;
709        try {
710            DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter);
711            result.Add("TYPE",         pParameter->Type());
712            result.Add("DESCRIPTION",  pParameter->Description());
713            result.Add("MANDATORY",    pParameter->Mandatory());
714            result.Add("FIX",          pParameter->Fix());
715            result.Add("MULTIPLICITY", pParameter->Multiplicity());
716            if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());
717            if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());
718            if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());
719            if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());
720            if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());
721        }
722        catch (LinuxSamplerException e) {
723            result.Error(e);
724        }
725        return result.Produce();
726    }
727    
728    String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) {
729        dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str()));
730        LSCPResultSet result;
731        try {
732            DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter);
733            result.Add("TYPE",         pParameter->Type());
734            result.Add("DESCRIPTION",  pParameter->Description());
735            result.Add("MANDATORY",    pParameter->Mandatory());
736            result.Add("FIX",          pParameter->Fix());
737            result.Add("MULTIPLICITY", pParameter->Multiplicity());
738            if (pParameter->Depends())       result.Add("DEPENDS",       pParameter->Depends());
739            if (pParameter->Default())       result.Add("DEFAULT",       pParameter->Default());
740            if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());
741            if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());
742            if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());
743        }
744        catch (LinuxSamplerException e) {
745            result.Error(e);
746        }
747        return result.Produce();
748    }
749    
750    String LSCPServer::GetAudioOutputDeviceCount() {
751        dmsg(2,("LSCPServer: GetAudioOutputDeviceCount()\n"));
752        LSCPResultSet result;
753        try {
754            uint count = pSampler->AudioOutputDevices();
755            result.Add(count); // success
756        }
757        catch (LinuxSamplerException e) {
758            result.Error(e);
759        }
760        return result.Produce();
761    }
762    
763    String LSCPServer::GetMidiInputDeviceCount() {
764        dmsg(2,("LSCPServer: GetMidiInputDeviceCount()\n"));
765        LSCPResultSet result;
766        try {
767            uint count = pSampler->MidiInputDevices();
768            result.Add(count); // success
769        }
770        catch (LinuxSamplerException e) {
771            result.Error(e);
772        }
773        return result.Produce();
774    }
775    
776    String LSCPServer::GetAudioOutputDevices() {
777        dmsg(2,("LSCPServer: GetAudioOutputDevices()\n"));
778        LSCPResultSet result;
779        try {
780            String s;
781            std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
782            std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();
783            for (; iter != devices.end(); iter++) {
784                if (s != "") s += ",";
785                s += ToString(iter->first);
786            }
787            result.Add(s);
788        }
789        catch (LinuxSamplerException e) {
790            result.Error(e);
791        }
792        return result.Produce();
793    }
794    
795    String LSCPServer::GetMidiInputDevices() {
796        dmsg(2,("LSCPServer: GetMidiInputDevices()\n"));
797        LSCPResultSet result;
798        try {
799            String s;
800            std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
801            std::map<uint, MidiInputDevice*>::iterator iter = devices.begin();
802            for (; iter != devices.end(); iter++) {
803                if (s != "") s += ",";
804                s += ToString(iter->first);
805            }
806            result.Add(s);
807        }
808        catch (LinuxSamplerException e) {
809            result.Error(e);
810        }
811        return result.Produce();
812    }
813    
814    String LSCPServer::GetAudioOutputDeviceInfo(uint DeviceIndex) {
815        dmsg(2,("LSCPServer: GetAudioOutputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex));
816        LSCPResultSet result;
817        try {
818            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
819            if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
820            AudioOutputDevice* pDevice = devices[DeviceIndex];
821            result.Add("driver", pDevice->Driver());
822            std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
823            std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
824            for (; iter != parameters.end(); iter++) {
825                result.Add(iter->first, iter->second->Value());
826            }
827        }
828        catch (LinuxSamplerException e) {
829            result.Error(e);
830        }
831        return result.Produce();
832    }
833    
834    String LSCPServer::GetMidiInputDeviceInfo(uint DeviceIndex) {
835        dmsg(2,("LSCPServer: GetMidiInputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex));
836        LSCPResultSet result;
837        try {
838            std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
839            MidiInputDevice* pDevice = devices[DeviceIndex];
840            if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
841            result.Add("driver", pDevice->Driver());
842            std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
843            std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
844            for (; iter != parameters.end(); iter++) {
845                result.Add(iter->first, iter->second->Value());
846            }
847        }
848        catch (LinuxSamplerException e) {
849            result.Error(e);
850        }
851        return result.Produce();
852    }
853    String LSCPServer::GetMidiInputPortInfo(uint DeviceIndex, uint PortIndex) {
854        dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex));
855        LSCPResultSet result;
856        try {
857            std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
858            MidiInputDevice* pDevice = devices[DeviceIndex];
859            if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
860            MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
861            if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
862            std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();
863            std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin();
864            for (; iter != parameters.end(); iter++) {
865                result.Add(iter->first, iter->second->Value());
866            }
867        }
868        catch (LinuxSamplerException e) {
869            result.Error(e);
870        }
871        return result.Produce();
872    }
873    
874    String LSCPServer::GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId) {
875        dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%d,ChannelId)\n",DeviceId,ChannelId));
876        LSCPResultSet result;
877        try {
878            // get audio output device
879            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
880            if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
881            AudioOutputDevice* pDevice = devices[DeviceId];
882    
883            // get audio channel
884            AudioChannel* pChannel = pDevice->Channel(ChannelId);
885            if (!pChannel) throw LinuxSamplerException("Audio ouotput device does not have channel " + ToString(ChannelId) + ".");
886    
887            // return the values of all audio channel parameters
888            std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
889            std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin();
890            for (; iter != parameters.end(); iter++) {
891                result.Add(iter->first, iter->second->Value());
892            }
893        }
894        catch (LinuxSamplerException e) {
895            result.Error(e);
896        }
897        return result.Produce();
898    }
899    
900    String LSCPServer::GetMidiInputPortParameterInfo(uint DeviceId, uint PortId, String ParameterName) {
901        dmsg(2,("LSCPServer: GetMidiInputPortParameterInfo(DeviceId=%d,PortId=%d,ParameterName=%s)\n",DeviceId,PortId,ParameterName.c_str()));
902        LSCPResultSet result;
903        try {
904            // get audio output device
905            std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
906            if (!devices[DeviceId]) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + ".");
907            MidiInputDevice* pDevice = devices[DeviceId];
908    
909            // get midi port
910            MidiInputDevice::MidiInputPort* pPort = pDevice->GetPort(PortId);
911            if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + ".");
912    
913            // get desired port parameter
914            std::map<String,DeviceCreationParameter*> parameters = pPort->DeviceParameters();
915            if (!parameters[ParameterName]) throw LinuxSamplerException("Midi port does not provice a parameters '" + ParameterName + "'.");
916            DeviceCreationParameter* pParameter = parameters[ParameterName];
917            
918            // return all fields of this audio channel parameter
919            result.Add("TYPE",         pParameter->Type());
920            result.Add("DESCRIPTION",  pParameter->Description());
921            result.Add("FIX",          pParameter->Fix());
922            result.Add("MULTIPLICITY", pParameter->Multiplicity());
923            if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());
924            if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());
925            if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());
926        }
927        catch (LinuxSamplerException e) {
928            result.Error(e);
929        }
930        return result.Produce();
931    }
932    
933    String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) {
934        dmsg(2,("LSCPServer: GetAudioOutputChannelParameterInfo(DeviceId=%d,ChannelId=%d,ParameterName=%s)\n",DeviceId,ChannelId,ParameterName.c_str()));
935        LSCPResultSet result;
936        try {
937            // get audio output device
938            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
939            if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
940            AudioOutputDevice* pDevice = devices[DeviceId];
941    
942            // get audio channel
943            AudioChannel* pChannel = pDevice->Channel(ChannelId);
944            if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");
945    
946            // get desired audio channel parameter
947            std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
948            if (!parameters[ParameterName]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'.");
949            DeviceRuntimeParameter* pParameter = parameters[ParameterName];
950    
951            // return all fields of this audio channel parameter
952            result.Add("TYPE",         pParameter->Type());
953            result.Add("DESCRIPTION",  pParameter->Description());
954            result.Add("FIX",          pParameter->Fix());
955            result.Add("MULTIPLICITY", pParameter->Multiplicity());
956            if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());
957            if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());
958            if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());
959      }      }
960      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
961           e.PrintMessage();          result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
962      }      }
963      return ConvertResult(result);      return result.Produce();
964    }
965    
966    String LSCPServer::SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal) {
967        dmsg(2,("LSCPServer: SetAudioOutputChannelParameter(DeviceId=%d,ChannelId=%d,ParamKey=%s,ParamVal=%s)\n",DeviceId,ChannelId,ParamKey.c_str(),ParamVal.c_str()));
968        LSCPResultSet result;
969        try {
970            // get audio output device
971            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
972            if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + ".");
973            AudioOutputDevice* pDevice = devices[DeviceId];
974    
975            // get audio channel
976            AudioChannel* pChannel = pDevice->Channel(ChannelId);
977            if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");
978    
979            // get desired audio channel parameter
980            std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
981            if (!parameters[ParamKey]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'.");
982            DeviceRuntimeParameter* pParameter = parameters[ParamKey];
983    
984            // set new channel parameter value
985            pParameter->SetValue(ParamVal);
986        }
987        catch (LinuxSamplerException e) {
988            result.Error(e);
989        }
990        return result.Produce();
991    }
992    
993    String LSCPServer::SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal) {
994        dmsg(2,("LSCPServer: SetAudioOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str()));
995        LSCPResultSet result;
996        try {
997            std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
998            if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + ".");
999            AudioOutputDevice* pDevice = devices[DeviceIndex];
1000            std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1001            if (!parameters[ParamKey]) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
1002            parameters[ParamKey]->SetValue(ParamVal);
1003        }
1004        catch (LinuxSamplerException e) {
1005            result.Error(e);
1006        }
1007        return result.Produce();
1008    }
1009    
1010    String LSCPServer::SetMidiInputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal) {
1011        dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str()));
1012        LSCPResultSet result;
1013        try {
1014            std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1015            if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1016            MidiInputDevice* pDevice = devices[DeviceIndex];
1017            std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1018            if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'");
1019            parameters[ParamKey]->SetValue(ParamVal);
1020        }
1021        catch (LinuxSamplerException e) {
1022            result.Error(e);
1023        }
1024        return result.Produce();
1025    }
1026    
1027    String LSCPServer::SetMidiInputPortParameter(uint DeviceIndex, uint PortIndex, String ParamKey, String ParamVal) {
1028        dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str()));
1029        LSCPResultSet result;
1030        try {
1031            std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1032            MidiInputDevice* pDevice = devices[DeviceIndex];
1033            if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + ".");
1034            MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex);
1035            if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + ".");
1036            std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters();
1037            if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'");
1038            parameters[ParamKey]->SetValue(ParamVal);
1039        }
1040        catch (LinuxSamplerException e) {
1041            result.Error(e);
1042        }
1043        return result.Produce();
1044  }  }
1045    
1046  /**  /**
1047   * Will be called by the parser to change the audio output channel for   * Will be called by the parser to change the audio output channel for
1048   * playback on a particular sampler channel.   * playback on a particular sampler channel.
1049   */   */
1050  String LSCPServer::SetAudioOutputChannel(uint AudioOutputChannel, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) {
1051      dmsg(2,("LSCPServer: SetAudioOutputChannel(AudioOutputChannel=%d, SamplerChannel=%d)\n", AudioOutputChannel, uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel));
1052      return "ERR:0:Not implemented yet.\r\n";      return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class?
1053  }  }
1054    
1055  String LSCPServer::SetMIDIInputType(MidiInputDevice::type_t MidiInputType, uint uiSamplerChannel) {  String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) {
1056      dmsg(2,("LSCPServer: SetMIDIInputType(MidiInputType=%d, SamplerChannel=%d)\n", MidiInputType, uiSamplerChannel));      dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel));
1057      result_t result;      LSCPResultSet result;
1058      try {      try {
1059          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1060          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
1061          pSamplerChannel->SetMidiInputDevice(MidiInputType);          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1062          result.type = result_type_success;          AudioOutputDevice* pDevice = devices[AudioDeviceId];
1063            if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));
1064            pSamplerChannel->SetAudioOutputDevice(pDevice);
1065      }      }
1066      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1067           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
1068      }      }
1069      return ConvertResult(result);      return result.Produce();
1070  }  }
1071    
1072  /**  String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) {
1073   * Will be called by the parser to change the MIDI input port on which the      dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel));
1074   * engine of a particular sampler channel should listen to.      LSCPResultSet result;
  */  
 String LSCPServer::SetMIDIInputPort(String MIDIInputPort, uint uiSamplerChannel) {  
     dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIInputPort=%s, Samplerchannel=%d)\n", MIDIInputPort.c_str(), uiSamplerChannel));  
     result_t result;  
1075      try {      try {
1076          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1077          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
1078          if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet");          // Driver type name aliasing...
1079          pSamplerChannel->GetMidiInputDevice()->SetInputPort(MIDIInputPort.c_str());          if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa";
1080          result.type = result_type_success;          if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack";        
1081            // Check if there's one audio output device already created
1082            // for the intended audio driver type (AudioOutputDriver)...
1083            AudioOutputDevice *pDevice = NULL;
1084            std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1085            std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin();
1086            for (; iter != devices.end(); iter++) {
1087                if ((iter->second)->Driver() == AudioOutputDriver) {
1088                    pDevice = iter->second;
1089                    break;
1090                }
1091            }
1092            // If it doesn't exist, create a new one with default parameters...
1093            if (pDevice == NULL) {
1094                std::map<String,String> params;
1095                pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params);
1096            }
1097            // Must have a device...
1098            if (pDevice == NULL)
1099                throw LinuxSamplerException("Internal error: could not create audio output device.");
1100            // Set it as the current channel device...
1101            pSamplerChannel->SetAudioOutputDevice(pDevice);
1102        }
1103        catch (LinuxSamplerException e) {
1104             result.Error(e);
1105        }
1106        return result.Produce();
1107    }
1108    
1109    String LSCPServer::SetMIDIInputPort(uint MIDIPort, uint uiSamplerChannel) {
1110        dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIPort=%d, SamplerChannel=%d)\n",MIDIPort,uiSamplerChannel));
1111        LSCPResultSet result;
1112        try {
1113            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1114            if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
1115            pSamplerChannel->SetMidiInputPort(MIDIPort);
1116        }
1117        catch (LinuxSamplerException e) {
1118             result.Error(e);
1119        }
1120        return result.Produce();
1121    }
1122    
1123    String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) {
1124        dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n",MIDIChannel,uiSamplerChannel));
1125        LSCPResultSet result;
1126        try {
1127            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1128            if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
1129            pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);
1130      }      }
1131      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1132           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
1133      }      }
1134      return ConvertResult(result);      return result.Produce();
1135    }
1136    
1137    String LSCPServer::SetMIDIInputDevice(uint MIDIDeviceId, uint uiSamplerChannel) {
1138        dmsg(2,("LSCPServer: SetMIDIInputDevice(MIDIDeviceId=%d, SamplerChannel=%d)\n",MIDIDeviceId,uiSamplerChannel));
1139        LSCPResultSet result;
1140        try {
1141            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1142            if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
1143            std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1144            MidiInputDevice* pDevice = devices[MIDIDeviceId];
1145            if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1146            pSamplerChannel->SetMidiInputDevice(pDevice);
1147        }
1148        catch (LinuxSamplerException e) {
1149             result.Error(e);
1150        }
1151        return result.Produce();
1152    }
1153    
1154    String LSCPServer::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) {
1155        dmsg(2,("LSCPServer: SetMIDIInputType(String MidiInputDriver=%s, SamplerChannel=%d)\n",MidiInputDriver.c_str(),uiSamplerChannel));
1156        LSCPResultSet result;
1157        try {
1158            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1159            if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
1160            // Driver type name aliasing...
1161            if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa";
1162            // Check if there's one MIDI input device already created
1163            // for the intended MIDI driver type (MidiInputDriver)...
1164            MidiInputDevice *pDevice = NULL;
1165            std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1166            std::map<uint, MidiInputDevice*>::iterator iter = devices.begin();
1167            for (; iter != devices.end(); iter++) {
1168                if ((iter->second)->Driver() == MidiInputDriver) {
1169                    pDevice = iter->second;
1170                    break;
1171                }
1172            }
1173            // If it doesn't exist, create a new one with default parameters...
1174            if (pDevice == NULL) {
1175                std::map<String,String> params;
1176                pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params);
1177                // Make it with at least one initial port.
1178                std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters();
1179                parameters["ports"]->SetValue("1");
1180            }
1181            // Must have a device...
1182            if (pDevice == NULL)
1183                throw LinuxSamplerException("Internal error: could not create MIDI input device.");
1184            // Set it as the current channel device...
1185            pSamplerChannel->SetMidiInputDevice(pDevice);
1186        }
1187        catch (LinuxSamplerException e) {
1188             result.Error(e);
1189        }
1190        return result.Produce();
1191  }  }
1192    
1193  /**  /**
1194   * Will be called by the parser to change the MIDI input channel on which the   * Will be called by the parser to change the MIDI input device, port and channel on which
1195   * engine of a particular sampler channel should listen to.   * engine of a particular sampler channel should listen to.
1196   */   */
1197  String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) {  String LSCPServer::SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel) {
1198      dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, uiSamplerChannel));      dmsg(2,("LSCPServer: SetMIDIInput(MIDIDeviceId=%d, MIDIPort=%d, MIDIChannel=%d, SamplerChannel=%d)\n", MIDIDeviceId, MIDIPort, MIDIChannel, uiSamplerChannel));
1199      result_t result;      LSCPResultSet result;
1200      try {      try {
1201          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1202          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
1203          if (!pSamplerChannel->GetMidiInputDevice()) throw LinuxSamplerException("No MIDI input device connected yet");          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1204          MidiInputDevice::type_t oldtype = pSamplerChannel->GetMidiInputDevice()->Type();          MidiInputDevice* pDevice = devices[MIDIDeviceId];
1205          pSamplerChannel->SetMidiInputDevice(oldtype, (MidiInputDevice::midi_chan_t) MIDIChannel);          if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1206            pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel);
         result.type = result_type_success;  
1207      }      }
1208      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1209           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
1210      }      }
1211      return ConvertResult(result);      return result.Produce();
1212  }  }
1213    
1214  /**  /**
# Line 418  String LSCPServer::SetMIDIInputChannel(u Line 1217  String LSCPServer::SetMIDIInputChannel(u
1217   */   */
1218  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {  String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) {
1219      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel));
1220      result_t result;      LSCPResultSet result;
1221      try {      try {
1222          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1223          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
1224          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
1225          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
1226          pEngine->Volume(Volume);          pEngine->Volume(Volume);
         result.type = result_type_success;  
1227      }      }
1228      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1229           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
1230      }      }
1231      return ConvertResult(result);      return result.Produce();
1232  }  }
1233    
1234  /**  /**
# Line 441  String LSCPServer::SetVolume(double Volu Line 1236  String LSCPServer::SetVolume(double Volu
1236   */   */
1237  String LSCPServer::ResetChannel(uint uiSamplerChannel) {  String LSCPServer::ResetChannel(uint uiSamplerChannel) {
1238      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel));
1239      result_t result;      LSCPResultSet result;
1240      try {      try {
1241          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1242          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");
1243          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
1244          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");
1245          pEngine->Reset();          pEngine->Reset();
         result.type = result_type_success;  
1246      }      }
1247      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1248           e.PrintMessage();           result.Error(e);
          result.type    = result_type_error;  
          result.code    = LSCP_ERR_UNKNOWN;  
          result.message = e.Message();  
1249      }      }
1250      return ConvertResult(result);      return result.Produce();
1251  }  }
1252    
1253  /**  /**
1254   * 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
1255   * server for receiving event messages.   * server for receiving event messages.
1256   */   */
1257  String LSCPServer::SubscribeNotification(uint UDPPort) {  String LSCPServer::SubscribeNotification(LSCPEvent::event_t type) {
1258      dmsg(2,("LSCPServer: SubscribeNotification(UDPPort=%d)\n", UDPPort));      dmsg(2,("LSCPServer: SubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str()));
1259      return "ERR:0:Not implemented yet.\r\n";      LSCPResultSet result;
1260        SubscriptionMutex.Lock();
1261        eventSubscriptions[type].push_back(currentSocket);
1262        SubscriptionMutex.Unlock();
1263        return result.Produce();
1264  }  }
1265    
1266  /**  /**
1267   * Will be called by the parser to unsubscribe a client on the server   * Will be called by the parser to unsubscribe a client on the server
1268   * for not receiving further event messages.   * for not receiving further event messages.
1269   */   */
1270  String LSCPServer::UnsubscribeNotification(String SessionID) {  String LSCPServer::UnsubscribeNotification(LSCPEvent::event_t type) {
1271      dmsg(2,("LSCPServer: UnsubscribeNotification(SessionID=%s)\n", SessionID.c_str()));      dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str()));
1272      return "ERR:0:Not implemented yet.\r\n";      LSCPResultSet result;
1273        SubscriptionMutex.Lock();
1274        eventSubscriptions[type].remove(currentSocket);
1275        SubscriptionMutex.Unlock();
1276        return result.Produce();
1277    }
1278    
1279    
1280    // Instrument loader constructor.
1281    LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument)
1282        : Thread(false, 0, -4)
1283    {
1284        this->pEngine = pEngine;
1285        this->Filename = Filename;
1286        this->uiInstrument = uiInstrument;
1287    }
1288    
1289    // Instrument loader process.
1290    int LSCPLoadInstrument::Main()
1291    {
1292        try {
1293            pEngine->LoadInstrument(Filename.c_str(), uiInstrument);
1294        }
1295    
1296        catch (LinuxSamplerException e) {
1297            e.PrintMessage();
1298        }
1299    
1300        // Always re-enable the engine.
1301        pEngine->Enable();
1302    
1303        // FIXME: Shoot ourselves on the foot?
1304        delete this;
1305  }  }

Legend:
Removed from v.113  
changed lines
  Added in v.185

  ViewVC Help
Powered by ViewVC