/[svn]/linuxsampler/trunk/src/network/lscpserver.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/network/lscpserver.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 184 by senkov, Wed Jul 7 02:00:37 2004 UTC revision 209 by schoenebeck, Sun Jul 18 00:29:39 2004 UTC
# Line 25  Line 25 
25  #include "lscpevent.h"  #include "lscpevent.h"
26    
27  #include "../engines/gig/Engine.h"  #include "../engines/gig/Engine.h"
28  #include "../audiodriver/AudioOutputDeviceFactory.h"  #include "../drivers/audio/AudioOutputDeviceFactory.h"
29  #include "../mididriver/MidiInputDeviceFactory.h"  #include "../drivers/midi/MidiInputDeviceFactory.h"
30    
31  /**  /**
32   * Below are a few static members of the LSCPServer class.   * Below are a few static members of the LSCPServer class.
# Line 86  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);
     struct timeval tv;  
     tv.tv_sec = 30;  
     tv.tv_usec = 0;  
89      FD_ZERO(&fdSet);      FD_ZERO(&fdSet);
90      FD_SET(hSocket, &fdSet);      FD_SET(hSocket, &fdSet);
91      int maxSessions = hSocket;      int maxSessions = hSocket;
92    
93      // Parser initialization      // Parser initialization
94      yyparse_param_t yyparse_param;      yyparse_param_t yyparse_param;
95      yyparse_param.pServer = this;      yyparse_param.pServer = this;
96    
97      while (true) {      while (true) {
98          fd_set selectSet = fdSet;          fd_set selectSet = fdSet;
99          int retval = select(maxSessions+1, &selectSet, NULL, NULL, &tv);          int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL);
100          if (retval == 0)          if (retval == 0)
101                  continue; //Nothing in 30 seconds, try again                  continue; //Nothing try again
102          if (retval == -1) {          if (retval == -1) {
103                  std::cerr << "LSCPServer: Socket select error." << std::endl;                  std::cerr << "LSCPServer: Socket select error." << std::endl;
104                  close(hSocket);                  close(hSocket);
105                  exit(EXIT_FAILURE);                  exit(EXIT_FAILURE);
106          }          }
107            
108          //Accept new connections now (if any)          //Accept new connections now (if any)
109          if (FD_ISSET(hSocket, &selectSet)) {          if (FD_ISSET(hSocket, &selectSet)) {
110                  int socket = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length);                  int socket = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length);
# Line 146  int LSCPServer::Main() { Line 143  int LSCPServer::Main() {
143                          }                          }
144                          //socket may have been closed, iter may be invalid, get out of the loop for now.                          //socket may have been closed, iter may be invalid, get out of the loop for now.
145                          //we'll be back if there is data.                          //we'll be back if there is data.
146                          break;                          break;
147                  }                  }
148          }          }
149    
# Line 241  bool LSCPServer::GetLSCPCommand( std::ve Line 238  bool LSCPServer::GetLSCPCommand( std::ve
238                          break;                          break;
239                  }                  }
240                  if (result == 1) {                  if (result == 1) {
241                          if (c == '\r')                          if (c == '\r')
242                                  continue; //Ignore CR                                  continue; //Ignore CR
243                          if (c == '\n') {                          if (c == '\n') {
244                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));                                  LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket));
# Line 268  bool LSCPServer::GetLSCPCommand( std::ve Line 265  bool LSCPServer::GetLSCPCommand( std::ve
265                                          break;                                          break;
266                                  case EAGAIN:                                  case EAGAIN:
267                                          dmsg(2,("LSCPScanner: The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.\n"));                                          dmsg(2,("LSCPScanner: The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.\n"));
268                                          break;                                          break;
269                                  case EINTR:                                  case EINTR:
270                                          dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n"));                                          dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n"));
271                                          break;                                          break;
272                                  case EFAULT:                                  case EFAULT:
273                                          dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n"));                                          dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n"));
274                                          break;                                          break;
275                                  case EINVAL:                                  case EINVAL:
276                                          dmsg(2,("LSCPScanner: Invalid argument passed.\n"));                                          dmsg(2,("LSCPScanner: Invalid argument passed.\n"));
277                                          break;                                          break;
278                                  case ENOMEM:                                  case ENOMEM:
279                                          dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n"));                                          dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n"));
280                                          break;                                          break;
281                                  default:                                  default:
282                                          dmsg(2,("LSCPScanner: Unknown recv() error.\n"));                                          dmsg(2,("LSCPScanner: Unknown recv() error.\n"));
283                                          break;                                          break;
284                          }                          }
285                          CloseConnection(iter);                          CloseConnection(iter);
286                          break;                          break;
287                  }                  }
# Line 457  String LSCPServer::GetChannels() { Line 454  String LSCPServer::GetChannels() {
454  }  }
455    
456  /**  /**
457     * Will be called by the parser to get the list of sampler channels.
458     */
459    String LSCPServer::ListChannels() {
460        dmsg(2,("LSCPServer: ListChannels()\n"));
461        String list;
462        std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels();
463        std::map<uint,SamplerChannel*>::iterator iter = channels.begin();
464        for (; iter != channels.end(); iter++) {
465            if (list != "") list += ",";
466            list += ToString(iter->first);
467        }
468        LSCPResultSet result;
469        result.Add(list);
470        return result.Produce();
471    }
472    
473    /**
474   * Will be called by the parser to add a sampler channel.   * Will be called by the parser to add a sampler channel.
475   */   */
476  String LSCPServer::AddChannel() {  String LSCPServer::AddChannel() {
# Line 897  String LSCPServer::GetAudioOutputChannel Line 911  String LSCPServer::GetAudioOutputChannel
911      return result.Produce();      return result.Produce();
912  }  }
913    
914    String LSCPServer::GetMidiInputPortParameterInfo(uint DeviceId, uint PortId, String ParameterName) {
915        dmsg(2,("LSCPServer: GetMidiInputPortParameterInfo(DeviceId=%d,PortId=%d,ParameterName=%s)\n",DeviceId,PortId,ParameterName.c_str()));
916        LSCPResultSet result;
917        try {
918            // get audio output device
919            std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
920            if (!devices[DeviceId]) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + ".");
921            MidiInputDevice* pDevice = devices[DeviceId];
922    
923            // get midi port
924            MidiInputDevice::MidiInputPort* pPort = pDevice->GetPort(PortId);
925            if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + ".");
926    
927            // get desired port parameter
928            std::map<String,DeviceCreationParameter*> parameters = pPort->DeviceParameters();
929            if (!parameters[ParameterName]) throw LinuxSamplerException("Midi port does not provice a parameters '" + ParameterName + "'.");
930            DeviceCreationParameter* pParameter = parameters[ParameterName];
931    
932            // return all fields of this audio channel parameter
933            result.Add("TYPE",         pParameter->Type());
934            result.Add("DESCRIPTION",  pParameter->Description());
935            result.Add("FIX",          pParameter->Fix());
936            result.Add("MULTIPLICITY", pParameter->Multiplicity());
937            if (pParameter->RangeMin())      result.Add("RANGE_MIN",     pParameter->RangeMin());
938            if (pParameter->RangeMax())      result.Add("RANGE_MAX",     pParameter->RangeMax());
939            if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities());
940        }
941        catch (LinuxSamplerException e) {
942            result.Error(e);
943        }
944        return result.Produce();
945    }
946    
947  String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) {  String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) {
948      dmsg(2,("LSCPServer: GetAudioOutputChannelParameterInfo(DeviceId=%d,ChannelId=%d,ParameterName=%s)\n",DeviceId,ChannelId,ParameterName.c_str()));      dmsg(2,("LSCPServer: GetAudioOutputChannelParameterInfo(DeviceId=%d,ChannelId=%d,ParameterName=%s)\n",DeviceId,ChannelId,ParameterName.c_str()));
949      LSCPResultSet result;      LSCPResultSet result;
# Line 1044  String LSCPServer::SetAudioOutputType(St Line 1091  String LSCPServer::SetAudioOutputType(St
1091          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));
1092          // Driver type name aliasing...          // Driver type name aliasing...
1093          if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa";          if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa";
1094          if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack";                  if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack";
1095          // Check if there's one audio output device already created          // Check if there's one audio output device already created
1096          // for the intended audio driver type (AudioOutputDriver)...          // for the intended audio driver type (AudioOutputDriver)...
1097          AudioOutputDevice *pDevice = NULL;          AudioOutputDevice *pDevice = NULL;

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

  ViewVC Help
Powered by ViewVC