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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 360 by senkov, Mon Feb 7 00:19:30 2005 UTC revision 411 by schoenebeck, Sat Feb 26 02:01:14 2005 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6     *   Copyright (C) 2005 Christian Schoenebeck                              *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
10   *   the Free Software Foundation; either version 2 of the License, or     *   *   the Free Software Foundation; either version 2 of the License, or     *
11   *   (at your option) any later version.                                   *   *   (at your option) any later version.                                   *
12   *                                                                         *   *                                                                         *
13   *   This program is distributed in the hope that it will be useful,       *   *   This library is distributed in the hope that it will be useful,       *
14   *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *   *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16   *   GNU General Public License for more details.                          *   *   GNU General Public License for more details.                          *
17   *                                                                         *   *                                                                         *
18   *   You should have received a copy of the GNU General Public License     *   *   You should have received a copy of the GNU General Public License     *
19   *   along with this program; if not, write to the Free Software           *   *   along with this library; if not, write to the Free Software           *
20   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
21   *   MA  02111-1307  USA                                                   *   *   MA  02111-1307  USA                                                   *
22   ***************************************************************************/   ***************************************************************************/
# Line 23  Line 24 
24  #include "lscpserver.h"  #include "lscpserver.h"
25  #include "lscpresultset.h"  #include "lscpresultset.h"
26  #include "lscpevent.h"  #include "lscpevent.h"
27    //#include "../common/global.h"
28    
29  #include "../engines/gig/Engine.h"  #include <fcntl.h>
30    
31    #if HAVE_SQLITE3
32    # include "sqlite3.h"
33    #endif
34    
35    #include "../engines/EngineFactory.h"
36  #include "../drivers/audio/AudioOutputDeviceFactory.h"  #include "../drivers/audio/AudioOutputDeviceFactory.h"
37  #include "../drivers/midi/MidiInputDeviceFactory.h"  #include "../drivers/midi/MidiInputDeviceFactory.h"
38    
# Line 52  Mutex LSCPServer::NotifyBufferMutex = Mu Line 60  Mutex LSCPServer::NotifyBufferMutex = Mu
60  Mutex LSCPServer::SubscriptionMutex = Mutex();  Mutex LSCPServer::SubscriptionMutex = Mutex();
61  Mutex LSCPServer::RTNotifyMutex = Mutex();  Mutex LSCPServer::RTNotifyMutex = Mutex();
62    
63  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(true, false, 0, -4) {
64      this->pSampler = pSampler;      this->pSampler = pSampler;
65      LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS");      LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS");
66      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");
# Line 445  String LSCPServer::LoadInstrument(String Line 453  String LSCPServer::LoadInstrument(String
453      LSCPResultSet result;      LSCPResultSet result;
454      try {      try {
455          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
456          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
457          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
458          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel yet");
459          if (!pSamplerChannel->GetAudioOutputDevice())          if (!pSamplerChannel->GetAudioOutputDevice())
460              throw LinuxSamplerException("No audio output device on channel");              throw LinuxSamplerException("No audio output device connected to sampler channel");
461          if (bBackground) {          if (bBackground) {
462              LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel);
463              pLoadInstrument->StartThread();          }
464            else {
465                // tell the engine channel which instrument to load
466                pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument);
467                // actually start to load the instrument (blocks until completed)
468                pEngineChannel->LoadInstrument();
469          }          }
         else pEngine->LoadInstrument(Filename.c_str(), uiInstrument);  
470      }      }
471      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
472           result.Error(e);           result.Error(e);
# Line 463  String LSCPServer::LoadInstrument(String Line 475  String LSCPServer::LoadInstrument(String
475  }  }
476    
477  /**  /**
478   * Will be called by the parser to load and deploy an engine.   * Will be called by the parser to assign a sampler engine type to a
479     * sampler channel.
480   */   */
481  String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) {  String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) {
482      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));      dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel));
483      LSCPResultSet result;      LSCPResultSet result;
484      try {      try {        
         Engine::type_t type;  
         if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig;  
         else throw LinuxSamplerException("Unknown engine type");  
485          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
486          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
487          LockRTNotify();          LockRTNotify();
488          pSamplerChannel->LoadEngine(type);          pSamplerChannel->SetEngineType(EngineName);
489          UnlockRTNotify();          UnlockRTNotify();
490      }      }
491      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 543  String LSCPServer::GetAvailableEngines() Line 553  String LSCPServer::GetAvailableEngines()
553  }  }
554    
555  /**  /**
556   * Will be called by the parser to get descriptions for a particular engine.   * Will be called by the parser to get descriptions for a particular
557     * sampler engine.
558   */   */
559  String LSCPServer::GetEngineInfo(String EngineName) {  String LSCPServer::GetEngineInfo(String EngineName) {
560      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));      dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str()));
561      LSCPResultSet result;      LSCPResultSet result;
562      try {      try {
563          if ((EngineName == "GigEngine") || (EngineName == "gig")) {          Engine* pEngine = EngineFactory::Create(EngineName);
564              Engine* pEngine = new LinuxSampler::gig::Engine;          result.Add("DESCRIPTION", pEngine->Description());
565              result.Add("DESCRIPTION", pEngine->Description());          result.Add("VERSION",     pEngine->Version());
566              result.Add("VERSION",     pEngine->Version());          delete pEngine;
             delete pEngine;  
         }  
         else throw LinuxSamplerException("Unknown engine type");  
567      }      }
568      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
569           result.Error(e);           result.Error(e);
# Line 572  String LSCPServer::GetChannelInfo(uint u Line 580  String LSCPServer::GetChannelInfo(uint u
580      LSCPResultSet result;      LSCPResultSet result;
581      try {      try {
582          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
583          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
584          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
585    
586          //Defaults values          //Defaults values
587          String EngineName = "NONE";          String EngineName = "NONE";
588          float Volume = 0.0f;          float Volume = 0.0f;
589          String InstrumentFileName = "NONE";          String InstrumentFileName = "NONE";
590            String InstrumentName = "NONE";
591          int InstrumentIndex = -1;          int InstrumentIndex = -1;
592          int InstrumentStatus = -1;          int InstrumentStatus = -1;
593          int AudioOutputChannels = 0;          int AudioOutputChannels = 0;
594          String AudioRouting;          String AudioRouting;
595    
596          if (pEngine) {          if (pEngineChannel) {                              
597              EngineName =  pEngine->EngineName();              EngineName          = pEngineChannel->GetEngine()->EngineName();
598              AudioOutputChannels = pEngine->Channels();              AudioOutputChannels = pEngineChannel->Channels();
599              Volume = pEngine->Volume();              Volume              = pEngineChannel->Volume();
600              InstrumentStatus = pEngine->InstrumentStatus();              InstrumentStatus    = pEngineChannel->InstrumentStatus();
601              InstrumentIndex = pEngine->InstrumentIndex();              InstrumentIndex     = pEngineChannel->InstrumentIndex();
602              if (InstrumentIndex != -1)              if (InstrumentIndex != -1) {
603                  InstrumentFileName = pEngine->InstrumentFileName();                  InstrumentFileName = pEngineChannel->InstrumentFileName();
604              for (int chan = 0; chan < pEngine->Channels(); chan++) {                  InstrumentName     = pEngineChannel->InstrumentName();
605                }
606                for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
607                  if (AudioRouting != "") AudioRouting += ",";                  if (AudioRouting != "") AudioRouting += ",";
608                  AudioRouting += ToString(pEngine->OutputChannel(chan));                  AudioRouting += ToString(pEngineChannel->OutputChannel(chan));
609              }              }
610          }          }
611    
# Line 613  String LSCPServer::GetChannelInfo(uint u Line 624  String LSCPServer::GetChannelInfo(uint u
624    
625          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
626          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
627            result.Add("INSTRUMENT_NAME", InstrumentName);
628          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
629      }      }
630      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 630  String LSCPServer::GetVoiceCount(uint ui Line 642  String LSCPServer::GetVoiceCount(uint ui
642      LSCPResultSet result;      LSCPResultSet result;
643      try {      try {
644          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
645          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
646          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
647          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine loaded on sampler channel");
648          result.Add(pEngine->VoiceCount());          result.Add(pEngineChannel->GetEngine()->VoiceCount());
649      }      }
650      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
651           result.Error(e);           result.Error(e);
# Line 650  String LSCPServer::GetStreamCount(uint u Line 662  String LSCPServer::GetStreamCount(uint u
662      LSCPResultSet result;      LSCPResultSet result;
663      try {      try {
664          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
665          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
666          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
667          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
668          result.Add(pEngine->DiskStreamCount());          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
669      }      }
670      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
671           result.Error(e);           result.Error(e);
# Line 670  String LSCPServer::GetBufferFill(fill_re Line 682  String LSCPServer::GetBufferFill(fill_re
682      LSCPResultSet result;      LSCPResultSet result;
683      try {      try {
684          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
685          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
686          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
687          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
688          if (!pEngine->DiskStreamSupported())          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
             result.Add("NA");  
689          else {          else {
690              switch (ResponseType) {              switch (ResponseType) {
691                  case fill_response_bytes:                  case fill_response_bytes:
692                      result.Add(pEngine->DiskStreamBufferFillBytes());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillBytes());
693                      break;                      break;
694                  case fill_response_percentage:                  case fill_response_percentage:
695                      result.Add(pEngine->DiskStreamBufferFillPercentage());                      result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage());
696                      break;                      break;
697                  default:                  default:
698                      throw LinuxSamplerException("Unknown fill response type");                      throw LinuxSamplerException("Unknown fill response type");
699              }              }
# Line 962  String LSCPServer::GetAudioOutputChannel Line 973  String LSCPServer::GetAudioOutputChannel
973    
974          // get audio channel          // get audio channel
975          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
976          if (!pChannel) throw LinuxSamplerException("Audio ouotput device does not have channel " + ToString(ChannelId) + ".");          if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
977    
978          // return the values of all audio channel parameters          // return the values of all audio channel parameters
979          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 1021  String LSCPServer::GetAudioOutputChannel Line 1032  String LSCPServer::GetAudioOutputChannel
1032    
1033          // get audio channel          // get audio channel
1034          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1035          if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");          if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
1036    
1037          // get desired audio channel parameter          // get desired audio channel parameter
1038          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 1054  String LSCPServer::SetAudioOutputChannel Line 1065  String LSCPServer::SetAudioOutputChannel
1065    
1066          // get audio channel          // get audio channel
1067          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1068          if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");          if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
1069    
1070          // get desired audio channel parameter          // get desired audio channel parameter
1071          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 1137  String LSCPServer::SetAudioOutputChannel Line 1148  String LSCPServer::SetAudioOutputChannel
1148      LSCPResultSet result;      LSCPResultSet result;
1149      try {      try {
1150          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1151          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1152          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1153          if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel));          if (!pEngineChannel) throw LinuxSamplerException("No engine type yet assigned to sampler channel " + ToString(uiSamplerChannel));
1154          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel));
1155          if (!devices.count(ChannelAudioOutputChannel)) throw LinuxSamplerException("There is no audio output device with index " + ToString(ChannelAudioOutputChannel));          pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
         pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);  
1156      }      }
1157      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1158           result.Error(e);           result.Error(e);
# Line 1155  String LSCPServer::SetAudioOutputDevice( Line 1165  String LSCPServer::SetAudioOutputDevice(
1165      LSCPResultSet result;      LSCPResultSet result;
1166      try {      try {
1167          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1168          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1169          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1170          if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));          if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));
1171          AudioOutputDevice* pDevice = devices[AudioDeviceId];          AudioOutputDevice* pDevice = devices[AudioDeviceId];
# Line 1172  String LSCPServer::SetAudioOutputType(St Line 1182  String LSCPServer::SetAudioOutputType(St
1182      LSCPResultSet result;      LSCPResultSet result;
1183      try {      try {
1184          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1185          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1186          // Driver type name aliasing...          // Driver type name aliasing...
1187          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1188          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
# Line 1209  String LSCPServer::SetMIDIInputPort(uint Line 1219  String LSCPServer::SetMIDIInputPort(uint
1219      LSCPResultSet result;      LSCPResultSet result;
1220      try {      try {
1221          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1222          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1223          pSamplerChannel->SetMidiInputPort(MIDIPort);          pSamplerChannel->SetMidiInputPort(MIDIPort);
1224      }      }
1225      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1223  String LSCPServer::SetMIDIInputChannel(u Line 1233  String LSCPServer::SetMIDIInputChannel(u
1233      LSCPResultSet result;      LSCPResultSet result;
1234      try {      try {
1235          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1236          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1237          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);
1238      }      }
1239      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1237  String LSCPServer::SetMIDIInputDevice(ui Line 1247  String LSCPServer::SetMIDIInputDevice(ui
1247      LSCPResultSet result;      LSCPResultSet result;
1248      try {      try {
1249          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1250          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1251          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1252          if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));          if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1253          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
# Line 1254  String LSCPServer::SetMIDIInputType(Stri Line 1264  String LSCPServer::SetMIDIInputType(Stri
1264      LSCPResultSet result;      LSCPResultSet result;
1265      try {      try {
1266          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1267          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1268          // Driver type name aliasing...          // Driver type name aliasing...
1269          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1270          // Check if there's one MIDI input device already created          // Check if there's one MIDI input device already created
# Line 1297  String LSCPServer::SetMIDIInput(uint MID Line 1307  String LSCPServer::SetMIDIInput(uint MID
1307      LSCPResultSet result;      LSCPResultSet result;
1308      try {      try {
1309          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1310          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1311          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1312          if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));          if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1313          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
# Line 1318  String LSCPServer::SetVolume(double dVol Line 1328  String LSCPServer::SetVolume(double dVol
1328      LSCPResultSet result;      LSCPResultSet result;
1329      try {      try {
1330          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1331          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1332          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1333          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1334          pEngine->Volume(dVolume);          pEngineChannel->Volume(dVolume);
1335      }      }
1336      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1337           result.Error(e);           result.Error(e);
# Line 1337  String LSCPServer::ResetChannel(uint uiS Line 1347  String LSCPServer::ResetChannel(uint uiS
1347      LSCPResultSet result;      LSCPResultSet result;
1348      try {      try {
1349          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1350          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1351          Engine* pEngine = pSamplerChannel->GetEngine();          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
1352          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngineChannel) throw LinuxSamplerException("No engine type assigned to sampler channel");
1353          pEngine->Reset();          pEngineChannel->GetEngine()->Reset();
1354      }      }
1355      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
1356           result.Error(e);           result.Error(e);
# Line 1384  String LSCPServer::UnsubscribeNotificati Line 1394  String LSCPServer::UnsubscribeNotificati
1394      return result.Produce();      return result.Produce();
1395  }  }
1396    
1397    static int select_callback(void * lscpResultSet, int argc,
1398                            char **argv, char **azColName)
1399    {
1400        LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet;
1401        resultSet->Add(argc, argv);
1402        return 0;
1403    }
1404    
1405    String LSCPServer::QueryDatabase(String query) {
1406        LSCPResultSet result;
1407    #if HAVE_SQLITE3
1408        char* zErrMsg = NULL;
1409        sqlite3 *db;
1410        String selectStr = "SELECT " + query;
1411    
1412        int rc = sqlite3_open("linuxsampler.db", &db);
1413        if (rc == SQLITE_OK)
1414        {
1415                rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg);
1416        }
1417        if ( rc != SQLITE_OK )
1418        {
1419                result.Error(String(zErrMsg), rc);
1420        }
1421        sqlite3_close(db);
1422    #else
1423        result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0);
1424    #endif
1425        return result.Produce();
1426    }
1427    
1428  /**  /**
1429   * Will be called by the parser to enable or disable echo mode; if echo   * Will be called by the parser to enable or disable echo mode; if echo
1430   * mode is enabled, all commands from the client will (immediately) be   * mode is enabled, all commands from the client will (immediately) be
# Line 1402  String LSCPServer::SetEcho(yyparse_param Line 1443  String LSCPServer::SetEcho(yyparse_param
1443      }      }
1444      return result.Produce();      return result.Produce();
1445  }  }
   
 // Instrument loader constructor.  
 LSCPLoadInstrument::LSCPLoadInstrument(Engine* pEngine, String Filename, uint uiInstrument)  
     : Thread(false, 0, -4)  
 {  
     this->pEngine = pEngine;  
     this->Filename = Filename;  
     this->uiInstrument = uiInstrument;  
 }  
   
 // Instrument loader process.  
 int LSCPLoadInstrument::Main()  
 {  
     try {  
         pEngine->LoadInstrument(Filename.c_str(), uiInstrument);  
     }  
   
     catch (LinuxSamplerException e) {  
         e.PrintMessage();  
     }  
   
     // Always re-enable the engine.  
     pEngine->Enable();  
   
     // FIXME: Shoot ourselves on the foot?  
     delete this;  
 }  

Legend:
Removed from v.360  
changed lines
  Added in v.411

  ViewVC Help
Powered by ViewVC