/[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 397 by senkov, Mon Feb 21 04:28:50 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    #ifdef HAVE_SQLITE3
30    #include "sqlite3.h"
31    #endif
32    
33  #include "../engines/gig/Engine.h"  #include "../engines/gig/Engine.h"
34  #include "../drivers/audio/AudioOutputDeviceFactory.h"  #include "../drivers/audio/AudioOutputDeviceFactory.h"
# Line 52  Mutex LSCPServer::NotifyBufferMutex = Mu Line 58  Mutex LSCPServer::NotifyBufferMutex = Mu
58  Mutex LSCPServer::SubscriptionMutex = Mutex();  Mutex LSCPServer::SubscriptionMutex = Mutex();
59  Mutex LSCPServer::RTNotifyMutex = Mutex();  Mutex LSCPServer::RTNotifyMutex = Mutex();
60    
61  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) {  LSCPServer::LSCPServer(Sampler* pSampler) : Thread(true, false, 0, -4) {
62      this->pSampler = pSampler;      this->pSampler = pSampler;
63      LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS");      LSCPEvent::RegisterEvent(LSCPEvent::event_channels, "CHANNELS");
64      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT");
# Line 445  String LSCPServer::LoadInstrument(String Line 451  String LSCPServer::LoadInstrument(String
451      LSCPResultSet result;      LSCPResultSet result;
452      try {      try {
453          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
454          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
455          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
456          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");
457          if (!pSamplerChannel->GetAudioOutputDevice())          if (!pSamplerChannel->GetAudioOutputDevice())
458              throw LinuxSamplerException("No audio output device on channel");              throw LinuxSamplerException("No audio output device connected to sampler channel");
459          if (bBackground) {          if (bBackground) {
460              LSCPLoadInstrument *pLoadInstrument = new LSCPLoadInstrument(pEngine, Filename.c_str(), uiInstrument);              InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngine);
461              pLoadInstrument->StartThread();          }
462            else {
463                // tell the engine which instrument to load
464                pEngine->PrepareLoadInstrument(Filename.c_str(), uiInstrument);
465                // actually start to load the instrument (blocks until completed)
466                pEngine->LoadInstrument();
467          }          }
         else pEngine->LoadInstrument(Filename.c_str(), uiInstrument);  
468      }      }
469      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
470           result.Error(e);           result.Error(e);
# Line 473  String LSCPServer::LoadEngine(String Eng Line 483  String LSCPServer::LoadEngine(String Eng
483          if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig;          if ((EngineName == "GigEngine") || (EngineName == "gig")) type = Engine::type_gig;
484          else throw LinuxSamplerException("Unknown engine type");          else throw LinuxSamplerException("Unknown engine type");
485          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
486          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
487          LockRTNotify();          LockRTNotify();
488          pSamplerChannel->LoadEngine(type);          pSamplerChannel->LoadEngine(type);
489          UnlockRTNotify();          UnlockRTNotify();
# Line 572  String LSCPServer::GetChannelInfo(uint u Line 582  String LSCPServer::GetChannelInfo(uint u
582      LSCPResultSet result;      LSCPResultSet result;
583      try {      try {
584          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
585          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
586          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
587    
588          //Defaults values          //Defaults values
589          String EngineName = "NONE";          String EngineName = "NONE";
590          float Volume = 0.0f;          float Volume = 0.0f;
591          String InstrumentFileName = "NONE";          String InstrumentFileName = "NONE";
592            String InstrumentName = "NONE";
593          int InstrumentIndex = -1;          int InstrumentIndex = -1;
594          int InstrumentStatus = -1;          int InstrumentStatus = -1;
595          int AudioOutputChannels = 0;          int AudioOutputChannels = 0;
# Line 591  String LSCPServer::GetChannelInfo(uint u Line 602  String LSCPServer::GetChannelInfo(uint u
602              InstrumentStatus = pEngine->InstrumentStatus();              InstrumentStatus = pEngine->InstrumentStatus();
603              InstrumentIndex = pEngine->InstrumentIndex();              InstrumentIndex = pEngine->InstrumentIndex();
604              if (InstrumentIndex != -1)              if (InstrumentIndex != -1)
605                {
606                  InstrumentFileName = pEngine->InstrumentFileName();                  InstrumentFileName = pEngine->InstrumentFileName();
607                    InstrumentName = pEngine->InstrumentName();
608                }
609              for (int chan = 0; chan < pEngine->Channels(); chan++) {              for (int chan = 0; chan < pEngine->Channels(); chan++) {
610                  if (AudioRouting != "") AudioRouting += ",";                  if (AudioRouting != "") AudioRouting += ",";
611                  AudioRouting += ToString(pEngine->OutputChannel(chan));                  AudioRouting += ToString(pEngine->OutputChannel(chan));
# Line 613  String LSCPServer::GetChannelInfo(uint u Line 627  String LSCPServer::GetChannelInfo(uint u
627    
628          result.Add("INSTRUMENT_FILE", InstrumentFileName);          result.Add("INSTRUMENT_FILE", InstrumentFileName);
629          result.Add("INSTRUMENT_NR", InstrumentIndex);          result.Add("INSTRUMENT_NR", InstrumentIndex);
630            result.Add("INSTRUMENT_NAME", InstrumentName);
631          result.Add("INSTRUMENT_STATUS", InstrumentStatus);          result.Add("INSTRUMENT_STATUS", InstrumentStatus);
632      }      }
633      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 630  String LSCPServer::GetVoiceCount(uint ui Line 645  String LSCPServer::GetVoiceCount(uint ui
645      LSCPResultSet result;      LSCPResultSet result;
646      try {      try {
647          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
648          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
649          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
650          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");
651          result.Add(pEngine->VoiceCount());          result.Add(pEngine->VoiceCount());
652      }      }
653      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 650  String LSCPServer::GetStreamCount(uint u Line 665  String LSCPServer::GetStreamCount(uint u
665      LSCPResultSet result;      LSCPResultSet result;
666      try {      try {
667          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
668          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
669          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
670          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");
671          result.Add(pEngine->DiskStreamCount());          result.Add(pEngine->DiskStreamCount());
672      }      }
673      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 670  String LSCPServer::GetBufferFill(fill_re Line 685  String LSCPServer::GetBufferFill(fill_re
685      LSCPResultSet result;      LSCPResultSet result;
686      try {      try {
687          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
688          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
689          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
690          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");
691          if (!pEngine->DiskStreamSupported())          if (!pEngine->DiskStreamSupported())
692              result.Add("NA");              result.Add("NA");
693          else {          else {
# Line 962  String LSCPServer::GetAudioOutputChannel Line 977  String LSCPServer::GetAudioOutputChannel
977    
978          // get audio channel          // get audio channel
979          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
980          if (!pChannel) throw LinuxSamplerException("Audio ouotput device does not have channel " + ToString(ChannelId) + ".");          if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
981    
982          // return the values of all audio channel parameters          // return the values of all audio channel parameters
983          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 1021  String LSCPServer::GetAudioOutputChannel Line 1036  String LSCPServer::GetAudioOutputChannel
1036    
1037          // get audio channel          // get audio channel
1038          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1039          if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");          if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
1040    
1041          // get desired audio channel parameter          // get desired audio channel parameter
1042          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 1054  String LSCPServer::SetAudioOutputChannel Line 1069  String LSCPServer::SetAudioOutputChannel
1069    
1070          // get audio channel          // get audio channel
1071          AudioChannel* pChannel = pDevice->Channel(ChannelId);          AudioChannel* pChannel = pDevice->Channel(ChannelId);
1072          if (!pChannel) throw LinuxSamplerException("Audio output device does not have channel " + ToString(ChannelId) + ".");          if (!pChannel) throw LinuxSamplerException("Audio output device does not have audio channel " + ToString(ChannelId) + ".");
1073    
1074          // get desired audio channel parameter          // get desired audio channel parameter
1075          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();          std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters();
# Line 1137  String LSCPServer::SetAudioOutputChannel Line 1152  String LSCPServer::SetAudioOutputChannel
1152      LSCPResultSet result;      LSCPResultSet result;
1153      try {      try {
1154          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1155          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1156          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
1157          if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel));          if (!pEngine) throw LinuxSamplerException("No engine deployed on sampler channel " + ToString(uiSamplerChannel));
1158          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          if (!pSamplerChannel->GetAudioOutputDevice()) throw LinuxSamplerException("No audio output device connected to sampler channel " + ToString(uiSamplerChannel));
         if (!devices.count(ChannelAudioOutputChannel)) throw LinuxSamplerException("There is no audio output device with index " + ToString(ChannelAudioOutputChannel));  
1159          pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);          pEngine->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel);
1160      }      }
1161      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1155  String LSCPServer::SetAudioOutputDevice( Line 1169  String LSCPServer::SetAudioOutputDevice(
1169      LSCPResultSet result;      LSCPResultSet result;
1170      try {      try {
1171          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1172          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1173          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
1174          if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));          if (!devices.count(AudioDeviceId)) throw LinuxSamplerException("There is no audio output device with index " + ToString(AudioDeviceId));
1175          AudioOutputDevice* pDevice = devices[AudioDeviceId];          AudioOutputDevice* pDevice = devices[AudioDeviceId];
# Line 1172  String LSCPServer::SetAudioOutputType(St Line 1186  String LSCPServer::SetAudioOutputType(St
1186      LSCPResultSet result;      LSCPResultSet result;
1187      try {      try {
1188          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1189          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1190          // Driver type name aliasing...          // Driver type name aliasing...
1191          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";          if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA";
1192          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";          if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK";
# Line 1209  String LSCPServer::SetMIDIInputPort(uint Line 1223  String LSCPServer::SetMIDIInputPort(uint
1223      LSCPResultSet result;      LSCPResultSet result;
1224      try {      try {
1225          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1226          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1227          pSamplerChannel->SetMidiInputPort(MIDIPort);          pSamplerChannel->SetMidiInputPort(MIDIPort);
1228      }      }
1229      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1223  String LSCPServer::SetMIDIInputChannel(u Line 1237  String LSCPServer::SetMIDIInputChannel(u
1237      LSCPResultSet result;      LSCPResultSet result;
1238      try {      try {
1239          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1240          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1241          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);          pSamplerChannel->SetMidiInputChannel((MidiInputPort::midi_chan_t) MIDIChannel);
1242      }      }
1243      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1237  String LSCPServer::SetMIDIInputDevice(ui Line 1251  String LSCPServer::SetMIDIInputDevice(ui
1251      LSCPResultSet result;      LSCPResultSet result;
1252      try {      try {
1253          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1254          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1255          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices();
1256          if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));          if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1257          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
# Line 1254  String LSCPServer::SetMIDIInputType(Stri Line 1268  String LSCPServer::SetMIDIInputType(Stri
1268      LSCPResultSet result;      LSCPResultSet result;
1269      try {      try {
1270          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1271          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1272          // Driver type name aliasing...          // Driver type name aliasing...
1273          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";          if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA";
1274          // Check if there's one MIDI input device already created          // Check if there's one MIDI input device already created
# Line 1297  String LSCPServer::SetMIDIInput(uint MID Line 1311  String LSCPServer::SetMIDIInput(uint MID
1311      LSCPResultSet result;      LSCPResultSet result;
1312      try {      try {
1313          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1314          if (!pSamplerChannel) throw LinuxSamplerException("Invalid channel number " + ToString(uiSamplerChannel));          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1315          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();          std::map<uint, MidiInputDevice*> devices =  pSampler->GetMidiInputDevices();
1316          if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));          if (!devices.count(MIDIDeviceId)) throw LinuxSamplerException("There is no MIDI input device with index " + ToString(MIDIDeviceId));
1317          MidiInputDevice* pDevice = devices[MIDIDeviceId];          MidiInputDevice* pDevice = devices[MIDIDeviceId];
# Line 1318  String LSCPServer::SetVolume(double dVol Line 1332  String LSCPServer::SetVolume(double dVol
1332      LSCPResultSet result;      LSCPResultSet result;
1333      try {      try {
1334          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1335          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1336          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
1337          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");
1338          pEngine->Volume(dVolume);          pEngine->Volume(dVolume);
1339      }      }
1340      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1337  String LSCPServer::ResetChannel(uint uiS Line 1351  String LSCPServer::ResetChannel(uint uiS
1351      LSCPResultSet result;      LSCPResultSet result;
1352      try {      try {
1353          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
1354          if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds");          if (!pSamplerChannel) throw LinuxSamplerException("Invalid sampler channel number " + ToString(uiSamplerChannel));
1355          Engine* pEngine = pSamplerChannel->GetEngine();          Engine* pEngine = pSamplerChannel->GetEngine();
1356          if (!pEngine) throw LinuxSamplerException("No engine loaded on channel");          if (!pEngine) throw LinuxSamplerException("No engine loaded on sampler channel");
1357          pEngine->Reset();          pEngine->Reset();
1358      }      }
1359      catch (LinuxSamplerException e) {      catch (LinuxSamplerException e) {
# Line 1384  String LSCPServer::UnsubscribeNotificati Line 1398  String LSCPServer::UnsubscribeNotificati
1398      return result.Produce();      return result.Produce();
1399  }  }
1400    
1401    static int select_callback(void * lscpResultSet, int argc,
1402                            char **argv, char **azColName)
1403    {
1404        LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet;
1405        resultSet->Add(argc, argv);
1406        return 0;
1407    }
1408    
1409    String LSCPServer::QueryDatabase(String query) {
1410        LSCPResultSet result;
1411    #ifdef HAVE_SQLITE3
1412        char* zErrMsg = NULL;
1413        sqlite3 *db;
1414        String selectStr = "SELECT " + query;
1415    
1416        int rc = sqlite3_open("linuxsampler.db", &db);
1417        if (rc == SQLITE_OK)
1418        {
1419                rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg);
1420        }
1421        if ( rc != SQLITE_OK )
1422        {
1423                //result.Error(String(zErrMsg), rc);
1424                result.Error(selectStr, 666);
1425        }
1426        sqlite3_close(db);
1427    #else
1428        result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0);
1429    #endif
1430        return result.Produce();
1431    }
1432    
1433  /**  /**
1434   * 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
1435   * 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 1448  String LSCPServer::SetEcho(yyparse_param
1448      }      }
1449      return result.Produce();      return result.Produce();
1450  }  }
   
 // 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.397

  ViewVC Help
Powered by ViewVC