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

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

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

revision 53 by schoenebeck, Mon Apr 26 17:15:51 2004 UTC revision 227 by schoenebeck, Thu Aug 26 22:05:44 2004 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003 by Benno Senoner and Christian Schoenebeck         *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *                                                                         *   *                                                                         *
7   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
8   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 26  Line 26 
26  #include <unistd.h>  #include <unistd.h>
27  #include <sys/types.h>  #include <sys/types.h>
28  #include <sys/socket.h>  #include <sys/socket.h>
29    #include <sys/select.h>
30    #include <sys/time.h>
31  #include <netinet/in.h>  #include <netinet/in.h>
32  #include <netinet/tcp.h>  #include <netinet/tcp.h>
33  #include <arpa/inet.h>  #include <arpa/inet.h>
34  #include <netdb.h>  #include <netdb.h>
35    
36    #include <list>
37    
38  #include "lscp.h"  #include "lscp.h"
39  #include "lscpparser.h"  #include "lscpparser.h"
40    #include "lscp.h"
41    #include "lscpevent.h"
42  #include "../Sampler.h"  #include "../Sampler.h"
43  #include "../common/Thread.h"  #include "../common/Thread.h"
44    #include "../common/Mutex.h"
45    #include "../common/Condition.h"
46    
47  /// TCP Port on which the server should listen for connection requests.  /// TCP Port on which the server should listen for connection requests.
48  #define LSCP_PORT 8888  #define LSCP_PORT 8888
49    
50  using namespace LinuxSampler;  /// try up to 3 minutes to bind server socket
51    #define LSCP_SERVER_BIND_TIMEOUT 180
52    
53  /// Handle for a client connection (FIXME: doesn't work for more than one network connections of course, thus has to be included to the yyparse() parameters instead).  using namespace LinuxSampler;
 extern int hSession;  
54    
55  // External references to the main scanner and parser functions  // External references to the main scanner and parser functions
56  extern int yyparse(void* YYPARSE_PARAM);  extern int yyparse(void* YYPARSE_PARAM);
57  extern int yylex_init(yyscan_t* scanner);  extern void restart(yyparse_param_t* pparam, int& yychar);
 extern int yylex_destroy(yyscan_t yyscanner);  
58    
59  /**  /**
60   * Network server for the LinuxSampler Control Protocol (LSCP).   * Network server for the LinuxSampler Control Protocol (LSCP).
# Line 55  extern int yylex_destroy(yyscan_t yyscan Line 62  extern int yylex_destroy(yyscan_t yyscan
62  class LSCPServer : public Thread {  class LSCPServer : public Thread {
63      public:      public:
64          LSCPServer(Sampler* pSampler);          LSCPServer(Sampler* pSampler);
65            int WaitUntilInitialized(long TimeoutSeconds = 0L, long TimeoutNanoSeconds = 0L);
66    
67          // Methods called by the parser          // Methods called by the parser
68          String LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel);          String DestroyAudioOutputDevice(uint DeviceIndex);
69            String DestroyMidiInputDevice(uint DeviceIndex);
70            String LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground = false);
71          String LoadEngine(String EngineName, uint uiSamplerChannel);          String LoadEngine(String EngineName, uint uiSamplerChannel);
72          String GetChannels();          String GetChannels();
73            String ListChannels();
74          String AddChannel();          String AddChannel();
75          String RemoveChannel(uint uiSamplerChannel);          String RemoveChannel(uint uiSamplerChannel);
76          String GetAvailableEngines();          String GetAvailableEngines();
# Line 68  class LSCPServer : public Thread { Line 79  class LSCPServer : public Thread {
79          String GetVoiceCount(uint uiSamplerChannel);          String GetVoiceCount(uint uiSamplerChannel);
80          String GetStreamCount(uint uiSamplerChannel);          String GetStreamCount(uint uiSamplerChannel);
81          String GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel);          String GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel);
82          String SetAudioOutputType(audio_output_type_t AudioOutputType, uint uiSamplerChannel);          String GetAvailableAudioOutputDrivers();
83          String SetAudioOutputChannel(uint AudioOutputChannel, uint uiSamplerChannel);          String GetAvailableMidiInputDrivers();
84          String SetMIDIInputType(midi_input_type_t MidiInputType, uint uiSamplerChannel);          String GetAudioOutputDriverInfo(String Driver);
85          String SetMIDIInputPort(String MIDIInputPort, uint uiSamplerchannel);          String GetMidiInputDriverInfo(String Driver);
86    #ifdef __GNUC__
87            typedef std::map<String,String> StringMap; // nasty workaround for a GCC bug (see GCC bug #15980, #57)
88            String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = StringMap());
89            String GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = StringMap());
90            String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters = StringMap());
91            String CreateMidiInputDevice(String Driver, std::map<String,String> Parameters = StringMap());
92    #else
93            String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = std::map<String,String>());
94            String GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = std::map<String,String>());
95            String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters = std::map<String,String>());
96            String CreateMidiInputDevice(String Driver, std::map<String,String> Parameters = std::map<String,String>());
97    #endif // __GNUC__
98            String GetAudioOutputDeviceCount();
99            String GetMidiInputDeviceCount();
100            String GetAudioOutputDevices();
101            String GetMidiInputDevices();
102            String GetAudioOutputDeviceInfo(uint DeviceIndex);
103            String GetMidiInputDeviceInfo(uint DeviceIndex);
104            String GetMidiInputPortInfo(uint DeviceIndex, uint PortIndex);
105            String GetMidiInputPortParameterInfo(uint DeviceId, uint PortId, String ParameterName);
106            String GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId);
107            String GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName);
108            String SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal);
109            String SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal);
110            String SetMidiInputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal);
111            String SetMidiInputPortParameter(uint DeviceIndex, uint PortIndex, String ParamKey, String ParamVal);
112            String SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel);
113            String SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel);
114            String SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel);
115            String SetMIDIInputPort(uint MIDIPort, uint uiSamplerChannel);
116          String SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel);          String SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel);
117          String SetVolume(double Volume, uint uiSamplerChannel);          String SetMIDIInputDevice(uint MIDIDeviceId, uint uiSamplerChannel);
118            String SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel);
119            String SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel);
120            String SetVolume(double dVolume, uint uiSamplerChannel);
121          String ResetChannel(uint uiSamplerChannel);          String ResetChannel(uint uiSamplerChannel);
122          String SubscribeNotification(uint UDPPort);          String ResetSampler();
123          String UnsubscribeNotification(String SessionID);          String SubscribeNotification(LSCPEvent::event_t);
124            String UnsubscribeNotification(LSCPEvent::event_t);
125            String SetEcho(yyparse_param_t* pSession, double boolean_value);
126          void   AnswerClient(String ReturnMessage);          void   AnswerClient(String ReturnMessage);
127    
128            static int currentSocket;
129            static std::map<int,String> bufferedCommands;
130    
131            static void SendLSCPNotify( LSCPEvent Event );
132    
133      protected:      protected:
134          int            hSocket;          int            hSocket;
135          sockaddr_in    SocketAddress;          sockaddr_in    SocketAddress;
136          Sampler*       pSampler;          Sampler*       pSampler;
137            Condition      Initialized;
138    
139          int Main(); ///< Implementation of virtual method from class Thread          int Main(); ///< Implementation of virtual method from class Thread
140    
141      private:      private:
142    
143            /**
144             * Find a created audio output device index.
145             */
146            int GetAudioOutputDeviceIndex (AudioOutputDevice *pDevice);
147    
148          /**          /**
149           * Converts a result_t structure into a valid LSCP answer message.           * Find a created midi input device index.
150           */           */
151          inline String ConvertResult(result_t result) {          int GetMidiInputDeviceIndex (MidiInputDevice *pDevice);
152              switch (result.type) {  
153                  case result_type_success: {          static std::map<int,String> bufferedNotifies;
154                      return "OK\r\n";          static Mutex NotifyMutex;
155                  }          static Mutex NotifyBufferMutex;
156                  case result_type_warning: {          static bool GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter );
157                      std::stringstream ss;          static void CloseConnection( std::vector<yyparse_param_t>::iterator iter );
158                      ss << "WRN:" << result.code << ":" << result.message << "\r\n";          static std::vector<yyparse_param_t> Sessions;
159                      return ss.str();          static Mutex SubscriptionMutex;
160                  }          static std::map< LSCPEvent::event_t, std::list<int> > eventSubscriptions;
161                  case result_type_error: {          static fd_set fdSet;
162                      std::stringstream ss;  };
163                      ss << "ERR:" << result.code << ":" << result.message << "\r\n";  
164                      return ss.str();  /**
165                  }   * Instrument loader thread for the LinuxSampler Control Protocol (LSCP).
166              }   */
167          }  class LSCPLoadInstrument : public Thread {
168    
169          template<class T> inline String ToString(T o) {      public:
170              std::stringstream ss;          LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument);
171              ss << o;  
172              return ss.str();      protected:
173          }          // Instance variables.
174            Engine* pEngine;
175            String  Filename;
176            uint    uiInstrument;
177    
178            // Implementation of virtual method from class Thread.
179            int Main();
180  };  };
181    
182  #endif // __LSCPSERVER_H_  #endif // __LSCPSERVER_H_

Legend:
Removed from v.53  
changed lines
  Added in v.227

  ViewVC Help
Powered by ViewVC