2 |
* * |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* * |
* * |
7 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
8 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
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" |
39 |
#include "lscpparser.h" |
#include "lscpparser.h" |
40 |
#include "../thread.h" |
#include "lscp.h" |
41 |
#include "../audiothread.h" |
#include "lscpevent.h" |
42 |
|
#include "../Sampler.h" |
43 |
|
#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 |
/// 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). |
using namespace LinuxSampler; |
|
extern int hSession; |
|
50 |
|
|
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); |
58 |
*/ |
*/ |
59 |
class LSCPServer : public Thread { |
class LSCPServer : public Thread { |
60 |
public: |
public: |
61 |
LSCPServer(AudioThread* pEngine); |
LSCPServer(Sampler* pSampler); |
62 |
|
|
63 |
// Methods called by the parser |
// Methods called by the parser |
64 |
String LoadInstrument(String Filename, uint Instrument, uint SamplerChannel); |
String DestroyAudioOutputDevice(uint DeviceIndex); |
65 |
String LoadEngine(String EngineName, uint SamplerChannel); |
String DestroyMidiInputDevice(uint DeviceIndex); |
66 |
|
String LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground = false); |
67 |
|
String LoadEngine(String EngineName, uint uiSamplerChannel); |
68 |
String GetChannels(); |
String GetChannels(); |
69 |
String AddChannel(); |
String AddChannel(); |
70 |
String RemoveChannel(uint SamplerChannel); |
String RemoveChannel(uint uiSamplerChannel); |
71 |
String GetAvailableEngines(); |
String GetAvailableEngines(); |
72 |
String GetEngineInfo(String EngineName); |
String GetEngineInfo(String EngineName); |
73 |
String GetChannelInfo(uint SamplerChannel); |
String GetChannelInfo(uint uiSamplerChannel); |
74 |
String GetVoiceCount(uint SamplerChannel); |
String GetVoiceCount(uint uiSamplerChannel); |
75 |
String GetStreamCount(uint SamplerChannel); |
String GetStreamCount(uint uiSamplerChannel); |
76 |
String GetBufferFill(fill_response_t ResponseType, uint SamplerChannel); |
String GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel); |
77 |
String SetAudioOutputType(audio_output_type_t AudioOutputType, uint SamplerChannel); |
String GetAvailableAudioOutputDrivers(); |
78 |
String SetAudioOutputChannel(uint AudioOutputChannel, uint SamplerChannel); |
String GetAvailableMidiInputDrivers(); |
79 |
String SetMIDIInputPort(String MIDIInputPort, uint Samplerchannel); |
String GetAudioOutputDriverInfo(String Driver); |
80 |
String SetMIDIInputChannel(uint MIDIChannel, uint SamplerChannel); |
String GetMidiInputDriverInfo(String Driver); |
81 |
String SetVolume(double Volume, uint SamplerChannel); |
#ifdef __GNUC__ |
82 |
String ResetChannel(uint SamplerChannel); |
typedef std::map<String,String> StringMap; // nasty workaround for a GCC bug (see GCC bug #15980, #57) |
83 |
String SubscribeNotification(uint UDPPort); |
String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = StringMap()); |
84 |
String UnsubscribeNotification(String SessionID); |
String GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = StringMap()); |
85 |
|
String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters = StringMap()); |
86 |
|
String CreateMidiInputDevice(String Driver, std::map<String,String> Parameters = StringMap()); |
87 |
|
#else |
88 |
|
String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = std::map<String,String>()); |
89 |
|
String GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = std::map<String,String>()); |
90 |
|
String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters = std::map<String,String>()); |
91 |
|
String CreateMidiInputDevice(String Driver, std::map<String,String> Parameters = std::map<String,String>()); |
92 |
|
#endif // __GNUC__ |
93 |
|
String GetAudioOutputDeviceCount(); |
94 |
|
String GetMidiInputDeviceCount(); |
95 |
|
String GetAudioOutputDevices(); |
96 |
|
String GetMidiInputDevices(); |
97 |
|
String GetAudioOutputDeviceInfo(uint DeviceIndex); |
98 |
|
String GetMidiInputDeviceInfo(uint DeviceIndex); |
99 |
|
String GetMidiInputPortInfo(uint DeviceIndex, uint PortIndex); |
100 |
|
String GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId); |
101 |
|
String GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName); |
102 |
|
String SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal); |
103 |
|
String SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal); |
104 |
|
String SetMidiInputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal); |
105 |
|
String SetMidiInputPortParameter(uint DeviceIndex, uint PortIndex, String ParamKey, String ParamVal); |
106 |
|
String SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel); |
107 |
|
String SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel); |
108 |
|
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); |
113 |
|
String SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel); |
114 |
|
String SetVolume(double Volume, uint uiSamplerChannel); |
115 |
|
String ResetChannel(uint uiSamplerChannel); |
116 |
|
String SubscribeNotification(LSCPEvent::event_t); |
117 |
|
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 |
protected: |
protected: |
123 |
int hSocket; |
int hSocket; |
124 |
sockaddr_in SocketAddress; |
sockaddr_in SocketAddress; |
125 |
AudioThread* pEngine; // FIXME: as long as we only have one engine... |
Sampler* pSampler; |
126 |
|
|
127 |
int Main(); ///< Implementation of virtual method from class Thread |
int Main(); ///< Implementation of virtual method from class Thread |
128 |
|
|
129 |
|
static void SendLSCPNotify( LSCPEvent Event ); |
130 |
|
|
131 |
private: |
private: |
132 |
|
|
133 |
/** |
/** |
134 |
* Converts a result_t structure into a valid LSCP answer message. |
* Find a created audio output device index. |
135 |
*/ |
*/ |
136 |
inline String ConvertResult(result_t result) { |
int GetAudioOutputDeviceIndex (AudioOutputDevice *pDevice); |
137 |
switch (result.type) { |
|
138 |
case result_type_success: { |
/** |
139 |
return "OK\r\n"; |
* Find a created midi input device index. |
140 |
} |
*/ |
141 |
case result_type_warning: { |
int GetMidiInputDeviceIndex (MidiInputDevice *pDevice); |
142 |
std::stringstream ss; |
|
143 |
ss << "WRN:" << result.code << ":" << result.message << "\r\n"; |
static std::map<int,String> bufferedNotifies; |
144 |
return ss.str(); |
static Mutex NotifyMutex; |
145 |
} |
static Mutex NotifyBufferMutex; |
146 |
case result_type_error: { |
static bool GetLSCPCommand( std::vector<int>::iterator iter ); |
147 |
std::stringstream ss; |
static void CloseConnection( std::vector<int>::iterator iter ); |
148 |
ss << "ERR:" << result.code << ":" << result.message << "\r\n"; |
static std::vector<int> hSessions; |
149 |
return ss.str(); |
static Mutex SubscriptionMutex; |
150 |
} |
static std::map< LSCPEvent::event_t, std::list<int> > eventSubscriptions; |
151 |
} |
static fd_set fdSet; |
152 |
} |
}; |
153 |
|
|
154 |
inline String ToString(int i) { |
/** |
155 |
std::stringstream ss; |
* Instrument loader thread for the LinuxSampler Control Protocol (LSCP). |
156 |
ss << i; |
*/ |
157 |
return ss.str(); |
class LSCPLoadInstrument : public Thread { |
158 |
} |
|
159 |
|
public: |
160 |
inline String ToString(double d) { |
LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument); |
161 |
std::stringstream ss; |
|
162 |
ss << d; |
protected: |
163 |
return ss.str(); |
// Instance variables. |
164 |
} |
Engine* pEngine; |
165 |
|
String Filename; |
166 |
|
uint uiInstrument; |
167 |
|
|
168 |
|
// Implementation of virtual method from class Thread. |
169 |
|
int Main(); |
170 |
}; |
}; |
171 |
|
|
172 |
#endif // __LSCPSERVER_H_ |
#endif // __LSCPSERVER_H_ |