42 |
#include "../Sampler.h" |
#include "../Sampler.h" |
43 |
#include "../common/Thread.h" |
#include "../common/Thread.h" |
44 |
#include "../common/Mutex.h" |
#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 |
|
/// try up to 3 minutes to bind server socket |
51 |
|
#define LSCP_SERVER_BIND_TIMEOUT 180 |
52 |
|
|
53 |
using namespace LinuxSampler; |
using namespace LinuxSampler; |
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). |
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 DestroyAudioOutputDevice(uint DeviceIndex); |
String DestroyAudioOutputDevice(uint DeviceIndex); |
70 |
String LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground = false); |
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(); |
117 |
String SetMIDIInputDevice(uint MIDIDeviceId, uint uiSamplerChannel); |
String SetMIDIInputDevice(uint MIDIDeviceId, uint uiSamplerChannel); |
118 |
String SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel); |
String SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel); |
119 |
String SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel); |
String SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel); |
120 |
String SetVolume(double Volume, uint uiSamplerChannel); |
String SetVolume(double dVolume, uint uiSamplerChannel); |
121 |
String ResetChannel(uint uiSamplerChannel); |
String ResetChannel(uint uiSamplerChannel); |
122 |
|
String ResetSampler(); |
123 |
String SubscribeNotification(LSCPEvent::event_t); |
String SubscribeNotification(LSCPEvent::event_t); |
124 |
String UnsubscribeNotification(LSCPEvent::event_t); |
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; |
static int currentSocket; |
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. |
* Find a created audio output device index. |
145 |
*/ |
*/ |
146 |
int GetAudioOutputDeviceIndex (AudioOutputDevice *pDevice); |
int GetAudioOutputDeviceIndex (AudioOutputDevice *pDevice); |
147 |
|
|
148 |
/** |
/** |
149 |
* Find a created midi input device index. |
* Find a created midi input device index. |
150 |
*/ |
*/ |
153 |
static std::map<int,String> bufferedNotifies; |
static std::map<int,String> bufferedNotifies; |
154 |
static Mutex NotifyMutex; |
static Mutex NotifyMutex; |
155 |
static Mutex NotifyBufferMutex; |
static Mutex NotifyBufferMutex; |
156 |
static bool GetLSCPCommand( std::vector<int>::iterator iter ); |
static bool GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ); |
157 |
static void CloseConnection( std::vector<int>::iterator iter ); |
static void CloseConnection( std::vector<yyparse_param_t>::iterator iter ); |
158 |
static std::vector<int> hSessions; |
static std::vector<yyparse_param_t> Sessions; |
159 |
static Mutex SubscriptionMutex; |
static Mutex SubscriptionMutex; |
160 |
static std::map< LSCPEvent::event_t, std::list<int> > eventSubscriptions; |
static std::map< LSCPEvent::event_t, std::list<int> > eventSubscriptions; |
161 |
static fd_set fdSet; |
static fd_set fdSet; |