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 |
senkov |
170 |
#include <sys/select.h> |
30 |
|
|
#include <sys/time.h> |
31 |
schoenebeck |
35 |
#include <netinet/in.h> |
32 |
|
|
#include <netinet/tcp.h> |
33 |
|
|
#include <arpa/inet.h> |
34 |
|
|
#include <netdb.h> |
35 |
|
|
|
36 |
senkov |
170 |
#include <list> |
37 |
|
|
|
38 |
schoenebeck |
53 |
#include "lscp.h" |
39 |
schoenebeck |
35 |
#include "lscpparser.h" |
40 |
senkov |
170 |
#include "lscp.h" |
41 |
|
|
#include "lscpevent.h" |
42 |
schoenebeck |
53 |
#include "../Sampler.h" |
43 |
|
|
#include "../common/Thread.h" |
44 |
senkov |
170 |
#include "../common/Mutex.h" |
45 |
schoenebeck |
211 |
#include "../common/Condition.h" |
46 |
schoenebeck |
35 |
|
47 |
|
|
/// TCP Port on which the server should listen for connection requests. |
48 |
|
|
#define LSCP_PORT 8888 |
49 |
|
|
|
50 |
schoenebeck |
227 |
/// try up to 3 minutes to bind server socket |
51 |
|
|
#define LSCP_SERVER_BIND_TIMEOUT 180 |
52 |
|
|
|
53 |
schoenebeck |
53 |
using namespace LinuxSampler; |
54 |
|
|
|
55 |
schoenebeck |
35 |
// External references to the main scanner and parser functions |
56 |
|
|
extern int yyparse(void* YYPARSE_PARAM); |
57 |
schoenebeck |
219 |
extern void restart(yyparse_param_t* pparam, int& yychar); |
58 |
schoenebeck |
35 |
|
59 |
|
|
/** |
60 |
|
|
* Network server for the LinuxSampler Control Protocol (LSCP). |
61 |
|
|
*/ |
62 |
|
|
class LSCPServer : public Thread { |
63 |
|
|
public: |
64 |
schoenebeck |
53 |
LSCPServer(Sampler* pSampler); |
65 |
schoenebeck |
211 |
int WaitUntilInitialized(long TimeoutSeconds = 0L, long TimeoutNanoSeconds = 0L); |
66 |
schoenebeck |
35 |
|
67 |
|
|
// Methods called by the parser |
68 |
schoenebeck |
123 |
String DestroyAudioOutputDevice(uint DeviceIndex); |
69 |
senkov |
155 |
String DestroyMidiInputDevice(uint DeviceIndex); |
70 |
capela |
137 |
String LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground = false); |
71 |
schoenebeck |
53 |
String LoadEngine(String EngineName, uint uiSamplerChannel); |
72 |
schoenebeck |
35 |
String GetChannels(); |
73 |
schoenebeck |
209 |
String ListChannels(); |
74 |
schoenebeck |
35 |
String AddChannel(); |
75 |
schoenebeck |
53 |
String RemoveChannel(uint uiSamplerChannel); |
76 |
schoenebeck |
35 |
String GetAvailableEngines(); |
77 |
|
|
String GetEngineInfo(String EngineName); |
78 |
schoenebeck |
53 |
String GetChannelInfo(uint uiSamplerChannel); |
79 |
|
|
String GetVoiceCount(uint uiSamplerChannel); |
80 |
|
|
String GetStreamCount(uint uiSamplerChannel); |
81 |
|
|
String GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel); |
82 |
schoenebeck |
123 |
String GetAvailableAudioOutputDrivers(); |
83 |
senkov |
155 |
String GetAvailableMidiInputDrivers(); |
84 |
schoenebeck |
123 |
String GetAudioOutputDriverInfo(String Driver); |
85 |
senkov |
155 |
String GetMidiInputDriverInfo(String Driver); |
86 |
schoenebeck |
123 |
#ifdef __GNUC__ |
87 |
|
|
typedef std::map<String,String> StringMap; // nasty workaround for a GCC bug (see GCC bug #15980, #57) |
88 |
|
|
String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = StringMap()); |
89 |
senkov |
155 |
String GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = StringMap()); |
90 |
senkov |
140 |
String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters = StringMap()); |
91 |
senkov |
155 |
String CreateMidiInputDevice(String Driver, std::map<String,String> Parameters = StringMap()); |
92 |
schoenebeck |
123 |
#else |
93 |
|
|
String GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = std::map<String,String>()); |
94 |
senkov |
155 |
String GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList = std::map<String,String>()); |
95 |
senkov |
140 |
String CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters = std::map<String,String>()); |
96 |
senkov |
155 |
String CreateMidiInputDevice(String Driver, std::map<String,String> Parameters = std::map<String,String>()); |
97 |
schoenebeck |
123 |
#endif // __GNUC__ |
98 |
|
|
String GetAudioOutputDeviceCount(); |
99 |
senkov |
155 |
String GetMidiInputDeviceCount(); |
100 |
schoenebeck |
123 |
String GetAudioOutputDevices(); |
101 |
senkov |
155 |
String GetMidiInputDevices(); |
102 |
schoenebeck |
123 |
String GetAudioOutputDeviceInfo(uint DeviceIndex); |
103 |
senkov |
155 |
String GetMidiInputDeviceInfo(uint DeviceIndex); |
104 |
|
|
String GetMidiInputPortInfo(uint DeviceIndex, uint PortIndex); |
105 |
senkov |
185 |
String GetMidiInputPortParameterInfo(uint DeviceId, uint PortId, String ParameterName); |
106 |
schoenebeck |
123 |
String GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId); |
107 |
|
|
String GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName); |
108 |
|
|
String SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal); |
109 |
|
|
String SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal); |
110 |
senkov |
155 |
String SetMidiInputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal); |
111 |
capela |
159 |
String SetMidiInputPortParameter(uint DeviceIndex, uint PortIndex, String ParamKey, String ParamVal); |
112 |
schoenebeck |
123 |
String SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel); |
113 |
capela |
159 |
String SetAudioOutputDevice(uint AudioDeviceId, uint SamplerChannel); |
114 |
capela |
143 |
String SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel); |
115 |
capela |
159 |
String SetMIDIInputPort(uint MIDIPort, uint uiSamplerChannel); |
116 |
|
|
String SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel); |
117 |
|
|
String SetMIDIInputDevice(uint MIDIDeviceId, uint uiSamplerChannel); |
118 |
schoenebeck |
123 |
String SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel); |
119 |
capela |
159 |
String SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel); |
120 |
schoenebeck |
225 |
String SetVolume(double dVolume, uint uiSamplerChannel); |
121 |
schoenebeck |
53 |
String ResetChannel(uint uiSamplerChannel); |
122 |
schoenebeck |
212 |
String ResetSampler(); |
123 |
senkov |
170 |
String SubscribeNotification(LSCPEvent::event_t); |
124 |
|
|
String UnsubscribeNotification(LSCPEvent::event_t); |
125 |
schoenebeck |
210 |
String SetEcho(yyparse_param_t* pSession, double boolean_value); |
126 |
schoenebeck |
35 |
void AnswerClient(String ReturnMessage); |
127 |
senkov |
170 |
|
128 |
|
|
static int currentSocket; |
129 |
|
|
static std::map<int,String> bufferedCommands; |
130 |
senkov |
184 |
|
131 |
|
|
static void SendLSCPNotify( LSCPEvent Event ); |
132 |
senkov |
360 |
static int EventSubscribers( std::list<LSCPEvent::event_t> events ); |
133 |
|
|
static void LockRTNotify( void ) { RTNotifyMutex.Lock(); } |
134 |
|
|
static void UnlockRTNotify( void ) { RTNotifyMutex.Unlock(); } |
135 |
senkov |
184 |
|
136 |
schoenebeck |
35 |
protected: |
137 |
schoenebeck |
53 |
int hSocket; |
138 |
|
|
sockaddr_in SocketAddress; |
139 |
|
|
Sampler* pSampler; |
140 |
schoenebeck |
211 |
Condition Initialized; |
141 |
schoenebeck |
35 |
|
142 |
|
|
int Main(); ///< Implementation of virtual method from class Thread |
143 |
senkov |
170 |
|
144 |
schoenebeck |
35 |
private: |
145 |
schoenebeck |
209 |
|
146 |
schoenebeck |
35 |
/** |
147 |
capela |
143 |
* Find a created audio output device index. |
148 |
|
|
*/ |
149 |
|
|
int GetAudioOutputDeviceIndex (AudioOutputDevice *pDevice); |
150 |
schoenebeck |
209 |
|
151 |
senkov |
155 |
/** |
152 |
|
|
* Find a created midi input device index. |
153 |
|
|
*/ |
154 |
|
|
int GetMidiInputDeviceIndex (MidiInputDevice *pDevice); |
155 |
capela |
143 |
|
156 |
senkov |
170 |
static std::map<int,String> bufferedNotifies; |
157 |
|
|
static Mutex NotifyMutex; |
158 |
|
|
static Mutex NotifyBufferMutex; |
159 |
schoenebeck |
210 |
static bool GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ); |
160 |
|
|
static void CloseConnection( std::vector<yyparse_param_t>::iterator iter ); |
161 |
|
|
static std::vector<yyparse_param_t> Sessions; |
162 |
senkov |
170 |
static Mutex SubscriptionMutex; |
163 |
|
|
static std::map< LSCPEvent::event_t, std::list<int> > eventSubscriptions; |
164 |
|
|
static fd_set fdSet; |
165 |
senkov |
360 |
|
166 |
|
|
//Protect main thread that generates real time notify messages |
167 |
|
|
//like voice count, stream count and buffer fill |
168 |
|
|
//from LSCP server removing engines and channels from underneath |
169 |
|
|
static Mutex RTNotifyMutex; |
170 |
schoenebeck |
35 |
}; |
171 |
|
|
|
172 |
capela |
133 |
/** |
173 |
|
|
* Instrument loader thread for the LinuxSampler Control Protocol (LSCP). |
174 |
|
|
*/ |
175 |
|
|
class LSCPLoadInstrument : public Thread { |
176 |
|
|
|
177 |
|
|
public: |
178 |
|
|
LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument); |
179 |
|
|
|
180 |
|
|
protected: |
181 |
|
|
// Instance variables. |
182 |
|
|
Engine* pEngine; |
183 |
|
|
String Filename; |
184 |
|
|
uint uiInstrument; |
185 |
|
|
|
186 |
|
|
// Implementation of virtual method from class Thread. |
187 |
|
|
int Main(); |
188 |
|
|
}; |
189 |
|
|
|
190 |
schoenebeck |
35 |
#endif // __LSCPSERVER_H_ |