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); |
66 |
String LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground = false); |
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(); |
98 |
String GetAudioOutputDeviceInfo(uint DeviceIndex); |
String GetAudioOutputDeviceInfo(uint DeviceIndex); |
99 |
String GetMidiInputDeviceInfo(uint DeviceIndex); |
String GetMidiInputDeviceInfo(uint DeviceIndex); |
100 |
String GetMidiInputPortInfo(uint DeviceIndex, uint PortIndex); |
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); |
115 |
String SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel); |
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(event_t Event); |
String SubscribeNotification(LSCPEvent::event_t); |
119 |
String UnsubscribeNotification(event_t Event); |
String UnsubscribeNotification(LSCPEvent::event_t); |
120 |
|
String SetEcho(yyparse_param_t* pSession, double boolean_value); |
121 |
void AnswerClient(String ReturnMessage); |
void AnswerClient(String ReturnMessage); |
122 |
|
|
123 |
|
static int currentSocket; |
124 |
|
static std::map<int,String> bufferedCommands; |
125 |
|
|
126 |
|
static void SendLSCPNotify( LSCPEvent Event ); |
127 |
|
|
128 |
protected: |
protected: |
129 |
int hSocket; |
int hSocket; |
130 |
sockaddr_in SocketAddress; |
sockaddr_in SocketAddress; |
131 |
Sampler* pSampler; |
Sampler* pSampler; |
132 |
|
|
133 |
int Main(); ///< Implementation of virtual method from class Thread |
int Main(); ///< Implementation of virtual method from class Thread |
134 |
|
|
135 |
private: |
private: |
136 |
|
|
137 |
/** |
/** |
138 |
* Find a created audio output device index. |
* Find a created audio output device index. |
139 |
*/ |
*/ |
140 |
int GetAudioOutputDeviceIndex (AudioOutputDevice *pDevice); |
int GetAudioOutputDeviceIndex (AudioOutputDevice *pDevice); |
141 |
|
|
142 |
/** |
/** |
143 |
* Find a created midi input device index. |
* Find a created midi input device index. |
144 |
*/ |
*/ |
145 |
int GetMidiInputDeviceIndex (MidiInputDevice *pDevice); |
int GetMidiInputDeviceIndex (MidiInputDevice *pDevice); |
146 |
|
|
147 |
/** |
static std::map<int,String> bufferedNotifies; |
148 |
* Converts a result_t structure into a valid LSCP answer message. |
static Mutex NotifyMutex; |
149 |
*/ |
static Mutex NotifyBufferMutex; |
150 |
inline String ConvertResult(result_t result) { |
static bool GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ); |
151 |
switch (result.type) { |
static void CloseConnection( std::vector<yyparse_param_t>::iterator iter ); |
152 |
case result_type_success: { |
static std::vector<yyparse_param_t> Sessions; |
153 |
return "OK\r\n"; |
static Mutex SubscriptionMutex; |
154 |
} |
static std::map< LSCPEvent::event_t, std::list<int> > eventSubscriptions; |
155 |
case result_type_warning: { |
static fd_set fdSet; |
|
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(); |
|
|
} |
|
156 |
}; |
}; |
157 |
|
|
|
|
|
158 |
/** |
/** |
159 |
* Instrument loader thread for the LinuxSampler Control Protocol (LSCP). |
* Instrument loader thread for the LinuxSampler Control Protocol (LSCP). |
160 |
*/ |
*/ |