/[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 123 by schoenebeck, Mon Jun 14 19:33:16 2004 UTC revision 209 by schoenebeck, Sun Jul 18 00:29:39 2004 UTC
# 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    
46  /// TCP Port on which the server should listen for connection requests.  /// TCP Port on which the server should listen for connection requests.
47  #define LSCP_PORT 8888  #define LSCP_PORT 8888
48    
49  using namespace LinuxSampler;  using namespace LinuxSampler;
50    
 /// 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).  
 extern int hSession;  
   
51  // External references to the main scanner and parser functions  // External references to the main scanner and parser functions
52  extern int yyparse(void* YYPARSE_PARAM);  extern int yyparse(void* YYPARSE_PARAM);
53  extern int yylex_init(yyscan_t* scanner);  extern int yylex_init(yyscan_t* scanner);
# Line 57  class LSCPServer : public Thread { Line 61  class LSCPServer : public Thread {
61          LSCPServer(Sampler* pSampler);          LSCPServer(Sampler* pSampler);
62    
63          // Methods called by the parser          // Methods called by the parser
         String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters);  
64          String DestroyAudioOutputDevice(uint DeviceIndex);          String DestroyAudioOutputDevice(uint DeviceIndex);
65          String LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel);          String DestroyMidiInputDevice(uint DeviceIndex);
66            String LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground = false);
67          String LoadEngine(String EngineName, uint uiSamplerChannel);          String LoadEngine(String EngineName, uint uiSamplerChannel);
68          String GetChannels();          String GetChannels();
69            String ListChannels();
70          String AddChannel();          String AddChannel();
71          String RemoveChannel(uint uiSamplerChannel);          String RemoveChannel(uint uiSamplerChannel);
72          String GetAvailableEngines();          String GetAvailableEngines();
# Line 71  class LSCPServer : public Thread { Line 76  class LSCPServer : public Thread {
76          String GetStreamCount(uint uiSamplerChannel);          String GetStreamCount(uint uiSamplerChannel);
77          String GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel);          String GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel);
78          String GetAvailableAudioOutputDrivers();          String GetAvailableAudioOutputDrivers();
79            String GetAvailableMidiInputDrivers();
80          String GetAudioOutputDriverInfo(String Driver);          String GetAudioOutputDriverInfo(String Driver);
81            String GetMidiInputDriverInfo(String Driver);
82  #ifdef __GNUC__  #ifdef __GNUC__
83          typedef std::map<String,String> StringMap; // nasty workaround for a GCC bug (see GCC bug #15980, #57)          typedef std::map<String,String> StringMap; // nasty workaround for a GCC bug (see GCC bug #15980, #57)
84          String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = StringMap());          String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = StringMap());
85            String GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = StringMap());
86            String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters = StringMap());
87            String CreateMidiInputDevice(String Driver, std::map<String,String> Parameters = StringMap());
88  #else  #else
89          String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = std::map<String,String>());          String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = std::map<String,String>());
90            String GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = std::map<String,String>());
91            String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters = std::map<String,String>());
92            String CreateMidiInputDevice(String Driver, std::map<String,String> Parameters = std::map<String,String>());
93  #endif // __GNUC__  #endif // __GNUC__
94          String GetAudioOutputDeviceCount();          String GetAudioOutputDeviceCount();
95            String GetMidiInputDeviceCount();
96          String GetAudioOutputDevices();          String GetAudioOutputDevices();
97            String GetMidiInputDevices();
98          String GetAudioOutputDeviceInfo(uint DeviceIndex);          String GetAudioOutputDeviceInfo(uint DeviceIndex);
99            String GetMidiInputDeviceInfo(uint DeviceIndex);
100            String GetMidiInputPortInfo(uint DeviceIndex, uint PortIndex);
101            String GetMidiInputPortParameterInfo(uint DeviceId, uint PortId, String ParameterName);
102          String GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId);          String GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId);
103          String GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName);          String GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName);
104          String SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal);          String SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal);
105          String SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal);          String SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal);
106            String SetMidiInputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal);
107            String SetMidiInputPortParameter(uint DeviceIndex, uint PortIndex, String ParamKey, String ParamVal);
108          String SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel);          String SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel);
         String SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel);  
         String SetMIDIInputPort(String MIDIInputPort, uint uiSamplerchannel);  
         String SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel);  
109          String SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel);          String SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel);
110            String SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel);
111            String SetMIDIInputPort(uint MIDIPort, uint uiSamplerChannel);
112            String SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel);
113            String SetMIDIInputDevice(uint MIDIDeviceId, uint uiSamplerChannel);
114            String SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel);
115            String SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel);
116          String SetVolume(double Volume, uint uiSamplerChannel);          String SetVolume(double Volume, uint uiSamplerChannel);
117          String ResetChannel(uint uiSamplerChannel);          String ResetChannel(uint uiSamplerChannel);
118          String SubscribeNotification(uint UDPPort);          String SubscribeNotification(LSCPEvent::event_t);
119          String UnsubscribeNotification(String SessionID);          String UnsubscribeNotification(LSCPEvent::event_t);
120          void   AnswerClient(String ReturnMessage);          void   AnswerClient(String ReturnMessage);
121    
122            static int currentSocket;
123            static std::map<int,String> bufferedCommands;
124    
125            static void SendLSCPNotify( LSCPEvent Event );
126    
127      protected:      protected:
128          int            hSocket;          int            hSocket;
129          sockaddr_in    SocketAddress;          sockaddr_in    SocketAddress;
130          Sampler*       pSampler;          Sampler*       pSampler;
131    
132          int Main(); ///< Implementation of virtual method from class Thread          int Main(); ///< Implementation of virtual method from class Thread
133    
134      private:      private:
135    
136          /**          /**
137           * Converts a result_t structure into a valid LSCP answer message.           * Find a created audio output device index.
138           */           */
139          inline String ConvertResult(result_t result) {          int GetAudioOutputDeviceIndex (AudioOutputDevice *pDevice);
140              switch (result.type) {  
141                  case result_type_success: {          /**
142                      return "OK\r\n";           * Find a created midi input device index.
143                  }           */
144                  case result_type_warning: {          int GetMidiInputDeviceIndex (MidiInputDevice *pDevice);
145                      std::stringstream ss;  
146                      ss << "WRN:" << result.code << ":" << result.message << "\r\n";          static std::map<int,String> bufferedNotifies;
147                      return ss.str();          static Mutex NotifyMutex;
148                  }          static Mutex NotifyBufferMutex;
149                  case result_type_error: {          static bool GetLSCPCommand( std::vector<int>::iterator iter );
150                      std::stringstream ss;          static void CloseConnection( std::vector<int>::iterator iter );
151                      ss << "ERR:" << result.code << ":" << result.message << "\r\n";          static std::vector<int> hSessions;
152                      return ss.str();          static Mutex SubscriptionMutex;
153                  }          static std::map< LSCPEvent::event_t, std::list<int> > eventSubscriptions;
154              }          static fd_set fdSet;
155          }  };
156    
157          template<class T> inline String ToString(T o) {  /**
158              std::stringstream ss;   * Instrument loader thread for the LinuxSampler Control Protocol (LSCP).
159              ss << o;   */
160              return ss.str();  class LSCPLoadInstrument : public Thread {
161          }  
162        public:
163            LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument);
164    
165        protected:
166            // Instance variables.
167            Engine* pEngine;
168            String  Filename;
169            uint    uiInstrument;
170    
171            // Implementation of virtual method from class Thread.
172            int Main();
173  };  };
174    
175  #endif // __LSCPSERVER_H_  #endif // __LSCPSERVER_H_

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

  ViewVC Help
Powered by ViewVC