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 |
385 |
* Copyright (C) 2005 Christian Schoenebeck * |
7 |
schoenebeck |
35 |
* * |
8 |
schoenebeck |
385 |
* This library is free software; you can redistribute it and/or modify * |
9 |
schoenebeck |
35 |
* it under the terms of the GNU General Public License as published by * |
10 |
|
|
* the Free Software Foundation; either version 2 of the License, or * |
11 |
|
|
* (at your option) any later version. * |
12 |
|
|
* * |
13 |
schoenebeck |
385 |
* This library is distributed in the hope that it will be useful, * |
14 |
schoenebeck |
35 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 |
|
|
* GNU General Public License for more details. * |
17 |
|
|
* * |
18 |
|
|
* You should have received a copy of the GNU General Public License * |
19 |
schoenebeck |
385 |
* along with this library; if not, write to the Free Software * |
20 |
schoenebeck |
35 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
|
|
* MA 02111-1307 USA * |
22 |
|
|
***************************************************************************/ |
23 |
|
|
|
24 |
|
|
#include "lscpserver.h" |
25 |
senkov |
113 |
#include "lscpresultset.h" |
26 |
senkov |
170 |
#include "lscpevent.h" |
27 |
senkov |
397 |
//#include "../common/global.h" |
28 |
schoenebeck |
35 |
|
29 |
schoenebeck |
411 |
#include <fcntl.h> |
30 |
|
|
|
31 |
schoenebeck |
401 |
#if HAVE_SQLITE3 |
32 |
|
|
# include "sqlite3.h" |
33 |
senkov |
397 |
#endif |
34 |
|
|
|
35 |
schoenebeck |
411 |
#include "../engines/EngineFactory.h" |
36 |
schoenebeck |
660 |
#include "../engines/EngineChannelFactory.h" |
37 |
schoenebeck |
203 |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
38 |
|
|
#include "../drivers/midi/MidiInputDeviceFactory.h" |
39 |
schoenebeck |
53 |
|
40 |
senkov |
170 |
/** |
41 |
|
|
* Below are a few static members of the LSCPServer class. |
42 |
|
|
* The big assumption here is that LSCPServer is going to remain a singleton. |
43 |
|
|
* These members are used to support client connections. |
44 |
|
|
* Class handles multiple connections at the same time using select() and non-blocking recv() |
45 |
|
|
* Commands are processed by a single LSCPServer thread. |
46 |
|
|
* Notifications are delivered either by the thread that originated them |
47 |
|
|
* or (if the resultset is currently in progress) by the LSCPServer thread |
48 |
|
|
* after the resultset was sent out. |
49 |
|
|
* This makes sure that resultsets can not be interrupted by notifications. |
50 |
|
|
* This also makes sure that the thread sending notification is not blocked |
51 |
|
|
* by the LSCPServer thread. |
52 |
|
|
*/ |
53 |
|
|
fd_set LSCPServer::fdSet; |
54 |
|
|
int LSCPServer::currentSocket = -1; |
55 |
schoenebeck |
210 |
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
56 |
senkov |
170 |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
57 |
|
|
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
58 |
|
|
std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions = std::map< LSCPEvent::event_t, std::list<int> >(); |
59 |
|
|
Mutex LSCPServer::NotifyMutex = Mutex(); |
60 |
|
|
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
61 |
|
|
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
62 |
senkov |
360 |
Mutex LSCPServer::RTNotifyMutex = Mutex(); |
63 |
senkov |
170 |
|
64 |
schoenebeck |
392 |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(true, false, 0, -4) { |
65 |
schoenebeck |
53 |
this->pSampler = pSampler; |
66 |
schoenebeck |
556 |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT"); |
67 |
senkov |
170 |
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
68 |
|
|
LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT"); |
69 |
|
|
LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL"); |
70 |
schoenebeck |
556 |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO"); |
71 |
senkov |
170 |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
72 |
schoenebeck |
475 |
hSocket = -1; |
73 |
schoenebeck |
35 |
} |
74 |
|
|
|
75 |
schoenebeck |
475 |
LSCPServer::~LSCPServer() { |
76 |
|
|
if (hSocket >= 0) close(hSocket); |
77 |
|
|
} |
78 |
|
|
|
79 |
schoenebeck |
211 |
/** |
80 |
|
|
* Blocks the calling thread until the LSCP Server is initialized and |
81 |
|
|
* accepting socket connections, if the server is already initialized then |
82 |
|
|
* this method will return immediately. |
83 |
|
|
* @param TimeoutSeconds - optional: max. wait time in seconds |
84 |
|
|
* (default: 0s) |
85 |
|
|
* @param TimeoutNanoSeconds - optional: max wait time in nano seconds |
86 |
|
|
* (default: 0ns) |
87 |
|
|
* @returns 0 on success, a value less than 0 if timeout exceeded |
88 |
|
|
*/ |
89 |
|
|
int LSCPServer::WaitUntilInitialized(long TimeoutSeconds, long TimeoutNanoSeconds) { |
90 |
|
|
return Initialized.WaitAndUnlockIf(false, TimeoutSeconds, TimeoutNanoSeconds); |
91 |
|
|
} |
92 |
|
|
|
93 |
schoenebeck |
35 |
int LSCPServer::Main() { |
94 |
schoenebeck |
475 |
hSocket = socket(AF_INET, SOCK_STREAM, 0); |
95 |
schoenebeck |
35 |
if (hSocket < 0) { |
96 |
|
|
std::cerr << "LSCPServer: Could not create server socket." << std::endl; |
97 |
schoenebeck |
53 |
//return -1; |
98 |
|
|
exit(EXIT_FAILURE); |
99 |
schoenebeck |
35 |
} |
100 |
|
|
|
101 |
|
|
SocketAddress.sin_family = AF_INET; |
102 |
|
|
SocketAddress.sin_port = htons(LSCP_PORT); |
103 |
|
|
SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY); |
104 |
|
|
|
105 |
|
|
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
106 |
schoenebeck |
227 |
std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds..."; |
107 |
|
|
for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds |
108 |
|
|
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
109 |
|
|
if (trial > LSCP_SERVER_BIND_TIMEOUT) { |
110 |
|
|
std::cerr << "gave up!" << std::endl; |
111 |
|
|
close(hSocket); |
112 |
|
|
//return -1; |
113 |
|
|
exit(EXIT_FAILURE); |
114 |
|
|
} |
115 |
|
|
else sleep(1); // sleep 1s |
116 |
|
|
} |
117 |
|
|
else break; // success |
118 |
|
|
} |
119 |
schoenebeck |
35 |
} |
120 |
|
|
|
121 |
|
|
listen(hSocket, 1); |
122 |
schoenebeck |
211 |
Initialized.Set(true); |
123 |
schoenebeck |
35 |
|
124 |
|
|
// now wait for client connections and handle their requests |
125 |
|
|
sockaddr_in client; |
126 |
|
|
int length = sizeof(client); |
127 |
senkov |
170 |
FD_ZERO(&fdSet); |
128 |
|
|
FD_SET(hSocket, &fdSet); |
129 |
|
|
int maxSessions = hSocket; |
130 |
schoenebeck |
203 |
|
131 |
schoenebeck |
35 |
while (true) { |
132 |
senkov |
170 |
fd_set selectSet = fdSet; |
133 |
senkov |
198 |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL); |
134 |
senkov |
170 |
if (retval == 0) |
135 |
senkov |
198 |
continue; //Nothing try again |
136 |
senkov |
170 |
if (retval == -1) { |
137 |
|
|
std::cerr << "LSCPServer: Socket select error." << std::endl; |
138 |
|
|
close(hSocket); |
139 |
|
|
exit(EXIT_FAILURE); |
140 |
|
|
} |
141 |
schoenebeck |
203 |
|
142 |
senkov |
170 |
//Accept new connections now (if any) |
143 |
|
|
if (FD_ISSET(hSocket, &selectSet)) { |
144 |
|
|
int socket = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length); |
145 |
|
|
if (socket < 0) { |
146 |
|
|
std::cerr << "LSCPServer: Client connection failed." << std::endl; |
147 |
|
|
exit(EXIT_FAILURE); |
148 |
|
|
} |
149 |
schoenebeck |
35 |
|
150 |
senkov |
170 |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
151 |
|
|
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
152 |
|
|
exit(EXIT_FAILURE); |
153 |
|
|
} |
154 |
schoenebeck |
35 |
|
155 |
schoenebeck |
210 |
// Parser initialization |
156 |
|
|
yyparse_param_t yyparse_param; |
157 |
|
|
yyparse_param.pServer = this; |
158 |
|
|
yyparse_param.hSession = socket; |
159 |
|
|
|
160 |
|
|
Sessions.push_back(yyparse_param); |
161 |
senkov |
170 |
FD_SET(socket, &fdSet); |
162 |
|
|
if (socket > maxSessions) |
163 |
|
|
maxSessions = socket; |
164 |
|
|
dmsg(1,("LSCPServer: Client connection established on socket:%d.\n", socket)); |
165 |
|
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection established on socket", socket)); |
166 |
|
|
continue; //Maybe this was the only selected socket, better select again |
167 |
|
|
} |
168 |
schoenebeck |
35 |
|
169 |
senkov |
170 |
//Something was selected and it was not the hSocket, so it must be some command(s) coming. |
170 |
schoenebeck |
210 |
for (std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); iter != Sessions.end(); iter++) { |
171 |
|
|
if (FD_ISSET((*iter).hSession, &selectSet)) { //Was it this socket? |
172 |
senkov |
170 |
if (GetLSCPCommand(iter)) { //Have we read the entire command? |
173 |
|
|
dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket)); |
174 |
schoenebeck |
219 |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
175 |
|
|
restart(NULL, dummy); // restart the 'scanner' |
176 |
schoenebeck |
210 |
currentSocket = (*iter).hSession; //a hack |
177 |
schoenebeck |
475 |
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
178 |
schoenebeck |
210 |
if ((*iter).bVerbose) { // if echo mode enabled |
179 |
|
|
AnswerClient(bufferedCommands[currentSocket]); |
180 |
|
|
} |
181 |
|
|
int result = yyparse(&(*iter)); |
182 |
senkov |
170 |
currentSocket = -1; //continuation of a hack |
183 |
|
|
dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket)); |
184 |
|
|
if (result == LSCP_QUIT) { //Was it a quit command by any chance? |
185 |
|
|
CloseConnection(iter); |
186 |
|
|
} |
187 |
|
|
} |
188 |
|
|
//socket may have been closed, iter may be invalid, get out of the loop for now. |
189 |
|
|
//we'll be back if there is data. |
190 |
schoenebeck |
203 |
break; |
191 |
senkov |
170 |
} |
192 |
|
|
} |
193 |
|
|
|
194 |
schoenebeck |
660 |
// check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers |
195 |
|
|
{ |
196 |
|
|
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
197 |
|
|
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
198 |
|
|
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
199 |
|
|
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
200 |
|
|
if ((*itEngineChannel)->StatusChanged()) { |
201 |
|
|
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
202 |
|
|
} |
203 |
|
|
} |
204 |
|
|
} |
205 |
|
|
|
206 |
senkov |
170 |
//Now let's deliver late notifies (if any) |
207 |
|
|
NotifyBufferMutex.Lock(); |
208 |
|
|
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
209 |
|
|
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); |
210 |
|
|
bufferedNotifies.erase(iterNotify); |
211 |
|
|
} |
212 |
|
|
NotifyBufferMutex.Unlock(); |
213 |
schoenebeck |
35 |
} |
214 |
|
|
} |
215 |
|
|
|
216 |
schoenebeck |
210 |
void LSCPServer::CloseConnection( std::vector<yyparse_param_t>::iterator iter ) { |
217 |
|
|
int socket = (*iter).hSession; |
218 |
senkov |
170 |
dmsg(1,("LSCPServer: Client connection terminated on socket:%d.\n",socket)); |
219 |
|
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket)); |
220 |
schoenebeck |
210 |
Sessions.erase(iter); |
221 |
senkov |
170 |
FD_CLR(socket, &fdSet); |
222 |
|
|
SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any) |
223 |
|
|
for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) { |
224 |
|
|
iter->second.remove(socket); |
225 |
|
|
} |
226 |
|
|
SubscriptionMutex.Unlock(); |
227 |
|
|
NotifyMutex.Lock(); |
228 |
|
|
bufferedCommands.erase(socket); |
229 |
|
|
bufferedNotifies.erase(socket); |
230 |
|
|
close(socket); |
231 |
|
|
NotifyMutex.Unlock(); |
232 |
|
|
} |
233 |
|
|
|
234 |
senkov |
360 |
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
235 |
|
|
int subs = 0; |
236 |
|
|
SubscriptionMutex.Lock(); |
237 |
|
|
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
238 |
|
|
iter != events.end(); iter++) |
239 |
|
|
{ |
240 |
|
|
subs += eventSubscriptions.count(*iter); |
241 |
|
|
} |
242 |
|
|
SubscriptionMutex.Unlock(); |
243 |
|
|
return subs; |
244 |
|
|
} |
245 |
|
|
|
246 |
senkov |
170 |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
247 |
|
|
SubscriptionMutex.Lock(); |
248 |
|
|
if (eventSubscriptions.count(event.GetType()) == 0) { |
249 |
|
|
SubscriptionMutex.Unlock(); //Nobody is subscribed to this event |
250 |
|
|
return; |
251 |
|
|
} |
252 |
|
|
std::list<int>::iterator iter = eventSubscriptions[event.GetType()].begin(); |
253 |
|
|
std::list<int>::iterator end = eventSubscriptions[event.GetType()].end(); |
254 |
|
|
String notify = event.Produce(); |
255 |
|
|
|
256 |
|
|
while (true) { |
257 |
|
|
if (NotifyMutex.Trylock()) { |
258 |
|
|
for(;iter != end; iter++) |
259 |
|
|
send(*iter, notify.c_str(), notify.size(), 0); |
260 |
|
|
NotifyMutex.Unlock(); |
261 |
|
|
break; |
262 |
|
|
} else { |
263 |
|
|
if (NotifyBufferMutex.Trylock()) { |
264 |
|
|
for(;iter != end; iter++) |
265 |
|
|
bufferedNotifies[*iter] += notify; |
266 |
|
|
NotifyBufferMutex.Unlock(); |
267 |
|
|
break; |
268 |
|
|
} |
269 |
|
|
} |
270 |
|
|
} |
271 |
|
|
SubscriptionMutex.Unlock(); |
272 |
|
|
} |
273 |
|
|
|
274 |
|
|
extern int GetLSCPCommand( void *buf, int max_size ) { |
275 |
|
|
String command = LSCPServer::bufferedCommands[LSCPServer::currentSocket]; |
276 |
|
|
if (command.size() == 0) { //Parser wants input but we have nothing. |
277 |
|
|
strcpy((char*) buf, "\n"); //So give it an empty command |
278 |
|
|
return 1; //to keep it happy. |
279 |
|
|
} |
280 |
|
|
|
281 |
|
|
if (max_size < command.size()) { |
282 |
|
|
std::cerr << "getLSCPCommand: Flex buffer too small, ignoring the command." << std::endl; |
283 |
|
|
return 0; //This will never happen |
284 |
|
|
} |
285 |
|
|
|
286 |
|
|
strcpy((char*) buf, command.c_str()); |
287 |
|
|
LSCPServer::bufferedCommands.erase(LSCPServer::currentSocket); |
288 |
|
|
return command.size(); |
289 |
|
|
} |
290 |
|
|
|
291 |
schoenebeck |
35 |
/** |
292 |
senkov |
170 |
* Will be called to try to read the command from the socket |
293 |
|
|
* If command is read, it will return true. Otherwise false is returned. |
294 |
|
|
* In any case the received portion (complete or incomplete) is saved into bufferedCommand map. |
295 |
|
|
*/ |
296 |
schoenebeck |
210 |
bool LSCPServer::GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ) { |
297 |
|
|
int socket = (*iter).hSession; |
298 |
senkov |
170 |
char c; |
299 |
|
|
int i = 0; |
300 |
|
|
while (true) { |
301 |
|
|
int result = recv(socket, (void *)&c, 1, 0); //Read one character at a time for now |
302 |
|
|
if (result == 0) { //socket was selected, so 0 here means client has closed the connection |
303 |
|
|
CloseConnection(iter); |
304 |
|
|
break; |
305 |
|
|
} |
306 |
|
|
if (result == 1) { |
307 |
schoenebeck |
203 |
if (c == '\r') |
308 |
senkov |
170 |
continue; //Ignore CR |
309 |
|
|
if (c == '\n') { |
310 |
senkov |
184 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket)); |
311 |
senkov |
170 |
bufferedCommands[socket] += "\n"; |
312 |
|
|
return true; //Complete command was read |
313 |
|
|
} |
314 |
|
|
bufferedCommands[socket] += c; |
315 |
|
|
} |
316 |
|
|
if (result == -1) { |
317 |
|
|
if (errno == EAGAIN) //Would block, try again later. |
318 |
|
|
return false; |
319 |
|
|
switch(errno) { |
320 |
|
|
case EBADF: |
321 |
|
|
dmsg(2,("LSCPScanner: The argument s is an invalid descriptor.\n")); |
322 |
|
|
break; |
323 |
|
|
case ECONNREFUSED: |
324 |
|
|
dmsg(2,("LSCPScanner: A remote host refused to allow the network connection (typically because it is not running the requested service).\n")); |
325 |
|
|
break; |
326 |
|
|
case ENOTCONN: |
327 |
|
|
dmsg(2,("LSCPScanner: The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2)).\n")); |
328 |
|
|
break; |
329 |
|
|
case ENOTSOCK: |
330 |
|
|
dmsg(2,("LSCPScanner: The argument s does not refer to a socket.\n")); |
331 |
|
|
break; |
332 |
|
|
case EAGAIN: |
333 |
|
|
dmsg(2,("LSCPScanner: The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.\n")); |
334 |
schoenebeck |
203 |
break; |
335 |
|
|
case EINTR: |
336 |
senkov |
170 |
dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n")); |
337 |
schoenebeck |
203 |
break; |
338 |
|
|
case EFAULT: |
339 |
|
|
dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n")); |
340 |
|
|
break; |
341 |
|
|
case EINVAL: |
342 |
|
|
dmsg(2,("LSCPScanner: Invalid argument passed.\n")); |
343 |
|
|
break; |
344 |
|
|
case ENOMEM: |
345 |
|
|
dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n")); |
346 |
|
|
break; |
347 |
|
|
default: |
348 |
|
|
dmsg(2,("LSCPScanner: Unknown recv() error.\n")); |
349 |
|
|
break; |
350 |
|
|
} |
351 |
senkov |
170 |
CloseConnection(iter); |
352 |
|
|
break; |
353 |
|
|
} |
354 |
|
|
} |
355 |
|
|
return false; |
356 |
|
|
} |
357 |
|
|
|
358 |
|
|
/** |
359 |
schoenebeck |
35 |
* Will be called by the parser whenever it wants to send an answer to the |
360 |
|
|
* client / frontend. |
361 |
|
|
* |
362 |
|
|
* @param ReturnMessage - message that will be send to the client |
363 |
|
|
*/ |
364 |
|
|
void LSCPServer::AnswerClient(String ReturnMessage) { |
365 |
|
|
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
366 |
senkov |
170 |
if (currentSocket != -1) { |
367 |
|
|
NotifyMutex.Lock(); |
368 |
|
|
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
369 |
|
|
NotifyMutex.Unlock(); |
370 |
|
|
} |
371 |
schoenebeck |
35 |
} |
372 |
|
|
|
373 |
capela |
143 |
/** |
374 |
|
|
* Find a created audio output device index. |
375 |
|
|
*/ |
376 |
|
|
int LSCPServer::GetAudioOutputDeviceIndex ( AudioOutputDevice *pDevice ) |
377 |
|
|
{ |
378 |
|
|
// Search for the created device to get its index |
379 |
|
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
380 |
|
|
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
381 |
|
|
for (; iter != devices.end(); iter++) { |
382 |
|
|
if (iter->second == pDevice) |
383 |
|
|
return iter->first; |
384 |
|
|
} |
385 |
|
|
// Not found. |
386 |
|
|
return -1; |
387 |
|
|
} |
388 |
|
|
|
389 |
senkov |
155 |
/** |
390 |
|
|
* Find a created midi input device index. |
391 |
|
|
*/ |
392 |
|
|
int LSCPServer::GetMidiInputDeviceIndex ( MidiInputDevice *pDevice ) |
393 |
|
|
{ |
394 |
|
|
// Search for the created device to get its index |
395 |
|
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
396 |
|
|
std::map<uint, MidiInputDevice*>::iterator iter = devices.begin(); |
397 |
|
|
for (; iter != devices.end(); iter++) { |
398 |
|
|
if (iter->second == pDevice) |
399 |
|
|
return iter->first; |
400 |
|
|
} |
401 |
|
|
// Not found. |
402 |
|
|
return -1; |
403 |
|
|
} |
404 |
|
|
|
405 |
schoenebeck |
123 |
String LSCPServer::CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters) { |
406 |
|
|
dmsg(2,("LSCPServer: CreateAudioOutputDevice(Driver=%s)\n", Driver.c_str())); |
407 |
|
|
LSCPResultSet result; |
408 |
|
|
try { |
409 |
|
|
AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters); |
410 |
|
|
// search for the created device to get its index |
411 |
capela |
143 |
int index = GetAudioOutputDeviceIndex(pDevice); |
412 |
schoenebeck |
123 |
if (index == -1) throw LinuxSamplerException("Internal error: could not find created audio output device."); |
413 |
|
|
result = index; // success |
414 |
|
|
} |
415 |
|
|
catch (LinuxSamplerException e) { |
416 |
|
|
result.Error(e); |
417 |
|
|
} |
418 |
|
|
return result.Produce(); |
419 |
|
|
} |
420 |
|
|
|
421 |
senkov |
155 |
String LSCPServer::CreateMidiInputDevice(String Driver, std::map<String,String> Parameters) { |
422 |
|
|
dmsg(2,("LSCPServer: CreateMidiInputDevice(Driver=%s)\n", Driver.c_str())); |
423 |
|
|
LSCPResultSet result; |
424 |
|
|
try { |
425 |
|
|
MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters); |
426 |
|
|
// search for the created device to get its index |
427 |
|
|
int index = GetMidiInputDeviceIndex(pDevice); |
428 |
|
|
if (index == -1) throw LinuxSamplerException("Internal error: could not find created midi input device."); |
429 |
|
|
result = index; // success |
430 |
|
|
} |
431 |
|
|
catch (LinuxSamplerException e) { |
432 |
|
|
result.Error(e); |
433 |
|
|
} |
434 |
|
|
return result.Produce(); |
435 |
|
|
} |
436 |
|
|
|
437 |
schoenebeck |
123 |
String LSCPServer::DestroyAudioOutputDevice(uint DeviceIndex) { |
438 |
|
|
dmsg(2,("LSCPServer: DestroyAudioOutputDevice(DeviceIndex=%d)\n", DeviceIndex)); |
439 |
|
|
LSCPResultSet result; |
440 |
|
|
try { |
441 |
|
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
442 |
schoenebeck |
223 |
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
443 |
schoenebeck |
123 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
444 |
|
|
pSampler->DestroyAudioOutputDevice(pDevice); |
445 |
|
|
} |
446 |
|
|
catch (LinuxSamplerException e) { |
447 |
|
|
result.Error(e); |
448 |
|
|
} |
449 |
|
|
return result.Produce(); |
450 |
|
|
} |
451 |
|
|
|
452 |
senkov |
155 |
String LSCPServer::DestroyMidiInputDevice(uint DeviceIndex) { |
453 |
|
|
dmsg(2,("LSCPServer: DestroyMidiInputDevice(DeviceIndex=%d)\n", DeviceIndex)); |
454 |
|
|
LSCPResultSet result; |
455 |
|
|
try { |
456 |
|
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
457 |
schoenebeck |
223 |
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
458 |
senkov |
155 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
459 |
|
|
pSampler->DestroyMidiInputDevice(pDevice); |
460 |
|
|
} |
461 |
|
|
catch (LinuxSamplerException e) { |
462 |
|
|
result.Error(e); |
463 |
|
|
} |
464 |
|
|
return result.Produce(); |
465 |
|
|
} |
466 |
|
|
|
467 |
schoenebeck |
35 |
/** |
468 |
|
|
* Will be called by the parser to load an instrument. |
469 |
|
|
*/ |
470 |
capela |
137 |
String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground) { |
471 |
schoenebeck |
53 |
dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), uiInstrument, uiSamplerChannel)); |
472 |
senkov |
120 |
LSCPResultSet result; |
473 |
schoenebeck |
53 |
try { |
474 |
|
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
475 |
schoenebeck |
374 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
476 |
schoenebeck |
411 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
477 |
|
|
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet"); |
478 |
schoenebeck |
223 |
if (!pSamplerChannel->GetAudioOutputDevice()) |
479 |
schoenebeck |
374 |
throw LinuxSamplerException("No audio output device connected to sampler channel"); |
480 |
capela |
137 |
if (bBackground) { |
481 |
schoenebeck |
411 |
InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel); |
482 |
capela |
137 |
} |
483 |
schoenebeck |
392 |
else { |
484 |
schoenebeck |
411 |
// tell the engine channel which instrument to load |
485 |
|
|
pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument); |
486 |
schoenebeck |
392 |
// actually start to load the instrument (blocks until completed) |
487 |
schoenebeck |
411 |
pEngineChannel->LoadInstrument(); |
488 |
schoenebeck |
392 |
} |
489 |
schoenebeck |
53 |
} |
490 |
|
|
catch (LinuxSamplerException e) { |
491 |
senkov |
120 |
result.Error(e); |
492 |
schoenebeck |
53 |
} |
493 |
senkov |
120 |
return result.Produce(); |
494 |
schoenebeck |
35 |
} |
495 |
|
|
|
496 |
|
|
/** |
497 |
schoenebeck |
411 |
* Will be called by the parser to assign a sampler engine type to a |
498 |
|
|
* sampler channel. |
499 |
schoenebeck |
35 |
*/ |
500 |
schoenebeck |
411 |
String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) { |
501 |
schoenebeck |
53 |
dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel)); |
502 |
senkov |
120 |
LSCPResultSet result; |
503 |
schoenebeck |
475 |
try { |
504 |
schoenebeck |
53 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
505 |
schoenebeck |
374 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
506 |
senkov |
360 |
LockRTNotify(); |
507 |
schoenebeck |
411 |
pSamplerChannel->SetEngineType(EngineName); |
508 |
senkov |
360 |
UnlockRTNotify(); |
509 |
schoenebeck |
53 |
} |
510 |
|
|
catch (LinuxSamplerException e) { |
511 |
senkov |
120 |
result.Error(e); |
512 |
schoenebeck |
53 |
} |
513 |
senkov |
120 |
return result.Produce(); |
514 |
schoenebeck |
35 |
} |
515 |
|
|
|
516 |
|
|
/** |
517 |
|
|
* Will be called by the parser to get the amount of sampler channels. |
518 |
|
|
*/ |
519 |
|
|
String LSCPServer::GetChannels() { |
520 |
|
|
dmsg(2,("LSCPServer: GetChannels()\n")); |
521 |
senkov |
120 |
LSCPResultSet result; |
522 |
|
|
result.Add(pSampler->SamplerChannels()); |
523 |
|
|
return result.Produce(); |
524 |
schoenebeck |
35 |
} |
525 |
|
|
|
526 |
|
|
/** |
527 |
schoenebeck |
209 |
* Will be called by the parser to get the list of sampler channels. |
528 |
|
|
*/ |
529 |
|
|
String LSCPServer::ListChannels() { |
530 |
|
|
dmsg(2,("LSCPServer: ListChannels()\n")); |
531 |
|
|
String list; |
532 |
|
|
std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels(); |
533 |
|
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
534 |
|
|
for (; iter != channels.end(); iter++) { |
535 |
|
|
if (list != "") list += ","; |
536 |
|
|
list += ToString(iter->first); |
537 |
|
|
} |
538 |
|
|
LSCPResultSet result; |
539 |
|
|
result.Add(list); |
540 |
|
|
return result.Produce(); |
541 |
|
|
} |
542 |
|
|
|
543 |
|
|
/** |
544 |
schoenebeck |
35 |
* Will be called by the parser to add a sampler channel. |
545 |
|
|
*/ |
546 |
|
|
String LSCPServer::AddChannel() { |
547 |
|
|
dmsg(2,("LSCPServer: AddChannel()\n")); |
548 |
schoenebeck |
53 |
SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel(); |
549 |
senkov |
120 |
LSCPResultSet result(pSamplerChannel->Index()); |
550 |
|
|
return result.Produce(); |
551 |
schoenebeck |
35 |
} |
552 |
|
|
|
553 |
|
|
/** |
554 |
|
|
* Will be called by the parser to remove a sampler channel. |
555 |
|
|
*/ |
556 |
schoenebeck |
53 |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
557 |
|
|
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
558 |
senkov |
120 |
LSCPResultSet result; |
559 |
senkov |
360 |
LockRTNotify(); |
560 |
schoenebeck |
53 |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
561 |
senkov |
360 |
UnlockRTNotify(); |
562 |
senkov |
120 |
return result.Produce(); |
563 |
schoenebeck |
35 |
} |
564 |
|
|
|
565 |
|
|
/** |
566 |
capela |
527 |
* Will be called by the parser to get the amount of all available engines. |
567 |
schoenebeck |
35 |
*/ |
568 |
|
|
String LSCPServer::GetAvailableEngines() { |
569 |
|
|
dmsg(2,("LSCPServer: GetAvailableEngines()\n")); |
570 |
capela |
527 |
LSCPResultSet result("1"); |
571 |
senkov |
120 |
return result.Produce(); |
572 |
schoenebeck |
35 |
} |
573 |
|
|
|
574 |
|
|
/** |
575 |
capela |
527 |
* Will be called by the parser to get a list of all available engines. |
576 |
|
|
*/ |
577 |
|
|
String LSCPServer::ListAvailableEngines() { |
578 |
|
|
dmsg(2,("LSCPServer: ListAvailableEngines()\n")); |
579 |
|
|
LSCPResultSet result("\'GIG\'"); |
580 |
|
|
return result.Produce(); |
581 |
|
|
} |
582 |
|
|
|
583 |
|
|
/** |
584 |
schoenebeck |
411 |
* Will be called by the parser to get descriptions for a particular |
585 |
|
|
* sampler engine. |
586 |
schoenebeck |
35 |
*/ |
587 |
|
|
String LSCPServer::GetEngineInfo(String EngineName) { |
588 |
|
|
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
589 |
senkov |
120 |
LSCPResultSet result; |
590 |
schoenebeck |
53 |
try { |
591 |
schoenebeck |
411 |
Engine* pEngine = EngineFactory::Create(EngineName); |
592 |
|
|
result.Add("DESCRIPTION", pEngine->Description()); |
593 |
|
|
result.Add("VERSION", pEngine->Version()); |
594 |
schoenebeck |
660 |
EngineFactory::Destroy(pEngine); |
595 |
schoenebeck |
53 |
} |
596 |
|
|
catch (LinuxSamplerException e) { |
597 |
senkov |
120 |
result.Error(e); |
598 |
schoenebeck |
53 |
} |
599 |
senkov |
120 |
return result.Produce(); |
600 |
schoenebeck |
35 |
} |
601 |
|
|
|
602 |
|
|
/** |
603 |
|
|
* Will be called by the parser to get informations about a particular |
604 |
|
|
* sampler channel. |
605 |
|
|
*/ |
606 |
schoenebeck |
53 |
String LSCPServer::GetChannelInfo(uint uiSamplerChannel) { |
607 |
|
|
dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", uiSamplerChannel)); |
608 |
senkov |
120 |
LSCPResultSet result; |
609 |
senkov |
113 |
try { |
610 |
|
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
611 |
schoenebeck |
374 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
612 |
schoenebeck |
411 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
613 |
schoenebeck |
123 |
|
614 |
senkov |
117 |
//Defaults values |
615 |
|
|
String EngineName = "NONE"; |
616 |
schoenebeck |
225 |
float Volume = 0.0f; |
617 |
senkov |
117 |
String InstrumentFileName = "NONE"; |
618 |
senkov |
376 |
String InstrumentName = "NONE"; |
619 |
capela |
133 |
int InstrumentIndex = -1; |
620 |
|
|
int InstrumentStatus = -1; |
621 |
schoenebeck |
225 |
int AudioOutputChannels = 0; |
622 |
|
|
String AudioRouting; |
623 |
schoenebeck |
123 |
|
624 |
schoenebeck |
475 |
if (pEngineChannel) { |
625 |
|
|
EngineName = pEngineChannel->EngineName(); |
626 |
schoenebeck |
411 |
AudioOutputChannels = pEngineChannel->Channels(); |
627 |
|
|
Volume = pEngineChannel->Volume(); |
628 |
|
|
InstrumentStatus = pEngineChannel->InstrumentStatus(); |
629 |
|
|
InstrumentIndex = pEngineChannel->InstrumentIndex(); |
630 |
|
|
if (InstrumentIndex != -1) { |
631 |
|
|
InstrumentFileName = pEngineChannel->InstrumentFileName(); |
632 |
|
|
InstrumentName = pEngineChannel->InstrumentName(); |
633 |
|
|
} |
634 |
|
|
for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { |
635 |
schoenebeck |
225 |
if (AudioRouting != "") AudioRouting += ","; |
636 |
schoenebeck |
411 |
AudioRouting += ToString(pEngineChannel->OutputChannel(chan)); |
637 |
schoenebeck |
225 |
} |
638 |
senkov |
113 |
} |
639 |
senkov |
117 |
|
640 |
|
|
result.Add("ENGINE_NAME", EngineName); |
641 |
|
|
result.Add("VOLUME", Volume); |
642 |
|
|
|
643 |
capela |
143 |
//Some not-so-hardcoded stuff to make GUI look good |
644 |
|
|
result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice())); |
645 |
schoenebeck |
225 |
result.Add("AUDIO_OUTPUT_CHANNELS", AudioOutputChannels); |
646 |
|
|
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
647 |
senkov |
113 |
|
648 |
capela |
159 |
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
649 |
|
|
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
650 |
schoenebeck |
274 |
if (pSamplerChannel->GetMidiInputChannel() == MidiInputPort::midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
651 |
|
|
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
652 |
capela |
159 |
|
653 |
senkov |
117 |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
654 |
|
|
result.Add("INSTRUMENT_NR", InstrumentIndex); |
655 |
senkov |
376 |
result.Add("INSTRUMENT_NAME", InstrumentName); |
656 |
capela |
133 |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
657 |
senkov |
113 |
} |
658 |
|
|
catch (LinuxSamplerException e) { |
659 |
senkov |
120 |
result.Error(e); |
660 |
senkov |
113 |
} |
661 |
senkov |
120 |
return result.Produce(); |
662 |
schoenebeck |
35 |
} |
663 |
|
|
|
664 |
|
|
/** |
665 |
|
|
* Will be called by the parser to get the amount of active voices on a |
666 |
|
|
* particular sampler channel. |
667 |
|
|
*/ |
668 |
schoenebeck |
53 |
String LSCPServer::GetVoiceCount(uint uiSamplerChannel) { |
669 |
|
|
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
670 |
senkov |
120 |
LSCPResultSet result; |
671 |
schoenebeck |
53 |
try { |
672 |
|
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
673 |
schoenebeck |
374 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
674 |
schoenebeck |
411 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
675 |
|
|
if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel"); |
676 |
schoenebeck |
620 |
if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); |
677 |
schoenebeck |
411 |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
678 |
schoenebeck |
53 |
} |
679 |
|
|
catch (LinuxSamplerException e) { |
680 |
senkov |
120 |
result.Error(e); |
681 |
schoenebeck |
53 |
} |
682 |
senkov |
120 |
return result.Produce(); |
683 |
schoenebeck |
35 |
} |
684 |
|
|
|
685 |
|
|
/** |
686 |
|
|
* Will be called by the parser to get the amount of active disk streams on a |
687 |
|
|
* particular sampler channel. |
688 |
|
|
*/ |
689 |
schoenebeck |
53 |
String LSCPServer::GetStreamCount(uint uiSamplerChannel) { |
690 |
|
|
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
691 |
senkov |
120 |
LSCPResultSet result; |
692 |
schoenebeck |
53 |
try { |
693 |
|
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
694 |
schoenebeck |
374 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
695 |
schoenebeck |
411 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
696 |
|
|
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
697 |
schoenebeck |
620 |
if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); |
698 |
schoenebeck |
411 |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
699 |
schoenebeck |
53 |
} |
700 |
|
|
catch (LinuxSamplerException e) { |
701 |
senkov |
120 |
result.Error(e); |
702 |
schoenebeck |
53 |
} |
703 |
senkov |
120 |
return result.Produce(); |
704 |
schoenebeck |
35 |
} |
705 |
|
|
|
706 |
|
|
/** |
707 |
|
|
* Will be called by the parser to get the buffer fill states of all disk |
708 |
|
|
* streams on a particular sampler channel. |
709 |
|
|
*/ |
710 |
schoenebeck |
53 |
String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel) { |
711 |
|
|
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); |
712 |
senkov |
120 |
LSCPResultSet result; |
713 |
schoenebeck |
53 |
try { |
714 |
|
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
715 |
schoenebeck |
374 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
716 |
schoenebeck |
411 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
717 |
|
|
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
718 |
schoenebeck |
620 |
if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); |
719 |
schoenebeck |
411 |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
720 |
senkov |
129 |
else { |
721 |
|
|
switch (ResponseType) { |
722 |
|
|
case fill_response_bytes: |
723 |
schoenebeck |
411 |
result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillBytes()); |
724 |
|
|
break; |
725 |
senkov |
129 |
case fill_response_percentage: |
726 |
schoenebeck |
411 |
result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage()); |
727 |
|
|
break; |
728 |
senkov |
129 |
default: |
729 |
|
|
throw LinuxSamplerException("Unknown fill response type"); |
730 |
|
|
} |
731 |
|
|
} |
732 |
schoenebeck |
53 |
} |
733 |
|
|
catch (LinuxSamplerException e) { |
734 |
senkov |
120 |
result.Error(e); |
735 |
schoenebeck |
53 |
} |
736 |
senkov |
120 |
return result.Produce(); |
737 |
schoenebeck |
35 |
} |
738 |
|
|
|
739 |
schoenebeck |
123 |
String LSCPServer::GetAvailableAudioOutputDrivers() { |
740 |
|
|
dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n")); |
741 |
senkov |
120 |
LSCPResultSet result; |
742 |
schoenebeck |
53 |
try { |
743 |
capela |
527 |
int n = AudioOutputDeviceFactory::AvailableDrivers().size(); |
744 |
|
|
result.Add(n); |
745 |
|
|
} |
746 |
|
|
catch (LinuxSamplerException e) { |
747 |
|
|
result.Error(e); |
748 |
|
|
} |
749 |
|
|
return result.Produce(); |
750 |
|
|
} |
751 |
|
|
|
752 |
|
|
String LSCPServer::ListAvailableAudioOutputDrivers() { |
753 |
|
|
dmsg(2,("LSCPServer: ListAvailableAudioOutputDrivers()\n")); |
754 |
|
|
LSCPResultSet result; |
755 |
|
|
try { |
756 |
schoenebeck |
123 |
String s = AudioOutputDeviceFactory::AvailableDriversAsString(); |
757 |
|
|
result.Add(s); |
758 |
schoenebeck |
53 |
} |
759 |
|
|
catch (LinuxSamplerException e) { |
760 |
schoenebeck |
123 |
result.Error(e); |
761 |
schoenebeck |
53 |
} |
762 |
senkov |
120 |
return result.Produce(); |
763 |
schoenebeck |
35 |
} |
764 |
|
|
|
765 |
senkov |
155 |
String LSCPServer::GetAvailableMidiInputDrivers() { |
766 |
|
|
dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n")); |
767 |
|
|
LSCPResultSet result; |
768 |
|
|
try { |
769 |
capela |
527 |
int n = MidiInputDeviceFactory::AvailableDrivers().size(); |
770 |
|
|
result.Add(n); |
771 |
|
|
} |
772 |
|
|
catch (LinuxSamplerException e) { |
773 |
|
|
result.Error(e); |
774 |
|
|
} |
775 |
|
|
return result.Produce(); |
776 |
|
|
} |
777 |
|
|
|
778 |
|
|
String LSCPServer::ListAvailableMidiInputDrivers() { |
779 |
|
|
dmsg(2,("LSCPServer: ListAvailableMidiInputDrivers()\n")); |
780 |
|
|
LSCPResultSet result; |
781 |
|
|
try { |
782 |
senkov |
155 |
String s = MidiInputDeviceFactory::AvailableDriversAsString(); |
783 |
|
|
result.Add(s); |
784 |
|
|
} |
785 |
|
|
catch (LinuxSamplerException e) { |
786 |
|
|
result.Error(e); |
787 |
|
|
} |
788 |
|
|
return result.Produce(); |
789 |
|
|
} |
790 |
|
|
|
791 |
|
|
String LSCPServer::GetMidiInputDriverInfo(String Driver) { |
792 |
|
|
dmsg(2,("LSCPServer: GetMidiInputDriverInfo(Driver=%s)\n",Driver.c_str())); |
793 |
|
|
LSCPResultSet result; |
794 |
|
|
try { |
795 |
|
|
result.Add("DESCRIPTION", MidiInputDeviceFactory::GetDriverDescription(Driver)); |
796 |
|
|
result.Add("VERSION", MidiInputDeviceFactory::GetDriverVersion(Driver)); |
797 |
|
|
|
798 |
|
|
std::map<String,DeviceCreationParameter*> parameters = MidiInputDeviceFactory::GetAvailableDriverParameters(Driver); |
799 |
|
|
if (parameters.size()) { // if there are parameters defined for this driver |
800 |
|
|
String s; |
801 |
|
|
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
802 |
|
|
for (;iter != parameters.end(); iter++) { |
803 |
|
|
if (s != "") s += ","; |
804 |
|
|
s += iter->first; |
805 |
|
|
} |
806 |
|
|
result.Add("PARAMETERS", s); |
807 |
|
|
} |
808 |
|
|
} |
809 |
|
|
catch (LinuxSamplerException e) { |
810 |
|
|
result.Error(e); |
811 |
|
|
} |
812 |
|
|
return result.Produce(); |
813 |
|
|
} |
814 |
|
|
|
815 |
schoenebeck |
123 |
String LSCPServer::GetAudioOutputDriverInfo(String Driver) { |
816 |
|
|
dmsg(2,("LSCPServer: GetAudioOutputDriverInfo(Driver=%s)\n",Driver.c_str())); |
817 |
|
|
LSCPResultSet result; |
818 |
|
|
try { |
819 |
|
|
result.Add("DESCRIPTION", AudioOutputDeviceFactory::GetDriverDescription(Driver)); |
820 |
|
|
result.Add("VERSION", AudioOutputDeviceFactory::GetDriverVersion(Driver)); |
821 |
|
|
|
822 |
|
|
std::map<String,DeviceCreationParameter*> parameters = AudioOutputDeviceFactory::GetAvailableDriverParameters(Driver); |
823 |
|
|
if (parameters.size()) { // if there are parameters defined for this driver |
824 |
|
|
String s; |
825 |
|
|
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
826 |
|
|
for (;iter != parameters.end(); iter++) { |
827 |
|
|
if (s != "") s += ","; |
828 |
|
|
s += iter->first; |
829 |
|
|
} |
830 |
|
|
result.Add("PARAMETERS", s); |
831 |
|
|
} |
832 |
|
|
} |
833 |
|
|
catch (LinuxSamplerException e) { |
834 |
|
|
result.Error(e); |
835 |
|
|
} |
836 |
|
|
return result.Produce(); |
837 |
|
|
} |
838 |
|
|
|
839 |
senkov |
155 |
String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
840 |
schoenebeck |
226 |
dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size())); |
841 |
senkov |
155 |
LSCPResultSet result; |
842 |
|
|
try { |
843 |
|
|
DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter); |
844 |
|
|
result.Add("TYPE", pParameter->Type()); |
845 |
|
|
result.Add("DESCRIPTION", pParameter->Description()); |
846 |
schoenebeck |
223 |
result.Add("MANDATORY", pParameter->Mandatory()); |
847 |
|
|
result.Add("FIX", pParameter->Fix()); |
848 |
|
|
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
849 |
schoenebeck |
226 |
optional<String> oDepends = pParameter->Depends(); |
850 |
|
|
optional<String> oDefault = pParameter->Default(DependencyList); |
851 |
|
|
optional<String> oRangeMin = pParameter->RangeMin(DependencyList); |
852 |
|
|
optional<String> oRangeMax = pParameter->RangeMax(DependencyList); |
853 |
|
|
optional<String> oPossibilities = pParameter->Possibilities(DependencyList); |
854 |
|
|
if (oDepends) result.Add("DEPENDS", *oDepends); |
855 |
|
|
if (oDefault) result.Add("DEFAULT", *oDefault); |
856 |
|
|
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
857 |
|
|
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
858 |
|
|
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
859 |
senkov |
155 |
} |
860 |
|
|
catch (LinuxSamplerException e) { |
861 |
|
|
result.Error(e); |
862 |
|
|
} |
863 |
|
|
return result.Produce(); |
864 |
|
|
} |
865 |
|
|
|
866 |
schoenebeck |
123 |
String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
867 |
schoenebeck |
226 |
dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size())); |
868 |
schoenebeck |
123 |
LSCPResultSet result; |
869 |
|
|
try { |
870 |
|
|
DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter); |
871 |
|
|
result.Add("TYPE", pParameter->Type()); |
872 |
|
|
result.Add("DESCRIPTION", pParameter->Description()); |
873 |
schoenebeck |
223 |
result.Add("MANDATORY", pParameter->Mandatory()); |
874 |
|
|
result.Add("FIX", pParameter->Fix()); |
875 |
|
|
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
876 |
schoenebeck |
226 |
optional<String> oDepends = pParameter->Depends(); |
877 |
|
|
optional<String> oDefault = pParameter->Default(DependencyList); |
878 |
|
|
optional<String> oRangeMin = pParameter->RangeMin(DependencyList); |
879 |
|
|
optional<String> oRangeMax = pParameter->RangeMax(DependencyList); |
880 |
|
|
optional<String> oPossibilities = pParameter->Possibilities(DependencyList); |
881 |
|
|
if (oDepends) result.Add("DEPENDS", *oDepends); |
882 |
|
|
if (oDefault) result.Add("DEFAULT", *oDefault); |
883 |
|
|
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
884 |
|
|
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
885 |
|
|
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
886 |
schoenebeck |
123 |
} |
887 |
|
|
catch (LinuxSamplerException e) { |
888 |
|
|
result.Error(e); |
889 |
|
|
} |
890 |
|
|
return result.Produce(); |
891 |
|
|
} |
892 |
|
|
|
893 |
|
|
String LSCPServer::GetAudioOutputDeviceCount() { |
894 |
|
|
dmsg(2,("LSCPServer: GetAudioOutputDeviceCount()\n")); |
895 |
|
|
LSCPResultSet result; |
896 |
|
|
try { |
897 |
|
|
uint count = pSampler->AudioOutputDevices(); |
898 |
senkov |
138 |
result.Add(count); // success |
899 |
schoenebeck |
123 |
} |
900 |
|
|
catch (LinuxSamplerException e) { |
901 |
|
|
result.Error(e); |
902 |
|
|
} |
903 |
|
|
return result.Produce(); |
904 |
|
|
} |
905 |
|
|
|
906 |
senkov |
155 |
String LSCPServer::GetMidiInputDeviceCount() { |
907 |
|
|
dmsg(2,("LSCPServer: GetMidiInputDeviceCount()\n")); |
908 |
|
|
LSCPResultSet result; |
909 |
|
|
try { |
910 |
|
|
uint count = pSampler->MidiInputDevices(); |
911 |
|
|
result.Add(count); // success |
912 |
|
|
} |
913 |
|
|
catch (LinuxSamplerException e) { |
914 |
|
|
result.Error(e); |
915 |
|
|
} |
916 |
|
|
return result.Produce(); |
917 |
|
|
} |
918 |
|
|
|
919 |
schoenebeck |
123 |
String LSCPServer::GetAudioOutputDevices() { |
920 |
|
|
dmsg(2,("LSCPServer: GetAudioOutputDevices()\n")); |
921 |
|
|
LSCPResultSet result; |
922 |
|
|
try { |
923 |
|
|
String s; |
924 |
|
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
925 |
|
|
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
926 |
|
|
for (; iter != devices.end(); iter++) { |
927 |
|
|
if (s != "") s += ","; |
928 |
|
|
s += ToString(iter->first); |
929 |
|
|
} |
930 |
|
|
result.Add(s); |
931 |
|
|
} |
932 |
|
|
catch (LinuxSamplerException e) { |
933 |
|
|
result.Error(e); |
934 |
|
|
} |
935 |
|
|
return result.Produce(); |
936 |
|
|
} |
937 |
|
|
|
938 |
senkov |
155 |
String LSCPServer::GetMidiInputDevices() { |
939 |
|
|
dmsg(2,("LSCPServer: GetMidiInputDevices()\n")); |
940 |
|
|
LSCPResultSet result; |
941 |
|
|
try { |
942 |
|
|
String s; |
943 |
|
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
944 |
|
|
std::map<uint, MidiInputDevice*>::iterator iter = devices.begin(); |
945 |
|
|
for (; iter != devices.end(); iter++) { |
946 |
|
|
if (s != "") s += ","; |
947 |
|
|
s += ToString(iter->first); |
948 |
|
|
} |
949 |
|
|
result.Add(s); |
950 |
|
|
} |
951 |
|
|
catch (LinuxSamplerException e) { |
952 |
|
|
result.Error(e); |
953 |
|
|
} |
954 |
|
|
return result.Produce(); |
955 |
|
|
} |
956 |
|
|
|
957 |
schoenebeck |
123 |
String LSCPServer::GetAudioOutputDeviceInfo(uint DeviceIndex) { |
958 |
|
|
dmsg(2,("LSCPServer: GetAudioOutputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex)); |
959 |
|
|
LSCPResultSet result; |
960 |
|
|
try { |
961 |
|
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
962 |
schoenebeck |
223 |
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
963 |
schoenebeck |
123 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
964 |
schoenebeck |
221 |
result.Add("DRIVER", pDevice->Driver()); |
965 |
schoenebeck |
123 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
966 |
|
|
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
967 |
|
|
for (; iter != parameters.end(); iter++) { |
968 |
|
|
result.Add(iter->first, iter->second->Value()); |
969 |
|
|
} |
970 |
|
|
} |
971 |
|
|
catch (LinuxSamplerException e) { |
972 |
|
|
result.Error(e); |
973 |
|
|
} |
974 |
|
|
return result.Produce(); |
975 |
|
|
} |
976 |
|
|
|
977 |
senkov |
155 |
String LSCPServer::GetMidiInputDeviceInfo(uint DeviceIndex) { |
978 |
|
|
dmsg(2,("LSCPServer: GetMidiInputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex)); |
979 |
|
|
LSCPResultSet result; |
980 |
|
|
try { |
981 |
|
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
982 |
schoenebeck |
223 |
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
983 |
senkov |
155 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
984 |
schoenebeck |
221 |
result.Add("DRIVER", pDevice->Driver()); |
985 |
senkov |
155 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
986 |
|
|
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
987 |
|
|
for (; iter != parameters.end(); iter++) { |
988 |
|
|
result.Add(iter->first, iter->second->Value()); |
989 |
|
|
} |
990 |
|
|
} |
991 |
|
|
catch (LinuxSamplerException e) { |
992 |
|
|
result.Error(e); |
993 |
|
|
} |
994 |
|
|
return result.Produce(); |
995 |
|
|
} |
996 |
|
|
String LSCPServer::GetMidiInputPortInfo(uint DeviceIndex, uint PortIndex) { |
997 |
|
|
dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex)); |
998 |
|
|
LSCPResultSet result; |
999 |
|
|
try { |
1000 |
schoenebeck |
223 |
// get MIDI input device |
1001 |
senkov |
155 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1002 |
schoenebeck |
223 |
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
1003 |
senkov |
155 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
1004 |
schoenebeck |
223 |
|
1005 |
|
|
// get MIDI port |
1006 |
schoenebeck |
221 |
MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
1007 |
|
|
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
1008 |
schoenebeck |
223 |
|
1009 |
|
|
// return the values of all MIDI port parameters |
1010 |
schoenebeck |
221 |
std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters(); |
1011 |
|
|
std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin(); |
1012 |
senkov |
155 |
for (; iter != parameters.end(); iter++) { |
1013 |
|
|
result.Add(iter->first, iter->second->Value()); |
1014 |
|
|
} |
1015 |
|
|
} |
1016 |
|
|
catch (LinuxSamplerException e) { |
1017 |
|
|
result.Error(e); |
1018 |
|
|
} |
1019 |
|
|
return result.Produce(); |
1020 |
|
|
} |
1021 |
|
|
|
1022 |
schoenebeck |
123 |
String LSCPServer::GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId) { |
1023 |
|
|
dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%d,ChannelId)\n",DeviceId,ChannelId)); |
1024 |
|
|
LSCPResultSet result; |
1025 |
|
|
try { |
1026 |
|
|
// get audio output device |
1027 |
|
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1028 |
schoenebeck |
223 |
if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); |
1029 |
schoenebeck |
123 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
1030 |
|
|
|
1031 |
|
|
// get audio channel |
1032 |
|
|
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1033 |
schoenebeck |
374 |
if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + "."); |
1034 |
schoenebeck |
123 |
|
1035 |
|
|
// return the values of all audio channel parameters |
1036 |
|
|
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1037 |
|
|
std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin(); |
1038 |
|
|
for (; iter != parameters.end(); iter++) { |
1039 |
|
|
result.Add(iter->first, iter->second->Value()); |
1040 |
|
|
} |
1041 |
|
|
} |
1042 |
|
|
catch (LinuxSamplerException e) { |
1043 |
|
|
result.Error(e); |
1044 |
|
|
} |
1045 |
|
|
return result.Produce(); |
1046 |
|
|
} |
1047 |
|
|
|
1048 |
senkov |
185 |
String LSCPServer::GetMidiInputPortParameterInfo(uint DeviceId, uint PortId, String ParameterName) { |
1049 |
|
|
dmsg(2,("LSCPServer: GetMidiInputPortParameterInfo(DeviceId=%d,PortId=%d,ParameterName=%s)\n",DeviceId,PortId,ParameterName.c_str())); |
1050 |
|
|
LSCPResultSet result; |
1051 |
|
|
try { |
1052 |
schoenebeck |
223 |
// get MIDI input device |
1053 |
|
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1054 |
|
|
if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + "."); |
1055 |
|
|
MidiInputDevice* pDevice = devices[DeviceId]; |
1056 |
senkov |
185 |
|
1057 |
schoenebeck |
221 |
// get midi port |
1058 |
|
|
MidiInputPort* pPort = pDevice->GetPort(PortId); |
1059 |
|
|
if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + "."); |
1060 |
senkov |
185 |
|
1061 |
schoenebeck |
223 |
// get desired port parameter |
1062 |
|
|
std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters(); |
1063 |
|
|
if (!parameters.count(ParameterName)) throw LinuxSamplerException("Midi port does not provide a parameter '" + ParameterName + "'."); |
1064 |
|
|
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
1065 |
schoenebeck |
203 |
|
1066 |
senkov |
185 |
// return all fields of this audio channel parameter |
1067 |
|
|
result.Add("TYPE", pParameter->Type()); |
1068 |
|
|
result.Add("DESCRIPTION", pParameter->Description()); |
1069 |
|
|
result.Add("FIX", pParameter->Fix()); |
1070 |
|
|
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
1071 |
schoenebeck |
223 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
1072 |
|
|
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
1073 |
|
|
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
1074 |
senkov |
185 |
} |
1075 |
|
|
catch (LinuxSamplerException e) { |
1076 |
|
|
result.Error(e); |
1077 |
|
|
} |
1078 |
|
|
return result.Produce(); |
1079 |
|
|
} |
1080 |
|
|
|
1081 |
schoenebeck |
123 |
String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) { |
1082 |
|
|
dmsg(2,("LSCPServer: GetAudioOutputChannelParameterInfo(DeviceId=%d,ChannelId=%d,ParameterName=%s)\n",DeviceId,ChannelId,ParameterName.c_str())); |
1083 |
|
|
LSCPResultSet result; |
1084 |
|
|
try { |
1085 |
|
|
// get audio output device |
1086 |
|
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1087 |
schoenebeck |
223 |
if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); |
1088 |
schoenebeck |
123 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
1089 |
|
|
|
1090 |
|
|
// get audio channel |
1091 |
|
|
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1092 |
schoenebeck |
374 |
if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + "."); |
1093 |
schoenebeck |
123 |
|
1094 |
|
|
// get desired audio channel parameter |
1095 |
|
|
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1096 |
schoenebeck |
223 |
if (!parameters.count(ParameterName)) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'."); |
1097 |
schoenebeck |
123 |
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
1098 |
|
|
|
1099 |
|
|
// return all fields of this audio channel parameter |
1100 |
|
|
result.Add("TYPE", pParameter->Type()); |
1101 |
|
|
result.Add("DESCRIPTION", pParameter->Description()); |
1102 |
|
|
result.Add("FIX", pParameter->Fix()); |
1103 |
|
|
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
1104 |
schoenebeck |
223 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
1105 |
|
|
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
1106 |
|
|
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
1107 |
schoenebeck |
123 |
} |
1108 |
|
|
catch (LinuxSamplerException e) { |
1109 |
|
|
result.Error(e); |
1110 |
|
|
} |
1111 |
|
|
return result.Produce(); |
1112 |
|
|
} |
1113 |
|
|
|
1114 |
|
|
String LSCPServer::SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal) { |
1115 |
|
|
dmsg(2,("LSCPServer: SetAudioOutputChannelParameter(DeviceId=%d,ChannelId=%d,ParamKey=%s,ParamVal=%s)\n",DeviceId,ChannelId,ParamKey.c_str(),ParamVal.c_str())); |
1116 |
|
|
LSCPResultSet result; |
1117 |
|
|
try { |
1118 |
|
|
// get audio output device |
1119 |
|
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1120 |
schoenebeck |
223 |
if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); |
1121 |
schoenebeck |
123 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
1122 |
|
|
|
1123 |
|
|
// get audio channel |
1124 |
|
|
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1125 |
schoenebeck |
374 |
if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + "."); |
1126 |
schoenebeck |
123 |
|
1127 |
|
|
// get desired audio channel parameter |
1128 |
|
|
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1129 |
schoenebeck |
223 |
if (!parameters.count(ParamKey)) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'."); |
1130 |
schoenebeck |
123 |
DeviceRuntimeParameter* pParameter = parameters[ParamKey]; |
1131 |
|
|
|
1132 |
|
|
// set new channel parameter value |
1133 |
|
|
pParameter->SetValue(ParamVal); |
1134 |
|
|
} |
1135 |
|
|
catch (LinuxSamplerException e) { |
1136 |
|
|
result.Error(e); |
1137 |
|
|
} |
1138 |
|
|
return result.Produce(); |
1139 |
|
|
} |
1140 |
|
|
|
1141 |
|
|
String LSCPServer::SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal) { |
1142 |
|
|
dmsg(2,("LSCPServer: SetAudioOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str())); |
1143 |
|
|
LSCPResultSet result; |
1144 |
|
|
try { |
1145 |
|
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1146 |
schoenebeck |
223 |
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
1147 |
schoenebeck |
123 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
1148 |
|
|
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1149 |
schoenebeck |
223 |
if (!parameters.count(ParamKey)) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
1150 |
schoenebeck |
123 |
parameters[ParamKey]->SetValue(ParamVal); |
1151 |
|
|
} |
1152 |
|
|
catch (LinuxSamplerException e) { |
1153 |
|
|
result.Error(e); |
1154 |
|
|
} |
1155 |
|
|
return result.Produce(); |
1156 |
|
|
} |
1157 |
|
|
|
1158 |
senkov |
155 |
String LSCPServer::SetMidiInputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal) { |
1159 |
|
|
dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str())); |
1160 |
|
|
LSCPResultSet result; |
1161 |
|
|
try { |
1162 |
|
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1163 |
schoenebeck |
223 |
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
1164 |
senkov |
155 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
1165 |
|
|
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1166 |
schoenebeck |
223 |
if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
1167 |
senkov |
155 |
parameters[ParamKey]->SetValue(ParamVal); |
1168 |
|
|
} |
1169 |
|
|
catch (LinuxSamplerException e) { |
1170 |
|
|
result.Error(e); |
1171 |
|
|
} |
1172 |
|
|
return result.Produce(); |
1173 |
|
|
} |
1174 |
|
|
|
1175 |
|
|
String LSCPServer::SetMidiInputPortParameter(uint DeviceIndex, uint PortIndex, String ParamKey, String ParamVal) { |
1176 |
|
|
dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str())); |
1177 |
|
|
LSCPResultSet result; |
1178 |
|
|
try { |
1179 |
schoenebeck |
223 |
// get MIDI input device |
1180 |
senkov |
155 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1181 |
schoenebeck |
223 |
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
1182 |
senkov |
155 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
1183 |
schoenebeck |
223 |
|
1184 |
|
|
// get MIDI port |
1185 |
schoenebeck |
221 |
MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
1186 |
|
|
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
1187 |
schoenebeck |
223 |
|
1188 |
|
|
// set port parameter value |
1189 |
schoenebeck |
221 |
std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters(); |
1190 |
schoenebeck |
223 |
if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); |
1191 |
senkov |
155 |
parameters[ParamKey]->SetValue(ParamVal); |
1192 |
|
|
} |
1193 |
|
|
catch (LinuxSamplerException e) { |
1194 |
|
|
result.Error(e); |
1195 |
|
|
} |
1196 |
|
|
return result.Produce(); |
1197 |
|
|
} |
1198 |
|
|
|
1199 |
schoenebeck |
35 |
/** |
1200 |
|
|
* Will be called by the parser to change the audio output channel for |
1201 |
|
|
* playback on a particular sampler channel. |
1202 |
|
|
*/ |
1203 |
schoenebeck |
123 |
String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) { |
1204 |
|
|
dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel)); |
1205 |
schoenebeck |
225 |
LSCPResultSet result; |
1206 |
|
|
try { |
1207 |
|
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1208 |
schoenebeck |
374 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1209 |
schoenebeck |
411 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1210 |
|
|
if (!pEngineChannel) throw LinuxSamplerException("No engine type yet assigned to sampler channel " + ToString(uiSamplerChannel)); |
1211 |
schoenebeck |
374 |
if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel)); |
1212 |
schoenebeck |
411 |
pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
1213 |
schoenebeck |
225 |
} |
1214 |
|
|
catch (LinuxSamplerException e) { |
1215 |
|
|
result.Error(e); |
1216 |
|
|
} |
1217 |
|
|
return result.Produce(); |
1218 |
schoenebeck |
35 |
} |
1219 |
|
|
|
1220 |
capela |
159 |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
1221 |
|
|
dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel)); |
1222 |
|
|
LSCPResultSet result; |
1223 |
|
|
try { |
1224 |
|
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1225 |
schoenebeck |
374 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1226 |
capela |
159 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1227 |
schoenebeck |
223 |
if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId)); |
1228 |
capela |
159 |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
1229 |
|
|
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1230 |
|
|
} |
1231 |
|
|
catch (LinuxSamplerException e) { |
1232 |
|
|
result.Error(e); |
1233 |
|
|
} |
1234 |
|
|
return result.Produce(); |
1235 |
|
|
} |
1236 |
|
|
|
1237 |
capela |
143 |
String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) { |
1238 |
|
|
dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel)); |
1239 |
|
|
LSCPResultSet result; |
1240 |
|
|
try { |
1241 |
|
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1242 |
schoenebeck |
374 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1243 |
capela |
143 |
// Driver type name aliasing... |
1244 |
schoenebeck |
226 |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
1245 |
|
|
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
1246 |
capela |
143 |
// Check if there's one audio output device already created |
1247 |
|
|
// for the intended audio driver type (AudioOutputDriver)... |
1248 |
|
|
AudioOutputDevice *pDevice = NULL; |
1249 |
|
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1250 |
|
|
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
1251 |
|
|
for (; iter != devices.end(); iter++) { |
1252 |
|
|
if ((iter->second)->Driver() == AudioOutputDriver) { |
1253 |
|
|
pDevice = iter->second; |
1254 |
|
|
break; |
1255 |
|
|
} |
1256 |
|
|
} |
1257 |
|
|
// If it doesn't exist, create a new one with default parameters... |
1258 |
|
|
if (pDevice == NULL) { |
1259 |
|
|
std::map<String,String> params; |
1260 |
|
|
pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params); |
1261 |
|
|
} |
1262 |
|
|
// Must have a device... |
1263 |
|
|
if (pDevice == NULL) |
1264 |
|
|
throw LinuxSamplerException("Internal error: could not create audio output device."); |
1265 |
|
|
// Set it as the current channel device... |
1266 |
|
|
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1267 |
|
|
} |
1268 |
|
|
catch (LinuxSamplerException e) { |
1269 |
|
|
result.Error(e); |
1270 |
|
|
} |
1271 |
|
|
return result.Produce(); |
1272 |
|
|
} |
1273 |
|
|
|
1274 |
capela |
159 |
String LSCPServer::SetMIDIInputPort(uint MIDIPort, uint uiSamplerChannel) { |
1275 |
|
|
dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIPort=%d, SamplerChannel=%d)\n",MIDIPort,uiSamplerChannel)); |
1276 |
senkov |
120 |
LSCPResultSet result; |
1277 |
schoenebeck |
53 |
try { |
1278 |
|
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1279 |
schoenebeck |
374 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1280 |
capela |
159 |
pSamplerChannel->SetMidiInputPort(MIDIPort); |
1281 |
schoenebeck |
53 |
} |
1282 |
|
|
catch (LinuxSamplerException e) { |
1283 |
senkov |
120 |
result.Error(e); |
1284 |
schoenebeck |
53 |
} |
1285 |
senkov |
120 |
return result.Produce(); |
1286 |
schoenebeck |
53 |
} |
1287 |
|
|
|
1288 |
capela |
159 |
String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) { |
1289 |
|
|
dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n",MIDIChannel,uiSamplerChannel)); |
1290 |
senkov |
120 |
LSCPResultSet result; |
1291 |
senkov |
68 |
try { |
1292 |
|
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1293 |
schoenebeck |
374 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1294 |
schoenebeck |
221 |
pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); |
1295 |
senkov |
68 |
} |
1296 |
|
|
catch (LinuxSamplerException e) { |
1297 |
senkov |
120 |
result.Error(e); |
1298 |
senkov |
68 |
} |
1299 |
senkov |
120 |
return result.Produce(); |
1300 |
schoenebeck |
35 |
} |
1301 |
|
|
|
1302 |
capela |
159 |
String LSCPServer::SetMIDIInputDevice(uint MIDIDeviceId, uint uiSamplerChannel) { |
1303 |
|
|
dmsg(2,("LSCPServer: SetMIDIInputDevice(MIDIDeviceId=%d, SamplerChannel=%d)\n",MIDIDeviceId,uiSamplerChannel)); |
1304 |
schoenebeck |
123 |
LSCPResultSet result; |
1305 |
|
|
try { |
1306 |
capela |
159 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1307 |
schoenebeck |
374 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1308 |
capela |
159 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1309 |
schoenebeck |
223 |
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1310 |
capela |
159 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1311 |
|
|
pSamplerChannel->SetMidiInputDevice(pDevice); |
1312 |
schoenebeck |
123 |
} |
1313 |
|
|
catch (LinuxSamplerException e) { |
1314 |
|
|
result.Error(e); |
1315 |
|
|
} |
1316 |
|
|
return result.Produce(); |
1317 |
|
|
} |
1318 |
|
|
|
1319 |
capela |
159 |
String LSCPServer::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) { |
1320 |
|
|
dmsg(2,("LSCPServer: SetMIDIInputType(String MidiInputDriver=%s, SamplerChannel=%d)\n",MidiInputDriver.c_str(),uiSamplerChannel)); |
1321 |
|
|
LSCPResultSet result; |
1322 |
|
|
try { |
1323 |
|
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1324 |
schoenebeck |
374 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1325 |
capela |
159 |
// Driver type name aliasing... |
1326 |
schoenebeck |
226 |
if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; |
1327 |
capela |
159 |
// Check if there's one MIDI input device already created |
1328 |
|
|
// for the intended MIDI driver type (MidiInputDriver)... |
1329 |
|
|
MidiInputDevice *pDevice = NULL; |
1330 |
|
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1331 |
|
|
std::map<uint, MidiInputDevice*>::iterator iter = devices.begin(); |
1332 |
|
|
for (; iter != devices.end(); iter++) { |
1333 |
|
|
if ((iter->second)->Driver() == MidiInputDriver) { |
1334 |
|
|
pDevice = iter->second; |
1335 |
|
|
break; |
1336 |
|
|
} |
1337 |
|
|
} |
1338 |
|
|
// If it doesn't exist, create a new one with default parameters... |
1339 |
|
|
if (pDevice == NULL) { |
1340 |
|
|
std::map<String,String> params; |
1341 |
|
|
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
1342 |
|
|
// Make it with at least one initial port. |
1343 |
|
|
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1344 |
schoenebeck |
221 |
parameters["PORTS"]->SetValue("1"); |
1345 |
capela |
159 |
} |
1346 |
|
|
// Must have a device... |
1347 |
|
|
if (pDevice == NULL) |
1348 |
|
|
throw LinuxSamplerException("Internal error: could not create MIDI input device."); |
1349 |
|
|
// Set it as the current channel device... |
1350 |
|
|
pSamplerChannel->SetMidiInputDevice(pDevice); |
1351 |
|
|
} |
1352 |
|
|
catch (LinuxSamplerException e) { |
1353 |
|
|
result.Error(e); |
1354 |
|
|
} |
1355 |
|
|
return result.Produce(); |
1356 |
|
|
} |
1357 |
|
|
|
1358 |
schoenebeck |
35 |
/** |
1359 |
capela |
159 |
* Will be called by the parser to change the MIDI input device, port and channel on which |
1360 |
|
|
* engine of a particular sampler channel should listen to. |
1361 |
|
|
*/ |
1362 |
|
|
String LSCPServer::SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel) { |
1363 |
|
|
dmsg(2,("LSCPServer: SetMIDIInput(MIDIDeviceId=%d, MIDIPort=%d, MIDIChannel=%d, SamplerChannel=%d)\n", MIDIDeviceId, MIDIPort, MIDIChannel, uiSamplerChannel)); |
1364 |
|
|
LSCPResultSet result; |
1365 |
|
|
try { |
1366 |
|
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1367 |
schoenebeck |
374 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1368 |
capela |
159 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1369 |
schoenebeck |
223 |
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1370 |
capela |
159 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1371 |
schoenebeck |
221 |
pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel); |
1372 |
capela |
159 |
} |
1373 |
|
|
catch (LinuxSamplerException e) { |
1374 |
|
|
result.Error(e); |
1375 |
|
|
} |
1376 |
|
|
return result.Produce(); |
1377 |
|
|
} |
1378 |
|
|
|
1379 |
|
|
/** |
1380 |
schoenebeck |
35 |
* Will be called by the parser to change the global volume factor on a |
1381 |
|
|
* particular sampler channel. |
1382 |
|
|
*/ |
1383 |
schoenebeck |
225 |
String LSCPServer::SetVolume(double dVolume, uint uiSamplerChannel) { |
1384 |
|
|
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
1385 |
senkov |
120 |
LSCPResultSet result; |
1386 |
schoenebeck |
53 |
try { |
1387 |
|
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1388 |
schoenebeck |
374 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1389 |
schoenebeck |
411 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1390 |
|
|
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1391 |
|
|
pEngineChannel->Volume(dVolume); |
1392 |
schoenebeck |
53 |
} |
1393 |
|
|
catch (LinuxSamplerException e) { |
1394 |
senkov |
120 |
result.Error(e); |
1395 |
schoenebeck |
53 |
} |
1396 |
senkov |
120 |
return result.Produce(); |
1397 |
schoenebeck |
35 |
} |
1398 |
|
|
|
1399 |
|
|
/** |
1400 |
|
|
* Will be called by the parser to reset a particular sampler channel. |
1401 |
|
|
*/ |
1402 |
schoenebeck |
53 |
String LSCPServer::ResetChannel(uint uiSamplerChannel) { |
1403 |
|
|
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
1404 |
senkov |
120 |
LSCPResultSet result; |
1405 |
schoenebeck |
53 |
try { |
1406 |
|
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1407 |
schoenebeck |
374 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1408 |
schoenebeck |
411 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1409 |
|
|
if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel"); |
1410 |
schoenebeck |
579 |
if (!pEngineChannel->GetEngine()) throw LinuxSamplerException("No audio output device connected to sampler channel"); |
1411 |
schoenebeck |
411 |
pEngineChannel->GetEngine()->Reset(); |
1412 |
schoenebeck |
53 |
} |
1413 |
|
|
catch (LinuxSamplerException e) { |
1414 |
senkov |
120 |
result.Error(e); |
1415 |
schoenebeck |
53 |
} |
1416 |
senkov |
120 |
return result.Produce(); |
1417 |
schoenebeck |
35 |
} |
1418 |
|
|
|
1419 |
|
|
/** |
1420 |
schoenebeck |
212 |
* Will be called by the parser to reset the whole sampler. |
1421 |
|
|
*/ |
1422 |
|
|
String LSCPServer::ResetSampler() { |
1423 |
|
|
dmsg(2,("LSCPServer: ResetSampler()\n")); |
1424 |
|
|
pSampler->Reset(); |
1425 |
|
|
LSCPResultSet result; |
1426 |
|
|
return result.Produce(); |
1427 |
|
|
} |
1428 |
|
|
|
1429 |
|
|
/** |
1430 |
schoenebeck |
563 |
* Will be called by the parser to return general informations about this |
1431 |
|
|
* sampler. |
1432 |
|
|
*/ |
1433 |
|
|
String LSCPServer::GetServerInfo() { |
1434 |
|
|
dmsg(2,("LSCPServer: GetServerInfo()\n")); |
1435 |
|
|
LSCPResultSet result; |
1436 |
|
|
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
1437 |
schoenebeck |
570 |
result.Add("VERSION", VERSION); |
1438 |
|
|
result.Add("PROTOCOL_VERSION", "1.0"); |
1439 |
schoenebeck |
563 |
return result.Produce(); |
1440 |
|
|
} |
1441 |
|
|
|
1442 |
|
|
/** |
1443 |
schoenebeck |
35 |
* Will be called by the parser to subscribe a client (frontend) on the |
1444 |
|
|
* server for receiving event messages. |
1445 |
|
|
*/ |
1446 |
senkov |
170 |
String LSCPServer::SubscribeNotification(LSCPEvent::event_t type) { |
1447 |
|
|
dmsg(2,("LSCPServer: SubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
1448 |
|
|
LSCPResultSet result; |
1449 |
|
|
SubscriptionMutex.Lock(); |
1450 |
|
|
eventSubscriptions[type].push_back(currentSocket); |
1451 |
|
|
SubscriptionMutex.Unlock(); |
1452 |
|
|
return result.Produce(); |
1453 |
schoenebeck |
35 |
} |
1454 |
|
|
|
1455 |
|
|
/** |
1456 |
|
|
* Will be called by the parser to unsubscribe a client on the server |
1457 |
|
|
* for not receiving further event messages. |
1458 |
|
|
*/ |
1459 |
senkov |
170 |
String LSCPServer::UnsubscribeNotification(LSCPEvent::event_t type) { |
1460 |
|
|
dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
1461 |
|
|
LSCPResultSet result; |
1462 |
|
|
SubscriptionMutex.Lock(); |
1463 |
|
|
eventSubscriptions[type].remove(currentSocket); |
1464 |
|
|
SubscriptionMutex.Unlock(); |
1465 |
|
|
return result.Produce(); |
1466 |
schoenebeck |
35 |
} |
1467 |
capela |
133 |
|
1468 |
senkov |
397 |
static int select_callback(void * lscpResultSet, int argc, |
1469 |
|
|
char **argv, char **azColName) |
1470 |
|
|
{ |
1471 |
|
|
LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet; |
1472 |
|
|
resultSet->Add(argc, argv); |
1473 |
|
|
return 0; |
1474 |
|
|
} |
1475 |
|
|
|
1476 |
|
|
String LSCPServer::QueryDatabase(String query) { |
1477 |
|
|
LSCPResultSet result; |
1478 |
schoenebeck |
401 |
#if HAVE_SQLITE3 |
1479 |
senkov |
397 |
char* zErrMsg = NULL; |
1480 |
|
|
sqlite3 *db; |
1481 |
|
|
String selectStr = "SELECT " + query; |
1482 |
|
|
|
1483 |
|
|
int rc = sqlite3_open("linuxsampler.db", &db); |
1484 |
|
|
if (rc == SQLITE_OK) |
1485 |
|
|
{ |
1486 |
|
|
rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg); |
1487 |
|
|
} |
1488 |
|
|
if ( rc != SQLITE_OK ) |
1489 |
|
|
{ |
1490 |
senkov |
398 |
result.Error(String(zErrMsg), rc); |
1491 |
senkov |
397 |
} |
1492 |
|
|
sqlite3_close(db); |
1493 |
|
|
#else |
1494 |
|
|
result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0); |
1495 |
|
|
#endif |
1496 |
|
|
return result.Produce(); |
1497 |
|
|
} |
1498 |
|
|
|
1499 |
schoenebeck |
210 |
/** |
1500 |
|
|
* Will be called by the parser to enable or disable echo mode; if echo |
1501 |
|
|
* mode is enabled, all commands from the client will (immediately) be |
1502 |
|
|
* echoed back to the client. |
1503 |
|
|
*/ |
1504 |
|
|
String LSCPServer::SetEcho(yyparse_param_t* pSession, double boolean_value) { |
1505 |
|
|
dmsg(2,("LSCPServer: SetEcho(val=%f)\n", boolean_value)); |
1506 |
|
|
LSCPResultSet result; |
1507 |
|
|
try { |
1508 |
|
|
if (boolean_value == 0) pSession->bVerbose = false; |
1509 |
|
|
else if (boolean_value == 1) pSession->bVerbose = true; |
1510 |
|
|
else throw LinuxSamplerException("Not a boolean value, must either be 0 or 1"); |
1511 |
|
|
} |
1512 |
|
|
catch (LinuxSamplerException e) { |
1513 |
|
|
result.Error(e); |
1514 |
|
|
} |
1515 |
|
|
return result.Produce(); |
1516 |
|
|
} |