3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
|
* Copyright (C) 2005 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This library is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
10 |
* the Free Software Foundation; either version 2 of the License, or * |
* the Free Software Foundation; either version 2 of the License, or * |
11 |
* (at your option) any later version. * |
* (at your option) any later version. * |
12 |
* * |
* * |
13 |
* This program is distributed in the hope that it will be useful, * |
* This library is distributed in the hope that it will be useful, * |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 |
* GNU General Public License for more details. * |
* GNU General Public License for more details. * |
17 |
* * |
* * |
18 |
* You should have received a copy of the GNU General Public License * |
* You should have received a copy of the GNU General Public License * |
19 |
* along with this program; if not, write to the Free Software * |
* along with this library; if not, write to the Free Software * |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
***************************************************************************/ |
24 |
#include "lscpserver.h" |
#include "lscpserver.h" |
25 |
#include "lscpresultset.h" |
#include "lscpresultset.h" |
26 |
#include "lscpevent.h" |
#include "lscpevent.h" |
27 |
|
//#include "../common/global.h" |
28 |
|
|
29 |
|
#ifdef HAVE_SQLITE3 |
30 |
|
#include "sqlite3.h" |
31 |
|
#endif |
32 |
|
|
33 |
#include "../engines/gig/Engine.h" |
#include "../engines/gig/Engine.h" |
34 |
#include "../audiodriver/AudioOutputDeviceFactory.h" |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
35 |
#include "../mididriver/MidiInputDeviceFactory.h" |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
36 |
|
|
37 |
/** |
/** |
38 |
* Below are a few static members of the LSCPServer class. |
* Below are a few static members of the LSCPServer class. |
49 |
*/ |
*/ |
50 |
fd_set LSCPServer::fdSet; |
fd_set LSCPServer::fdSet; |
51 |
int LSCPServer::currentSocket = -1; |
int LSCPServer::currentSocket = -1; |
52 |
std::vector<int> LSCPServer::hSessions = std::vector<int>(); |
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
53 |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
54 |
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
55 |
std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions = std::map< LSCPEvent::event_t, std::list<int> >(); |
std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions = std::map< LSCPEvent::event_t, std::list<int> >(); |
56 |
Mutex LSCPServer::NotifyMutex = Mutex(); |
Mutex LSCPServer::NotifyMutex = Mutex(); |
57 |
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
58 |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
59 |
|
Mutex LSCPServer::RTNotifyMutex = Mutex(); |
60 |
|
|
61 |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) { |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(true, false, 0, -4) { |
62 |
this->pSampler = pSampler; |
this->pSampler = pSampler; |
63 |
LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS"); |
64 |
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
68 |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
69 |
} |
} |
70 |
|
|
71 |
|
/** |
72 |
|
* Blocks the calling thread until the LSCP Server is initialized and |
73 |
|
* accepting socket connections, if the server is already initialized then |
74 |
|
* this method will return immediately. |
75 |
|
* @param TimeoutSeconds - optional: max. wait time in seconds |
76 |
|
* (default: 0s) |
77 |
|
* @param TimeoutNanoSeconds - optional: max wait time in nano seconds |
78 |
|
* (default: 0ns) |
79 |
|
* @returns 0 on success, a value less than 0 if timeout exceeded |
80 |
|
*/ |
81 |
|
int LSCPServer::WaitUntilInitialized(long TimeoutSeconds, long TimeoutNanoSeconds) { |
82 |
|
return Initialized.WaitAndUnlockIf(false, TimeoutSeconds, TimeoutNanoSeconds); |
83 |
|
} |
84 |
|
|
85 |
int LSCPServer::Main() { |
int LSCPServer::Main() { |
86 |
int hSocket = socket(AF_INET, SOCK_STREAM, 0); |
int hSocket = socket(AF_INET, SOCK_STREAM, 0); |
87 |
if (hSocket < 0) { |
if (hSocket < 0) { |
95 |
SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY); |
SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY); |
96 |
|
|
97 |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
98 |
std::cerr << "LSCPServer: Could not bind server socket." << std::endl; |
std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds..."; |
99 |
close(hSocket); |
for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds |
100 |
//return -1; |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
101 |
exit(EXIT_FAILURE); |
if (trial > LSCP_SERVER_BIND_TIMEOUT) { |
102 |
|
std::cerr << "gave up!" << std::endl; |
103 |
|
close(hSocket); |
104 |
|
//return -1; |
105 |
|
exit(EXIT_FAILURE); |
106 |
|
} |
107 |
|
else sleep(1); // sleep 1s |
108 |
|
} |
109 |
|
else break; // success |
110 |
|
} |
111 |
} |
} |
112 |
|
|
113 |
listen(hSocket, 1); |
listen(hSocket, 1); |
114 |
dmsg(1,("LSCPServer: Server running.\n")); // server running |
Initialized.Set(true); |
115 |
|
|
116 |
// now wait for client connections and handle their requests |
// now wait for client connections and handle their requests |
117 |
sockaddr_in client; |
sockaddr_in client; |
118 |
int length = sizeof(client); |
int length = sizeof(client); |
|
struct timeval tv; |
|
|
tv.tv_sec = 30; |
|
|
tv.tv_usec = 0; |
|
119 |
FD_ZERO(&fdSet); |
FD_ZERO(&fdSet); |
120 |
FD_SET(hSocket, &fdSet); |
FD_SET(hSocket, &fdSet); |
121 |
int maxSessions = hSocket; |
int maxSessions = hSocket; |
|
|
|
|
// Parser initialization |
|
|
yyparse_param_t yyparse_param; |
|
|
yyparse_param.pServer = this; |
|
122 |
|
|
123 |
while (true) { |
while (true) { |
124 |
fd_set selectSet = fdSet; |
fd_set selectSet = fdSet; |
125 |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &tv); |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, NULL); |
126 |
if (retval == 0) |
if (retval == 0) |
127 |
continue; //Nothing in 30 seconds, try again |
continue; //Nothing try again |
128 |
if (retval == -1) { |
if (retval == -1) { |
129 |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
130 |
close(hSocket); |
close(hSocket); |
131 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
132 |
} |
} |
133 |
|
|
134 |
//Accept new connections now (if any) |
//Accept new connections now (if any) |
135 |
if (FD_ISSET(hSocket, &selectSet)) { |
if (FD_ISSET(hSocket, &selectSet)) { |
136 |
int socket = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length); |
int socket = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length); |
144 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
145 |
} |
} |
146 |
|
|
147 |
hSessions.push_back(socket); |
// Parser initialization |
148 |
|
yyparse_param_t yyparse_param; |
149 |
|
yyparse_param.pServer = this; |
150 |
|
yyparse_param.hSession = socket; |
151 |
|
|
152 |
|
Sessions.push_back(yyparse_param); |
153 |
FD_SET(socket, &fdSet); |
FD_SET(socket, &fdSet); |
154 |
if (socket > maxSessions) |
if (socket > maxSessions) |
155 |
maxSessions = socket; |
maxSessions = socket; |
159 |
} |
} |
160 |
|
|
161 |
//Something was selected and it was not the hSocket, so it must be some command(s) coming. |
//Something was selected and it was not the hSocket, so it must be some command(s) coming. |
162 |
for (std::vector<int>::iterator iter = hSessions.begin(); iter != hSessions.end(); iter++) { |
for (std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); iter != Sessions.end(); iter++) { |
163 |
if (FD_ISSET(*iter, &selectSet)) { //Was it this socket? |
if (FD_ISSET((*iter).hSession, &selectSet)) { //Was it this socket? |
164 |
if (GetLSCPCommand(iter)) { //Have we read the entire command? |
if (GetLSCPCommand(iter)) { //Have we read the entire command? |
165 |
dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket)); |
dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket)); |
166 |
yylex_init(&yyparse_param.pScanner); |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
167 |
currentSocket = *iter; //a hack |
restart(NULL, dummy); // restart the 'scanner' |
168 |
int result = yyparse(&yyparse_param); |
currentSocket = (*iter).hSession; //a hack |
169 |
|
if ((*iter).bVerbose) { // if echo mode enabled |
170 |
|
AnswerClient(bufferedCommands[currentSocket]); |
171 |
|
} |
172 |
|
int result = yyparse(&(*iter)); |
173 |
currentSocket = -1; //continuation of a hack |
currentSocket = -1; //continuation of a hack |
174 |
dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket)); |
dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket)); |
175 |
if (result == LSCP_QUIT) { //Was it a quit command by any chance? |
if (result == LSCP_QUIT) { //Was it a quit command by any chance? |
178 |
} |
} |
179 |
//socket may have been closed, iter may be invalid, get out of the loop for now. |
//socket may have been closed, iter may be invalid, get out of the loop for now. |
180 |
//we'll be back if there is data. |
//we'll be back if there is data. |
181 |
break; |
break; |
182 |
} |
} |
183 |
} |
} |
184 |
|
|
190 |
} |
} |
191 |
NotifyBufferMutex.Unlock(); |
NotifyBufferMutex.Unlock(); |
192 |
} |
} |
|
//It will never get here anyway |
|
|
//yylex_destroy(yyparse_param.pScanner); |
|
193 |
} |
} |
194 |
|
|
195 |
void LSCPServer::CloseConnection( std::vector<int>::iterator iter ) { |
void LSCPServer::CloseConnection( std::vector<yyparse_param_t>::iterator iter ) { |
196 |
int socket = *iter; |
int socket = (*iter).hSession; |
197 |
dmsg(1,("LSCPServer: Client connection terminated on socket:%d.\n",socket)); |
dmsg(1,("LSCPServer: Client connection terminated on socket:%d.\n",socket)); |
198 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket)); |
199 |
hSessions.erase(iter); |
Sessions.erase(iter); |
200 |
FD_CLR(socket, &fdSet); |
FD_CLR(socket, &fdSet); |
201 |
SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any) |
SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any) |
202 |
for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) { |
for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) { |
210 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
211 |
} |
} |
212 |
|
|
213 |
|
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
214 |
|
int subs = 0; |
215 |
|
SubscriptionMutex.Lock(); |
216 |
|
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
217 |
|
iter != events.end(); iter++) |
218 |
|
{ |
219 |
|
subs += eventSubscriptions.count(*iter); |
220 |
|
} |
221 |
|
SubscriptionMutex.Unlock(); |
222 |
|
return subs; |
223 |
|
} |
224 |
|
|
225 |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
226 |
SubscriptionMutex.Lock(); |
SubscriptionMutex.Lock(); |
227 |
if (eventSubscriptions.count(event.GetType()) == 0) { |
if (eventSubscriptions.count(event.GetType()) == 0) { |
272 |
* If command is read, it will return true. Otherwise false is returned. |
* If command is read, it will return true. Otherwise false is returned. |
273 |
* In any case the received portion (complete or incomplete) is saved into bufferedCommand map. |
* In any case the received portion (complete or incomplete) is saved into bufferedCommand map. |
274 |
*/ |
*/ |
275 |
bool LSCPServer::GetLSCPCommand( std::vector<int>::iterator iter ) { |
bool LSCPServer::GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ) { |
276 |
int socket = *iter; |
int socket = (*iter).hSession; |
277 |
char c; |
char c; |
278 |
int i = 0; |
int i = 0; |
279 |
while (true) { |
while (true) { |
283 |
break; |
break; |
284 |
} |
} |
285 |
if (result == 1) { |
if (result == 1) { |
286 |
if (c == '\r') |
if (c == '\r') |
287 |
continue; //Ignore CR |
continue; //Ignore CR |
288 |
if (c == '\n') { |
if (c == '\n') { |
289 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket)); |
310 |
break; |
break; |
311 |
case EAGAIN: |
case EAGAIN: |
312 |
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")); |
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")); |
313 |
break; |
break; |
314 |
case EINTR: |
case EINTR: |
315 |
dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n")); |
dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n")); |
316 |
break; |
break; |
317 |
case EFAULT: |
case EFAULT: |
318 |
dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n")); |
dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n")); |
319 |
break; |
break; |
320 |
case EINVAL: |
case EINVAL: |
321 |
dmsg(2,("LSCPScanner: Invalid argument passed.\n")); |
dmsg(2,("LSCPScanner: Invalid argument passed.\n")); |
322 |
break; |
break; |
323 |
case ENOMEM: |
case ENOMEM: |
324 |
dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n")); |
dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n")); |
325 |
break; |
break; |
326 |
default: |
default: |
327 |
dmsg(2,("LSCPScanner: Unknown recv() error.\n")); |
dmsg(2,("LSCPScanner: Unknown recv() error.\n")); |
328 |
break; |
break; |
329 |
} |
} |
330 |
CloseConnection(iter); |
CloseConnection(iter); |
331 |
break; |
break; |
332 |
} |
} |
418 |
LSCPResultSet result; |
LSCPResultSet result; |
419 |
try { |
try { |
420 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
421 |
if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
422 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
423 |
pSampler->DestroyAudioOutputDevice(pDevice); |
pSampler->DestroyAudioOutputDevice(pDevice); |
424 |
} |
} |
433 |
LSCPResultSet result; |
LSCPResultSet result; |
434 |
try { |
try { |
435 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
436 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
437 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
|
if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
|
438 |
pSampler->DestroyMidiInputDevice(pDevice); |
pSampler->DestroyMidiInputDevice(pDevice); |
439 |
} |
} |
440 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
451 |
LSCPResultSet result; |
LSCPResultSet result; |
452 |
try { |
try { |
453 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
454 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
455 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
456 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
457 |
if (pSamplerChannel->GetAudioOutputDevice() == NULL) |
if (!pSamplerChannel->GetAudioOutputDevice()) |
458 |
throw LinuxSamplerException("No audio output device on channel"); |
throw LinuxSamplerException("No audio output device connected to sampler channel"); |
459 |
if (bBackground) { |
if (bBackground) { |
460 |
LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument); |
InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngine); |
461 |
pLoadInstrument->StartThread(); |
} |
462 |
|
else { |
463 |
|
// tell the engine which instrument to load |
464 |
|
pEngine->PrepareLoadInstrument(Filename.c_str(), uiInstrument); |
465 |
|
// actually start to load the instrument (blocks until completed) |
466 |
|
pEngine->LoadInstrument(); |
467 |
} |
} |
|
else pEngine->LoadInstrument(Filename.c_str(), uiInstrument); |
|
468 |
} |
} |
469 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
470 |
result.Error(e); |
result.Error(e); |
483 |
if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig; |
if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig; |
484 |
else throw LinuxSamplerException("Unknown engine type"); |
else throw LinuxSamplerException("Unknown engine type"); |
485 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
486 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
487 |
|
LockRTNotify(); |
488 |
pSamplerChannel->LoadEngine(type); |
pSamplerChannel->LoadEngine(type); |
489 |
|
UnlockRTNotify(); |
490 |
} |
} |
491 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
492 |
result.Error(e); |
result.Error(e); |
505 |
} |
} |
506 |
|
|
507 |
/** |
/** |
508 |
|
* Will be called by the parser to get the list of sampler channels. |
509 |
|
*/ |
510 |
|
String LSCPServer::ListChannels() { |
511 |
|
dmsg(2,("LSCPServer: ListChannels()\n")); |
512 |
|
String list; |
513 |
|
std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels(); |
514 |
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
515 |
|
for (; iter != channels.end(); iter++) { |
516 |
|
if (list != "") list += ","; |
517 |
|
list += ToString(iter->first); |
518 |
|
} |
519 |
|
LSCPResultSet result; |
520 |
|
result.Add(list); |
521 |
|
return result.Produce(); |
522 |
|
} |
523 |
|
|
524 |
|
/** |
525 |
* Will be called by the parser to add a sampler channel. |
* Will be called by the parser to add a sampler channel. |
526 |
*/ |
*/ |
527 |
String LSCPServer::AddChannel() { |
String LSCPServer::AddChannel() { |
537 |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
538 |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
539 |
LSCPResultSet result; |
LSCPResultSet result; |
540 |
|
LockRTNotify(); |
541 |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
542 |
|
UnlockRTNotify(); |
543 |
return result.Produce(); |
return result.Produce(); |
544 |
} |
} |
545 |
|
|
561 |
try { |
try { |
562 |
if ((EngineName == "GigEngine") || (EngineName == "gig")) { |
if ((EngineName == "GigEngine") || (EngineName == "gig")) { |
563 |
Engine* pEngine = new LinuxSampler::gig::Engine; |
Engine* pEngine = new LinuxSampler::gig::Engine; |
564 |
result.Add(pEngine->Description()); |
result.Add("DESCRIPTION", pEngine->Description()); |
565 |
result.Add(pEngine->Version()); |
result.Add("VERSION", pEngine->Version()); |
566 |
delete pEngine; |
delete pEngine; |
567 |
} |
} |
568 |
else throw LinuxSamplerException("Unknown engine type"); |
else throw LinuxSamplerException("Unknown engine type"); |
582 |
LSCPResultSet result; |
LSCPResultSet result; |
583 |
try { |
try { |
584 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
585 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
586 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
587 |
|
|
588 |
//Defaults values |
//Defaults values |
589 |
String EngineName = "NONE"; |
String EngineName = "NONE"; |
590 |
float Volume = 0; |
float Volume = 0.0f; |
591 |
String InstrumentFileName = "NONE"; |
String InstrumentFileName = "NONE"; |
592 |
|
String InstrumentName = "NONE"; |
593 |
int InstrumentIndex = -1; |
int InstrumentIndex = -1; |
594 |
int InstrumentStatus = -1; |
int InstrumentStatus = -1; |
595 |
|
int AudioOutputChannels = 0; |
596 |
|
String AudioRouting; |
597 |
|
|
598 |
if (pEngine) { |
if (pEngine) { |
599 |
EngineName = pEngine->EngineName(); |
EngineName = pEngine->EngineName(); |
600 |
|
AudioOutputChannels = pEngine->Channels(); |
601 |
Volume = pEngine->Volume(); |
Volume = pEngine->Volume(); |
602 |
InstrumentStatus = pEngine->InstrumentStatus(); |
InstrumentStatus = pEngine->InstrumentStatus(); |
603 |
InstrumentIndex = pEngine->InstrumentIndex(); |
InstrumentIndex = pEngine->InstrumentIndex(); |
604 |
if (InstrumentIndex != -1) |
if (InstrumentIndex != -1) |
605 |
|
{ |
606 |
InstrumentFileName = pEngine->InstrumentFileName(); |
InstrumentFileName = pEngine->InstrumentFileName(); |
607 |
|
InstrumentName = pEngine->InstrumentName(); |
608 |
|
} |
609 |
|
for (int chan = 0; chan < pEngine->Channels(); chan++) { |
610 |
|
if (AudioRouting != "") AudioRouting += ","; |
611 |
|
AudioRouting += ToString(pEngine->OutputChannel(chan)); |
612 |
|
} |
613 |
} |
} |
614 |
|
|
615 |
result.Add("ENGINE_NAME", EngineName); |
result.Add("ENGINE_NAME", EngineName); |
617 |
|
|
618 |
//Some not-so-hardcoded stuff to make GUI look good |
//Some not-so-hardcoded stuff to make GUI look good |
619 |
result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice())); |
result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice())); |
620 |
result.Add("AUDIO_OUTPUT_CHANNELS", "2"); |
result.Add("AUDIO_OUTPUT_CHANNELS", AudioOutputChannels); |
621 |
result.Add("AUDIO_OUTPUT_ROUTING", "0,1"); |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
622 |
|
|
623 |
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
624 |
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
625 |
result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
if (pSamplerChannel->GetMidiInputChannel() == MidiInputPort::midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
626 |
|
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
627 |
|
|
628 |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
629 |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
630 |
|
result.Add("INSTRUMENT_NAME", InstrumentName); |
631 |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
632 |
} |
} |
633 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
645 |
LSCPResultSet result; |
LSCPResultSet result; |
646 |
try { |
try { |
647 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
648 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
649 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
650 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
651 |
result.Add(pEngine->VoiceCount()); |
result.Add(pEngine->VoiceCount()); |
652 |
} |
} |
653 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
665 |
LSCPResultSet result; |
LSCPResultSet result; |
666 |
try { |
try { |
667 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
668 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
669 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
670 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
671 |
result.Add(pEngine->DiskStreamCount()); |
result.Add(pEngine->DiskStreamCount()); |
672 |
} |
} |
673 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
685 |
LSCPResultSet result; |
LSCPResultSet result; |
686 |
try { |
try { |
687 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
688 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
689 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
690 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
691 |
if (!pEngine->DiskStreamSupported()) |
if (!pEngine->DiskStreamSupported()) |
692 |
result.Add("NA"); |
result.Add("NA"); |
693 |
else { |
else { |
784 |
} |
} |
785 |
|
|
786 |
String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
787 |
dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str())); |
dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size())); |
788 |
LSCPResultSet result; |
LSCPResultSet result; |
789 |
try { |
try { |
790 |
DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter); |
DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter); |
793 |
result.Add("MANDATORY", pParameter->Mandatory()); |
result.Add("MANDATORY", pParameter->Mandatory()); |
794 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
795 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
796 |
if (pParameter->Depends()) result.Add("DEPENDS", pParameter->Depends()); |
optional<String> oDepends = pParameter->Depends(); |
797 |
if (pParameter->Default()) result.Add("DEFAULT", pParameter->Default()); |
optional<String> oDefault = pParameter->Default(DependencyList); |
798 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
optional<String> oRangeMin = pParameter->RangeMin(DependencyList); |
799 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
optional<String> oRangeMax = pParameter->RangeMax(DependencyList); |
800 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
optional<String> oPossibilities = pParameter->Possibilities(DependencyList); |
801 |
|
if (oDepends) result.Add("DEPENDS", *oDepends); |
802 |
|
if (oDefault) result.Add("DEFAULT", *oDefault); |
803 |
|
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
804 |
|
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
805 |
|
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
806 |
} |
} |
807 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
808 |
result.Error(e); |
result.Error(e); |
811 |
} |
} |
812 |
|
|
813 |
String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
814 |
dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s)\n",Driver.c_str(),Parameter.c_str())); |
dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size())); |
815 |
LSCPResultSet result; |
LSCPResultSet result; |
816 |
try { |
try { |
817 |
DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter); |
DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter); |
820 |
result.Add("MANDATORY", pParameter->Mandatory()); |
result.Add("MANDATORY", pParameter->Mandatory()); |
821 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
822 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
823 |
if (pParameter->Depends()) result.Add("DEPENDS", pParameter->Depends()); |
optional<String> oDepends = pParameter->Depends(); |
824 |
if (pParameter->Default()) result.Add("DEFAULT", pParameter->Default()); |
optional<String> oDefault = pParameter->Default(DependencyList); |
825 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
optional<String> oRangeMin = pParameter->RangeMin(DependencyList); |
826 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
optional<String> oRangeMax = pParameter->RangeMax(DependencyList); |
827 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
optional<String> oPossibilities = pParameter->Possibilities(DependencyList); |
828 |
|
if (oDepends) result.Add("DEPENDS", *oDepends); |
829 |
|
if (oDefault) result.Add("DEFAULT", *oDefault); |
830 |
|
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
831 |
|
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
832 |
|
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
833 |
} |
} |
834 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
835 |
result.Error(e); |
result.Error(e); |
906 |
LSCPResultSet result; |
LSCPResultSet result; |
907 |
try { |
try { |
908 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
909 |
if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
910 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
911 |
result.Add("driver", pDevice->Driver()); |
result.Add("DRIVER", pDevice->Driver()); |
912 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
913 |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
914 |
for (; iter != parameters.end(); iter++) { |
for (; iter != parameters.end(); iter++) { |
926 |
LSCPResultSet result; |
LSCPResultSet result; |
927 |
try { |
try { |
928 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
929 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
930 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
931 |
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
result.Add("DRIVER", pDevice->Driver()); |
|
result.Add("driver", pDevice->Driver()); |
|
932 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
933 |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
934 |
for (; iter != parameters.end(); iter++) { |
for (; iter != parameters.end(); iter++) { |
944 |
dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex)); |
dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex)); |
945 |
LSCPResultSet result; |
LSCPResultSet result; |
946 |
try { |
try { |
947 |
|
// get MIDI input device |
948 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
949 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
950 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
951 |
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
|
952 |
MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
// get MIDI port |
953 |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
954 |
std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters(); |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
955 |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
|
956 |
|
// return the values of all MIDI port parameters |
957 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters(); |
958 |
|
std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin(); |
959 |
for (; iter != parameters.end(); iter++) { |
for (; iter != parameters.end(); iter++) { |
960 |
result.Add(iter->first, iter->second->Value()); |
result.Add(iter->first, iter->second->Value()); |
961 |
} |
} |
972 |
try { |
try { |
973 |
// get audio output device |
// get audio output device |
974 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
975 |
if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); |
if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); |
976 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
AudioOutputDevice* pDevice = devices[DeviceId]; |
977 |
|
|
978 |
// get audio channel |
// get audio channel |
979 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
980 |
if (!pChannel) throw LinuxSamplerException("Audio ouotput device does not have channel " + ToString(ChannelId) + "."); |
if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + "."); |
981 |
|
|
982 |
// return the values of all audio channel parameters |
// return the values of all audio channel parameters |
983 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
996 |
dmsg(2,("LSCPServer: GetMidiInputPortParameterInfo(DeviceId=%d,PortId=%d,ParameterName=%s)\n",DeviceId,PortId,ParameterName.c_str())); |
dmsg(2,("LSCPServer: GetMidiInputPortParameterInfo(DeviceId=%d,PortId=%d,ParameterName=%s)\n",DeviceId,PortId,ParameterName.c_str())); |
997 |
LSCPResultSet result; |
LSCPResultSet result; |
998 |
try { |
try { |
999 |
// get audio output device |
// get MIDI input device |
1000 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1001 |
if (!devices[DeviceId]) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + "."); |
if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no midi input device with index " + ToString(DeviceId) + "."); |
1002 |
MidiInputDevice* pDevice = devices[DeviceId]; |
MidiInputDevice* pDevice = devices[DeviceId]; |
1003 |
|
|
1004 |
// get midi port |
// get midi port |
1005 |
MidiInputDevice::MidiInputPort* pPort = pDevice->GetPort(PortId); |
MidiInputPort* pPort = pDevice->GetPort(PortId); |
1006 |
if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + "."); |
if (!pPort) throw LinuxSamplerException("Midi input device does not have port " + ToString(PortId) + "."); |
1007 |
|
|
1008 |
// get desired port parameter |
// get desired port parameter |
1009 |
std::map<String,DeviceCreationParameter*> parameters = pPort->DeviceParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters(); |
1010 |
if (!parameters[ParameterName]) throw LinuxSamplerException("Midi port does not provice a parameters '" + ParameterName + "'."); |
if (!parameters.count(ParameterName)) throw LinuxSamplerException("Midi port does not provide a parameter '" + ParameterName + "'."); |
1011 |
DeviceCreationParameter* pParameter = parameters[ParameterName]; |
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
1012 |
|
|
1013 |
// return all fields of this audio channel parameter |
// return all fields of this audio channel parameter |
1014 |
result.Add("TYPE", pParameter->Type()); |
result.Add("TYPE", pParameter->Type()); |
1015 |
result.Add("DESCRIPTION", pParameter->Description()); |
result.Add("DESCRIPTION", pParameter->Description()); |
1016 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
1017 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
1018 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
1019 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
1020 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
1021 |
} |
} |
1022 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1023 |
result.Error(e); |
result.Error(e); |
1031 |
try { |
try { |
1032 |
// get audio output device |
// get audio output device |
1033 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1034 |
if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); |
if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); |
1035 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
AudioOutputDevice* pDevice = devices[DeviceId]; |
1036 |
|
|
1037 |
// get audio channel |
// get audio channel |
1038 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1039 |
if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + "."); |
if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + "."); |
1040 |
|
|
1041 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1042 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1043 |
if (!parameters[ParameterName]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'."); |
if (!parameters.count(ParameterName)) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParameterName + "'."); |
1044 |
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
1045 |
|
|
1046 |
// return all fields of this audio channel parameter |
// return all fields of this audio channel parameter |
1048 |
result.Add("DESCRIPTION", pParameter->Description()); |
result.Add("DESCRIPTION", pParameter->Description()); |
1049 |
result.Add("FIX", pParameter->Fix()); |
result.Add("FIX", pParameter->Fix()); |
1050 |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
1051 |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", pParameter->RangeMin()); |
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
1052 |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", pParameter->RangeMax()); |
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
1053 |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", pParameter->Possibilities()); |
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
1054 |
} |
} |
1055 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1056 |
result.Error(e); |
result.Error(e); |
1064 |
try { |
try { |
1065 |
// get audio output device |
// get audio output device |
1066 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1067 |
if (!devices[DeviceId]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); |
if (!devices.count(DeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceId) + "."); |
1068 |
AudioOutputDevice* pDevice = devices[DeviceId]; |
AudioOutputDevice* pDevice = devices[DeviceId]; |
1069 |
|
|
1070 |
// get audio channel |
// get audio channel |
1071 |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1072 |
if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + "."); |
if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + "."); |
1073 |
|
|
1074 |
// get desired audio channel parameter |
// get desired audio channel parameter |
1075 |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1076 |
if (!parameters[ParamKey]) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'."); |
if (!parameters.count(ParamKey)) throw LinuxSamplerException("Audio channel does not provide a parameter '" + ParamKey + "'."); |
1077 |
DeviceRuntimeParameter* pParameter = parameters[ParamKey]; |
DeviceRuntimeParameter* pParameter = parameters[ParamKey]; |
1078 |
|
|
1079 |
// set new channel parameter value |
// set new channel parameter value |
1090 |
LSCPResultSet result; |
LSCPResultSet result; |
1091 |
try { |
try { |
1092 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1093 |
if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
1094 |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
1095 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1096 |
if (!parameters[ParamKey]) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
if (!parameters.count(ParamKey)) throw LinuxSamplerException("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
1097 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1098 |
} |
} |
1099 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1107 |
LSCPResultSet result; |
LSCPResultSet result; |
1108 |
try { |
try { |
1109 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1110 |
if (!devices[DeviceIndex]) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
1111 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
1112 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1113 |
if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
1114 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1115 |
} |
} |
1116 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1123 |
dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str())); |
dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str())); |
1124 |
LSCPResultSet result; |
LSCPResultSet result; |
1125 |
try { |
try { |
1126 |
|
// get MIDI input device |
1127 |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1128 |
|
if (!devices.count(DeviceIndex)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
1129 |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
MidiInputDevice* pDevice = devices[DeviceIndex]; |
1130 |
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
|
1131 |
MidiInputDevice::MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
// get MIDI port |
1132 |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
1133 |
std::map<String,DeviceCreationParameter*> parameters = pMidiInputPort->DeviceParameters(); |
if (!pMidiInputPort) throw LinuxSamplerException("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
1134 |
if (!parameters[ParamKey]) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); |
|
1135 |
|
// set port parameter value |
1136 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters(); |
1137 |
|
if (!parameters.count(ParamKey)) throw LinuxSamplerException("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); |
1138 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1139 |
} |
} |
1140 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1149 |
*/ |
*/ |
1150 |
String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) { |
1151 |
dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel)); |
1152 |
return "ERR:0:Not implemented yet.\r\n"; //FIXME: Add support for this in resultset class? |
LSCPResultSet result; |
1153 |
|
try { |
1154 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1155 |
|
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1156 |
|
Engine* pEngine = pSamplerChannel->GetEngine(); |
1157 |
|
if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel)); |
1158 |
|
if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel)); |
1159 |
|
pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
1160 |
|
} |
1161 |
|
catch (LinuxSamplerException e) { |
1162 |
|
result.Error(e); |
1163 |
|
} |
1164 |
|
return result.Produce(); |
1165 |
} |
} |
1166 |
|
|
1167 |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
1169 |
LSCPResultSet result; |
LSCPResultSet result; |
1170 |
try { |
try { |
1171 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1172 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1173 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1174 |
|
if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId)); |
1175 |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
|
if (!pDevice) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId)); |
|
1176 |
pSamplerChannel->SetAudioOutputDevice(pDevice); |
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1177 |
} |
} |
1178 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1186 |
LSCPResultSet result; |
LSCPResultSet result; |
1187 |
try { |
try { |
1188 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1189 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1190 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1191 |
if (AudioOutputDriver == "ALSA") AudioOutputDriver = "Alsa"; |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
1192 |
if (AudioOutputDriver == "JACK") AudioOutputDriver = "Jack"; |
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
1193 |
// Check if there's one audio output device already created |
// Check if there's one audio output device already created |
1194 |
// for the intended audio driver type (AudioOutputDriver)... |
// for the intended audio driver type (AudioOutputDriver)... |
1195 |
AudioOutputDevice *pDevice = NULL; |
AudioOutputDevice *pDevice = NULL; |
1223 |
LSCPResultSet result; |
LSCPResultSet result; |
1224 |
try { |
try { |
1225 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1226 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1227 |
pSamplerChannel->SetMidiInputPort(MIDIPort); |
pSamplerChannel->SetMidiInputPort(MIDIPort); |
1228 |
} |
} |
1229 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1237 |
LSCPResultSet result; |
LSCPResultSet result; |
1238 |
try { |
try { |
1239 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1240 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1241 |
pSamplerChannel->SetMidiInputChannel((MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel); |
pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel); |
1242 |
} |
} |
1243 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1244 |
result.Error(e); |
result.Error(e); |
1251 |
LSCPResultSet result; |
LSCPResultSet result; |
1252 |
try { |
try { |
1253 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1254 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1255 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1256 |
|
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1257 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
|
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
|
1258 |
pSamplerChannel->SetMidiInputDevice(pDevice); |
pSamplerChannel->SetMidiInputDevice(pDevice); |
1259 |
} |
} |
1260 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1268 |
LSCPResultSet result; |
LSCPResultSet result; |
1269 |
try { |
try { |
1270 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1271 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1272 |
// Driver type name aliasing... |
// Driver type name aliasing... |
1273 |
if (MidiInputDriver == "ALSA") MidiInputDriver = "Alsa"; |
if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; |
1274 |
// Check if there's one MIDI input device already created |
// Check if there's one MIDI input device already created |
1275 |
// for the intended MIDI driver type (MidiInputDriver)... |
// for the intended MIDI driver type (MidiInputDriver)... |
1276 |
MidiInputDevice *pDevice = NULL; |
MidiInputDevice *pDevice = NULL; |
1288 |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
1289 |
// Make it with at least one initial port. |
// Make it with at least one initial port. |
1290 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1291 |
parameters["ports"]->SetValue("1"); |
parameters["PORTS"]->SetValue("1"); |
1292 |
} |
} |
1293 |
// Must have a device... |
// Must have a device... |
1294 |
if (pDevice == NULL) |
if (pDevice == NULL) |
1311 |
LSCPResultSet result; |
LSCPResultSet result; |
1312 |
try { |
try { |
1313 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1314 |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1315 |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1316 |
|
if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1317 |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1318 |
if (!pDevice) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputPort::midi_chan_t) MIDIChannel); |
|
pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (MidiInputDevice::MidiInputPort::midi_chan_t) MIDIChannel); |
|
1319 |
} |
} |
1320 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1321 |
result.Error(e); |
result.Error(e); |
1327 |
* Will be called by the parser to change the global volume factor on a |
* Will be called by the parser to change the global volume factor on a |
1328 |
* particular sampler channel. |
* particular sampler channel. |
1329 |
*/ |
*/ |
1330 |
String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) { |
String LSCPServer::SetVolume(double dVolume, uint uiSamplerChannel) { |
1331 |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
1332 |
LSCPResultSet result; |
LSCPResultSet result; |
1333 |
try { |
try { |
1334 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1335 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1336 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
1337 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
1338 |
pEngine->Volume(Volume); |
pEngine->Volume(dVolume); |
1339 |
} |
} |
1340 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1341 |
result.Error(e); |
result.Error(e); |
1351 |
LSCPResultSet result; |
LSCPResultSet result; |
1352 |
try { |
try { |
1353 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1354 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1355 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
Engine* pEngine = pSamplerChannel->GetEngine(); |
1356 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel"); |
1357 |
pEngine->Reset(); |
pEngine->Reset(); |
1358 |
} |
} |
1359 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1363 |
} |
} |
1364 |
|
|
1365 |
/** |
/** |
1366 |
|
* Will be called by the parser to reset the whole sampler. |
1367 |
|
*/ |
1368 |
|
String LSCPServer::ResetSampler() { |
1369 |
|
dmsg(2,("LSCPServer: ResetSampler()\n")); |
1370 |
|
pSampler->Reset(); |
1371 |
|
LSCPResultSet result; |
1372 |
|
return result.Produce(); |
1373 |
|
} |
1374 |
|
|
1375 |
|
/** |
1376 |
* Will be called by the parser to subscribe a client (frontend) on the |
* Will be called by the parser to subscribe a client (frontend) on the |
1377 |
* server for receiving event messages. |
* server for receiving event messages. |
1378 |
*/ |
*/ |
1398 |
return result.Produce(); |
return result.Produce(); |
1399 |
} |
} |
1400 |
|
|
1401 |
|
static int select_callback(void * lscpResultSet, int argc, |
1402 |
// Instrument loader constructor. |
char **argv, char **azColName) |
|
LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument) |
|
|
: Thread(false, 0, -4) |
|
1403 |
{ |
{ |
1404 |
this->pEngine = pEngine; |
LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet; |
1405 |
this->Filename = Filename; |
resultSet->Add(argc, argv); |
1406 |
this->uiInstrument = uiInstrument; |
return 0; |
1407 |
} |
} |
1408 |
|
|
1409 |
// Instrument loader process. |
String LSCPServer::QueryDatabase(String query) { |
1410 |
int LSCPLoadInstrument::Main() |
LSCPResultSet result; |
1411 |
{ |
#ifdef HAVE_SQLITE3 |
1412 |
try { |
char* zErrMsg = NULL; |
1413 |
pEngine->LoadInstrument(Filename.c_str(), uiInstrument); |
sqlite3 *db; |
1414 |
|
String selectStr = "SELECT " + query; |
1415 |
|
|
1416 |
|
int rc = sqlite3_open("linuxsampler.db", &db); |
1417 |
|
if (rc == SQLITE_OK) |
1418 |
|
{ |
1419 |
|
rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg); |
1420 |
|
} |
1421 |
|
if ( rc != SQLITE_OK ) |
1422 |
|
{ |
1423 |
|
result.Error(String(zErrMsg), rc); |
1424 |
} |
} |
1425 |
|
sqlite3_close(db); |
1426 |
|
#else |
1427 |
|
result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0); |
1428 |
|
#endif |
1429 |
|
return result.Produce(); |
1430 |
|
} |
1431 |
|
|
1432 |
|
/** |
1433 |
|
* Will be called by the parser to enable or disable echo mode; if echo |
1434 |
|
* mode is enabled, all commands from the client will (immediately) be |
1435 |
|
* echoed back to the client. |
1436 |
|
*/ |
1437 |
|
String LSCPServer::SetEcho(yyparse_param_t* pSession, double boolean_value) { |
1438 |
|
dmsg(2,("LSCPServer: SetEcho(val=%f)\n", boolean_value)); |
1439 |
|
LSCPResultSet result; |
1440 |
|
try { |
1441 |
|
if (boolean_value == 0) pSession->bVerbose = false; |
1442 |
|
else if (boolean_value == 1) pSession->bVerbose = true; |
1443 |
|
else throw LinuxSamplerException("Not a boolean value, must either be 0 or 1"); |
1444 |
|
} |
1445 |
catch (LinuxSamplerException e) { |
catch (LinuxSamplerException e) { |
1446 |
e.PrintMessage(); |
result.Error(e); |
1447 |
} |
} |
1448 |
|
return result.Produce(); |
|
// Always re-enable the engine. |
|
|
pEngine->Enable(); |
|
|
|
|
|
// FIXME: Shoot ourselves on the foot? |
|
|
delete this; |
|
1449 |
} |
} |