/[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 1848 by iliev, Sat Feb 28 21:23:06 2009 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 "../common/File.h"
28  #include "lscpserver.h"  #include "lscpserver.h"
29  #include "lscpresultset.h"  #include "lscpresultset.h"
30  #include "lscpevent.h"  #include "lscpevent.h"
# Line 40  Line 44 
44  #include "../drivers/audio/AudioOutputDeviceFactory.h"  #include "../drivers/audio/AudioOutputDeviceFactory.h"
45  #include "../drivers/midi/MidiInputDeviceFactory.h"  #include "../drivers/midi/MidiInputDeviceFactory.h"
46    
47    namespace LinuxSampler {
48    
49  /**  /**
50   * 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 106  Mutex LSCPServer::NotifyBufferMutex = Mu
106  Mutex LSCPServer::SubscriptionMutex = Mutex();  Mutex LSCPServer::SubscriptionMutex = Mutex();
107  Mutex LSCPServer::RTNotifyMutex = Mutex();  Mutex LSCPServer::RTNotifyMutex = Mutex();
108    
109  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) {
110      SocketAddress.sin_family      = AF_INET;      SocketAddress.sin_family      = AF_INET;
111      SocketAddress.sin_addr.s_addr = addr;      SocketAddress.sin_addr.s_addr = addr;
112      SocketAddress.sin_port        = port;      SocketAddress.sin_port        = port;
# Line 127  LSCPServer::LSCPServer(Sampler* pSampler Line 132  LSCPServer::LSCPServer(Sampler* pSampler
132      LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO");
133      LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO");
134      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
135        LSCPEvent::RegisterEvent(LSCPEvent::event_total_stream_count, "TOTAL_STREAM_COUNT");
136      LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");
137      LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO");
138        LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI");
139        LSCPEvent::RegisterEvent(LSCPEvent::event_device_midi, "DEVICE_MIDI");
140      hSocket = -1;      hSocket = -1;
141  }  }
142    
143  LSCPServer::~LSCPServer() {  LSCPServer::~LSCPServer() {
144        CloseAllConnections();
145  #if defined(WIN32)  #if defined(WIN32)
146      if (hSocket >= 0) closesocket(hSocket);      if (hSocket >= 0) closesocket(hSocket);
147  #else  #else
# Line 140  LSCPServer::~LSCPServer() { Line 149  LSCPServer::~LSCPServer() {
149  #endif  #endif
150  }  }
151    
152    LSCPServer::EventHandler::EventHandler(LSCPServer* pParent) {
153        this->pParent = pParent;
154    }
155    
156    LSCPServer::EventHandler::~EventHandler() {
157        std::vector<midi_listener_entry> l = channelMidiListeners;
158        channelMidiListeners.clear();
159        for (int i = 0; i < l.size(); i++)
160            delete l[i].pMidiListener;
161    }
162    
163  void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) {  void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) {
164      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount));
165  }  }
166    
167    void LSCPServer::EventHandler::ChannelAdded(SamplerChannel* pChannel) {
168        pChannel->AddEngineChangeListener(this);
169    }
170    
171    void LSCPServer::EventHandler::ChannelToBeRemoved(SamplerChannel* pChannel) {
172        if (!pChannel->GetEngineChannel()) return;
173        EngineToBeChanged(pChannel->Index());
174    }
175    
176    void LSCPServer::EventHandler::EngineToBeChanged(int ChannelId) {
177        SamplerChannel* pSamplerChannel =
178            pParent->pSampler->GetSamplerChannel(ChannelId);
179        if (!pSamplerChannel) return;
180        EngineChannel* pEngineChannel =
181            pSamplerChannel->GetEngineChannel();
182        if (!pEngineChannel) return;
183        for (std::vector<midi_listener_entry>::iterator iter = channelMidiListeners.begin(); iter != channelMidiListeners.end(); ++iter) {
184            if ((*iter).pEngineChannel == pEngineChannel) {
185                VirtualMidiDevice* pMidiListener = (*iter).pMidiListener;
186                pEngineChannel->Disconnect(pMidiListener);
187                channelMidiListeners.erase(iter);
188                delete pMidiListener;
189                return;
190            }
191        }
192    }
193    
194    void LSCPServer::EventHandler::EngineChanged(int ChannelId) {
195        SamplerChannel* pSamplerChannel =
196            pParent->pSampler->GetSamplerChannel(ChannelId);
197        if (!pSamplerChannel) return;
198        EngineChannel* pEngineChannel =
199            pSamplerChannel->GetEngineChannel();
200        if (!pEngineChannel) return;
201        VirtualMidiDevice* pMidiListener = new VirtualMidiDevice;
202        pEngineChannel->Connect(pMidiListener);
203        midi_listener_entry entry = {
204            pSamplerChannel, pEngineChannel, pMidiListener
205        };
206        channelMidiListeners.push_back(entry);
207    }
208    
209  void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) {  void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) {
210      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount));
211  }  }
# Line 152  void LSCPServer::EventHandler::MidiDevic Line 214  void LSCPServer::EventHandler::MidiDevic
214      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount));
215  }  }
216    
217    void LSCPServer::EventHandler::MidiDeviceToBeDestroyed(MidiInputDevice* pDevice) {
218        pDevice->RemoveMidiPortCountListener(this);
219        for (int i = 0; i < pDevice->PortCount(); ++i)
220            MidiPortToBeRemoved(pDevice->GetPort(i));
221    }
222    
223    void LSCPServer::EventHandler::MidiDeviceCreated(MidiInputDevice* pDevice) {
224        pDevice->AddMidiPortCountListener(this);
225        for (int i = 0; i < pDevice->PortCount(); ++i)
226            MidiPortAdded(pDevice->GetPort(i));
227    }
228    
229    void LSCPServer::EventHandler::MidiPortCountChanged(int NewCount) {
230        // yet unused
231    }
232    
233    void LSCPServer::EventHandler::MidiPortToBeRemoved(MidiInputPort* pPort) {
234        for (std::vector<device_midi_listener_entry>::iterator iter = deviceMidiListeners.begin(); iter != deviceMidiListeners.end(); ++iter) {
235            if ((*iter).pPort == pPort) {
236                VirtualMidiDevice* pMidiListener = (*iter).pMidiListener;
237                pPort->Disconnect(pMidiListener);
238                deviceMidiListeners.erase(iter);
239                delete pMidiListener;
240                return;
241            }
242        }
243    }
244    
245    void LSCPServer::EventHandler::MidiPortAdded(MidiInputPort* pPort) {
246        // find out the device ID
247        std::map<uint, MidiInputDevice*> devices =
248            pParent->pSampler->GetMidiInputDevices();
249        for (
250            std::map<uint, MidiInputDevice*>::iterator iter = devices.begin();
251            iter != devices.end(); ++iter
252        ) {
253            if (iter->second == pPort->GetDevice()) { // found
254                VirtualMidiDevice* pMidiListener = new VirtualMidiDevice;
255                pPort->Connect(pMidiListener);
256                device_midi_listener_entry entry = {
257                    pPort, pMidiListener, iter->first
258                };
259                deviceMidiListeners.push_back(entry);
260                return;
261            }
262        }
263    }
264    
265  void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) {  void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) {
266      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount));
267  }  }
# Line 188  void LSCPServer::EventHandler::TotalVoic Line 298  void LSCPServer::EventHandler::TotalVoic
298      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount));      LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount));
299  }  }
300    
301    void LSCPServer::EventHandler::TotalStreamCountChanged(int NewCount) {
302        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_stream_count, NewCount));
303    }
304    
305  #if HAVE_SQLITE3  #if HAVE_SQLITE3
306  void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) {  void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) {
307      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 222  void LSCPServer::DbInstrumentsEventHandl Line 336  void LSCPServer::DbInstrumentsEventHandl
336  }  }
337  #endif // HAVE_SQLITE3  #endif // HAVE_SQLITE3
338    
339    void LSCPServer::RemoveListeners() {
340        pSampler->RemoveChannelCountListener(&eventHandler);
341        pSampler->RemoveAudioDeviceCountListener(&eventHandler);
342        pSampler->RemoveMidiDeviceCountListener(&eventHandler);
343        pSampler->RemoveVoiceCountListener(&eventHandler);
344        pSampler->RemoveStreamCountListener(&eventHandler);
345        pSampler->RemoveBufferFillListener(&eventHandler);
346        pSampler->RemoveTotalStreamCountListener(&eventHandler);
347        pSampler->RemoveTotalVoiceCountListener(&eventHandler);
348        pSampler->RemoveFxSendCountListener(&eventHandler);
349        MidiInstrumentMapper::RemoveMidiInstrumentCountListener(&eventHandler);
350        MidiInstrumentMapper::RemoveMidiInstrumentInfoListener(&eventHandler);
351        MidiInstrumentMapper::RemoveMidiInstrumentMapCountListener(&eventHandler);
352        MidiInstrumentMapper::RemoveMidiInstrumentMapInfoListener(&eventHandler);
353    #if HAVE_SQLITE3
354        InstrumentsDb::GetInstrumentsDb()->RemoveInstrumentsDbListener(&dbInstrumentsEventHandler);
355    #endif
356    }
357    
358  /**  /**
359   * Blocks the calling thread until the LSCP Server is initialized and   * Blocks the calling thread until the LSCP Server is initialized and
# Line 284  int LSCPServer::Main() { Line 416  int LSCPServer::Main() {
416      pSampler->AddVoiceCountListener(&eventHandler);      pSampler->AddVoiceCountListener(&eventHandler);
417      pSampler->AddStreamCountListener(&eventHandler);      pSampler->AddStreamCountListener(&eventHandler);
418      pSampler->AddBufferFillListener(&eventHandler);      pSampler->AddBufferFillListener(&eventHandler);
419        pSampler->AddTotalStreamCountListener(&eventHandler);
420      pSampler->AddTotalVoiceCountListener(&eventHandler);      pSampler->AddTotalVoiceCountListener(&eventHandler);
421      pSampler->AddFxSendCountListener(&eventHandler);      pSampler->AddFxSendCountListener(&eventHandler);
422      MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler);      MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler);
# Line 303  int LSCPServer::Main() { Line 436  int LSCPServer::Main() {
436      timeval timeout;      timeval timeout;
437    
438      while (true) {      while (true) {
439            #if CONFIG_PTHREAD_TESTCANCEL
440                    TestCancel();
441            #endif
442          // 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
443          {          {
444              std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();              std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
# Line 310  int LSCPServer::Main() { Line 446  int LSCPServer::Main() {
446              std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();              std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
447              for (; itEngineChannel != itEnd; ++itEngineChannel) {              for (; itEngineChannel != itEnd; ++itEngineChannel) {
448                  if ((*itEngineChannel)->StatusChanged()) {                  if ((*itEngineChannel)->StatusChanged()) {
449                      SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));                      SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->GetSamplerChannel()->Index()));
450                  }                  }
451    
452                  for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {                  for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {
453                      FxSend* fxs = (*itEngineChannel)->GetFxSend(i);                      FxSend* fxs = (*itEngineChannel)->GetFxSend(i);
454                      if(fxs != NULL && fxs->IsInfoChanged()) {                      if(fxs != NULL && fxs->IsInfoChanged()) {
455                          int chn = (*itEngineChannel)->iSamplerChannelIndex;                          int chn = (*itEngineChannel)->GetSamplerChannel()->Index();
456                          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id()));                          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id()));
457                          fxs->SetInfoChanged(false);                          fxs->SetInfoChanged(false);
458                      }                      }
# Line 324  int LSCPServer::Main() { Line 460  int LSCPServer::Main() {
460              }              }
461          }          }
462    
463            // check if MIDI data arrived on some engine channel
464            for (int i = 0; i < eventHandler.channelMidiListeners.size(); ++i) {
465                const EventHandler::midi_listener_entry entry =
466                    eventHandler.channelMidiListeners[i];
467                VirtualMidiDevice* pMidiListener = entry.pMidiListener;
468                if (pMidiListener->NotesChanged()) {
469                    for (int iNote = 0; iNote < 128; iNote++) {
470                        if (pMidiListener->NoteChanged(iNote)) {
471                            const bool bActive = pMidiListener->NoteIsActive(iNote);
472                            LSCPServer::SendLSCPNotify(
473                                LSCPEvent(
474                                    LSCPEvent::event_channel_midi,
475                                    entry.pSamplerChannel->Index(),
476                                    std::string(bActive ? "NOTE_ON" : "NOTE_OFF"),
477                                    iNote,
478                                    bActive ? pMidiListener->NoteOnVelocity(iNote)
479                                            : pMidiListener->NoteOffVelocity(iNote)
480                                )
481                            );
482                        }
483                    }
484                }
485            }
486    
487            // check if MIDI data arrived on some MIDI device
488            for (int i = 0; i < eventHandler.deviceMidiListeners.size(); ++i) {
489                const EventHandler::device_midi_listener_entry entry =
490                    eventHandler.deviceMidiListeners[i];
491                VirtualMidiDevice* pMidiListener = entry.pMidiListener;
492                if (pMidiListener->NotesChanged()) {
493                    for (int iNote = 0; iNote < 128; iNote++) {
494                        if (pMidiListener->NoteChanged(iNote)) {
495                            const bool bActive = pMidiListener->NoteIsActive(iNote);
496                            LSCPServer::SendLSCPNotify(
497                                LSCPEvent(
498                                    LSCPEvent::event_device_midi,
499                                    entry.uiDeviceID,
500                                    entry.pPort->GetPortNumber(),
501                                    std::string(bActive ? "NOTE_ON" : "NOTE_OFF"),
502                                    iNote,
503                                    bActive ? pMidiListener->NoteOnVelocity(iNote)
504                                            : pMidiListener->NoteOffVelocity(iNote)
505                                )
506                            );
507                        }
508                    }
509                }
510            }
511    
512          //Now let's deliver late notifies (if any)          //Now let's deliver late notifies (if any)
513          NotifyBufferMutex.Lock();          NotifyBufferMutex.Lock();
514          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 342  int LSCPServer::Main() { Line 527  int LSCPServer::Main() {
527    
528          int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout);          int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout);
529    
530          if (retval == 0)          if (retval == 0 || (retval == -1 && errno == EINTR))
531                  continue; //Nothing try again                  continue; //Nothing try again
532          if (retval == -1) {          if (retval == -1) {
533                  std::cerr << "LSCPServer: Socket select error." << std::endl;                  std::cerr << "LSCPServer: Socket select error." << std::endl;
# Line 440  void LSCPServer::CloseConnection( std::v Line 625  void LSCPServer::CloseConnection( std::v
625          NotifyMutex.Unlock();          NotifyMutex.Unlock();
626  }  }
627    
628    void LSCPServer::CloseAllConnections() {
629        std::vector<yyparse_param_t>::iterator iter = Sessions.begin();
630        while(iter != Sessions.end()) {
631            CloseConnection(iter);
632            iter = Sessions.begin();
633        }
634    }
635    
636    void LSCPServer::LockRTNotify() {
637        RTNotifyMutex.Lock();
638    }
639    
640    void LSCPServer::UnlockRTNotify() {
641        RTNotifyMutex.Unlock();
642    }
643    
644  int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) {  int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) {
645          int subs = 0;          int subs = 0;
646          SubscriptionMutex.Lock();          SubscriptionMutex.Lock();
# Line 962  String LSCPServer::GetVoiceCount(uint ui Line 1163  String LSCPServer::GetVoiceCount(uint ui
1163      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel));
1164      LSCPResultSet result;      LSCPResultSet result;
1165      try {      try {
1166          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");  
1167          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");
1168          result.Add(pEngineChannel->GetEngine()->VoiceCount());          result.Add(pEngineChannel->GetEngine()->VoiceCount());
1169      }      }
# Line 983  String LSCPServer::GetStreamCount(uint u Line 1181  String LSCPServer::GetStreamCount(uint u
1181      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel));
1182      LSCPResultSet result;      LSCPResultSet result;
1183      try {      try {
1184          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");  
1185          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");
1186          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
1187      }      }
# Line 1004  String LSCPServer::GetBufferFill(fill_re Line 1199  String LSCPServer::GetBufferFill(fill_re
1199      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel));      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel));
1200      LSCPResultSet result;      LSCPResultSet result;
1201      try {      try {
1202          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");  
1203          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");
1204          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
1205          else {          else {
# Line 1095  String LSCPServer::GetMidiInputDriverInf Line 1287  String LSCPServer::GetMidiInputDriverInf
1287              for (;iter != parameters.end(); iter++) {              for (;iter != parameters.end(); iter++) {
1288                  if (s != "") s += ",";                  if (s != "") s += ",";
1289                  s += iter->first;                  s += iter->first;
1290                    delete iter->second;
1291              }              }
1292              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
1293          }          }
# Line 1119  String LSCPServer::GetAudioOutputDriverI Line 1312  String LSCPServer::GetAudioOutputDriverI
1312              for (;iter != parameters.end(); iter++) {              for (;iter != parameters.end(); iter++) {
1313                  if (s != "") s += ",";                  if (s != "") s += ",";
1314                  s += iter->first;                  s += iter->first;
1315                    delete iter->second;
1316              }              }
1317              result.Add("PARAMETERS", s);              result.Add("PARAMETERS", s);
1318          }          }
# Line 1149  String LSCPServer::GetMidiInputDriverPar Line 1343  String LSCPServer::GetMidiInputDriverPar
1343          if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);          if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
1344          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
1345          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
1346            delete pParameter;
1347      }      }
1348      catch (Exception e) {      catch (Exception e) {
1349          result.Error(e);          result.Error(e);
# Line 1176  String LSCPServer::GetAudioOutputDriverP Line 1371  String LSCPServer::GetAudioOutputDriverP
1371          if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);          if (oRangeMin)      result.Add("RANGE_MIN",     *oRangeMin);
1372          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);          if (oRangeMax)      result.Add("RANGE_MAX",     *oRangeMax);
1373          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);          if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities);
1374            delete pParameter;
1375      }      }
1376      catch (Exception e) {      catch (Exception e) {
1377          result.Error(e);          result.Error(e);
# Line 1685  String LSCPServer::SetVolume(double dVol Line 1881  String LSCPServer::SetVolume(double dVol
1881      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel));
1882      LSCPResultSet result;      LSCPResultSet result;
1883      try {      try {
1884          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");  
1885          pEngineChannel->Volume(dVolume);          pEngineChannel->Volume(dVolume);
1886      }      }
1887      catch (Exception e) {      catch (Exception e) {
# Line 1704  String LSCPServer::SetChannelMute(bool b Line 1897  String LSCPServer::SetChannelMute(bool b
1897      dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel));      dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel));
1898      LSCPResultSet result;      LSCPResultSet result;
1899      try {      try {
1900          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");  
1901    
1902          if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);          if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);
1903          else pEngineChannel->SetMute(1);          else pEngineChannel->SetMute(1);
# Line 1725  String LSCPServer::SetChannelSolo(bool b Line 1914  String LSCPServer::SetChannelSolo(bool b
1914      dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel));      dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel));
1915      LSCPResultSet result;      LSCPResultSet result;
1916      try {      try {
1917          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");  
1918    
1919          bool oldSolo = pEngineChannel->GetSolo();          bool oldSolo = pEngineChannel->GetSolo();
1920          bool hadSoloChannel = HasSoloChannel();          bool hadSoloChannel = HasSoloChannel();
# Line 1849  String LSCPServer::GetMidiInstrumentMapp Line 2034  String LSCPServer::GetMidiInstrumentMapp
2034      dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n"));      dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n"));
2035      LSCPResultSet result;      LSCPResultSet result;
2036      try {      try {
2037          result.Add(MidiInstrumentMapper::Entries(MidiMapID).size());          result.Add(MidiInstrumentMapper::GetInstrumentCount(MidiMapID));
2038      } catch (Exception e) {      } catch (Exception e) {
2039          result.Error(e);          result.Error(e);
2040      }      }
# Line 1860  String LSCPServer::GetMidiInstrumentMapp Line 2045  String LSCPServer::GetMidiInstrumentMapp
2045  String LSCPServer::GetAllMidiInstrumentMappings() {  String LSCPServer::GetAllMidiInstrumentMappings() {
2046      dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n"));      dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n"));
2047      LSCPResultSet result;      LSCPResultSet result;
2048      std::vector<int> maps = MidiInstrumentMapper::Maps();      try {
2049      int totalMappings = 0;          result.Add(MidiInstrumentMapper::GetInstrumentCount());
2050      for (int i = 0; i < maps.size(); i++) {      } catch (Exception e) {
2051          try {          result.Error(e);
             totalMappings += MidiInstrumentMapper::Entries(maps[i]).size();  
         } catch (Exception e) { /*NOOP*/ }  
2052      }      }
     result.Add(totalMappings);  
2053      return result.Produce();      return result.Produce();
2054  }  }
2055    
# Line 1875  String LSCPServer::GetMidiInstrumentMapp Line 2057  String LSCPServer::GetMidiInstrumentMapp
2057      dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n"));      dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n"));
2058      LSCPResultSet result;      LSCPResultSet result;
2059      try {      try {
2060          midi_prog_index_t idx;          MidiInstrumentMapper::entry_t entry = MidiInstrumentMapper::GetEntry(MidiMapID, MidiBank, MidiProg);
2061          idx.midi_bank_msb = (MidiBank >> 7) & 0x7f;          // convert the filename into the correct encoding as defined for LSCP
2062          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)  
2063  #if WIN32  #if WIN32
2064              const String instrumentFileName = Path::fromWindows(iter->second.InstrumentFile).toLscp();          const String instrumentFileName = Path::fromWindows(entry.InstrumentFile).toLscp();
2065  #else  #else
2066              // assuming POSIX          // assuming POSIX
2067              const String instrumentFileName = Path::fromPosix(iter->second.InstrumentFile).toLscp();          const String instrumentFileName = Path::fromPosix(entry.InstrumentFile).toLscp();
2068  #endif  #endif
2069    
2070              result.Add("NAME", _escapeLscpResponse(iter->second.Name));          result.Add("NAME", _escapeLscpResponse(entry.Name));
2071              result.Add("ENGINE_NAME", iter->second.EngineName);          result.Add("ENGINE_NAME", entry.EngineName);
2072              result.Add("INSTRUMENT_FILE", instrumentFileName);          result.Add("INSTRUMENT_FILE", instrumentFileName);
2073              result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex);          result.Add("INSTRUMENT_NR", (int) entry.InstrumentIndex);
2074              String instrumentName;          String instrumentName;
2075              Engine* pEngine = EngineFactory::Create(iter->second.EngineName);          Engine* pEngine = EngineFactory::Create(entry.EngineName);
2076              if (pEngine) {          if (pEngine) {
2077                  if (pEngine->GetInstrumentManager()) {              if (pEngine->GetInstrumentManager()) {
2078                      InstrumentManager::instrument_id_t instrID;                  InstrumentManager::instrument_id_t instrID;
2079                      instrID.FileName = iter->second.InstrumentFile;                  instrID.FileName = entry.InstrumentFile;
2080                      instrID.Index    = iter->second.InstrumentIndex;                  instrID.Index    = entry.InstrumentIndex;
2081                      instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID);                  instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID);
                 }  
                 EngineFactory::Destroy(pEngine);  
2082              }              }
2083              result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName));              EngineFactory::Destroy(pEngine);
2084              switch (iter->second.LoadMode) {          }
2085                  case MidiInstrumentMapper::ON_DEMAND:          result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName));
2086                      result.Add("LOAD_MODE", "ON_DEMAND");          switch (entry.LoadMode) {
2087                      break;              case MidiInstrumentMapper::ON_DEMAND:
2088                  case MidiInstrumentMapper::ON_DEMAND_HOLD:                  result.Add("LOAD_MODE", "ON_DEMAND");
2089                      result.Add("LOAD_MODE", "ON_DEMAND_HOLD");                  break;
2090                      break;              case MidiInstrumentMapper::ON_DEMAND_HOLD:
2091                  case MidiInstrumentMapper::PERSISTENT:                  result.Add("LOAD_MODE", "ON_DEMAND_HOLD");
2092                      result.Add("LOAD_MODE", "PERSISTENT");                  break;
2093                      break;              case MidiInstrumentMapper::PERSISTENT:
2094                  default:                  result.Add("LOAD_MODE", "PERSISTENT");
2095                      throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!");                  break;
2096              }              default:
2097              result.Add("VOLUME", iter->second.Volume);                  throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!");
2098          }          }
2099            result.Add("VOLUME", entry.Volume);
2100      } catch (Exception e) {      } catch (Exception e) {
2101          result.Error(e);          result.Error(e);
2102      }      }
# Line 2095  String LSCPServer::SetChannelMap(uint ui Line 2267  String LSCPServer::SetChannelMap(uint ui
2267      dmsg(2,("LSCPServer: SetChannelMap()\n"));      dmsg(2,("LSCPServer: SetChannelMap()\n"));
2268      LSCPResultSet result;      LSCPResultSet result;
2269      try {      try {
2270          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");  
2271    
2272          if      (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone();          if      (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone();
2273          else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault();          else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault();
# Line 2278  String LSCPServer::EditSamplerChannelIns Line 2446  String LSCPServer::EditSamplerChannelIns
2446      dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel));
2447      LSCPResultSet result;      LSCPResultSet result;
2448      try {      try {
2449          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");  
2450          if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel");          if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel");
2451          Engine* pEngine = pEngineChannel->GetEngine();          Engine* pEngine = pEngineChannel->GetEngine();
2452          InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager();          InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager();
# Line 2296  String LSCPServer::EditSamplerChannelIns Line 2461  String LSCPServer::EditSamplerChannelIns
2461      return result.Produce();      return result.Produce();
2462  }  }
2463    
2464    String LSCPServer::SendChannelMidiData(String MidiMsg, uint uiSamplerChannel, uint Arg1, uint Arg2) {
2465        dmsg(2,("LSCPServer: SendChannelMidiData(MidiMsg=%s,uiSamplerChannel=%d,Arg1=%d,Arg2=%d)\n", MidiMsg.c_str(), uiSamplerChannel, Arg1, Arg2));
2466        LSCPResultSet result;
2467        try {
2468            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2469    
2470            if (Arg1 > 127 || Arg2 > 127) {
2471                throw Exception("Invalid MIDI message");
2472            }
2473    
2474            VirtualMidiDevice* pMidiDevice = NULL;
2475            std::vector<EventHandler::midi_listener_entry>::iterator iter = eventHandler.channelMidiListeners.begin();
2476            for (; iter != eventHandler.channelMidiListeners.end(); ++iter) {
2477                if ((*iter).pEngineChannel == pEngineChannel) {
2478                    pMidiDevice = (*iter).pMidiListener;
2479                    break;
2480                }
2481            }
2482            
2483            if(pMidiDevice == NULL) throw Exception("Couldn't find virtual MIDI device");
2484    
2485            if (MidiMsg == "NOTE_ON") {
2486                pMidiDevice->SendNoteOnToDevice(Arg1, Arg2);
2487                bool b = pMidiDevice->SendNoteOnToSampler(Arg1, Arg2);
2488                if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2));
2489            } else if (MidiMsg == "NOTE_OFF") {
2490                pMidiDevice->SendNoteOffToDevice(Arg1, Arg2);
2491                bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2);
2492                if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2));
2493            } else {
2494                throw Exception("Unknown MIDI message type: " + MidiMsg);
2495            }
2496        } catch (Exception e) {
2497            result.Error(e);
2498        }
2499        return result.Produce();
2500    }
2501    
2502  /**  /**
2503   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
2504   */   */
# Line 2303  String LSCPServer::ResetChannel(uint uiS Line 2506  String LSCPServer::ResetChannel(uint uiS
2506      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel));
2507      LSCPResultSet result;      LSCPResultSet result;
2508      try {      try {
2509          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");  
2510          pEngineChannel->Reset();          pEngineChannel->Reset();
2511      }      }
2512      catch (Exception e) {      catch (Exception e) {
# Line 2347  String LSCPServer::GetServerInfo() { Line 2547  String LSCPServer::GetServerInfo() {
2547  }  }
2548    
2549  /**  /**
2550     * Will be called by the parser to return the current number of all active streams.
2551     */
2552    String LSCPServer::GetTotalStreamCount() {
2553        dmsg(2,("LSCPServer: GetTotalStreamCount()\n"));
2554        LSCPResultSet result;
2555        result.Add(pSampler->GetDiskStreamCount());
2556        return result.Produce();
2557    }
2558    
2559    /**
2560   * 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.
2561   */   */
2562  String LSCPServer::GetTotalVoiceCount() {  String LSCPServer::GetTotalVoiceCount() {
# Line 2362  String LSCPServer::GetTotalVoiceCount() Line 2572  String LSCPServer::GetTotalVoiceCount()
2572  String LSCPServer::GetTotalVoiceCountMax() {  String LSCPServer::GetTotalVoiceCountMax() {
2573      dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));      dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));
2574      LSCPResultSet result;      LSCPResultSet result;
2575      result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES);      result.Add(EngineFactory::EngineInstances().size() * GLOBAL_MAX_VOICES);
2576        return result.Produce();
2577    }
2578    
2579    /**
2580     * Will be called by the parser to return the sampler global maximum
2581     * allowed number of voices.
2582     */
2583    String LSCPServer::GetGlobalMaxVoices() {
2584        dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n"));
2585        LSCPResultSet result;
2586        result.Add(GLOBAL_MAX_VOICES);
2587        return result.Produce();
2588    }
2589    
2590    /**
2591     * Will be called by the parser to set the sampler global maximum number of
2592     * voices.
2593     */
2594    String LSCPServer::SetGlobalMaxVoices(int iVoices) {
2595        dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices));
2596        LSCPResultSet result;
2597        try {
2598            if (iVoices < 1) throw Exception("Maximum voices may not be less than 1");
2599            GLOBAL_MAX_VOICES = iVoices; // see common/global_private.cpp
2600            const std::set<Engine*>& engines = EngineFactory::EngineInstances();
2601            if (engines.size() > 0) {
2602                std::set<Engine*>::iterator iter = engines.begin();
2603                std::set<Engine*>::iterator end  = engines.end();
2604                for (; iter != end; ++iter) {
2605                    (*iter)->SetMaxVoices(iVoices);
2606                }
2607            }
2608            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOICES", GLOBAL_MAX_VOICES));
2609        } catch (Exception e) {
2610            result.Error(e);
2611        }
2612        return result.Produce();
2613    }
2614    
2615    /**
2616     * Will be called by the parser to return the sampler global maximum
2617     * allowed number of disk streams.
2618     */
2619    String LSCPServer::GetGlobalMaxStreams() {
2620        dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n"));
2621        LSCPResultSet result;
2622        result.Add(GLOBAL_MAX_STREAMS);
2623        return result.Produce();
2624    }
2625    
2626    /**
2627     * Will be called by the parser to set the sampler global maximum number of
2628     * disk streams.
2629     */
2630    String LSCPServer::SetGlobalMaxStreams(int iStreams) {
2631        dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams));
2632        LSCPResultSet result;
2633        try {
2634            if (iStreams < 0) throw Exception("Maximum disk streams may not be negative");
2635            GLOBAL_MAX_STREAMS = iStreams; // see common/global_private.cpp
2636            const std::set<Engine*>& engines = EngineFactory::EngineInstances();
2637            if (engines.size() > 0) {
2638                std::set<Engine*>::iterator iter = engines.begin();
2639                std::set<Engine*>::iterator end  = engines.end();
2640                for (; iter != end; ++iter) {
2641                    (*iter)->SetMaxDiskStreams(iStreams);
2642                }
2643            }
2644            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "STREAMS", GLOBAL_MAX_STREAMS));
2645        } catch (Exception e) {
2646            result.Error(e);
2647        }
2648      return result.Produce();      return result.Produce();
2649  }  }
2650    
# Line 2376  String LSCPServer::SetGlobalVolume(doubl Line 2658  String LSCPServer::SetGlobalVolume(doubl
2658      LSCPResultSet result;      LSCPResultSet result;
2659      try {      try {
2660          if (dVolume < 0) throw Exception("Volume may not be negative");          if (dVolume < 0) throw Exception("Volume may not be negative");
2661          GLOBAL_VOLUME = dVolume; // see common/global.cpp          GLOBAL_VOLUME = dVolume; // see common/global_private.cpp
2662          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME));          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME));
2663      } catch (Exception e) {      } catch (Exception e) {
2664          result.Error(e);          result.Error(e);
# Line 2503  String LSCPServer::GetFileInstrumentInfo Line 2785  String LSCPServer::GetFileInstrumentInfo
2785                  result.Add("FORMAT_VERSION", info.FormatVersion);                  result.Add("FORMAT_VERSION", info.FormatVersion);
2786                  result.Add("PRODUCT", info.Product);                  result.Add("PRODUCT", info.Product);
2787                  result.Add("ARTISTS", info.Artists);                  result.Add("ARTISTS", info.Artists);
2788    
2789                    std::stringstream ss;
2790                    bool b = false;
2791                    for (int i = 0; i < 128; i++) {
2792                        if (info.KeyBindings[i]) {
2793                            if (b) ss << ',';
2794                            ss << i; b = true;
2795                        }
2796                    }
2797                    result.Add("KEY_BINDINGS", ss.str());
2798    
2799                    b = false;
2800                    std::stringstream ss2;
2801                    for (int i = 0; i < 128; i++) {
2802                        if (info.KeySwitchBindings[i]) {
2803                            if (b) ss2 << ',';
2804                            ss2 << i; b = true;
2805                        }
2806                    }
2807                    result.Add("KEYSWITCH_BINDINGS", ss2.str());
2808                  // no more need to ask other engine types                  // no more need to ask other engine types
2809                  bFound = true;                  bFound = true;
2810              } 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 2831  void LSCPServer::VerifyFile(String Filen
2831      if ( win32FileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {      if ( win32FileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {
2832          throw Exception("Directory is specified");          throw Exception("Directory is specified");
2833      }      }
2834      #else          #else
2835      struct stat statBuf;      File f(Filename);
2836      int res = stat(Filename.c_str(), &statBuf);      if(!f.Exist()) throw Exception(f.GetErrorMsg());
2837      if (res) {      if (f.IsDirectory()) throw Exception("Directory is specified");
         std::stringstream ss;  
         ss << "Fail to stat `" << Filename << "`: " << strerror(errno);  
         throw Exception(ss.str());  
     }  
   
     if (S_ISDIR(statBuf.st_mode)) {  
         throw Exception("Directory is specified");  
     }  
2838      #endif      #endif
2839  }  }
2840    
# Line 2735  String LSCPServer::AddDbInstruments(Stri Line 3029  String LSCPServer::AddDbInstruments(Stri
3029      return result.Produce();      return result.Produce();
3030  }  }
3031    
3032  String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) {  String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground, bool insDir) {
3033      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));
3034      LSCPResultSet result;      LSCPResultSet result;
3035  #if HAVE_SQLITE3  #if HAVE_SQLITE3
3036      try {      try {
3037          int id;          int id;
3038          InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();          InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();
3039          if (ScanMode.compare("RECURSIVE") == 0) {          if (ScanMode.compare("RECURSIVE") == 0) {
3040             id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground);              id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground, insDir);
3041          } else if (ScanMode.compare("NON_RECURSIVE") == 0) {          } else if (ScanMode.compare("NON_RECURSIVE") == 0) {
3042             id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground);              id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground, insDir);
3043          } else if (ScanMode.compare("FLAT") == 0) {          } else if (ScanMode.compare("FLAT") == 0) {
3044             id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground);              id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground, insDir);
3045          } else {          } else {
3046              throw Exception("Unknown scan mode: " + ScanMode);              throw Exception("Unknown scan mode: " + ScanMode);
3047          }          }
# Line 2923  String LSCPServer::SetDbInstrumentDescri Line 3217  String LSCPServer::SetDbInstrumentDescri
3217      return result.Produce();      return result.Produce();
3218  }  }
3219    
3220    String LSCPServer::SetDbInstrumentFilePath(String OldPath, String NewPath) {
3221        dmsg(2,("LSCPServer: SetDbInstrumentFilePath(OldPath=%s,NewPath=%s)\n", OldPath.c_str(), NewPath.c_str()));
3222        LSCPResultSet result;
3223    #if HAVE_SQLITE3
3224        try {
3225            InstrumentsDb::GetInstrumentsDb()->SetInstrumentFilePath(OldPath, NewPath);
3226        } catch (Exception e) {
3227             result.Error(e);
3228        }
3229    #else
3230        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
3231    #endif
3232        return result.Produce();
3233    }
3234    
3235    String LSCPServer::FindLostDbInstrumentFiles() {
3236        dmsg(2,("LSCPServer: FindLostDbInstrumentFiles()\n"));
3237        LSCPResultSet result;
3238    #if HAVE_SQLITE3
3239        try {
3240            String list;
3241            StringListPtr pLostFiles = InstrumentsDb::GetInstrumentsDb()->FindLostInstrumentFiles();
3242    
3243            for (int i = 0; i < pLostFiles->size(); i++) {
3244                if (list != "") list += ",";
3245                list += "'" + pLostFiles->at(i) + "'";
3246            }
3247    
3248            result.Add(list);
3249        } catch (Exception e) {
3250             result.Error(e);
3251        }
3252    #else
3253        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
3254    #endif
3255        return result.Produce();
3256    }
3257    
3258  String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) {  String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) {
3259      dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str()));      dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str()));
3260      LSCPResultSet result;      LSCPResultSet result;
# Line 3053  String LSCPServer::SetEcho(yyparse_param Line 3385  String LSCPServer::SetEcho(yyparse_param
3385      }      }
3386      return result.Produce();      return result.Produce();
3387  }  }
3388    
3389    }

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

  ViewVC Help
Powered by ViewVC