/[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 1765 by persson, Sat Sep 6 16:44:42 2008 UTC revision 1771 by iliev, Wed Sep 10 15:02:24 2008 UTC
# Line 22  Line 22 
22   ***************************************************************************/   ***************************************************************************/
23    
24  #include <algorithm>  #include <algorithm>
25    #include <string>
26    
27  #include "lscpserver.h"  #include "lscpserver.h"
28  #include "lscpresultset.h"  #include "lscpresultset.h"
# Line 1134  String LSCPServer::GetVoiceCount(uint ui Line 1135  String LSCPServer::GetVoiceCount(uint ui
1135      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel));
1136      LSCPResultSet result;      LSCPResultSet result;
1137      try {      try {
1138          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine loaded on sampler channel");  
1139          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
1140          result.Add(pEngineChannel->GetEngine()->VoiceCount());          result.Add(pEngineChannel->GetEngine()->VoiceCount());
1141      }      }
# Line 1155  String LSCPServer::GetStreamCount(uint u Line 1153  String LSCPServer::GetStreamCount(uint u
1153      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel));
1154      LSCPResultSet result;      LSCPResultSet result;
1155      try {      try {
1156          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
1157          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
1158          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());          result.Add(pEngineChannel->GetEngine()->DiskStreamCount());
1159      }      }
# Line 1176  String LSCPServer::GetBufferFill(fill_re Line 1171  String LSCPServer::GetBufferFill(fill_re
1171      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel));      dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel));
1172      LSCPResultSet result;      LSCPResultSet result;
1173      try {      try {
1174          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
1175          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");          if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel");
1176          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");          if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA");
1177          else {          else {
# Line 1857  String LSCPServer::SetVolume(double dVol Line 1849  String LSCPServer::SetVolume(double dVol
1849      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel));      dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel));
1850      LSCPResultSet result;      LSCPResultSet result;
1851      try {      try {
1852          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
1853          pEngineChannel->Volume(dVolume);          pEngineChannel->Volume(dVolume);
1854      }      }
1855      catch (Exception e) {      catch (Exception e) {
# Line 1876  String LSCPServer::SetChannelMute(bool b Line 1865  String LSCPServer::SetChannelMute(bool b
1865      dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel));      dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel));
1866      LSCPResultSet result;      LSCPResultSet result;
1867      try {      try {
1868          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
   
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
1869    
1870          if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);          if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0);
1871          else pEngineChannel->SetMute(1);          else pEngineChannel->SetMute(1);
# Line 1897  String LSCPServer::SetChannelSolo(bool b Line 1882  String LSCPServer::SetChannelSolo(bool b
1882      dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel));      dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel));
1883      LSCPResultSet result;      LSCPResultSet result;
1884      try {      try {
1885          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
   
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
1886    
1887          bool oldSolo = pEngineChannel->GetSolo();          bool oldSolo = pEngineChannel->GetSolo();
1888          bool hadSoloChannel = HasSoloChannel();          bool hadSoloChannel = HasSoloChannel();
# Line 2254  String LSCPServer::SetChannelMap(uint ui Line 2235  String LSCPServer::SetChannelMap(uint ui
2235      dmsg(2,("LSCPServer: SetChannelMap()\n"));      dmsg(2,("LSCPServer: SetChannelMap()\n"));
2236      LSCPResultSet result;      LSCPResultSet result;
2237      try {      try {
2238          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
   
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");  
2239    
2240          if      (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone();          if      (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone();
2241          else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault();          else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault();
# Line 2437  String LSCPServer::EditSamplerChannelIns Line 2414  String LSCPServer::EditSamplerChannelIns
2414      dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel));
2415      LSCPResultSet result;      LSCPResultSet result;
2416      try {      try {
2417          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");  
2418          if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel");          if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel");
2419          Engine* pEngine = pEngineChannel->GetEngine();          Engine* pEngine = pEngineChannel->GetEngine();
2420          InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager();          InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager();
# Line 2455  String LSCPServer::EditSamplerChannelIns Line 2429  String LSCPServer::EditSamplerChannelIns
2429      return result.Produce();      return result.Produce();
2430  }  }
2431    
2432    String LSCPServer::SendChannelMidiData(String MidiMsg, uint uiSamplerChannel, uint Arg1, uint Arg2) {
2433        dmsg(2,("LSCPServer: SendChannelMidiData(MidiMsg=%s,uiSamplerChannel=%d,Arg1=%d,Arg2=%d)\n", MidiMsg.c_str(), uiSamplerChannel, Arg1, Arg2));
2434        LSCPResultSet result;
2435        try {
2436            EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2437    
2438            if (Arg1 > 127 || Arg2 > 127) {
2439                throw Exception("Invalid MIDI message");
2440            }
2441    
2442            VirtualMidiDevice* pMidiDevice = NULL;
2443            std::vector<EventHandler::midi_listener_entry>::iterator iter = eventHandler.channelMidiListeners.begin();
2444            for (; iter != eventHandler.channelMidiListeners.end(); ++iter) {
2445                if ((*iter).pEngineChannel == pEngineChannel) {
2446                    pMidiDevice = (*iter).pMidiListener;
2447                    break;
2448                }
2449            }
2450            
2451            if(pMidiDevice == NULL) throw Exception("Couldn't find virtual MIDI device");
2452    
2453            if (MidiMsg == "NOTE_ON") {
2454                bool b = pMidiDevice->SendNoteOnToSampler(Arg1, Arg2);
2455                if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2));
2456            } else if (MidiMsg == "NOTE_OFF") {
2457                bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2);
2458                if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2));
2459            } else {
2460                throw Exception("Unknown MIDI message type: " + MidiMsg);
2461            }
2462        } catch (Exception e) {
2463            result.Error(e);
2464        }
2465        return result.Produce();
2466    }
2467    
2468  /**  /**
2469   * Will be called by the parser to reset a particular sampler channel.   * Will be called by the parser to reset a particular sampler channel.
2470   */   */
# Line 2462  String LSCPServer::ResetChannel(uint uiS Line 2472  String LSCPServer::ResetChannel(uint uiS
2472      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel));      dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel));
2473      LSCPResultSet result;      LSCPResultSet result;
2474      try {      try {
2475          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");  
2476          pEngineChannel->Reset();          pEngineChannel->Reset();
2477      }      }
2478      catch (Exception e) {      catch (Exception e) {
# Line 2672  String LSCPServer::GetFileInstrumentInfo Line 2679  String LSCPServer::GetFileInstrumentInfo
2679                  result.Add("FORMAT_VERSION", info.FormatVersion);                  result.Add("FORMAT_VERSION", info.FormatVersion);
2680                  result.Add("PRODUCT", info.Product);                  result.Add("PRODUCT", info.Product);
2681                  result.Add("ARTISTS", info.Artists);                  result.Add("ARTISTS", info.Artists);
2682    
2683                    std::stringstream ss;
2684                    bool b = false;
2685                    for (int i = 0; i < 128; i++) {
2686                        if (info.KeyBindings[i]) {
2687                            if (b) ss << ',';
2688                            ss << i; b = true;
2689                        }
2690                    }
2691                    result.Add("KEY_BINDINGS", ss.str());
2692    
2693                    std::stringstream ss2;
2694                    for (int i = 0; i < 128; i++) {
2695                        if (info.KeySwitchBindings[i]) {
2696                            if (b) ss2 << ',';
2697                            ss2 << i; b = true;
2698                        }
2699                    }
2700                    result.Add("KEYSWITCH_BINDINGS", ss2.str());
2701                  // no more need to ask other engine types                  // no more need to ask other engine types
2702                  bFound = true;                  bFound = true;
2703              } 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()));

Legend:
Removed from v.1765  
changed lines
  Added in v.1771

  ViewVC Help
Powered by ViewVC