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); |
102 |
String SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal); |
String SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal); |
103 |
String SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal); |
String SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal); |
104 |
String SetMidiInputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal); |
String SetMidiInputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal); |
105 |
String SetMidiInputPortParameter(uint DeviceIndex, uint PortIndex, String ParamKey, String ParamVal); |
String SetMidiInputPortParameter(uint DeviceIndex, uint PortIndex, String ParamKey, String ParamVal); |
106 |
String SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel); |
String SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel); |
107 |
|
String SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel); |
108 |
String SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel); |
String SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel); |
109 |
|
String SetMIDIInputPort(uint MIDIPort, uint uiSamplerChannel); |
110 |
|
String SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel); |
111 |
|
String SetMIDIInputDevice(uint MIDIDeviceId, uint uiSamplerChannel); |
112 |
String SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel); |
String SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel); |
113 |
String SetMIDIInput(uint MIDIDevice, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel); |
String SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel); |
|
String SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel); |
|
114 |
String SetVolume(double Volume, uint uiSamplerChannel); |
String SetVolume(double Volume, uint uiSamplerChannel); |
115 |
String ResetChannel(uint uiSamplerChannel); |
String ResetChannel(uint uiSamplerChannel); |
116 |
String SubscribeNotification(event_t Event); |
String SubscribeNotification(LSCPEvent::event_t); |
117 |
String UnsubscribeNotification(event_t Event); |
String UnsubscribeNotification(LSCPEvent::event_t); |
118 |
void AnswerClient(String ReturnMessage); |
void AnswerClient(String ReturnMessage); |
119 |
|
|
120 |
|
static int currentSocket; |
121 |
|
static std::map<int,String> bufferedCommands; |
122 |
|
|
123 |
|
static void SendLSCPNotify( LSCPEvent Event ); |
124 |
|
|
125 |
protected: |
protected: |
126 |
int hSocket; |
int hSocket; |
127 |
sockaddr_in SocketAddress; |
sockaddr_in SocketAddress; |
128 |
Sampler* pSampler; |
Sampler* pSampler; |
129 |
|
|
130 |
int Main(); ///< Implementation of virtual method from class Thread |
int Main(); ///< Implementation of virtual method from class Thread |
131 |
|
|
132 |
private: |
private: |
133 |
|
|
134 |
/** |
/** |
141 |
*/ |
*/ |
142 |
int GetMidiInputDeviceIndex (MidiInputDevice *pDevice); |
int GetMidiInputDeviceIndex (MidiInputDevice *pDevice); |
143 |
|
|
144 |
/** |
static std::map<int,String> bufferedNotifies; |
145 |
* Converts a result_t structure into a valid LSCP answer message. |
static Mutex NotifyMutex; |
146 |
*/ |
static Mutex NotifyBufferMutex; |
147 |
inline String ConvertResult(result_t result) { |
static bool GetLSCPCommand( std::vector<int>::iterator iter ); |
148 |
switch (result.type) { |
static void CloseConnection( std::vector<int>::iterator iter ); |
149 |
case result_type_success: { |
static std::vector<int> hSessions; |
150 |
return "OK\r\n"; |
static Mutex SubscriptionMutex; |
151 |
} |
static std::map< LSCPEvent::event_t, std::list<int> > eventSubscriptions; |
152 |
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(); |
|
|
} |
|
153 |
}; |
}; |
154 |
|
|
|
|
|
155 |
/** |
/** |
156 |
* Instrument loader thread for the LinuxSampler Control Protocol (LSCP). |
* Instrument loader thread for the LinuxSampler Control Protocol (LSCP). |
157 |
*/ |
*/ |