/[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 2137 by schoenebeck, Mon Oct 4 12:20:23 2010 UTC revision 2375 by schoenebeck, Thu Oct 4 17:45:22 2012 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 - 2010 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2012 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 138  LSCPServer::LSCPServer(Sampler* pSampler Line 138  LSCPServer::LSCPServer(Sampler* pSampler
138      LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO");
139      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI");
140      LSCPEvent::RegisterEvent(LSCPEvent::event_device_midi, "DEVICE_MIDI");      LSCPEvent::RegisterEvent(LSCPEvent::event_device_midi, "DEVICE_MIDI");
141        LSCPEvent::RegisterEvent(LSCPEvent::event_fx_instance_count, "EFFECT_INSTANCE_COUNT");
142        LSCPEvent::RegisterEvent(LSCPEvent::event_fx_instance_info, "EFFECT_INSTANCE_INFO");
143        LSCPEvent::RegisterEvent(LSCPEvent::event_send_fx_chain_count, "SEND_EFFECT_CHAIN_COUNT");
144        LSCPEvent::RegisterEvent(LSCPEvent::event_send_fx_chain_info, "SEND_EFFECT_CHAIN_INFO");
145      hSocket = -1;      hSocket = -1;
146  }  }
147    
# Line 443  int LSCPServer::Main() { Line 447  int LSCPServer::Main() {
447          #endif          #endif
448          // 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
449          {          {
450                EngineChannelFactory::EngineChannelsMutex.Lock();
451              std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();              std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
452              std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();              std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
453              std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();              std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
# Line 460  int LSCPServer::Main() { Line 465  int LSCPServer::Main() {
465                      }                      }
466                  }                  }
467              }              }
468                EngineChannelFactory::EngineChannelsMutex.Unlock();
469          }          }
470    
471          // check if MIDI data arrived on some engine channel          // check if MIDI data arrived on some engine channel
# Line 2393  String LSCPServer::GetFxSendInfo(uint ui Line 2399  String LSCPServer::GetFxSendInfo(uint ui
2399          result.Add("MIDI_CONTROLLER", pFxSend->MidiController());          result.Add("MIDI_CONTROLLER", pFxSend->MidiController());
2400          result.Add("LEVEL", ToString(pFxSend->Level()));          result.Add("LEVEL", ToString(pFxSend->Level()));
2401          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
2402          result.Add("SEND_EFFECT", sEffectRouting);          result.Add("EFFECT", sEffectRouting);
2403      } catch (Exception e) {      } catch (Exception e) {
2404          result.Error(e);          result.Error(e);
2405      }      }
# Line 2610  String LSCPServer::SetEffectInstanceInpu Line 2616  String LSCPServer::SetEffectInstanceInpu
2616              );              );
2617    
2618          pEffectControl->SetValue(dValue);          pEffectControl->SetValue(dValue);
2619            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_info, iEffectInstance));
2620      } catch (Exception e) {      } catch (Exception e) {
2621          result.Error(e);          result.Error(e);
2622      }      }
# Line 2624  String LSCPServer::CreateEffectInstance( Line 2631  String LSCPServer::CreateEffectInstance(
2631          if (!pEffectInfo)          if (!pEffectInfo)
2632              throw Exception("There is no effect with index " + ToString(iEffectIndex));              throw Exception("There is no effect with index " + ToString(iEffectIndex));
2633          Effect* pEffect = EffectFactory::Create(pEffectInfo);          Effect* pEffect = EffectFactory::Create(pEffectInfo);
2634          result.Add(pEffect->ID());          result = pEffect->ID(); // success
2635            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount()));
2636      } catch (Exception e) {      } catch (Exception e) {
2637          result.Error(e);          result.Error(e);
2638      }      }
# Line 2671  String LSCPServer::CreateEffectInstance( Line 2679  String LSCPServer::CreateEffectInstance(
2679    
2680          Effect* pEffect = EffectFactory::Create(pEffectInfo);          Effect* pEffect = EffectFactory::Create(pEffectInfo);
2681          result = LSCPResultSet(pEffect->ID());          result = LSCPResultSet(pEffect->ID());
2682            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount()));
2683      } catch (Exception e) {      } catch (Exception e) {
2684          result.Error(e);          result.Error(e);
2685      }      }
# Line 2685  String LSCPServer::DestroyEffectInstance Line 2694  String LSCPServer::DestroyEffectInstance
2694          if (!pEffect)          if (!pEffect)
2695              throw Exception("There is no effect instance with ID " + ToString(iEffectInstance));              throw Exception("There is no effect instance with ID " + ToString(iEffectInstance));
2696          EffectFactory::Destroy(pEffect);          EffectFactory::Destroy(pEffect);
2697            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount()));
2698      } catch (Exception e) {      } catch (Exception e) {
2699          result.Error(e);          result.Error(e);
2700      }      }
# Line 2768  String LSCPServer::AddSendEffectChain(in Line 2778  String LSCPServer::AddSendEffectChain(in
2778              throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + ".");              throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + ".");
2779          AudioOutputDevice* pDevice = devices[iAudioOutputDevice];          AudioOutputDevice* pDevice = devices[iAudioOutputDevice];
2780          EffectChain* pEffectChain = pDevice->AddSendEffectChain();          EffectChain* pEffectChain = pDevice->AddSendEffectChain();
2781          result.Add(pEffectChain->ID());          result = pEffectChain->ID();
2782            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_count, iAudioOutputDevice, pDevice->SendEffectChainCount()));
2783      } catch (Exception e) {      } catch (Exception e) {
2784          result.Error(e);          result.Error(e);
2785      }      }
# Line 2782  String LSCPServer::RemoveSendEffectChain Line 2793  String LSCPServer::RemoveSendEffectChain
2793          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();          std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices();
2794          if (!devices.count(iAudioOutputDevice))          if (!devices.count(iAudioOutputDevice))
2795              throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + ".");              throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + ".");
2796    
2797            std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
2798            std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
2799            std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
2800            for (; itEngineChannel != itEnd; ++itEngineChannel) {
2801                AudioOutputDevice* pDev = (*itEngineChannel)->GetAudioOutputDevice();
2802                if (pDev != NULL && pDev->deviceId() == iAudioOutputDevice) {
2803                    for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {
2804                        FxSend* fxs = (*itEngineChannel)->GetFxSend(i);
2805                        if(fxs != NULL && fxs->DestinationEffectChain() == iSendEffectChain) {
2806                            throw Exception("The effect chain is still in use by channel " + ToString((*itEngineChannel)->GetSamplerChannel()->Index()));
2807                        }
2808                    }
2809                }
2810            }
2811    
2812          AudioOutputDevice* pDevice = devices[iAudioOutputDevice];          AudioOutputDevice* pDevice = devices[iAudioOutputDevice];
2813          for (int i = 0; i < pDevice->SendEffectChainCount(); i++) {          for (int i = 0; i < pDevice->SendEffectChainCount(); i++) {
2814              EffectChain* pEffectChain = pDevice->SendEffectChain(i);              EffectChain* pEffectChain = pDevice->SendEffectChain(i);
2815              if (pEffectChain->ID() == iSendEffectChain) {              if (pEffectChain->ID() == iSendEffectChain) {
2816                  pDevice->RemoveSendEffectChain(i);                  pDevice->RemoveSendEffectChain(i);
2817                    LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_count, iAudioOutputDevice, pDevice->SendEffectChainCount()));
2818                  return result.Produce();                  return result.Produce();
2819              }              }
2820          }          }
# Line 2809  static EffectChain* _getSendEffectChain( Line 2837  static EffectChain* _getSendEffectChain(
2837              ToString(iAudioOutputDevice) + "."              ToString(iAudioOutputDevice) + "."
2838          );          );
2839      AudioOutputDevice* pDevice = devices[iAudioOutputDevice];      AudioOutputDevice* pDevice = devices[iAudioOutputDevice];
2840      for (int i = 0; i < pDevice->SendEffectChainCount(); i++) {      EffectChain* pEffectChain = pDevice->SendEffectChainByID(iSendEffectChain);
2841          EffectChain* pEffectChain = pDevice->SendEffectChain(i);      if(pEffectChain != NULL) return pEffectChain;
         if (pEffectChain->ID() == iSendEffectChain) {  
             return pEffectChain;  
         }  
     }  
2842      throw Exception(      throw Exception(
2843          "There is no send effect chain with ID " +          "There is no send effect chain with ID " +
2844          ToString(iSendEffectChain) + " for audio output device " +          ToString(iSendEffectChain) + " for audio output device " +
# Line 2851  String LSCPServer::AppendSendEffectChain Line 2875  String LSCPServer::AppendSendEffectChain
2875          if (!pEffect)          if (!pEffect)
2876              throw Exception("There is no effect instance with ID " + ToString(iEffectInstance));              throw Exception("There is no effect instance with ID " + ToString(iEffectInstance));
2877          pEffectChain->AppendEffect(pEffect);          pEffectChain->AppendEffect(pEffect);
2878            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount()));
2879      } catch (Exception e) {      } catch (Exception e) {
2880          result.Error(e);          result.Error(e);
2881      }      }
# Line 2867  String LSCPServer::InsertSendEffectChain Line 2892  String LSCPServer::InsertSendEffectChain
2892          if (!pEffect)          if (!pEffect)
2893              throw Exception("There is no effect instance with index " + ToString(iEffectInstance));              throw Exception("There is no effect instance with index " + ToString(iEffectInstance));
2894          pEffectChain->InsertEffect(pEffect, iEffectChainPosition);          pEffectChain->InsertEffect(pEffect, iEffectChainPosition);
2895            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount()));
2896      } catch (Exception e) {      } catch (Exception e) {
2897          result.Error(e);          result.Error(e);
2898      }      }
# Line 2879  String LSCPServer::RemoveSendEffectChain Line 2905  String LSCPServer::RemoveSendEffectChain
2905      try {      try {
2906          EffectChain* pEffectChain =          EffectChain* pEffectChain =
2907              _getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain);              _getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain);
2908    
2909            std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances();
2910            std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin();
2911            std::set<EngineChannel*>::iterator itEnd           = engineChannels.end();
2912            for (; itEngineChannel != itEnd; ++itEngineChannel) {
2913                AudioOutputDevice* pDev = (*itEngineChannel)->GetAudioOutputDevice();
2914                if (pDev != NULL && pDev->deviceId() == iAudioOutputDevice) {
2915                    for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {
2916                        FxSend* fxs = (*itEngineChannel)->GetFxSend(i);
2917                        if(fxs != NULL && fxs->DestinationEffectChain() == iSendEffectChain && fxs->DestinationEffectChainPosition() == iEffectChainPosition) {
2918                            throw Exception("The effect instance is still in use by channel " + ToString((*itEngineChannel)->GetSamplerChannel()->Index()));
2919                        }
2920                    }
2921                }
2922            }
2923    
2924          pEffectChain->RemoveEffect(iEffectChainPosition);          pEffectChain->RemoveEffect(iEffectChainPosition);
2925            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount()));
2926      } catch (Exception e) {      } catch (Exception e) {
2927          result.Error(e);          result.Error(e);
2928      }      }
# Line 3020  String LSCPServer::GetTotalVoiceCount() Line 3063  String LSCPServer::GetTotalVoiceCount()
3063  String LSCPServer::GetTotalVoiceCountMax() {  String LSCPServer::GetTotalVoiceCountMax() {
3064      dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));      dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n"));
3065      LSCPResultSet result;      LSCPResultSet result;
3066      result.Add(EngineFactory::EngineInstances().size() * GLOBAL_MAX_VOICES);      result.Add(EngineFactory::EngineInstances().size() * pSampler->GetGlobalMaxVoices());
3067      return result.Produce();      return result.Produce();
3068  }  }
3069    
# Line 3031  String LSCPServer::GetTotalVoiceCountMax Line 3074  String LSCPServer::GetTotalVoiceCountMax
3074  String LSCPServer::GetGlobalMaxVoices() {  String LSCPServer::GetGlobalMaxVoices() {
3075      dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n"));      dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n"));
3076      LSCPResultSet result;      LSCPResultSet result;
3077      result.Add(GLOBAL_MAX_VOICES);      result.Add(pSampler->GetGlobalMaxVoices());
3078      return result.Produce();      return result.Produce();
3079  }  }
3080    
# Line 3043  String LSCPServer::SetGlobalMaxVoices(in Line 3086  String LSCPServer::SetGlobalMaxVoices(in
3086      dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices));      dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices));
3087      LSCPResultSet result;      LSCPResultSet result;
3088      try {      try {
3089          if (iVoices < 1) throw Exception("Maximum voices may not be less than 1");          pSampler->SetGlobalMaxVoices(iVoices);
3090          GLOBAL_MAX_VOICES = iVoices; // see common/global_private.cpp          LSCPServer::SendLSCPNotify(
3091          const std::set<Engine*>& engines = EngineFactory::EngineInstances();              LSCPEvent(LSCPEvent::event_global_info, "VOICES", pSampler->GetGlobalMaxVoices())
3092          if (engines.size() > 0) {          );
             std::set<Engine*>::iterator iter = engines.begin();  
             std::set<Engine*>::iterator end  = engines.end();  
             for (; iter != end; ++iter) {  
                 (*iter)->SetMaxVoices(iVoices);  
             }  
         }  
         LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOICES", GLOBAL_MAX_VOICES));  
3093      } catch (Exception e) {      } catch (Exception e) {
3094          result.Error(e);          result.Error(e);
3095      }      }
# Line 3067  String LSCPServer::SetGlobalMaxVoices(in Line 3103  String LSCPServer::SetGlobalMaxVoices(in
3103  String LSCPServer::GetGlobalMaxStreams() {  String LSCPServer::GetGlobalMaxStreams() {
3104      dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n"));      dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n"));
3105      LSCPResultSet result;      LSCPResultSet result;
3106      result.Add(GLOBAL_MAX_STREAMS);      result.Add(pSampler->GetGlobalMaxStreams());
3107      return result.Produce();      return result.Produce();
3108  }  }
3109    
# Line 3079  String LSCPServer::SetGlobalMaxStreams(i Line 3115  String LSCPServer::SetGlobalMaxStreams(i
3115      dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams));      dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams));
3116      LSCPResultSet result;      LSCPResultSet result;
3117      try {      try {
3118          if (iStreams < 0) throw Exception("Maximum disk streams may not be negative");          pSampler->SetGlobalMaxStreams(iStreams);
3119          GLOBAL_MAX_STREAMS = iStreams; // see common/global_private.cpp          LSCPServer::SendLSCPNotify(
3120          const std::set<Engine*>& engines = EngineFactory::EngineInstances();              LSCPEvent(LSCPEvent::event_global_info, "STREAMS", pSampler->GetGlobalMaxStreams())
3121          if (engines.size() > 0) {          );
             std::set<Engine*>::iterator iter = engines.begin();  
             std::set<Engine*>::iterator end  = engines.end();  
             for (; iter != end; ++iter) {  
                 (*iter)->SetMaxDiskStreams(iStreams);  
             }  
         }  
         LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "STREAMS", GLOBAL_MAX_STREAMS));  
3122      } catch (Exception e) {      } catch (Exception e) {
3123          result.Error(e);          result.Error(e);
3124      }      }

Legend:
Removed from v.2137  
changed lines
  Added in v.2375

  ViewVC Help
Powered by ViewVC