/[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 1537 by senoner, Mon Dec 3 18:30:47 2007 UTC revision 1800 by schoenebeck, Sun Dec 7 01:26:46 2008 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 - 2007 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2008 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This library 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  *
# Line 21  Line 21 
21   *   MA  02111-1307  USA                                                   *   *   MA  02111-1307  USA                                                   *
22   ***************************************************************************/   ***************************************************************************/
23    
24    #include <algorithm>
25    #include <string>
26    
27  #include "lscpserver.h"  #include "lscpserver.h"
28  #include "lscpresultset.h"  #include "lscpresultset.h"
29  #include "lscpevent.h"  #include "lscpevent.h"
# Line 40  Line 43 
43  #include "../drivers/audio/AudioOutputDeviceFactory.h"  #include "../drivers/audio/AudioOutputDeviceFactory.h"
44  #include "../drivers/midi/MidiInputDeviceFactory.h"  #include "../drivers/midi/MidiInputDeviceFactory.h"
45    
46    namespace LinuxSampler {
47    
48  /**  /**
49   * Returns a copy of the given string where all special characters are   * Returns a copy of the given string where all special characters are
# Line 101  Mutex LSCPServer::NotifyBufferMutex = Mu Line 105  Mutex LSCPServer::NotifyBufferMutex = Mu
105  Mutex LSCPServer::SubscriptionMutex = Mutex();  Mutex LSCPServer::SubscriptionMutex = Mutex();
106  Mutex LSCPServer::RTNotifyMutex = Mutex();  Mutex LSCPServer::RTNotifyMutex = Mutex();
107    
108  LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4) {  LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4), eventHandler(this) {
109      SocketAddress.sin_family      = AF_INET;      SocketAddress.sin_family      = AF_INET;
110      SocketAddress.sin_addr.s_addr = addr;      SocketAddress.sin_addr.s_addr = addr;
111      SocketAddress.sin_port        = port;      SocketAddress.sin_port        = port;
# Line 127  LSCPServer::LSCPServer(Sampler* pSampler Line 131  LSCPServer::LSCPServer(Sampler* pSampler
131      LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO");
132      LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO");
133      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
134        LSCPEvent::RegisterEvent(LSCPEvent::event_total_stream_count, "TOTAL_STREAM_COUNT");
135      LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");
136      LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO");
137        LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI");
138        LSCPEvent::RegisterEvent(LSCPEvent::event_device_midi, "DEVICE_MIDI");
139      hSocket = -1;      hSocket = -1;
140  }  }
141    
# Line 140  LSCPServer::~LSCPServer() { Line 147  LSCPServer::~LSCPServer() {
147  #endif  #endif
148  }  }
149    
150    LSCPServer::EventHandler::EventHandler(LSCPServer* pParent) {
151        this->pParent = pParent;
152    }
153    
154    LSCPServer::EventHandler::~EventHandler() {
155        std::vector<midi_listener_entry> l = channelMidiListeners;
156        channelMidiListeners.clear();
157        for (int i = 0; i < l.size(); i++)
158            delete l[i].pMidiListener;
159    }
160    
161  void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) {  void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) {
162      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount));
163  }  }
164    
165    void LSCPServer::EventHandler::ChannelAdded(SamplerChannel* pChannel) {
166        pChannel->AddEngineChangeListener(this);
167    }
168    
169    void LSCPServer::EventHandler::ChannelToBeRemoved(SamplerChannel* pChannel) {
170        if (!pChannel->GetEngineChannel()) return;
171        EngineToBeChanged(pChannel->Index());
172    }
173    
174    void LSCPServer::EventHandler::EngineToBeChanged(int ChannelId) {
175        SamplerChannel* pSamplerChannel =
176            pParent->pSampler->GetSamplerChannel(ChannelId);
177        if (!pSamplerChannel) return;
178        EngineChannel* pEngineChannel =
179            pSamplerChannel->GetEngineChannel();
180        if (!pEngineChannel) return;
181        for (std::vector<midi_listener_entry>::iterator iter = channelMidiListeners.begin(); iter != channelMidiListeners.end(); ++iter) {
182            if ((*iter).pEngineChannel == pEngineChannel) {
183                VirtualMidiDevice* pMidiListener = (*iter).pMidiListener;
184                pEngineChannel->Disconnect(pMidiListener);
185                channelMidiListeners.erase(iter);
186                delete pMidiListener;
187                return;
188            }
189        }
190    }
191    
192    void LSCPServer::EventHandler::EngineChanged(int ChannelId) {
193        SamplerChannel* pSamplerChannel =
194            pParent->pSampler->GetSamplerChannel(ChannelId);
195        if (!pSamplerChannel) return;
196        EngineChannel* pEngineChannel =
197            pSamplerChannel->GetEngineChannel();
198        if (!pEngineChannel) return;
199        VirtualMidiDevice* pMidiListener = new VirtualMidiDevice;
200        pEngineChannel->Connect(pMidiListener);
201        midi_listener_entry entry = {
202            pSamplerChannel, pEngineChannel, pMidiListener
203        };
204        channelMidiListeners.push_back(entry);
205    }
206    
207  void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) {  void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) {
208      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount));
209  }  }
# Line 152  void LSCPServer::EventHandler::MidiDevic Line 212  void LSCPServer::EventHandler::MidiDevic
212      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount));
213  }  }
214    
215    void LSCPServer::EventHandler::MidiDeviceToBeDestroyed(MidiInputDevice* pDevice) {
216        pDevice->RemoveMidiPortCountListener(this);
217        for (int i = 0; i < pDevice->PortCount(); ++i)
218            MidiPortToBeRemoved(pDevice->GetPort(i));
219    }
220    
221    void LSCPServer::EventHandler::MidiDeviceCreated(MidiInputDevice* pDevice) {
222        pDevice->AddMidiPortCountListener(this);
223        for (int i = 0; i < pDevice->PortCount(); ++i)
224            MidiPortAdded(pDevice->GetPort(i));
225    }
226    
227    void LSCPServer::EventHandler::MidiPortCountChanged(int NewCount) {
228        // yet unused
229    }
230    
231    void LSCPServer::EventHandler::MidiPortToBeRemoved(MidiInputPort* pPort) {
232        for (std::vector<device_midi_listener_entry>::iterator iter = deviceMidiListeners.begin(); iter != deviceMidiListeners.end(); ++iter) {
233            if ((*iter).pPort == pPort) {
234                VirtualMidiDevice* pMidiListener = (*iter).pMidiListener;
235                pPort->Disconnect(pMidiListener);
236                deviceMidiListeners.erase(iter);
237                delete pMidiListener;
238                return;
239            }
240        }
241    }
242    
243    void LSCPServer::EventHandler::MidiPortAdded(MidiInputPort* pPort) {
244        // find out the device ID
245        std::map<uint, MidiInputDevice*> devices =
246            pParent->pSampler->GetMidiInputDevices();
247        for (
248            std::map<uint, MidiInputDevice*>::iterator iter = devices.begin();
249            iter != devices.end(); ++iter
250        ) {
251            if (iter->second == pPort->GetDevice()) { // found
252                VirtualMidiDevice* pMidiListener = new VirtualMidiDevice;
253                pPort->Connect(pMidiListener);
254                device_midi_listener_entry entry = {
255                    pPort, pMidiListener, iter->first
256                };
257                deviceMidiListeners.push_back(entry);
258                return;
259            }
260        }
261    }
262    
263  void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) {  void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) {
264      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount));
265  }  }
# Line 188  void LSCPServer::EventHandler::TotalVoic Line 296  void LSCPServer::EventHandler::TotalVoic
296      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount));
297  }  }
298    
299    void LSCPServer::EventHandler::TotalStreamCountChanged(int NewCount) {
300        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_stream_count, NewCount));
301    }
302    
303  #if HAVE_SQLITE3  #if HAVE_SQLITE3
304  void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) {  void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) {
305      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, InstrumentsDb::toEscapedPath(Dir)));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, InstrumentsDb::toEscapedPath(Dir)));
# Line 284  int LSCPServer::Main() { Line 396  int LSCPServer::Main() {
396      pSampler->AddVoiceCountListener(&eventHandler);      pSampler->AddVoiceCountListener(&eventHandler);
397      pSampler->AddStreamCountListener(&eventHandler);      pSampler->AddStreamCountListener(&eventHandler);
398      pSampler->AddBufferFillListener(&eventHandler);      pSampler->AddBufferFillListener(&eventHandler);
399        pSampler->AddTotalStreamCountListener(&eventHandler);
400      pSampler->AddTotalVoiceCountListener(&eventHandler);      pSampler->AddTotalVoiceCountListener(&eventHandler);
401      pSampler->AddFxSendCountListener(&eventHandler);      pSampler->AddFxSendCountListener(&eventHandler);
402      MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler);      MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler);
# Line 303  int LSCPServer::Main() { Line 416  int LSCPServer::Main() {
416      timeval timeout;      timeval timeout;
417    
418      while (true) {      while (true) {
419            #if CONFIG_PTHREAD_TESTCANCEL
420                    TestCancel();
421            #endif
422          // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers          // check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers
423          {          {
424              std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();              std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
# Line 310  int LSCPServer::Main() { Line 426  int LSCPServer::Main() {
426              std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();              std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
427              for (; itEngineChannel != itEnd; ++itEngineChannel) {              for (; itEngineChannel != itEnd; ++itEngineChannel) {
428                  if ((*itEngineChannel)->StatusChanged()) {                  if ((*itEngineChannel)->StatusChanged()) {
429                      SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));                      SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->GetSamplerChannel()->Index()));
430                  }                  }
431    
432                  for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {                  for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {
433                      FxSend* fxs = (*itEngineChannel)->GetFxSend(i);                      FxSend* fxs = (*itEngineChannel)->GetFxSend(i);
434                      if(fxs != NULL && fxs->IsInfoChanged()) {                      if(fxs != NULL && fxs->IsInfoChanged()) {
435                          int chn = (*itEngineChannel)->iSamplerChannelIndex;                          int chn = (*itEngineChannel)->GetSamplerChannel()->Index();
436                          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id()));                          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id()));
437                          fxs->SetInfoChanged(false);                          fxs->SetInfoChanged(false);
438                      }                      }
# Line 324  int LSCPServer::Main() { Line 440  int LSCPServer::Main() {
440              }              }
441          }          }
442    
443            // check if MIDI data arrived on some engine channel
444            for (int i = 0; i < eventHandler.channelMidiListeners.size(); ++i) {
445                const EventHandler::midi_listener_entry entry =
446                    eventHandler.channelMidiListeners[i];
447                VirtualMidiDevice* pMidiListener = entry.pMidiListener;
448                if (pMidiListener->NotesChanged()) {
449                    for (int iNote = 0; iNote < 128; iNote++) {
450                        if (pMidiListener->NoteChanged(iNote)) {
451                            const bool bActive = pMidiListener->NoteIsActive(iNote);
452                            LSCPServer::SendLSCPNotify(
453                                LSCPEvent(
454                                    LSCPEvent::event_channel_midi,
455                                    entry.pSamplerChannel->Index(),
456                                    std::string(bActive ? "NOTE_ON" : "NOTE_OFF"),
457                                    iNote,
458                                    bActive ? pMidiListener->NoteOnVelocity(iNote)
459                                            : pMidiListener->NoteOffVelocity(iNote)
460                                )
461                            );
462                        }
463                    }
464                }
465            }
466    
467            // check if MIDI data arrived on some MIDI device
468            for (int i = 0; i < eventHandler.deviceMidiListeners.size(); ++i) {
469                const EventHandler::device_midi_listener_entry entry =
470                    eventHandler.deviceMidiListeners[i];
471                VirtualMidiDevice* pMidiListener = entry.pMidiListener;
472                if (pMidiListener->NotesChanged()) {
473                    for (int iNote = 0; iNote < 128; iNote++) {
474                        if (pMidiListener->NoteChanged(iNote)) {
475                            const bool bActive = pMidiListener->NoteIsActive(iNote);
476                            LSCPServer::SendLSCPNotify(
477                                LSCPEvent(
478                                    LSCPEvent::event_device_midi,
479                                    entry.uiDeviceID,
480                                    entry.pPort->GetPortNumber(),
481                                    std::string(bActive ? "NOTE_ON" : "NOTE_OFF"),
482                                    iNote,
483                                    bActive ? pMidiListener->NoteOnVelocity(iNote)
484                                            : pMidiListener->NoteOffVelocity(iNote)
485                                )
486                            );
487                        }
488                    }
489                }
490            }
491    
492          //Now let's deliver late notifies (if any)          //Now let's deliver late notifies (if any)
493          NotifyBufferMutex.Lock();          NotifyBufferMutex.Lock();
494          for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {          for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) {
# Line 440  void LSCPServer::CloseConnection( std::v Line 605  void LSCPServer::CloseConnection( std::v
605          NotifyMutex.Unlock();          NotifyMutex.Unlock();
606  }  }
607    
608    void LSCPServer::LockRTNotify() {
609        RTNotifyMutex.Lock();
610    }
611    
612    void LSCPServer::UnlockRTNotify() {
613        RTNotifyMutex.Unlock();
614    }
615    
616  int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) {  int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) {
617          int subs = 0;          int subs = 0;
618          SubscriptionMutex.Lock();          SubscriptionMutex.Lock();
# Line 962  String LSCPServer::GetVoiceCount(uint ui Line 1135  String LSCPServer::GetVoiceCount(uint ui
1135      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel));
1136      LSCPResultSet result;      LSCPResultSet result;
1137      try {      try {
1138          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine loaded on sampler channel");  
1139          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
1140          result.Add(pEngineChannel->GetEngine()->VoiceCount());          result.Add(pEngineChannel->GetEngine()->VoiceCount());
1141      }      }
# Line 983  String LSCPServer::GetStreamCount(uint u Line 1153  String LSCPServer::GetStreamCount(uint u
1153      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel));
1154      LSCPResultSet result;      LSCPResultSet result;
1155      try {      try {
1156          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
1157          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
1158          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
1159      }      }
# Line 1004  String LSCPServer::GetBufferFill(fill_re Line 1171  String LSCPServer::GetBufferFill(fill_re
1171      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel));      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel));
1172      LSCPResultSet result;      LSCPResultSet result;
1173      try {      try {
1174          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
1175          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
1176          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
1177          else {          else {
# Line 1685  String LSCPServer::SetVolume(double dVol Line 1849  String LSCPServer::SetVolume(double dVol
1849      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel));
1850      LSCPResultSet result;      LSCPResultSet result;
1851      try {      try {
1852          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
1853          pEngineChannel->Volume(dVolume);          pEngineChannel->Volume(dVolume);
1854      }      }
1855      catch (Exception e) {      catch (Exception e) {
# Line 1704  String LSCPServer::SetChannelMute(bool b Line 1865  String LSCPServer::SetChannelMute(bool b
1865      dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel));      dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel));
1866      LSCPResultSet result;      LSCPResultSet result;
1867      try {      try {
1868          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
   
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
1869    
1870          if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);          if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);
1871          else pEngineChannel->SetMute(1);          else pEngineChannel->SetMute(1);
# Line 1725  String LSCPServer::SetChannelSolo(bool b Line 1882  String LSCPServer::SetChannelSolo(bool b
1882      dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel));      dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel));
1883      LSCPResultSet result;      LSCPResultSet result;
1884      try {      try {
1885          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
   
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
1886    
1887          bool oldSolo = pEngineChannel->GetSolo();          bool oldSolo = pEngineChannel->GetSolo();
1888          bool hadSoloChannel = HasSoloChannel();          bool hadSoloChannel = HasSoloChannel();
# Line 1849  String LSCPServer::GetMidiInstrumentMapp Line 2002  String LSCPServer::GetMidiInstrumentMapp
2002      dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n"));      dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n"));
2003      LSCPResultSet result;      LSCPResultSet result;
2004      try {      try {
2005          result.Add(MidiInstrumentMapper::Entries(MidiMapID).size());          result.Add(MidiInstrumentMapper::GetInstrumentCount(MidiMapID));
2006      } catch (Exception e) {      } catch (Exception e) {
2007          result.Error(e);          result.Error(e);
2008      }      }
# Line 1860  String LSCPServer::GetMidiInstrumentMapp Line 2013  String LSCPServer::GetMidiInstrumentMapp
2013  String LSCPServer::GetAllMidiInstrumentMappings() {  String LSCPServer::GetAllMidiInstrumentMappings() {
2014      dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n"));      dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n"));
2015      LSCPResultSet result;      LSCPResultSet result;
2016      std::vector<int> maps = MidiInstrumentMapper::Maps();      try {
2017      int totalMappings = 0;          result.Add(MidiInstrumentMapper::GetInstrumentCount());
2018      for (int i = 0; i < maps.size(); i++) {      } catch (Exception e) {
2019          try {          result.Error(e);
             totalMappings += MidiInstrumentMapper::Entries(maps[i]).size();  
         } catch (Exception e) { /*NOOP*/ }  
2020      }      }
     result.Add(totalMappings);  
2021      return result.Produce();      return result.Produce();
2022  }  }
2023    
# Line 1875  String LSCPServer::GetMidiInstrumentMapp Line 2025  String LSCPServer::GetMidiInstrumentMapp
2025      dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n"));      dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n"));
2026      LSCPResultSet result;      LSCPResultSet result;
2027      try {      try {
2028          midi_prog_index_t idx;          MidiInstrumentMapper::entry_t entry = MidiInstrumentMapper::GetEntry(MidiMapID, MidiBank, MidiProg);
2029          idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;          // convert the filename into the correct encoding as defined for LSCP
2030          idx.midi_bank_lsb = MidiBank & 0x7f;          // (especially in terms of special characters -> escape sequences)
         idx.midi_prog     = MidiProg;  
   
         std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID);  
         std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx);  
         if (iter == mappings.end()) result.Error("there is no map entry with that index");  
         else { // found  
   
             // convert the filename into the correct encoding as defined for LSCP  
             // (especially in terms of special characters -> escape sequences)  
2031  #if WIN32  #if WIN32
2032              const String instrumentFileName = Path::fromWindows(iter->second.InstrumentFile).toLscp();          const String instrumentFileName = Path::fromWindows(entry.InstrumentFile).toLscp();
2033  #else  #else
2034              // assuming POSIX          // assuming POSIX
2035              const String instrumentFileName = Path::fromPosix(iter->second.InstrumentFile).toLscp();          const String instrumentFileName = Path::fromPosix(entry.InstrumentFile).toLscp();
2036  #endif  #endif
2037    
2038              result.Add("NAME", _escapeLscpResponse(iter->second.Name));          result.Add("NAME", _escapeLscpResponse(entry.Name));
2039              result.Add("ENGINE_NAME", iter->second.EngineName);          result.Add("ENGINE_NAME", entry.EngineName);
2040              result.Add("INSTRUMENT_FILE", instrumentFileName);          result.Add("INSTRUMENT_FILE", instrumentFileName);
2041              result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex);          result.Add("INSTRUMENT_NR", (int) entry.InstrumentIndex);
2042              String instrumentName;          String instrumentName;
2043              Engine* pEngine = EngineFactory::Create(iter->second.EngineName);          Engine* pEngine = EngineFactory::Create(entry.EngineName);
2044              if (pEngine) {          if (pEngine) {
2045                  if (pEngine->GetInstrumentManager()) {              if (pEngine->GetInstrumentManager()) {
2046                      InstrumentManager::instrument_id_t instrID;                  InstrumentManager::instrument_id_t instrID;
2047                      instrID.FileName = iter->second.InstrumentFile;                  instrID.FileName = entry.InstrumentFile;
2048                      instrID.Index    = iter->second.InstrumentIndex;                  instrID.Index    = entry.InstrumentIndex;
2049                      instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID);                  instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID);
                 }  
                 EngineFactory::Destroy(pEngine);  
2050              }              }
2051              result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName));              EngineFactory::Destroy(pEngine);
             switch (iter->second.LoadMode) {  
                 case MidiInstrumentMapper::ON_DEMAND:  
                     result.Add("LOAD_MODE", "ON_DEMAND");  
                     break;  
                 case MidiInstrumentMapper::ON_DEMAND_HOLD:  
                     result.Add("LOAD_MODE", "ON_DEMAND_HOLD");  
                     break;  
                 case MidiInstrumentMapper::PERSISTENT:  
                     result.Add("LOAD_MODE", "PERSISTENT");  
                     break;  
                 default:  
                     throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!");  
             }  
             result.Add("VOLUME", iter->second.Volume);  
2052          }          }
2053            result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName));
2054            switch (entry.LoadMode) {
2055                case MidiInstrumentMapper::ON_DEMAND:
2056                    result.Add("LOAD_MODE", "ON_DEMAND");
2057                    break;
2058                case MidiInstrumentMapper::ON_DEMAND_HOLD:
2059                    result.Add("LOAD_MODE", "ON_DEMAND_HOLD");
2060                    break;
2061                case MidiInstrumentMapper::PERSISTENT:
2062                    result.Add("LOAD_MODE", "PERSISTENT");
2063                    break;
2064                default:
2065                    throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!");
2066            }
2067            result.Add("VOLUME", entry.Volume);
2068      } catch (Exception e) {      } catch (Exception e) {
2069          result.Error(e);          result.Error(e);
2070      }      }
# Line 2095  String LSCPServer::SetChannelMap(uint ui Line 2235  String LSCPServer::SetChannelMap(uint ui
2235      dmsg(2,("LSCPServer: SetChannelMap()\n"));      dmsg(2,("LSCPServer: SetChannelMap()\n"));
2236      LSCPResultSet result;      LSCPResultSet result;
2237      try {      try {
2238          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
   
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");  
2239    
2240          if      (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone();          if      (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone();
2241          else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault();          else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault();
# Line 2278  String LSCPServer::EditSamplerChannelIns Line 2414  String LSCPServer::EditSamplerChannelIns
2414      dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel));
2415      LSCPResultSet result;      LSCPResultSet result;
2416      try {      try {
2417          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
2418          if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel");          if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel");
2419          Engine* pEngine = pEngineChannel->GetEngine();          Engine* pEngine = pEngineChannel->GetEngine();
2420          InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager();          InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager();
# Line 2296  String LSCPServer::EditSamplerChannelIns Line 2429  String LSCPServer::EditSamplerChannelIns
2429      return result.Produce();      return result.Produce();
2430  }  }
2431    
2432    String LSCPServer::SendChannelMidiData(String MidiMsg, uint uiSamplerChannel, uint Arg1, uint Arg2) {
2433        dmsg(2,("LSCPServer: SendChannelMidiData(MidiMsg=%s,uiSamplerChannel=%d,Arg1=%d,Arg2=%d)\n", MidiMsg.c_str(), uiSamplerChannel, Arg1, Arg2));
2434        LSCPResultSet result;
2435        try {
2436            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2437    
2438            if (Arg1 > 127 || Arg2 > 127) {
2439                throw Exception("Invalid MIDI message");
2440            }
2441    
2442            VirtualMidiDevice* pMidiDevice = NULL;
2443            std::vector<EventHandler::midi_listener_entry>::iterator iter = eventHandler.channelMidiListeners.begin();
2444            for (; iter != eventHandler.channelMidiListeners.end(); ++iter) {
2445                if ((*iter).pEngineChannel == pEngineChannel) {
2446                    pMidiDevice = (*iter).pMidiListener;
2447                    break;
2448                }
2449            }
2450            
2451            if(pMidiDevice == NULL) throw Exception("Couldn't find virtual MIDI device");
2452    
2453            if (MidiMsg == "NOTE_ON") {
2454                pMidiDevice->SendNoteOnToDevice(Arg1, Arg2);
2455                bool b = pMidiDevice->SendNoteOnToSampler(Arg1, Arg2);
2456                if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2));
2457            } else if (MidiMsg == "NOTE_OFF") {
2458                pMidiDevice->SendNoteOffToDevice(Arg1, Arg2);
2459                bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2);
2460                if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2));
2461            } else {
2462                throw Exception("Unknown MIDI message type: " + MidiMsg);
2463            }
2464        } catch (Exception e) {
2465            result.Error(e);
2466        }
2467        return result.Produce();
2468    }
2469    
2470  /**  /**
2471   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
2472   */   */
# Line 2303  String LSCPServer::ResetChannel(uint uiS Line 2474  String LSCPServer::ResetChannel(uint uiS
2474      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel));
2475      LSCPResultSet result;      LSCPResultSet result;
2476      try {      try {
2477          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
2478          pEngineChannel->Reset();          pEngineChannel->Reset();
2479      }      }
2480      catch (Exception e) {      catch (Exception e) {
# Line 2347  String LSCPServer::GetServerInfo() { Line 2515  String LSCPServer::GetServerInfo() {
2515  }  }
2516    
2517  /**  /**
2518     * Will be called by the parser to return the current number of all active streams.
2519     */
2520    String LSCPServer::GetTotalStreamCount() {
2521        dmsg(2,("LSCPServer: GetTotalStreamCount()\n"));
2522        LSCPResultSet result;
2523        result.Add(pSampler->GetDiskStreamCount());
2524        return result.Produce();
2525    }
2526    
2527    /**
2528   * Will be called by the parser to return the current number of all active voices.   * Will be called by the parser to return the current number of all active voices.
2529   */   */
2530  String LSCPServer::GetTotalVoiceCount() {  String LSCPServer::GetTotalVoiceCount() {
# Line 2362  String LSCPServer::GetTotalVoiceCount() Line 2540  String LSCPServer::GetTotalVoiceCount()
2540  String LSCPServer::GetTotalVoiceCountMax() {  String LSCPServer::GetTotalVoiceCountMax() {
2541      dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));      dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));
2542      LSCPResultSet result;      LSCPResultSet result;
2543      result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES);      result.Add(EngineFactory::EngineInstances().size() * GLOBAL_MAX_VOICES);
2544        return result.Produce();
2545    }
2546    
2547    /**
2548     * Will be called by the parser to return the sampler global maximum
2549     * allowed number of voices.
2550     */
2551    String LSCPServer::GetGlobalMaxVoices() {
2552        dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n"));
2553        LSCPResultSet result;
2554        result.Add(GLOBAL_MAX_VOICES);
2555        return result.Produce();
2556    }
2557    
2558    /**
2559     * Will be called by the parser to set the sampler global maximum number of
2560     * voices.
2561     */
2562    String LSCPServer::SetGlobalMaxVoices(int iVoices) {
2563        dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices));
2564        LSCPResultSet result;
2565        try {
2566            if (iVoices < 1) throw Exception("Maximum voices may not be less than 1");
2567            GLOBAL_MAX_VOICES = iVoices; // see common/global_private.cpp
2568            const std::set<Engine*>& engines = EngineFactory::EngineInstances();
2569            if (engines.size() > 0) {
2570                std::set<Engine*>::iterator iter = engines.begin();
2571                std::set<Engine*>::iterator end  = engines.end();
2572                for (; iter != end; ++iter) {
2573                    (*iter)->SetMaxVoices(iVoices);
2574                }
2575            }
2576            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOICES", GLOBAL_MAX_VOICES));
2577        } catch (Exception e) {
2578            result.Error(e);
2579        }
2580        return result.Produce();
2581    }
2582    
2583    /**
2584     * Will be called by the parser to return the sampler global maximum
2585     * allowed number of disk streams.
2586     */
2587    String LSCPServer::GetGlobalMaxStreams() {
2588        dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n"));
2589        LSCPResultSet result;
2590        result.Add(GLOBAL_MAX_STREAMS);
2591        return result.Produce();
2592    }
2593    
2594    /**
2595     * Will be called by the parser to set the sampler global maximum number of
2596     * disk streams.
2597     */
2598    String LSCPServer::SetGlobalMaxStreams(int iStreams) {
2599        dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams));
2600        LSCPResultSet result;
2601        try {
2602            if (iStreams < 0) throw Exception("Maximum disk streams may not be negative");
2603            GLOBAL_MAX_STREAMS = iStreams; // see common/global_private.cpp
2604            const std::set<Engine*>& engines = EngineFactory::EngineInstances();
2605            if (engines.size() > 0) {
2606                std::set<Engine*>::iterator iter = engines.begin();
2607                std::set<Engine*>::iterator end  = engines.end();
2608                for (; iter != end; ++iter) {
2609                    (*iter)->SetMaxDiskStreams(iStreams);
2610                }
2611            }
2612            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "STREAMS", GLOBAL_MAX_STREAMS));
2613        } catch (Exception e) {
2614            result.Error(e);
2615        }
2616      return result.Produce();      return result.Produce();
2617  }  }
2618    
# Line 2376  String LSCPServer::SetGlobalVolume(doubl Line 2626  String LSCPServer::SetGlobalVolume(doubl
2626      LSCPResultSet result;      LSCPResultSet result;
2627      try {      try {
2628          if (dVolume < 0) throw Exception("Volume may not be negative");          if (dVolume < 0) throw Exception("Volume may not be negative");
2629          GLOBAL_VOLUME = dVolume; // see common/global.cpp          GLOBAL_VOLUME = dVolume; // see common/global_private.cpp
2630          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME));          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME));
2631      } catch (Exception e) {      } catch (Exception e) {
2632          result.Error(e);          result.Error(e);
# Line 2503  String LSCPServer::GetFileInstrumentInfo Line 2753  String LSCPServer::GetFileInstrumentInfo
2753                  result.Add("FORMAT_VERSION", info.FormatVersion);                  result.Add("FORMAT_VERSION", info.FormatVersion);
2754                  result.Add("PRODUCT", info.Product);                  result.Add("PRODUCT", info.Product);
2755                  result.Add("ARTISTS", info.Artists);                  result.Add("ARTISTS", info.Artists);
2756    
2757                    std::stringstream ss;
2758                    bool b = false;
2759                    for (int i = 0; i < 128; i++) {
2760                        if (info.KeyBindings[i]) {
2761                            if (b) ss << ',';
2762                            ss << i; b = true;
2763                        }
2764                    }
2765                    result.Add("KEY_BINDINGS", ss.str());
2766    
2767                    b = false;
2768                    std::stringstream ss2;
2769                    for (int i = 0; i < 128; i++) {
2770                        if (info.KeySwitchBindings[i]) {
2771                            if (b) ss2 << ',';
2772                            ss2 << i; b = true;
2773                        }
2774                    }
2775                    result.Add("KEYSWITCH_BINDINGS", ss2.str());
2776                  // no more need to ask other engine types                  // no more need to ask other engine types
2777                  bFound = true;                  bFound = true;
2778              } else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str()));              } else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str()));
# Line 2529  void LSCPServer::VerifyFile(String Filen Line 2799  void LSCPServer::VerifyFile(String Filen
2799      if ( win32FileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {      if ( win32FileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {
2800          throw Exception("Directory is specified");          throw Exception("Directory is specified");
2801      }      }
2802      #else          #else
2803      struct stat statBuf;      struct stat statBuf;
2804      int res = stat(Filename.c_str(), &statBuf);      int res = stat(Filename.c_str(), &statBuf);
2805      if (res) {      if (res) {
# Line 2735  String LSCPServer::AddDbInstruments(Stri Line 3005  String LSCPServer::AddDbInstruments(Stri
3005      return result.Produce();      return result.Produce();
3006  }  }
3007    
3008  String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) {  String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground, bool insDir) {
3009      dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground));      dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d,insDir=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground, insDir));
3010      LSCPResultSet result;      LSCPResultSet result;
3011  #if HAVE_SQLITE3  #if HAVE_SQLITE3
3012      try {      try {
3013          int id;          int id;
3014          InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();          InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();
3015          if (ScanMode.compare("RECURSIVE") == 0) {          if (ScanMode.compare("RECURSIVE") == 0) {
3016             id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground);              id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground, insDir);
3017          } else if (ScanMode.compare("NON_RECURSIVE") == 0) {          } else if (ScanMode.compare("NON_RECURSIVE") == 0) {
3018             id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground);              id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground, insDir);
3019          } else if (ScanMode.compare("FLAT") == 0) {          } else if (ScanMode.compare("FLAT") == 0) {
3020             id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground);              id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground, insDir);
3021          } else {          } else {
3022              throw Exception("Unknown scan mode: " + ScanMode);              throw Exception("Unknown scan mode: " + ScanMode);
3023          }          }
# Line 2923  String LSCPServer::SetDbInstrumentDescri Line 3193  String LSCPServer::SetDbInstrumentDescri
3193      return result.Produce();      return result.Produce();
3194  }  }
3195    
3196    String LSCPServer::SetDbInstrumentFilePath(String OldPath, String NewPath) {
3197        dmsg(2,("LSCPServer: SetDbInstrumentFilePath(OldPath=%s,NewPath=%s)\n", OldPath.c_str(), NewPath.c_str()));
3198        LSCPResultSet result;
3199    #if HAVE_SQLITE3
3200        try {
3201            InstrumentsDb::GetInstrumentsDb()->SetInstrumentFilePath(OldPath, NewPath);
3202        } catch (Exception e) {
3203             result.Error(e);
3204        }
3205    #else
3206        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
3207    #endif
3208        return result.Produce();
3209    }
3210    
3211    String LSCPServer::FindLostDbInstrumentFiles() {
3212        dmsg(2,("LSCPServer: FindLostDbInstrumentFiles()\n"));
3213        LSCPResultSet result;
3214    #if HAVE_SQLITE3
3215        try {
3216            String list;
3217            StringListPtr pLostFiles = InstrumentsDb::GetInstrumentsDb()->FindLostInstrumentFiles();
3218    
3219            for (int i = 0; i < pLostFiles->size(); i++) {
3220                if (list != "") list += ",";
3221                list += "'" + pLostFiles->at(i) + "'";
3222            }
3223    
3224            result.Add(list);
3225        } catch (Exception e) {
3226             result.Error(e);
3227        }
3228    #else
3229        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
3230    #endif
3231        return result.Produce();
3232    }
3233    
3234  String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) {  String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) {
3235      dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str()));      dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str()));
3236      LSCPResultSet result;      LSCPResultSet result;
# Line 3053  String LSCPServer::SetEcho(yyparse_param Line 3361  String LSCPServer::SetEcho(yyparse_param
3361      }      }
3362      return result.Produce();      return result.Produce();
3363  }  }
3364    
3365    }

Legend:
Removed from v.1537  
changed lines
  Added in v.1800

  ViewVC Help
Powered by ViewVC