1 |
schoenebeck |
35 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
|
|
* LinuxSampler - modular, streaming capable sampler * |
4 |
|
|
* * |
5 |
schoenebeck |
56 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
schoenebeck |
35 |
* * |
7 |
|
|
* 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 * |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or * |
10 |
|
|
* (at your option) any later version. * |
11 |
|
|
* * |
12 |
|
|
* This program is distributed in the hope that it will be useful, * |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
15 |
|
|
* GNU General Public License for more details. * |
16 |
|
|
* * |
17 |
|
|
* You should have received a copy of the GNU General Public License * |
18 |
|
|
* along with this program; if not, write to the Free Software * |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
20 |
|
|
* MA 02111-1307 USA * |
21 |
|
|
***************************************************************************/ |
22 |
|
|
|
23 |
|
|
#ifndef __LSCPSERVER_H_ |
24 |
|
|
#define __LSCPSERVER_H_ |
25 |
|
|
|
26 |
|
|
#include <unistd.h> |
27 |
|
|
#include <sys/types.h> |
28 |
|
|
#include <sys/socket.h> |
29 |
|
|
#include <netinet/in.h> |
30 |
|
|
#include <netinet/tcp.h> |
31 |
|
|
#include <arpa/inet.h> |
32 |
|
|
#include <netdb.h> |
33 |
|
|
|
34 |
schoenebeck |
53 |
#include "lscp.h" |
35 |
schoenebeck |
35 |
#include "lscpparser.h" |
36 |
schoenebeck |
53 |
#include "../Sampler.h" |
37 |
|
|
#include "../common/Thread.h" |
38 |
schoenebeck |
35 |
|
39 |
|
|
/// TCP Port on which the server should listen for connection requests. |
40 |
|
|
#define LSCP_PORT 8888 |
41 |
|
|
|
42 |
schoenebeck |
53 |
using namespace LinuxSampler; |
43 |
|
|
|
44 |
schoenebeck |
35 |
/// 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). |
45 |
|
|
extern int hSession; |
46 |
|
|
|
47 |
|
|
// External references to the main scanner and parser functions |
48 |
|
|
extern int yyparse(void* YYPARSE_PARAM); |
49 |
|
|
extern int yylex_init(yyscan_t* scanner); |
50 |
|
|
extern int yylex_destroy(yyscan_t yyscanner); |
51 |
|
|
|
52 |
|
|
/** |
53 |
|
|
* Network server for the LinuxSampler Control Protocol (LSCP). |
54 |
|
|
*/ |
55 |
|
|
class LSCPServer : public Thread { |
56 |
|
|
public: |
57 |
schoenebeck |
53 |
LSCPServer(Sampler* pSampler); |
58 |
schoenebeck |
35 |
|
59 |
|
|
// Methods called by the parser |
60 |
schoenebeck |
123 |
String DestroyAudioOutputDevice(uint DeviceIndex); |
61 |
senkov |
155 |
String DestroyMidiInputDevice(uint DeviceIndex); |
62 |
capela |
137 |
String LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground = false); |
63 |
schoenebeck |
53 |
String LoadEngine(String EngineName, uint uiSamplerChannel); |
64 |
schoenebeck |
35 |
String GetChannels(); |
65 |
|
|
String AddChannel(); |
66 |
schoenebeck |
53 |
String RemoveChannel(uint uiSamplerChannel); |
67 |
schoenebeck |
35 |
String GetAvailableEngines(); |
68 |
|
|
String GetEngineInfo(String EngineName); |
69 |
schoenebeck |
53 |
String GetChannelInfo(uint uiSamplerChannel); |
70 |
|
|
String GetVoiceCount(uint uiSamplerChannel); |
71 |
|
|
String GetStreamCount(uint uiSamplerChannel); |
72 |
|
|
String GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel); |
73 |
schoenebeck |
123 |
String GetAvailableAudioOutputDrivers(); |
74 |
senkov |
155 |
String GetAvailableMidiInputDrivers(); |
75 |
schoenebeck |
123 |
String GetAudioOutputDriverInfo(String Driver); |
76 |
senkov |
155 |
String GetMidiInputDriverInfo(String Driver); |
77 |
schoenebeck |
123 |
#ifdef __GNUC__ |
78 |
|
|
typedef std::map<String,String> StringMap; // nasty workaround for a GCC bug (see GCC bug #15980, #57) |
79 |
|
|
String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = StringMap()); |
80 |
senkov |
155 |
String GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = StringMap()); |
81 |
senkov |
140 |
String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters = StringMap()); |
82 |
senkov |
155 |
String CreateMidiInputDevice(String Driver, std::map<String,String> Parameters = StringMap()); |
83 |
schoenebeck |
123 |
#else |
84 |
|
|
String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = std::map<String,String>()); |
85 |
senkov |
155 |
String GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = std::map<String,String>()); |
86 |
senkov |
140 |
String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters = std::map<String,String>()); |
87 |
senkov |
155 |
String CreateMidiInputDevice(String Driver, std::map<String,String> Parameters = std::map<String,String>()); |
88 |
schoenebeck |
123 |
#endif // __GNUC__ |
89 |
|
|
String GetAudioOutputDeviceCount(); |
90 |
senkov |
155 |
String GetMidiInputDeviceCount(); |
91 |
schoenebeck |
123 |
String GetAudioOutputDevices(); |
92 |
senkov |
155 |
String GetMidiInputDevices(); |
93 |
schoenebeck |
123 |
String GetAudioOutputDeviceInfo(uint DeviceIndex); |
94 |
senkov |
155 |
String GetMidiInputDeviceInfo(uint DeviceIndex); |
95 |
|
|
String GetMidiInputPortInfo(uint DeviceIndex, uint PortIndex); |
96 |
schoenebeck |
123 |
String GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId); |
97 |
|
|
String GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName); |
98 |
|
|
String SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal); |
99 |
|
|
String SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal); |
100 |
senkov |
155 |
String SetMidiInputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal); |
101 |
capela |
159 |
String SetMidiInputPortParameter(uint DeviceIndex, uint PortIndex, String ParamKey, String ParamVal); |
102 |
schoenebeck |
123 |
String SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel); |
103 |
capela |
159 |
String SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel); |
104 |
capela |
143 |
String SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel); |
105 |
capela |
159 |
String SetMIDIInputPort(uint MIDIPort, uint uiSamplerChannel); |
106 |
|
|
String SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel); |
107 |
|
|
String SetMIDIInputDevice(uint MIDIDeviceId, uint uiSamplerChannel); |
108 |
schoenebeck |
123 |
String SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel); |
109 |
capela |
159 |
String SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel); |
110 |
schoenebeck |
53 |
String SetVolume(double Volume, uint uiSamplerChannel); |
111 |
|
|
String ResetChannel(uint uiSamplerChannel); |
112 |
senkov |
135 |
String SubscribeNotification(event_t Event); |
113 |
|
|
String UnsubscribeNotification(event_t Event); |
114 |
schoenebeck |
35 |
void AnswerClient(String ReturnMessage); |
115 |
|
|
protected: |
116 |
schoenebeck |
53 |
int hSocket; |
117 |
|
|
sockaddr_in SocketAddress; |
118 |
|
|
Sampler* pSampler; |
119 |
schoenebeck |
35 |
|
120 |
|
|
int Main(); ///< Implementation of virtual method from class Thread |
121 |
|
|
private: |
122 |
capela |
143 |
|
123 |
schoenebeck |
35 |
/** |
124 |
capela |
143 |
* Find a created audio output device index. |
125 |
|
|
*/ |
126 |
|
|
int GetAudioOutputDeviceIndex (AudioOutputDevice *pDevice); |
127 |
senkov |
155 |
|
128 |
|
|
/** |
129 |
|
|
* Find a created midi input device index. |
130 |
|
|
*/ |
131 |
|
|
int GetMidiInputDeviceIndex (MidiInputDevice *pDevice); |
132 |
capela |
143 |
|
133 |
|
|
/** |
134 |
schoenebeck |
35 |
* Converts a result_t structure into a valid LSCP answer message. |
135 |
|
|
*/ |
136 |
|
|
inline String ConvertResult(result_t result) { |
137 |
|
|
switch (result.type) { |
138 |
|
|
case result_type_success: { |
139 |
|
|
return "OK\r\n"; |
140 |
|
|
} |
141 |
|
|
case result_type_warning: { |
142 |
|
|
std::stringstream ss; |
143 |
|
|
ss << "WRN:" << result.code << ":" << result.message << "\r\n"; |
144 |
|
|
return ss.str(); |
145 |
|
|
} |
146 |
|
|
case result_type_error: { |
147 |
|
|
std::stringstream ss; |
148 |
|
|
ss << "ERR:" << result.code << ":" << result.message << "\r\n"; |
149 |
|
|
return ss.str(); |
150 |
|
|
} |
151 |
|
|
} |
152 |
|
|
} |
153 |
|
|
|
154 |
schoenebeck |
53 |
template<class T> inline String ToString(T o) { |
155 |
schoenebeck |
35 |
std::stringstream ss; |
156 |
schoenebeck |
53 |
ss << o; |
157 |
schoenebeck |
35 |
return ss.str(); |
158 |
|
|
} |
159 |
|
|
}; |
160 |
|
|
|
161 |
capela |
133 |
|
162 |
|
|
/** |
163 |
|
|
* Instrument loader thread for the LinuxSampler Control Protocol (LSCP). |
164 |
|
|
*/ |
165 |
|
|
class LSCPLoadInstrument : public Thread { |
166 |
|
|
|
167 |
|
|
public: |
168 |
|
|
LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument); |
169 |
|
|
|
170 |
|
|
protected: |
171 |
|
|
// Instance variables. |
172 |
|
|
Engine* pEngine; |
173 |
|
|
String Filename; |
174 |
|
|
uint uiInstrument; |
175 |
|
|
|
176 |
|
|
// Implementation of virtual method from class Thread. |
177 |
|
|
int Main(); |
178 |
|
|
}; |
179 |
|
|
|
180 |
schoenebeck |
35 |
#endif // __LSCPSERVER_H_ |