2 |
* * |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
|
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program 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 * |
10 |
* the Free Software Foundation; either version 2 of the License, or * |
* the Free Software Foundation; either version 2 of the License, or * |
11 |
* (at your option) any later version. * |
* (at your option) any later version. * |
12 |
* * |
* * |
13 |
* This program is distributed in the hope that it will be useful, * |
* This library is distributed in the hope that it will be useful, * |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 |
* GNU General Public License for more details. * |
* GNU General Public License for more details. * |
17 |
* * |
* * |
18 |
* You should have received a copy of the GNU General Public License * |
* You should have received a copy of the GNU General Public License * |
19 |
* along with this program; if not, write to the Free Software * |
* along with this library; if not, write to the Free Software * |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
***************************************************************************/ |
23 |
|
|
24 |
|
#include <algorithm> |
25 |
|
#include <string> |
26 |
|
|
27 |
#include "lscpserver.h" |
#include "lscpserver.h" |
28 |
|
#include "lscpresultset.h" |
29 |
|
#include "lscpevent.h" |
30 |
|
|
31 |
|
#if defined(WIN32) |
32 |
|
#include <windows.h> |
33 |
|
#else |
34 |
|
#include <fcntl.h> |
35 |
|
#endif |
36 |
|
|
37 |
|
#if ! HAVE_SQLITE3 |
38 |
|
#define DOESNT_HAVE_SQLITE3 "No database support. SQLITE3 was not installed when linuxsampler was built." |
39 |
|
#endif |
40 |
|
|
41 |
|
#include "../engines/EngineFactory.h" |
42 |
|
#include "../engines/EngineChannelFactory.h" |
43 |
|
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
44 |
|
#include "../drivers/midi/MidiInputDeviceFactory.h" |
45 |
|
|
46 |
|
namespace LinuxSampler { |
47 |
|
|
48 |
|
/** |
49 |
|
* Returns a copy of the given string where all special characters are |
50 |
|
* replaced by LSCP escape sequences ("\xHH"). This function shall be used |
51 |
|
* to escape LSCP response fields in case the respective response field is |
52 |
|
* actually defined as using escape sequences in the LSCP specs. |
53 |
|
* |
54 |
|
* @e Caution: DO NOT use this function for escaping path based responses, |
55 |
|
* use the Path class (src/common/Path.h) for this instead! |
56 |
|
*/ |
57 |
|
static String _escapeLscpResponse(String txt) { |
58 |
|
for (int i = 0; i < txt.length(); i++) { |
59 |
|
const char c = txt.c_str()[i]; |
60 |
|
if ( |
61 |
|
!(c >= '0' && c <= '9') && |
62 |
|
!(c >= 'a' && c <= 'z') && |
63 |
|
!(c >= 'A' && c <= 'Z') && |
64 |
|
!(c == ' ') && !(c == '!') && !(c == '#') && !(c == '$') && |
65 |
|
!(c == '%') && !(c == '&') && !(c == '(') && !(c == ')') && |
66 |
|
!(c == '*') && !(c == '+') && !(c == ',') && !(c == '-') && |
67 |
|
!(c == '.') && !(c == '/') && !(c == ':') && !(c == ';') && |
68 |
|
!(c == '<') && !(c == '=') && !(c == '>') && !(c == '?') && |
69 |
|
!(c == '@') && !(c == '[') && !(c == ']') && |
70 |
|
!(c == '^') && !(c == '_') && !(c == '`') && !(c == '{') && |
71 |
|
!(c == '|') && !(c == '}') && !(c == '~') |
72 |
|
) { |
73 |
|
// convert the "special" character into a "\xHH" LSCP escape sequence |
74 |
|
char buf[5]; |
75 |
|
snprintf(buf, sizeof(buf), "\\x%02x", static_cast<unsigned char>(c)); |
76 |
|
txt.replace(i, 1, buf); |
77 |
|
i += 3; |
78 |
|
} |
79 |
|
} |
80 |
|
return txt; |
81 |
|
} |
82 |
|
|
83 |
#include "../engines/gig/Engine.h" |
/** |
84 |
|
* Below are a few static members of the LSCPServer class. |
85 |
|
* The big assumption here is that LSCPServer is going to remain a singleton. |
86 |
|
* These members are used to support client connections. |
87 |
|
* Class handles multiple connections at the same time using select() and non-blocking recv() |
88 |
|
* Commands are processed by a single LSCPServer thread. |
89 |
|
* Notifications are delivered either by the thread that originated them |
90 |
|
* or (if the resultset is currently in progress) by the LSCPServer thread |
91 |
|
* after the resultset was sent out. |
92 |
|
* This makes sure that resultsets can not be interrupted by notifications. |
93 |
|
* This also makes sure that the thread sending notification is not blocked |
94 |
|
* by the LSCPServer thread. |
95 |
|
*/ |
96 |
|
fd_set LSCPServer::fdSet; |
97 |
|
int LSCPServer::currentSocket = -1; |
98 |
|
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
99 |
|
std::vector<yyparse_param_t>::iterator itCurrentSession = std::vector<yyparse_param_t>::iterator(); |
100 |
|
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
101 |
|
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
102 |
|
std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions = std::map< LSCPEvent::event_t, std::list<int> >(); |
103 |
|
Mutex LSCPServer::NotifyMutex = Mutex(); |
104 |
|
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
105 |
|
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
106 |
|
Mutex LSCPServer::RTNotifyMutex = Mutex(); |
107 |
|
|
108 |
LSCPServer::LSCPServer(Sampler* pSampler) : Thread(false, 0, -4) { |
LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4), eventHandler(this) { |
109 |
|
SocketAddress.sin_family = AF_INET; |
110 |
|
SocketAddress.sin_addr.s_addr = addr; |
111 |
|
SocketAddress.sin_port = port; |
112 |
this->pSampler = pSampler; |
this->pSampler = pSampler; |
113 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_count, "AUDIO_OUTPUT_DEVICE_COUNT"); |
114 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_audio_device_info, "AUDIO_OUTPUT_DEVICE_INFO"); |
115 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_device_count, "MIDI_INPUT_DEVICE_COUNT"); |
116 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_device_info, "MIDI_INPUT_DEVICE_INFO"); |
117 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_count, "CHANNEL_COUNT"); |
118 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_voice_count, "VOICE_COUNT"); |
119 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT"); |
120 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL"); |
121 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO"); |
122 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_fx_send_count, "FX_SEND_COUNT"); |
123 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_fx_send_info, "FX_SEND_INFO"); |
124 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_count, "MIDI_INSTRUMENT_MAP_COUNT"); |
125 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO"); |
126 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT"); |
127 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO"); |
128 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_count, "DB_INSTRUMENT_DIRECTORY_COUNT"); |
129 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_info, "DB_INSTRUMENT_DIRECTORY_INFO"); |
130 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_count, "DB_INSTRUMENT_COUNT"); |
131 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO"); |
132 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO"); |
133 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
134 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_total_stream_count, "TOTAL_STREAM_COUNT"); |
135 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
136 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
137 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI"); |
138 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_device_midi, "DEVICE_MIDI"); |
139 |
|
hSocket = -1; |
140 |
|
} |
141 |
|
|
142 |
|
LSCPServer::~LSCPServer() { |
143 |
|
#if defined(WIN32) |
144 |
|
if (hSocket >= 0) closesocket(hSocket); |
145 |
|
#else |
146 |
|
if (hSocket >= 0) close(hSocket); |
147 |
|
#endif |
148 |
|
} |
149 |
|
|
150 |
|
LSCPServer::EventHandler::EventHandler(LSCPServer* pParent) { |
151 |
|
this->pParent = pParent; |
152 |
|
} |
153 |
|
|
154 |
|
LSCPServer::EventHandler::~EventHandler() { |
155 |
|
std::vector<midi_listener_entry> l = channelMidiListeners; |
156 |
|
channelMidiListeners.clear(); |
157 |
|
for (int i = 0; i < l.size(); i++) |
158 |
|
delete l[i].pMidiListener; |
159 |
|
} |
160 |
|
|
161 |
|
void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) { |
162 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount)); |
163 |
|
} |
164 |
|
|
165 |
|
void LSCPServer::EventHandler::ChannelAdded(SamplerChannel* pChannel) { |
166 |
|
pChannel->AddEngineChangeListener(this); |
167 |
|
} |
168 |
|
|
169 |
|
void LSCPServer::EventHandler::ChannelToBeRemoved(SamplerChannel* pChannel) { |
170 |
|
if (!pChannel->GetEngineChannel()) return; |
171 |
|
EngineToBeChanged(pChannel->Index()); |
172 |
|
} |
173 |
|
|
174 |
|
void LSCPServer::EventHandler::EngineToBeChanged(int ChannelId) { |
175 |
|
SamplerChannel* pSamplerChannel = |
176 |
|
pParent->pSampler->GetSamplerChannel(ChannelId); |
177 |
|
if (!pSamplerChannel) return; |
178 |
|
EngineChannel* pEngineChannel = |
179 |
|
pSamplerChannel->GetEngineChannel(); |
180 |
|
if (!pEngineChannel) return; |
181 |
|
for (std::vector<midi_listener_entry>::iterator iter = channelMidiListeners.begin(); iter != channelMidiListeners.end(); ++iter) { |
182 |
|
if ((*iter).pEngineChannel == pEngineChannel) { |
183 |
|
VirtualMidiDevice* pMidiListener = (*iter).pMidiListener; |
184 |
|
pEngineChannel->Disconnect(pMidiListener); |
185 |
|
channelMidiListeners.erase(iter); |
186 |
|
delete pMidiListener; |
187 |
|
return; |
188 |
|
} |
189 |
|
} |
190 |
|
} |
191 |
|
|
192 |
|
void LSCPServer::EventHandler::EngineChanged(int ChannelId) { |
193 |
|
SamplerChannel* pSamplerChannel = |
194 |
|
pParent->pSampler->GetSamplerChannel(ChannelId); |
195 |
|
if (!pSamplerChannel) return; |
196 |
|
EngineChannel* pEngineChannel = |
197 |
|
pSamplerChannel->GetEngineChannel(); |
198 |
|
if (!pEngineChannel) return; |
199 |
|
VirtualMidiDevice* pMidiListener = new VirtualMidiDevice; |
200 |
|
pEngineChannel->Connect(pMidiListener); |
201 |
|
midi_listener_entry entry = { |
202 |
|
pSamplerChannel, pEngineChannel, pMidiListener |
203 |
|
}; |
204 |
|
channelMidiListeners.push_back(entry); |
205 |
|
} |
206 |
|
|
207 |
|
void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) { |
208 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount)); |
209 |
|
} |
210 |
|
|
211 |
|
void LSCPServer::EventHandler::MidiDeviceCountChanged(int NewCount) { |
212 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount)); |
213 |
|
} |
214 |
|
|
215 |
|
void LSCPServer::EventHandler::MidiDeviceToBeDestroyed(MidiInputDevice* pDevice) { |
216 |
|
pDevice->RemoveMidiPortCountListener(this); |
217 |
|
for (int i = 0; i < pDevice->PortCount(); ++i) |
218 |
|
MidiPortToBeRemoved(pDevice->GetPort(i)); |
219 |
|
} |
220 |
|
|
221 |
|
void LSCPServer::EventHandler::MidiDeviceCreated(MidiInputDevice* pDevice) { |
222 |
|
pDevice->AddMidiPortCountListener(this); |
223 |
|
for (int i = 0; i < pDevice->PortCount(); ++i) |
224 |
|
MidiPortAdded(pDevice->GetPort(i)); |
225 |
|
} |
226 |
|
|
227 |
|
void LSCPServer::EventHandler::MidiPortCountChanged(int NewCount) { |
228 |
|
// yet unused |
229 |
|
} |
230 |
|
|
231 |
|
void LSCPServer::EventHandler::MidiPortToBeRemoved(MidiInputPort* pPort) { |
232 |
|
for (std::vector<device_midi_listener_entry>::iterator iter = deviceMidiListeners.begin(); iter != deviceMidiListeners.end(); ++iter) { |
233 |
|
if ((*iter).pPort == pPort) { |
234 |
|
VirtualMidiDevice* pMidiListener = (*iter).pMidiListener; |
235 |
|
pPort->Disconnect(pMidiListener); |
236 |
|
deviceMidiListeners.erase(iter); |
237 |
|
delete pMidiListener; |
238 |
|
return; |
239 |
|
} |
240 |
|
} |
241 |
|
} |
242 |
|
|
243 |
|
void LSCPServer::EventHandler::MidiPortAdded(MidiInputPort* pPort) { |
244 |
|
// find out the device ID |
245 |
|
std::map<uint, MidiInputDevice*> devices = |
246 |
|
pParent->pSampler->GetMidiInputDevices(); |
247 |
|
for ( |
248 |
|
std::map<uint, MidiInputDevice*>::iterator iter = devices.begin(); |
249 |
|
iter != devices.end(); ++iter |
250 |
|
) { |
251 |
|
if (iter->second == pPort->GetDevice()) { // found |
252 |
|
VirtualMidiDevice* pMidiListener = new VirtualMidiDevice; |
253 |
|
pPort->Connect(pMidiListener); |
254 |
|
device_midi_listener_entry entry = { |
255 |
|
pPort, pMidiListener, iter->first |
256 |
|
}; |
257 |
|
deviceMidiListeners.push_back(entry); |
258 |
|
return; |
259 |
|
} |
260 |
|
} |
261 |
|
} |
262 |
|
|
263 |
|
void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) { |
264 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount)); |
265 |
|
} |
266 |
|
|
267 |
|
void LSCPServer::EventHandler::MidiInstrumentInfoChanged(int MapId, int Bank, int Program) { |
268 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_info, MapId, Bank, Program)); |
269 |
|
} |
270 |
|
|
271 |
|
void LSCPServer::EventHandler::MidiInstrumentMapCountChanged(int NewCount) { |
272 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_count, NewCount)); |
273 |
|
} |
274 |
|
|
275 |
|
void LSCPServer::EventHandler::MidiInstrumentMapInfoChanged(int MapId) { |
276 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_info, MapId)); |
277 |
|
} |
278 |
|
|
279 |
|
void LSCPServer::EventHandler::FxSendCountChanged(int ChannelId, int NewCount) { |
280 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_count, ChannelId, NewCount)); |
281 |
|
} |
282 |
|
|
283 |
|
void LSCPServer::EventHandler::VoiceCountChanged(int ChannelId, int NewCount) { |
284 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_voice_count, ChannelId, NewCount)); |
285 |
|
} |
286 |
|
|
287 |
|
void LSCPServer::EventHandler::StreamCountChanged(int ChannelId, int NewCount) { |
288 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_stream_count, ChannelId, NewCount)); |
289 |
|
} |
290 |
|
|
291 |
|
void LSCPServer::EventHandler::BufferFillChanged(int ChannelId, String FillData) { |
292 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_buffer_fill, ChannelId, FillData)); |
293 |
|
} |
294 |
|
|
295 |
|
void LSCPServer::EventHandler::TotalVoiceCountChanged(int NewCount) { |
296 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount)); |
297 |
|
} |
298 |
|
|
299 |
|
void LSCPServer::EventHandler::TotalStreamCountChanged(int NewCount) { |
300 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_stream_count, NewCount)); |
301 |
|
} |
302 |
|
|
303 |
|
#if HAVE_SQLITE3 |
304 |
|
void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) { |
305 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, InstrumentsDb::toEscapedPath(Dir))); |
306 |
|
} |
307 |
|
|
308 |
|
void LSCPServer::DbInstrumentsEventHandler::DirectoryInfoChanged(String Dir) { |
309 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, InstrumentsDb::toEscapedPath(Dir))); |
310 |
|
} |
311 |
|
|
312 |
|
void LSCPServer::DbInstrumentsEventHandler::DirectoryNameChanged(String Dir, String NewName) { |
313 |
|
Dir = "'" + InstrumentsDb::toEscapedPath(Dir) + "'"; |
314 |
|
NewName = "'" + InstrumentsDb::toEscapedPath(NewName) + "'"; |
315 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, "NAME", Dir, NewName)); |
316 |
|
} |
317 |
|
|
318 |
|
void LSCPServer::DbInstrumentsEventHandler::InstrumentCountChanged(String Dir) { |
319 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_count, InstrumentsDb::toEscapedPath(Dir))); |
320 |
|
} |
321 |
|
|
322 |
|
void LSCPServer::DbInstrumentsEventHandler::InstrumentInfoChanged(String Instr) { |
323 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, InstrumentsDb::toEscapedPath(Instr))); |
324 |
|
} |
325 |
|
|
326 |
|
void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) { |
327 |
|
Instr = "'" + InstrumentsDb::toEscapedPath(Instr) + "'"; |
328 |
|
NewName = "'" + InstrumentsDb::toEscapedPath(NewName) + "'"; |
329 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, "NAME", Instr, NewName)); |
330 |
|
} |
331 |
|
|
332 |
|
void LSCPServer::DbInstrumentsEventHandler::JobStatusChanged(int JobId) { |
333 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instrs_job_info, JobId)); |
334 |
|
} |
335 |
|
#endif // HAVE_SQLITE3 |
336 |
|
|
337 |
|
|
338 |
|
/** |
339 |
|
* Blocks the calling thread until the LSCP Server is initialized and |
340 |
|
* accepting socket connections, if the server is already initialized then |
341 |
|
* this method will return immediately. |
342 |
|
* @param TimeoutSeconds - optional: max. wait time in seconds |
343 |
|
* (default: 0s) |
344 |
|
* @param TimeoutNanoSeconds - optional: max wait time in nano seconds |
345 |
|
* (default: 0ns) |
346 |
|
* @returns 0 on success, a value less than 0 if timeout exceeded |
347 |
|
*/ |
348 |
|
int LSCPServer::WaitUntilInitialized(long TimeoutSeconds, long TimeoutNanoSeconds) { |
349 |
|
return Initialized.WaitAndUnlockIf(false, TimeoutSeconds, TimeoutNanoSeconds); |
350 |
} |
} |
351 |
|
|
352 |
int LSCPServer::Main() { |
int LSCPServer::Main() { |
353 |
|
#if defined(WIN32) |
354 |
|
WSADATA wsaData; |
355 |
|
int iResult; |
356 |
|
iResult = WSAStartup(MAKEWORD(2,2), &wsaData); |
357 |
|
if (iResult != 0) { |
358 |
|
std::cerr << "LSCPServer: WSAStartup failed: " << iResult << "\n"; |
359 |
|
exit(EXIT_FAILURE); |
360 |
|
} |
361 |
|
#endif |
362 |
hSocket = socket(AF_INET, SOCK_STREAM, 0); |
hSocket = socket(AF_INET, SOCK_STREAM, 0); |
363 |
if (hSocket < 0) { |
if (hSocket < 0) { |
364 |
std::cerr << "LSCPServer: Could not create server socket." << std::endl; |
std::cerr << "LSCPServer: Could not create server socket." << std::endl; |
366 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
367 |
} |
} |
368 |
|
|
|
SocketAddress.sin_family = AF_INET; |
|
|
SocketAddress.sin_port = htons(LSCP_PORT); |
|
|
SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY); |
|
|
|
|
369 |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
370 |
std::cerr << "LSCPServer: Could not bind server socket." << std::endl; |
std::cerr << "LSCPServer: Could not bind server socket, retrying for " << ToString(LSCP_SERVER_BIND_TIMEOUT) << " seconds..."; |
371 |
close(hSocket); |
for (int trial = 0; true; trial++) { // retry for LSCP_SERVER_BIND_TIMEOUT seconds |
372 |
//return -1; |
if (bind(hSocket, (sockaddr*) &SocketAddress, sizeof(sockaddr_in)) < 0) { |
373 |
exit(EXIT_FAILURE); |
if (trial > LSCP_SERVER_BIND_TIMEOUT) { |
374 |
|
std::cerr << "gave up!" << std::endl; |
375 |
|
#if defined(WIN32) |
376 |
|
closesocket(hSocket); |
377 |
|
#else |
378 |
|
close(hSocket); |
379 |
|
#endif |
380 |
|
//return -1; |
381 |
|
exit(EXIT_FAILURE); |
382 |
|
} |
383 |
|
else sleep(1); // sleep 1s |
384 |
|
} |
385 |
|
else break; // success |
386 |
|
} |
387 |
} |
} |
388 |
|
|
389 |
listen(hSocket, 1); |
listen(hSocket, 1); |
390 |
dmsg(1,("LSCPServer: Server running.\n")); // server running |
Initialized.Set(true); |
391 |
|
|
392 |
|
// Registering event listeners |
393 |
|
pSampler->AddChannelCountListener(&eventHandler); |
394 |
|
pSampler->AddAudioDeviceCountListener(&eventHandler); |
395 |
|
pSampler->AddMidiDeviceCountListener(&eventHandler); |
396 |
|
pSampler->AddVoiceCountListener(&eventHandler); |
397 |
|
pSampler->AddStreamCountListener(&eventHandler); |
398 |
|
pSampler->AddBufferFillListener(&eventHandler); |
399 |
|
pSampler->AddTotalStreamCountListener(&eventHandler); |
400 |
|
pSampler->AddTotalVoiceCountListener(&eventHandler); |
401 |
|
pSampler->AddFxSendCountListener(&eventHandler); |
402 |
|
MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler); |
403 |
|
MidiInstrumentMapper::AddMidiInstrumentInfoListener(&eventHandler); |
404 |
|
MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&eventHandler); |
405 |
|
MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(&eventHandler); |
406 |
|
#if HAVE_SQLITE3 |
407 |
|
InstrumentsDb::GetInstrumentsDb()->AddInstrumentsDbListener(&dbInstrumentsEventHandler); |
408 |
|
#endif |
409 |
// now wait for client connections and handle their requests |
// now wait for client connections and handle their requests |
410 |
sockaddr_in client; |
sockaddr_in client; |
411 |
int length = sizeof(client); |
int length = sizeof(client); |
412 |
|
FD_ZERO(&fdSet); |
413 |
|
FD_SET(hSocket, &fdSet); |
414 |
|
int maxSessions = hSocket; |
415 |
|
|
416 |
|
timeval timeout; |
417 |
|
|
418 |
while (true) { |
while (true) { |
419 |
hSession = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length); |
#if CONFIG_PTHREAD_TESTCANCEL |
420 |
if (hSession < 0) { |
TestCancel(); |
421 |
std::cerr << "LSCPServer: Client connection failed." << std::endl; |
#endif |
422 |
close(hSocket); |
// check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers |
423 |
//return -1; |
{ |
424 |
exit(EXIT_FAILURE); |
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
425 |
} |
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
426 |
|
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
427 |
dmsg(1,("LSCPServer: Client connection established.\n")); |
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
428 |
//send(hSession, "Welcome!\r\n", 10, 0); |
if ((*itEngineChannel)->StatusChanged()) { |
429 |
|
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->GetSamplerChannel()->Index())); |
430 |
// Parser invocation |
} |
431 |
yyparse_param_t yyparse_param; |
|
432 |
yyparse_param.pServer = this; |
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
433 |
yylex_init(&yyparse_param.pScanner); |
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
434 |
while (yyparse(&yyparse_param) == LSCP_SYNTAX_ERROR); // recall parser in case of syntax error |
if(fxs != NULL && fxs->IsInfoChanged()) { |
435 |
yylex_destroy(yyparse_param.pScanner); |
int chn = (*itEngineChannel)->GetSamplerChannel()->Index(); |
436 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id())); |
437 |
|
fxs->SetInfoChanged(false); |
438 |
|
} |
439 |
|
} |
440 |
|
} |
441 |
|
} |
442 |
|
|
443 |
close(hSession); |
// check if MIDI data arrived on some engine channel |
444 |
dmsg(1,("LSCPServer: Client connection terminated.\n")); |
for (int i = 0; i < eventHandler.channelMidiListeners.size(); ++i) { |
445 |
} |
const EventHandler::midi_listener_entry entry = |
446 |
|
eventHandler.channelMidiListeners[i]; |
447 |
|
VirtualMidiDevice* pMidiListener = entry.pMidiListener; |
448 |
|
if (pMidiListener->NotesChanged()) { |
449 |
|
for (int iNote = 0; iNote < 128; iNote++) { |
450 |
|
if (pMidiListener->NoteChanged(iNote)) { |
451 |
|
const bool bActive = pMidiListener->NoteIsActive(iNote); |
452 |
|
LSCPServer::SendLSCPNotify( |
453 |
|
LSCPEvent( |
454 |
|
LSCPEvent::event_channel_midi, |
455 |
|
entry.pSamplerChannel->Index(), |
456 |
|
std::string(bActive ? "NOTE_ON" : "NOTE_OFF"), |
457 |
|
iNote, |
458 |
|
bActive ? pMidiListener->NoteOnVelocity(iNote) |
459 |
|
: pMidiListener->NoteOffVelocity(iNote) |
460 |
|
) |
461 |
|
); |
462 |
|
} |
463 |
|
} |
464 |
|
} |
465 |
|
} |
466 |
|
|
467 |
|
// check if MIDI data arrived on some MIDI device |
468 |
|
for (int i = 0; i < eventHandler.deviceMidiListeners.size(); ++i) { |
469 |
|
const EventHandler::device_midi_listener_entry entry = |
470 |
|
eventHandler.deviceMidiListeners[i]; |
471 |
|
VirtualMidiDevice* pMidiListener = entry.pMidiListener; |
472 |
|
if (pMidiListener->NotesChanged()) { |
473 |
|
for (int iNote = 0; iNote < 128; iNote++) { |
474 |
|
if (pMidiListener->NoteChanged(iNote)) { |
475 |
|
const bool bActive = pMidiListener->NoteIsActive(iNote); |
476 |
|
LSCPServer::SendLSCPNotify( |
477 |
|
LSCPEvent( |
478 |
|
LSCPEvent::event_device_midi, |
479 |
|
entry.uiDeviceID, |
480 |
|
entry.pPort->GetPortNumber(), |
481 |
|
std::string(bActive ? "NOTE_ON" : "NOTE_OFF"), |
482 |
|
iNote, |
483 |
|
bActive ? pMidiListener->NoteOnVelocity(iNote) |
484 |
|
: pMidiListener->NoteOffVelocity(iNote) |
485 |
|
) |
486 |
|
); |
487 |
|
} |
488 |
|
} |
489 |
|
} |
490 |
|
} |
491 |
|
|
492 |
|
//Now let's deliver late notifies (if any) |
493 |
|
NotifyBufferMutex.Lock(); |
494 |
|
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
495 |
|
#ifdef MSG_NOSIGNAL |
496 |
|
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL); |
497 |
|
#else |
498 |
|
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); |
499 |
|
#endif |
500 |
|
} |
501 |
|
bufferedNotifies.clear(); |
502 |
|
NotifyBufferMutex.Unlock(); |
503 |
|
|
504 |
|
fd_set selectSet = fdSet; |
505 |
|
timeout.tv_sec = 0; |
506 |
|
timeout.tv_usec = 100000; |
507 |
|
|
508 |
|
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
509 |
|
|
510 |
|
if (retval == 0) |
511 |
|
continue; //Nothing try again |
512 |
|
if (retval == -1) { |
513 |
|
std::cerr << "LSCPServer: Socket select error." << std::endl; |
514 |
|
#if defined(WIN32) |
515 |
|
closesocket(hSocket); |
516 |
|
#else |
517 |
|
close(hSocket); |
518 |
|
#endif |
519 |
|
exit(EXIT_FAILURE); |
520 |
|
} |
521 |
|
|
522 |
|
//Accept new connections now (if any) |
523 |
|
if (FD_ISSET(hSocket, &selectSet)) { |
524 |
|
int socket = accept(hSocket, (sockaddr*) &client, (socklen_t*) &length); |
525 |
|
if (socket < 0) { |
526 |
|
std::cerr << "LSCPServer: Client connection failed." << std::endl; |
527 |
|
exit(EXIT_FAILURE); |
528 |
|
} |
529 |
|
|
530 |
|
#if defined(WIN32) |
531 |
|
u_long nonblock_io = 1; |
532 |
|
if( ioctlsocket(socket, FIONBIO, &nonblock_io) ) { |
533 |
|
std::cerr << "LSCPServer: ioctlsocket: set FIONBIO failed. Error " << WSAGetLastError() << std::endl; |
534 |
|
exit(EXIT_FAILURE); |
535 |
|
} |
536 |
|
#else |
537 |
|
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
538 |
|
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
539 |
|
exit(EXIT_FAILURE); |
540 |
|
} |
541 |
|
#endif |
542 |
|
|
543 |
|
// Parser initialization |
544 |
|
yyparse_param_t yyparse_param; |
545 |
|
yyparse_param.pServer = this; |
546 |
|
yyparse_param.hSession = socket; |
547 |
|
|
548 |
|
Sessions.push_back(yyparse_param); |
549 |
|
FD_SET(socket, &fdSet); |
550 |
|
if (socket > maxSessions) |
551 |
|
maxSessions = socket; |
552 |
|
dmsg(1,("LSCPServer: Client connection established on socket:%d.\n", socket)); |
553 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection established on socket", socket)); |
554 |
|
continue; //Maybe this was the only selected socket, better select again |
555 |
|
} |
556 |
|
|
557 |
|
//Something was selected and it was not the hSocket, so it must be some command(s) coming. |
558 |
|
for (std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); iter != Sessions.end(); iter++) { |
559 |
|
if (FD_ISSET((*iter).hSession, &selectSet)) { //Was it this socket? |
560 |
|
if (GetLSCPCommand(iter)) { //Have we read the entire command? |
561 |
|
dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket)); |
562 |
|
int dummy; // just a temporary hack to fulfill the restart() function prototype |
563 |
|
restart(NULL, dummy); // restart the 'scanner' |
564 |
|
currentSocket = (*iter).hSession; //a hack |
565 |
|
itCurrentSession = iter; // another hack |
566 |
|
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
567 |
|
if ((*iter).bVerbose) { // if echo mode enabled |
568 |
|
AnswerClient(bufferedCommands[currentSocket]); |
569 |
|
} |
570 |
|
int result = yyparse(&(*iter)); |
571 |
|
currentSocket = -1; //continuation of a hack |
572 |
|
itCurrentSession = Sessions.end(); // hack as well |
573 |
|
dmsg(3,("LSCPServer: Done parsing on socket %d.\n", currentSocket)); |
574 |
|
if (result == LSCP_QUIT) { //Was it a quit command by any chance? |
575 |
|
CloseConnection(iter); |
576 |
|
} |
577 |
|
} |
578 |
|
//socket may have been closed, iter may be invalid, get out of the loop for now. |
579 |
|
//we'll be back if there is data. |
580 |
|
break; |
581 |
|
} |
582 |
|
} |
583 |
|
} |
584 |
|
} |
585 |
|
|
586 |
|
void LSCPServer::CloseConnection( std::vector<yyparse_param_t>::iterator iter ) { |
587 |
|
int socket = (*iter).hSession; |
588 |
|
dmsg(1,("LSCPServer: Client connection terminated on socket:%d.\n",socket)); |
589 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket)); |
590 |
|
Sessions.erase(iter); |
591 |
|
FD_CLR(socket, &fdSet); |
592 |
|
SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any) |
593 |
|
for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) { |
594 |
|
iter->second.remove(socket); |
595 |
|
} |
596 |
|
SubscriptionMutex.Unlock(); |
597 |
|
NotifyMutex.Lock(); |
598 |
|
bufferedCommands.erase(socket); |
599 |
|
bufferedNotifies.erase(socket); |
600 |
|
#if defined(WIN32) |
601 |
|
closesocket(socket); |
602 |
|
#else |
603 |
|
close(socket); |
604 |
|
#endif |
605 |
|
NotifyMutex.Unlock(); |
606 |
|
} |
607 |
|
|
608 |
|
void LSCPServer::LockRTNotify() { |
609 |
|
RTNotifyMutex.Lock(); |
610 |
|
} |
611 |
|
|
612 |
|
void LSCPServer::UnlockRTNotify() { |
613 |
|
RTNotifyMutex.Unlock(); |
614 |
|
} |
615 |
|
|
616 |
|
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
617 |
|
int subs = 0; |
618 |
|
SubscriptionMutex.Lock(); |
619 |
|
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
620 |
|
iter != events.end(); iter++) |
621 |
|
{ |
622 |
|
subs += eventSubscriptions.count(*iter); |
623 |
|
} |
624 |
|
SubscriptionMutex.Unlock(); |
625 |
|
return subs; |
626 |
|
} |
627 |
|
|
628 |
|
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
629 |
|
SubscriptionMutex.Lock(); |
630 |
|
if (eventSubscriptions.count(event.GetType()) == 0) { |
631 |
|
SubscriptionMutex.Unlock(); //Nobody is subscribed to this event |
632 |
|
return; |
633 |
|
} |
634 |
|
std::list<int>::iterator iter = eventSubscriptions[event.GetType()].begin(); |
635 |
|
std::list<int>::iterator end = eventSubscriptions[event.GetType()].end(); |
636 |
|
String notify = event.Produce(); |
637 |
|
|
638 |
|
while (true) { |
639 |
|
if (NotifyMutex.Trylock()) { |
640 |
|
for(;iter != end; iter++) |
641 |
|
#ifdef MSG_NOSIGNAL |
642 |
|
send(*iter, notify.c_str(), notify.size(), MSG_NOSIGNAL); |
643 |
|
#else |
644 |
|
send(*iter, notify.c_str(), notify.size(), 0); |
645 |
|
#endif |
646 |
|
NotifyMutex.Unlock(); |
647 |
|
break; |
648 |
|
} else { |
649 |
|
if (NotifyBufferMutex.Trylock()) { |
650 |
|
for(;iter != end; iter++) |
651 |
|
bufferedNotifies[*iter] += notify; |
652 |
|
NotifyBufferMutex.Unlock(); |
653 |
|
break; |
654 |
|
} |
655 |
|
} |
656 |
|
} |
657 |
|
SubscriptionMutex.Unlock(); |
658 |
|
} |
659 |
|
|
660 |
|
extern int GetLSCPCommand( void *buf, int max_size ) { |
661 |
|
String command = LSCPServer::bufferedCommands[LSCPServer::currentSocket]; |
662 |
|
if (command.size() == 0) { //Parser wants input but we have nothing. |
663 |
|
strcpy((char*) buf, "\n"); //So give it an empty command |
664 |
|
return 1; //to keep it happy. |
665 |
|
} |
666 |
|
|
667 |
|
if (max_size < command.size()) { |
668 |
|
std::cerr << "getLSCPCommand: Flex buffer too small, ignoring the command." << std::endl; |
669 |
|
return 0; //This will never happen |
670 |
|
} |
671 |
|
|
672 |
|
strcpy((char*) buf, command.c_str()); |
673 |
|
LSCPServer::bufferedCommands.erase(LSCPServer::currentSocket); |
674 |
|
return command.size(); |
675 |
|
} |
676 |
|
|
677 |
|
extern yyparse_param_t* GetCurrentYaccSession() { |
678 |
|
return &(*itCurrentSession); |
679 |
|
} |
680 |
|
|
681 |
|
/** |
682 |
|
* Will be called to try to read the command from the socket |
683 |
|
* If command is read, it will return true. Otherwise false is returned. |
684 |
|
* In any case the received portion (complete or incomplete) is saved into bufferedCommand map. |
685 |
|
*/ |
686 |
|
bool LSCPServer::GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ) { |
687 |
|
int socket = (*iter).hSession; |
688 |
|
char c; |
689 |
|
int i = 0; |
690 |
|
while (true) { |
691 |
|
#if defined(WIN32) |
692 |
|
int result = recv(socket, (char *)&c, 1, 0); //Read one character at a time for now |
693 |
|
#else |
694 |
|
int result = recv(socket, (void *)&c, 1, 0); //Read one character at a time for now |
695 |
|
#endif |
696 |
|
if (result == 0) { //socket was selected, so 0 here means client has closed the connection |
697 |
|
CloseConnection(iter); |
698 |
|
break; |
699 |
|
} |
700 |
|
if (result == 1) { |
701 |
|
if (c == '\r') |
702 |
|
continue; //Ignore CR |
703 |
|
if (c == '\n') { |
704 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket)); |
705 |
|
bufferedCommands[socket] += "\r\n"; |
706 |
|
return true; //Complete command was read |
707 |
|
} |
708 |
|
bufferedCommands[socket] += c; |
709 |
|
} |
710 |
|
#if defined(WIN32) |
711 |
|
if (result == SOCKET_ERROR) { |
712 |
|
int wsa_lasterror = WSAGetLastError(); |
713 |
|
if (wsa_lasterror == WSAEWOULDBLOCK) //Would block, try again later. |
714 |
|
return false; |
715 |
|
dmsg(2,("LSCPScanner: Socket error after recv() Error %d.\n", wsa_lasterror)); |
716 |
|
CloseConnection(iter); |
717 |
|
break; |
718 |
|
} |
719 |
|
#else |
720 |
|
if (result == -1) { |
721 |
|
if (errno == EAGAIN) //Would block, try again later. |
722 |
|
return false; |
723 |
|
switch(errno) { |
724 |
|
case EBADF: |
725 |
|
dmsg(2,("LSCPScanner: The argument s is an invalid descriptor.\n")); |
726 |
|
break; |
727 |
|
case ECONNREFUSED: |
728 |
|
dmsg(2,("LSCPScanner: A remote host refused to allow the network connection (typically because it is not running the requested service).\n")); |
729 |
|
break; |
730 |
|
case ENOTCONN: |
731 |
|
dmsg(2,("LSCPScanner: The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2)).\n")); |
732 |
|
break; |
733 |
|
case ENOTSOCK: |
734 |
|
dmsg(2,("LSCPScanner: The argument s does not refer to a socket.\n")); |
735 |
|
break; |
736 |
|
case EAGAIN: |
737 |
|
dmsg(2,("LSCPScanner: The socket is marked non-blocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received.\n")); |
738 |
|
break; |
739 |
|
case EINTR: |
740 |
|
dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n")); |
741 |
|
break; |
742 |
|
case EFAULT: |
743 |
|
dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n")); |
744 |
|
break; |
745 |
|
case EINVAL: |
746 |
|
dmsg(2,("LSCPScanner: Invalid argument passed.\n")); |
747 |
|
break; |
748 |
|
case ENOMEM: |
749 |
|
dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n")); |
750 |
|
break; |
751 |
|
default: |
752 |
|
dmsg(2,("LSCPScanner: Unknown recv() error.\n")); |
753 |
|
break; |
754 |
|
} |
755 |
|
CloseConnection(iter); |
756 |
|
break; |
757 |
|
} |
758 |
|
#endif |
759 |
|
} |
760 |
|
return false; |
761 |
} |
} |
762 |
|
|
763 |
/** |
/** |
768 |
*/ |
*/ |
769 |
void LSCPServer::AnswerClient(String ReturnMessage) { |
void LSCPServer::AnswerClient(String ReturnMessage) { |
770 |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
771 |
send(hSession, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
if (currentSocket != -1) { |
772 |
|
NotifyMutex.Lock(); |
773 |
|
#ifdef MSG_NOSIGNAL |
774 |
|
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL); |
775 |
|
#else |
776 |
|
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
777 |
|
#endif |
778 |
|
NotifyMutex.Unlock(); |
779 |
|
} |
780 |
|
} |
781 |
|
|
782 |
|
/** |
783 |
|
* Find a created audio output device index. |
784 |
|
*/ |
785 |
|
int LSCPServer::GetAudioOutputDeviceIndex ( AudioOutputDevice *pDevice ) |
786 |
|
{ |
787 |
|
// Search for the created device to get its index |
788 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
789 |
|
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
790 |
|
for (; iter != devices.end(); iter++) { |
791 |
|
if (iter->second == pDevice) |
792 |
|
return iter->first; |
793 |
|
} |
794 |
|
// Not found. |
795 |
|
return -1; |
796 |
|
} |
797 |
|
|
798 |
|
/** |
799 |
|
* Find a created midi input device index. |
800 |
|
*/ |
801 |
|
int LSCPServer::GetMidiInputDeviceIndex ( MidiInputDevice *pDevice ) |
802 |
|
{ |
803 |
|
// Search for the created device to get its index |
804 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
805 |
|
std::map<uint, MidiInputDevice*>::iterator iter = devices.begin(); |
806 |
|
for (; iter != devices.end(); iter++) { |
807 |
|
if (iter->second == pDevice) |
808 |
|
return iter->first; |
809 |
|
} |
810 |
|
// Not found. |
811 |
|
return -1; |
812 |
|
} |
813 |
|
|
814 |
|
String LSCPServer::CreateAudioOutputDevice(String Driver, std::map<String,String> Parameters) { |
815 |
|
dmsg(2,("LSCPServer: CreateAudioOutputDevice(Driver=%s)\n", Driver.c_str())); |
816 |
|
LSCPResultSet result; |
817 |
|
try { |
818 |
|
AudioOutputDevice* pDevice = pSampler->CreateAudioOutputDevice(Driver, Parameters); |
819 |
|
// search for the created device to get its index |
820 |
|
int index = GetAudioOutputDeviceIndex(pDevice); |
821 |
|
if (index == -1) throw Exception("Internal error: could not find created audio output device."); |
822 |
|
result = index; // success |
823 |
|
} |
824 |
|
catch (Exception e) { |
825 |
|
result.Error(e); |
826 |
|
} |
827 |
|
return result.Produce(); |
828 |
|
} |
829 |
|
|
830 |
|
String LSCPServer::CreateMidiInputDevice(String Driver, std::map<String,String> Parameters) { |
831 |
|
dmsg(2,("LSCPServer: CreateMidiInputDevice(Driver=%s)\n", Driver.c_str())); |
832 |
|
LSCPResultSet result; |
833 |
|
try { |
834 |
|
MidiInputDevice* pDevice = pSampler->CreateMidiInputDevice(Driver, Parameters); |
835 |
|
// search for the created device to get its index |
836 |
|
int index = GetMidiInputDeviceIndex(pDevice); |
837 |
|
if (index == -1) throw Exception("Internal error: could not find created midi input device."); |
838 |
|
result = index; // success |
839 |
|
} |
840 |
|
catch (Exception e) { |
841 |
|
result.Error(e); |
842 |
|
} |
843 |
|
return result.Produce(); |
844 |
|
} |
845 |
|
|
846 |
|
String LSCPServer::DestroyAudioOutputDevice(uint DeviceIndex) { |
847 |
|
dmsg(2,("LSCPServer: DestroyAudioOutputDevice(DeviceIndex=%d)\n", DeviceIndex)); |
848 |
|
LSCPResultSet result; |
849 |
|
try { |
850 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
851 |
|
if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
852 |
|
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
853 |
|
pSampler->DestroyAudioOutputDevice(pDevice); |
854 |
|
} |
855 |
|
catch (Exception e) { |
856 |
|
result.Error(e); |
857 |
|
} |
858 |
|
return result.Produce(); |
859 |
|
} |
860 |
|
|
861 |
|
String LSCPServer::DestroyMidiInputDevice(uint DeviceIndex) { |
862 |
|
dmsg(2,("LSCPServer: DestroyMidiInputDevice(DeviceIndex=%d)\n", DeviceIndex)); |
863 |
|
LSCPResultSet result; |
864 |
|
try { |
865 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
866 |
|
if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
867 |
|
MidiInputDevice* pDevice = devices[DeviceIndex]; |
868 |
|
pSampler->DestroyMidiInputDevice(pDevice); |
869 |
|
} |
870 |
|
catch (Exception e) { |
871 |
|
result.Error(e); |
872 |
|
} |
873 |
|
return result.Produce(); |
874 |
|
} |
875 |
|
|
876 |
|
EngineChannel* LSCPServer::GetEngineChannel(uint uiSamplerChannel) { |
877 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
878 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
879 |
|
|
880 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
881 |
|
if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); |
882 |
|
|
883 |
|
return pEngineChannel; |
884 |
} |
} |
885 |
|
|
886 |
/** |
/** |
887 |
* Will be called by the parser to load an instrument. |
* Will be called by the parser to load an instrument. |
888 |
*/ |
*/ |
889 |
String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel) { |
String LSCPServer::LoadInstrument(String Filename, uint uiInstrument, uint uiSamplerChannel, bool bBackground) { |
890 |
dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), uiInstrument, uiSamplerChannel)); |
dmsg(2,("LSCPServer: LoadInstrument(Filename=%s,Instrument=%d,SamplerChannel=%d)\n", Filename.c_str(), uiInstrument, uiSamplerChannel)); |
891 |
result_t result; |
LSCPResultSet result; |
892 |
try { |
try { |
893 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
894 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
895 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
896 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel yet"); |
897 |
pEngine->LoadInstrument(Filename.c_str(), uiInstrument); |
if (!pSamplerChannel->GetAudioOutputDevice()) |
898 |
result.type = result_type_success; |
throw Exception("No audio output device connected to sampler channel"); |
899 |
|
if (bBackground) { |
900 |
|
InstrumentManager::instrument_id_t id; |
901 |
|
id.FileName = Filename; |
902 |
|
id.Index = uiInstrument; |
903 |
|
InstrumentManager::LoadInstrumentInBackground(id, pEngineChannel); |
904 |
|
} |
905 |
|
else { |
906 |
|
// tell the engine channel which instrument to load |
907 |
|
pEngineChannel->PrepareLoadInstrument(Filename.c_str(), uiInstrument); |
908 |
|
// actually start to load the instrument (blocks until completed) |
909 |
|
pEngineChannel->LoadInstrument(); |
910 |
|
} |
911 |
} |
} |
912 |
catch (LinuxSamplerException e) { |
catch (Exception e) { |
913 |
e.PrintMessage(); |
result.Error(e); |
|
result.type = result_type_error; |
|
|
result.code = LSCP_ERR_UNKNOWN; |
|
|
result.message = e.Message(); |
|
914 |
} |
} |
915 |
return ConvertResult(result); |
return result.Produce(); |
916 |
} |
} |
917 |
|
|
918 |
/** |
/** |
919 |
* Will be called by the parser to load and deploy an engine. |
* Will be called by the parser to assign a sampler engine type to a |
920 |
|
* sampler channel. |
921 |
*/ |
*/ |
922 |
String LSCPServer::LoadEngine(String EngineName, uint uiSamplerChannel) { |
String LSCPServer::SetEngineType(String EngineName, uint uiSamplerChannel) { |
923 |
dmsg(2,("LSCPServer: LoadEngine(EngineName=%s,SamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetEngineType(EngineName=%s,uiSamplerChannel=%d)\n", EngineName.c_str(), uiSamplerChannel)); |
924 |
result_t result; |
LSCPResultSet result; |
925 |
try { |
try { |
|
engine_type_t type; |
|
|
if (EngineName == "gig") type = engine_type_gig; |
|
|
else throw LinuxSamplerException("Unknown engine type"); |
|
926 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
927 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
928 |
pSamplerChannel->LoadEngine(type); |
LockRTNotify(); |
929 |
result.type = result_type_success; |
pSamplerChannel->SetEngineType(EngineName); |
930 |
|
if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1); |
931 |
|
UnlockRTNotify(); |
932 |
} |
} |
933 |
catch (LinuxSamplerException e) { |
catch (Exception e) { |
934 |
e.PrintMessage(); |
result.Error(e); |
|
result.type = result_type_error; |
|
|
result.code = LSCP_ERR_UNKNOWN; |
|
|
result.message = e.Message(); |
|
935 |
} |
} |
936 |
return ConvertResult(result); |
return result.Produce(); |
937 |
} |
} |
938 |
|
|
939 |
/** |
/** |
941 |
*/ |
*/ |
942 |
String LSCPServer::GetChannels() { |
String LSCPServer::GetChannels() { |
943 |
dmsg(2,("LSCPServer: GetChannels()\n")); |
dmsg(2,("LSCPServer: GetChannels()\n")); |
944 |
return ToString(pSampler->SamplerChannels()) + "\r\n"; |
LSCPResultSet result; |
945 |
|
result.Add(pSampler->SamplerChannels()); |
946 |
|
return result.Produce(); |
947 |
|
} |
948 |
|
|
949 |
|
/** |
950 |
|
* Will be called by the parser to get the list of sampler channels. |
951 |
|
*/ |
952 |
|
String LSCPServer::ListChannels() { |
953 |
|
dmsg(2,("LSCPServer: ListChannels()\n")); |
954 |
|
String list; |
955 |
|
std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels(); |
956 |
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
957 |
|
for (; iter != channels.end(); iter++) { |
958 |
|
if (list != "") list += ","; |
959 |
|
list += ToString(iter->first); |
960 |
|
} |
961 |
|
LSCPResultSet result; |
962 |
|
result.Add(list); |
963 |
|
return result.Produce(); |
964 |
} |
} |
965 |
|
|
966 |
/** |
/** |
968 |
*/ |
*/ |
969 |
String LSCPServer::AddChannel() { |
String LSCPServer::AddChannel() { |
970 |
dmsg(2,("LSCPServer: AddChannel()\n")); |
dmsg(2,("LSCPServer: AddChannel()\n")); |
971 |
|
LockRTNotify(); |
972 |
SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel(); |
SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel(); |
973 |
return "OK[" + ToString(pSamplerChannel->Index()) + "]\r\n"; |
UnlockRTNotify(); |
974 |
|
LSCPResultSet result(pSamplerChannel->Index()); |
975 |
|
return result.Produce(); |
976 |
} |
} |
977 |
|
|
978 |
/** |
/** |
980 |
*/ |
*/ |
981 |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
982 |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
983 |
|
LSCPResultSet result; |
984 |
|
LockRTNotify(); |
985 |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
986 |
return "OK\r\n"; |
UnlockRTNotify(); |
987 |
|
return result.Produce(); |
988 |
} |
} |
989 |
|
|
990 |
/** |
/** |
991 |
* Will be called by the parser to get all available engines. |
* Will be called by the parser to get the amount of all available engines. |
992 |
*/ |
*/ |
993 |
String LSCPServer::GetAvailableEngines() { |
String LSCPServer::GetAvailableEngines() { |
994 |
dmsg(2,("LSCPServer: GetAvailableEngines()\n")); |
dmsg(2,("LSCPServer: GetAvailableEngines()\n")); |
995 |
return "gig\r\n"; |
LSCPResultSet result; |
996 |
|
try { |
997 |
|
int n = EngineFactory::AvailableEngineTypes().size(); |
998 |
|
result.Add(n); |
999 |
|
} |
1000 |
|
catch (Exception e) { |
1001 |
|
result.Error(e); |
1002 |
|
} |
1003 |
|
return result.Produce(); |
1004 |
|
} |
1005 |
|
|
1006 |
|
/** |
1007 |
|
* Will be called by the parser to get a list of all available engines. |
1008 |
|
*/ |
1009 |
|
String LSCPServer::ListAvailableEngines() { |
1010 |
|
dmsg(2,("LSCPServer: ListAvailableEngines()\n")); |
1011 |
|
LSCPResultSet result; |
1012 |
|
try { |
1013 |
|
String s = EngineFactory::AvailableEngineTypesAsString(); |
1014 |
|
result.Add(s); |
1015 |
|
} |
1016 |
|
catch (Exception e) { |
1017 |
|
result.Error(e); |
1018 |
|
} |
1019 |
|
return result.Produce(); |
1020 |
} |
} |
1021 |
|
|
1022 |
/** |
/** |
1023 |
* Will be called by the parser to get descriptions for a particular engine. |
* Will be called by the parser to get descriptions for a particular |
1024 |
|
* sampler engine. |
1025 |
*/ |
*/ |
1026 |
String LSCPServer::GetEngineInfo(String EngineName) { |
String LSCPServer::GetEngineInfo(String EngineName) { |
1027 |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
1028 |
result_t result; |
LSCPResultSet result; |
1029 |
|
LockRTNotify(); |
1030 |
try { |
try { |
1031 |
if (EngineName == "gig") { |
Engine* pEngine = EngineFactory::Create(EngineName); |
1032 |
Engine* pEngine = new LinuxSampler::gig::Engine; |
result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description())); |
1033 |
String info = pEngine->Description() + "\r\n"; |
result.Add("VERSION", pEngine->Version()); |
1034 |
delete pEngine; |
EngineFactory::Destroy(pEngine); |
|
return info; // success |
|
|
} |
|
|
else throw LinuxSamplerException("Unknown engine type"); |
|
|
} |
|
|
catch (LinuxSamplerException e) { |
|
|
e.PrintMessage(); |
|
|
result.type = result_type_error; |
|
|
result.code = LSCP_ERR_UNKNOWN; |
|
|
result.message = e.Message(); |
|
1035 |
} |
} |
1036 |
return ConvertResult(result); |
catch (Exception e) { |
1037 |
|
result.Error(e); |
1038 |
|
} |
1039 |
|
UnlockRTNotify(); |
1040 |
|
return result.Produce(); |
1041 |
} |
} |
1042 |
|
|
1043 |
/** |
/** |
1046 |
*/ |
*/ |
1047 |
String LSCPServer::GetChannelInfo(uint uiSamplerChannel) { |
String LSCPServer::GetChannelInfo(uint uiSamplerChannel) { |
1048 |
dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetChannelInfo(SamplerChannel=%d)\n", uiSamplerChannel)); |
1049 |
return "ERR:0:Not implemented yet.\r\n"; |
LSCPResultSet result; |
1050 |
|
try { |
1051 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1052 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1053 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1054 |
|
|
1055 |
|
//Defaults values |
1056 |
|
String EngineName = "NONE"; |
1057 |
|
float Volume = 0.0f; |
1058 |
|
String InstrumentFileName = "NONE"; |
1059 |
|
String InstrumentName = "NONE"; |
1060 |
|
int InstrumentIndex = -1; |
1061 |
|
int InstrumentStatus = -1; |
1062 |
|
int AudioOutputChannels = 0; |
1063 |
|
String AudioRouting; |
1064 |
|
int Mute = 0; |
1065 |
|
bool Solo = false; |
1066 |
|
String MidiInstrumentMap = "NONE"; |
1067 |
|
|
1068 |
|
if (pEngineChannel) { |
1069 |
|
EngineName = pEngineChannel->EngineName(); |
1070 |
|
AudioOutputChannels = pEngineChannel->Channels(); |
1071 |
|
Volume = pEngineChannel->Volume(); |
1072 |
|
InstrumentStatus = pEngineChannel->InstrumentStatus(); |
1073 |
|
InstrumentIndex = pEngineChannel->InstrumentIndex(); |
1074 |
|
if (InstrumentIndex != -1) { |
1075 |
|
InstrumentFileName = pEngineChannel->InstrumentFileName(); |
1076 |
|
InstrumentName = pEngineChannel->InstrumentName(); |
1077 |
|
} |
1078 |
|
for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { |
1079 |
|
if (AudioRouting != "") AudioRouting += ","; |
1080 |
|
AudioRouting += ToString(pEngineChannel->OutputChannel(chan)); |
1081 |
|
} |
1082 |
|
Mute = pEngineChannel->GetMute(); |
1083 |
|
Solo = pEngineChannel->GetSolo(); |
1084 |
|
if (pEngineChannel->UsesNoMidiInstrumentMap()) |
1085 |
|
MidiInstrumentMap = "NONE"; |
1086 |
|
else if (pEngineChannel->UsesDefaultMidiInstrumentMap()) |
1087 |
|
MidiInstrumentMap = "DEFAULT"; |
1088 |
|
else |
1089 |
|
MidiInstrumentMap = ToString(pEngineChannel->GetMidiInstrumentMap()); |
1090 |
|
} |
1091 |
|
|
1092 |
|
result.Add("ENGINE_NAME", EngineName); |
1093 |
|
result.Add("VOLUME", Volume); |
1094 |
|
|
1095 |
|
//Some not-so-hardcoded stuff to make GUI look good |
1096 |
|
result.Add("AUDIO_OUTPUT_DEVICE", GetAudioOutputDeviceIndex(pSamplerChannel->GetAudioOutputDevice())); |
1097 |
|
result.Add("AUDIO_OUTPUT_CHANNELS", AudioOutputChannels); |
1098 |
|
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
1099 |
|
|
1100 |
|
result.Add("MIDI_INPUT_DEVICE", GetMidiInputDeviceIndex(pSamplerChannel->GetMidiInputDevice())); |
1101 |
|
result.Add("MIDI_INPUT_PORT", pSamplerChannel->GetMidiInputPort()); |
1102 |
|
if (pSamplerChannel->GetMidiInputChannel() == midi_chan_all) result.Add("MIDI_INPUT_CHANNEL", "ALL"); |
1103 |
|
else result.Add("MIDI_INPUT_CHANNEL", pSamplerChannel->GetMidiInputChannel()); |
1104 |
|
|
1105 |
|
// convert the filename into the correct encoding as defined for LSCP |
1106 |
|
// (especially in terms of special characters -> escape sequences) |
1107 |
|
if (InstrumentFileName != "NONE" && InstrumentFileName != "") { |
1108 |
|
#if WIN32 |
1109 |
|
InstrumentFileName = Path::fromWindows(InstrumentFileName).toLscp(); |
1110 |
|
#else |
1111 |
|
// assuming POSIX |
1112 |
|
InstrumentFileName = Path::fromPosix(InstrumentFileName).toLscp(); |
1113 |
|
#endif |
1114 |
|
} |
1115 |
|
|
1116 |
|
result.Add("INSTRUMENT_FILE", InstrumentFileName); |
1117 |
|
result.Add("INSTRUMENT_NR", InstrumentIndex); |
1118 |
|
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(InstrumentName)); |
1119 |
|
result.Add("INSTRUMENT_STATUS", InstrumentStatus); |
1120 |
|
result.Add("MUTE", Mute == -1 ? "MUTED_BY_SOLO" : (Mute ? "true" : "false")); |
1121 |
|
result.Add("SOLO", Solo); |
1122 |
|
result.Add("MIDI_INSTRUMENT_MAP", MidiInstrumentMap); |
1123 |
|
} |
1124 |
|
catch (Exception e) { |
1125 |
|
result.Error(e); |
1126 |
|
} |
1127 |
|
return result.Produce(); |
1128 |
} |
} |
1129 |
|
|
1130 |
/** |
/** |
1133 |
*/ |
*/ |
1134 |
String LSCPServer::GetVoiceCount(uint uiSamplerChannel) { |
String LSCPServer::GetVoiceCount(uint uiSamplerChannel) { |
1135 |
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
1136 |
result_t result; |
LSCPResultSet result; |
1137 |
try { |
try { |
1138 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
1139 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
1140 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
|
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
|
|
return ToString(pEngine->VoiceCount()) + "\r\n"; // success |
|
1141 |
} |
} |
1142 |
catch (LinuxSamplerException e) { |
catch (Exception e) { |
1143 |
e.PrintMessage(); |
result.Error(e); |
|
result.type = result_type_error; |
|
|
result.code = LSCP_ERR_UNKNOWN; |
|
|
result.message = e.Message(); |
|
1144 |
} |
} |
1145 |
return ConvertResult(result); |
return result.Produce(); |
1146 |
} |
} |
1147 |
|
|
1148 |
/** |
/** |
1151 |
*/ |
*/ |
1152 |
String LSCPServer::GetStreamCount(uint uiSamplerChannel) { |
String LSCPServer::GetStreamCount(uint uiSamplerChannel) { |
1153 |
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
1154 |
result_t result; |
LSCPResultSet result; |
1155 |
try { |
try { |
1156 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
1157 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
1158 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
|
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
|
|
return ToString(pEngine->DiskStreamCount()) + "\r\n"; // success |
|
1159 |
} |
} |
1160 |
catch (LinuxSamplerException e) { |
catch (Exception e) { |
1161 |
e.PrintMessage(); |
result.Error(e); |
|
result.type = result_type_error; |
|
|
result.code = LSCP_ERR_UNKNOWN; |
|
|
result.message = e.Message(); |
|
1162 |
} |
} |
1163 |
return ConvertResult(result); |
return result.Produce(); |
1164 |
} |
} |
1165 |
|
|
1166 |
/** |
/** |
1169 |
*/ |
*/ |
1170 |
String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel) { |
String LSCPServer::GetBufferFill(fill_response_t ResponseType, uint uiSamplerChannel) { |
1171 |
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); |
1172 |
result_t result; |
LSCPResultSet result; |
1173 |
try { |
try { |
1174 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
1175 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
1176 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
1177 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
else { |
1178 |
if (!pEngine->DiskStreamSupported()) return "NA\r\n"; |
switch (ResponseType) { |
1179 |
switch (ResponseType) { |
case fill_response_bytes: |
1180 |
case fill_response_bytes: |
result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillBytes()); |
1181 |
return ToString(pEngine->DiskStreamBufferFillBytes()) + "\r\n"; // success |
break; |
1182 |
case fill_response_percentage: |
case fill_response_percentage: |
1183 |
return ToString(pEngine->DiskStreamBufferFillPercentage()) + "\r\n"; // success |
result.Add(pEngineChannel->GetEngine()->DiskStreamBufferFillPercentage()); |
1184 |
default: |
break; |
1185 |
throw LinuxSamplerException("Unknown fill response type"); |
default: |
1186 |
|
throw Exception("Unknown fill response type"); |
1187 |
|
} |
1188 |
|
} |
1189 |
|
} |
1190 |
|
catch (Exception e) { |
1191 |
|
result.Error(e); |
1192 |
|
} |
1193 |
|
return result.Produce(); |
1194 |
|
} |
1195 |
|
|
1196 |
|
String LSCPServer::GetAvailableAudioOutputDrivers() { |
1197 |
|
dmsg(2,("LSCPServer: GetAvailableAudioOutputDrivers()\n")); |
1198 |
|
LSCPResultSet result; |
1199 |
|
try { |
1200 |
|
int n = AudioOutputDeviceFactory::AvailableDrivers().size(); |
1201 |
|
result.Add(n); |
1202 |
|
} |
1203 |
|
catch (Exception e) { |
1204 |
|
result.Error(e); |
1205 |
|
} |
1206 |
|
return result.Produce(); |
1207 |
|
} |
1208 |
|
|
1209 |
|
String LSCPServer::ListAvailableAudioOutputDrivers() { |
1210 |
|
dmsg(2,("LSCPServer: ListAvailableAudioOutputDrivers()\n")); |
1211 |
|
LSCPResultSet result; |
1212 |
|
try { |
1213 |
|
String s = AudioOutputDeviceFactory::AvailableDriversAsString(); |
1214 |
|
result.Add(s); |
1215 |
|
} |
1216 |
|
catch (Exception e) { |
1217 |
|
result.Error(e); |
1218 |
|
} |
1219 |
|
return result.Produce(); |
1220 |
|
} |
1221 |
|
|
1222 |
|
String LSCPServer::GetAvailableMidiInputDrivers() { |
1223 |
|
dmsg(2,("LSCPServer: GetAvailableMidiInputDrivers()\n")); |
1224 |
|
LSCPResultSet result; |
1225 |
|
try { |
1226 |
|
int n = MidiInputDeviceFactory::AvailableDrivers().size(); |
1227 |
|
result.Add(n); |
1228 |
|
} |
1229 |
|
catch (Exception e) { |
1230 |
|
result.Error(e); |
1231 |
|
} |
1232 |
|
return result.Produce(); |
1233 |
|
} |
1234 |
|
|
1235 |
|
String LSCPServer::ListAvailableMidiInputDrivers() { |
1236 |
|
dmsg(2,("LSCPServer: ListAvailableMidiInputDrivers()\n")); |
1237 |
|
LSCPResultSet result; |
1238 |
|
try { |
1239 |
|
String s = MidiInputDeviceFactory::AvailableDriversAsString(); |
1240 |
|
result.Add(s); |
1241 |
|
} |
1242 |
|
catch (Exception e) { |
1243 |
|
result.Error(e); |
1244 |
|
} |
1245 |
|
return result.Produce(); |
1246 |
|
} |
1247 |
|
|
1248 |
|
String LSCPServer::GetMidiInputDriverInfo(String Driver) { |
1249 |
|
dmsg(2,("LSCPServer: GetMidiInputDriverInfo(Driver=%s)\n",Driver.c_str())); |
1250 |
|
LSCPResultSet result; |
1251 |
|
try { |
1252 |
|
result.Add("DESCRIPTION", MidiInputDeviceFactory::GetDriverDescription(Driver)); |
1253 |
|
result.Add("VERSION", MidiInputDeviceFactory::GetDriverVersion(Driver)); |
1254 |
|
|
1255 |
|
std::map<String,DeviceCreationParameter*> parameters = MidiInputDeviceFactory::GetAvailableDriverParameters(Driver); |
1256 |
|
if (parameters.size()) { // if there are parameters defined for this driver |
1257 |
|
String s; |
1258 |
|
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
1259 |
|
for (;iter != parameters.end(); iter++) { |
1260 |
|
if (s != "") s += ","; |
1261 |
|
s += iter->first; |
1262 |
|
} |
1263 |
|
result.Add("PARAMETERS", s); |
1264 |
} |
} |
1265 |
} |
} |
1266 |
catch (LinuxSamplerException e) { |
catch (Exception e) { |
1267 |
e.PrintMessage(); |
result.Error(e); |
|
result.type = result_type_error; |
|
|
result.code = LSCP_ERR_UNKNOWN; |
|
|
result.message = e.Message(); |
|
1268 |
} |
} |
1269 |
return ConvertResult(result); |
return result.Produce(); |
1270 |
} |
} |
1271 |
|
|
1272 |
/** |
String LSCPServer::GetAudioOutputDriverInfo(String Driver) { |
1273 |
* Will be called by the parser to change the audio output type on a |
dmsg(2,("LSCPServer: GetAudioOutputDriverInfo(Driver=%s)\n",Driver.c_str())); |
1274 |
* particular sampler channel. |
LSCPResultSet result; |
1275 |
*/ |
try { |
1276 |
String LSCPServer::SetAudioOutputType(audio_output_type_t AudioOutputType, uint uiSamplerChannel) { |
result.Add("DESCRIPTION", AudioOutputDeviceFactory::GetDriverDescription(Driver)); |
1277 |
dmsg(2,("LSCPServer: SetAudioOutputType(AudioOutputType=%d, SamplerChannel=%d)\n", AudioOutputType, uiSamplerChannel)); |
result.Add("VERSION", AudioOutputDeviceFactory::GetDriverVersion(Driver)); |
1278 |
result_t result; |
|
1279 |
try { |
std::map<String,DeviceCreationParameter*> parameters = AudioOutputDeviceFactory::GetAvailableDriverParameters(Driver); |
1280 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
if (parameters.size()) { // if there are parameters defined for this driver |
1281 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
String s; |
1282 |
pSamplerChannel->SetAudioOutputDevice(AudioOutputType); |
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
1283 |
result.type = result_type_success; |
for (;iter != parameters.end(); iter++) { |
1284 |
} |
if (s != "") s += ","; |
1285 |
catch (LinuxSamplerException e) { |
s += iter->first; |
1286 |
e.PrintMessage(); |
} |
1287 |
result.type = result_type_error; |
result.Add("PARAMETERS", s); |
1288 |
result.code = LSCP_ERR_UNKNOWN; |
} |
1289 |
result.message = e.Message(); |
} |
1290 |
|
catch (Exception e) { |
1291 |
|
result.Error(e); |
1292 |
|
} |
1293 |
|
return result.Produce(); |
1294 |
|
} |
1295 |
|
|
1296 |
|
String LSCPServer::GetMidiInputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
1297 |
|
dmsg(2,("LSCPServer: GetMidiInputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size())); |
1298 |
|
LSCPResultSet result; |
1299 |
|
try { |
1300 |
|
DeviceCreationParameter* pParameter = MidiInputDeviceFactory::GetDriverParameter(Driver, Parameter); |
1301 |
|
result.Add("TYPE", pParameter->Type()); |
1302 |
|
result.Add("DESCRIPTION", pParameter->Description()); |
1303 |
|
result.Add("MANDATORY", pParameter->Mandatory()); |
1304 |
|
result.Add("FIX", pParameter->Fix()); |
1305 |
|
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
1306 |
|
optional<String> oDepends = pParameter->Depends(); |
1307 |
|
optional<String> oDefault = pParameter->Default(DependencyList); |
1308 |
|
optional<String> oRangeMin = pParameter->RangeMin(DependencyList); |
1309 |
|
optional<String> oRangeMax = pParameter->RangeMax(DependencyList); |
1310 |
|
optional<String> oPossibilities = pParameter->Possibilities(DependencyList); |
1311 |
|
if (oDepends) result.Add("DEPENDS", *oDepends); |
1312 |
|
if (oDefault) result.Add("DEFAULT", *oDefault); |
1313 |
|
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1314 |
|
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1315 |
|
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1316 |
|
} |
1317 |
|
catch (Exception e) { |
1318 |
|
result.Error(e); |
1319 |
|
} |
1320 |
|
return result.Produce(); |
1321 |
|
} |
1322 |
|
|
1323 |
|
String LSCPServer::GetAudioOutputDriverParameterInfo(String Driver, String Parameter, std::map<String,String> DependencyList) { |
1324 |
|
dmsg(2,("LSCPServer: GetAudioOutputDriverParameterInfo(Driver=%s,Parameter=%s,DependencyListSize=%d)\n",Driver.c_str(),Parameter.c_str(),DependencyList.size())); |
1325 |
|
LSCPResultSet result; |
1326 |
|
try { |
1327 |
|
DeviceCreationParameter* pParameter = AudioOutputDeviceFactory::GetDriverParameter(Driver, Parameter); |
1328 |
|
result.Add("TYPE", pParameter->Type()); |
1329 |
|
result.Add("DESCRIPTION", pParameter->Description()); |
1330 |
|
result.Add("MANDATORY", pParameter->Mandatory()); |
1331 |
|
result.Add("FIX", pParameter->Fix()); |
1332 |
|
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
1333 |
|
optional<String> oDepends = pParameter->Depends(); |
1334 |
|
optional<String> oDefault = pParameter->Default(DependencyList); |
1335 |
|
optional<String> oRangeMin = pParameter->RangeMin(DependencyList); |
1336 |
|
optional<String> oRangeMax = pParameter->RangeMax(DependencyList); |
1337 |
|
optional<String> oPossibilities = pParameter->Possibilities(DependencyList); |
1338 |
|
if (oDepends) result.Add("DEPENDS", *oDepends); |
1339 |
|
if (oDefault) result.Add("DEFAULT", *oDefault); |
1340 |
|
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1341 |
|
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1342 |
|
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1343 |
|
} |
1344 |
|
catch (Exception e) { |
1345 |
|
result.Error(e); |
1346 |
|
} |
1347 |
|
return result.Produce(); |
1348 |
|
} |
1349 |
|
|
1350 |
|
String LSCPServer::GetAudioOutputDeviceCount() { |
1351 |
|
dmsg(2,("LSCPServer: GetAudioOutputDeviceCount()\n")); |
1352 |
|
LSCPResultSet result; |
1353 |
|
try { |
1354 |
|
uint count = pSampler->AudioOutputDevices(); |
1355 |
|
result.Add(count); // success |
1356 |
|
} |
1357 |
|
catch (Exception e) { |
1358 |
|
result.Error(e); |
1359 |
|
} |
1360 |
|
return result.Produce(); |
1361 |
|
} |
1362 |
|
|
1363 |
|
String LSCPServer::GetMidiInputDeviceCount() { |
1364 |
|
dmsg(2,("LSCPServer: GetMidiInputDeviceCount()\n")); |
1365 |
|
LSCPResultSet result; |
1366 |
|
try { |
1367 |
|
uint count = pSampler->MidiInputDevices(); |
1368 |
|
result.Add(count); // success |
1369 |
|
} |
1370 |
|
catch (Exception e) { |
1371 |
|
result.Error(e); |
1372 |
|
} |
1373 |
|
return result.Produce(); |
1374 |
|
} |
1375 |
|
|
1376 |
|
String LSCPServer::GetAudioOutputDevices() { |
1377 |
|
dmsg(2,("LSCPServer: GetAudioOutputDevices()\n")); |
1378 |
|
LSCPResultSet result; |
1379 |
|
try { |
1380 |
|
String s; |
1381 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1382 |
|
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
1383 |
|
for (; iter != devices.end(); iter++) { |
1384 |
|
if (s != "") s += ","; |
1385 |
|
s += ToString(iter->first); |
1386 |
|
} |
1387 |
|
result.Add(s); |
1388 |
|
} |
1389 |
|
catch (Exception e) { |
1390 |
|
result.Error(e); |
1391 |
|
} |
1392 |
|
return result.Produce(); |
1393 |
|
} |
1394 |
|
|
1395 |
|
String LSCPServer::GetMidiInputDevices() { |
1396 |
|
dmsg(2,("LSCPServer: GetMidiInputDevices()\n")); |
1397 |
|
LSCPResultSet result; |
1398 |
|
try { |
1399 |
|
String s; |
1400 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1401 |
|
std::map<uint, MidiInputDevice*>::iterator iter = devices.begin(); |
1402 |
|
for (; iter != devices.end(); iter++) { |
1403 |
|
if (s != "") s += ","; |
1404 |
|
s += ToString(iter->first); |
1405 |
|
} |
1406 |
|
result.Add(s); |
1407 |
|
} |
1408 |
|
catch (Exception e) { |
1409 |
|
result.Error(e); |
1410 |
|
} |
1411 |
|
return result.Produce(); |
1412 |
|
} |
1413 |
|
|
1414 |
|
String LSCPServer::GetAudioOutputDeviceInfo(uint DeviceIndex) { |
1415 |
|
dmsg(2,("LSCPServer: GetAudioOutputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex)); |
1416 |
|
LSCPResultSet result; |
1417 |
|
try { |
1418 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1419 |
|
if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
1420 |
|
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
1421 |
|
result.Add("DRIVER", pDevice->Driver()); |
1422 |
|
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1423 |
|
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
1424 |
|
for (; iter != parameters.end(); iter++) { |
1425 |
|
result.Add(iter->first, iter->second->Value()); |
1426 |
|
} |
1427 |
|
} |
1428 |
|
catch (Exception e) { |
1429 |
|
result.Error(e); |
1430 |
|
} |
1431 |
|
return result.Produce(); |
1432 |
|
} |
1433 |
|
|
1434 |
|
String LSCPServer::GetMidiInputDeviceInfo(uint DeviceIndex) { |
1435 |
|
dmsg(2,("LSCPServer: GetMidiInputDeviceInfo(DeviceIndex=%d)\n",DeviceIndex)); |
1436 |
|
LSCPResultSet result; |
1437 |
|
try { |
1438 |
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1439 |
|
if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
1440 |
|
MidiInputDevice* pDevice = devices[DeviceIndex]; |
1441 |
|
result.Add("DRIVER", pDevice->Driver()); |
1442 |
|
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1443 |
|
std::map<String,DeviceCreationParameter*>::iterator iter = parameters.begin(); |
1444 |
|
for (; iter != parameters.end(); iter++) { |
1445 |
|
result.Add(iter->first, iter->second->Value()); |
1446 |
|
} |
1447 |
|
} |
1448 |
|
catch (Exception e) { |
1449 |
|
result.Error(e); |
1450 |
|
} |
1451 |
|
return result.Produce(); |
1452 |
|
} |
1453 |
|
String LSCPServer::GetMidiInputPortInfo(uint DeviceIndex, uint PortIndex) { |
1454 |
|
dmsg(2,("LSCPServer: GetMidiInputPortInfo(DeviceIndex=%d, PortIndex=%d)\n",DeviceIndex, PortIndex)); |
1455 |
|
LSCPResultSet result; |
1456 |
|
try { |
1457 |
|
// get MIDI input device |
1458 |
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1459 |
|
if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
1460 |
|
MidiInputDevice* pDevice = devices[DeviceIndex]; |
1461 |
|
|
1462 |
|
// get MIDI port |
1463 |
|
MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
1464 |
|
if (!pMidiInputPort) throw Exception("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
1465 |
|
|
1466 |
|
// return the values of all MIDI port parameters |
1467 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters(); |
1468 |
|
std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin(); |
1469 |
|
for (; iter != parameters.end(); iter++) { |
1470 |
|
result.Add(iter->first, iter->second->Value()); |
1471 |
|
} |
1472 |
|
} |
1473 |
|
catch (Exception e) { |
1474 |
|
result.Error(e); |
1475 |
|
} |
1476 |
|
return result.Produce(); |
1477 |
|
} |
1478 |
|
|
1479 |
|
String LSCPServer::GetAudioOutputChannelInfo(uint DeviceId, uint ChannelId) { |
1480 |
|
dmsg(2,("LSCPServer: GetAudioOutputChannelInfo(DeviceId=%d,ChannelId)\n",DeviceId,ChannelId)); |
1481 |
|
LSCPResultSet result; |
1482 |
|
try { |
1483 |
|
// get audio output device |
1484 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1485 |
|
if (!devices.count(DeviceId)) throw Exception("There is no audio output device with index " + ToString(DeviceId) + "."); |
1486 |
|
AudioOutputDevice* pDevice = devices[DeviceId]; |
1487 |
|
|
1488 |
|
// get audio channel |
1489 |
|
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1490 |
|
if (!pChannel) throw Exception("Audio output device does not have audio channel " + ToString(ChannelId) + "."); |
1491 |
|
|
1492 |
|
// return the values of all audio channel parameters |
1493 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1494 |
|
std::map<String,DeviceRuntimeParameter*>::iterator iter = parameters.begin(); |
1495 |
|
for (; iter != parameters.end(); iter++) { |
1496 |
|
result.Add(iter->first, iter->second->Value()); |
1497 |
|
} |
1498 |
|
} |
1499 |
|
catch (Exception e) { |
1500 |
|
result.Error(e); |
1501 |
} |
} |
1502 |
return ConvertResult(result); |
return result.Produce(); |
1503 |
|
} |
1504 |
|
|
1505 |
|
String LSCPServer::GetMidiInputPortParameterInfo(uint DeviceId, uint PortId, String ParameterName) { |
1506 |
|
dmsg(2,("LSCPServer: GetMidiInputPortParameterInfo(DeviceId=%d,PortId=%d,ParameterName=%s)\n",DeviceId,PortId,ParameterName.c_str())); |
1507 |
|
LSCPResultSet result; |
1508 |
|
try { |
1509 |
|
// get MIDI input device |
1510 |
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1511 |
|
if (!devices.count(DeviceId)) throw Exception("There is no midi input device with index " + ToString(DeviceId) + "."); |
1512 |
|
MidiInputDevice* pDevice = devices[DeviceId]; |
1513 |
|
|
1514 |
|
// get midi port |
1515 |
|
MidiInputPort* pPort = pDevice->GetPort(PortId); |
1516 |
|
if (!pPort) throw Exception("Midi input device does not have port " + ToString(PortId) + "."); |
1517 |
|
|
1518 |
|
// get desired port parameter |
1519 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pPort->PortParameters(); |
1520 |
|
if (!parameters.count(ParameterName)) throw Exception("Midi port does not provide a parameter '" + ParameterName + "'."); |
1521 |
|
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
1522 |
|
|
1523 |
|
// return all fields of this audio channel parameter |
1524 |
|
result.Add("TYPE", pParameter->Type()); |
1525 |
|
result.Add("DESCRIPTION", pParameter->Description()); |
1526 |
|
result.Add("FIX", pParameter->Fix()); |
1527 |
|
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
1528 |
|
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
1529 |
|
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
1530 |
|
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
1531 |
|
} |
1532 |
|
catch (Exception e) { |
1533 |
|
result.Error(e); |
1534 |
|
} |
1535 |
|
return result.Produce(); |
1536 |
|
} |
1537 |
|
|
1538 |
|
String LSCPServer::GetAudioOutputChannelParameterInfo(uint DeviceId, uint ChannelId, String ParameterName) { |
1539 |
|
dmsg(2,("LSCPServer: GetAudioOutputChannelParameterInfo(DeviceId=%d,ChannelId=%d,ParameterName=%s)\n",DeviceId,ChannelId,ParameterName.c_str())); |
1540 |
|
LSCPResultSet result; |
1541 |
|
try { |
1542 |
|
// get audio output device |
1543 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1544 |
|
if (!devices.count(DeviceId)) throw Exception("There is no audio output device with index " + ToString(DeviceId) + "."); |
1545 |
|
AudioOutputDevice* pDevice = devices[DeviceId]; |
1546 |
|
|
1547 |
|
// get audio channel |
1548 |
|
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1549 |
|
if (!pChannel) throw Exception("Audio output device does not have audio channel " + ToString(ChannelId) + "."); |
1550 |
|
|
1551 |
|
// get desired audio channel parameter |
1552 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1553 |
|
if (!parameters.count(ParameterName)) throw Exception("Audio channel does not provide a parameter '" + ParameterName + "'."); |
1554 |
|
DeviceRuntimeParameter* pParameter = parameters[ParameterName]; |
1555 |
|
|
1556 |
|
// return all fields of this audio channel parameter |
1557 |
|
result.Add("TYPE", pParameter->Type()); |
1558 |
|
result.Add("DESCRIPTION", pParameter->Description()); |
1559 |
|
result.Add("FIX", pParameter->Fix()); |
1560 |
|
result.Add("MULTIPLICITY", pParameter->Multiplicity()); |
1561 |
|
if (pParameter->RangeMin()) result.Add("RANGE_MIN", *pParameter->RangeMin()); |
1562 |
|
if (pParameter->RangeMax()) result.Add("RANGE_MAX", *pParameter->RangeMax()); |
1563 |
|
if (pParameter->Possibilities()) result.Add("POSSIBILITIES", *pParameter->Possibilities()); |
1564 |
|
} |
1565 |
|
catch (Exception e) { |
1566 |
|
result.Error(e); |
1567 |
|
} |
1568 |
|
return result.Produce(); |
1569 |
|
} |
1570 |
|
|
1571 |
|
String LSCPServer::SetAudioOutputChannelParameter(uint DeviceId, uint ChannelId, String ParamKey, String ParamVal) { |
1572 |
|
dmsg(2,("LSCPServer: SetAudioOutputChannelParameter(DeviceId=%d,ChannelId=%d,ParamKey=%s,ParamVal=%s)\n",DeviceId,ChannelId,ParamKey.c_str(),ParamVal.c_str())); |
1573 |
|
LSCPResultSet result; |
1574 |
|
try { |
1575 |
|
// get audio output device |
1576 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1577 |
|
if (!devices.count(DeviceId)) throw Exception("There is no audio output device with index " + ToString(DeviceId) + "."); |
1578 |
|
AudioOutputDevice* pDevice = devices[DeviceId]; |
1579 |
|
|
1580 |
|
// get audio channel |
1581 |
|
AudioChannel* pChannel = pDevice->Channel(ChannelId); |
1582 |
|
if (!pChannel) throw Exception("Audio output device does not have audio channel " + ToString(ChannelId) + "."); |
1583 |
|
|
1584 |
|
// get desired audio channel parameter |
1585 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pChannel->ChannelParameters(); |
1586 |
|
if (!parameters.count(ParamKey)) throw Exception("Audio channel does not provide a parameter '" + ParamKey + "'."); |
1587 |
|
DeviceRuntimeParameter* pParameter = parameters[ParamKey]; |
1588 |
|
|
1589 |
|
// set new channel parameter value |
1590 |
|
pParameter->SetValue(ParamVal); |
1591 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceId)); |
1592 |
|
} |
1593 |
|
catch (Exception e) { |
1594 |
|
result.Error(e); |
1595 |
|
} |
1596 |
|
return result.Produce(); |
1597 |
|
} |
1598 |
|
|
1599 |
|
String LSCPServer::SetAudioOutputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal) { |
1600 |
|
dmsg(2,("LSCPServer: SetAudioOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str())); |
1601 |
|
LSCPResultSet result; |
1602 |
|
try { |
1603 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1604 |
|
if (!devices.count(DeviceIndex)) throw Exception("There is no audio output device with index " + ToString(DeviceIndex) + "."); |
1605 |
|
AudioOutputDevice* pDevice = devices[DeviceIndex]; |
1606 |
|
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1607 |
|
if (!parameters.count(ParamKey)) throw Exception("Audio output device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
1608 |
|
parameters[ParamKey]->SetValue(ParamVal); |
1609 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_info, DeviceIndex)); |
1610 |
|
} |
1611 |
|
catch (Exception e) { |
1612 |
|
result.Error(e); |
1613 |
|
} |
1614 |
|
return result.Produce(); |
1615 |
|
} |
1616 |
|
|
1617 |
|
String LSCPServer::SetMidiInputDeviceParameter(uint DeviceIndex, String ParamKey, String ParamVal) { |
1618 |
|
dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str())); |
1619 |
|
LSCPResultSet result; |
1620 |
|
try { |
1621 |
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1622 |
|
if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
1623 |
|
MidiInputDevice* pDevice = devices[DeviceIndex]; |
1624 |
|
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1625 |
|
if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(DeviceIndex) + " does not have a device parameter '" + ParamKey + "'"); |
1626 |
|
parameters[ParamKey]->SetValue(ParamVal); |
1627 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex)); |
1628 |
|
} |
1629 |
|
catch (Exception e) { |
1630 |
|
result.Error(e); |
1631 |
|
} |
1632 |
|
return result.Produce(); |
1633 |
|
} |
1634 |
|
|
1635 |
|
String LSCPServer::SetMidiInputPortParameter(uint DeviceIndex, uint PortIndex, String ParamKey, String ParamVal) { |
1636 |
|
dmsg(2,("LSCPServer: SetMidiOutputDeviceParameter(DeviceIndex=%d,ParamKey=%s,ParamVal=%s)\n",DeviceIndex,ParamKey.c_str(),ParamVal.c_str())); |
1637 |
|
LSCPResultSet result; |
1638 |
|
try { |
1639 |
|
// get MIDI input device |
1640 |
|
std::map<uint,MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1641 |
|
if (!devices.count(DeviceIndex)) throw Exception("There is no MIDI input device with index " + ToString(DeviceIndex) + "."); |
1642 |
|
MidiInputDevice* pDevice = devices[DeviceIndex]; |
1643 |
|
|
1644 |
|
// get MIDI port |
1645 |
|
MidiInputPort* pMidiInputPort = pDevice->GetPort(PortIndex); |
1646 |
|
if (!pMidiInputPort) throw Exception("There is no MIDI input port with index " + ToString(PortIndex) + "."); |
1647 |
|
|
1648 |
|
// set port parameter value |
1649 |
|
std::map<String,DeviceRuntimeParameter*> parameters = pMidiInputPort->PortParameters(); |
1650 |
|
if (!parameters.count(ParamKey)) throw Exception("MIDI input device " + ToString(PortIndex) + " does not have a parameter '" + ParamKey + "'"); |
1651 |
|
parameters[ParamKey]->SetValue(ParamVal); |
1652 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_info, DeviceIndex)); |
1653 |
|
} |
1654 |
|
catch (Exception e) { |
1655 |
|
result.Error(e); |
1656 |
|
} |
1657 |
|
return result.Produce(); |
1658 |
} |
} |
1659 |
|
|
1660 |
/** |
/** |
1661 |
* Will be called by the parser to change the audio output channel for |
* Will be called by the parser to change the audio output channel for |
1662 |
* playback on a particular sampler channel. |
* playback on a particular sampler channel. |
1663 |
*/ |
*/ |
1664 |
String LSCPServer::SetAudioOutputChannel(uint AudioOutputChannel, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputChannel(uint ChannelAudioOutputChannel, uint AudioOutputDeviceInputChannel, uint uiSamplerChannel) { |
1665 |
dmsg(2,("LSCPServer: SetAudioOutputChannel(AudioOutputChannel=%d, SamplerChannel=%d)\n", AudioOutputChannel, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetAudioOutputChannel(ChannelAudioOutputChannel=%d, AudioOutputDeviceInputChannel=%d, SamplerChannel=%d)\n",ChannelAudioOutputChannel,AudioOutputDeviceInputChannel,uiSamplerChannel)); |
1666 |
return "ERR:0:Not implemented yet.\r\n"; |
LSCPResultSet result; |
1667 |
|
try { |
1668 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1669 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1670 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
1671 |
|
if (!pEngineChannel) throw Exception("No engine type yet assigned to sampler channel " + ToString(uiSamplerChannel)); |
1672 |
|
if (!pSamplerChannel->GetAudioOutputDevice()) throw Exception("No audio output device connected to sampler channel " + ToString(uiSamplerChannel)); |
1673 |
|
pEngineChannel->SetOutputChannel(ChannelAudioOutputChannel, AudioOutputDeviceInputChannel); |
1674 |
|
} |
1675 |
|
catch (Exception e) { |
1676 |
|
result.Error(e); |
1677 |
|
} |
1678 |
|
return result.Produce(); |
1679 |
|
} |
1680 |
|
|
1681 |
|
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
1682 |
|
dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel)); |
1683 |
|
LSCPResultSet result; |
1684 |
|
LockRTNotify(); |
1685 |
|
try { |
1686 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1687 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1688 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1689 |
|
if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId)); |
1690 |
|
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
1691 |
|
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1692 |
|
} |
1693 |
|
catch (Exception e) { |
1694 |
|
result.Error(e); |
1695 |
|
} |
1696 |
|
UnlockRTNotify(); |
1697 |
|
return result.Produce(); |
1698 |
|
} |
1699 |
|
|
1700 |
|
String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) { |
1701 |
|
dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel)); |
1702 |
|
LSCPResultSet result; |
1703 |
|
LockRTNotify(); |
1704 |
|
try { |
1705 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1706 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1707 |
|
// Driver type name aliasing... |
1708 |
|
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
1709 |
|
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
1710 |
|
// Check if there's one audio output device already created |
1711 |
|
// for the intended audio driver type (AudioOutputDriver)... |
1712 |
|
AudioOutputDevice *pDevice = NULL; |
1713 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1714 |
|
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
1715 |
|
for (; iter != devices.end(); iter++) { |
1716 |
|
if ((iter->second)->Driver() == AudioOutputDriver) { |
1717 |
|
pDevice = iter->second; |
1718 |
|
break; |
1719 |
|
} |
1720 |
|
} |
1721 |
|
// If it doesn't exist, create a new one with default parameters... |
1722 |
|
if (pDevice == NULL) { |
1723 |
|
std::map<String,String> params; |
1724 |
|
pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params); |
1725 |
|
} |
1726 |
|
// Must have a device... |
1727 |
|
if (pDevice == NULL) |
1728 |
|
throw Exception("Internal error: could not create audio output device."); |
1729 |
|
// Set it as the current channel device... |
1730 |
|
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1731 |
|
} |
1732 |
|
catch (Exception e) { |
1733 |
|
result.Error(e); |
1734 |
|
} |
1735 |
|
UnlockRTNotify(); |
1736 |
|
return result.Produce(); |
1737 |
|
} |
1738 |
|
|
1739 |
|
String LSCPServer::SetMIDIInputPort(uint MIDIPort, uint uiSamplerChannel) { |
1740 |
|
dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIPort=%d, SamplerChannel=%d)\n",MIDIPort,uiSamplerChannel)); |
1741 |
|
LSCPResultSet result; |
1742 |
|
try { |
1743 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1744 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1745 |
|
pSamplerChannel->SetMidiInputPort(MIDIPort); |
1746 |
|
} |
1747 |
|
catch (Exception e) { |
1748 |
|
result.Error(e); |
1749 |
|
} |
1750 |
|
return result.Produce(); |
1751 |
} |
} |
1752 |
|
|
1753 |
String LSCPServer::SetMIDIInputType(midi_input_type_t MidiInputType, uint uiSamplerChannel) { |
String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) { |
1754 |
dmsg(2,("LSCPServer: SetMIDIInputType(MidiInputType=%d, SamplerChannel=%d)\n", MidiInputType, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n",MIDIChannel,uiSamplerChannel)); |
1755 |
result_t result; |
LSCPResultSet result; |
1756 |
try { |
try { |
1757 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1758 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1759 |
pSamplerChannel->SetMidiInputDevice(MidiInputType); |
pSamplerChannel->SetMidiInputChannel((midi_chan_t) MIDIChannel); |
|
result.type = result_type_success; |
|
1760 |
} |
} |
1761 |
catch (LinuxSamplerException e) { |
catch (Exception e) { |
1762 |
e.PrintMessage(); |
result.Error(e); |
|
result.type = result_type_error; |
|
|
result.code = LSCP_ERR_UNKNOWN; |
|
|
result.message = e.Message(); |
|
1763 |
} |
} |
1764 |
return ConvertResult(result); |
return result.Produce(); |
1765 |
} |
} |
1766 |
|
|
1767 |
/** |
String LSCPServer::SetMIDIInputDevice(uint MIDIDeviceId, uint uiSamplerChannel) { |
1768 |
* Will be called by the parser to change the MIDI input port on which the |
dmsg(2,("LSCPServer: SetMIDIInputDevice(MIDIDeviceId=%d, SamplerChannel=%d)\n",MIDIDeviceId,uiSamplerChannel)); |
1769 |
* engine of a particular sampler channel should listen to. |
LSCPResultSet result; |
1770 |
*/ |
try { |
1771 |
String LSCPServer::SetMIDIInputPort(String MIDIInputPort, uint uiSamplerchannel) { |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1772 |
dmsg(2,("LSCPServer: SetMIDIInputPort(MIDIInputPort=%s, Samplerchannel=%d)\n", MIDIInputPort.c_str(), uiSamplerchannel)); |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1773 |
return "ERR:0:Not implemented yet.\r\n"; |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1774 |
|
if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1775 |
|
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1776 |
|
pSamplerChannel->SetMidiInputDevice(pDevice); |
1777 |
|
} |
1778 |
|
catch (Exception e) { |
1779 |
|
result.Error(e); |
1780 |
|
} |
1781 |
|
return result.Produce(); |
1782 |
|
} |
1783 |
|
|
1784 |
|
String LSCPServer::SetMIDIInputType(String MidiInputDriver, uint uiSamplerChannel) { |
1785 |
|
dmsg(2,("LSCPServer: SetMIDIInputType(String MidiInputDriver=%s, SamplerChannel=%d)\n",MidiInputDriver.c_str(),uiSamplerChannel)); |
1786 |
|
LSCPResultSet result; |
1787 |
|
try { |
1788 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1789 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1790 |
|
// Driver type name aliasing... |
1791 |
|
if (MidiInputDriver == "Alsa") MidiInputDriver = "ALSA"; |
1792 |
|
// Check if there's one MIDI input device already created |
1793 |
|
// for the intended MIDI driver type (MidiInputDriver)... |
1794 |
|
MidiInputDevice *pDevice = NULL; |
1795 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1796 |
|
std::map<uint, MidiInputDevice*>::iterator iter = devices.begin(); |
1797 |
|
for (; iter != devices.end(); iter++) { |
1798 |
|
if ((iter->second)->Driver() == MidiInputDriver) { |
1799 |
|
pDevice = iter->second; |
1800 |
|
break; |
1801 |
|
} |
1802 |
|
} |
1803 |
|
// If it doesn't exist, create a new one with default parameters... |
1804 |
|
if (pDevice == NULL) { |
1805 |
|
std::map<String,String> params; |
1806 |
|
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
1807 |
|
// Make it with at least one initial port. |
1808 |
|
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
1809 |
|
parameters["PORTS"]->SetValue("1"); |
1810 |
|
} |
1811 |
|
// Must have a device... |
1812 |
|
if (pDevice == NULL) |
1813 |
|
throw Exception("Internal error: could not create MIDI input device."); |
1814 |
|
// Set it as the current channel device... |
1815 |
|
pSamplerChannel->SetMidiInputDevice(pDevice); |
1816 |
|
} |
1817 |
|
catch (Exception e) { |
1818 |
|
result.Error(e); |
1819 |
|
} |
1820 |
|
return result.Produce(); |
1821 |
} |
} |
1822 |
|
|
1823 |
/** |
/** |
1824 |
* Will be called by the parser to change the MIDI input channel on which the |
* Will be called by the parser to change the MIDI input device, port and channel on which |
1825 |
* engine of a particular sampler channel should listen to. |
* engine of a particular sampler channel should listen to. |
1826 |
*/ |
*/ |
1827 |
String LSCPServer::SetMIDIInputChannel(uint MIDIChannel, uint uiSamplerChannel) { |
String LSCPServer::SetMIDIInput(uint MIDIDeviceId, uint MIDIPort, uint MIDIChannel, uint uiSamplerChannel) { |
1828 |
dmsg(2,("LSCPServer: SetMIDIInputChannel(MIDIChannel=%d, SamplerChannel=%d)\n", MIDIChannel, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetMIDIInput(MIDIDeviceId=%d, MIDIPort=%d, MIDIChannel=%d, SamplerChannel=%d)\n", MIDIDeviceId, MIDIPort, MIDIChannel, uiSamplerChannel)); |
1829 |
return "ERR:0:Not implemented yet.\r\n"; |
LSCPResultSet result; |
1830 |
|
try { |
1831 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1832 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1833 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1834 |
|
if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1835 |
|
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1836 |
|
pSamplerChannel->SetMidiInput(pDevice, MIDIPort, (midi_chan_t) MIDIChannel); |
1837 |
|
} |
1838 |
|
catch (Exception e) { |
1839 |
|
result.Error(e); |
1840 |
|
} |
1841 |
|
return result.Produce(); |
1842 |
} |
} |
1843 |
|
|
1844 |
/** |
/** |
1845 |
* Will be called by the parser to change the global volume factor on a |
* Will be called by the parser to change the global volume factor on a |
1846 |
* particular sampler channel. |
* particular sampler channel. |
1847 |
*/ |
*/ |
1848 |
String LSCPServer::SetVolume(double Volume, uint uiSamplerChannel) { |
String LSCPServer::SetVolume(double dVolume, uint uiSamplerChannel) { |
1849 |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", Volume, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
1850 |
result_t result; |
LSCPResultSet result; |
1851 |
try { |
try { |
1852 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
1853 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
pEngineChannel->Volume(dVolume); |
1854 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
} |
1855 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
catch (Exception e) { |
1856 |
pEngine->Volume(Volume); |
result.Error(e); |
1857 |
result.type = result_type_success; |
} |
1858 |
} |
return result.Produce(); |
1859 |
catch (LinuxSamplerException e) { |
} |
1860 |
e.PrintMessage(); |
|
1861 |
result.type = result_type_error; |
/** |
1862 |
result.code = LSCP_ERR_UNKNOWN; |
* Will be called by the parser to mute/unmute particular sampler channel. |
1863 |
result.message = e.Message(); |
*/ |
1864 |
|
String LSCPServer::SetChannelMute(bool bMute, uint uiSamplerChannel) { |
1865 |
|
dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); |
1866 |
|
LSCPResultSet result; |
1867 |
|
try { |
1868 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
1869 |
|
|
1870 |
|
if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); |
1871 |
|
else pEngineChannel->SetMute(1); |
1872 |
|
} catch (Exception e) { |
1873 |
|
result.Error(e); |
1874 |
|
} |
1875 |
|
return result.Produce(); |
1876 |
|
} |
1877 |
|
|
1878 |
|
/** |
1879 |
|
* Will be called by the parser to solo particular sampler channel. |
1880 |
|
*/ |
1881 |
|
String LSCPServer::SetChannelSolo(bool bSolo, uint uiSamplerChannel) { |
1882 |
|
dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel)); |
1883 |
|
LSCPResultSet result; |
1884 |
|
try { |
1885 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
1886 |
|
|
1887 |
|
bool oldSolo = pEngineChannel->GetSolo(); |
1888 |
|
bool hadSoloChannel = HasSoloChannel(); |
1889 |
|
|
1890 |
|
pEngineChannel->SetSolo(bSolo); |
1891 |
|
|
1892 |
|
if(!oldSolo && bSolo) { |
1893 |
|
if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0); |
1894 |
|
if(!hadSoloChannel) MuteNonSoloChannels(); |
1895 |
|
} |
1896 |
|
|
1897 |
|
if(oldSolo && !bSolo) { |
1898 |
|
if(!HasSoloChannel()) UnmuteChannels(); |
1899 |
|
else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1); |
1900 |
|
} |
1901 |
|
} catch (Exception e) { |
1902 |
|
result.Error(e); |
1903 |
|
} |
1904 |
|
return result.Produce(); |
1905 |
|
} |
1906 |
|
|
1907 |
|
/** |
1908 |
|
* Determines whether there is at least one solo channel in the channel list. |
1909 |
|
* |
1910 |
|
* @returns true if there is at least one solo channel in the channel list, |
1911 |
|
* false otherwise. |
1912 |
|
*/ |
1913 |
|
bool LSCPServer::HasSoloChannel() { |
1914 |
|
std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels(); |
1915 |
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
1916 |
|
for (; iter != channels.end(); iter++) { |
1917 |
|
EngineChannel* c = iter->second->GetEngineChannel(); |
1918 |
|
if(c && c->GetSolo()) return true; |
1919 |
|
} |
1920 |
|
|
1921 |
|
return false; |
1922 |
|
} |
1923 |
|
|
1924 |
|
/** |
1925 |
|
* Mutes all unmuted non-solo channels. Notice that the channels are muted |
1926 |
|
* with -1 which indicates that they are muted because of the presence |
1927 |
|
* of a solo channel(s). Channels muted with -1 will be automatically unmuted |
1928 |
|
* when there are no solo channels left. |
1929 |
|
*/ |
1930 |
|
void LSCPServer::MuteNonSoloChannels() { |
1931 |
|
dmsg(2,("LSCPServer: MuteNonSoloChannels()\n")); |
1932 |
|
std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels(); |
1933 |
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
1934 |
|
for (; iter != channels.end(); iter++) { |
1935 |
|
EngineChannel* c = iter->second->GetEngineChannel(); |
1936 |
|
if(c && !c->GetSolo() && !c->GetMute()) c->SetMute(-1); |
1937 |
|
} |
1938 |
|
} |
1939 |
|
|
1940 |
|
/** |
1941 |
|
* Unmutes all channels that are muted because of the presence |
1942 |
|
* of a solo channel(s). |
1943 |
|
*/ |
1944 |
|
void LSCPServer::UnmuteChannels() { |
1945 |
|
dmsg(2,("LSCPServer: UnmuteChannels()\n")); |
1946 |
|
std::map<uint,SamplerChannel*> channels = pSampler->GetSamplerChannels(); |
1947 |
|
std::map<uint,SamplerChannel*>::iterator iter = channels.begin(); |
1948 |
|
for (; iter != channels.end(); iter++) { |
1949 |
|
EngineChannel* c = iter->second->GetEngineChannel(); |
1950 |
|
if(c && c->GetMute() == -1) c->SetMute(0); |
1951 |
|
} |
1952 |
|
} |
1953 |
|
|
1954 |
|
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) { |
1955 |
|
dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n")); |
1956 |
|
|
1957 |
|
midi_prog_index_t idx; |
1958 |
|
idx.midi_bank_msb = (MidiBank >> 7) & 0x7f; |
1959 |
|
idx.midi_bank_lsb = MidiBank & 0x7f; |
1960 |
|
idx.midi_prog = MidiProg; |
1961 |
|
|
1962 |
|
MidiInstrumentMapper::entry_t entry; |
1963 |
|
entry.EngineName = EngineType; |
1964 |
|
entry.InstrumentFile = InstrumentFile; |
1965 |
|
entry.InstrumentIndex = InstrumentIndex; |
1966 |
|
entry.LoadMode = LoadMode; |
1967 |
|
entry.Volume = Volume; |
1968 |
|
entry.Name = Name; |
1969 |
|
|
1970 |
|
LSCPResultSet result; |
1971 |
|
try { |
1972 |
|
// PERSISTENT mapping commands might block for a long time, so in |
1973 |
|
// that case we add/replace the mapping in another thread in case |
1974 |
|
// the NON_MODAL argument was supplied, non persistent mappings |
1975 |
|
// should return immediately, so we don't need to do that for them |
1976 |
|
bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT && !bModal); |
1977 |
|
MidiInstrumentMapper::AddOrReplaceEntry(MidiMapID, idx, entry, bInBackground); |
1978 |
|
} catch (Exception e) { |
1979 |
|
result.Error(e); |
1980 |
|
} |
1981 |
|
return result.Produce(); |
1982 |
|
} |
1983 |
|
|
1984 |
|
String LSCPServer::RemoveMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) { |
1985 |
|
dmsg(2,("LSCPServer: RemoveMIDIInstrumentMapping()\n")); |
1986 |
|
|
1987 |
|
midi_prog_index_t idx; |
1988 |
|
idx.midi_bank_msb = (MidiBank >> 7) & 0x7f; |
1989 |
|
idx.midi_bank_lsb = MidiBank & 0x7f; |
1990 |
|
idx.midi_prog = MidiProg; |
1991 |
|
|
1992 |
|
LSCPResultSet result; |
1993 |
|
try { |
1994 |
|
MidiInstrumentMapper::RemoveEntry(MidiMapID, idx); |
1995 |
|
} catch (Exception e) { |
1996 |
|
result.Error(e); |
1997 |
|
} |
1998 |
|
return result.Produce(); |
1999 |
|
} |
2000 |
|
|
2001 |
|
String LSCPServer::GetMidiInstrumentMappings(uint MidiMapID) { |
2002 |
|
dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n")); |
2003 |
|
LSCPResultSet result; |
2004 |
|
try { |
2005 |
|
result.Add(MidiInstrumentMapper::GetInstrumentCount(MidiMapID)); |
2006 |
|
} catch (Exception e) { |
2007 |
|
result.Error(e); |
2008 |
|
} |
2009 |
|
return result.Produce(); |
2010 |
|
} |
2011 |
|
|
2012 |
|
|
2013 |
|
String LSCPServer::GetAllMidiInstrumentMappings() { |
2014 |
|
dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n")); |
2015 |
|
LSCPResultSet result; |
2016 |
|
try { |
2017 |
|
result.Add(MidiInstrumentMapper::GetInstrumentCount()); |
2018 |
|
} catch (Exception e) { |
2019 |
|
result.Error(e); |
2020 |
|
} |
2021 |
|
return result.Produce(); |
2022 |
|
} |
2023 |
|
|
2024 |
|
String LSCPServer::GetMidiInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg) { |
2025 |
|
dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n")); |
2026 |
|
LSCPResultSet result; |
2027 |
|
try { |
2028 |
|
MidiInstrumentMapper::entry_t entry = MidiInstrumentMapper::GetEntry(MidiMapID, MidiBank, MidiProg); |
2029 |
|
// convert the filename into the correct encoding as defined for LSCP |
2030 |
|
// (especially in terms of special characters -> escape sequences) |
2031 |
|
#if WIN32 |
2032 |
|
const String instrumentFileName = Path::fromWindows(entry.InstrumentFile).toLscp(); |
2033 |
|
#else |
2034 |
|
// assuming POSIX |
2035 |
|
const String instrumentFileName = Path::fromPosix(entry.InstrumentFile).toLscp(); |
2036 |
|
#endif |
2037 |
|
|
2038 |
|
result.Add("NAME", _escapeLscpResponse(entry.Name)); |
2039 |
|
result.Add("ENGINE_NAME", entry.EngineName); |
2040 |
|
result.Add("INSTRUMENT_FILE", instrumentFileName); |
2041 |
|
result.Add("INSTRUMENT_NR", (int) entry.InstrumentIndex); |
2042 |
|
String instrumentName; |
2043 |
|
Engine* pEngine = EngineFactory::Create(entry.EngineName); |
2044 |
|
if (pEngine) { |
2045 |
|
if (pEngine->GetInstrumentManager()) { |
2046 |
|
InstrumentManager::instrument_id_t instrID; |
2047 |
|
instrID.FileName = entry.InstrumentFile; |
2048 |
|
instrID.Index = entry.InstrumentIndex; |
2049 |
|
instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID); |
2050 |
|
} |
2051 |
|
EngineFactory::Destroy(pEngine); |
2052 |
|
} |
2053 |
|
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName)); |
2054 |
|
switch (entry.LoadMode) { |
2055 |
|
case MidiInstrumentMapper::ON_DEMAND: |
2056 |
|
result.Add("LOAD_MODE", "ON_DEMAND"); |
2057 |
|
break; |
2058 |
|
case MidiInstrumentMapper::ON_DEMAND_HOLD: |
2059 |
|
result.Add("LOAD_MODE", "ON_DEMAND_HOLD"); |
2060 |
|
break; |
2061 |
|
case MidiInstrumentMapper::PERSISTENT: |
2062 |
|
result.Add("LOAD_MODE", "PERSISTENT"); |
2063 |
|
break; |
2064 |
|
default: |
2065 |
|
throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!"); |
2066 |
|
} |
2067 |
|
result.Add("VOLUME", entry.Volume); |
2068 |
|
} catch (Exception e) { |
2069 |
|
result.Error(e); |
2070 |
|
} |
2071 |
|
return result.Produce(); |
2072 |
|
} |
2073 |
|
|
2074 |
|
String LSCPServer::ListMidiInstrumentMappings(uint MidiMapID) { |
2075 |
|
dmsg(2,("LSCPServer: ListMidiInstrumentMappings()\n")); |
2076 |
|
LSCPResultSet result; |
2077 |
|
try { |
2078 |
|
String s; |
2079 |
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID); |
2080 |
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin(); |
2081 |
|
for (; iter != mappings.end(); iter++) { |
2082 |
|
if (s.size()) s += ","; |
2083 |
|
s += "{" + ToString(MidiMapID) + "," |
2084 |
|
+ ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + "," |
2085 |
|
+ ToString(int(iter->first.midi_prog)) + "}"; |
2086 |
|
} |
2087 |
|
result.Add(s); |
2088 |
|
} catch (Exception e) { |
2089 |
|
result.Error(e); |
2090 |
|
} |
2091 |
|
return result.Produce(); |
2092 |
|
} |
2093 |
|
|
2094 |
|
String LSCPServer::ListAllMidiInstrumentMappings() { |
2095 |
|
dmsg(2,("LSCPServer: ListAllMidiInstrumentMappings()\n")); |
2096 |
|
LSCPResultSet result; |
2097 |
|
try { |
2098 |
|
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
2099 |
|
String s; |
2100 |
|
for (int i = 0; i < maps.size(); i++) { |
2101 |
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(maps[i]); |
2102 |
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.begin(); |
2103 |
|
for (; iter != mappings.end(); iter++) { |
2104 |
|
if (s.size()) s += ","; |
2105 |
|
s += "{" + ToString(maps[i]) + "," |
2106 |
|
+ ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + "," |
2107 |
|
+ ToString(int(iter->first.midi_prog)) + "}"; |
2108 |
|
} |
2109 |
|
} |
2110 |
|
result.Add(s); |
2111 |
|
} catch (Exception e) { |
2112 |
|
result.Error(e); |
2113 |
|
} |
2114 |
|
return result.Produce(); |
2115 |
|
} |
2116 |
|
|
2117 |
|
String LSCPServer::ClearMidiInstrumentMappings(uint MidiMapID) { |
2118 |
|
dmsg(2,("LSCPServer: ClearMidiInstrumentMappings()\n")); |
2119 |
|
LSCPResultSet result; |
2120 |
|
try { |
2121 |
|
MidiInstrumentMapper::RemoveAllEntries(MidiMapID); |
2122 |
|
} catch (Exception e) { |
2123 |
|
result.Error(e); |
2124 |
|
} |
2125 |
|
return result.Produce(); |
2126 |
|
} |
2127 |
|
|
2128 |
|
String LSCPServer::ClearAllMidiInstrumentMappings() { |
2129 |
|
dmsg(2,("LSCPServer: ClearAllMidiInstrumentMappings()\n")); |
2130 |
|
LSCPResultSet result; |
2131 |
|
try { |
2132 |
|
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
2133 |
|
for (int i = 0; i < maps.size(); i++) |
2134 |
|
MidiInstrumentMapper::RemoveAllEntries(maps[i]); |
2135 |
|
} catch (Exception e) { |
2136 |
|
result.Error(e); |
2137 |
|
} |
2138 |
|
return result.Produce(); |
2139 |
|
} |
2140 |
|
|
2141 |
|
String LSCPServer::AddMidiInstrumentMap(String MapName) { |
2142 |
|
dmsg(2,("LSCPServer: AddMidiInstrumentMap()\n")); |
2143 |
|
LSCPResultSet result; |
2144 |
|
try { |
2145 |
|
int MapID = MidiInstrumentMapper::AddMap(MapName); |
2146 |
|
result = LSCPResultSet(MapID); |
2147 |
|
} catch (Exception e) { |
2148 |
|
result.Error(e); |
2149 |
|
} |
2150 |
|
return result.Produce(); |
2151 |
|
} |
2152 |
|
|
2153 |
|
String LSCPServer::RemoveMidiInstrumentMap(uint MidiMapID) { |
2154 |
|
dmsg(2,("LSCPServer: RemoveMidiInstrumentMap()\n")); |
2155 |
|
LSCPResultSet result; |
2156 |
|
try { |
2157 |
|
MidiInstrumentMapper::RemoveMap(MidiMapID); |
2158 |
|
} catch (Exception e) { |
2159 |
|
result.Error(e); |
2160 |
|
} |
2161 |
|
return result.Produce(); |
2162 |
|
} |
2163 |
|
|
2164 |
|
String LSCPServer::RemoveAllMidiInstrumentMaps() { |
2165 |
|
dmsg(2,("LSCPServer: RemoveAllMidiInstrumentMaps()\n")); |
2166 |
|
LSCPResultSet result; |
2167 |
|
try { |
2168 |
|
MidiInstrumentMapper::RemoveAllMaps(); |
2169 |
|
} catch (Exception e) { |
2170 |
|
result.Error(e); |
2171 |
|
} |
2172 |
|
return result.Produce(); |
2173 |
|
} |
2174 |
|
|
2175 |
|
String LSCPServer::GetMidiInstrumentMaps() { |
2176 |
|
dmsg(2,("LSCPServer: GetMidiInstrumentMaps()\n")); |
2177 |
|
LSCPResultSet result; |
2178 |
|
try { |
2179 |
|
result.Add(MidiInstrumentMapper::Maps().size()); |
2180 |
|
} catch (Exception e) { |
2181 |
|
result.Error(e); |
2182 |
|
} |
2183 |
|
return result.Produce(); |
2184 |
|
} |
2185 |
|
|
2186 |
|
String LSCPServer::ListMidiInstrumentMaps() { |
2187 |
|
dmsg(2,("LSCPServer: ListMidiInstrumentMaps()\n")); |
2188 |
|
LSCPResultSet result; |
2189 |
|
try { |
2190 |
|
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
2191 |
|
String sList; |
2192 |
|
for (int i = 0; i < maps.size(); i++) { |
2193 |
|
if (sList != "") sList += ","; |
2194 |
|
sList += ToString(maps[i]); |
2195 |
|
} |
2196 |
|
result.Add(sList); |
2197 |
|
} catch (Exception e) { |
2198 |
|
result.Error(e); |
2199 |
|
} |
2200 |
|
return result.Produce(); |
2201 |
|
} |
2202 |
|
|
2203 |
|
String LSCPServer::GetMidiInstrumentMap(uint MidiMapID) { |
2204 |
|
dmsg(2,("LSCPServer: GetMidiInstrumentMap()\n")); |
2205 |
|
LSCPResultSet result; |
2206 |
|
try { |
2207 |
|
result.Add("NAME", _escapeLscpResponse(MidiInstrumentMapper::MapName(MidiMapID))); |
2208 |
|
result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID); |
2209 |
|
} catch (Exception e) { |
2210 |
|
result.Error(e); |
2211 |
|
} |
2212 |
|
return result.Produce(); |
2213 |
|
} |
2214 |
|
|
2215 |
|
String LSCPServer::SetMidiInstrumentMapName(uint MidiMapID, String NewName) { |
2216 |
|
dmsg(2,("LSCPServer: SetMidiInstrumentMapName()\n")); |
2217 |
|
LSCPResultSet result; |
2218 |
|
try { |
2219 |
|
MidiInstrumentMapper::RenameMap(MidiMapID, NewName); |
2220 |
|
} catch (Exception e) { |
2221 |
|
result.Error(e); |
2222 |
|
} |
2223 |
|
return result.Produce(); |
2224 |
|
} |
2225 |
|
|
2226 |
|
/** |
2227 |
|
* Set the MIDI instrument map the given sampler channel shall use for |
2228 |
|
* handling MIDI program change messages. There are the following two |
2229 |
|
* special (negative) values: |
2230 |
|
* |
2231 |
|
* - (-1) : set to NONE (ignore program changes) |
2232 |
|
* - (-2) : set to DEFAULT map |
2233 |
|
*/ |
2234 |
|
String LSCPServer::SetChannelMap(uint uiSamplerChannel, int MidiMapID) { |
2235 |
|
dmsg(2,("LSCPServer: SetChannelMap()\n")); |
2236 |
|
LSCPResultSet result; |
2237 |
|
try { |
2238 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2239 |
|
|
2240 |
|
if (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone(); |
2241 |
|
else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault(); |
2242 |
|
else pEngineChannel->SetMidiInstrumentMap(MidiMapID); |
2243 |
|
} catch (Exception e) { |
2244 |
|
result.Error(e); |
2245 |
|
} |
2246 |
|
return result.Produce(); |
2247 |
|
} |
2248 |
|
|
2249 |
|
String LSCPServer::CreateFxSend(uint uiSamplerChannel, uint MidiCtrl, String Name) { |
2250 |
|
dmsg(2,("LSCPServer: CreateFxSend()\n")); |
2251 |
|
LSCPResultSet result; |
2252 |
|
try { |
2253 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2254 |
|
|
2255 |
|
FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name); |
2256 |
|
if (!pFxSend) throw Exception("Could not add FxSend, don't ask, I don't know why (probably a bug)"); |
2257 |
|
|
2258 |
|
result = LSCPResultSet(pFxSend->Id()); // success |
2259 |
|
} catch (Exception e) { |
2260 |
|
result.Error(e); |
2261 |
|
} |
2262 |
|
return result.Produce(); |
2263 |
|
} |
2264 |
|
|
2265 |
|
String LSCPServer::DestroyFxSend(uint uiSamplerChannel, uint FxSendID) { |
2266 |
|
dmsg(2,("LSCPServer: DestroyFxSend()\n")); |
2267 |
|
LSCPResultSet result; |
2268 |
|
try { |
2269 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2270 |
|
|
2271 |
|
FxSend* pFxSend = NULL; |
2272 |
|
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
2273 |
|
if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) { |
2274 |
|
pFxSend = pEngineChannel->GetFxSend(i); |
2275 |
|
break; |
2276 |
|
} |
2277 |
|
} |
2278 |
|
if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel"); |
2279 |
|
pEngineChannel->RemoveFxSend(pFxSend); |
2280 |
|
} catch (Exception e) { |
2281 |
|
result.Error(e); |
2282 |
|
} |
2283 |
|
return result.Produce(); |
2284 |
|
} |
2285 |
|
|
2286 |
|
String LSCPServer::GetFxSends(uint uiSamplerChannel) { |
2287 |
|
dmsg(2,("LSCPServer: GetFxSends()\n")); |
2288 |
|
LSCPResultSet result; |
2289 |
|
try { |
2290 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2291 |
|
|
2292 |
|
result.Add(pEngineChannel->GetFxSendCount()); |
2293 |
|
} catch (Exception e) { |
2294 |
|
result.Error(e); |
2295 |
|
} |
2296 |
|
return result.Produce(); |
2297 |
|
} |
2298 |
|
|
2299 |
|
String LSCPServer::ListFxSends(uint uiSamplerChannel) { |
2300 |
|
dmsg(2,("LSCPServer: ListFxSends()\n")); |
2301 |
|
LSCPResultSet result; |
2302 |
|
String list; |
2303 |
|
try { |
2304 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2305 |
|
|
2306 |
|
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
2307 |
|
FxSend* pFxSend = pEngineChannel->GetFxSend(i); |
2308 |
|
if (list != "") list += ","; |
2309 |
|
list += ToString(pFxSend->Id()); |
2310 |
|
} |
2311 |
|
result.Add(list); |
2312 |
|
} catch (Exception e) { |
2313 |
|
result.Error(e); |
2314 |
|
} |
2315 |
|
return result.Produce(); |
2316 |
|
} |
2317 |
|
|
2318 |
|
FxSend* LSCPServer::GetFxSend(uint uiSamplerChannel, uint FxSendID) { |
2319 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2320 |
|
|
2321 |
|
FxSend* pFxSend = NULL; |
2322 |
|
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
2323 |
|
if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) { |
2324 |
|
pFxSend = pEngineChannel->GetFxSend(i); |
2325 |
|
break; |
2326 |
|
} |
2327 |
|
} |
2328 |
|
if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel"); |
2329 |
|
return pFxSend; |
2330 |
|
} |
2331 |
|
|
2332 |
|
String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) { |
2333 |
|
dmsg(2,("LSCPServer: GetFxSendInfo()\n")); |
2334 |
|
LSCPResultSet result; |
2335 |
|
try { |
2336 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2337 |
|
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2338 |
|
|
2339 |
|
// gather audio routing informations |
2340 |
|
String AudioRouting; |
2341 |
|
for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { |
2342 |
|
if (AudioRouting != "") AudioRouting += ","; |
2343 |
|
AudioRouting += ToString(pFxSend->DestinationChannel(chan)); |
2344 |
|
} |
2345 |
|
|
2346 |
|
// success |
2347 |
|
result.Add("NAME", _escapeLscpResponse(pFxSend->Name())); |
2348 |
|
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
2349 |
|
result.Add("LEVEL", ToString(pFxSend->Level())); |
2350 |
|
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
2351 |
|
} catch (Exception e) { |
2352 |
|
result.Error(e); |
2353 |
|
} |
2354 |
|
return result.Produce(); |
2355 |
|
} |
2356 |
|
|
2357 |
|
String LSCPServer::SetFxSendName(uint uiSamplerChannel, uint FxSendID, String Name) { |
2358 |
|
dmsg(2,("LSCPServer: SetFxSendName()\n")); |
2359 |
|
LSCPResultSet result; |
2360 |
|
try { |
2361 |
|
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2362 |
|
|
2363 |
|
pFxSend->SetName(Name); |
2364 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2365 |
|
} catch (Exception e) { |
2366 |
|
result.Error(e); |
2367 |
|
} |
2368 |
|
return result.Produce(); |
2369 |
|
} |
2370 |
|
|
2371 |
|
String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) { |
2372 |
|
dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n")); |
2373 |
|
LSCPResultSet result; |
2374 |
|
try { |
2375 |
|
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2376 |
|
|
2377 |
|
pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel); |
2378 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2379 |
|
} catch (Exception e) { |
2380 |
|
result.Error(e); |
2381 |
|
} |
2382 |
|
return result.Produce(); |
2383 |
|
} |
2384 |
|
|
2385 |
|
String LSCPServer::SetFxSendMidiController(uint uiSamplerChannel, uint FxSendID, uint MidiController) { |
2386 |
|
dmsg(2,("LSCPServer: SetFxSendMidiController()\n")); |
2387 |
|
LSCPResultSet result; |
2388 |
|
try { |
2389 |
|
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2390 |
|
|
2391 |
|
pFxSend->SetMidiController(MidiController); |
2392 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2393 |
|
} catch (Exception e) { |
2394 |
|
result.Error(e); |
2395 |
|
} |
2396 |
|
return result.Produce(); |
2397 |
|
} |
2398 |
|
|
2399 |
|
String LSCPServer::SetFxSendLevel(uint uiSamplerChannel, uint FxSendID, double dLevel) { |
2400 |
|
dmsg(2,("LSCPServer: SetFxSendLevel()\n")); |
2401 |
|
LSCPResultSet result; |
2402 |
|
try { |
2403 |
|
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2404 |
|
|
2405 |
|
pFxSend->SetLevel((float)dLevel); |
2406 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2407 |
|
} catch (Exception e) { |
2408 |
|
result.Error(e); |
2409 |
|
} |
2410 |
|
return result.Produce(); |
2411 |
|
} |
2412 |
|
|
2413 |
|
String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) { |
2414 |
|
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
2415 |
|
LSCPResultSet result; |
2416 |
|
try { |
2417 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2418 |
|
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
2419 |
|
Engine* pEngine = pEngineChannel->GetEngine(); |
2420 |
|
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
2421 |
|
if (!pInstrumentManager) throw Exception("Engine does not provide an instrument manager"); |
2422 |
|
InstrumentManager::instrument_id_t instrumentID; |
2423 |
|
instrumentID.FileName = pEngineChannel->InstrumentFileName(); |
2424 |
|
instrumentID.Index = pEngineChannel->InstrumentIndex(); |
2425 |
|
pInstrumentManager->LaunchInstrumentEditor(instrumentID); |
2426 |
|
} catch (Exception e) { |
2427 |
|
result.Error(e); |
2428 |
|
} |
2429 |
|
return result.Produce(); |
2430 |
|
} |
2431 |
|
|
2432 |
|
String LSCPServer::SendChannelMidiData(String MidiMsg, uint uiSamplerChannel, uint Arg1, uint Arg2) { |
2433 |
|
dmsg(2,("LSCPServer: SendChannelMidiData(MidiMsg=%s,uiSamplerChannel=%d,Arg1=%d,Arg2=%d)\n", MidiMsg.c_str(), uiSamplerChannel, Arg1, Arg2)); |
2434 |
|
LSCPResultSet result; |
2435 |
|
try { |
2436 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2437 |
|
|
2438 |
|
if (Arg1 > 127 || Arg2 > 127) { |
2439 |
|
throw Exception("Invalid MIDI message"); |
2440 |
|
} |
2441 |
|
|
2442 |
|
VirtualMidiDevice* pMidiDevice = NULL; |
2443 |
|
std::vector<EventHandler::midi_listener_entry>::iterator iter = eventHandler.channelMidiListeners.begin(); |
2444 |
|
for (; iter != eventHandler.channelMidiListeners.end(); ++iter) { |
2445 |
|
if ((*iter).pEngineChannel == pEngineChannel) { |
2446 |
|
pMidiDevice = (*iter).pMidiListener; |
2447 |
|
break; |
2448 |
|
} |
2449 |
|
} |
2450 |
|
|
2451 |
|
if(pMidiDevice == NULL) throw Exception("Couldn't find virtual MIDI device"); |
2452 |
|
|
2453 |
|
if (MidiMsg == "NOTE_ON") { |
2454 |
|
bool b = pMidiDevice->SendNoteOnToSampler(Arg1, Arg2); |
2455 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2456 |
|
} else if (MidiMsg == "NOTE_OFF") { |
2457 |
|
bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2); |
2458 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2459 |
|
} else { |
2460 |
|
throw Exception("Unknown MIDI message type: " + MidiMsg); |
2461 |
|
} |
2462 |
|
} catch (Exception e) { |
2463 |
|
result.Error(e); |
2464 |
} |
} |
2465 |
return ConvertResult(result); |
return result.Produce(); |
2466 |
} |
} |
2467 |
|
|
2468 |
/** |
/** |
2470 |
*/ |
*/ |
2471 |
String LSCPServer::ResetChannel(uint uiSamplerChannel) { |
String LSCPServer::ResetChannel(uint uiSamplerChannel) { |
2472 |
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
2473 |
result_t result; |
LSCPResultSet result; |
2474 |
try { |
try { |
2475 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2476 |
if (!pSamplerChannel) throw LinuxSamplerException("Index out of bounds"); |
pEngineChannel->Reset(); |
2477 |
Engine* pEngine = pSamplerChannel->GetEngine(); |
} |
2478 |
if (!pEngine) throw LinuxSamplerException("No engine loaded on channel"); |
catch (Exception e) { |
2479 |
pEngine->Reset(); |
result.Error(e); |
|
result.type = result_type_success; |
|
|
} |
|
|
catch (LinuxSamplerException e) { |
|
|
e.PrintMessage(); |
|
|
result.type = result_type_error; |
|
|
result.code = LSCP_ERR_UNKNOWN; |
|
|
result.message = e.Message(); |
|
2480 |
} |
} |
2481 |
return ConvertResult(result); |
return result.Produce(); |
2482 |
|
} |
2483 |
|
|
2484 |
|
/** |
2485 |
|
* Will be called by the parser to reset the whole sampler. |
2486 |
|
*/ |
2487 |
|
String LSCPServer::ResetSampler() { |
2488 |
|
dmsg(2,("LSCPServer: ResetSampler()\n")); |
2489 |
|
pSampler->Reset(); |
2490 |
|
LSCPResultSet result; |
2491 |
|
return result.Produce(); |
2492 |
|
} |
2493 |
|
|
2494 |
|
/** |
2495 |
|
* Will be called by the parser to return general informations about this |
2496 |
|
* sampler. |
2497 |
|
*/ |
2498 |
|
String LSCPServer::GetServerInfo() { |
2499 |
|
dmsg(2,("LSCPServer: GetServerInfo()\n")); |
2500 |
|
const std::string description = |
2501 |
|
_escapeLscpResponse("LinuxSampler - modular, streaming capable sampler"); |
2502 |
|
LSCPResultSet result; |
2503 |
|
result.Add("DESCRIPTION", description); |
2504 |
|
result.Add("VERSION", VERSION); |
2505 |
|
result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR)); |
2506 |
|
#if HAVE_SQLITE3 |
2507 |
|
result.Add("INSTRUMENTS_DB_SUPPORT", "yes"); |
2508 |
|
#else |
2509 |
|
result.Add("INSTRUMENTS_DB_SUPPORT", "no"); |
2510 |
|
#endif |
2511 |
|
|
2512 |
|
return result.Produce(); |
2513 |
|
} |
2514 |
|
|
2515 |
|
/** |
2516 |
|
* Will be called by the parser to return the current number of all active streams. |
2517 |
|
*/ |
2518 |
|
String LSCPServer::GetTotalStreamCount() { |
2519 |
|
dmsg(2,("LSCPServer: GetTotalStreamCount()\n")); |
2520 |
|
LSCPResultSet result; |
2521 |
|
result.Add(pSampler->GetDiskStreamCount()); |
2522 |
|
return result.Produce(); |
2523 |
|
} |
2524 |
|
|
2525 |
|
/** |
2526 |
|
* Will be called by the parser to return the current number of all active voices. |
2527 |
|
*/ |
2528 |
|
String LSCPServer::GetTotalVoiceCount() { |
2529 |
|
dmsg(2,("LSCPServer: GetTotalVoiceCount()\n")); |
2530 |
|
LSCPResultSet result; |
2531 |
|
result.Add(pSampler->GetVoiceCount()); |
2532 |
|
return result.Produce(); |
2533 |
|
} |
2534 |
|
|
2535 |
|
/** |
2536 |
|
* Will be called by the parser to return the maximum number of voices. |
2537 |
|
*/ |
2538 |
|
String LSCPServer::GetTotalVoiceCountMax() { |
2539 |
|
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
2540 |
|
LSCPResultSet result; |
2541 |
|
result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES); |
2542 |
|
return result.Produce(); |
2543 |
|
} |
2544 |
|
|
2545 |
|
String LSCPServer::GetGlobalVolume() { |
2546 |
|
LSCPResultSet result; |
2547 |
|
result.Add(ToString(GLOBAL_VOLUME)); // see common/global.cpp |
2548 |
|
return result.Produce(); |
2549 |
|
} |
2550 |
|
|
2551 |
|
String LSCPServer::SetGlobalVolume(double dVolume) { |
2552 |
|
LSCPResultSet result; |
2553 |
|
try { |
2554 |
|
if (dVolume < 0) throw Exception("Volume may not be negative"); |
2555 |
|
GLOBAL_VOLUME = dVolume; // see common/global_private.cpp |
2556 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME)); |
2557 |
|
} catch (Exception e) { |
2558 |
|
result.Error(e); |
2559 |
|
} |
2560 |
|
return result.Produce(); |
2561 |
|
} |
2562 |
|
|
2563 |
|
String LSCPServer::GetFileInstruments(String Filename) { |
2564 |
|
dmsg(2,("LSCPServer: GetFileInstruments(String Filename=%s)\n",Filename.c_str())); |
2565 |
|
LSCPResultSet result; |
2566 |
|
try { |
2567 |
|
VerifyFile(Filename); |
2568 |
|
} catch (Exception e) { |
2569 |
|
result.Error(e); |
2570 |
|
return result.Produce(); |
2571 |
|
} |
2572 |
|
// try to find a sampler engine that can handle the file |
2573 |
|
bool bFound = false; |
2574 |
|
std::vector<String> engineTypes = EngineFactory::AvailableEngineTypes(); |
2575 |
|
for (int i = 0; !bFound && i < engineTypes.size(); i++) { |
2576 |
|
Engine* pEngine = NULL; |
2577 |
|
try { |
2578 |
|
pEngine = EngineFactory::Create(engineTypes[i]); |
2579 |
|
if (!pEngine) throw Exception("Internal error: could not create '" + engineTypes[i] + "' engine"); |
2580 |
|
InstrumentManager* pManager = pEngine->GetInstrumentManager(); |
2581 |
|
if (pManager) { |
2582 |
|
std::vector<InstrumentManager::instrument_id_t> IDs = |
2583 |
|
pManager->GetInstrumentFileContent(Filename); |
2584 |
|
// return the amount of instruments in the file |
2585 |
|
result.Add(IDs.size()); |
2586 |
|
// no more need to ask other engine types |
2587 |
|
bFound = true; |
2588 |
|
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
2589 |
|
} catch (Exception e) { |
2590 |
|
// NOOP, as exception is thrown if engine doesn't support file |
2591 |
|
} |
2592 |
|
if (pEngine) EngineFactory::Destroy(pEngine); |
2593 |
|
} |
2594 |
|
|
2595 |
|
if (!bFound) result.Error("Unknown file format"); |
2596 |
|
return result.Produce(); |
2597 |
|
} |
2598 |
|
|
2599 |
|
String LSCPServer::ListFileInstruments(String Filename) { |
2600 |
|
dmsg(2,("LSCPServer: ListFileInstruments(String Filename=%s)\n",Filename.c_str())); |
2601 |
|
LSCPResultSet result; |
2602 |
|
try { |
2603 |
|
VerifyFile(Filename); |
2604 |
|
} catch (Exception e) { |
2605 |
|
result.Error(e); |
2606 |
|
return result.Produce(); |
2607 |
|
} |
2608 |
|
// try to find a sampler engine that can handle the file |
2609 |
|
bool bFound = false; |
2610 |
|
std::vector<String> engineTypes = EngineFactory::AvailableEngineTypes(); |
2611 |
|
for (int i = 0; !bFound && i < engineTypes.size(); i++) { |
2612 |
|
Engine* pEngine = NULL; |
2613 |
|
try { |
2614 |
|
pEngine = EngineFactory::Create(engineTypes[i]); |
2615 |
|
if (!pEngine) throw Exception("Internal error: could not create '" + engineTypes[i] + "' engine"); |
2616 |
|
InstrumentManager* pManager = pEngine->GetInstrumentManager(); |
2617 |
|
if (pManager) { |
2618 |
|
std::vector<InstrumentManager::instrument_id_t> IDs = |
2619 |
|
pManager->GetInstrumentFileContent(Filename); |
2620 |
|
// return a list of IDs of the instruments in the file |
2621 |
|
String s; |
2622 |
|
for (int j = 0; j < IDs.size(); j++) { |
2623 |
|
if (s.size()) s += ","; |
2624 |
|
s += ToString(IDs[j].Index); |
2625 |
|
} |
2626 |
|
result.Add(s); |
2627 |
|
// no more need to ask other engine types |
2628 |
|
bFound = true; |
2629 |
|
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
2630 |
|
} catch (Exception e) { |
2631 |
|
// NOOP, as exception is thrown if engine doesn't support file |
2632 |
|
} |
2633 |
|
if (pEngine) EngineFactory::Destroy(pEngine); |
2634 |
|
} |
2635 |
|
|
2636 |
|
if (!bFound) result.Error("Unknown file format"); |
2637 |
|
return result.Produce(); |
2638 |
|
} |
2639 |
|
|
2640 |
|
String LSCPServer::GetFileInstrumentInfo(String Filename, uint InstrumentID) { |
2641 |
|
dmsg(2,("LSCPServer: GetFileInstrumentInfo(String Filename=%s, InstrumentID=%d)\n",Filename.c_str(),InstrumentID)); |
2642 |
|
LSCPResultSet result; |
2643 |
|
try { |
2644 |
|
VerifyFile(Filename); |
2645 |
|
} catch (Exception e) { |
2646 |
|
result.Error(e); |
2647 |
|
return result.Produce(); |
2648 |
|
} |
2649 |
|
InstrumentManager::instrument_id_t id; |
2650 |
|
id.FileName = Filename; |
2651 |
|
id.Index = InstrumentID; |
2652 |
|
// try to find a sampler engine that can handle the file |
2653 |
|
bool bFound = false; |
2654 |
|
bool bFatalErr = false; |
2655 |
|
std::vector<String> engineTypes = EngineFactory::AvailableEngineTypes(); |
2656 |
|
for (int i = 0; !bFound && !bFatalErr && i < engineTypes.size(); i++) { |
2657 |
|
Engine* pEngine = NULL; |
2658 |
|
try { |
2659 |
|
pEngine = EngineFactory::Create(engineTypes[i]); |
2660 |
|
if (!pEngine) throw Exception("Internal error: could not create '" + engineTypes[i] + "' engine"); |
2661 |
|
InstrumentManager* pManager = pEngine->GetInstrumentManager(); |
2662 |
|
if (pManager) { |
2663 |
|
// check if the instrument index is valid |
2664 |
|
// FIXME: this won't work if an engine only supports parts of the instrument file |
2665 |
|
std::vector<InstrumentManager::instrument_id_t> IDs = |
2666 |
|
pManager->GetInstrumentFileContent(Filename); |
2667 |
|
if (std::find(IDs.begin(), IDs.end(), id) == IDs.end()) { |
2668 |
|
std::stringstream ss; |
2669 |
|
ss << "Invalid instrument index " << InstrumentID << " for instrument file '" << Filename << "'"; |
2670 |
|
bFatalErr = true; |
2671 |
|
throw Exception(ss.str()); |
2672 |
|
} |
2673 |
|
// get the info of the requested instrument |
2674 |
|
InstrumentManager::instrument_info_t info = |
2675 |
|
pManager->GetInstrumentInfo(id); |
2676 |
|
// return detailed informations about the file |
2677 |
|
result.Add("NAME", info.InstrumentName); |
2678 |
|
result.Add("FORMAT_FAMILY", engineTypes[i]); |
2679 |
|
result.Add("FORMAT_VERSION", info.FormatVersion); |
2680 |
|
result.Add("PRODUCT", info.Product); |
2681 |
|
result.Add("ARTISTS", info.Artists); |
2682 |
|
|
2683 |
|
std::stringstream ss; |
2684 |
|
bool b = false; |
2685 |
|
for (int i = 0; i < 128; i++) { |
2686 |
|
if (info.KeyBindings[i]) { |
2687 |
|
if (b) ss << ','; |
2688 |
|
ss << i; b = true; |
2689 |
|
} |
2690 |
|
} |
2691 |
|
result.Add("KEY_BINDINGS", ss.str()); |
2692 |
|
|
2693 |
|
std::stringstream ss2; |
2694 |
|
for (int i = 0; i < 128; i++) { |
2695 |
|
if (info.KeySwitchBindings[i]) { |
2696 |
|
if (b) ss2 << ','; |
2697 |
|
ss2 << i; b = true; |
2698 |
|
} |
2699 |
|
} |
2700 |
|
result.Add("KEYSWITCH_BINDINGS", ss2.str()); |
2701 |
|
// no more need to ask other engine types |
2702 |
|
bFound = true; |
2703 |
|
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
2704 |
|
} catch (Exception e) { |
2705 |
|
// usually NOOP, as exception is thrown if engine doesn't support file |
2706 |
|
if (bFatalErr) result.Error(e); |
2707 |
|
} |
2708 |
|
if (pEngine) EngineFactory::Destroy(pEngine); |
2709 |
|
} |
2710 |
|
|
2711 |
|
if (!bFound && !bFatalErr) result.Error("Unknown file format"); |
2712 |
|
return result.Produce(); |
2713 |
|
} |
2714 |
|
|
2715 |
|
void LSCPServer::VerifyFile(String Filename) { |
2716 |
|
#if WIN32 |
2717 |
|
WIN32_FIND_DATA win32FileAttributeData; |
2718 |
|
BOOL res = GetFileAttributesEx( Filename.c_str(), GetFileExInfoStandard, &win32FileAttributeData ); |
2719 |
|
if (!res) { |
2720 |
|
std::stringstream ss; |
2721 |
|
ss << "File does not exist, GetFileAttributesEx failed `" << Filename << "`: Error " << GetLastError(); |
2722 |
|
throw Exception(ss.str()); |
2723 |
|
} |
2724 |
|
if ( win32FileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { |
2725 |
|
throw Exception("Directory is specified"); |
2726 |
|
} |
2727 |
|
#else |
2728 |
|
struct stat statBuf; |
2729 |
|
int res = stat(Filename.c_str(), &statBuf); |
2730 |
|
if (res) { |
2731 |
|
std::stringstream ss; |
2732 |
|
ss << "Fail to stat `" << Filename << "`: " << strerror(errno); |
2733 |
|
throw Exception(ss.str()); |
2734 |
|
} |
2735 |
|
|
2736 |
|
if (S_ISDIR(statBuf.st_mode)) { |
2737 |
|
throw Exception("Directory is specified"); |
2738 |
|
} |
2739 |
|
#endif |
2740 |
} |
} |
2741 |
|
|
2742 |
/** |
/** |
2743 |
* 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 |
2744 |
* server for receiving event messages. |
* server for receiving event messages. |
2745 |
*/ |
*/ |
2746 |
String LSCPServer::SubscribeNotification(uint UDPPort) { |
String LSCPServer::SubscribeNotification(LSCPEvent::event_t type) { |
2747 |
dmsg(2,("LSCPServer: SubscribeNotification(UDPPort=%d)\n", UDPPort)); |
dmsg(2,("LSCPServer: SubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
2748 |
return "ERR:0:Not implemented yet.\r\n"; |
LSCPResultSet result; |
2749 |
|
SubscriptionMutex.Lock(); |
2750 |
|
eventSubscriptions[type].push_back(currentSocket); |
2751 |
|
SubscriptionMutex.Unlock(); |
2752 |
|
return result.Produce(); |
2753 |
} |
} |
2754 |
|
|
2755 |
/** |
/** |
2756 |
* Will be called by the parser to unsubscribe a client on the server |
* Will be called by the parser to unsubscribe a client on the server |
2757 |
* for not receiving further event messages. |
* for not receiving further event messages. |
2758 |
*/ |
*/ |
2759 |
String LSCPServer::UnsubscribeNotification(String SessionID) { |
String LSCPServer::UnsubscribeNotification(LSCPEvent::event_t type) { |
2760 |
dmsg(2,("LSCPServer: UnsubscribeNotification(SessionID=%s)\n", SessionID.c_str())); |
dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
2761 |
return "ERR:0:Not implemented yet.\r\n"; |
LSCPResultSet result; |
2762 |
|
SubscriptionMutex.Lock(); |
2763 |
|
eventSubscriptions[type].remove(currentSocket); |
2764 |
|
SubscriptionMutex.Unlock(); |
2765 |
|
return result.Produce(); |
2766 |
|
} |
2767 |
|
|
2768 |
|
String LSCPServer::AddDbInstrumentDirectory(String Dir) { |
2769 |
|
dmsg(2,("LSCPServer: AddDbInstrumentDirectory(Dir=%s)\n", Dir.c_str())); |
2770 |
|
LSCPResultSet result; |
2771 |
|
#if HAVE_SQLITE3 |
2772 |
|
try { |
2773 |
|
InstrumentsDb::GetInstrumentsDb()->AddDirectory(Dir); |
2774 |
|
} catch (Exception e) { |
2775 |
|
result.Error(e); |
2776 |
|
} |
2777 |
|
#else |
2778 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2779 |
|
#endif |
2780 |
|
return result.Produce(); |
2781 |
|
} |
2782 |
|
|
2783 |
|
String LSCPServer::RemoveDbInstrumentDirectory(String Dir, bool Force) { |
2784 |
|
dmsg(2,("LSCPServer: RemoveDbInstrumentDirectory(Dir=%s,Force=%d)\n", Dir.c_str(), Force)); |
2785 |
|
LSCPResultSet result; |
2786 |
|
#if HAVE_SQLITE3 |
2787 |
|
try { |
2788 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveDirectory(Dir, Force); |
2789 |
|
} catch (Exception e) { |
2790 |
|
result.Error(e); |
2791 |
|
} |
2792 |
|
#else |
2793 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2794 |
|
#endif |
2795 |
|
return result.Produce(); |
2796 |
|
} |
2797 |
|
|
2798 |
|
String LSCPServer::GetDbInstrumentDirectoryCount(String Dir, bool Recursive) { |
2799 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2800 |
|
LSCPResultSet result; |
2801 |
|
#if HAVE_SQLITE3 |
2802 |
|
try { |
2803 |
|
result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir, Recursive)); |
2804 |
|
} catch (Exception e) { |
2805 |
|
result.Error(e); |
2806 |
|
} |
2807 |
|
#else |
2808 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2809 |
|
#endif |
2810 |
|
return result.Produce(); |
2811 |
|
} |
2812 |
|
|
2813 |
|
String LSCPServer::GetDbInstrumentDirectories(String Dir, bool Recursive) { |
2814 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2815 |
|
LSCPResultSet result; |
2816 |
|
#if HAVE_SQLITE3 |
2817 |
|
try { |
2818 |
|
String list; |
2819 |
|
StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir, Recursive); |
2820 |
|
|
2821 |
|
for (int i = 0; i < dirs->size(); i++) { |
2822 |
|
if (list != "") list += ","; |
2823 |
|
list += "'" + InstrumentsDb::toEscapedPath(dirs->at(i)) + "'"; |
2824 |
|
} |
2825 |
|
|
2826 |
|
result.Add(list); |
2827 |
|
} catch (Exception e) { |
2828 |
|
result.Error(e); |
2829 |
|
} |
2830 |
|
#else |
2831 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2832 |
|
#endif |
2833 |
|
return result.Produce(); |
2834 |
|
} |
2835 |
|
|
2836 |
|
String LSCPServer::GetDbInstrumentDirectoryInfo(String Dir) { |
2837 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectoryInfo(Dir=%s)\n", Dir.c_str())); |
2838 |
|
LSCPResultSet result; |
2839 |
|
#if HAVE_SQLITE3 |
2840 |
|
try { |
2841 |
|
DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir); |
2842 |
|
|
2843 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(info.Description)); |
2844 |
|
result.Add("CREATED", info.Created); |
2845 |
|
result.Add("MODIFIED", info.Modified); |
2846 |
|
} catch (Exception e) { |
2847 |
|
result.Error(e); |
2848 |
|
} |
2849 |
|
#else |
2850 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2851 |
|
#endif |
2852 |
|
return result.Produce(); |
2853 |
|
} |
2854 |
|
|
2855 |
|
String LSCPServer::SetDbInstrumentDirectoryName(String Dir, String Name) { |
2856 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDirectoryName(Dir=%s,Name=%s)\n", Dir.c_str(), Name.c_str())); |
2857 |
|
LSCPResultSet result; |
2858 |
|
#if HAVE_SQLITE3 |
2859 |
|
try { |
2860 |
|
InstrumentsDb::GetInstrumentsDb()->RenameDirectory(Dir, Name); |
2861 |
|
} catch (Exception e) { |
2862 |
|
result.Error(e); |
2863 |
|
} |
2864 |
|
#else |
2865 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2866 |
|
#endif |
2867 |
|
return result.Produce(); |
2868 |
|
} |
2869 |
|
|
2870 |
|
String LSCPServer::MoveDbInstrumentDirectory(String Dir, String Dst) { |
2871 |
|
dmsg(2,("LSCPServer: MoveDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str())); |
2872 |
|
LSCPResultSet result; |
2873 |
|
#if HAVE_SQLITE3 |
2874 |
|
try { |
2875 |
|
InstrumentsDb::GetInstrumentsDb()->MoveDirectory(Dir, Dst); |
2876 |
|
} catch (Exception e) { |
2877 |
|
result.Error(e); |
2878 |
|
} |
2879 |
|
#else |
2880 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2881 |
|
#endif |
2882 |
|
return result.Produce(); |
2883 |
|
} |
2884 |
|
|
2885 |
|
String LSCPServer::CopyDbInstrumentDirectory(String Dir, String Dst) { |
2886 |
|
dmsg(2,("LSCPServer: CopyDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str())); |
2887 |
|
LSCPResultSet result; |
2888 |
|
#if HAVE_SQLITE3 |
2889 |
|
try { |
2890 |
|
InstrumentsDb::GetInstrumentsDb()->CopyDirectory(Dir, Dst); |
2891 |
|
} catch (Exception e) { |
2892 |
|
result.Error(e); |
2893 |
|
} |
2894 |
|
#else |
2895 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2896 |
|
#endif |
2897 |
|
return result.Produce(); |
2898 |
|
} |
2899 |
|
|
2900 |
|
String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) { |
2901 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDirectoryDescription(Dir=%s,Desc=%s)\n", Dir.c_str(), Desc.c_str())); |
2902 |
|
LSCPResultSet result; |
2903 |
|
#if HAVE_SQLITE3 |
2904 |
|
try { |
2905 |
|
InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc); |
2906 |
|
} catch (Exception e) { |
2907 |
|
result.Error(e); |
2908 |
|
} |
2909 |
|
#else |
2910 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2911 |
|
#endif |
2912 |
|
return result.Produce(); |
2913 |
|
} |
2914 |
|
|
2915 |
|
String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index, bool bBackground) { |
2916 |
|
dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d,bBackground=%d)\n", DbDir.c_str(), FilePath.c_str(), Index, bBackground)); |
2917 |
|
LSCPResultSet result; |
2918 |
|
#if HAVE_SQLITE3 |
2919 |
|
try { |
2920 |
|
int id; |
2921 |
|
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
2922 |
|
id = db->AddInstruments(DbDir, FilePath, Index, bBackground); |
2923 |
|
if (bBackground) result = id; |
2924 |
|
} catch (Exception e) { |
2925 |
|
result.Error(e); |
2926 |
|
} |
2927 |
|
#else |
2928 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2929 |
|
#endif |
2930 |
|
return result.Produce(); |
2931 |
|
} |
2932 |
|
|
2933 |
|
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) { |
2934 |
|
dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground)); |
2935 |
|
LSCPResultSet result; |
2936 |
|
#if HAVE_SQLITE3 |
2937 |
|
try { |
2938 |
|
int id; |
2939 |
|
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
2940 |
|
if (ScanMode.compare("RECURSIVE") == 0) { |
2941 |
|
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground); |
2942 |
|
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
2943 |
|
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground); |
2944 |
|
} else if (ScanMode.compare("FLAT") == 0) { |
2945 |
|
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground); |
2946 |
|
} else { |
2947 |
|
throw Exception("Unknown scan mode: " + ScanMode); |
2948 |
|
} |
2949 |
|
|
2950 |
|
if (bBackground) result = id; |
2951 |
|
} catch (Exception e) { |
2952 |
|
result.Error(e); |
2953 |
|
} |
2954 |
|
#else |
2955 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2956 |
|
#endif |
2957 |
|
return result.Produce(); |
2958 |
|
} |
2959 |
|
|
2960 |
|
String LSCPServer::RemoveDbInstrument(String Instr) { |
2961 |
|
dmsg(2,("LSCPServer: RemoveDbInstrument(Instr=%s)\n", Instr.c_str())); |
2962 |
|
LSCPResultSet result; |
2963 |
|
#if HAVE_SQLITE3 |
2964 |
|
try { |
2965 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveInstrument(Instr); |
2966 |
|
} catch (Exception e) { |
2967 |
|
result.Error(e); |
2968 |
|
} |
2969 |
|
#else |
2970 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2971 |
|
#endif |
2972 |
|
return result.Produce(); |
2973 |
|
} |
2974 |
|
|
2975 |
|
String LSCPServer::GetDbInstrumentCount(String Dir, bool Recursive) { |
2976 |
|
dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2977 |
|
LSCPResultSet result; |
2978 |
|
#if HAVE_SQLITE3 |
2979 |
|
try { |
2980 |
|
result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir, Recursive)); |
2981 |
|
} catch (Exception e) { |
2982 |
|
result.Error(e); |
2983 |
|
} |
2984 |
|
#else |
2985 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2986 |
|
#endif |
2987 |
|
return result.Produce(); |
2988 |
|
} |
2989 |
|
|
2990 |
|
String LSCPServer::GetDbInstruments(String Dir, bool Recursive) { |
2991 |
|
dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2992 |
|
LSCPResultSet result; |
2993 |
|
#if HAVE_SQLITE3 |
2994 |
|
try { |
2995 |
|
String list; |
2996 |
|
StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir, Recursive); |
2997 |
|
|
2998 |
|
for (int i = 0; i < instrs->size(); i++) { |
2999 |
|
if (list != "") list += ","; |
3000 |
|
list += "'" + InstrumentsDb::toEscapedPath(instrs->at(i)) + "'"; |
3001 |
|
} |
3002 |
|
|
3003 |
|
result.Add(list); |
3004 |
|
} catch (Exception e) { |
3005 |
|
result.Error(e); |
3006 |
|
} |
3007 |
|
#else |
3008 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3009 |
|
#endif |
3010 |
|
return result.Produce(); |
3011 |
|
} |
3012 |
|
|
3013 |
|
String LSCPServer::GetDbInstrumentInfo(String Instr) { |
3014 |
|
dmsg(2,("LSCPServer: GetDbInstrumentInfo(Instr=%s)\n", Instr.c_str())); |
3015 |
|
LSCPResultSet result; |
3016 |
|
#if HAVE_SQLITE3 |
3017 |
|
try { |
3018 |
|
DbInstrument info = InstrumentsDb::GetInstrumentsDb()->GetInstrumentInfo(Instr); |
3019 |
|
|
3020 |
|
result.Add("INSTRUMENT_FILE", info.InstrFile); |
3021 |
|
result.Add("INSTRUMENT_NR", info.InstrNr); |
3022 |
|
result.Add("FORMAT_FAMILY", info.FormatFamily); |
3023 |
|
result.Add("FORMAT_VERSION", info.FormatVersion); |
3024 |
|
result.Add("SIZE", (int)info.Size); |
3025 |
|
result.Add("CREATED", info.Created); |
3026 |
|
result.Add("MODIFIED", info.Modified); |
3027 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(info.Description)); |
3028 |
|
result.Add("IS_DRUM", info.IsDrum); |
3029 |
|
result.Add("PRODUCT", _escapeLscpResponse(info.Product)); |
3030 |
|
result.Add("ARTISTS", _escapeLscpResponse(info.Artists)); |
3031 |
|
result.Add("KEYWORDS", _escapeLscpResponse(info.Keywords)); |
3032 |
|
} catch (Exception e) { |
3033 |
|
result.Error(e); |
3034 |
|
} |
3035 |
|
#else |
3036 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3037 |
|
#endif |
3038 |
|
return result.Produce(); |
3039 |
|
} |
3040 |
|
|
3041 |
|
String LSCPServer::GetDbInstrumentsJobInfo(int JobId) { |
3042 |
|
dmsg(2,("LSCPServer: GetDbInstrumentsJobInfo(JobId=%d)\n", JobId)); |
3043 |
|
LSCPResultSet result; |
3044 |
|
#if HAVE_SQLITE3 |
3045 |
|
try { |
3046 |
|
ScanJob job = InstrumentsDb::GetInstrumentsDb()->Jobs.GetJobById(JobId); |
3047 |
|
|
3048 |
|
result.Add("FILES_TOTAL", job.FilesTotal); |
3049 |
|
result.Add("FILES_SCANNED", job.FilesScanned); |
3050 |
|
result.Add("SCANNING", job.Scanning); |
3051 |
|
result.Add("STATUS", job.Status); |
3052 |
|
} catch (Exception e) { |
3053 |
|
result.Error(e); |
3054 |
|
} |
3055 |
|
#else |
3056 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3057 |
|
#endif |
3058 |
|
return result.Produce(); |
3059 |
|
} |
3060 |
|
|
3061 |
|
String LSCPServer::SetDbInstrumentName(String Instr, String Name) { |
3062 |
|
dmsg(2,("LSCPServer: SetDbInstrumentName(Instr=%s,Name=%s)\n", Instr.c_str(), Name.c_str())); |
3063 |
|
LSCPResultSet result; |
3064 |
|
#if HAVE_SQLITE3 |
3065 |
|
try { |
3066 |
|
InstrumentsDb::GetInstrumentsDb()->RenameInstrument(Instr, Name); |
3067 |
|
} catch (Exception e) { |
3068 |
|
result.Error(e); |
3069 |
|
} |
3070 |
|
#else |
3071 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3072 |
|
#endif |
3073 |
|
return result.Produce(); |
3074 |
|
} |
3075 |
|
|
3076 |
|
String LSCPServer::MoveDbInstrument(String Instr, String Dst) { |
3077 |
|
dmsg(2,("LSCPServer: MoveDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str())); |
3078 |
|
LSCPResultSet result; |
3079 |
|
#if HAVE_SQLITE3 |
3080 |
|
try { |
3081 |
|
InstrumentsDb::GetInstrumentsDb()->MoveInstrument(Instr, Dst); |
3082 |
|
} catch (Exception e) { |
3083 |
|
result.Error(e); |
3084 |
|
} |
3085 |
|
#else |
3086 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3087 |
|
#endif |
3088 |
|
return result.Produce(); |
3089 |
|
} |
3090 |
|
|
3091 |
|
String LSCPServer::CopyDbInstrument(String Instr, String Dst) { |
3092 |
|
dmsg(2,("LSCPServer: CopyDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str())); |
3093 |
|
LSCPResultSet result; |
3094 |
|
#if HAVE_SQLITE3 |
3095 |
|
try { |
3096 |
|
InstrumentsDb::GetInstrumentsDb()->CopyInstrument(Instr, Dst); |
3097 |
|
} catch (Exception e) { |
3098 |
|
result.Error(e); |
3099 |
|
} |
3100 |
|
#else |
3101 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3102 |
|
#endif |
3103 |
|
return result.Produce(); |
3104 |
|
} |
3105 |
|
|
3106 |
|
String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) { |
3107 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDescription(Instr=%s,Desc=%s)\n", Instr.c_str(), Desc.c_str())); |
3108 |
|
LSCPResultSet result; |
3109 |
|
#if HAVE_SQLITE3 |
3110 |
|
try { |
3111 |
|
InstrumentsDb::GetInstrumentsDb()->SetInstrumentDescription(Instr, Desc); |
3112 |
|
} catch (Exception e) { |
3113 |
|
result.Error(e); |
3114 |
|
} |
3115 |
|
#else |
3116 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3117 |
|
#endif |
3118 |
|
return result.Produce(); |
3119 |
|
} |
3120 |
|
|
3121 |
|
String LSCPServer::SetDbInstrumentFilePath(String OldPath, String NewPath) { |
3122 |
|
dmsg(2,("LSCPServer: SetDbInstrumentFilePath(OldPath=%s,NewPath=%s)\n", OldPath.c_str(), NewPath.c_str())); |
3123 |
|
LSCPResultSet result; |
3124 |
|
#if HAVE_SQLITE3 |
3125 |
|
try { |
3126 |
|
InstrumentsDb::GetInstrumentsDb()->SetInstrumentFilePath(OldPath, NewPath); |
3127 |
|
} catch (Exception e) { |
3128 |
|
result.Error(e); |
3129 |
|
} |
3130 |
|
#else |
3131 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3132 |
|
#endif |
3133 |
|
return result.Produce(); |
3134 |
|
} |
3135 |
|
|
3136 |
|
String LSCPServer::FindLostDbInstrumentFiles() { |
3137 |
|
dmsg(2,("LSCPServer: FindLostDbInstrumentFiles()\n")); |
3138 |
|
LSCPResultSet result; |
3139 |
|
#if HAVE_SQLITE3 |
3140 |
|
try { |
3141 |
|
String list; |
3142 |
|
StringListPtr pLostFiles = InstrumentsDb::GetInstrumentsDb()->FindLostInstrumentFiles(); |
3143 |
|
|
3144 |
|
for (int i = 0; i < pLostFiles->size(); i++) { |
3145 |
|
if (list != "") list += ","; |
3146 |
|
list += "'" + pLostFiles->at(i) + "'"; |
3147 |
|
} |
3148 |
|
|
3149 |
|
result.Add(list); |
3150 |
|
} catch (Exception e) { |
3151 |
|
result.Error(e); |
3152 |
|
} |
3153 |
|
#else |
3154 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3155 |
|
#endif |
3156 |
|
return result.Produce(); |
3157 |
|
} |
3158 |
|
|
3159 |
|
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
3160 |
|
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
3161 |
|
LSCPResultSet result; |
3162 |
|
#if HAVE_SQLITE3 |
3163 |
|
try { |
3164 |
|
SearchQuery Query; |
3165 |
|
std::map<String,String>::iterator iter; |
3166 |
|
for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { |
3167 |
|
if (iter->first.compare("NAME") == 0) { |
3168 |
|
Query.Name = iter->second; |
3169 |
|
} else if (iter->first.compare("CREATED") == 0) { |
3170 |
|
Query.SetCreated(iter->second); |
3171 |
|
} else if (iter->first.compare("MODIFIED") == 0) { |
3172 |
|
Query.SetModified(iter->second); |
3173 |
|
} else if (iter->first.compare("DESCRIPTION") == 0) { |
3174 |
|
Query.Description = iter->second; |
3175 |
|
} else { |
3176 |
|
throw Exception("Unknown search criteria: " + iter->first); |
3177 |
|
} |
3178 |
|
} |
3179 |
|
|
3180 |
|
String list; |
3181 |
|
StringListPtr pDirectories = |
3182 |
|
InstrumentsDb::GetInstrumentsDb()->FindDirectories(Dir, &Query, Recursive); |
3183 |
|
|
3184 |
|
for (int i = 0; i < pDirectories->size(); i++) { |
3185 |
|
if (list != "") list += ","; |
3186 |
|
list += "'" + InstrumentsDb::toEscapedPath(pDirectories->at(i)) + "'"; |
3187 |
|
} |
3188 |
|
|
3189 |
|
result.Add(list); |
3190 |
|
} catch (Exception e) { |
3191 |
|
result.Error(e); |
3192 |
|
} |
3193 |
|
#else |
3194 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3195 |
|
#endif |
3196 |
|
return result.Produce(); |
3197 |
|
} |
3198 |
|
|
3199 |
|
String LSCPServer::FindDbInstruments(String Dir, std::map<String,String> Parameters, bool Recursive) { |
3200 |
|
dmsg(2,("LSCPServer: FindDbInstruments(Dir=%s)\n", Dir.c_str())); |
3201 |
|
LSCPResultSet result; |
3202 |
|
#if HAVE_SQLITE3 |
3203 |
|
try { |
3204 |
|
SearchQuery Query; |
3205 |
|
std::map<String,String>::iterator iter; |
3206 |
|
for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { |
3207 |
|
if (iter->first.compare("NAME") == 0) { |
3208 |
|
Query.Name = iter->second; |
3209 |
|
} else if (iter->first.compare("FORMAT_FAMILIES") == 0) { |
3210 |
|
Query.SetFormatFamilies(iter->second); |
3211 |
|
} else if (iter->first.compare("SIZE") == 0) { |
3212 |
|
Query.SetSize(iter->second); |
3213 |
|
} else if (iter->first.compare("CREATED") == 0) { |
3214 |
|
Query.SetCreated(iter->second); |
3215 |
|
} else if (iter->first.compare("MODIFIED") == 0) { |
3216 |
|
Query.SetModified(iter->second); |
3217 |
|
} else if (iter->first.compare("DESCRIPTION") == 0) { |
3218 |
|
Query.Description = iter->second; |
3219 |
|
} else if (iter->first.compare("IS_DRUM") == 0) { |
3220 |
|
if (!strcasecmp(iter->second.c_str(), "true")) { |
3221 |
|
Query.InstrType = SearchQuery::DRUM; |
3222 |
|
} else { |
3223 |
|
Query.InstrType = SearchQuery::CHROMATIC; |
3224 |
|
} |
3225 |
|
} else if (iter->first.compare("PRODUCT") == 0) { |
3226 |
|
Query.Product = iter->second; |
3227 |
|
} else if (iter->first.compare("ARTISTS") == 0) { |
3228 |
|
Query.Artists = iter->second; |
3229 |
|
} else if (iter->first.compare("KEYWORDS") == 0) { |
3230 |
|
Query.Keywords = iter->second; |
3231 |
|
} else { |
3232 |
|
throw Exception("Unknown search criteria: " + iter->first); |
3233 |
|
} |
3234 |
|
} |
3235 |
|
|
3236 |
|
String list; |
3237 |
|
StringListPtr pInstruments = |
3238 |
|
InstrumentsDb::GetInstrumentsDb()->FindInstruments(Dir, &Query, Recursive); |
3239 |
|
|
3240 |
|
for (int i = 0; i < pInstruments->size(); i++) { |
3241 |
|
if (list != "") list += ","; |
3242 |
|
list += "'" + InstrumentsDb::toEscapedPath(pInstruments->at(i)) + "'"; |
3243 |
|
} |
3244 |
|
|
3245 |
|
result.Add(list); |
3246 |
|
} catch (Exception e) { |
3247 |
|
result.Error(e); |
3248 |
|
} |
3249 |
|
#else |
3250 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3251 |
|
#endif |
3252 |
|
return result.Produce(); |
3253 |
|
} |
3254 |
|
|
3255 |
|
String LSCPServer::FormatInstrumentsDb() { |
3256 |
|
dmsg(2,("LSCPServer: FormatInstrumentsDb()\n")); |
3257 |
|
LSCPResultSet result; |
3258 |
|
#if HAVE_SQLITE3 |
3259 |
|
try { |
3260 |
|
InstrumentsDb::GetInstrumentsDb()->Format(); |
3261 |
|
} catch (Exception e) { |
3262 |
|
result.Error(e); |
3263 |
|
} |
3264 |
|
#else |
3265 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3266 |
|
#endif |
3267 |
|
return result.Produce(); |
3268 |
|
} |
3269 |
|
|
3270 |
|
|
3271 |
|
/** |
3272 |
|
* Will be called by the parser to enable or disable echo mode; if echo |
3273 |
|
* mode is enabled, all commands from the client will (immediately) be |
3274 |
|
* echoed back to the client. |
3275 |
|
*/ |
3276 |
|
String LSCPServer::SetEcho(yyparse_param_t* pSession, double boolean_value) { |
3277 |
|
dmsg(2,("LSCPServer: SetEcho(val=%f)\n", boolean_value)); |
3278 |
|
LSCPResultSet result; |
3279 |
|
try { |
3280 |
|
if (boolean_value == 0) pSession->bVerbose = false; |
3281 |
|
else if (boolean_value == 1) pSession->bVerbose = true; |
3282 |
|
else throw Exception("Not a boolean value, must either be 0 or 1"); |
3283 |
|
} |
3284 |
|
catch (Exception e) { |
3285 |
|
result.Error(e); |
3286 |
|
} |
3287 |
|
return result.Produce(); |
3288 |
|
} |
3289 |
|
|
3290 |
} |
} |