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" |
52 |
fd_set LSCPServer::fdSet; |
fd_set LSCPServer::fdSet; |
53 |
int LSCPServer::currentSocket = -1; |
int LSCPServer::currentSocket = -1; |
54 |
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
55 |
|
std::vector<yyparse_param_t>::iterator itCurrentSession = std::vector<yyparse_param_t>::iterator(); |
56 |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
57 |
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
58 |
std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions = std::map< LSCPEvent::event_t, std::list<int> >(); |
std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions = std::map< LSCPEvent::event_t, std::list<int> >(); |
81 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO"); |
82 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT"); |
83 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO"); |
84 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_count, "DB_INSTRUMENT_DIRECTORY_COUNT"); |
85 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_info, "DB_INSTRUMENT_DIRECTORY_INFO"); |
86 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_count, "DB_INSTRUMENT_COUNT"); |
87 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO"); |
88 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO"); |
89 |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
90 |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
91 |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
144 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount)); |
145 |
} |
} |
146 |
|
|
147 |
|
#if HAVE_SQLITE3 |
148 |
|
void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) { |
149 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, Dir)); |
150 |
|
} |
151 |
|
|
152 |
|
void LSCPServer::DbInstrumentsEventHandler::DirectoryInfoChanged(String Dir) { |
153 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, Dir)); |
154 |
|
} |
155 |
|
|
156 |
|
void LSCPServer::DbInstrumentsEventHandler::DirectoryNameChanged(String Dir, String NewName) { |
157 |
|
Dir = "'" + Dir + "'"; |
158 |
|
NewName = "'" + NewName + "'"; |
159 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, "NAME", Dir, NewName)); |
160 |
|
} |
161 |
|
|
162 |
|
void LSCPServer::DbInstrumentsEventHandler::InstrumentCountChanged(String Dir) { |
163 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_count, Dir)); |
164 |
|
} |
165 |
|
|
166 |
|
void LSCPServer::DbInstrumentsEventHandler::InstrumentInfoChanged(String Instr) { |
167 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, Instr)); |
168 |
|
} |
169 |
|
|
170 |
|
void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) { |
171 |
|
Instr = "'" + Instr + "'"; |
172 |
|
NewName = "'" + NewName + "'"; |
173 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, "NAME", Instr, NewName)); |
174 |
|
} |
175 |
|
|
176 |
|
void LSCPServer::DbInstrumentsEventHandler::JobStatusChanged(int JobId) { |
177 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instrs_job_info, JobId)); |
178 |
|
} |
179 |
|
#endif // HAVE_SQLITE3 |
180 |
|
|
181 |
|
|
182 |
/** |
/** |
183 |
* Blocks the calling thread until the LSCP Server is initialized and |
* Blocks the calling thread until the LSCP Server is initialized and |
219 |
|
|
220 |
listen(hSocket, 1); |
listen(hSocket, 1); |
221 |
Initialized.Set(true); |
Initialized.Set(true); |
222 |
|
|
223 |
// Registering event listeners |
// Registering event listeners |
224 |
pSampler->AddChannelCountListener(&eventHandler); |
pSampler->AddChannelCountListener(&eventHandler); |
225 |
pSampler->AddAudioDeviceCountListener(&eventHandler); |
pSampler->AddAudioDeviceCountListener(&eventHandler); |
233 |
MidiInstrumentMapper::AddMidiInstrumentInfoListener(&eventHandler); |
MidiInstrumentMapper::AddMidiInstrumentInfoListener(&eventHandler); |
234 |
MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&eventHandler); |
MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&eventHandler); |
235 |
MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(&eventHandler); |
MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(&eventHandler); |
236 |
|
#if HAVE_SQLITE3 |
237 |
|
InstrumentsDb::GetInstrumentsDb()->AddInstrumentsDbListener(&dbInstrumentsEventHandler); |
238 |
|
#endif |
239 |
// now wait for client connections and handle their requests |
// now wait for client connections and handle their requests |
240 |
sockaddr_in client; |
sockaddr_in client; |
241 |
int length = sizeof(client); |
int length = sizeof(client); |
328 |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
329 |
restart(NULL, dummy); // restart the 'scanner' |
restart(NULL, dummy); // restart the 'scanner' |
330 |
currentSocket = (*iter).hSession; //a hack |
currentSocket = (*iter).hSession; //a hack |
331 |
|
itCurrentSession = iter; // another hack |
332 |
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
333 |
if ((*iter).bVerbose) { // if echo mode enabled |
if ((*iter).bVerbose) { // if echo mode enabled |
334 |
AnswerClient(bufferedCommands[currentSocket]); |
AnswerClient(bufferedCommands[currentSocket]); |
335 |
} |
} |
336 |
int result = yyparse(&(*iter)); |
int result = yyparse(&(*iter)); |
337 |
currentSocket = -1; //continuation of a hack |
currentSocket = -1; //continuation of a hack |
338 |
|
itCurrentSession = Sessions.end(); // hack as well |
339 |
dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket)); |
dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket)); |
340 |
if (result == LSCP_QUIT) { //Was it a quit command by any chance? |
if (result == LSCP_QUIT) { //Was it a quit command by any chance? |
341 |
CloseConnection(iter); |
CloseConnection(iter); |
428 |
return command.size(); |
return command.size(); |
429 |
} |
} |
430 |
|
|
431 |
|
extern yyparse_param_t* GetCurrentYaccSession() { |
432 |
|
return &(*itCurrentSession); |
433 |
|
} |
434 |
|
|
435 |
/** |
/** |
436 |
* Will be called to try to read the command from the socket |
* Will be called to try to read the command from the socket |
437 |
* If command is read, it will return true. Otherwise false is returned. |
* If command is read, it will return true. Otherwise false is returned. |
612 |
return result.Produce(); |
return result.Produce(); |
613 |
} |
} |
614 |
|
|
615 |
|
EngineChannel* LSCPServer::GetEngineChannel(uint uiSamplerChannel) { |
616 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
617 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
618 |
|
|
619 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
620 |
|
if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); |
621 |
|
|
622 |
|
return pEngineChannel; |
623 |
|
} |
624 |
|
|
625 |
/** |
/** |
626 |
* Will be called by the parser to load an instrument. |
* Will be called by the parser to load an instrument. |
627 |
*/ |
*/ |
1956 |
LSCPResultSet result; |
LSCPResultSet result; |
1957 |
try { |
try { |
1958 |
result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID)); |
result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID)); |
1959 |
|
result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID); |
1960 |
} catch (Exception e) { |
} catch (Exception e) { |
1961 |
result.Error(e); |
result.Error(e); |
1962 |
} |
} |
2005 |
dmsg(2,("LSCPServer: CreateFxSend()\n")); |
dmsg(2,("LSCPServer: CreateFxSend()\n")); |
2006 |
LSCPResultSet result; |
LSCPResultSet result; |
2007 |
try { |
try { |
2008 |
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"); |
|
2009 |
|
|
2010 |
FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name); |
FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name); |
2011 |
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)"); |
2021 |
dmsg(2,("LSCPServer: DestroyFxSend()\n")); |
dmsg(2,("LSCPServer: DestroyFxSend()\n")); |
2022 |
LSCPResultSet result; |
LSCPResultSet result; |
2023 |
try { |
try { |
2024 |
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"); |
|
2025 |
|
|
2026 |
FxSend* pFxSend = NULL; |
FxSend* pFxSend = NULL; |
2027 |
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
2042 |
dmsg(2,("LSCPServer: GetFxSends()\n")); |
dmsg(2,("LSCPServer: GetFxSends()\n")); |
2043 |
LSCPResultSet result; |
LSCPResultSet result; |
2044 |
try { |
try { |
2045 |
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"); |
|
2046 |
|
|
2047 |
result.Add(pEngineChannel->GetFxSendCount()); |
result.Add(pEngineChannel->GetFxSendCount()); |
2048 |
} catch (Exception e) { |
} catch (Exception e) { |
2056 |
LSCPResultSet result; |
LSCPResultSet result; |
2057 |
String list; |
String list; |
2058 |
try { |
try { |
2059 |
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"); |
|
2060 |
|
|
2061 |
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
2062 |
FxSend* pFxSend = pEngineChannel->GetFxSend(i); |
FxSend* pFxSend = pEngineChannel->GetFxSend(i); |
2070 |
return result.Produce(); |
return result.Produce(); |
2071 |
} |
} |
2072 |
|
|
2073 |
|
FxSend* LSCPServer::GetFxSend(uint uiSamplerChannel, uint FxSendID) { |
2074 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2075 |
|
|
2076 |
|
FxSend* pFxSend = NULL; |
2077 |
|
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
2078 |
|
if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) { |
2079 |
|
pFxSend = pEngineChannel->GetFxSend(i); |
2080 |
|
break; |
2081 |
|
} |
2082 |
|
} |
2083 |
|
if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel"); |
2084 |
|
return pFxSend; |
2085 |
|
} |
2086 |
|
|
2087 |
String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) { |
String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) { |
2088 |
dmsg(2,("LSCPServer: GetFxSendInfo()\n")); |
dmsg(2,("LSCPServer: GetFxSendInfo()\n")); |
2089 |
LSCPResultSet result; |
LSCPResultSet result; |
2090 |
try { |
try { |
2091 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2092 |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
|
|
|
|
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"); |
|
2093 |
|
|
2094 |
// gather audio routing informations |
// gather audio routing informations |
2095 |
String AudioRouting; |
String AudioRouting; |
2109 |
return result.Produce(); |
return result.Produce(); |
2110 |
} |
} |
2111 |
|
|
2112 |
String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) { |
String LSCPServer::SetFxSendName(uint uiSamplerChannel, uint FxSendID, String Name) { |
2113 |
dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n")); |
dmsg(2,("LSCPServer: SetFxSendName()\n")); |
2114 |
LSCPResultSet result; |
LSCPResultSet result; |
2115 |
try { |
try { |
2116 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
2117 |
|
|
2118 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
pFxSend->SetName(Name); |
2119 |
if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2120 |
|
} catch (Exception e) { |
2121 |
|
result.Error(e); |
2122 |
|
} |
2123 |
|
return result.Produce(); |
2124 |
|
} |
2125 |
|
|
2126 |
FxSend* pFxSend = NULL; |
String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) { |
2127 |
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n")); |
2128 |
if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) { |
LSCPResultSet result; |
2129 |
pFxSend = pEngineChannel->GetFxSend(i); |
try { |
2130 |
break; |
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
|
} |
|
|
} |
|
|
if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel"); |
|
2131 |
|
|
2132 |
pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel); |
pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel); |
2133 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2141 |
dmsg(2,("LSCPServer: SetFxSendMidiController()\n")); |
dmsg(2,("LSCPServer: SetFxSendMidiController()\n")); |
2142 |
LSCPResultSet result; |
LSCPResultSet result; |
2143 |
try { |
try { |
2144 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
|
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"); |
|
|
|
|
|
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"); |
|
2145 |
|
|
2146 |
pFxSend->SetMidiController(MidiController); |
pFxSend->SetMidiController(MidiController); |
2147 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2155 |
dmsg(2,("LSCPServer: SetFxSendLevel()\n")); |
dmsg(2,("LSCPServer: SetFxSendLevel()\n")); |
2156 |
LSCPResultSet result; |
LSCPResultSet result; |
2157 |
try { |
try { |
2158 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
|
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"); |
|
|
|
|
|
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"); |
|
2159 |
|
|
2160 |
pFxSend->SetLevel((float)dLevel); |
pFxSend->SetLevel((float)dLevel); |
2161 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2165 |
return result.Produce(); |
return result.Produce(); |
2166 |
} |
} |
2167 |
|
|
2168 |
|
String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) { |
2169 |
|
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
2170 |
|
LSCPResultSet result; |
2171 |
|
try { |
2172 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
2173 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
2174 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
2175 |
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
2176 |
|
Engine* pEngine = pEngineChannel->GetEngine(); |
2177 |
|
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
2178 |
|
if (!pInstrumentManager) throw Exception("Engine does not provide an instrument manager"); |
2179 |
|
InstrumentManager::instrument_id_t instrumentID; |
2180 |
|
instrumentID.FileName = pEngineChannel->InstrumentFileName(); |
2181 |
|
instrumentID.Index = pEngineChannel->InstrumentIndex(); |
2182 |
|
pInstrumentManager->LaunchInstrumentEditor(instrumentID); |
2183 |
|
} catch (Exception e) { |
2184 |
|
result.Error(e); |
2185 |
|
} |
2186 |
|
return result.Produce(); |
2187 |
|
} |
2188 |
|
|
2189 |
/** |
/** |
2190 |
* Will be called by the parser to reset a particular sampler channel. |
* Will be called by the parser to reset a particular sampler channel. |
2191 |
*/ |
*/ |
2225 |
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
2226 |
result.Add("VERSION", VERSION); |
result.Add("VERSION", VERSION); |
2227 |
result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR)); |
result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR)); |
2228 |
|
#if HAVE_SQLITE3 |
2229 |
|
result.Add("INSTRUMENTS_DB_SUPPORT", "yes"); |
2230 |
|
#else |
2231 |
|
result.Add("INSTRUMENTS_DB_SUPPORT", "no"); |
2232 |
|
#endif |
2233 |
|
|
2234 |
return result.Produce(); |
return result.Produce(); |
2235 |
} |
} |
2236 |
|
|
2298 |
return result.Produce(); |
return result.Produce(); |
2299 |
} |
} |
2300 |
|
|
2301 |
static int select_callback(void * lscpResultSet, int argc, |
String LSCPServer::AddDbInstrumentDirectory(String Dir) { |
2302 |
char **argv, char **azColName) |
dmsg(2,("LSCPServer: AddDbInstrumentDirectory(Dir=%s)\n", Dir.c_str())); |
2303 |
{ |
LSCPResultSet result; |
2304 |
LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet; |
#if HAVE_SQLITE3 |
2305 |
resultSet->Add(argc, argv); |
try { |
2306 |
return 0; |
InstrumentsDb::GetInstrumentsDb()->AddDirectory(Dir); |
2307 |
|
} catch (Exception e) { |
2308 |
|
result.Error(e); |
2309 |
|
} |
2310 |
|
#else |
2311 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2312 |
|
#endif |
2313 |
|
return result.Produce(); |
2314 |
|
} |
2315 |
|
|
2316 |
|
String LSCPServer::RemoveDbInstrumentDirectory(String Dir, bool Force) { |
2317 |
|
dmsg(2,("LSCPServer: RemoveDbInstrumentDirectory(Dir=%s,Force=%d)\n", Dir.c_str(), Force)); |
2318 |
|
LSCPResultSet result; |
2319 |
|
#if HAVE_SQLITE3 |
2320 |
|
try { |
2321 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveDirectory(Dir, Force); |
2322 |
|
} catch (Exception e) { |
2323 |
|
result.Error(e); |
2324 |
|
} |
2325 |
|
#else |
2326 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2327 |
|
#endif |
2328 |
|
return result.Produce(); |
2329 |
|
} |
2330 |
|
|
2331 |
|
String LSCPServer::GetDbInstrumentDirectoryCount(String Dir, bool Recursive) { |
2332 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2333 |
|
LSCPResultSet result; |
2334 |
|
#if HAVE_SQLITE3 |
2335 |
|
try { |
2336 |
|
result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir, Recursive)); |
2337 |
|
} catch (Exception e) { |
2338 |
|
result.Error(e); |
2339 |
|
} |
2340 |
|
#else |
2341 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2342 |
|
#endif |
2343 |
|
return result.Produce(); |
2344 |
|
} |
2345 |
|
|
2346 |
|
String LSCPServer::GetDbInstrumentDirectories(String Dir, bool Recursive) { |
2347 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2348 |
|
LSCPResultSet result; |
2349 |
|
#if HAVE_SQLITE3 |
2350 |
|
try { |
2351 |
|
String list; |
2352 |
|
StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir, Recursive); |
2353 |
|
|
2354 |
|
for (int i = 0; i < dirs->size(); i++) { |
2355 |
|
if (list != "") list += ","; |
2356 |
|
list += "'" + dirs->at(i) + "'"; |
2357 |
|
} |
2358 |
|
|
2359 |
|
result.Add(list); |
2360 |
|
} catch (Exception e) { |
2361 |
|
result.Error(e); |
2362 |
|
} |
2363 |
|
#else |
2364 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2365 |
|
#endif |
2366 |
|
return result.Produce(); |
2367 |
} |
} |
2368 |
|
|
2369 |
String LSCPServer::QueryDatabase(String query) { |
String LSCPServer::GetDbInstrumentDirectoryInfo(String Dir) { |
2370 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectoryInfo(Dir=%s)\n", Dir.c_str())); |
2371 |
LSCPResultSet result; |
LSCPResultSet result; |
2372 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2373 |
char* zErrMsg = NULL; |
try { |
2374 |
sqlite3 *db; |
DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir); |
|
String selectStr = "SELECT " + query; |
|
2375 |
|
|
2376 |
int rc = sqlite3_open("linuxsampler.db", &db); |
result.Add("DESCRIPTION", info.Description); |
2377 |
if (rc == SQLITE_OK) |
result.Add("CREATED", info.Created); |
2378 |
{ |
result.Add("MODIFIED", info.Modified); |
2379 |
rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg); |
} catch (Exception e) { |
2380 |
|
result.Error(e); |
2381 |
} |
} |
2382 |
if ( rc != SQLITE_OK ) |
#else |
2383 |
{ |
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2384 |
result.Error(String(zErrMsg), rc); |
#endif |
2385 |
|
return result.Produce(); |
2386 |
|
} |
2387 |
|
|
2388 |
|
String LSCPServer::SetDbInstrumentDirectoryName(String Dir, String Name) { |
2389 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDirectoryName(Dir=%s,Name=%s)\n", Dir.c_str(), Name.c_str())); |
2390 |
|
LSCPResultSet result; |
2391 |
|
#if HAVE_SQLITE3 |
2392 |
|
try { |
2393 |
|
InstrumentsDb::GetInstrumentsDb()->RenameDirectory(Dir, Name); |
2394 |
|
} catch (Exception e) { |
2395 |
|
result.Error(e); |
2396 |
} |
} |
|
sqlite3_close(db); |
|
2397 |
#else |
#else |
2398 |
result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0); |
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2399 |
#endif |
#endif |
2400 |
return result.Produce(); |
return result.Produce(); |
2401 |
} |
} |
2402 |
|
|
2403 |
|
String LSCPServer::MoveDbInstrumentDirectory(String Dir, String Dst) { |
2404 |
|
dmsg(2,("LSCPServer: MoveDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str())); |
2405 |
|
LSCPResultSet result; |
2406 |
|
#if HAVE_SQLITE3 |
2407 |
|
try { |
2408 |
|
InstrumentsDb::GetInstrumentsDb()->MoveDirectory(Dir, Dst); |
2409 |
|
} catch (Exception e) { |
2410 |
|
result.Error(e); |
2411 |
|
} |
2412 |
|
#else |
2413 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2414 |
|
#endif |
2415 |
|
return result.Produce(); |
2416 |
|
} |
2417 |
|
|
2418 |
|
String LSCPServer::CopyDbInstrumentDirectory(String Dir, String Dst) { |
2419 |
|
dmsg(2,("LSCPServer: CopyDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str())); |
2420 |
|
LSCPResultSet result; |
2421 |
|
#if HAVE_SQLITE3 |
2422 |
|
try { |
2423 |
|
InstrumentsDb::GetInstrumentsDb()->CopyDirectory(Dir, Dst); |
2424 |
|
} catch (Exception e) { |
2425 |
|
result.Error(e); |
2426 |
|
} |
2427 |
|
#else |
2428 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2429 |
|
#endif |
2430 |
|
return result.Produce(); |
2431 |
|
} |
2432 |
|
|
2433 |
|
String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) { |
2434 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDirectoryDescription(Dir=%s,Desc=%s)\n", Dir.c_str(), Desc.c_str())); |
2435 |
|
LSCPResultSet result; |
2436 |
|
#if HAVE_SQLITE3 |
2437 |
|
try { |
2438 |
|
InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc); |
2439 |
|
} catch (Exception e) { |
2440 |
|
result.Error(e); |
2441 |
|
} |
2442 |
|
#else |
2443 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2444 |
|
#endif |
2445 |
|
return result.Produce(); |
2446 |
|
} |
2447 |
|
|
2448 |
|
String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index, bool bBackground) { |
2449 |
|
dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d,bBackground=%d)\n", DbDir.c_str(), FilePath.c_str(), Index, bBackground)); |
2450 |
|
LSCPResultSet result; |
2451 |
|
#if HAVE_SQLITE3 |
2452 |
|
try { |
2453 |
|
int id; |
2454 |
|
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
2455 |
|
id = db->AddInstruments(DbDir, FilePath, Index, bBackground); |
2456 |
|
if (bBackground) result = id; |
2457 |
|
} catch (Exception e) { |
2458 |
|
result.Error(e); |
2459 |
|
} |
2460 |
|
#else |
2461 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2462 |
|
#endif |
2463 |
|
return result.Produce(); |
2464 |
|
} |
2465 |
|
|
2466 |
|
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) { |
2467 |
|
dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground)); |
2468 |
|
LSCPResultSet result; |
2469 |
|
#if HAVE_SQLITE3 |
2470 |
|
try { |
2471 |
|
int id; |
2472 |
|
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
2473 |
|
if (ScanMode.compare("RECURSIVE") == 0) { |
2474 |
|
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground); |
2475 |
|
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
2476 |
|
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground); |
2477 |
|
} else if (ScanMode.compare("FLAT") == 0) { |
2478 |
|
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground); |
2479 |
|
} else { |
2480 |
|
throw Exception("Unknown scan mode: " + ScanMode); |
2481 |
|
} |
2482 |
|
|
2483 |
|
if (bBackground) result = id; |
2484 |
|
} catch (Exception e) { |
2485 |
|
result.Error(e); |
2486 |
|
} |
2487 |
|
#else |
2488 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2489 |
|
#endif |
2490 |
|
return result.Produce(); |
2491 |
|
} |
2492 |
|
|
2493 |
|
String LSCPServer::RemoveDbInstrument(String Instr) { |
2494 |
|
dmsg(2,("LSCPServer: RemoveDbInstrument(Instr=%s)\n", Instr.c_str())); |
2495 |
|
LSCPResultSet result; |
2496 |
|
#if HAVE_SQLITE3 |
2497 |
|
try { |
2498 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveInstrument(Instr); |
2499 |
|
} catch (Exception e) { |
2500 |
|
result.Error(e); |
2501 |
|
} |
2502 |
|
#else |
2503 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2504 |
|
#endif |
2505 |
|
return result.Produce(); |
2506 |
|
} |
2507 |
|
|
2508 |
|
String LSCPServer::GetDbInstrumentCount(String Dir, bool Recursive) { |
2509 |
|
dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2510 |
|
LSCPResultSet result; |
2511 |
|
#if HAVE_SQLITE3 |
2512 |
|
try { |
2513 |
|
result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir, Recursive)); |
2514 |
|
} catch (Exception e) { |
2515 |
|
result.Error(e); |
2516 |
|
} |
2517 |
|
#else |
2518 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2519 |
|
#endif |
2520 |
|
return result.Produce(); |
2521 |
|
} |
2522 |
|
|
2523 |
|
String LSCPServer::GetDbInstruments(String Dir, bool Recursive) { |
2524 |
|
dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2525 |
|
LSCPResultSet result; |
2526 |
|
#if HAVE_SQLITE3 |
2527 |
|
try { |
2528 |
|
String list; |
2529 |
|
StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir, Recursive); |
2530 |
|
|
2531 |
|
for (int i = 0; i < instrs->size(); i++) { |
2532 |
|
if (list != "") list += ","; |
2533 |
|
list += "'" + instrs->at(i) + "'"; |
2534 |
|
} |
2535 |
|
|
2536 |
|
result.Add(list); |
2537 |
|
} catch (Exception e) { |
2538 |
|
result.Error(e); |
2539 |
|
} |
2540 |
|
#else |
2541 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2542 |
|
#endif |
2543 |
|
return result.Produce(); |
2544 |
|
} |
2545 |
|
|
2546 |
|
String LSCPServer::GetDbInstrumentInfo(String Instr) { |
2547 |
|
dmsg(2,("LSCPServer: GetDbInstrumentInfo(Instr=%s)\n", Instr.c_str())); |
2548 |
|
LSCPResultSet result; |
2549 |
|
#if HAVE_SQLITE3 |
2550 |
|
try { |
2551 |
|
DbInstrument info = InstrumentsDb::GetInstrumentsDb()->GetInstrumentInfo(Instr); |
2552 |
|
|
2553 |
|
result.Add("INSTRUMENT_FILE", info.InstrFile); |
2554 |
|
result.Add("INSTRUMENT_NR", info.InstrNr); |
2555 |
|
result.Add("FORMAT_FAMILY", info.FormatFamily); |
2556 |
|
result.Add("FORMAT_VERSION", info.FormatVersion); |
2557 |
|
result.Add("SIZE", (int)info.Size); |
2558 |
|
result.Add("CREATED", info.Created); |
2559 |
|
result.Add("MODIFIED", info.Modified); |
2560 |
|
result.Add("DESCRIPTION", FilterEndlines(info.Description)); |
2561 |
|
result.Add("IS_DRUM", info.IsDrum); |
2562 |
|
result.Add("PRODUCT", FilterEndlines(info.Product)); |
2563 |
|
result.Add("ARTISTS", FilterEndlines(info.Artists)); |
2564 |
|
result.Add("KEYWORDS", FilterEndlines(info.Keywords)); |
2565 |
|
} catch (Exception e) { |
2566 |
|
result.Error(e); |
2567 |
|
} |
2568 |
|
#else |
2569 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2570 |
|
#endif |
2571 |
|
return result.Produce(); |
2572 |
|
} |
2573 |
|
|
2574 |
|
String LSCPServer::GetDbInstrumentsJobInfo(int JobId) { |
2575 |
|
dmsg(2,("LSCPServer: GetDbInstrumentsJobInfo(JobId=%d)\n", JobId)); |
2576 |
|
LSCPResultSet result; |
2577 |
|
#if HAVE_SQLITE3 |
2578 |
|
try { |
2579 |
|
ScanJob job = InstrumentsDb::GetInstrumentsDb()->Jobs.GetJobById(JobId); |
2580 |
|
|
2581 |
|
result.Add("FILES_TOTAL", job.FilesTotal); |
2582 |
|
result.Add("FILES_SCANNED", job.FilesScanned); |
2583 |
|
result.Add("SCANNING", job.Scanning); |
2584 |
|
result.Add("STATUS", job.Status); |
2585 |
|
} catch (Exception e) { |
2586 |
|
result.Error(e); |
2587 |
|
} |
2588 |
|
#else |
2589 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2590 |
|
#endif |
2591 |
|
return result.Produce(); |
2592 |
|
} |
2593 |
|
|
2594 |
|
String LSCPServer::SetDbInstrumentName(String Instr, String Name) { |
2595 |
|
dmsg(2,("LSCPServer: SetDbInstrumentName(Instr=%s,Name=%s)\n", Instr.c_str(), Name.c_str())); |
2596 |
|
LSCPResultSet result; |
2597 |
|
#if HAVE_SQLITE3 |
2598 |
|
try { |
2599 |
|
InstrumentsDb::GetInstrumentsDb()->RenameInstrument(Instr, Name); |
2600 |
|
} catch (Exception e) { |
2601 |
|
result.Error(e); |
2602 |
|
} |
2603 |
|
#else |
2604 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2605 |
|
#endif |
2606 |
|
return result.Produce(); |
2607 |
|
} |
2608 |
|
|
2609 |
|
String LSCPServer::MoveDbInstrument(String Instr, String Dst) { |
2610 |
|
dmsg(2,("LSCPServer: MoveDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str())); |
2611 |
|
LSCPResultSet result; |
2612 |
|
#if HAVE_SQLITE3 |
2613 |
|
try { |
2614 |
|
InstrumentsDb::GetInstrumentsDb()->MoveInstrument(Instr, Dst); |
2615 |
|
} catch (Exception e) { |
2616 |
|
result.Error(e); |
2617 |
|
} |
2618 |
|
#else |
2619 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2620 |
|
#endif |
2621 |
|
return result.Produce(); |
2622 |
|
} |
2623 |
|
|
2624 |
|
String LSCPServer::CopyDbInstrument(String Instr, String Dst) { |
2625 |
|
dmsg(2,("LSCPServer: CopyDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str())); |
2626 |
|
LSCPResultSet result; |
2627 |
|
#if HAVE_SQLITE3 |
2628 |
|
try { |
2629 |
|
InstrumentsDb::GetInstrumentsDb()->CopyInstrument(Instr, Dst); |
2630 |
|
} catch (Exception e) { |
2631 |
|
result.Error(e); |
2632 |
|
} |
2633 |
|
#else |
2634 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2635 |
|
#endif |
2636 |
|
return result.Produce(); |
2637 |
|
} |
2638 |
|
|
2639 |
|
String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) { |
2640 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDescription(Instr=%s,Desc=%s)\n", Instr.c_str(), Desc.c_str())); |
2641 |
|
LSCPResultSet result; |
2642 |
|
#if HAVE_SQLITE3 |
2643 |
|
try { |
2644 |
|
InstrumentsDb::GetInstrumentsDb()->SetInstrumentDescription(Instr, Desc); |
2645 |
|
} catch (Exception e) { |
2646 |
|
result.Error(e); |
2647 |
|
} |
2648 |
|
#else |
2649 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2650 |
|
#endif |
2651 |
|
return result.Produce(); |
2652 |
|
} |
2653 |
|
|
2654 |
|
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
2655 |
|
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
2656 |
|
LSCPResultSet result; |
2657 |
|
#if HAVE_SQLITE3 |
2658 |
|
try { |
2659 |
|
SearchQuery Query; |
2660 |
|
std::map<String,String>::iterator iter; |
2661 |
|
for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { |
2662 |
|
if (iter->first.compare("NAME") == 0) { |
2663 |
|
Query.Name = iter->second; |
2664 |
|
} else if (iter->first.compare("CREATED") == 0) { |
2665 |
|
Query.SetCreated(iter->second); |
2666 |
|
} else if (iter->first.compare("MODIFIED") == 0) { |
2667 |
|
Query.SetModified(iter->second); |
2668 |
|
} else if (iter->first.compare("DESCRIPTION") == 0) { |
2669 |
|
Query.Description = iter->second; |
2670 |
|
} else { |
2671 |
|
throw Exception("Unknown search criteria: " + iter->first); |
2672 |
|
} |
2673 |
|
} |
2674 |
|
|
2675 |
|
String list; |
2676 |
|
StringListPtr pDirectories = |
2677 |
|
InstrumentsDb::GetInstrumentsDb()->FindDirectories(Dir, &Query, Recursive); |
2678 |
|
|
2679 |
|
for (int i = 0; i < pDirectories->size(); i++) { |
2680 |
|
if (list != "") list += ","; |
2681 |
|
list += "'" + pDirectories->at(i) + "'"; |
2682 |
|
} |
2683 |
|
|
2684 |
|
result.Add(list); |
2685 |
|
} catch (Exception e) { |
2686 |
|
result.Error(e); |
2687 |
|
} |
2688 |
|
#else |
2689 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2690 |
|
#endif |
2691 |
|
return result.Produce(); |
2692 |
|
} |
2693 |
|
|
2694 |
|
String LSCPServer::FindDbInstruments(String Dir, std::map<String,String> Parameters, bool Recursive) { |
2695 |
|
dmsg(2,("LSCPServer: FindDbInstruments(Dir=%s)\n", Dir.c_str())); |
2696 |
|
LSCPResultSet result; |
2697 |
|
#if HAVE_SQLITE3 |
2698 |
|
try { |
2699 |
|
SearchQuery Query; |
2700 |
|
std::map<String,String>::iterator iter; |
2701 |
|
for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { |
2702 |
|
if (iter->first.compare("NAME") == 0) { |
2703 |
|
Query.Name = iter->second; |
2704 |
|
} else if (iter->first.compare("FORMAT_FAMILIES") == 0) { |
2705 |
|
Query.SetFormatFamilies(iter->second); |
2706 |
|
} else if (iter->first.compare("SIZE") == 0) { |
2707 |
|
Query.SetSize(iter->second); |
2708 |
|
} else if (iter->first.compare("CREATED") == 0) { |
2709 |
|
Query.SetCreated(iter->second); |
2710 |
|
} else if (iter->first.compare("MODIFIED") == 0) { |
2711 |
|
Query.SetModified(iter->second); |
2712 |
|
} else if (iter->first.compare("DESCRIPTION") == 0) { |
2713 |
|
Query.Description = iter->second; |
2714 |
|
} else if (iter->first.compare("IS_DRUM") == 0) { |
2715 |
|
if (!strcasecmp(iter->second.c_str(), "true")) { |
2716 |
|
Query.InstrType = SearchQuery::DRUM; |
2717 |
|
} else { |
2718 |
|
Query.InstrType = SearchQuery::CHROMATIC; |
2719 |
|
} |
2720 |
|
} else if (iter->first.compare("PRODUCT") == 0) { |
2721 |
|
Query.Product = iter->second; |
2722 |
|
} else if (iter->first.compare("ARTISTS") == 0) { |
2723 |
|
Query.Artists = iter->second; |
2724 |
|
} else if (iter->first.compare("KEYWORDS") == 0) { |
2725 |
|
Query.Keywords = iter->second; |
2726 |
|
} else { |
2727 |
|
throw Exception("Unknown search criteria: " + iter->first); |
2728 |
|
} |
2729 |
|
} |
2730 |
|
|
2731 |
|
String list; |
2732 |
|
StringListPtr pInstruments = |
2733 |
|
InstrumentsDb::GetInstrumentsDb()->FindInstruments(Dir, &Query, Recursive); |
2734 |
|
|
2735 |
|
for (int i = 0; i < pInstruments->size(); i++) { |
2736 |
|
if (list != "") list += ","; |
2737 |
|
list += "'" + pInstruments->at(i) + "'"; |
2738 |
|
} |
2739 |
|
|
2740 |
|
result.Add(list); |
2741 |
|
} catch (Exception e) { |
2742 |
|
result.Error(e); |
2743 |
|
} |
2744 |
|
#else |
2745 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2746 |
|
#endif |
2747 |
|
return result.Produce(); |
2748 |
|
} |
2749 |
|
|
2750 |
|
|
2751 |
/** |
/** |
2752 |
* 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 |
2753 |
* mode is enabled, all commands from the client will (immediately) be |
* mode is enabled, all commands from the client will (immediately) be |
2766 |
} |
} |
2767 |
return result.Produce(); |
return result.Produce(); |
2768 |
} |
} |
2769 |
|
|
2770 |
|
String LSCPServer::FilterEndlines(String s) { |
2771 |
|
String s2 = s; |
2772 |
|
for (int i = 0; i < s2.length(); i++) { |
2773 |
|
if (s2.at(i) == '\r') s2.at(i) = ' '; |
2774 |
|
else if (s2.at(i) == '\n') s2.at(i) = ' '; |
2775 |
|
} |
2776 |
|
|
2777 |
|
return s2; |
2778 |
|
} |