/[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 1007 by schoenebeck, Tue Jan 2 15:37:01 2007 UTC revision 1212 by schoenebeck, Tue May 29 23:59:36 2007 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, 2006 Christian Schoenebeck                        *   *   Copyright (C) 2005 - 2007 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 24  Line 24 
24  #include "lscpserver.h"  #include "lscpserver.h"
25  #include "lscpresultset.h"  #include "lscpresultset.h"
26  #include "lscpevent.h"  #include "lscpevent.h"
 #include "../common/global.h"  
27    
28  #include <fcntl.h>  #include <fcntl.h>
29    
30  #if HAVE_SQLITE3  #if ! HAVE_SQLITE3
31  # include "sqlite3.h"  #define DOESNT_HAVE_SQLITE3 "No database support. SQLITE3 was not installed when linuxsampler was built."
32  #endif  #endif
33    
34  #include "../engines/EngineFactory.h"  #include "../engines/EngineFactory.h"
# Line 75  LSCPServer::LSCPServer(Sampler* pSampler Line 74  LSCPServer::LSCPServer(Sampler* pSampler
74      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT");
75      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");      LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL");
76      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO");
77        LSCPEvent::RegisterEvent(LSCPEvent::event_fx_send_count, "FX_SEND_COUNT");
78        LSCPEvent::RegisterEvent(LSCPEvent::event_fx_send_info, "FX_SEND_INFO");
79      LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_count, "MIDI_INSTRUMENT_MAP_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_count, "MIDI_INSTRUMENT_MAP_COUNT");
80      LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO");
81      LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT");
82      LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO");      LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO");
83        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_count, "DB_INSTRUMENT_DIRECTORY_COUNT");
84        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_info, "DB_INSTRUMENT_DIRECTORY_INFO");
85        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_count, "DB_INSTRUMENT_COUNT");
86        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO");
87        LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO");
88      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");      LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS");
89      LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");      LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT");
90        LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO");
91      hSocket = -1;      hSocket = -1;
92  }  }
93    
# Line 88  LSCPServer::~LSCPServer() { Line 95  LSCPServer::~LSCPServer() {
95      if (hSocket >= 0) close(hSocket);      if (hSocket >= 0) close(hSocket);
96  }  }
97    
98    void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) {
99        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount));
100    }
101    
102    void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) {
103        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount));
104    }
105    
106    void LSCPServer::EventHandler::MidiDeviceCountChanged(int NewCount) {
107        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount));
108    }
109    
110    void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) {
111        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount));
112    }
113    
114    void LSCPServer::EventHandler::MidiInstrumentInfoChanged(int MapId, int Bank, int Program) {
115        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_info, MapId, Bank, Program));
116    }
117    
118    void LSCPServer::EventHandler::MidiInstrumentMapCountChanged(int NewCount) {
119        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_count, NewCount));
120    }
121    
122    void LSCPServer::EventHandler::MidiInstrumentMapInfoChanged(int MapId) {
123        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_info, MapId));
124    }
125    
126    void LSCPServer::EventHandler::FxSendCountChanged(int ChannelId, int NewCount) {
127        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_count, ChannelId, NewCount));
128    }
129    
130    void LSCPServer::EventHandler::VoiceCountChanged(int ChannelId, int NewCount) {
131        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_voice_count, ChannelId, NewCount));
132    }
133    
134    void LSCPServer::EventHandler::StreamCountChanged(int ChannelId, int NewCount) {
135        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_stream_count, ChannelId, NewCount));
136    }
137    
138    void LSCPServer::EventHandler::BufferFillChanged(int ChannelId, String FillData) {
139        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_buffer_fill, ChannelId, FillData));
140    }
141    
142    void LSCPServer::EventHandler::TotalVoiceCountChanged(int NewCount) {
143        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount));
144    }
145    
146    #if HAVE_SQLITE3
147    void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) {
148        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, Dir));
149    }
150    
151    void LSCPServer::DbInstrumentsEventHandler::DirectoryInfoChanged(String Dir) {
152        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, Dir));
153    }
154    
155    void LSCPServer::DbInstrumentsEventHandler::DirectoryNameChanged(String Dir, String NewName) {
156        Dir = "'" + Dir + "'";
157        NewName = "'" + NewName + "'";
158        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, "NAME", Dir, NewName));
159    }
160    
161    void LSCPServer::DbInstrumentsEventHandler::InstrumentCountChanged(String Dir) {
162        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_count, Dir));
163    }
164    
165    void LSCPServer::DbInstrumentsEventHandler::InstrumentInfoChanged(String Instr) {
166        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, Instr));
167    }
168    
169    void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) {
170        Instr = "'" + Instr + "'";
171        NewName = "'" + NewName + "'";
172        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, "NAME", Instr, NewName));
173    }
174    
175    void LSCPServer::DbInstrumentsEventHandler::JobStatusChanged(int JobId) {
176        LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instrs_job_info, JobId));
177    }
178    #endif // HAVE_SQLITE3
179    
180    
181  /**  /**
182   * Blocks the calling thread until the LSCP Server is initialized and   * Blocks the calling thread until the LSCP Server is initialized and
183   * accepting socket connections, if the server is already initialized then   * accepting socket connections, if the server is already initialized then
# Line 128  int LSCPServer::Main() { Line 218  int LSCPServer::Main() {
218    
219      listen(hSocket, 1);      listen(hSocket, 1);
220      Initialized.Set(true);      Initialized.Set(true);
221        
222        // Registering event listeners
223        pSampler->AddChannelCountListener(&eventHandler);
224        pSampler->AddAudioDeviceCountListener(&eventHandler);
225        pSampler->AddMidiDeviceCountListener(&eventHandler);
226        pSampler->AddVoiceCountListener(&eventHandler);
227        pSampler->AddStreamCountListener(&eventHandler);
228        pSampler->AddBufferFillListener(&eventHandler);
229        pSampler->AddTotalVoiceCountListener(&eventHandler);
230        pSampler->AddFxSendCountListener(&eventHandler);
231        MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler);
232        MidiInstrumentMapper::AddMidiInstrumentInfoListener(&eventHandler);
233        MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&eventHandler);
234        MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(&eventHandler);
235    #if HAVE_SQLITE3
236        InstrumentsDb::GetInstrumentsDb()->AddInstrumentsDbListener(&dbInstrumentsEventHandler);
237    #endif
238      // now wait for client connections and handle their requests      // now wait for client connections and handle their requests
239      sockaddr_in client;      sockaddr_in client;
240      int length = sizeof(client);      int length = sizeof(client);
# Line 148  int LSCPServer::Main() { Line 254  int LSCPServer::Main() {
254                  if ((*itEngineChannel)->StatusChanged()) {                  if ((*itEngineChannel)->StatusChanged()) {
255                      SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));                      SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex));
256                  }                  }
257    
258                    for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) {
259                        FxSend* fxs = (*itEngineChannel)->GetFxSend(i);
260                        if(fxs != NULL && fxs->IsInfoChanged()) {
261                            int chn = (*itEngineChannel)->iSamplerChannelIndex;
262                            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id()));
263                            fxs->SetInfoChanged(false);
264                        }
265                    }
266              }              }
267          }          }
268    
# Line 490  String LSCPServer::DestroyMidiInputDevic Line 605  String LSCPServer::DestroyMidiInputDevic
605      return result.Produce();      return result.Produce();
606  }  }
607    
608    EngineChannel* LSCPServer::GetEngineChannel(uint uiSamplerChannel) {
609        SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
610        if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
611    
612        EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
613        if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");
614    
615        return pEngineChannel;        
616    }
617    
618  /**  /**
619   * Will be called by the parser to load an instrument.   * Will be called by the parser to load an instrument.
620   */   */
# Line 670  String LSCPServer::GetChannelInfo(uint u Line 795  String LSCPServer::GetChannelInfo(uint u
795          String AudioRouting;          String AudioRouting;
796          int Mute = 0;          int Mute = 0;
797          bool Solo = false;          bool Solo = false;
798          String MidiInstrumentMap;          String MidiInstrumentMap = "NONE";
799    
800          if (pEngineChannel) {          if (pEngineChannel) {
801              EngineName          = pEngineChannel->EngineName();              EngineName          = pEngineChannel->EngineName();
# Line 1502  String LSCPServer::SetChannelSolo(bool b Line 1627  String LSCPServer::SetChannelSolo(bool b
1627    
1628          bool oldSolo = pEngineChannel->GetSolo();          bool oldSolo = pEngineChannel->GetSolo();
1629          bool hadSoloChannel = HasSoloChannel();          bool hadSoloChannel = HasSoloChannel();
1630            
1631          pEngineChannel->SetSolo(bSolo);          pEngineChannel->SetSolo(bSolo);
1632            
1633          if(!oldSolo && bSolo) {          if(!oldSolo && bSolo) {
1634              if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0);              if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0);
1635              if(!hadSoloChannel) MuteNonSoloChannels();              if(!hadSoloChannel) MuteNonSoloChannels();
1636          }          }
1637            
1638          if(oldSolo && !bSolo) {          if(oldSolo && !bSolo) {
1639              if(!HasSoloChannel()) UnmuteChannels();              if(!HasSoloChannel()) UnmuteChannels();
1640              else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1);              else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1);
# Line 1567  void  LSCPServer::UnmuteChannels() { Line 1692  void  LSCPServer::UnmuteChannels() {
1692      }      }
1693  }  }
1694    
1695  String LSCPServer::AddOrReplaceMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg, String EngineType, String InstrumentFile, uint InstrumentIndex, float Volume, MidiInstrumentMapper::mode_t LoadMode, String Name) {  String LSCPServer::AddOrReplaceMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg, String EngineType, String InstrumentFile, uint InstrumentIndex, float Volume, MidiInstrumentMapper::mode_t LoadMode, String Name, bool bModal) {
1696      dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n"));      dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n"));
1697    
1698      midi_prog_index_t idx;      midi_prog_index_t idx;
# Line 1585  String LSCPServer::AddOrReplaceMIDIInstr Line 1710  String LSCPServer::AddOrReplaceMIDIInstr
1710    
1711      LSCPResultSet result;      LSCPResultSet result;
1712      try {      try {
1713          // PERSISTENT mapping commands might bloock for a long time, so in          // PERSISTENT mapping commands might block for a long time, so in
1714          // that case we add/replace the mapping in another thread          // that case we add/replace the mapping in another thread in case
1715          bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT);          // the NON_MODAL argument was supplied, non persistent mappings
1716            // should return immediately, so we don't need to do that for them
1717            bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT && !bModal);
1718          MidiInstrumentMapper::AddOrReplaceEntry(MidiMapID, idx, entry, bInBackground);          MidiInstrumentMapper::AddOrReplaceEntry(MidiMapID, idx, entry, bInBackground);
1719      } catch (Exception e) {      } catch (Exception e) {
1720          result.Error(e);          result.Error(e);
# Line 1720  String LSCPServer::ListAllMidiInstrument Line 1847  String LSCPServer::ListAllMidiInstrument
1847              for (; iter != mappings.end(); iter++) {              for (; iter != mappings.end(); iter++) {
1848                  if (s.size()) s += ",";                  if (s.size()) s += ",";
1849                  s += "{" + ToString(maps[i]) + ","                  s += "{" + ToString(maps[i]) + ","
1850                           + ToString((int(iter->first.midi_bank_msb) << 7) & int(iter->first.midi_bank_lsb)) + ","                           + ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + ","
1851                           + ToString(int(iter->first.midi_prog)) + "}";                           + ToString(int(iter->first.midi_prog)) + "}";
1852              }              }
1853          }          }
# Line 1822  String LSCPServer::GetMidiInstrumentMap( Line 1949  String LSCPServer::GetMidiInstrumentMap(
1949      LSCPResultSet result;      LSCPResultSet result;
1950      try {      try {
1951          result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID));          result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID));
1952            result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID);
1953      } catch (Exception e) {      } catch (Exception e) {
1954          result.Error(e);          result.Error(e);
1955      }      }
# Line 1870  String LSCPServer::CreateFxSend(uint uiS Line 1998  String LSCPServer::CreateFxSend(uint uiS
1998      dmsg(2,("LSCPServer: CreateFxSend()\n"));      dmsg(2,("LSCPServer: CreateFxSend()\n"));
1999      LSCPResultSet result;      LSCPResultSet result;
2000      try {      try {
2001          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2002          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");  
   
2003          FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name);          FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name);
2004          if (!pFxSend) throw Exception("Could not add FxSend, don't ask, I don't know why (probably a bug)");          if (!pFxSend) throw Exception("Could not add FxSend, don't ask, I don't know why (probably a bug)");
2005    
# Line 1890  String LSCPServer::DestroyFxSend(uint ui Line 2014  String LSCPServer::DestroyFxSend(uint ui
2014      dmsg(2,("LSCPServer: DestroyFxSend()\n"));      dmsg(2,("LSCPServer: DestroyFxSend()\n"));
2015      LSCPResultSet result;      LSCPResultSet result;
2016      try {      try {
2017          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");  
2018    
2019          FxSend* pFxSend = NULL;          FxSend* pFxSend = NULL;
2020          for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {          for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
# Line 1915  String LSCPServer::GetFxSends(uint uiSam Line 2035  String LSCPServer::GetFxSends(uint uiSam
2035      dmsg(2,("LSCPServer: GetFxSends()\n"));      dmsg(2,("LSCPServer: GetFxSends()\n"));
2036      LSCPResultSet result;      LSCPResultSet result;
2037      try {      try {
2038          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");  
2039    
2040          result.Add(pEngineChannel->GetFxSendCount());          result.Add(pEngineChannel->GetFxSendCount());
2041      } catch (Exception e) {      } catch (Exception e) {
# Line 1933  String LSCPServer::ListFxSends(uint uiSa Line 2049  String LSCPServer::ListFxSends(uint uiSa
2049      LSCPResultSet result;      LSCPResultSet result;
2050      String list;      String list;
2051      try {      try {
2052          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");  
2053    
2054          for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {          for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2055              FxSend* pFxSend = pEngineChannel->GetFxSend(i);              FxSend* pFxSend = pEngineChannel->GetFxSend(i);
# Line 1951  String LSCPServer::ListFxSends(uint uiSa Line 2063  String LSCPServer::ListFxSends(uint uiSa
2063      return result.Produce();      return result.Produce();
2064  }  }
2065    
2066    FxSend* LSCPServer::GetFxSend(uint uiSamplerChannel, uint FxSendID) {
2067        EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2068    
2069        FxSend* pFxSend = NULL;
2070        for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {
2071            if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {
2072                pFxSend = pEngineChannel->GetFxSend(i);
2073                break;
2074            }
2075        }
2076        if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");
2077        return pFxSend;
2078    }
2079    
2080  String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) {  String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) {
2081      dmsg(2,("LSCPServer: GetFxSendInfo()\n"));      dmsg(2,("LSCPServer: GetFxSendInfo()\n"));
2082      LSCPResultSet result;      LSCPResultSet result;
2083      try {      try {
2084          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel);
2085          if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));          FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2086            
         EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();  
         if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");  
   
         FxSend* pFxSend = NULL;  
         for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {  
             if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {  
                 pFxSend = pEngineChannel->GetFxSend(i);  
                 break;  
             }  
         }  
         if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");  
   
2087          // gather audio routing informations          // gather audio routing informations
2088          String AudioRouting;          String AudioRouting;
2089          for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {          for (int chan = 0; chan < pEngineChannel->Channels(); chan++) {
# Line 1979  String LSCPServer::GetFxSendInfo(uint ui Line 2093  String LSCPServer::GetFxSendInfo(uint ui
2093    
2094          // success          // success
2095          result.Add("NAME", pFxSend->Name());          result.Add("NAME", pFxSend->Name());
2096            result.Add("MIDI_CONTROLLER", pFxSend->MidiController());
2097            result.Add("LEVEL", ToString(pFxSend->Level()));
2098          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);          result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting);
2099      } catch (Exception e) {      } catch (Exception e) {
2100          result.Error(e);          result.Error(e);
# Line 1986  String LSCPServer::GetFxSendInfo(uint ui Line 2102  String LSCPServer::GetFxSendInfo(uint ui
2102      return result.Produce();      return result.Produce();
2103  }  }
2104    
2105    String LSCPServer::SetFxSendName(uint uiSamplerChannel, uint FxSendID, String Name) {
2106        dmsg(2,("LSCPServer: SetFxSendName()\n"));
2107        LSCPResultSet result;
2108        try {
2109            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2110    
2111            pFxSend->SetName(Name);
2112            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2113        } catch (Exception e) {
2114            result.Error(e);
2115        }
2116        return result.Produce();
2117    }
2118    
2119  String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) {  String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) {
2120      dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n"));      dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n"));
2121      LSCPResultSet result;      LSCPResultSet result;
2122      try {      try {
2123          SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);          FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
         if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));  
2124    
2125          EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();          pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel);
2126          if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet");          LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2127        } catch (Exception e) {
2128            result.Error(e);
2129        }
2130        return result.Produce();
2131    }
2132    
2133          FxSend* pFxSend = NULL;  String LSCPServer::SetFxSendMidiController(uint uiSamplerChannel, uint FxSendID, uint MidiController) {
2134          for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) {      dmsg(2,("LSCPServer: SetFxSendMidiController()\n"));
2135              if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) {      LSCPResultSet result;
2136                  pFxSend = pEngineChannel->GetFxSend(i);      try {
2137                  break;          FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
             }  
         }  
         if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel");  
2138    
2139          pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel);          pFxSend->SetMidiController(MidiController);
2140            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2141        } catch (Exception e) {
2142            result.Error(e);
2143        }
2144        return result.Produce();
2145    }
2146    
2147    String LSCPServer::SetFxSendLevel(uint uiSamplerChannel, uint FxSendID, double dLevel) {
2148        dmsg(2,("LSCPServer: SetFxSendLevel()\n"));
2149        LSCPResultSet result;
2150        try {
2151            FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID);
2152    
2153            pFxSend->SetLevel((float)dLevel);
2154            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID));
2155        } catch (Exception e) {
2156            result.Error(e);
2157        }
2158        return result.Produce();
2159    }
2160    
2161    String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) {
2162        dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel));
2163        LSCPResultSet result;
2164        try {
2165            SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel);
2166            if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel));
2167            EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel();
2168            if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel");
2169            Engine* pEngine = pEngineChannel->GetEngine();
2170            InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager();
2171            if (!pInstrumentManager) throw Exception("Engine does not provide an instrument manager");
2172            InstrumentManager::instrument_id_t instrumentID;
2173            instrumentID.FileName = pEngineChannel->InstrumentFileName();
2174            instrumentID.Index    = pEngineChannel->InstrumentIndex();
2175            pInstrumentManager->LaunchInstrumentEditor(instrumentID);
2176      } catch (Exception e) {      } catch (Exception e) {
2177          result.Error(e);          result.Error(e);
2178      }      }
# Line 2051  String LSCPServer::GetServerInfo() { Line 2218  String LSCPServer::GetServerInfo() {
2218      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");      result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler");
2219      result.Add("VERSION", VERSION);      result.Add("VERSION", VERSION);
2220      result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR));      result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR));
2221    #if HAVE_SQLITE3
2222        result.Add("INSTRUMENTS_DB_SUPPORT", "yes");
2223    #else
2224        result.Add("INSTRUMENTS_DB_SUPPORT", "no");
2225    #endif
2226        
2227      return result.Produce();      return result.Produce();
2228  }  }
2229    
# Line 2085  String LSCPServer::SetGlobalVolume(doubl Line 2258  String LSCPServer::SetGlobalVolume(doubl
2258      try {      try {
2259          if (dVolume < 0) throw Exception("Volume may not be negative");          if (dVolume < 0) throw Exception("Volume may not be negative");
2260          GLOBAL_VOLUME = dVolume; // see common/global.cpp          GLOBAL_VOLUME = dVolume; // see common/global.cpp
2261            LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME));
2262      } catch (Exception e) {      } catch (Exception e) {
2263          result.Error(e);          result.Error(e);
2264      }      }
# Line 2117  String LSCPServer::UnsubscribeNotificati Line 2291  String LSCPServer::UnsubscribeNotificati
2291      return result.Produce();      return result.Produce();
2292  }  }
2293    
2294  static int select_callback(void * lscpResultSet, int argc,  String LSCPServer::AddDbInstrumentDirectory(String Dir) {
2295                          char **argv, char **azColName)      dmsg(2,("LSCPServer: AddDbInstrumentDirectory(Dir=%s)\n", Dir.c_str()));
2296  {      LSCPResultSet result;
2297      LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet;  #if HAVE_SQLITE3
2298      resultSet->Add(argc, argv);      try {
2299      return 0;          InstrumentsDb::GetInstrumentsDb()->AddDirectory(Dir);
2300        } catch (Exception e) {
2301             result.Error(e);
2302        }
2303    #else
2304        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2305    #endif
2306        return result.Produce();
2307    }
2308    
2309    String LSCPServer::RemoveDbInstrumentDirectory(String Dir, bool Force) {
2310        dmsg(2,("LSCPServer: RemoveDbInstrumentDirectory(Dir=%s,Force=%d)\n", Dir.c_str(), Force));
2311        LSCPResultSet result;
2312    #if HAVE_SQLITE3
2313        try {
2314            InstrumentsDb::GetInstrumentsDb()->RemoveDirectory(Dir, Force);
2315        } catch (Exception e) {
2316             result.Error(e);
2317        }
2318    #else
2319        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2320    #endif
2321        return result.Produce();
2322    }
2323    
2324    String LSCPServer::GetDbInstrumentDirectoryCount(String Dir, bool Recursive) {
2325        dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2326        LSCPResultSet result;
2327    #if HAVE_SQLITE3
2328        try {
2329            result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir, Recursive));
2330        } catch (Exception e) {
2331             result.Error(e);
2332        }
2333    #else
2334        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2335    #endif
2336        return result.Produce();
2337    }
2338    
2339    String LSCPServer::GetDbInstrumentDirectories(String Dir, bool Recursive) {
2340        dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2341        LSCPResultSet result;
2342    #if HAVE_SQLITE3
2343        try {
2344            String list;
2345            StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir, Recursive);
2346    
2347            for (int i = 0; i < dirs->size(); i++) {
2348                if (list != "") list += ",";
2349                list += "'" + dirs->at(i) + "'";
2350            }
2351    
2352            result.Add(list);
2353        } catch (Exception e) {
2354             result.Error(e);
2355        }
2356    #else
2357        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2358    #endif
2359        return result.Produce();
2360    }
2361    
2362    String LSCPServer::GetDbInstrumentDirectoryInfo(String Dir) {
2363        dmsg(2,("LSCPServer: GetDbInstrumentDirectoryInfo(Dir=%s)\n", Dir.c_str()));
2364        LSCPResultSet result;
2365    #if HAVE_SQLITE3
2366        try {
2367            DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir);
2368    
2369            result.Add("DESCRIPTION", info.Description);
2370            result.Add("CREATED", info.Created);
2371            result.Add("MODIFIED", info.Modified);
2372        } catch (Exception e) {
2373             result.Error(e);
2374        }
2375    #else
2376        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2377    #endif
2378        return result.Produce();
2379    }
2380    
2381    String LSCPServer::SetDbInstrumentDirectoryName(String Dir, String Name) {
2382        dmsg(2,("LSCPServer: SetDbInstrumentDirectoryName(Dir=%s,Name=%s)\n", Dir.c_str(), Name.c_str()));
2383        LSCPResultSet result;
2384    #if HAVE_SQLITE3
2385        try {
2386            InstrumentsDb::GetInstrumentsDb()->RenameDirectory(Dir, Name);
2387        } catch (Exception e) {
2388             result.Error(e);
2389        }
2390    #else
2391        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2392    #endif
2393        return result.Produce();
2394    }
2395    
2396    String LSCPServer::MoveDbInstrumentDirectory(String Dir, String Dst) {
2397        dmsg(2,("LSCPServer: MoveDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str()));
2398        LSCPResultSet result;
2399    #if HAVE_SQLITE3
2400        try {
2401            InstrumentsDb::GetInstrumentsDb()->MoveDirectory(Dir, Dst);
2402        } catch (Exception e) {
2403             result.Error(e);
2404        }
2405    #else
2406        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2407    #endif
2408        return result.Produce();
2409    }
2410    
2411    String LSCPServer::CopyDbInstrumentDirectory(String Dir, String Dst) {
2412        dmsg(2,("LSCPServer: CopyDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str()));
2413        LSCPResultSet result;
2414    #if HAVE_SQLITE3
2415        try {
2416            InstrumentsDb::GetInstrumentsDb()->CopyDirectory(Dir, Dst);
2417        } catch (Exception e) {
2418             result.Error(e);
2419        }
2420    #else
2421        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2422    #endif
2423        return result.Produce();
2424    }
2425    
2426    String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) {
2427        dmsg(2,("LSCPServer: SetDbInstrumentDirectoryDescription(Dir=%s,Desc=%s)\n", Dir.c_str(), Desc.c_str()));
2428        LSCPResultSet result;
2429    #if HAVE_SQLITE3
2430        try {
2431            InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc);
2432        } catch (Exception e) {
2433             result.Error(e);
2434        }
2435    #else
2436        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2437    #endif
2438        return result.Produce();
2439    }
2440    
2441    String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index, bool bBackground) {
2442        dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d,bBackground=%d)\n", DbDir.c_str(), FilePath.c_str(), Index, bBackground));
2443        LSCPResultSet result;
2444    #if HAVE_SQLITE3
2445        try {
2446            int id;
2447            InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();
2448            id = db->AddInstruments(DbDir, FilePath, Index, bBackground);
2449            if (bBackground) result = id;
2450        } catch (Exception e) {
2451             result.Error(e);
2452        }
2453    #else
2454        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2455    #endif
2456        return result.Produce();
2457    }
2458    
2459    String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) {
2460        dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground));
2461        LSCPResultSet result;
2462    #if HAVE_SQLITE3
2463        try {
2464            int id;
2465            InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb();
2466            if (ScanMode.compare("RECURSIVE") == 0) {
2467               id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground);
2468            } else if (ScanMode.compare("NON_RECURSIVE") == 0) {
2469               id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground);
2470            } else if (ScanMode.compare("FLAT") == 0) {
2471               id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground);
2472            } else {
2473                throw Exception("Unknown scan mode: " + ScanMode);
2474            }
2475            
2476            if (bBackground) result = id;
2477        } catch (Exception e) {
2478             result.Error(e);
2479        }
2480    #else
2481        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2482    #endif
2483        return result.Produce();
2484    }
2485    
2486    String LSCPServer::RemoveDbInstrument(String Instr) {
2487        dmsg(2,("LSCPServer: RemoveDbInstrument(Instr=%s)\n", Instr.c_str()));
2488        LSCPResultSet result;
2489    #if HAVE_SQLITE3
2490        try {
2491            InstrumentsDb::GetInstrumentsDb()->RemoveInstrument(Instr);
2492        } catch (Exception e) {
2493             result.Error(e);
2494        }
2495    #else
2496        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2497    #endif
2498        return result.Produce();
2499    }
2500    
2501    String LSCPServer::GetDbInstrumentCount(String Dir, bool Recursive) {
2502        dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2503        LSCPResultSet result;
2504    #if HAVE_SQLITE3
2505        try {
2506            result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir, Recursive));
2507        } catch (Exception e) {
2508             result.Error(e);
2509        }
2510    #else
2511        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2512    #endif
2513        return result.Produce();
2514    }
2515    
2516    String LSCPServer::GetDbInstruments(String Dir, bool Recursive) {
2517        dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive));
2518        LSCPResultSet result;
2519    #if HAVE_SQLITE3
2520        try {
2521            String list;
2522            StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir, Recursive);
2523    
2524            for (int i = 0; i < instrs->size(); i++) {
2525                if (list != "") list += ",";
2526                list += "'" + instrs->at(i) + "'";
2527            }
2528    
2529            result.Add(list);
2530        } catch (Exception e) {
2531             result.Error(e);
2532        }
2533    #else
2534        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2535    #endif
2536        return result.Produce();
2537  }  }
2538    
2539  String LSCPServer::QueryDatabase(String query) {  String LSCPServer::GetDbInstrumentInfo(String Instr) {
2540        dmsg(2,("LSCPServer: GetDbInstrumentInfo(Instr=%s)\n", Instr.c_str()));
2541      LSCPResultSet result;      LSCPResultSet result;
2542  #if HAVE_SQLITE3  #if HAVE_SQLITE3
2543      char* zErrMsg = NULL;      try {
2544      sqlite3 *db;          DbInstrument info = InstrumentsDb::GetInstrumentsDb()->GetInstrumentInfo(Instr);
     String selectStr = "SELECT " + query;  
2545    
2546      int rc = sqlite3_open("linuxsampler.db", &db);          result.Add("INSTRUMENT_FILE", info.InstrFile);
2547      if (rc == SQLITE_OK)          result.Add("INSTRUMENT_NR", info.InstrNr);
2548      {          result.Add("FORMAT_FAMILY", info.FormatFamily);
2549              rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg);          result.Add("FORMAT_VERSION", info.FormatVersion);
2550            result.Add("SIZE", (int)info.Size);
2551            result.Add("CREATED", info.Created);
2552            result.Add("MODIFIED", info.Modified);
2553            result.Add("DESCRIPTION", FilterEndlines(info.Description));
2554            result.Add("IS_DRUM", info.IsDrum);
2555            result.Add("PRODUCT", FilterEndlines(info.Product));
2556            result.Add("ARTISTS", FilterEndlines(info.Artists));
2557            result.Add("KEYWORDS", FilterEndlines(info.Keywords));
2558        } catch (Exception e) {
2559             result.Error(e);
2560      }      }
2561      if ( rc != SQLITE_OK )  #else
2562      {      result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2563              result.Error(String(zErrMsg), rc);  #endif
2564        return result.Produce();
2565    }
2566    
2567    String LSCPServer::GetDbInstrumentsJobInfo(int JobId) {
2568        dmsg(2,("LSCPServer: GetDbInstrumentsJobInfo(JobId=%d)\n", JobId));
2569        LSCPResultSet result;
2570    #if HAVE_SQLITE3
2571        try {
2572            ScanJob job = InstrumentsDb::GetInstrumentsDb()->Jobs.GetJobById(JobId);
2573    
2574            result.Add("FILES_TOTAL", job.FilesTotal);
2575            result.Add("FILES_SCANNED", job.FilesScanned);
2576            result.Add("SCANNING", job.Scanning);
2577            result.Add("STATUS", job.Status);
2578        } catch (Exception e) {
2579             result.Error(e);
2580      }      }
     sqlite3_close(db);  
2581  #else  #else
2582      result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0);      result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2583  #endif  #endif
2584      return result.Produce();      return result.Produce();
2585  }  }
2586    
2587    String LSCPServer::SetDbInstrumentName(String Instr, String Name) {
2588        dmsg(2,("LSCPServer: SetDbInstrumentName(Instr=%s,Name=%s)\n", Instr.c_str(), Name.c_str()));
2589        LSCPResultSet result;
2590    #if HAVE_SQLITE3
2591        try {
2592            InstrumentsDb::GetInstrumentsDb()->RenameInstrument(Instr, Name);
2593        } catch (Exception e) {
2594             result.Error(e);
2595        }
2596    #else
2597        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2598    #endif
2599        return result.Produce();
2600    }
2601    
2602    String LSCPServer::MoveDbInstrument(String Instr, String Dst) {
2603        dmsg(2,("LSCPServer: MoveDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str()));
2604        LSCPResultSet result;
2605    #if HAVE_SQLITE3
2606        try {
2607            InstrumentsDb::GetInstrumentsDb()->MoveInstrument(Instr, Dst);
2608        } catch (Exception e) {
2609             result.Error(e);
2610        }
2611    #else
2612        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2613    #endif
2614        return result.Produce();
2615    }
2616    
2617    String LSCPServer::CopyDbInstrument(String Instr, String Dst) {
2618        dmsg(2,("LSCPServer: CopyDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str()));
2619        LSCPResultSet result;
2620    #if HAVE_SQLITE3
2621        try {
2622            InstrumentsDb::GetInstrumentsDb()->CopyInstrument(Instr, Dst);
2623        } catch (Exception e) {
2624             result.Error(e);
2625        }
2626    #else
2627        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2628    #endif
2629        return result.Produce();
2630    }
2631    
2632    String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) {
2633        dmsg(2,("LSCPServer: SetDbInstrumentDescription(Instr=%s,Desc=%s)\n", Instr.c_str(), Desc.c_str()));
2634        LSCPResultSet result;
2635    #if HAVE_SQLITE3
2636        try {
2637            InstrumentsDb::GetInstrumentsDb()->SetInstrumentDescription(Instr, Desc);
2638        } catch (Exception e) {
2639             result.Error(e);
2640        }
2641    #else
2642        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2643    #endif
2644        return result.Produce();
2645    }
2646    
2647    String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) {
2648        dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str()));
2649        LSCPResultSet result;
2650    #if HAVE_SQLITE3
2651        try {
2652            SearchQuery Query;
2653            std::map<String,String>::iterator iter;
2654            for (iter = Parameters.begin(); iter != Parameters.end(); iter++) {
2655                if (iter->first.compare("NAME") == 0) {
2656                    Query.Name = iter->second;
2657                } else if (iter->first.compare("CREATED") == 0) {
2658                    Query.SetCreated(iter->second);
2659                } else if (iter->first.compare("MODIFIED") == 0) {
2660                    Query.SetModified(iter->second);
2661                } else if (iter->first.compare("DESCRIPTION") == 0) {
2662                    Query.Description = iter->second;
2663                } else {
2664                    throw Exception("Unknown search criteria: " + iter->first);
2665                }
2666            }
2667    
2668            String list;
2669            StringListPtr pDirectories =
2670                InstrumentsDb::GetInstrumentsDb()->FindDirectories(Dir, &Query, Recursive);
2671    
2672            for (int i = 0; i < pDirectories->size(); i++) {
2673                if (list != "") list += ",";
2674                list += "'" + pDirectories->at(i) + "'";
2675            }
2676    
2677            result.Add(list);
2678        } catch (Exception e) {
2679             result.Error(e);
2680        }
2681    #else
2682        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2683    #endif
2684        return result.Produce();
2685    }
2686    
2687    String LSCPServer::FindDbInstruments(String Dir, std::map<String,String> Parameters, bool Recursive) {
2688        dmsg(2,("LSCPServer: FindDbInstruments(Dir=%s)\n", Dir.c_str()));
2689        LSCPResultSet result;
2690    #if HAVE_SQLITE3
2691        try {
2692            SearchQuery Query;
2693            std::map<String,String>::iterator iter;
2694            for (iter = Parameters.begin(); iter != Parameters.end(); iter++) {
2695                if (iter->first.compare("NAME") == 0) {
2696                    Query.Name = iter->second;
2697                } else if (iter->first.compare("FORMAT_FAMILIES") == 0) {
2698                    Query.SetFormatFamilies(iter->second);
2699                } else if (iter->first.compare("SIZE") == 0) {
2700                    Query.SetSize(iter->second);
2701                } else if (iter->first.compare("CREATED") == 0) {
2702                    Query.SetCreated(iter->second);
2703                } else if (iter->first.compare("MODIFIED") == 0) {
2704                    Query.SetModified(iter->second);
2705                } else if (iter->first.compare("DESCRIPTION") == 0) {
2706                    Query.Description = iter->second;
2707                } else if (iter->first.compare("IS_DRUM") == 0) {
2708                    if (!strcasecmp(iter->second.c_str(), "true")) {
2709                        Query.InstrType = SearchQuery::DRUM;
2710                    } else {
2711                        Query.InstrType = SearchQuery::CHROMATIC;
2712                    }
2713                } else if (iter->first.compare("PRODUCT") == 0) {
2714                     Query.Product = iter->second;
2715                } else if (iter->first.compare("ARTISTS") == 0) {
2716                     Query.Artists = iter->second;
2717                } else if (iter->first.compare("KEYWORDS") == 0) {
2718                     Query.Keywords = iter->second;
2719                } else {
2720                    throw Exception("Unknown search criteria: " + iter->first);
2721                }
2722            }
2723    
2724            String list;
2725            StringListPtr pInstruments =
2726                InstrumentsDb::GetInstrumentsDb()->FindInstruments(Dir, &Query, Recursive);
2727    
2728            for (int i = 0; i < pInstruments->size(); i++) {
2729                if (list != "") list += ",";
2730                list += "'" + pInstruments->at(i) + "'";
2731            }
2732    
2733            result.Add(list);
2734        } catch (Exception e) {
2735             result.Error(e);
2736        }
2737    #else
2738        result.Error(String(DOESNT_HAVE_SQLITE3), 0);
2739    #endif
2740        return result.Produce();
2741    }
2742    
2743    
2744  /**  /**
2745   * Will be called by the parser to enable or disable echo mode; if echo   * Will be called by the parser to enable or disable echo mode; if echo
2746   * mode is enabled, all commands from the client will (immediately) be   * mode is enabled, all commands from the client will (immediately) be
# Line 2166  String LSCPServer::SetEcho(yyparse_param Line 2759  String LSCPServer::SetEcho(yyparse_param
2759      }      }
2760      return result.Produce();      return result.Produce();
2761  }  }
2762    
2763    String LSCPServer::FilterEndlines(String s) {
2764        String s2 = s;
2765        for (int i = 0; i < s2.length(); i++) {
2766            if (s2.at(i) == '\r') s2.at(i) = ' ';
2767            else if (s2.at(i) == '\n') s2.at(i) = ' ';
2768        }
2769        
2770        return s2;
2771    }

Legend:
Removed from v.1007  
changed lines
  Added in v.1212

  ViewVC Help
Powered by ViewVC