/[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 133 by capela, Fri Jun 18 14:29:02 2004 UTC revision 225 by schoenebeck, Sun Aug 22 14:46:47 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    #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;  using namespace LinuxSampler;
51    
 /// 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;  
   
52  // External references to the main scanner and parser functions  // External references to the main scanner and parser functions
53  extern int yyparse(void* YYPARSE_PARAM);  extern int yyparse(void* YYPARSE_PARAM);
54  extern int yylex_init(yyscan_t* scanner);  extern void restart(yyparse_param_t* pparam, int& yychar);
 extern int yylex_destroy(yyscan_t yyscanner);  
55    
56  /**  /**
57   * 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 59  extern int yylex_destroy(yyscan_t yyscan
59  class LSCPServer : public Thread {  class LSCPServer : public Thread {
60      public:      public:
61          LSCPServer(Sampler* pSampler);          LSCPServer(Sampler* pSampler);
62            int WaitUntilInitialized(long TimeoutSeconds = 0L, long TimeoutNanoSeconds = 0L);
63    
64          // Methods called by the parser          // Methods called by the parser
         String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters);  
65          String DestroyAudioOutputDevice(uint DeviceIndex);          String DestroyAudioOutputDevice(uint DeviceIndex);
66          String LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel);          String DestroyMidiInputDevice(uint DeviceIndex);
67            String LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground = false);
68          String LoadEngine(String EngineName, uint uiSamplerChannel);          String LoadEngine(String EngineName, uint uiSamplerChannel);
69          String GetChannels();          String GetChannels();
70            String ListChannels();
71          String AddChannel();          String AddChannel();
72          String RemoveChannel(uint uiSamplerChannel);          String RemoveChannel(uint uiSamplerChannel);
73          String GetAvailableEngines();          String GetAvailableEngines();
# Line 71  class LSCPServer : public Thread { Line 77  class LSCPServer : public Thread {
77          String GetStreamCount(uint uiSamplerChannel);          String GetStreamCount(uint uiSamplerChannel);
78          String GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel);          String GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel);
79          String GetAvailableAudioOutputDrivers();          String GetAvailableAudioOutputDrivers();
80            String GetAvailableMidiInputDrivers();
81          String GetAudioOutputDriverInfo(String Driver);          String GetAudioOutputDriverInfo(String Driver);
82            String GetMidiInputDriverInfo(String Driver);
83  #ifdef __GNUC__  #ifdef __GNUC__
84          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)
85          String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = StringMap());          String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = StringMap());
86            String GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = StringMap());
87            String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters = StringMap());
88            String CreateMidiInputDevice(String Driver, std::map<String,String> Parameters = StringMap());
89  #else  #else
90          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>());
91            String GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = std::map<String,String>());
92            String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters = std::map<String,String>());
93            String CreateMidiInputDevice(String Driver, std::map<String,String> Parameters = std::map<String,String>());
94  #endif // __GNUC__  #endif // __GNUC__
95          String GetAudioOutputDeviceCount();          String GetAudioOutputDeviceCount();
96            String GetMidiInputDeviceCount();
97          String GetAudioOutputDevices();          String GetAudioOutputDevices();
98            String GetMidiInputDevices();
99          String GetAudioOutputDeviceInfo(uint DeviceIndex);          String GetAudioOutputDeviceInfo(uint DeviceIndex);
100            String GetMidiInputDeviceInfo(uint DeviceIndex);
101            String GetMidiInputPortInfo(uint DeviceIndex, uint PortIndex);
102            String GetMidiInputPortParameterInfo(uint DeviceId, uint PortId, String ParameterName);
103          String GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId);          String GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId);
104          String GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName);          String GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName);
105          String SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal);          String SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal);
106          String SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal);          String SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal);
107            String SetMidiInputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal);
108            String SetMidiInputPortParameter(uint DeviceIndex, uint PortIndex, String ParamKey, String ParamVal);
109          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);  
110          String SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel);          String SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel);
111          String SetVolume(double Volume, uint uiSamplerChannel);          String SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel);
112            String SetMIDIInputPort(uint MIDIPort, uint uiSamplerChannel);
113            String SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel);
114            String SetMIDIInputDevice(uint MIDIDeviceId, uint uiSamplerChannel);
115            String SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel);
116            String SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel);
117            String SetVolume(double dVolume, uint uiSamplerChannel);
118          String ResetChannel(uint uiSamplerChannel);          String ResetChannel(uint uiSamplerChannel);
119          String SubscribeNotification(uint UDPPort);          String ResetSampler();
120          String UnsubscribeNotification(String SessionID);          String SubscribeNotification(LSCPEvent::event_t);
121            String UnsubscribeNotification(LSCPEvent::event_t);
122            String SetEcho(yyparse_param_t* pSession, double boolean_value);
123          void   AnswerClient(String ReturnMessage);          void   AnswerClient(String ReturnMessage);
124    
125            static int currentSocket;
126            static std::map<int,String> bufferedCommands;
127    
128            static void SendLSCPNotify( LSCPEvent Event );
129    
130      protected:      protected:
131          int            hSocket;          int            hSocket;
132          sockaddr_in    SocketAddress;          sockaddr_in    SocketAddress;
133          Sampler*       pSampler;          Sampler*       pSampler;
134            Condition      Initialized;
135    
136          int Main(); ///< Implementation of virtual method from class Thread          int Main(); ///< Implementation of virtual method from class Thread
137    
138      private:      private:
139    
140          /**          /**
141           * Converts a result_t structure into a valid LSCP answer message.           * Find a created audio output device index.
142           */           */
143          inline String ConvertResult(result_t result) {          int GetAudioOutputDeviceIndex (AudioOutputDevice *pDevice);
             switch (result.type) {  
                 case result_type_success: {  
                     return "OK\r\n";  
                 }  
                 case result_type_warning: {  
                     std::stringstream ss;  
                     ss << "WRN:" << result.code << ":" << result.message << "\r\n";  
                     return ss.str();  
                 }  
                 case result_type_error: {  
                     std::stringstream ss;  
                     ss << "ERR:" << result.code << ":" << result.message << "\r\n";  
                     return ss.str();  
                 }  
             }  
         }  
   
         template<class T> inline String ToString(T o) {  
             std::stringstream ss;  
             ss << o;  
             return ss.str();  
         }  
 };  
144    
145            /**
146             * Find a created midi input device index.
147             */
148            int GetMidiInputDeviceIndex (MidiInputDevice *pDevice);
149    
150            static std::map<int,String> bufferedNotifies;
151            static Mutex NotifyMutex;
152            static Mutex NotifyBufferMutex;
153            static bool GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter );
154            static void CloseConnection( std::vector<yyparse_param_t>::iterator iter );
155            static std::vector<yyparse_param_t> Sessions;
156            static Mutex SubscriptionMutex;
157            static std::map< LSCPEvent::event_t, std::list<int> > eventSubscriptions;
158            static fd_set fdSet;
159    };
160    
161  /**  /**
162   * Instrument loader thread for the LinuxSampler Control Protocol (LSCP).   * Instrument loader thread for the LinuxSampler Control Protocol (LSCP).

Legend:
Removed from v.133  
changed lines
  Added in v.225

  ViewVC Help
Powered by ViewVC