3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005, 2006 Christian Schoenebeck * |
* Copyright (C) 2005 - 2007 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This library is free software; you can redistribute it and/or modify * |
* This library is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
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> >(); |
66 |
SocketAddress.sin_addr.s_addr = addr; |
SocketAddress.sin_addr.s_addr = addr; |
67 |
SocketAddress.sin_port = port; |
SocketAddress.sin_port = port; |
68 |
this->pSampler = pSampler; |
this->pSampler = pSampler; |
69 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_count, "AUDIO_OUTPUT_DEVICE_COUNT"); |
70 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_info, "AUDIO_OUTPUT_DEVICE_INFO"); |
71 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_device_count, "MIDI_INPUT_DEVICE_COUNT"); |
72 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_device_info, "MIDI_INPUT_DEVICE_INFO"); |
73 |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT"); |
74 |
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
75 |
LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT"); |
76 |
LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL"); |
77 |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO"); |
78 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_fx_send_count, "FX_SEND_COUNT"); |
79 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_fx_send_info, "FX_SEND_INFO"); |
80 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_count, "MIDI_INSTRUMENT_MAP_COUNT"); |
81 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO"); |
82 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT"); |
83 |
|
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"); |
92 |
hSocket = -1; |
hSocket = -1; |
93 |
} |
} |
94 |
|
|
96 |
if (hSocket >= 0) close(hSocket); |
if (hSocket >= 0) close(hSocket); |
97 |
} |
} |
98 |
|
|
99 |
|
void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) { |
100 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount)); |
101 |
|
} |
102 |
|
|
103 |
|
void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) { |
104 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount)); |
105 |
|
} |
106 |
|
|
107 |
|
void LSCPServer::EventHandler::MidiDeviceCountChanged(int NewCount) { |
108 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount)); |
109 |
|
} |
110 |
|
|
111 |
|
void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) { |
112 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount)); |
113 |
|
} |
114 |
|
|
115 |
|
void LSCPServer::EventHandler::MidiInstrumentInfoChanged(int MapId, int Bank, int Program) { |
116 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_info, MapId, Bank, Program)); |
117 |
|
} |
118 |
|
|
119 |
|
void LSCPServer::EventHandler::MidiInstrumentMapCountChanged(int NewCount) { |
120 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_count, NewCount)); |
121 |
|
} |
122 |
|
|
123 |
|
void LSCPServer::EventHandler::MidiInstrumentMapInfoChanged(int MapId) { |
124 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_info, MapId)); |
125 |
|
} |
126 |
|
|
127 |
|
void LSCPServer::EventHandler::FxSendCountChanged(int ChannelId, int NewCount) { |
128 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_count, ChannelId, NewCount)); |
129 |
|
} |
130 |
|
|
131 |
|
void LSCPServer::EventHandler::VoiceCountChanged(int ChannelId, int NewCount) { |
132 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_voice_count, ChannelId, NewCount)); |
133 |
|
} |
134 |
|
|
135 |
|
void LSCPServer::EventHandler::StreamCountChanged(int ChannelId, int NewCount) { |
136 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_stream_count, ChannelId, NewCount)); |
137 |
|
} |
138 |
|
|
139 |
|
void LSCPServer::EventHandler::BufferFillChanged(int ChannelId, String FillData) { |
140 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_buffer_fill, ChannelId, FillData)); |
141 |
|
} |
142 |
|
|
143 |
|
void LSCPServer::EventHandler::TotalVoiceCountChanged(int NewCount) { |
144 |
|
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 |
184 |
* accepting socket connections, if the server is already initialized then |
* accepting socket connections, if the server is already initialized then |
220 |
listen(hSocket, 1); |
listen(hSocket, 1); |
221 |
Initialized.Set(true); |
Initialized.Set(true); |
222 |
|
|
223 |
|
// Registering event listeners |
224 |
|
pSampler->AddChannelCountListener(&eventHandler); |
225 |
|
pSampler->AddAudioDeviceCountListener(&eventHandler); |
226 |
|
pSampler->AddMidiDeviceCountListener(&eventHandler); |
227 |
|
pSampler->AddVoiceCountListener(&eventHandler); |
228 |
|
pSampler->AddStreamCountListener(&eventHandler); |
229 |
|
pSampler->AddBufferFillListener(&eventHandler); |
230 |
|
pSampler->AddTotalVoiceCountListener(&eventHandler); |
231 |
|
pSampler->AddFxSendCountListener(&eventHandler); |
232 |
|
MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler); |
233 |
|
MidiInstrumentMapper::AddMidiInstrumentInfoListener(&eventHandler); |
234 |
|
MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&eventHandler); |
235 |
|
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); |
255 |
if ((*itEngineChannel)->StatusChanged()) { |
if ((*itEngineChannel)->StatusChanged()) { |
256 |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
257 |
} |
} |
258 |
|
|
259 |
|
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
260 |
|
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
261 |
|
if(fxs != NULL && fxs->IsInfoChanged()) { |
262 |
|
int chn = (*itEngineChannel)->iSamplerChannelIndex; |
263 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id())); |
264 |
|
fxs->SetInfoChanged(false); |
265 |
|
} |
266 |
|
} |
267 |
} |
} |
268 |
} |
} |
269 |
|
|
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 |
*/ |
*/ |
636 |
if (!pSamplerChannel->GetAudioOutputDevice()) |
if (!pSamplerChannel->GetAudioOutputDevice()) |
637 |
throw Exception("No audio output device connected to sampler channel"); |
throw Exception("No audio output device connected to sampler channel"); |
638 |
if (bBackground) { |
if (bBackground) { |
639 |
InstrumentLoader.StartNewLoad(Filename, uiInstrument, pEngineChannel); |
InstrumentManager::instrument_id_t id; |
640 |
|
id.FileName = Filename; |
641 |
|
id.Index = uiInstrument; |
642 |
|
InstrumentManager::LoadInstrumentInBackground(id, pEngineChannel); |
643 |
} |
} |
644 |
else { |
else { |
645 |
// tell the engine channel which instrument to load |
// tell the engine channel which instrument to load |
802 |
String AudioRouting; |
String AudioRouting; |
803 |
int Mute = 0; |
int Mute = 0; |
804 |
bool Solo = false; |
bool Solo = false; |
805 |
|
String MidiInstrumentMap = "NONE"; |
806 |
|
|
807 |
if (pEngineChannel) { |
if (pEngineChannel) { |
808 |
EngineName = pEngineChannel->EngineName(); |
EngineName = pEngineChannel->EngineName(); |
820 |
} |
} |
821 |
Mute = pEngineChannel->GetMute(); |
Mute = pEngineChannel->GetMute(); |
822 |
Solo = pEngineChannel->GetSolo(); |
Solo = pEngineChannel->GetSolo(); |
823 |
|
if (pEngineChannel->UsesNoMidiInstrumentMap()) |
824 |
|
MidiInstrumentMap = "NONE"; |
825 |
|
else if (pEngineChannel->UsesDefaultMidiInstrumentMap()) |
826 |
|
MidiInstrumentMap = "DEFAULT"; |
827 |
|
else |
828 |
|
MidiInstrumentMap = ToString(pEngineChannel->GetMidiInstrumentMap()); |
829 |
} |
} |
830 |
|
|
831 |
result.Add("ENGINE_NAME", EngineName); |
result.Add("ENGINE_NAME", EngineName); |
847 |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
848 |
result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false")); |
result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false")); |
849 |
result.Add("SOLO", Solo); |
result.Add("SOLO", Solo); |
850 |
|
result.Add("MIDI_INSTRUMENT_MAP", MidiInstrumentMap); |
851 |
} |
} |
852 |
catch (Exception e) { |
catch (Exception e) { |
853 |
result.Error(e); |
result.Error(e); |
1325 |
|
|
1326 |
// set new channel parameter value |
// set new channel parameter value |
1327 |
pParameter->SetValue(ParamVal); |
pParameter->SetValue(ParamVal); |
1328 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceId)); |
1329 |
} |
} |
1330 |
catch (Exception e) { |
catch (Exception e) { |
1331 |
result.Error(e); |
result.Error(e); |
1343 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1344 |
if (!parameters.count(ParamKey)) throw Exception("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
if (!parameters.count(ParamKey)) throw Exception("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
1345 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1346 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceIndex)); |
1347 |
} |
} |
1348 |
catch (Exception e) { |
catch (Exception e) { |
1349 |
result.Error(e); |
result.Error(e); |
1361 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1362 |
if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
1363 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1364 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex)); |
1365 |
} |
} |
1366 |
catch (Exception e) { |
catch (Exception e) { |
1367 |
result.Error(e); |
result.Error(e); |
1386 |
std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters(); |
std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters(); |
1387 |
if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); |
if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); |
1388 |
parameters[ParamKey]->SetValue(ParamVal); |
parameters[ParamKey]->SetValue(ParamVal); |
1389 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex)); |
1390 |
} |
} |
1391 |
catch (Exception e) { |
catch (Exception e) { |
1392 |
result.Error(e); |
result.Error(e); |
1634 |
|
|
1635 |
bool oldSolo = pEngineChannel->GetSolo(); |
bool oldSolo = pEngineChannel->GetSolo(); |
1636 |
bool hadSoloChannel = HasSoloChannel(); |
bool hadSoloChannel = HasSoloChannel(); |
1637 |
|
|
1638 |
pEngineChannel->SetSolo(bSolo); |
pEngineChannel->SetSolo(bSolo); |
1639 |
|
|
1640 |
if(!oldSolo && bSolo) { |
if(!oldSolo && bSolo) { |
1641 |
if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0); |
if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0); |
1642 |
if(!hadSoloChannel) MuteNonSoloChannels(); |
if(!hadSoloChannel) MuteNonSoloChannels(); |
1643 |
} |
} |
1644 |
|
|
1645 |
if(oldSolo && !bSolo) { |
if(oldSolo && !bSolo) { |
1646 |
if(!HasSoloChannel()) UnmuteChannels(); |
if(!HasSoloChannel()) UnmuteChannels(); |
1647 |
else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1); |
else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1); |
1699 |
} |
} |
1700 |
} |
} |
1701 |
|
|
1702 |
|
String LSCPServer::AddOrReplaceMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg, String EngineType, String InstrumentFile, uint InstrumentIndex, float Volume, MidiInstrumentMapper::mode_t LoadMode, String Name, bool bModal) { |
1703 |
|
dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n")); |
1704 |
|
|
1705 |
|
midi_prog_index_t idx; |
1706 |
|
idx.midi_bank_msb = (MidiBank >> 7) & 0x7f; |
1707 |
|
idx.midi_bank_lsb = MidiBank & 0x7f; |
1708 |
|
idx.midi_prog = MidiProg; |
1709 |
|
|
1710 |
|
MidiInstrumentMapper::entry_t entry; |
1711 |
|
entry.EngineName = EngineType; |
1712 |
|
entry.InstrumentFile = InstrumentFile; |
1713 |
|
entry.InstrumentIndex = InstrumentIndex; |
1714 |
|
entry.LoadMode = LoadMode; |
1715 |
|
entry.Volume = Volume; |
1716 |
|
entry.Name = Name; |
1717 |
|
|
1718 |
|
LSCPResultSet result; |
1719 |
|
try { |
1720 |
|
// PERSISTENT mapping commands might block for a long time, so in |
1721 |
|
// that case we add/replace the mapping in another thread in case |
1722 |
|
// the NON_MODAL argument was supplied, non persistent mappings |
1723 |
|
// should return immediately, so we don't need to do that for them |
1724 |
|
bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT && !bModal); |
1725 |
|
MidiInstrumentMapper::AddOrReplaceEntry(MidiMapID, idx, entry, bInBackground); |
1726 |
|
} catch (Exception e) { |
1727 |
|
result.Error(e); |
1728 |
|
} |
1729 |
|
return result.Produce(); |
1730 |
|
} |
1731 |
|
|
1732 |
|
String LSCPServer::RemoveMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) { |
1733 |
|
dmsg(2,("LSCPServer: RemoveMIDIInstrumentMapping()\n")); |
1734 |
|
|
1735 |
|
midi_prog_index_t idx; |
1736 |
|
idx.midi_bank_msb = (MidiBank >> 7) & 0x7f; |
1737 |
|
idx.midi_bank_lsb = MidiBank & 0x7f; |
1738 |
|
idx.midi_prog = MidiProg; |
1739 |
|
|
1740 |
|
LSCPResultSet result; |
1741 |
|
try { |
1742 |
|
MidiInstrumentMapper::RemoveEntry(MidiMapID, idx); |
1743 |
|
} catch (Exception e) { |
1744 |
|
result.Error(e); |
1745 |
|
} |
1746 |
|
return result.Produce(); |
1747 |
|
} |
1748 |
|
|
1749 |
|
String LSCPServer::GetMidiInstrumentMappings(uint MidiMapID) { |
1750 |
|
dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n")); |
1751 |
|
LSCPResultSet result; |
1752 |
|
try { |
1753 |
|
result.Add(MidiInstrumentMapper::Entries(MidiMapID).size()); |
1754 |
|
} catch (Exception e) { |
1755 |
|
result.Error(e); |
1756 |
|
} |
1757 |
|
return result.Produce(); |
1758 |
|
} |
1759 |
|
|
1760 |
|
|
1761 |
|
String LSCPServer::GetAllMidiInstrumentMappings() { |
1762 |
|
dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n")); |
1763 |
|
LSCPResultSet result; |
1764 |
|
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
1765 |
|
int totalMappings = 0; |
1766 |
|
for (int i = 0; i < maps.size(); i++) { |
1767 |
|
try { |
1768 |
|
totalMappings += MidiInstrumentMapper::Entries(maps[i]).size(); |
1769 |
|
} catch (Exception e) { /*NOOP*/ } |
1770 |
|
} |
1771 |
|
result.Add(totalMappings); |
1772 |
|
return result.Produce(); |
1773 |
|
} |
1774 |
|
|
1775 |
|
String LSCPServer::GetMidiInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) { |
1776 |
|
dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n")); |
1777 |
|
LSCPResultSet result; |
1778 |
|
try { |
1779 |
|
midi_prog_index_t idx; |
1780 |
|
idx.midi_bank_msb = (MidiBank >> 7) & 0x7f; |
1781 |
|
idx.midi_bank_lsb = MidiBank & 0x7f; |
1782 |
|
idx.midi_prog = MidiProg; |
1783 |
|
|
1784 |
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID); |
1785 |
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx); |
1786 |
|
if (iter == mappings.end()) result.Error("there is no map entry with that index"); |
1787 |
|
else { // found |
1788 |
|
result.Add("NAME", iter->second.Name); |
1789 |
|
result.Add("ENGINE_NAME", iter->second.EngineName); |
1790 |
|
result.Add("INSTRUMENT_FILE", iter->second.InstrumentFile); |
1791 |
|
result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex); |
1792 |
|
String instrumentName; |
1793 |
|
Engine* pEngine = EngineFactory::Create(iter->second.EngineName); |
1794 |
|
if (pEngine) { |
1795 |
|
if (pEngine->GetInstrumentManager()) { |
1796 |
|
InstrumentManager::instrument_id_t instrID; |
1797 |
|
instrID.FileName = iter->second.InstrumentFile; |
1798 |
|
instrID.Index = iter->second.InstrumentIndex; |
1799 |
|
instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID); |
1800 |
|
} |
1801 |
|
EngineFactory::Destroy(pEngine); |
1802 |
|
} |
1803 |
|
result.Add("INSTRUMENT_NAME", instrumentName); |
1804 |
|
switch (iter->second.LoadMode) { |
1805 |
|
case MidiInstrumentMapper::ON_DEMAND: |
1806 |
|
result.Add("LOAD_MODE", "ON_DEMAND"); |
1807 |
|
break; |
1808 |
|
case MidiInstrumentMapper::ON_DEMAND_HOLD: |
1809 |
|
result.Add("LOAD_MODE", "ON_DEMAND_HOLD"); |
1810 |
|
break; |
1811 |
|
case MidiInstrumentMapper::PERSISTENT: |
1812 |
|
result.Add("LOAD_MODE", "PERSISTENT"); |
1813 |
|
break; |
1814 |
|
default: |
1815 |
|
throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!"); |
1816 |
|
} |
1817 |
|
result.Add("VOLUME", iter->second.Volume); |
1818 |
|
} |
1819 |
|
} catch (Exception e) { |
1820 |
|
result.Error(e); |
1821 |
|
} |
1822 |
|
return result.Produce(); |
1823 |
|
} |
1824 |
|
|
1825 |
|
String LSCPServer::ListMidiInstrumentMappings(uint MidiMapID) { |
1826 |
|
dmsg(2,("LSCPServer: ListMidiInstrumentMappings()\n")); |
1827 |
|
LSCPResultSet result; |
1828 |
|
try { |
1829 |
|
String s; |
1830 |
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID); |
1831 |
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin(); |
1832 |
|
for (; iter != mappings.end(); iter++) { |
1833 |
|
if (s.size()) s += ","; |
1834 |
|
s += "{" + ToString(MidiMapID) + "," |
1835 |
|
+ ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + "," |
1836 |
|
+ ToString(int(iter->first.midi_prog)) + "}"; |
1837 |
|
} |
1838 |
|
result.Add(s); |
1839 |
|
} catch (Exception e) { |
1840 |
|
result.Error(e); |
1841 |
|
} |
1842 |
|
return result.Produce(); |
1843 |
|
} |
1844 |
|
|
1845 |
|
String LSCPServer::ListAllMidiInstrumentMappings() { |
1846 |
|
dmsg(2,("LSCPServer: ListAllMidiInstrumentMappings()\n")); |
1847 |
|
LSCPResultSet result; |
1848 |
|
try { |
1849 |
|
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
1850 |
|
String s; |
1851 |
|
for (int i = 0; i < maps.size(); i++) { |
1852 |
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(maps[i]); |
1853 |
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin(); |
1854 |
|
for (; iter != mappings.end(); iter++) { |
1855 |
|
if (s.size()) s += ","; |
1856 |
|
s += "{" + ToString(maps[i]) + "," |
1857 |
|
+ ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + "," |
1858 |
|
+ ToString(int(iter->first.midi_prog)) + "}"; |
1859 |
|
} |
1860 |
|
} |
1861 |
|
result.Add(s); |
1862 |
|
} catch (Exception e) { |
1863 |
|
result.Error(e); |
1864 |
|
} |
1865 |
|
return result.Produce(); |
1866 |
|
} |
1867 |
|
|
1868 |
|
String LSCPServer::ClearMidiInstrumentMappings(uint MidiMapID) { |
1869 |
|
dmsg(2,("LSCPServer: ClearMidiInstrumentMappings()\n")); |
1870 |
|
LSCPResultSet result; |
1871 |
|
try { |
1872 |
|
MidiInstrumentMapper::RemoveAllEntries(MidiMapID); |
1873 |
|
} catch (Exception e) { |
1874 |
|
result.Error(e); |
1875 |
|
} |
1876 |
|
return result.Produce(); |
1877 |
|
} |
1878 |
|
|
1879 |
|
String LSCPServer::ClearAllMidiInstrumentMappings() { |
1880 |
|
dmsg(2,("LSCPServer: ClearAllMidiInstrumentMappings()\n")); |
1881 |
|
LSCPResultSet result; |
1882 |
|
try { |
1883 |
|
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
1884 |
|
for (int i = 0; i < maps.size(); i++) |
1885 |
|
MidiInstrumentMapper::RemoveAllEntries(maps[i]); |
1886 |
|
} catch (Exception e) { |
1887 |
|
result.Error(e); |
1888 |
|
} |
1889 |
|
return result.Produce(); |
1890 |
|
} |
1891 |
|
|
1892 |
|
String LSCPServer::AddMidiInstrumentMap(String MapName) { |
1893 |
|
dmsg(2,("LSCPServer: AddMidiInstrumentMap()\n")); |
1894 |
|
LSCPResultSet result; |
1895 |
|
try { |
1896 |
|
int MapID = MidiInstrumentMapper::AddMap(MapName); |
1897 |
|
result = LSCPResultSet(MapID); |
1898 |
|
} catch (Exception e) { |
1899 |
|
result.Error(e); |
1900 |
|
} |
1901 |
|
return result.Produce(); |
1902 |
|
} |
1903 |
|
|
1904 |
|
String LSCPServer::RemoveMidiInstrumentMap(uint MidiMapID) { |
1905 |
|
dmsg(2,("LSCPServer: RemoveMidiInstrumentMap()\n")); |
1906 |
|
LSCPResultSet result; |
1907 |
|
try { |
1908 |
|
MidiInstrumentMapper::RemoveMap(MidiMapID); |
1909 |
|
} catch (Exception e) { |
1910 |
|
result.Error(e); |
1911 |
|
} |
1912 |
|
return result.Produce(); |
1913 |
|
} |
1914 |
|
|
1915 |
|
String LSCPServer::RemoveAllMidiInstrumentMaps() { |
1916 |
|
dmsg(2,("LSCPServer: RemoveAllMidiInstrumentMaps()\n")); |
1917 |
|
LSCPResultSet result; |
1918 |
|
try { |
1919 |
|
MidiInstrumentMapper::RemoveAllMaps(); |
1920 |
|
} catch (Exception e) { |
1921 |
|
result.Error(e); |
1922 |
|
} |
1923 |
|
return result.Produce(); |
1924 |
|
} |
1925 |
|
|
1926 |
|
String LSCPServer::GetMidiInstrumentMaps() { |
1927 |
|
dmsg(2,("LSCPServer: GetMidiInstrumentMaps()\n")); |
1928 |
|
LSCPResultSet result; |
1929 |
|
try { |
1930 |
|
result.Add(MidiInstrumentMapper::Maps().size()); |
1931 |
|
} catch (Exception e) { |
1932 |
|
result.Error(e); |
1933 |
|
} |
1934 |
|
return result.Produce(); |
1935 |
|
} |
1936 |
|
|
1937 |
|
String LSCPServer::ListMidiInstrumentMaps() { |
1938 |
|
dmsg(2,("LSCPServer: ListMidiInstrumentMaps()\n")); |
1939 |
|
LSCPResultSet result; |
1940 |
|
try { |
1941 |
|
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
1942 |
|
String sList; |
1943 |
|
for (int i = 0; i < maps.size(); i++) { |
1944 |
|
if (sList != "") sList += ","; |
1945 |
|
sList += ToString(maps[i]); |
1946 |
|
} |
1947 |
|
result.Add(sList); |
1948 |
|
} catch (Exception e) { |
1949 |
|
result.Error(e); |
1950 |
|
} |
1951 |
|
return result.Produce(); |
1952 |
|
} |
1953 |
|
|
1954 |
|
String LSCPServer::GetMidiInstrumentMap(uint MidiMapID) { |
1955 |
|
dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n")); |
1956 |
|
LSCPResultSet result; |
1957 |
|
try { |
1958 |
|
result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID)); |
1959 |
|
result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID); |
1960 |
|
} catch (Exception e) { |
1961 |
|
result.Error(e); |
1962 |
|
} |
1963 |
|
return result.Produce(); |
1964 |
|
} |
1965 |
|
|
1966 |
|
String LSCPServer::SetMidiInstrumentMapName(uint MidiMapID, String NewName) { |
1967 |
|
dmsg(2,("LSCPServer: SetMidiInstrumentMapName()\n")); |
1968 |
|
LSCPResultSet result; |
1969 |
|
try { |
1970 |
|
MidiInstrumentMapper::RenameMap(MidiMapID, NewName); |
1971 |
|
} catch (Exception e) { |
1972 |
|
result.Error(e); |
1973 |
|
} |
1974 |
|
return result.Produce(); |
1975 |
|
} |
1976 |
|
|
1977 |
|
/** |
1978 |
|
* Set the MIDI instrument map the given sampler channel shall use for |
1979 |
|
* handling MIDI program change messages. There are the following two |
1980 |
|
* special (negative) values: |
1981 |
|
* |
1982 |
|
* - (-1) : set to NONE (ignore program changes) |
1983 |
|
* - (-2) : set to DEFAULT map |
1984 |
|
*/ |
1985 |
|
String LSCPServer::SetChannelMap(uint uiSamplerChannel, int MidiMapID) { |
1986 |
|
dmsg(2,("LSCPServer: SetChannelMap()\n")); |
1987 |
|
LSCPResultSet result; |
1988 |
|
try { |
1989 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1990 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1991 |
|
|
1992 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1993 |
|
if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); |
1994 |
|
|
1995 |
|
if (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone(); |
1996 |
|
else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault(); |
1997 |
|
else pEngineChannel->SetMidiInstrumentMap(MidiMapID); |
1998 |
|
} catch (Exception e) { |
1999 |
|
result.Error(e); |
2000 |
|
} |
2001 |
|
return result.Produce(); |
2002 |
|
} |
2003 |
|
|
2004 |
|
String LSCPServer::CreateFxSend(uint uiSamplerChannel, uint MidiCtrl, String Name) { |
2005 |
|
dmsg(2,("LSCPServer: CreateFxSend()\n")); |
2006 |
|
LSCPResultSet result; |
2007 |
|
try { |
2008 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2009 |
|
|
2010 |
|
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)"); |
2012 |
|
|
2013 |
|
result = LSCPResultSet(pFxSend->Id()); // success |
2014 |
|
} catch (Exception e) { |
2015 |
|
result.Error(e); |
2016 |
|
} |
2017 |
|
return result.Produce(); |
2018 |
|
} |
2019 |
|
|
2020 |
|
String LSCPServer::DestroyFxSend(uint uiSamplerChannel, uint FxSendID) { |
2021 |
|
dmsg(2,("LSCPServer: DestroyFxSend()\n")); |
2022 |
|
LSCPResultSet result; |
2023 |
|
try { |
2024 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2025 |
|
|
2026 |
|
FxSend* pFxSend = NULL; |
2027 |
|
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
2028 |
|
if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) { |
2029 |
|
pFxSend = pEngineChannel->GetFxSend(i); |
2030 |
|
break; |
2031 |
|
} |
2032 |
|
} |
2033 |
|
if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel"); |
2034 |
|
pEngineChannel->RemoveFxSend(pFxSend); |
2035 |
|
} catch (Exception e) { |
2036 |
|
result.Error(e); |
2037 |
|
} |
2038 |
|
return result.Produce(); |
2039 |
|
} |
2040 |
|
|
2041 |
|
String LSCPServer::GetFxSends(uint uiSamplerChannel) { |
2042 |
|
dmsg(2,("LSCPServer: GetFxSends()\n")); |
2043 |
|
LSCPResultSet result; |
2044 |
|
try { |
2045 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2046 |
|
|
2047 |
|
result.Add(pEngineChannel->GetFxSendCount()); |
2048 |
|
} catch (Exception e) { |
2049 |
|
result.Error(e); |
2050 |
|
} |
2051 |
|
return result.Produce(); |
2052 |
|
} |
2053 |
|
|
2054 |
|
String LSCPServer::ListFxSends(uint uiSamplerChannel) { |
2055 |
|
dmsg(2,("LSCPServer: ListFxSends()\n")); |
2056 |
|
LSCPResultSet result; |
2057 |
|
String list; |
2058 |
|
try { |
2059 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2060 |
|
|
2061 |
|
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
2062 |
|
FxSend* pFxSend = pEngineChannel->GetFxSend(i); |
2063 |
|
if (list != "") list += ","; |
2064 |
|
list += ToString(pFxSend->Id()); |
2065 |
|
} |
2066 |
|
result.Add(list); |
2067 |
|
} catch (Exception e) { |
2068 |
|
result.Error(e); |
2069 |
|
} |
2070 |
|
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) { |
2088 |
|
dmsg(2,("LSCPServer: GetFxSendInfo()\n")); |
2089 |
|
LSCPResultSet result; |
2090 |
|
try { |
2091 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2092 |
|
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2093 |
|
|
2094 |
|
// gather audio routing informations |
2095 |
|
String AudioRouting; |
2096 |
|
for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { |
2097 |
|
if (AudioRouting != "") AudioRouting += ","; |
2098 |
|
AudioRouting += ToString(pFxSend->DestinationChannel(chan)); |
2099 |
|
} |
2100 |
|
|
2101 |
|
// success |
2102 |
|
result.Add("NAME", pFxSend->Name()); |
2103 |
|
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
2104 |
|
result.Add("LEVEL", ToString(pFxSend->Level())); |
2105 |
|
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
2106 |
|
} catch (Exception e) { |
2107 |
|
result.Error(e); |
2108 |
|
} |
2109 |
|
return result.Produce(); |
2110 |
|
} |
2111 |
|
|
2112 |
|
String LSCPServer::SetFxSendName(uint uiSamplerChannel, uint FxSendID, String Name) { |
2113 |
|
dmsg(2,("LSCPServer: SetFxSendName()\n")); |
2114 |
|
LSCPResultSet result; |
2115 |
|
try { |
2116 |
|
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2117 |
|
|
2118 |
|
pFxSend->SetName(Name); |
2119 |
|
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 |
|
String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) { |
2127 |
|
dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n")); |
2128 |
|
LSCPResultSet result; |
2129 |
|
try { |
2130 |
|
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2131 |
|
|
2132 |
|
pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel); |
2133 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2134 |
|
} catch (Exception e) { |
2135 |
|
result.Error(e); |
2136 |
|
} |
2137 |
|
return result.Produce(); |
2138 |
|
} |
2139 |
|
|
2140 |
|
String LSCPServer::SetFxSendMidiController(uint uiSamplerChannel, uint FxSendID, uint MidiController) { |
2141 |
|
dmsg(2,("LSCPServer: SetFxSendMidiController()\n")); |
2142 |
|
LSCPResultSet result; |
2143 |
|
try { |
2144 |
|
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2145 |
|
|
2146 |
|
pFxSend->SetMidiController(MidiController); |
2147 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2148 |
|
} catch (Exception e) { |
2149 |
|
result.Error(e); |
2150 |
|
} |
2151 |
|
return result.Produce(); |
2152 |
|
} |
2153 |
|
|
2154 |
|
String LSCPServer::SetFxSendLevel(uint uiSamplerChannel, uint FxSendID, double dLevel) { |
2155 |
|
dmsg(2,("LSCPServer: SetFxSendLevel()\n")); |
2156 |
|
LSCPResultSet result; |
2157 |
|
try { |
2158 |
|
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2159 |
|
|
2160 |
|
pFxSend->SetLevel((float)dLevel); |
2161 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2162 |
|
} catch (Exception e) { |
2163 |
|
result.Error(e); |
2164 |
|
} |
2165 |
|
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 |
|
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
2177 |
|
Engine* pEngine = pEngineChannel->GetEngine(); |
2178 |
|
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
2179 |
|
if (!pInstrumentManager) throw Exception("Engine does not provide an instrument manager"); |
2180 |
|
InstrumentManager::instrument_id_t instrumentID; |
2181 |
|
instrumentID.FileName = pEngineChannel->InstrumentFileName(); |
2182 |
|
instrumentID.Index = pEngineChannel->InstrumentIndex(); |
2183 |
|
pInstrumentManager->LaunchInstrumentEditor(instrumentID); |
2184 |
|
} catch (Exception e) { |
2185 |
|
result.Error(e); |
2186 |
|
} |
2187 |
|
return result.Produce(); |
2188 |
|
} |
2189 |
|
|
2190 |
/** |
/** |
2191 |
* Will be called by the parser to reset a particular sampler channel. |
* Will be called by the parser to reset a particular sampler channel. |
2192 |
*/ |
*/ |
2225 |
LSCPResultSet result; |
LSCPResultSet result; |
2226 |
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
2227 |
result.Add("VERSION", VERSION); |
result.Add("VERSION", VERSION); |
2228 |
result.Add("PROTOCOL_VERSION", "1.0"); |
result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR)); |
2229 |
|
#if HAVE_SQLITE3 |
2230 |
|
result.Add("INSTRUMENTS_DB_SUPPORT", "yes"); |
2231 |
|
#else |
2232 |
|
result.Add("INSTRUMENTS_DB_SUPPORT", "no"); |
2233 |
|
#endif |
2234 |
|
|
2235 |
return result.Produce(); |
return result.Produce(); |
2236 |
} |
} |
2237 |
|
|
2255 |
return result.Produce(); |
return result.Produce(); |
2256 |
} |
} |
2257 |
|
|
2258 |
|
String LSCPServer::GetGlobalVolume() { |
2259 |
|
LSCPResultSet result; |
2260 |
|
result.Add(ToString(GLOBAL_VOLUME)); // see common/global.cpp |
2261 |
|
return result.Produce(); |
2262 |
|
} |
2263 |
|
|
2264 |
|
String LSCPServer::SetGlobalVolume(double dVolume) { |
2265 |
|
LSCPResultSet result; |
2266 |
|
try { |
2267 |
|
if (dVolume < 0) throw Exception("Volume may not be negative"); |
2268 |
|
GLOBAL_VOLUME = dVolume; // see common/global.cpp |
2269 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME)); |
2270 |
|
} catch (Exception e) { |
2271 |
|
result.Error(e); |
2272 |
|
} |
2273 |
|
return result.Produce(); |
2274 |
|
} |
2275 |
|
|
2276 |
/** |
/** |
2277 |
* 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 |
2278 |
* server for receiving event messages. |
* server for receiving event messages. |
2299 |
return result.Produce(); |
return result.Produce(); |
2300 |
} |
} |
2301 |
|
|
2302 |
static int select_callback(void * lscpResultSet, int argc, |
String LSCPServer::AddDbInstrumentDirectory(String Dir) { |
2303 |
char **argv, char **azColName) |
dmsg(2,("LSCPServer: AddDbInstrumentDirectory(Dir=%s)\n", Dir.c_str())); |
2304 |
{ |
LSCPResultSet result; |
2305 |
LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet; |
#if HAVE_SQLITE3 |
2306 |
resultSet->Add(argc, argv); |
try { |
2307 |
return 0; |
InstrumentsDb::GetInstrumentsDb()->AddDirectory(Dir); |
2308 |
|
} catch (Exception e) { |
2309 |
|
result.Error(e); |
2310 |
|
} |
2311 |
|
#else |
2312 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2313 |
|
#endif |
2314 |
|
return result.Produce(); |
2315 |
} |
} |
2316 |
|
|
2317 |
String LSCPServer::QueryDatabase(String query) { |
String LSCPServer::RemoveDbInstrumentDirectory(String Dir, bool Force) { |
2318 |
|
dmsg(2,("LSCPServer: RemoveDbInstrumentDirectory(Dir=%s,Force=%d)\n", Dir.c_str(), Force)); |
2319 |
LSCPResultSet result; |
LSCPResultSet result; |
2320 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2321 |
char* zErrMsg = NULL; |
try { |
2322 |
sqlite3 *db; |
InstrumentsDb::GetInstrumentsDb()->RemoveDirectory(Dir, Force); |
2323 |
String selectStr = "SELECT " + query; |
} catch (Exception e) { |
2324 |
|
result.Error(e); |
2325 |
|
} |
2326 |
|
#else |
2327 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2328 |
|
#endif |
2329 |
|
return result.Produce(); |
2330 |
|
} |
2331 |
|
|
2332 |
int rc = sqlite3_open("linuxsampler.db", &db); |
String LSCPServer::GetDbInstrumentDirectoryCount(String Dir, bool Recursive) { |
2333 |
if (rc == SQLITE_OK) |
dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2334 |
{ |
LSCPResultSet result; |
2335 |
rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg); |
#if HAVE_SQLITE3 |
2336 |
|
try { |
2337 |
|
result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir, Recursive)); |
2338 |
|
} catch (Exception e) { |
2339 |
|
result.Error(e); |
2340 |
} |
} |
2341 |
if ( rc != SQLITE_OK ) |
#else |
2342 |
{ |
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2343 |
result.Error(String(zErrMsg), rc); |
#endif |
2344 |
|
return result.Produce(); |
2345 |
|
} |
2346 |
|
|
2347 |
|
String LSCPServer::GetDbInstrumentDirectories(String Dir, bool Recursive) { |
2348 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2349 |
|
LSCPResultSet result; |
2350 |
|
#if HAVE_SQLITE3 |
2351 |
|
try { |
2352 |
|
String list; |
2353 |
|
StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir, Recursive); |
2354 |
|
|
2355 |
|
for (int i = 0; i < dirs->size(); i++) { |
2356 |
|
if (list != "") list += ","; |
2357 |
|
list += "'" + dirs->at(i) + "'"; |
2358 |
|
} |
2359 |
|
|
2360 |
|
result.Add(list); |
2361 |
|
} catch (Exception e) { |
2362 |
|
result.Error(e); |
2363 |
} |
} |
|
sqlite3_close(db); |
|
2364 |
#else |
#else |
2365 |
result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0); |
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2366 |
#endif |
#endif |
2367 |
return result.Produce(); |
return result.Produce(); |
2368 |
} |
} |
2369 |
|
|
2370 |
|
String LSCPServer::GetDbInstrumentDirectoryInfo(String Dir) { |
2371 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectoryInfo(Dir=%s)\n", Dir.c_str())); |
2372 |
|
LSCPResultSet result; |
2373 |
|
#if HAVE_SQLITE3 |
2374 |
|
try { |
2375 |
|
DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir); |
2376 |
|
|
2377 |
|
result.Add("DESCRIPTION", info.Description); |
2378 |
|
result.Add("CREATED", info.Created); |
2379 |
|
result.Add("MODIFIED", info.Modified); |
2380 |
|
} catch (Exception e) { |
2381 |
|
result.Error(e); |
2382 |
|
} |
2383 |
|
#else |
2384 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2385 |
|
#endif |
2386 |
|
return result.Produce(); |
2387 |
|
} |
2388 |
|
|
2389 |
|
String LSCPServer::SetDbInstrumentDirectoryName(String Dir, String Name) { |
2390 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDirectoryName(Dir=%s,Name=%s)\n", Dir.c_str(), Name.c_str())); |
2391 |
|
LSCPResultSet result; |
2392 |
|
#if HAVE_SQLITE3 |
2393 |
|
try { |
2394 |
|
InstrumentsDb::GetInstrumentsDb()->RenameDirectory(Dir, Name); |
2395 |
|
} catch (Exception e) { |
2396 |
|
result.Error(e); |
2397 |
|
} |
2398 |
|
#else |
2399 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2400 |
|
#endif |
2401 |
|
return result.Produce(); |
2402 |
|
} |
2403 |
|
|
2404 |
|
String LSCPServer::MoveDbInstrumentDirectory(String Dir, String Dst) { |
2405 |
|
dmsg(2,("LSCPServer: MoveDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str())); |
2406 |
|
LSCPResultSet result; |
2407 |
|
#if HAVE_SQLITE3 |
2408 |
|
try { |
2409 |
|
InstrumentsDb::GetInstrumentsDb()->MoveDirectory(Dir, Dst); |
2410 |
|
} catch (Exception e) { |
2411 |
|
result.Error(e); |
2412 |
|
} |
2413 |
|
#else |
2414 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2415 |
|
#endif |
2416 |
|
return result.Produce(); |
2417 |
|
} |
2418 |
|
|
2419 |
|
String LSCPServer::CopyDbInstrumentDirectory(String Dir, String Dst) { |
2420 |
|
dmsg(2,("LSCPServer: CopyDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str())); |
2421 |
|
LSCPResultSet result; |
2422 |
|
#if HAVE_SQLITE3 |
2423 |
|
try { |
2424 |
|
InstrumentsDb::GetInstrumentsDb()->CopyDirectory(Dir, Dst); |
2425 |
|
} catch (Exception e) { |
2426 |
|
result.Error(e); |
2427 |
|
} |
2428 |
|
#else |
2429 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2430 |
|
#endif |
2431 |
|
return result.Produce(); |
2432 |
|
} |
2433 |
|
|
2434 |
|
String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) { |
2435 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDirectoryDescription(Dir=%s,Desc=%s)\n", Dir.c_str(), Desc.c_str())); |
2436 |
|
LSCPResultSet result; |
2437 |
|
#if HAVE_SQLITE3 |
2438 |
|
try { |
2439 |
|
InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc); |
2440 |
|
} catch (Exception e) { |
2441 |
|
result.Error(e); |
2442 |
|
} |
2443 |
|
#else |
2444 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2445 |
|
#endif |
2446 |
|
return result.Produce(); |
2447 |
|
} |
2448 |
|
|
2449 |
|
String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index, bool bBackground) { |
2450 |
|
dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d,bBackground=%d)\n", DbDir.c_str(), FilePath.c_str(), Index, bBackground)); |
2451 |
|
LSCPResultSet result; |
2452 |
|
#if HAVE_SQLITE3 |
2453 |
|
try { |
2454 |
|
int id; |
2455 |
|
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
2456 |
|
id = db->AddInstruments(DbDir, FilePath, Index, bBackground); |
2457 |
|
if (bBackground) result = id; |
2458 |
|
} catch (Exception e) { |
2459 |
|
result.Error(e); |
2460 |
|
} |
2461 |
|
#else |
2462 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2463 |
|
#endif |
2464 |
|
return result.Produce(); |
2465 |
|
} |
2466 |
|
|
2467 |
|
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) { |
2468 |
|
dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground)); |
2469 |
|
LSCPResultSet result; |
2470 |
|
#if HAVE_SQLITE3 |
2471 |
|
try { |
2472 |
|
int id; |
2473 |
|
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
2474 |
|
if (ScanMode.compare("RECURSIVE") == 0) { |
2475 |
|
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground); |
2476 |
|
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
2477 |
|
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground); |
2478 |
|
} else if (ScanMode.compare("FLAT") == 0) { |
2479 |
|
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground); |
2480 |
|
} else { |
2481 |
|
throw Exception("Unknown scan mode: " + ScanMode); |
2482 |
|
} |
2483 |
|
|
2484 |
|
if (bBackground) result = id; |
2485 |
|
} catch (Exception e) { |
2486 |
|
result.Error(e); |
2487 |
|
} |
2488 |
|
#else |
2489 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2490 |
|
#endif |
2491 |
|
return result.Produce(); |
2492 |
|
} |
2493 |
|
|
2494 |
|
String LSCPServer::RemoveDbInstrument(String Instr) { |
2495 |
|
dmsg(2,("LSCPServer: RemoveDbInstrument(Instr=%s)\n", Instr.c_str())); |
2496 |
|
LSCPResultSet result; |
2497 |
|
#if HAVE_SQLITE3 |
2498 |
|
try { |
2499 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveInstrument(Instr); |
2500 |
|
} catch (Exception e) { |
2501 |
|
result.Error(e); |
2502 |
|
} |
2503 |
|
#else |
2504 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2505 |
|
#endif |
2506 |
|
return result.Produce(); |
2507 |
|
} |
2508 |
|
|
2509 |
|
String LSCPServer::GetDbInstrumentCount(String Dir, bool Recursive) { |
2510 |
|
dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2511 |
|
LSCPResultSet result; |
2512 |
|
#if HAVE_SQLITE3 |
2513 |
|
try { |
2514 |
|
result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir, Recursive)); |
2515 |
|
} catch (Exception e) { |
2516 |
|
result.Error(e); |
2517 |
|
} |
2518 |
|
#else |
2519 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2520 |
|
#endif |
2521 |
|
return result.Produce(); |
2522 |
|
} |
2523 |
|
|
2524 |
|
String LSCPServer::GetDbInstruments(String Dir, bool Recursive) { |
2525 |
|
dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2526 |
|
LSCPResultSet result; |
2527 |
|
#if HAVE_SQLITE3 |
2528 |
|
try { |
2529 |
|
String list; |
2530 |
|
StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir, Recursive); |
2531 |
|
|
2532 |
|
for (int i = 0; i < instrs->size(); i++) { |
2533 |
|
if (list != "") list += ","; |
2534 |
|
list += "'" + instrs->at(i) + "'"; |
2535 |
|
} |
2536 |
|
|
2537 |
|
result.Add(list); |
2538 |
|
} catch (Exception e) { |
2539 |
|
result.Error(e); |
2540 |
|
} |
2541 |
|
#else |
2542 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2543 |
|
#endif |
2544 |
|
return result.Produce(); |
2545 |
|
} |
2546 |
|
|
2547 |
|
String LSCPServer::GetDbInstrumentInfo(String Instr) { |
2548 |
|
dmsg(2,("LSCPServer: GetDbInstrumentInfo(Instr=%s)\n", Instr.c_str())); |
2549 |
|
LSCPResultSet result; |
2550 |
|
#if HAVE_SQLITE3 |
2551 |
|
try { |
2552 |
|
DbInstrument info = InstrumentsDb::GetInstrumentsDb()->GetInstrumentInfo(Instr); |
2553 |
|
|
2554 |
|
result.Add("INSTRUMENT_FILE", info.InstrFile); |
2555 |
|
result.Add("INSTRUMENT_NR", info.InstrNr); |
2556 |
|
result.Add("FORMAT_FAMILY", info.FormatFamily); |
2557 |
|
result.Add("FORMAT_VERSION", info.FormatVersion); |
2558 |
|
result.Add("SIZE", (int)info.Size); |
2559 |
|
result.Add("CREATED", info.Created); |
2560 |
|
result.Add("MODIFIED", info.Modified); |
2561 |
|
result.Add("DESCRIPTION", FilterEndlines(info.Description)); |
2562 |
|
result.Add("IS_DRUM", info.IsDrum); |
2563 |
|
result.Add("PRODUCT", FilterEndlines(info.Product)); |
2564 |
|
result.Add("ARTISTS", FilterEndlines(info.Artists)); |
2565 |
|
result.Add("KEYWORDS", FilterEndlines(info.Keywords)); |
2566 |
|
} catch (Exception e) { |
2567 |
|
result.Error(e); |
2568 |
|
} |
2569 |
|
#else |
2570 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2571 |
|
#endif |
2572 |
|
return result.Produce(); |
2573 |
|
} |
2574 |
|
|
2575 |
|
String LSCPServer::GetDbInstrumentsJobInfo(int JobId) { |
2576 |
|
dmsg(2,("LSCPServer: GetDbInstrumentsJobInfo(JobId=%d)\n", JobId)); |
2577 |
|
LSCPResultSet result; |
2578 |
|
#if HAVE_SQLITE3 |
2579 |
|
try { |
2580 |
|
ScanJob job = InstrumentsDb::GetInstrumentsDb()->Jobs.GetJobById(JobId); |
2581 |
|
|
2582 |
|
result.Add("FILES_TOTAL", job.FilesTotal); |
2583 |
|
result.Add("FILES_SCANNED", job.FilesScanned); |
2584 |
|
result.Add("SCANNING", job.Scanning); |
2585 |
|
result.Add("STATUS", job.Status); |
2586 |
|
} catch (Exception e) { |
2587 |
|
result.Error(e); |
2588 |
|
} |
2589 |
|
#else |
2590 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2591 |
|
#endif |
2592 |
|
return result.Produce(); |
2593 |
|
} |
2594 |
|
|
2595 |
|
String LSCPServer::SetDbInstrumentName(String Instr, String Name) { |
2596 |
|
dmsg(2,("LSCPServer: SetDbInstrumentName(Instr=%s,Name=%s)\n", Instr.c_str(), Name.c_str())); |
2597 |
|
LSCPResultSet result; |
2598 |
|
#if HAVE_SQLITE3 |
2599 |
|
try { |
2600 |
|
InstrumentsDb::GetInstrumentsDb()->RenameInstrument(Instr, Name); |
2601 |
|
} catch (Exception e) { |
2602 |
|
result.Error(e); |
2603 |
|
} |
2604 |
|
#else |
2605 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2606 |
|
#endif |
2607 |
|
return result.Produce(); |
2608 |
|
} |
2609 |
|
|
2610 |
|
String LSCPServer::MoveDbInstrument(String Instr, String Dst) { |
2611 |
|
dmsg(2,("LSCPServer: MoveDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str())); |
2612 |
|
LSCPResultSet result; |
2613 |
|
#if HAVE_SQLITE3 |
2614 |
|
try { |
2615 |
|
InstrumentsDb::GetInstrumentsDb()->MoveInstrument(Instr, Dst); |
2616 |
|
} catch (Exception e) { |
2617 |
|
result.Error(e); |
2618 |
|
} |
2619 |
|
#else |
2620 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2621 |
|
#endif |
2622 |
|
return result.Produce(); |
2623 |
|
} |
2624 |
|
|
2625 |
|
String LSCPServer::CopyDbInstrument(String Instr, String Dst) { |
2626 |
|
dmsg(2,("LSCPServer: CopyDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str())); |
2627 |
|
LSCPResultSet result; |
2628 |
|
#if HAVE_SQLITE3 |
2629 |
|
try { |
2630 |
|
InstrumentsDb::GetInstrumentsDb()->CopyInstrument(Instr, Dst); |
2631 |
|
} catch (Exception e) { |
2632 |
|
result.Error(e); |
2633 |
|
} |
2634 |
|
#else |
2635 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2636 |
|
#endif |
2637 |
|
return result.Produce(); |
2638 |
|
} |
2639 |
|
|
2640 |
|
String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) { |
2641 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDescription(Instr=%s,Desc=%s)\n", Instr.c_str(), Desc.c_str())); |
2642 |
|
LSCPResultSet result; |
2643 |
|
#if HAVE_SQLITE3 |
2644 |
|
try { |
2645 |
|
InstrumentsDb::GetInstrumentsDb()->SetInstrumentDescription(Instr, Desc); |
2646 |
|
} catch (Exception e) { |
2647 |
|
result.Error(e); |
2648 |
|
} |
2649 |
|
#else |
2650 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2651 |
|
#endif |
2652 |
|
return result.Produce(); |
2653 |
|
} |
2654 |
|
|
2655 |
|
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
2656 |
|
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
2657 |
|
LSCPResultSet result; |
2658 |
|
#if HAVE_SQLITE3 |
2659 |
|
try { |
2660 |
|
SearchQuery Query; |
2661 |
|
std::map<String,String>::iterator iter; |
2662 |
|
for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { |
2663 |
|
if (iter->first.compare("NAME") == 0) { |
2664 |
|
Query.Name = iter->second; |
2665 |
|
} else if (iter->first.compare("CREATED") == 0) { |
2666 |
|
Query.SetCreated(iter->second); |
2667 |
|
} else if (iter->first.compare("MODIFIED") == 0) { |
2668 |
|
Query.SetModified(iter->second); |
2669 |
|
} else if (iter->first.compare("DESCRIPTION") == 0) { |
2670 |
|
Query.Description = iter->second; |
2671 |
|
} else { |
2672 |
|
throw Exception("Unknown search criteria: " + iter->first); |
2673 |
|
} |
2674 |
|
} |
2675 |
|
|
2676 |
|
String list; |
2677 |
|
StringListPtr pDirectories = |
2678 |
|
InstrumentsDb::GetInstrumentsDb()->FindDirectories(Dir, &Query, Recursive); |
2679 |
|
|
2680 |
|
for (int i = 0; i < pDirectories->size(); i++) { |
2681 |
|
if (list != "") list += ","; |
2682 |
|
list += "'" + pDirectories->at(i) + "'"; |
2683 |
|
} |
2684 |
|
|
2685 |
|
result.Add(list); |
2686 |
|
} catch (Exception e) { |
2687 |
|
result.Error(e); |
2688 |
|
} |
2689 |
|
#else |
2690 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2691 |
|
#endif |
2692 |
|
return result.Produce(); |
2693 |
|
} |
2694 |
|
|
2695 |
|
String LSCPServer::FindDbInstruments(String Dir, std::map<String,String> Parameters, bool Recursive) { |
2696 |
|
dmsg(2,("LSCPServer: FindDbInstruments(Dir=%s)\n", Dir.c_str())); |
2697 |
|
LSCPResultSet result; |
2698 |
|
#if HAVE_SQLITE3 |
2699 |
|
try { |
2700 |
|
SearchQuery Query; |
2701 |
|
std::map<String,String>::iterator iter; |
2702 |
|
for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { |
2703 |
|
if (iter->first.compare("NAME") == 0) { |
2704 |
|
Query.Name = iter->second; |
2705 |
|
} else if (iter->first.compare("FORMAT_FAMILIES") == 0) { |
2706 |
|
Query.SetFormatFamilies(iter->second); |
2707 |
|
} else if (iter->first.compare("SIZE") == 0) { |
2708 |
|
Query.SetSize(iter->second); |
2709 |
|
} else if (iter->first.compare("CREATED") == 0) { |
2710 |
|
Query.SetCreated(iter->second); |
2711 |
|
} else if (iter->first.compare("MODIFIED") == 0) { |
2712 |
|
Query.SetModified(iter->second); |
2713 |
|
} else if (iter->first.compare("DESCRIPTION") == 0) { |
2714 |
|
Query.Description = iter->second; |
2715 |
|
} else if (iter->first.compare("IS_DRUM") == 0) { |
2716 |
|
if (!strcasecmp(iter->second.c_str(), "true")) { |
2717 |
|
Query.InstrType = SearchQuery::DRUM; |
2718 |
|
} else { |
2719 |
|
Query.InstrType = SearchQuery::CHROMATIC; |
2720 |
|
} |
2721 |
|
} else if (iter->first.compare("PRODUCT") == 0) { |
2722 |
|
Query.Product = iter->second; |
2723 |
|
} else if (iter->first.compare("ARTISTS") == 0) { |
2724 |
|
Query.Artists = iter->second; |
2725 |
|
} else if (iter->first.compare("KEYWORDS") == 0) { |
2726 |
|
Query.Keywords = iter->second; |
2727 |
|
} else { |
2728 |
|
throw Exception("Unknown search criteria: " + iter->first); |
2729 |
|
} |
2730 |
|
} |
2731 |
|
|
2732 |
|
String list; |
2733 |
|
StringListPtr pInstruments = |
2734 |
|
InstrumentsDb::GetInstrumentsDb()->FindInstruments(Dir, &Query, Recursive); |
2735 |
|
|
2736 |
|
for (int i = 0; i < pInstruments->size(); i++) { |
2737 |
|
if (list != "") list += ","; |
2738 |
|
list += "'" + pInstruments->at(i) + "'"; |
2739 |
|
} |
2740 |
|
|
2741 |
|
result.Add(list); |
2742 |
|
} catch (Exception e) { |
2743 |
|
result.Error(e); |
2744 |
|
} |
2745 |
|
#else |
2746 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2747 |
|
#endif |
2748 |
|
return result.Produce(); |
2749 |
|
} |
2750 |
|
|
2751 |
|
|
2752 |
/** |
/** |
2753 |
* 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 |
2754 |
* mode is enabled, all commands from the client will (immediately) be |
* mode is enabled, all commands from the client will (immediately) be |
2767 |
} |
} |
2768 |
return result.Produce(); |
return result.Produce(); |
2769 |
} |
} |
2770 |
|
|
2771 |
|
String LSCPServer::FilterEndlines(String s) { |
2772 |
|
String s2 = s; |
2773 |
|
for (int i = 0; i < s2.length(); i++) { |
2774 |
|
if (s2.at(i) == '\r') s2.at(i) = ' '; |
2775 |
|
else if (s2.at(i) == '\n') s2.at(i) = ' '; |
2776 |
|
} |
2777 |
|
|
2778 |
|
return s2; |
2779 |
|
} |