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 |
|
#if defined(WIN32) |
29 |
|
#include <windows.h> |
30 |
|
#else |
31 |
#include <fcntl.h> |
#include <fcntl.h> |
32 |
|
#endif |
33 |
|
|
34 |
#if HAVE_SQLITE3 |
#if ! HAVE_SQLITE3 |
35 |
# include "sqlite3.h" |
#define DOESNT_HAVE_SQLITE3 "No database support. SQLITE3 was not installed when linuxsampler was built." |
36 |
#endif |
#endif |
37 |
|
|
38 |
#include "../engines/EngineFactory.h" |
#include "../engines/EngineFactory.h" |
40 |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
41 |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
42 |
|
|
43 |
|
|
44 |
|
/** |
45 |
|
* Returns a copy of the given string where all special characters are |
46 |
|
* replaced by LSCP escape sequences ("\xHH"). This function shall be used |
47 |
|
* to escape LSCP response fields in case the respective response field is |
48 |
|
* actually defined as using escape sequences in the LSCP specs. |
49 |
|
* |
50 |
|
* @e Caution: DO NOT use this function for escaping path based responses, |
51 |
|
* use the Path class (src/common/Path.h) for this instead! |
52 |
|
*/ |
53 |
|
static String _escapeLscpResponse(String txt) { |
54 |
|
for (int i = 0; i < txt.length(); i++) { |
55 |
|
const char c = txt.c_str()[i]; |
56 |
|
if ( |
57 |
|
!(c >= '0' && c <= '9') && |
58 |
|
!(c >= 'a' && c <= 'z') && |
59 |
|
!(c >= 'A' && c <= 'Z') && |
60 |
|
!(c == ' ') && !(c == '!') && !(c == '#') && !(c == '$') && |
61 |
|
!(c == '%') && !(c == '&') && !(c == '(') && !(c == ')') && |
62 |
|
!(c == '*') && !(c == '+') && !(c == ',') && !(c == '-') && |
63 |
|
!(c == '.') && !(c == '/') && !(c == ':') && !(c == ';') && |
64 |
|
!(c == '<') && !(c == '=') && !(c == '>') && !(c == '?') && |
65 |
|
!(c == '@') && !(c == '[') && !(c == ']') && |
66 |
|
!(c == '^') && !(c == '_') && !(c == '`') && !(c == '{') && |
67 |
|
!(c == '|') && !(c == '}') && !(c == '~') |
68 |
|
) { |
69 |
|
// convert the "special" character into a "\xHH" LSCP escape sequence |
70 |
|
char buf[5]; |
71 |
|
snprintf(buf, sizeof(buf), "\\x%02x", static_cast<unsigned char>(c)); |
72 |
|
txt.replace(i, 1, buf); |
73 |
|
i += 3; |
74 |
|
} |
75 |
|
} |
76 |
|
return txt; |
77 |
|
} |
78 |
|
|
79 |
/** |
/** |
80 |
* Below are a few static members of the LSCPServer class. |
* Below are a few static members of the LSCPServer class. |
81 |
* The big assumption here is that LSCPServer is going to remain a singleton. |
* The big assumption here is that LSCPServer is going to remain a singleton. |
92 |
fd_set LSCPServer::fdSet; |
fd_set LSCPServer::fdSet; |
93 |
int LSCPServer::currentSocket = -1; |
int LSCPServer::currentSocket = -1; |
94 |
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
95 |
|
std::vector<yyparse_param_t>::iterator itCurrentSession = std::vector<yyparse_param_t>::iterator(); |
96 |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
97 |
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
98 |
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> >(); |
121 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO"); |
122 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT"); |
123 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO"); |
124 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_count, "DB_INSTRUMENT_DIRECTORY_COUNT"); |
125 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_info, "DB_INSTRUMENT_DIRECTORY_INFO"); |
126 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_count, "DB_INSTRUMENT_COUNT"); |
127 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO"); |
128 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO"); |
129 |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
130 |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
131 |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
133 |
} |
} |
134 |
|
|
135 |
LSCPServer::~LSCPServer() { |
LSCPServer::~LSCPServer() { |
136 |
|
#if defined(WIN32) |
137 |
|
if (hSocket >= 0) closesocket(hSocket); |
138 |
|
#else |
139 |
if (hSocket >= 0) close(hSocket); |
if (hSocket >= 0) close(hSocket); |
140 |
|
#endif |
141 |
} |
} |
142 |
|
|
143 |
void LSCPServer::LscpChannelCountListener::ChannelCountChanged(int NewCount) { |
void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) { |
144 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount)); |
145 |
} |
} |
146 |
|
|
147 |
void LSCPServer::LscpAudioDeviceCountListener::AudioDeviceCountChanged(int NewCount) { |
void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) { |
148 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount)); |
149 |
} |
} |
150 |
|
|
151 |
void LSCPServer::LscpMidiDeviceCountListener::MidiDeviceCountChanged(int NewCount) { |
void LSCPServer::EventHandler::MidiDeviceCountChanged(int NewCount) { |
152 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount)); |
153 |
} |
} |
154 |
|
|
155 |
void LSCPServer::LscpMidiInstrumentCountListener::MidiInstrumentCountChanged(int MapId, int NewCount) { |
void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) { |
156 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount)); |
157 |
} |
} |
158 |
|
|
159 |
void LSCPServer::LscpMidiInstrumentInfoListener::MidiInstrumentInfoChanged(int MapId, int Bank, int Program) { |
void LSCPServer::EventHandler::MidiInstrumentInfoChanged(int MapId, int Bank, int Program) { |
160 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_info, MapId, Bank, Program)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_info, MapId, Bank, Program)); |
161 |
} |
} |
162 |
|
|
163 |
void LSCPServer::LscpMidiInstrumentMapCountListener::MidiInstrumentMapCountChanged(int NewCount) { |
void LSCPServer::EventHandler::MidiInstrumentMapCountChanged(int NewCount) { |
164 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_count, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_count, NewCount)); |
165 |
} |
} |
166 |
|
|
167 |
void LSCPServer::LscpMidiInstrumentMapInfoListener::MidiInstrumentMapInfoChanged(int MapId) { |
void LSCPServer::EventHandler::MidiInstrumentMapInfoChanged(int MapId) { |
168 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_info, MapId)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_info, MapId)); |
169 |
} |
} |
170 |
|
|
171 |
void LSCPServer::LscpFxSendCountListener::FxSendCountChanged(int ChannelId, int NewCount) { |
void LSCPServer::EventHandler::FxSendCountChanged(int ChannelId, int NewCount) { |
172 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_count, ChannelId, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_count, ChannelId, NewCount)); |
173 |
} |
} |
174 |
|
|
175 |
void LSCPServer::LscpVoiceCountListener::VoiceCountChanged(int ChannelId, int NewCount) { |
void LSCPServer::EventHandler::VoiceCountChanged(int ChannelId, int NewCount) { |
176 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_voice_count, ChannelId, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_voice_count, ChannelId, NewCount)); |
177 |
} |
} |
178 |
|
|
179 |
void LSCPServer::LscpStreamCountListener::StreamCountChanged(int ChannelId, int NewCount) { |
void LSCPServer::EventHandler::StreamCountChanged(int ChannelId, int NewCount) { |
180 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_stream_count, ChannelId, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_stream_count, ChannelId, NewCount)); |
181 |
} |
} |
182 |
|
|
183 |
void LSCPServer::LscpBufferFillListener::BufferFillChanged(int ChannelId, String FillData) { |
void LSCPServer::EventHandler::BufferFillChanged(int ChannelId, String FillData) { |
184 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_buffer_fill, ChannelId, FillData)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_buffer_fill, ChannelId, FillData)); |
185 |
} |
} |
186 |
|
|
187 |
void LSCPServer::LscpTotalVoiceCountListener::TotalVoiceCountChanged(int NewCount) { |
void LSCPServer::EventHandler::TotalVoiceCountChanged(int NewCount) { |
188 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount)); |
189 |
} |
} |
190 |
|
|
191 |
|
#if HAVE_SQLITE3 |
192 |
|
void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) { |
193 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, InstrumentsDb::toEscapedPath(Dir))); |
194 |
|
} |
195 |
|
|
196 |
|
void LSCPServer::DbInstrumentsEventHandler::DirectoryInfoChanged(String Dir) { |
197 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, InstrumentsDb::toEscapedPath(Dir))); |
198 |
|
} |
199 |
|
|
200 |
|
void LSCPServer::DbInstrumentsEventHandler::DirectoryNameChanged(String Dir, String NewName) { |
201 |
|
Dir = "'" + InstrumentsDb::toEscapedPath(Dir) + "'"; |
202 |
|
NewName = "'" + InstrumentsDb::toEscapedPath(NewName) + "'"; |
203 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, "NAME", Dir, NewName)); |
204 |
|
} |
205 |
|
|
206 |
|
void LSCPServer::DbInstrumentsEventHandler::InstrumentCountChanged(String Dir) { |
207 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_count, InstrumentsDb::toEscapedPath(Dir))); |
208 |
|
} |
209 |
|
|
210 |
|
void LSCPServer::DbInstrumentsEventHandler::InstrumentInfoChanged(String Instr) { |
211 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, InstrumentsDb::toEscapedPath(Instr))); |
212 |
|
} |
213 |
|
|
214 |
|
void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) { |
215 |
|
Instr = "'" + InstrumentsDb::toEscapedPath(Instr) + "'"; |
216 |
|
NewName = "'" + InstrumentsDb::toEscapedPath(NewName) + "'"; |
217 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, "NAME", Instr, NewName)); |
218 |
|
} |
219 |
|
|
220 |
|
void LSCPServer::DbInstrumentsEventHandler::JobStatusChanged(int JobId) { |
221 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instrs_job_info, JobId)); |
222 |
|
} |
223 |
|
#endif // HAVE_SQLITE3 |
224 |
|
|
225 |
|
|
226 |
/** |
/** |
227 |
* Blocks the calling thread until the LSCP Server is initialized and |
* Blocks the calling thread until the LSCP Server is initialized and |
238 |
} |
} |
239 |
|
|
240 |
int LSCPServer::Main() { |
int LSCPServer::Main() { |
241 |
|
#if defined(WIN32) |
242 |
|
WSADATA wsaData; |
243 |
|
int iResult; |
244 |
|
iResult = WSAStartup(MAKEWORD(2,2), &wsaData); |
245 |
|
if (iResult != 0) { |
246 |
|
std::cerr << "LSCPServer: WSAStartup failed: " << iResult << "\n"; |
247 |
|
exit(EXIT_FAILURE); |
248 |
|
} |
249 |
|
#endif |
250 |
hSocket = socket(AF_INET, SOCK_STREAM, 0); |
hSocket = socket(AF_INET, SOCK_STREAM, 0); |
251 |
if (hSocket < 0) { |
if (hSocket < 0) { |
252 |
std::cerr << "LSCPServer: Could not create server socket." << std::endl; |
std::cerr << "LSCPServer: Could not create server socket." << std::endl; |
260 |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
261 |
if (trial > LSCP_SERVER_BIND_TIMEOUT) { |
if (trial > LSCP_SERVER_BIND_TIMEOUT) { |
262 |
std::cerr << "gave up!" << std::endl; |
std::cerr << "gave up!" << std::endl; |
263 |
|
#if defined(WIN32) |
264 |
|
closesocket(hSocket); |
265 |
|
#else |
266 |
close(hSocket); |
close(hSocket); |
267 |
|
#endif |
268 |
//return -1; |
//return -1; |
269 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
270 |
} |
} |
276 |
|
|
277 |
listen(hSocket, 1); |
listen(hSocket, 1); |
278 |
Initialized.Set(true); |
Initialized.Set(true); |
|
|
|
|
// Registering event listeners |
|
|
pSampler->AddChannelCountListener(&channelCountListener); |
|
|
pSampler->AddAudioDeviceCountListener(&audioDeviceCountListener); |
|
|
pSampler->AddMidiDeviceCountListener(&midiDeviceCountListener); |
|
|
pSampler->AddVoiceCountListener(&voiceCountListener); |
|
|
pSampler->AddStreamCountListener(&streamCountListener); |
|
|
pSampler->AddBufferFillListener(&bufferFillListener); |
|
|
pSampler->AddTotalVoiceCountListener(&totalVoiceCountListener); |
|
|
pSampler->AddFxSendCountListener(&fxSendCountListener); |
|
|
MidiInstrumentMapper::AddMidiInstrumentCountListener(&midiInstrumentCountListener); |
|
|
MidiInstrumentMapper::AddMidiInstrumentInfoListener(&midiInstrumentInfoListener); |
|
|
MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&midiInstrumentMapCountListener); |
|
|
MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(&midiInstrumentMapInfoListener); |
|
279 |
|
|
280 |
|
// Registering event listeners |
281 |
|
pSampler->AddChannelCountListener(&eventHandler); |
282 |
|
pSampler->AddAudioDeviceCountListener(&eventHandler); |
283 |
|
pSampler->AddMidiDeviceCountListener(&eventHandler); |
284 |
|
pSampler->AddVoiceCountListener(&eventHandler); |
285 |
|
pSampler->AddStreamCountListener(&eventHandler); |
286 |
|
pSampler->AddBufferFillListener(&eventHandler); |
287 |
|
pSampler->AddTotalVoiceCountListener(&eventHandler); |
288 |
|
pSampler->AddFxSendCountListener(&eventHandler); |
289 |
|
MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler); |
290 |
|
MidiInstrumentMapper::AddMidiInstrumentInfoListener(&eventHandler); |
291 |
|
MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&eventHandler); |
292 |
|
MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(&eventHandler); |
293 |
|
#if HAVE_SQLITE3 |
294 |
|
InstrumentsDb::GetInstrumentsDb()->AddInstrumentsDbListener(&dbInstrumentsEventHandler); |
295 |
|
#endif |
296 |
// now wait for client connections and handle their requests |
// now wait for client connections and handle their requests |
297 |
sockaddr_in client; |
sockaddr_in client; |
298 |
int length = sizeof(client); |
int length = sizeof(client); |
346 |
continue; //Nothing try again |
continue; //Nothing try again |
347 |
if (retval == -1) { |
if (retval == -1) { |
348 |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
349 |
|
#if defined(WIN32) |
350 |
|
closesocket(hSocket); |
351 |
|
#else |
352 |
close(hSocket); |
close(hSocket); |
353 |
|
#endif |
354 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
355 |
} |
} |
356 |
|
|
362 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
363 |
} |
} |
364 |
|
|
365 |
|
#if defined(WIN32) |
366 |
|
u_long nonblock_io = 1; |
367 |
|
if( ioctlsocket(socket, FIONBIO, &nonblock_io) ) { |
368 |
|
std::cerr << "LSCPServer: ioctlsocket: set FIONBIO failed. Error " << WSAGetLastError() << std::endl; |
369 |
|
exit(EXIT_FAILURE); |
370 |
|
} |
371 |
|
#else |
372 |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
373 |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
374 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
375 |
} |
} |
376 |
|
#endif |
377 |
|
|
378 |
// Parser initialization |
// Parser initialization |
379 |
yyparse_param_t yyparse_param; |
yyparse_param_t yyparse_param; |
397 |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
398 |
restart(NULL, dummy); // restart the 'scanner' |
restart(NULL, dummy); // restart the 'scanner' |
399 |
currentSocket = (*iter).hSession; //a hack |
currentSocket = (*iter).hSession; //a hack |
400 |
|
itCurrentSession = iter; // another hack |
401 |
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
402 |
if ((*iter).bVerbose) { // if echo mode enabled |
if ((*iter).bVerbose) { // if echo mode enabled |
403 |
AnswerClient(bufferedCommands[currentSocket]); |
AnswerClient(bufferedCommands[currentSocket]); |
404 |
} |
} |
405 |
int result = yyparse(&(*iter)); |
int result = yyparse(&(*iter)); |
406 |
currentSocket = -1; //continuation of a hack |
currentSocket = -1; //continuation of a hack |
407 |
|
itCurrentSession = Sessions.end(); // hack as well |
408 |
dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket)); |
dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket)); |
409 |
if (result == LSCP_QUIT) { //Was it a quit command by any chance? |
if (result == LSCP_QUIT) { //Was it a quit command by any chance? |
410 |
CloseConnection(iter); |
CloseConnection(iter); |
432 |
NotifyMutex.Lock(); |
NotifyMutex.Lock(); |
433 |
bufferedCommands.erase(socket); |
bufferedCommands.erase(socket); |
434 |
bufferedNotifies.erase(socket); |
bufferedNotifies.erase(socket); |
435 |
|
#if defined(WIN32) |
436 |
|
closesocket(socket); |
437 |
|
#else |
438 |
close(socket); |
close(socket); |
439 |
|
#endif |
440 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
441 |
} |
} |
442 |
|
|
501 |
return command.size(); |
return command.size(); |
502 |
} |
} |
503 |
|
|
504 |
|
extern yyparse_param_t* GetCurrentYaccSession() { |
505 |
|
return &(*itCurrentSession); |
506 |
|
} |
507 |
|
|
508 |
/** |
/** |
509 |
* Will be called to try to read the command from the socket |
* Will be called to try to read the command from the socket |
510 |
* If command is read, it will return true. Otherwise false is returned. |
* If command is read, it will return true. Otherwise false is returned. |
515 |
char c; |
char c; |
516 |
int i = 0; |
int i = 0; |
517 |
while (true) { |
while (true) { |
518 |
|
#if defined(WIN32) |
519 |
|
int result = recv(socket, (char *)&c, 1, 0); //Read one character at a time for now |
520 |
|
#else |
521 |
int result = recv(socket, (void *)&c, 1, 0); //Read one character at a time for now |
int result = recv(socket, (void *)&c, 1, 0); //Read one character at a time for now |
522 |
|
#endif |
523 |
if (result == 0) { //socket was selected, so 0 here means client has closed the connection |
if (result == 0) { //socket was selected, so 0 here means client has closed the connection |
524 |
CloseConnection(iter); |
CloseConnection(iter); |
525 |
break; |
break; |
534 |
} |
} |
535 |
bufferedCommands[socket] += c; |
bufferedCommands[socket] += c; |
536 |
} |
} |
537 |
|
#if defined(WIN32) |
538 |
|
if (result == SOCKET_ERROR) { |
539 |
|
int wsa_lasterror = WSAGetLastError(); |
540 |
|
if (wsa_lasterror == WSAEWOULDBLOCK) //Would block, try again later. |
541 |
|
return false; |
542 |
|
dmsg(2,("LSCPScanner: Socket error after recv() Error %d.\n", wsa_lasterror)); |
543 |
|
CloseConnection(iter); |
544 |
|
break; |
545 |
|
} |
546 |
|
#else |
547 |
if (result == -1) { |
if (result == -1) { |
548 |
if (errno == EAGAIN) //Would block, try again later. |
if (errno == EAGAIN) //Would block, try again later. |
549 |
return false; |
return false; |
582 |
CloseConnection(iter); |
CloseConnection(iter); |
583 |
break; |
break; |
584 |
} |
} |
585 |
|
#endif |
586 |
} |
} |
587 |
return false; |
return false; |
588 |
} |
} |
700 |
return result.Produce(); |
return result.Produce(); |
701 |
} |
} |
702 |
|
|
703 |
|
EngineChannel* LSCPServer::GetEngineChannel(uint uiSamplerChannel) { |
704 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
705 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
706 |
|
|
707 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
708 |
|
if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); |
709 |
|
|
710 |
|
return pEngineChannel; |
711 |
|
} |
712 |
|
|
713 |
/** |
/** |
714 |
* Will be called by the parser to load an instrument. |
* Will be called by the parser to load an instrument. |
715 |
*/ |
*/ |
856 |
LockRTNotify(); |
LockRTNotify(); |
857 |
try { |
try { |
858 |
Engine* pEngine = EngineFactory::Create(EngineName); |
Engine* pEngine = EngineFactory::Create(EngineName); |
859 |
result.Add("DESCRIPTION", pEngine->Description()); |
result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description())); |
860 |
result.Add("VERSION", pEngine->Version()); |
result.Add("VERSION", pEngine->Version()); |
861 |
EngineFactory::Destroy(pEngine); |
EngineFactory::Destroy(pEngine); |
862 |
} |
} |
929 |
if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
930 |
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
931 |
|
|
932 |
|
// convert the filename into the correct encoding as defined for LSCP |
933 |
|
// (especially in terms of special characters -> escape sequences) |
934 |
|
if (InstrumentFileName != "NONE" && InstrumentFileName != "") { |
935 |
|
#if WIN32 |
936 |
|
InstrumentFileName = Path::fromWindows(InstrumentFileName).toLscp(); |
937 |
|
#else |
938 |
|
// assuming POSIX |
939 |
|
InstrumentFileName = Path::fromPosix(InstrumentFileName).toLscp(); |
940 |
|
#endif |
941 |
|
} |
942 |
|
|
943 |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
944 |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
result.Add("INSTRUMENT_NR", InstrumentIndex); |
945 |
result.Add("INSTRUMENT_NAME", InstrumentName); |
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(InstrumentName)); |
946 |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
947 |
result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false")); |
result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false")); |
948 |
result.Add("SOLO", Solo); |
result.Add("SOLO", Solo); |
1884 |
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx); |
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx); |
1885 |
if (iter == mappings.end()) result.Error("there is no map entry with that index"); |
if (iter == mappings.end()) result.Error("there is no map entry with that index"); |
1886 |
else { // found |
else { // found |
1887 |
result.Add("NAME", iter->second.Name); |
|
1888 |
|
// convert the filename into the correct encoding as defined for LSCP |
1889 |
|
// (especially in terms of special characters -> escape sequences) |
1890 |
|
#if WIN32 |
1891 |
|
const String instrumentFileName = Path::fromWindows(iter->second.InstrumentFile).toLscp(); |
1892 |
|
#else |
1893 |
|
// assuming POSIX |
1894 |
|
const String instrumentFileName = Path::fromPosix(iter->second.InstrumentFile).toLscp(); |
1895 |
|
#endif |
1896 |
|
|
1897 |
|
result.Add("NAME", _escapeLscpResponse(iter->second.Name)); |
1898 |
result.Add("ENGINE_NAME", iter->second.EngineName); |
result.Add("ENGINE_NAME", iter->second.EngineName); |
1899 |
result.Add("INSTRUMENT_FILE", iter->second.InstrumentFile); |
result.Add("INSTRUMENT_FILE", instrumentFileName); |
1900 |
result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex); |
result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex); |
1901 |
String instrumentName; |
String instrumentName; |
1902 |
Engine* pEngine = EngineFactory::Create(iter->second.EngineName); |
Engine* pEngine = EngineFactory::Create(iter->second.EngineName); |
1909 |
} |
} |
1910 |
EngineFactory::Destroy(pEngine); |
EngineFactory::Destroy(pEngine); |
1911 |
} |
} |
1912 |
result.Add("INSTRUMENT_NAME", instrumentName); |
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName)); |
1913 |
switch (iter->second.LoadMode) { |
switch (iter->second.LoadMode) { |
1914 |
case MidiInstrumentMapper::ON_DEMAND: |
case MidiInstrumentMapper::ON_DEMAND: |
1915 |
result.Add("LOAD_MODE", "ON_DEMAND"); |
result.Add("LOAD_MODE", "ON_DEMAND"); |
2064 |
dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n")); |
dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n")); |
2065 |
LSCPResultSet result; |
LSCPResultSet result; |
2066 |
try { |
try { |
2067 |
result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID)); |
result.Add("NAME", _escapeLscpResponse(MidiInstrumentMapper::MapName(MidiMapID))); |
2068 |
|
result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID); |
2069 |
} catch (Exception e) { |
} catch (Exception e) { |
2070 |
result.Error(e); |
result.Error(e); |
2071 |
} |
} |
2114 |
dmsg(2,("LSCPServer: CreateFxSend()\n")); |
dmsg(2,("LSCPServer: CreateFxSend()\n")); |
2115 |
LSCPResultSet result; |
LSCPResultSet result; |
2116 |
try { |
try { |
2117 |
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"); |
|
2118 |
|
|
2119 |
FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name); |
FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name); |
2120 |
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)"); |
2130 |
dmsg(2,("LSCPServer: DestroyFxSend()\n")); |
dmsg(2,("LSCPServer: DestroyFxSend()\n")); |
2131 |
LSCPResultSet result; |
LSCPResultSet result; |
2132 |
try { |
try { |
2133 |
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"); |
|
2134 |
|
|
2135 |
FxSend* pFxSend = NULL; |
FxSend* pFxSend = NULL; |
2136 |
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
2151 |
dmsg(2,("LSCPServer: GetFxSends()\n")); |
dmsg(2,("LSCPServer: GetFxSends()\n")); |
2152 |
LSCPResultSet result; |
LSCPResultSet result; |
2153 |
try { |
try { |
2154 |
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"); |
|
2155 |
|
|
2156 |
result.Add(pEngineChannel->GetFxSendCount()); |
result.Add(pEngineChannel->GetFxSendCount()); |
2157 |
} catch (Exception e) { |
} catch (Exception e) { |
2165 |
LSCPResultSet result; |
LSCPResultSet result; |
2166 |
String list; |
String list; |
2167 |
try { |
try { |
2168 |
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"); |
|
2169 |
|
|
2170 |
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
2171 |
FxSend* pFxSend = pEngineChannel->GetFxSend(i); |
FxSend* pFxSend = pEngineChannel->GetFxSend(i); |
2179 |
return result.Produce(); |
return result.Produce(); |
2180 |
} |
} |
2181 |
|
|
2182 |
|
FxSend* LSCPServer::GetFxSend(uint uiSamplerChannel, uint FxSendID) { |
2183 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2184 |
|
|
2185 |
|
FxSend* pFxSend = NULL; |
2186 |
|
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
2187 |
|
if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) { |
2188 |
|
pFxSend = pEngineChannel->GetFxSend(i); |
2189 |
|
break; |
2190 |
|
} |
2191 |
|
} |
2192 |
|
if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel"); |
2193 |
|
return pFxSend; |
2194 |
|
} |
2195 |
|
|
2196 |
String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) { |
String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) { |
2197 |
dmsg(2,("LSCPServer: GetFxSendInfo()\n")); |
dmsg(2,("LSCPServer: GetFxSendInfo()\n")); |
2198 |
LSCPResultSet result; |
LSCPResultSet result; |
2199 |
try { |
try { |
2200 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2201 |
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"); |
|
2202 |
|
|
2203 |
// gather audio routing informations |
// gather audio routing informations |
2204 |
String AudioRouting; |
String AudioRouting; |
2208 |
} |
} |
2209 |
|
|
2210 |
// success |
// success |
2211 |
result.Add("NAME", pFxSend->Name()); |
result.Add("NAME", _escapeLscpResponse(pFxSend->Name())); |
2212 |
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
2213 |
result.Add("LEVEL", ToString(pFxSend->Level())); |
result.Add("LEVEL", ToString(pFxSend->Level())); |
2214 |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
2218 |
return result.Produce(); |
return result.Produce(); |
2219 |
} |
} |
2220 |
|
|
2221 |
String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) { |
String LSCPServer::SetFxSendName(uint uiSamplerChannel, uint FxSendID, String Name) { |
2222 |
dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n")); |
dmsg(2,("LSCPServer: SetFxSendName()\n")); |
2223 |
LSCPResultSet result; |
LSCPResultSet result; |
2224 |
try { |
try { |
2225 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
2226 |
|
|
2227 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
pFxSend->SetName(Name); |
2228 |
if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2229 |
|
} catch (Exception e) { |
2230 |
|
result.Error(e); |
2231 |
|
} |
2232 |
|
return result.Produce(); |
2233 |
|
} |
2234 |
|
|
2235 |
FxSend* pFxSend = NULL; |
String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) { |
2236 |
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n")); |
2237 |
if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) { |
LSCPResultSet result; |
2238 |
pFxSend = pEngineChannel->GetFxSend(i); |
try { |
2239 |
break; |
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
|
} |
|
|
} |
|
|
if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel"); |
|
2240 |
|
|
2241 |
pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel); |
pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel); |
2242 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2250 |
dmsg(2,("LSCPServer: SetFxSendMidiController()\n")); |
dmsg(2,("LSCPServer: SetFxSendMidiController()\n")); |
2251 |
LSCPResultSet result; |
LSCPResultSet result; |
2252 |
try { |
try { |
2253 |
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"); |
|
2254 |
|
|
2255 |
pFxSend->SetMidiController(MidiController); |
pFxSend->SetMidiController(MidiController); |
2256 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2264 |
dmsg(2,("LSCPServer: SetFxSendLevel()\n")); |
dmsg(2,("LSCPServer: SetFxSendLevel()\n")); |
2265 |
LSCPResultSet result; |
LSCPResultSet result; |
2266 |
try { |
try { |
2267 |
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"); |
|
2268 |
|
|
2269 |
pFxSend->SetLevel((float)dLevel); |
pFxSend->SetLevel((float)dLevel); |
2270 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2274 |
return result.Produce(); |
return result.Produce(); |
2275 |
} |
} |
2276 |
|
|
2277 |
|
String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) { |
2278 |
|
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
2279 |
|
LSCPResultSet result; |
2280 |
|
try { |
2281 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
2282 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
2283 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
2284 |
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
2285 |
|
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
2286 |
|
Engine* pEngine = pEngineChannel->GetEngine(); |
2287 |
|
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
2288 |
|
if (!pInstrumentManager) throw Exception("Engine does not provide an instrument manager"); |
2289 |
|
InstrumentManager::instrument_id_t instrumentID; |
2290 |
|
instrumentID.FileName = pEngineChannel->InstrumentFileName(); |
2291 |
|
instrumentID.Index = pEngineChannel->InstrumentIndex(); |
2292 |
|
pInstrumentManager->LaunchInstrumentEditor(instrumentID); |
2293 |
|
} catch (Exception e) { |
2294 |
|
result.Error(e); |
2295 |
|
} |
2296 |
|
return result.Produce(); |
2297 |
|
} |
2298 |
|
|
2299 |
/** |
/** |
2300 |
* Will be called by the parser to reset a particular sampler channel. |
* Will be called by the parser to reset a particular sampler channel. |
2301 |
*/ |
*/ |
2331 |
*/ |
*/ |
2332 |
String LSCPServer::GetServerInfo() { |
String LSCPServer::GetServerInfo() { |
2333 |
dmsg(2,("LSCPServer: GetServerInfo()\n")); |
dmsg(2,("LSCPServer: GetServerInfo()\n")); |
2334 |
|
const std::string description = |
2335 |
|
_escapeLscpResponse("LinuxSampler - modular, streaming capable sampler"); |
2336 |
LSCPResultSet result; |
LSCPResultSet result; |
2337 |
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
result.Add("DESCRIPTION", description); |
2338 |
result.Add("VERSION", VERSION); |
result.Add("VERSION", VERSION); |
2339 |
result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR)); |
result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR)); |
2340 |
|
#if HAVE_SQLITE3 |
2341 |
|
result.Add("INSTRUMENTS_DB_SUPPORT", "yes"); |
2342 |
|
#else |
2343 |
|
result.Add("INSTRUMENTS_DB_SUPPORT", "no"); |
2344 |
|
#endif |
2345 |
|
|
2346 |
return result.Produce(); |
return result.Produce(); |
2347 |
} |
} |
2348 |
|
|
2384 |
return result.Produce(); |
return result.Produce(); |
2385 |
} |
} |
2386 |
|
|
2387 |
|
String LSCPServer::GetFileInstruments(String Filename) { |
2388 |
|
dmsg(2,("LSCPServer: GetFileInstruments(String Filename=%s)\n",Filename.c_str())); |
2389 |
|
LSCPResultSet result; |
2390 |
|
try { |
2391 |
|
VerifyFile(Filename); |
2392 |
|
} catch (Exception e) { |
2393 |
|
result.Error(e); |
2394 |
|
return result.Produce(); |
2395 |
|
} |
2396 |
|
// try to find a sampler engine that can handle the file |
2397 |
|
bool bFound = false; |
2398 |
|
std::vector<String> engineTypes = EngineFactory::AvailableEngineTypes(); |
2399 |
|
for (int i = 0; !bFound && i < engineTypes.size(); i++) { |
2400 |
|
Engine* pEngine = NULL; |
2401 |
|
try { |
2402 |
|
pEngine = EngineFactory::Create(engineTypes[i]); |
2403 |
|
if (!pEngine) throw Exception("Internal error: could not create '" + engineTypes[i] + "' engine"); |
2404 |
|
InstrumentManager* pManager = pEngine->GetInstrumentManager(); |
2405 |
|
if (pManager) { |
2406 |
|
std::vector<InstrumentManager::instrument_id_t> IDs = |
2407 |
|
pManager->GetInstrumentFileContent(Filename); |
2408 |
|
// return the amount of instruments in the file |
2409 |
|
result.Add(IDs.size()); |
2410 |
|
// no more need to ask other engine types |
2411 |
|
bFound = true; |
2412 |
|
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
2413 |
|
} catch (Exception e) { |
2414 |
|
// NOOP, as exception is thrown if engine doesn't support file |
2415 |
|
} |
2416 |
|
if (pEngine) EngineFactory::Destroy(pEngine); |
2417 |
|
} |
2418 |
|
|
2419 |
|
if (!bFound) result.Error("Unknown file format"); |
2420 |
|
return result.Produce(); |
2421 |
|
} |
2422 |
|
|
2423 |
|
String LSCPServer::ListFileInstruments(String Filename) { |
2424 |
|
dmsg(2,("LSCPServer: ListFileInstruments(String Filename=%s)\n",Filename.c_str())); |
2425 |
|
LSCPResultSet result; |
2426 |
|
try { |
2427 |
|
VerifyFile(Filename); |
2428 |
|
} catch (Exception e) { |
2429 |
|
result.Error(e); |
2430 |
|
return result.Produce(); |
2431 |
|
} |
2432 |
|
// try to find a sampler engine that can handle the file |
2433 |
|
bool bFound = false; |
2434 |
|
std::vector<String> engineTypes = EngineFactory::AvailableEngineTypes(); |
2435 |
|
for (int i = 0; !bFound && i < engineTypes.size(); i++) { |
2436 |
|
Engine* pEngine = NULL; |
2437 |
|
try { |
2438 |
|
pEngine = EngineFactory::Create(engineTypes[i]); |
2439 |
|
if (!pEngine) throw Exception("Internal error: could not create '" + engineTypes[i] + "' engine"); |
2440 |
|
InstrumentManager* pManager = pEngine->GetInstrumentManager(); |
2441 |
|
if (pManager) { |
2442 |
|
std::vector<InstrumentManager::instrument_id_t> IDs = |
2443 |
|
pManager->GetInstrumentFileContent(Filename); |
2444 |
|
// return a list of IDs of the instruments in the file |
2445 |
|
String s; |
2446 |
|
for (int j = 0; j < IDs.size(); j++) { |
2447 |
|
if (s.size()) s += ","; |
2448 |
|
s += ToString(IDs[j].Index); |
2449 |
|
} |
2450 |
|
result.Add(s); |
2451 |
|
// no more need to ask other engine types |
2452 |
|
bFound = true; |
2453 |
|
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
2454 |
|
} catch (Exception e) { |
2455 |
|
// NOOP, as exception is thrown if engine doesn't support file |
2456 |
|
} |
2457 |
|
if (pEngine) EngineFactory::Destroy(pEngine); |
2458 |
|
} |
2459 |
|
|
2460 |
|
if (!bFound) result.Error("Unknown file format"); |
2461 |
|
return result.Produce(); |
2462 |
|
} |
2463 |
|
|
2464 |
|
String LSCPServer::GetFileInstrumentInfo(String Filename, uint InstrumentID) { |
2465 |
|
dmsg(2,("LSCPServer: GetFileInstrumentInfo(String Filename=%s, InstrumentID=%d)\n",Filename.c_str(),InstrumentID)); |
2466 |
|
LSCPResultSet result; |
2467 |
|
try { |
2468 |
|
VerifyFile(Filename); |
2469 |
|
} catch (Exception e) { |
2470 |
|
result.Error(e); |
2471 |
|
return result.Produce(); |
2472 |
|
} |
2473 |
|
InstrumentManager::instrument_id_t id; |
2474 |
|
id.FileName = Filename; |
2475 |
|
id.Index = InstrumentID; |
2476 |
|
// try to find a sampler engine that can handle the file |
2477 |
|
bool bFound = false; |
2478 |
|
bool bFatalErr = false; |
2479 |
|
std::vector<String> engineTypes = EngineFactory::AvailableEngineTypes(); |
2480 |
|
for (int i = 0; !bFound && !bFatalErr && i < engineTypes.size(); i++) { |
2481 |
|
Engine* pEngine = NULL; |
2482 |
|
try { |
2483 |
|
pEngine = EngineFactory::Create(engineTypes[i]); |
2484 |
|
if (!pEngine) throw Exception("Internal error: could not create '" + engineTypes[i] + "' engine"); |
2485 |
|
InstrumentManager* pManager = pEngine->GetInstrumentManager(); |
2486 |
|
if (pManager) { |
2487 |
|
// check if the instrument index is valid |
2488 |
|
// FIXME: this won't work if an engine only supports parts of the instrument file |
2489 |
|
std::vector<InstrumentManager::instrument_id_t> IDs = |
2490 |
|
pManager->GetInstrumentFileContent(Filename); |
2491 |
|
if (std::find(IDs.begin(), IDs.end(), id) == IDs.end()) { |
2492 |
|
std::stringstream ss; |
2493 |
|
ss << "Invalid instrument index " << InstrumentID << " for instrument file '" << Filename << "'"; |
2494 |
|
bFatalErr = true; |
2495 |
|
throw Exception(ss.str()); |
2496 |
|
} |
2497 |
|
// get the info of the requested instrument |
2498 |
|
InstrumentManager::instrument_info_t info = |
2499 |
|
pManager->GetInstrumentInfo(id); |
2500 |
|
// return detailed informations about the file |
2501 |
|
result.Add("NAME", info.InstrumentName); |
2502 |
|
result.Add("FORMAT_FAMILY", engineTypes[i]); |
2503 |
|
result.Add("FORMAT_VERSION", info.FormatVersion); |
2504 |
|
result.Add("PRODUCT", info.Product); |
2505 |
|
result.Add("ARTISTS", info.Artists); |
2506 |
|
// no more need to ask other engine types |
2507 |
|
bFound = true; |
2508 |
|
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
2509 |
|
} catch (Exception e) { |
2510 |
|
// usually NOOP, as exception is thrown if engine doesn't support file |
2511 |
|
if (bFatalErr) result.Error(e); |
2512 |
|
} |
2513 |
|
if (pEngine) EngineFactory::Destroy(pEngine); |
2514 |
|
} |
2515 |
|
|
2516 |
|
if (!bFound && !bFatalErr) result.Error("Unknown file format"); |
2517 |
|
return result.Produce(); |
2518 |
|
} |
2519 |
|
|
2520 |
|
void LSCPServer::VerifyFile(String Filename) { |
2521 |
|
#if WIN32 |
2522 |
|
WIN32_FIND_DATA win32FileAttributeData; |
2523 |
|
BOOL res = GetFileAttributesEx( Filename.c_str(), GetFileExInfoStandard, &win32FileAttributeData ); |
2524 |
|
if (!res) { |
2525 |
|
std::stringstream ss; |
2526 |
|
ss << "File does not exist, GetFileAttributesEx failed `" << Filename << "`: Error " << GetLastError(); |
2527 |
|
throw Exception(ss.str()); |
2528 |
|
} |
2529 |
|
if ( win32FileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { |
2530 |
|
throw Exception("Directory is specified"); |
2531 |
|
} |
2532 |
|
#else |
2533 |
|
struct stat statBuf; |
2534 |
|
int res = stat(Filename.c_str(), &statBuf); |
2535 |
|
if (res) { |
2536 |
|
std::stringstream ss; |
2537 |
|
ss << "Fail to stat `" << Filename << "`: " << strerror(errno); |
2538 |
|
throw Exception(ss.str()); |
2539 |
|
} |
2540 |
|
|
2541 |
|
if (S_ISDIR(statBuf.st_mode)) { |
2542 |
|
throw Exception("Directory is specified"); |
2543 |
|
} |
2544 |
|
#endif |
2545 |
|
} |
2546 |
|
|
2547 |
/** |
/** |
2548 |
* Will be called by the parser to subscribe a client (frontend) on the |
* Will be called by the parser to subscribe a client (frontend) on the |
2549 |
* server for receiving event messages. |
* server for receiving event messages. |
2570 |
return result.Produce(); |
return result.Produce(); |
2571 |
} |
} |
2572 |
|
|
2573 |
static int select_callback(void * lscpResultSet, int argc, |
String LSCPServer::AddDbInstrumentDirectory(String Dir) { |
2574 |
char **argv, char **azColName) |
dmsg(2,("LSCPServer: AddDbInstrumentDirectory(Dir=%s)\n", Dir.c_str())); |
2575 |
{ |
LSCPResultSet result; |
2576 |
LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet; |
#if HAVE_SQLITE3 |
2577 |
resultSet->Add(argc, argv); |
try { |
2578 |
return 0; |
InstrumentsDb::GetInstrumentsDb()->AddDirectory(Dir); |
2579 |
|
} catch (Exception e) { |
2580 |
|
result.Error(e); |
2581 |
|
} |
2582 |
|
#else |
2583 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2584 |
|
#endif |
2585 |
|
return result.Produce(); |
2586 |
} |
} |
2587 |
|
|
2588 |
String LSCPServer::QueryDatabase(String query) { |
String LSCPServer::RemoveDbInstrumentDirectory(String Dir, bool Force) { |
2589 |
|
dmsg(2,("LSCPServer: RemoveDbInstrumentDirectory(Dir=%s,Force=%d)\n", Dir.c_str(), Force)); |
2590 |
LSCPResultSet result; |
LSCPResultSet result; |
2591 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2592 |
char* zErrMsg = NULL; |
try { |
2593 |
sqlite3 *db; |
InstrumentsDb::GetInstrumentsDb()->RemoveDirectory(Dir, Force); |
2594 |
String selectStr = "SELECT " + query; |
} catch (Exception e) { |
2595 |
|
result.Error(e); |
2596 |
|
} |
2597 |
|
#else |
2598 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2599 |
|
#endif |
2600 |
|
return result.Produce(); |
2601 |
|
} |
2602 |
|
|
2603 |
int rc = sqlite3_open("linuxsampler.db", &db); |
String LSCPServer::GetDbInstrumentDirectoryCount(String Dir, bool Recursive) { |
2604 |
if (rc == SQLITE_OK) |
dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2605 |
{ |
LSCPResultSet result; |
2606 |
rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg); |
#if HAVE_SQLITE3 |
2607 |
|
try { |
2608 |
|
result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir, Recursive)); |
2609 |
|
} catch (Exception e) { |
2610 |
|
result.Error(e); |
2611 |
} |
} |
2612 |
if ( rc != SQLITE_OK ) |
#else |
2613 |
{ |
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2614 |
result.Error(String(zErrMsg), rc); |
#endif |
2615 |
|
return result.Produce(); |
2616 |
|
} |
2617 |
|
|
2618 |
|
String LSCPServer::GetDbInstrumentDirectories(String Dir, bool Recursive) { |
2619 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2620 |
|
LSCPResultSet result; |
2621 |
|
#if HAVE_SQLITE3 |
2622 |
|
try { |
2623 |
|
String list; |
2624 |
|
StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir, Recursive); |
2625 |
|
|
2626 |
|
for (int i = 0; i < dirs->size(); i++) { |
2627 |
|
if (list != "") list += ","; |
2628 |
|
list += "'" + InstrumentsDb::toEscapedPath(dirs->at(i)) + "'"; |
2629 |
|
} |
2630 |
|
|
2631 |
|
result.Add(list); |
2632 |
|
} catch (Exception e) { |
2633 |
|
result.Error(e); |
2634 |
} |
} |
|
sqlite3_close(db); |
|
2635 |
#else |
#else |
2636 |
result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0); |
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2637 |
#endif |
#endif |
2638 |
return result.Produce(); |
return result.Produce(); |
2639 |
} |
} |
2640 |
|
|
2641 |
|
String LSCPServer::GetDbInstrumentDirectoryInfo(String Dir) { |
2642 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectoryInfo(Dir=%s)\n", Dir.c_str())); |
2643 |
|
LSCPResultSet result; |
2644 |
|
#if HAVE_SQLITE3 |
2645 |
|
try { |
2646 |
|
DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir); |
2647 |
|
|
2648 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(info.Description)); |
2649 |
|
result.Add("CREATED", info.Created); |
2650 |
|
result.Add("MODIFIED", info.Modified); |
2651 |
|
} catch (Exception e) { |
2652 |
|
result.Error(e); |
2653 |
|
} |
2654 |
|
#else |
2655 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2656 |
|
#endif |
2657 |
|
return result.Produce(); |
2658 |
|
} |
2659 |
|
|
2660 |
|
String LSCPServer::SetDbInstrumentDirectoryName(String Dir, String Name) { |
2661 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDirectoryName(Dir=%s,Name=%s)\n", Dir.c_str(), Name.c_str())); |
2662 |
|
LSCPResultSet result; |
2663 |
|
#if HAVE_SQLITE3 |
2664 |
|
try { |
2665 |
|
InstrumentsDb::GetInstrumentsDb()->RenameDirectory(Dir, Name); |
2666 |
|
} catch (Exception e) { |
2667 |
|
result.Error(e); |
2668 |
|
} |
2669 |
|
#else |
2670 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2671 |
|
#endif |
2672 |
|
return result.Produce(); |
2673 |
|
} |
2674 |
|
|
2675 |
|
String LSCPServer::MoveDbInstrumentDirectory(String Dir, String Dst) { |
2676 |
|
dmsg(2,("LSCPServer: MoveDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str())); |
2677 |
|
LSCPResultSet result; |
2678 |
|
#if HAVE_SQLITE3 |
2679 |
|
try { |
2680 |
|
InstrumentsDb::GetInstrumentsDb()->MoveDirectory(Dir, Dst); |
2681 |
|
} catch (Exception e) { |
2682 |
|
result.Error(e); |
2683 |
|
} |
2684 |
|
#else |
2685 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2686 |
|
#endif |
2687 |
|
return result.Produce(); |
2688 |
|
} |
2689 |
|
|
2690 |
|
String LSCPServer::CopyDbInstrumentDirectory(String Dir, String Dst) { |
2691 |
|
dmsg(2,("LSCPServer: CopyDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str())); |
2692 |
|
LSCPResultSet result; |
2693 |
|
#if HAVE_SQLITE3 |
2694 |
|
try { |
2695 |
|
InstrumentsDb::GetInstrumentsDb()->CopyDirectory(Dir, Dst); |
2696 |
|
} catch (Exception e) { |
2697 |
|
result.Error(e); |
2698 |
|
} |
2699 |
|
#else |
2700 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2701 |
|
#endif |
2702 |
|
return result.Produce(); |
2703 |
|
} |
2704 |
|
|
2705 |
|
String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) { |
2706 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDirectoryDescription(Dir=%s,Desc=%s)\n", Dir.c_str(), Desc.c_str())); |
2707 |
|
LSCPResultSet result; |
2708 |
|
#if HAVE_SQLITE3 |
2709 |
|
try { |
2710 |
|
InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc); |
2711 |
|
} catch (Exception e) { |
2712 |
|
result.Error(e); |
2713 |
|
} |
2714 |
|
#else |
2715 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2716 |
|
#endif |
2717 |
|
return result.Produce(); |
2718 |
|
} |
2719 |
|
|
2720 |
|
String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index, bool bBackground) { |
2721 |
|
dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d,bBackground=%d)\n", DbDir.c_str(), FilePath.c_str(), Index, bBackground)); |
2722 |
|
LSCPResultSet result; |
2723 |
|
#if HAVE_SQLITE3 |
2724 |
|
try { |
2725 |
|
int id; |
2726 |
|
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
2727 |
|
id = db->AddInstruments(DbDir, FilePath, Index, bBackground); |
2728 |
|
if (bBackground) result = id; |
2729 |
|
} catch (Exception e) { |
2730 |
|
result.Error(e); |
2731 |
|
} |
2732 |
|
#else |
2733 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2734 |
|
#endif |
2735 |
|
return result.Produce(); |
2736 |
|
} |
2737 |
|
|
2738 |
|
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) { |
2739 |
|
dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground)); |
2740 |
|
LSCPResultSet result; |
2741 |
|
#if HAVE_SQLITE3 |
2742 |
|
try { |
2743 |
|
int id; |
2744 |
|
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
2745 |
|
if (ScanMode.compare("RECURSIVE") == 0) { |
2746 |
|
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground); |
2747 |
|
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
2748 |
|
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground); |
2749 |
|
} else if (ScanMode.compare("FLAT") == 0) { |
2750 |
|
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground); |
2751 |
|
} else { |
2752 |
|
throw Exception("Unknown scan mode: " + ScanMode); |
2753 |
|
} |
2754 |
|
|
2755 |
|
if (bBackground) result = id; |
2756 |
|
} catch (Exception e) { |
2757 |
|
result.Error(e); |
2758 |
|
} |
2759 |
|
#else |
2760 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2761 |
|
#endif |
2762 |
|
return result.Produce(); |
2763 |
|
} |
2764 |
|
|
2765 |
|
String LSCPServer::RemoveDbInstrument(String Instr) { |
2766 |
|
dmsg(2,("LSCPServer: RemoveDbInstrument(Instr=%s)\n", Instr.c_str())); |
2767 |
|
LSCPResultSet result; |
2768 |
|
#if HAVE_SQLITE3 |
2769 |
|
try { |
2770 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveInstrument(Instr); |
2771 |
|
} catch (Exception e) { |
2772 |
|
result.Error(e); |
2773 |
|
} |
2774 |
|
#else |
2775 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2776 |
|
#endif |
2777 |
|
return result.Produce(); |
2778 |
|
} |
2779 |
|
|
2780 |
|
String LSCPServer::GetDbInstrumentCount(String Dir, bool Recursive) { |
2781 |
|
dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2782 |
|
LSCPResultSet result; |
2783 |
|
#if HAVE_SQLITE3 |
2784 |
|
try { |
2785 |
|
result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir, Recursive)); |
2786 |
|
} catch (Exception e) { |
2787 |
|
result.Error(e); |
2788 |
|
} |
2789 |
|
#else |
2790 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2791 |
|
#endif |
2792 |
|
return result.Produce(); |
2793 |
|
} |
2794 |
|
|
2795 |
|
String LSCPServer::GetDbInstruments(String Dir, bool Recursive) { |
2796 |
|
dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2797 |
|
LSCPResultSet result; |
2798 |
|
#if HAVE_SQLITE3 |
2799 |
|
try { |
2800 |
|
String list; |
2801 |
|
StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir, Recursive); |
2802 |
|
|
2803 |
|
for (int i = 0; i < instrs->size(); i++) { |
2804 |
|
if (list != "") list += ","; |
2805 |
|
list += "'" + InstrumentsDb::toEscapedPath(instrs->at(i)) + "'"; |
2806 |
|
} |
2807 |
|
|
2808 |
|
result.Add(list); |
2809 |
|
} catch (Exception e) { |
2810 |
|
result.Error(e); |
2811 |
|
} |
2812 |
|
#else |
2813 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2814 |
|
#endif |
2815 |
|
return result.Produce(); |
2816 |
|
} |
2817 |
|
|
2818 |
|
String LSCPServer::GetDbInstrumentInfo(String Instr) { |
2819 |
|
dmsg(2,("LSCPServer: GetDbInstrumentInfo(Instr=%s)\n", Instr.c_str())); |
2820 |
|
LSCPResultSet result; |
2821 |
|
#if HAVE_SQLITE3 |
2822 |
|
try { |
2823 |
|
DbInstrument info = InstrumentsDb::GetInstrumentsDb()->GetInstrumentInfo(Instr); |
2824 |
|
|
2825 |
|
result.Add("INSTRUMENT_FILE", info.InstrFile); |
2826 |
|
result.Add("INSTRUMENT_NR", info.InstrNr); |
2827 |
|
result.Add("FORMAT_FAMILY", info.FormatFamily); |
2828 |
|
result.Add("FORMAT_VERSION", info.FormatVersion); |
2829 |
|
result.Add("SIZE", (int)info.Size); |
2830 |
|
result.Add("CREATED", info.Created); |
2831 |
|
result.Add("MODIFIED", info.Modified); |
2832 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(info.Description)); |
2833 |
|
result.Add("IS_DRUM", info.IsDrum); |
2834 |
|
result.Add("PRODUCT", _escapeLscpResponse(info.Product)); |
2835 |
|
result.Add("ARTISTS", _escapeLscpResponse(info.Artists)); |
2836 |
|
result.Add("KEYWORDS", _escapeLscpResponse(info.Keywords)); |
2837 |
|
} catch (Exception e) { |
2838 |
|
result.Error(e); |
2839 |
|
} |
2840 |
|
#else |
2841 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2842 |
|
#endif |
2843 |
|
return result.Produce(); |
2844 |
|
} |
2845 |
|
|
2846 |
|
String LSCPServer::GetDbInstrumentsJobInfo(int JobId) { |
2847 |
|
dmsg(2,("LSCPServer: GetDbInstrumentsJobInfo(JobId=%d)\n", JobId)); |
2848 |
|
LSCPResultSet result; |
2849 |
|
#if HAVE_SQLITE3 |
2850 |
|
try { |
2851 |
|
ScanJob job = InstrumentsDb::GetInstrumentsDb()->Jobs.GetJobById(JobId); |
2852 |
|
|
2853 |
|
result.Add("FILES_TOTAL", job.FilesTotal); |
2854 |
|
result.Add("FILES_SCANNED", job.FilesScanned); |
2855 |
|
result.Add("SCANNING", job.Scanning); |
2856 |
|
result.Add("STATUS", job.Status); |
2857 |
|
} catch (Exception e) { |
2858 |
|
result.Error(e); |
2859 |
|
} |
2860 |
|
#else |
2861 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2862 |
|
#endif |
2863 |
|
return result.Produce(); |
2864 |
|
} |
2865 |
|
|
2866 |
|
String LSCPServer::SetDbInstrumentName(String Instr, String Name) { |
2867 |
|
dmsg(2,("LSCPServer: SetDbInstrumentName(Instr=%s,Name=%s)\n", Instr.c_str(), Name.c_str())); |
2868 |
|
LSCPResultSet result; |
2869 |
|
#if HAVE_SQLITE3 |
2870 |
|
try { |
2871 |
|
InstrumentsDb::GetInstrumentsDb()->RenameInstrument(Instr, Name); |
2872 |
|
} catch (Exception e) { |
2873 |
|
result.Error(e); |
2874 |
|
} |
2875 |
|
#else |
2876 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2877 |
|
#endif |
2878 |
|
return result.Produce(); |
2879 |
|
} |
2880 |
|
|
2881 |
|
String LSCPServer::MoveDbInstrument(String Instr, String Dst) { |
2882 |
|
dmsg(2,("LSCPServer: MoveDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str())); |
2883 |
|
LSCPResultSet result; |
2884 |
|
#if HAVE_SQLITE3 |
2885 |
|
try { |
2886 |
|
InstrumentsDb::GetInstrumentsDb()->MoveInstrument(Instr, Dst); |
2887 |
|
} catch (Exception e) { |
2888 |
|
result.Error(e); |
2889 |
|
} |
2890 |
|
#else |
2891 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2892 |
|
#endif |
2893 |
|
return result.Produce(); |
2894 |
|
} |
2895 |
|
|
2896 |
|
String LSCPServer::CopyDbInstrument(String Instr, String Dst) { |
2897 |
|
dmsg(2,("LSCPServer: CopyDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str())); |
2898 |
|
LSCPResultSet result; |
2899 |
|
#if HAVE_SQLITE3 |
2900 |
|
try { |
2901 |
|
InstrumentsDb::GetInstrumentsDb()->CopyInstrument(Instr, Dst); |
2902 |
|
} catch (Exception e) { |
2903 |
|
result.Error(e); |
2904 |
|
} |
2905 |
|
#else |
2906 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2907 |
|
#endif |
2908 |
|
return result.Produce(); |
2909 |
|
} |
2910 |
|
|
2911 |
|
String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) { |
2912 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDescription(Instr=%s,Desc=%s)\n", Instr.c_str(), Desc.c_str())); |
2913 |
|
LSCPResultSet result; |
2914 |
|
#if HAVE_SQLITE3 |
2915 |
|
try { |
2916 |
|
InstrumentsDb::GetInstrumentsDb()->SetInstrumentDescription(Instr, Desc); |
2917 |
|
} catch (Exception e) { |
2918 |
|
result.Error(e); |
2919 |
|
} |
2920 |
|
#else |
2921 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2922 |
|
#endif |
2923 |
|
return result.Produce(); |
2924 |
|
} |
2925 |
|
|
2926 |
|
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
2927 |
|
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
2928 |
|
LSCPResultSet result; |
2929 |
|
#if HAVE_SQLITE3 |
2930 |
|
try { |
2931 |
|
SearchQuery Query; |
2932 |
|
std::map<String,String>::iterator iter; |
2933 |
|
for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { |
2934 |
|
if (iter->first.compare("NAME") == 0) { |
2935 |
|
Query.Name = iter->second; |
2936 |
|
} else if (iter->first.compare("CREATED") == 0) { |
2937 |
|
Query.SetCreated(iter->second); |
2938 |
|
} else if (iter->first.compare("MODIFIED") == 0) { |
2939 |
|
Query.SetModified(iter->second); |
2940 |
|
} else if (iter->first.compare("DESCRIPTION") == 0) { |
2941 |
|
Query.Description = iter->second; |
2942 |
|
} else { |
2943 |
|
throw Exception("Unknown search criteria: " + iter->first); |
2944 |
|
} |
2945 |
|
} |
2946 |
|
|
2947 |
|
String list; |
2948 |
|
StringListPtr pDirectories = |
2949 |
|
InstrumentsDb::GetInstrumentsDb()->FindDirectories(Dir, &Query, Recursive); |
2950 |
|
|
2951 |
|
for (int i = 0; i < pDirectories->size(); i++) { |
2952 |
|
if (list != "") list += ","; |
2953 |
|
list += "'" + InstrumentsDb::toEscapedPath(pDirectories->at(i)) + "'"; |
2954 |
|
} |
2955 |
|
|
2956 |
|
result.Add(list); |
2957 |
|
} catch (Exception e) { |
2958 |
|
result.Error(e); |
2959 |
|
} |
2960 |
|
#else |
2961 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2962 |
|
#endif |
2963 |
|
return result.Produce(); |
2964 |
|
} |
2965 |
|
|
2966 |
|
String LSCPServer::FindDbInstruments(String Dir, std::map<String,String> Parameters, bool Recursive) { |
2967 |
|
dmsg(2,("LSCPServer: FindDbInstruments(Dir=%s)\n", Dir.c_str())); |
2968 |
|
LSCPResultSet result; |
2969 |
|
#if HAVE_SQLITE3 |
2970 |
|
try { |
2971 |
|
SearchQuery Query; |
2972 |
|
std::map<String,String>::iterator iter; |
2973 |
|
for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { |
2974 |
|
if (iter->first.compare("NAME") == 0) { |
2975 |
|
Query.Name = iter->second; |
2976 |
|
} else if (iter->first.compare("FORMAT_FAMILIES") == 0) { |
2977 |
|
Query.SetFormatFamilies(iter->second); |
2978 |
|
} else if (iter->first.compare("SIZE") == 0) { |
2979 |
|
Query.SetSize(iter->second); |
2980 |
|
} else if (iter->first.compare("CREATED") == 0) { |
2981 |
|
Query.SetCreated(iter->second); |
2982 |
|
} else if (iter->first.compare("MODIFIED") == 0) { |
2983 |
|
Query.SetModified(iter->second); |
2984 |
|
} else if (iter->first.compare("DESCRIPTION") == 0) { |
2985 |
|
Query.Description = iter->second; |
2986 |
|
} else if (iter->first.compare("IS_DRUM") == 0) { |
2987 |
|
if (!strcasecmp(iter->second.c_str(), "true")) { |
2988 |
|
Query.InstrType = SearchQuery::DRUM; |
2989 |
|
} else { |
2990 |
|
Query.InstrType = SearchQuery::CHROMATIC; |
2991 |
|
} |
2992 |
|
} else if (iter->first.compare("PRODUCT") == 0) { |
2993 |
|
Query.Product = iter->second; |
2994 |
|
} else if (iter->first.compare("ARTISTS") == 0) { |
2995 |
|
Query.Artists = iter->second; |
2996 |
|
} else if (iter->first.compare("KEYWORDS") == 0) { |
2997 |
|
Query.Keywords = iter->second; |
2998 |
|
} else { |
2999 |
|
throw Exception("Unknown search criteria: " + iter->first); |
3000 |
|
} |
3001 |
|
} |
3002 |
|
|
3003 |
|
String list; |
3004 |
|
StringListPtr pInstruments = |
3005 |
|
InstrumentsDb::GetInstrumentsDb()->FindInstruments(Dir, &Query, Recursive); |
3006 |
|
|
3007 |
|
for (int i = 0; i < pInstruments->size(); i++) { |
3008 |
|
if (list != "") list += ","; |
3009 |
|
list += "'" + InstrumentsDb::toEscapedPath(pInstruments->at(i)) + "'"; |
3010 |
|
} |
3011 |
|
|
3012 |
|
result.Add(list); |
3013 |
|
} catch (Exception e) { |
3014 |
|
result.Error(e); |
3015 |
|
} |
3016 |
|
#else |
3017 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3018 |
|
#endif |
3019 |
|
return result.Produce(); |
3020 |
|
} |
3021 |
|
|
3022 |
|
String LSCPServer::FormatInstrumentsDb() { |
3023 |
|
dmsg(2,("LSCPServer: FormatInstrumentsDb()\n")); |
3024 |
|
LSCPResultSet result; |
3025 |
|
#if HAVE_SQLITE3 |
3026 |
|
try { |
3027 |
|
InstrumentsDb::GetInstrumentsDb()->Format(); |
3028 |
|
} catch (Exception e) { |
3029 |
|
result.Error(e); |
3030 |
|
} |
3031 |
|
#else |
3032 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3033 |
|
#endif |
3034 |
|
return result.Produce(); |
3035 |
|
} |
3036 |
|
|
3037 |
|
|
3038 |
/** |
/** |
3039 |
* 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 |
3040 |
* mode is enabled, all commands from the client will (immediately) be |
* mode is enabled, all commands from the client will (immediately) be |