/[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 1536 by schoenebeck, Mon Dec 3 16:41:17 2007 UTC revision 1763 by iliev, Wed Sep 3 17:18:51 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    
26  #include "lscpserver.h"  #include "lscpserver.h"
27  #include "lscpresultset.h"  #include "lscpresultset.h"
28  #include "lscpevent.h"  #include "lscpevent.h"
29    
30  #if defined(WIN32)  #if defined(WIN32)
31    #include <windows.h>
32  #else  #else
33  #include <fcntl.h>  #include <fcntl.h>
34  #endif  #endif
# Line 100  Mutex LSCPServer::NotifyBufferMutex = Mu Line 103  Mutex LSCPServer::NotifyBufferMutex = Mu
103  Mutex LSCPServer::SubscriptionMutex = Mutex();  Mutex LSCPServer::SubscriptionMutex = Mutex();
104  Mutex LSCPServer::RTNotifyMutex = Mutex();  Mutex LSCPServer::RTNotifyMutex = Mutex();
105    
106  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) {
107      SocketAddress.sin_family      = AF_INET;      SocketAddress.sin_family      = AF_INET;
108      SocketAddress.sin_addr.s_addr = addr;      SocketAddress.sin_addr.s_addr = addr;
109      SocketAddress.sin_port        = port;      SocketAddress.sin_port        = port;
# Line 126  LSCPServer::LSCPServer(Sampler* pSampler Line 129  LSCPServer::LSCPServer(Sampler* pSampler
129      LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO");
130      LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO");
131      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
132        LSCPEvent::RegisterEvent(LSCPEvent::event_total_stream_count, "TOTAL_STREAM_COUNT");
133      LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");
134      LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO");
135        LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI");
136        LSCPEvent::RegisterEvent(LSCPEvent::event_device_midi, "DEVICE_MIDI");
137      hSocket = -1;      hSocket = -1;
138  }  }
139    
# Line 139  LSCPServer::~LSCPServer() { Line 145  LSCPServer::~LSCPServer() {
145  #endif  #endif
146  }  }
147    
148    LSCPServer::EventHandler::EventHandler(LSCPServer* pParent) {
149        this->pParent = pParent;
150    }
151    
152    LSCPServer::EventHandler::~EventHandler() {
153        std::vector<midi_listener_entry> l = channelMidiListeners;
154        channelMidiListeners.clear();
155        for (int i = 0; i < l.size(); i++)
156            delete l[i].pMidiListener;
157    }
158    
159  void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) {  void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) {
160      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount));
161  }  }
162    
163    void LSCPServer::EventHandler::ChannelAdded(SamplerChannel* pChannel) {
164        pChannel->AddEngineChangeListener(this);
165    }
166    
167    void LSCPServer::EventHandler::ChannelToBeRemoved(SamplerChannel* pChannel) {
168        if (!pChannel->GetEngineChannel()) return;
169        EngineToBeChanged(pChannel->Index());
170    }
171    
172    void LSCPServer::EventHandler::EngineToBeChanged(int ChannelId) {
173        SamplerChannel* pSamplerChannel =
174            pParent->pSampler->GetSamplerChannel(ChannelId);
175        if (!pSamplerChannel) return;
176        EngineChannel* pEngineChannel =
177            pSamplerChannel->GetEngineChannel();
178        if (!pEngineChannel) return;
179        for (std::vector<midi_listener_entry>::iterator iter = channelMidiListeners.begin(); iter != channelMidiListeners.end(); ++iter) {
180            if ((*iter).pEngineChannel == pEngineChannel) {
181                VirtualMidiDevice* pMidiListener = (*iter).pMidiListener;
182                pEngineChannel->Disconnect(pMidiListener);
183                channelMidiListeners.erase(iter);
184                delete pMidiListener;
185                return;
186            }
187        }
188    }
189    
190    void LSCPServer::EventHandler::EngineChanged(int ChannelId) {
191        SamplerChannel* pSamplerChannel =
192            pParent->pSampler->GetSamplerChannel(ChannelId);
193        if (!pSamplerChannel) return;
194        EngineChannel* pEngineChannel =
195            pSamplerChannel->GetEngineChannel();
196        if (!pEngineChannel) return;
197        VirtualMidiDevice* pMidiListener = new VirtualMidiDevice;
198        pEngineChannel->Connect(pMidiListener);
199        midi_listener_entry entry = {
200            pSamplerChannel, pEngineChannel, pMidiListener
201        };
202        channelMidiListeners.push_back(entry);
203    }
204    
205  void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) {  void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) {
206      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount));
207  }  }
# Line 151  void LSCPServer::EventHandler::MidiDevic Line 210  void LSCPServer::EventHandler::MidiDevic
210      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount));
211  }  }
212    
213    void LSCPServer::EventHandler::MidiDeviceToBeDestroyed(MidiInputDevice* pDevice) {
214        pDevice->RemoveMidiPortCountListener(this);
215        for (int i = 0; i < pDevice->PortCount(); ++i)
216            MidiPortToBeRemoved(pDevice->GetPort(i));
217    }
218    
219    void LSCPServer::EventHandler::MidiDeviceCreated(MidiInputDevice* pDevice) {
220        pDevice->AddMidiPortCountListener(this);
221        for (int i = 0; i < pDevice->PortCount(); ++i)
222            MidiPortAdded(pDevice->GetPort(i));
223    }
224    
225    void LSCPServer::EventHandler::MidiPortCountChanged(int NewCount) {
226        // yet unused
227    }
228    
229    void LSCPServer::EventHandler::MidiPortToBeRemoved(MidiInputPort* pPort) {
230        for (std::vector<device_midi_listener_entry>::iterator iter = deviceMidiListeners.begin(); iter != deviceMidiListeners.end(); ++iter) {
231            if ((*iter).pPort == pPort) {
232                VirtualMidiDevice* pMidiListener = (*iter).pMidiListener;
233                pPort->Disconnect(pMidiListener);
234                deviceMidiListeners.erase(iter);
235                delete pMidiListener;
236                return;
237            }
238        }
239    }
240    
241    void LSCPServer::EventHandler::MidiPortAdded(MidiInputPort* pPort) {
242        // find out the device ID
243        std::map<uint, MidiInputDevice*> devices =
244            pParent->pSampler->GetMidiInputDevices();
245        for (
246            std::map<uint, MidiInputDevice*>::iterator iter = devices.begin();
247            iter != devices.end(); ++iter
248        ) {
249            if (iter->second == pPort->GetDevice()) { // found
250                VirtualMidiDevice* pMidiListener = new VirtualMidiDevice;
251                pPort->Connect(pMidiListener);
252                device_midi_listener_entry entry = {
253                    pPort, pMidiListener, iter->first
254                };
255                deviceMidiListeners.push_back(entry);
256                return;
257            }
258        }
259    }
260    
261  void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) {  void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) {
262      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount));
263  }  }
# Line 187  void LSCPServer::EventHandler::TotalVoic Line 294  void LSCPServer::EventHandler::TotalVoic
294      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount));
295  }  }
296    
297    void LSCPServer::EventHandler::TotalStreamCountChanged(int NewCount) {
298        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_stream_count, NewCount));
299    }
300    
301  #if HAVE_SQLITE3  #if HAVE_SQLITE3
302  void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) {  void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) {
303      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 283  int LSCPServer::Main() { Line 394  int LSCPServer::Main() {
394      pSampler->AddVoiceCountListener(&eventHandler);      pSampler->AddVoiceCountListener(&eventHandler);
395      pSampler->AddStreamCountListener(&eventHandler);      pSampler->AddStreamCountListener(&eventHandler);
396      pSampler->AddBufferFillListener(&eventHandler);      pSampler->AddBufferFillListener(&eventHandler);
397        pSampler->AddTotalStreamCountListener(&eventHandler);
398      pSampler->AddTotalVoiceCountListener(&eventHandler);      pSampler->AddTotalVoiceCountListener(&eventHandler);
399      pSampler->AddFxSendCountListener(&eventHandler);      pSampler->AddFxSendCountListener(&eventHandler);
400      MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler);      MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler);
# Line 302  int LSCPServer::Main() { Line 414  int LSCPServer::Main() {
414      timeval timeout;      timeval timeout;
415    
416      while (true) {      while (true) {
417            #if CONFIG_PTHREAD_TESTCANCEL
418                    TestCancel();
419            #endif
420          // 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
421          {          {
422              std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();              std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
# Line 309  int LSCPServer::Main() { Line 424  int LSCPServer::Main() {
424              std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();              std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
425              for (; itEngineChannel != itEnd; ++itEngineChannel) {              for (; itEngineChannel != itEnd; ++itEngineChannel) {
426                  if ((*itEngineChannel)->StatusChanged()) {                  if ((*itEngineChannel)->StatusChanged()) {
427                      SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));                      SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->GetSamplerChannel()->Index()));
428                  }                  }
429    
430                  for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {                  for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {
431                      FxSend* fxs = (*itEngineChannel)->GetFxSend(i);                      FxSend* fxs = (*itEngineChannel)->GetFxSend(i);
432                      if(fxs != NULL && fxs->IsInfoChanged()) {                      if(fxs != NULL && fxs->IsInfoChanged()) {
433                          int chn = (*itEngineChannel)->iSamplerChannelIndex;                          int chn = (*itEngineChannel)->GetSamplerChannel()->Index();
434                          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id()));                          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id()));
435                          fxs->SetInfoChanged(false);                          fxs->SetInfoChanged(false);
436                      }                      }
# Line 323  int LSCPServer::Main() { Line 438  int LSCPServer::Main() {
438              }              }
439          }          }
440    
441            // check if MIDI data arrived on some engine channel
442            for (int i = 0; i < eventHandler.channelMidiListeners.size(); ++i) {
443                const EventHandler::midi_listener_entry entry =
444                    eventHandler.channelMidiListeners[i];
445                VirtualMidiDevice* pMidiListener = entry.pMidiListener;
446                if (pMidiListener->NotesChanged()) {
447                    for (int iNote = 0; iNote < 128; iNote++) {
448                        if (pMidiListener->NoteChanged(iNote)) {
449                            const bool bActive = pMidiListener->NoteIsActive(iNote);
450                            LSCPServer::SendLSCPNotify(
451                                LSCPEvent(
452                                    LSCPEvent::event_channel_midi,
453                                    entry.pSamplerChannel->Index(),
454                                    std::string(bActive ? "NOTE_ON" : "NOTE_OFF"),
455                                    iNote,
456                                    bActive ? pMidiListener->NoteOnVelocity(iNote)
457                                            : pMidiListener->NoteOffVelocity(iNote)
458                                )
459                            );
460                        }
461                    }
462                }
463            }
464    
465            // check if MIDI data arrived on some MIDI device
466            for (int i = 0; i < eventHandler.deviceMidiListeners.size(); ++i) {
467                const EventHandler::device_midi_listener_entry entry =
468                    eventHandler.deviceMidiListeners[i];
469                VirtualMidiDevice* pMidiListener = entry.pMidiListener;
470                if (pMidiListener->NotesChanged()) {
471                    for (int iNote = 0; iNote < 128; iNote++) {
472                        if (pMidiListener->NoteChanged(iNote)) {
473                            const bool bActive = pMidiListener->NoteIsActive(iNote);
474                            LSCPServer::SendLSCPNotify(
475                                LSCPEvent(
476                                    LSCPEvent::event_device_midi,
477                                    entry.uiDeviceID,
478                                    entry.pPort->GetPortNumber(),
479                                    std::string(bActive ? "NOTE_ON" : "NOTE_OFF"),
480                                    iNote,
481                                    bActive ? pMidiListener->NoteOnVelocity(iNote)
482                                            : pMidiListener->NoteOffVelocity(iNote)
483                                )
484                            );
485                        }
486                    }
487                }
488            }
489    
490          //Now let's deliver late notifies (if any)          //Now let's deliver late notifies (if any)
491          NotifyBufferMutex.Lock();          NotifyBufferMutex.Lock();
492          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 439  void LSCPServer::CloseConnection( std::v Line 603  void LSCPServer::CloseConnection( std::v
603          NotifyMutex.Unlock();          NotifyMutex.Unlock();
604  }  }
605    
606    void LSCPServer::LockRTNotify() {
607        RTNotifyMutex.Lock();
608    }
609    
610    void LSCPServer::UnlockRTNotify() {
611        RTNotifyMutex.Unlock();
612    }
613    
614  int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) {  int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) {
615          int subs = 0;          int subs = 0;
616          SubscriptionMutex.Lock();          SubscriptionMutex.Lock();
# Line 1848  String LSCPServer::GetMidiInstrumentMapp Line 2020  String LSCPServer::GetMidiInstrumentMapp
2020      dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n"));      dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n"));
2021      LSCPResultSet result;      LSCPResultSet result;
2022      try {      try {
2023          result.Add(MidiInstrumentMapper::Entries(MidiMapID).size());          result.Add(MidiInstrumentMapper::GetInstrumentCount(MidiMapID));
2024      } catch (Exception e) {      } catch (Exception e) {
2025          result.Error(e);          result.Error(e);
2026      }      }
# Line 1859  String LSCPServer::GetMidiInstrumentMapp Line 2031  String LSCPServer::GetMidiInstrumentMapp
2031  String LSCPServer::GetAllMidiInstrumentMappings() {  String LSCPServer::GetAllMidiInstrumentMappings() {
2032      dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n"));      dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n"));
2033      LSCPResultSet result;      LSCPResultSet result;
2034      std::vector<int> maps = MidiInstrumentMapper::Maps();      try {
2035      int totalMappings = 0;          result.Add(MidiInstrumentMapper::GetInstrumentCount());
2036      for (int i = 0; i < maps.size(); i++) {      } catch (Exception e) {
2037          try {          result.Error(e);
             totalMappings += MidiInstrumentMapper::Entries(maps[i]).size();  
         } catch (Exception e) { /*NOOP*/ }  
2038      }      }
     result.Add(totalMappings);  
2039      return result.Produce();      return result.Produce();
2040  }  }
2041    
# Line 1874  String LSCPServer::GetMidiInstrumentMapp Line 2043  String LSCPServer::GetMidiInstrumentMapp
2043      dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n"));      dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n"));
2044      LSCPResultSet result;      LSCPResultSet result;
2045      try {      try {
2046          midi_prog_index_t idx;          MidiInstrumentMapper::entry_t entry = MidiInstrumentMapper::GetEntry(MidiMapID, MidiBank, MidiProg);
2047          idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;          // convert the filename into the correct encoding as defined for LSCP
2048          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)  
2049  #if WIN32  #if WIN32
2050              const String instrumentFileName = Path::fromWindows(iter->second.InstrumentFile).toLscp();          const String instrumentFileName = Path::fromWindows(entry.InstrumentFile).toLscp();
2051  #else  #else
2052              // assuming POSIX          // assuming POSIX
2053              const String instrumentFileName = Path::fromPosix(iter->second.InstrumentFile).toLscp();          const String instrumentFileName = Path::fromPosix(entry.InstrumentFile).toLscp();
2054  #endif  #endif
2055    
2056              result.Add("NAME", _escapeLscpResponse(iter->second.Name));          result.Add("NAME", _escapeLscpResponse(entry.Name));
2057              result.Add("ENGINE_NAME", iter->second.EngineName);          result.Add("ENGINE_NAME", entry.EngineName);
2058              result.Add("INSTRUMENT_FILE", instrumentFileName);          result.Add("INSTRUMENT_FILE", instrumentFileName);
2059              result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex);          result.Add("INSTRUMENT_NR", (int) entry.InstrumentIndex);
2060              String instrumentName;          String instrumentName;
2061              Engine* pEngine = EngineFactory::Create(iter->second.EngineName);          Engine* pEngine = EngineFactory::Create(entry.EngineName);
2062              if (pEngine) {          if (pEngine) {
2063                  if (pEngine->GetInstrumentManager()) {              if (pEngine->GetInstrumentManager()) {
2064                      InstrumentManager::instrument_id_t instrID;                  InstrumentManager::instrument_id_t instrID;
2065                      instrID.FileName = iter->second.InstrumentFile;                  instrID.FileName = entry.InstrumentFile;
2066                      instrID.Index    = iter->second.InstrumentIndex;                  instrID.Index    = entry.InstrumentIndex;
2067                      instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID);                  instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID);
                 }  
                 EngineFactory::Destroy(pEngine);  
             }  
             result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName));  
             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!");  
2068              }              }
2069              result.Add("VOLUME", iter->second.Volume);              EngineFactory::Destroy(pEngine);
2070          }          }
2071            result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName));
2072            switch (entry.LoadMode) {
2073                case MidiInstrumentMapper::ON_DEMAND:
2074                    result.Add("LOAD_MODE", "ON_DEMAND");
2075                    break;
2076                case MidiInstrumentMapper::ON_DEMAND_HOLD:
2077                    result.Add("LOAD_MODE", "ON_DEMAND_HOLD");
2078                    break;
2079                case MidiInstrumentMapper::PERSISTENT:
2080                    result.Add("LOAD_MODE", "PERSISTENT");
2081                    break;
2082                default:
2083                    throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!");
2084            }
2085            result.Add("VOLUME", entry.Volume);
2086      } catch (Exception e) {      } catch (Exception e) {
2087          result.Error(e);          result.Error(e);
2088      }      }
# Line 2346  String LSCPServer::GetServerInfo() { Line 2505  String LSCPServer::GetServerInfo() {
2505  }  }
2506    
2507  /**  /**
2508     * Will be called by the parser to return the current number of all active streams.
2509     */
2510    String LSCPServer::GetTotalStreamCount() {
2511        dmsg(2,("LSCPServer: GetTotalStreamCount()\n"));
2512        LSCPResultSet result;
2513        result.Add(pSampler->GetDiskStreamCount());
2514        return result.Produce();
2515    }
2516    
2517    /**
2518   * 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.
2519   */   */
2520  String LSCPServer::GetTotalVoiceCount() {  String LSCPServer::GetTotalVoiceCount() {
# Line 2375  String LSCPServer::SetGlobalVolume(doubl Line 2544  String LSCPServer::SetGlobalVolume(doubl
2544      LSCPResultSet result;      LSCPResultSet result;
2545      try {      try {
2546          if (dVolume < 0) throw Exception("Volume may not be negative");          if (dVolume < 0) throw Exception("Volume may not be negative");
2547          GLOBAL_VOLUME = dVolume; // see common/global.cpp          GLOBAL_VOLUME = dVolume; // see common/global_private.cpp
2548          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME));          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME));
2549      } catch (Exception e) {      } catch (Exception e) {
2550          result.Error(e);          result.Error(e);
# Line 2517  String LSCPServer::GetFileInstrumentInfo Line 2686  String LSCPServer::GetFileInstrumentInfo
2686  }  }
2687    
2688  void LSCPServer::VerifyFile(String Filename) {  void LSCPServer::VerifyFile(String Filename) {
2689        #if WIN32
2690        WIN32_FIND_DATA win32FileAttributeData;
2691        BOOL res = GetFileAttributesEx( Filename.c_str(), GetFileExInfoStandard, &win32FileAttributeData );
2692        if (!res) {
2693            std::stringstream ss;
2694            ss << "File does not exist, GetFileAttributesEx failed `" << Filename << "`: Error " << GetLastError();
2695            throw Exception(ss.str());
2696        }
2697        if ( win32FileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {
2698            throw Exception("Directory is specified");
2699        }
2700        #else
2701      struct stat statBuf;      struct stat statBuf;
2702      int res = stat(Filename.c_str(), &statBuf);      int res = stat(Filename.c_str(), &statBuf);
2703      if (res) {      if (res) {
# Line 2528  void LSCPServer::VerifyFile(String Filen Line 2709  void LSCPServer::VerifyFile(String Filen
2709      if (S_ISDIR(statBuf.st_mode)) {      if (S_ISDIR(statBuf.st_mode)) {
2710          throw Exception("Directory is specified");          throw Exception("Directory is specified");
2711      }      }
2712        #endif
2713  }  }
2714    
2715  /**  /**
# Line 2903  String LSCPServer::SetDbInstrumentDescri Line 3085  String LSCPServer::SetDbInstrumentDescri
3085      } catch (Exception e) {      } catch (Exception e) {
3086           result.Error(e);           result.Error(e);
3087      }      }
3088    #else
3089        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
3090    #endif
3091        return result.Produce();
3092    }
3093    
3094    String LSCPServer::SetDbInstrumentFilePath(String OldPath, String NewPath) {
3095        dmsg(2,("LSCPServer: SetDbInstrumentFilePath(OldPath=%s,NewPath=%s)\n", OldPath.c_str(), NewPath.c_str()));
3096        LSCPResultSet result;
3097    #if HAVE_SQLITE3
3098        try {
3099            InstrumentsDb::GetInstrumentsDb()->SetInstrumentFilePath(OldPath, NewPath);
3100        } catch (Exception e) {
3101             result.Error(e);
3102        }
3103    #else
3104        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
3105    #endif
3106        return result.Produce();
3107    }
3108    
3109    String LSCPServer::FindLostDbInstrumentFiles() {
3110        dmsg(2,("LSCPServer: FindLostDbInstrumentFiles()\n"));
3111        LSCPResultSet result;
3112    #if HAVE_SQLITE3
3113        try {
3114            String list;
3115            StringListPtr pLostFiles = InstrumentsDb::GetInstrumentsDb()->FindLostInstrumentFiles();
3116    
3117            for (int i = 0; i < pLostFiles->size(); i++) {
3118                if (list != "") list += ",";
3119                list += "'" + pLostFiles->at(i) + "'";
3120            }
3121    
3122            result.Add(list);
3123        } catch (Exception e) {
3124             result.Error(e);
3125        }
3126  #else  #else
3127      result.Error(String(DOESNT_HAVE_SQLITE3), 0);      result.Error(String(DOESNT_HAVE_SQLITE3), 0);
3128  #endif  #endif

Legend:
Removed from v.1536  
changed lines
  Added in v.1763

  ViewVC Help
Powered by ViewVC