/[svn]/linuxsampler/trunk/src/network/lscpserver.cpp
ViewVC logotype

Annotation of /linuxsampler/trunk/src/network/lscpserver.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 392 - (hide annotations) (download)
Sat Feb 19 02:40:24 2005 UTC (19 years, 1 month ago) by schoenebeck
File size: 60760 byte(s)
* fixed possibility that memory got not locked
* immediately set instrument status when calling LOAD INSTUMENT NON_MODAL

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

  ViewVC Help
Powered by ViewVC