/[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 226 - (hide annotations) (download)
Wed Aug 25 22:00:33 2004 UTC (19 years, 7 months ago) by schoenebeck
File size: 59423 byte(s)
* ALSA MIDI driver: create one MIDI port by default, implemented parameter
  info for parameter 'ALSA_SEQ_BINDINGS'
* ALSA audio driver: implemented parameter info for driver parameters
  'FRAGMENTS' and 'FRAGMENTSIZE'
* JACK audio driver: fixed creation of channels on device creation, channel
  parameter 'NAME' now actually updates the respective JACK port name,
  implemented channel parameter 'JACK_BINDINGS' (as well as its parameter
  info)
* src/network/lscpserver.cpp: fixed commands
  "GET MIDI_INPUT_DRIVER_PARAMETER INFO" and
  "GET AUDIO_OUTPUT_DRIVER_PARAMETER  INFO", fixed backward compatibility
  for "SET AUDIO_OUTPUT_TYPE" and "SET MIDI_INPUT_TYPE" commands
* src/networ/lscp.y: added comma character (',') to symbol 'char'
* src/drivers/DeviceParameter.cpp: fixed methods RangeMin(), RangeMax() in
  class DeviceCreationParameterInt which returned wrong values

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

  ViewVC Help
Powered by ViewVC