3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2007 Christian Schoenebeck * |
* Copyright (C) 2005 - 2014 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This library is free software; you can redistribute it and/or modify * |
* This library is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
21 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
***************************************************************************/ |
23 |
|
|
24 |
|
#include <algorithm> |
25 |
|
#include <string> |
26 |
|
|
27 |
|
#include "../common/File.h" |
28 |
#include "lscpserver.h" |
#include "lscpserver.h" |
29 |
#include "lscpresultset.h" |
#include "lscpresultset.h" |
30 |
#include "lscpevent.h" |
#include "lscpevent.h" |
31 |
|
|
32 |
#if defined(WIN32) |
#if defined(WIN32) |
33 |
|
#include <windows.h> |
34 |
#else |
#else |
35 |
#include <fcntl.h> |
#include <fcntl.h> |
36 |
#endif |
#endif |
43 |
#include "../engines/EngineChannelFactory.h" |
#include "../engines/EngineChannelFactory.h" |
44 |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
45 |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
46 |
|
#include "../effects/EffectFactory.h" |
47 |
|
|
48 |
|
namespace LinuxSampler { |
49 |
|
|
50 |
|
String lscpParserProcessShellInteraction(String& line, yyparse_param_t* param, bool possibilities); |
51 |
|
|
52 |
/** |
/** |
53 |
* Returns a copy of the given string where all special characters are |
* Returns a copy of the given string where all special characters are |
99 |
*/ |
*/ |
100 |
fd_set LSCPServer::fdSet; |
fd_set LSCPServer::fdSet; |
101 |
int LSCPServer::currentSocket = -1; |
int LSCPServer::currentSocket = -1; |
102 |
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
std::vector<yyparse_param_t> LSCPServer::Sessions; |
103 |
std::vector<yyparse_param_t>::iterator itCurrentSession = std::vector<yyparse_param_t>::iterator(); |
std::vector<yyparse_param_t>::iterator itCurrentSession; |
104 |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedNotifies; |
105 |
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedCommands; |
106 |
std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions = std::map< LSCPEvent::event_t, std::list<int> >(); |
std::map< LSCPEvent::event_t, std::list<int> > LSCPServer::eventSubscriptions; |
107 |
Mutex LSCPServer::NotifyMutex = Mutex(); |
Mutex LSCPServer::NotifyMutex; |
108 |
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
Mutex LSCPServer::NotifyBufferMutex; |
109 |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
Mutex LSCPServer::SubscriptionMutex; |
110 |
Mutex LSCPServer::RTNotifyMutex = Mutex(); |
Mutex LSCPServer::RTNotifyMutex; |
111 |
|
|
112 |
LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4) { |
LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4), eventHandler(this) { |
113 |
SocketAddress.sin_family = AF_INET; |
SocketAddress.sin_family = AF_INET; |
114 |
SocketAddress.sin_addr.s_addr = addr; |
SocketAddress.sin_addr.s_addr = addr; |
115 |
SocketAddress.sin_port = port; |
SocketAddress.sin_port = port; |
135 |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO"); |
136 |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO"); |
137 |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
138 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_total_stream_count, "TOTAL_STREAM_COUNT"); |
139 |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
140 |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
141 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI"); |
142 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_device_midi, "DEVICE_MIDI"); |
143 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_fx_instance_count, "EFFECT_INSTANCE_COUNT"); |
144 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_fx_instance_info, "EFFECT_INSTANCE_INFO"); |
145 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_send_fx_chain_count, "SEND_EFFECT_CHAIN_COUNT"); |
146 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_send_fx_chain_info, "SEND_EFFECT_CHAIN_INFO"); |
147 |
hSocket = -1; |
hSocket = -1; |
148 |
} |
} |
149 |
|
|
150 |
LSCPServer::~LSCPServer() { |
LSCPServer::~LSCPServer() { |
151 |
|
CloseAllConnections(); |
152 |
|
InstrumentManager::StopBackgroundThread(); |
153 |
#if defined(WIN32) |
#if defined(WIN32) |
154 |
if (hSocket >= 0) closesocket(hSocket); |
if (hSocket >= 0) closesocket(hSocket); |
155 |
#else |
#else |
157 |
#endif |
#endif |
158 |
} |
} |
159 |
|
|
160 |
|
LSCPServer::EventHandler::EventHandler(LSCPServer* pParent) { |
161 |
|
this->pParent = pParent; |
162 |
|
} |
163 |
|
|
164 |
|
LSCPServer::EventHandler::~EventHandler() { |
165 |
|
std::vector<midi_listener_entry> l = channelMidiListeners; |
166 |
|
channelMidiListeners.clear(); |
167 |
|
for (int i = 0; i < l.size(); i++) |
168 |
|
delete l[i].pMidiListener; |
169 |
|
} |
170 |
|
|
171 |
void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) { |
void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) { |
172 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount)); |
173 |
} |
} |
174 |
|
|
175 |
|
void LSCPServer::EventHandler::ChannelAdded(SamplerChannel* pChannel) { |
176 |
|
pChannel->AddEngineChangeListener(this); |
177 |
|
} |
178 |
|
|
179 |
|
void LSCPServer::EventHandler::ChannelToBeRemoved(SamplerChannel* pChannel) { |
180 |
|
if (!pChannel->GetEngineChannel()) return; |
181 |
|
EngineToBeChanged(pChannel->Index()); |
182 |
|
} |
183 |
|
|
184 |
|
void LSCPServer::EventHandler::EngineToBeChanged(int ChannelId) { |
185 |
|
SamplerChannel* pSamplerChannel = |
186 |
|
pParent->pSampler->GetSamplerChannel(ChannelId); |
187 |
|
if (!pSamplerChannel) return; |
188 |
|
EngineChannel* pEngineChannel = |
189 |
|
pSamplerChannel->GetEngineChannel(); |
190 |
|
if (!pEngineChannel) return; |
191 |
|
for (std::vector<midi_listener_entry>::iterator iter = channelMidiListeners.begin(); iter != channelMidiListeners.end(); ++iter) { |
192 |
|
if ((*iter).pEngineChannel == pEngineChannel) { |
193 |
|
VirtualMidiDevice* pMidiListener = (*iter).pMidiListener; |
194 |
|
pEngineChannel->Disconnect(pMidiListener); |
195 |
|
channelMidiListeners.erase(iter); |
196 |
|
delete pMidiListener; |
197 |
|
return; |
198 |
|
} |
199 |
|
} |
200 |
|
} |
201 |
|
|
202 |
|
void LSCPServer::EventHandler::EngineChanged(int ChannelId) { |
203 |
|
SamplerChannel* pSamplerChannel = |
204 |
|
pParent->pSampler->GetSamplerChannel(ChannelId); |
205 |
|
if (!pSamplerChannel) return; |
206 |
|
EngineChannel* pEngineChannel = |
207 |
|
pSamplerChannel->GetEngineChannel(); |
208 |
|
if (!pEngineChannel) return; |
209 |
|
VirtualMidiDevice* pMidiListener = new VirtualMidiDevice; |
210 |
|
pEngineChannel->Connect(pMidiListener); |
211 |
|
midi_listener_entry entry = { |
212 |
|
pSamplerChannel, pEngineChannel, pMidiListener |
213 |
|
}; |
214 |
|
channelMidiListeners.push_back(entry); |
215 |
|
} |
216 |
|
|
217 |
void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) { |
void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) { |
218 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount)); |
219 |
} |
} |
222 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount)); |
223 |
} |
} |
224 |
|
|
225 |
|
void LSCPServer::EventHandler::MidiDeviceToBeDestroyed(MidiInputDevice* pDevice) { |
226 |
|
pDevice->RemoveMidiPortCountListener(this); |
227 |
|
for (int i = 0; i < pDevice->PortCount(); ++i) |
228 |
|
MidiPortToBeRemoved(pDevice->GetPort(i)); |
229 |
|
} |
230 |
|
|
231 |
|
void LSCPServer::EventHandler::MidiDeviceCreated(MidiInputDevice* pDevice) { |
232 |
|
pDevice->AddMidiPortCountListener(this); |
233 |
|
for (int i = 0; i < pDevice->PortCount(); ++i) |
234 |
|
MidiPortAdded(pDevice->GetPort(i)); |
235 |
|
} |
236 |
|
|
237 |
|
void LSCPServer::EventHandler::MidiPortCountChanged(int NewCount) { |
238 |
|
// yet unused |
239 |
|
} |
240 |
|
|
241 |
|
void LSCPServer::EventHandler::MidiPortToBeRemoved(MidiInputPort* pPort) { |
242 |
|
for (std::vector<device_midi_listener_entry>::iterator iter = deviceMidiListeners.begin(); iter != deviceMidiListeners.end(); ++iter) { |
243 |
|
if ((*iter).pPort == pPort) { |
244 |
|
VirtualMidiDevice* pMidiListener = (*iter).pMidiListener; |
245 |
|
pPort->Disconnect(pMidiListener); |
246 |
|
deviceMidiListeners.erase(iter); |
247 |
|
delete pMidiListener; |
248 |
|
return; |
249 |
|
} |
250 |
|
} |
251 |
|
} |
252 |
|
|
253 |
|
void LSCPServer::EventHandler::MidiPortAdded(MidiInputPort* pPort) { |
254 |
|
// find out the device ID |
255 |
|
std::map<uint, MidiInputDevice*> devices = |
256 |
|
pParent->pSampler->GetMidiInputDevices(); |
257 |
|
for ( |
258 |
|
std::map<uint, MidiInputDevice*>::iterator iter = devices.begin(); |
259 |
|
iter != devices.end(); ++iter |
260 |
|
) { |
261 |
|
if (iter->second == pPort->GetDevice()) { // found |
262 |
|
VirtualMidiDevice* pMidiListener = new VirtualMidiDevice; |
263 |
|
pPort->Connect(pMidiListener); |
264 |
|
device_midi_listener_entry entry = { |
265 |
|
pPort, pMidiListener, iter->first |
266 |
|
}; |
267 |
|
deviceMidiListeners.push_back(entry); |
268 |
|
return; |
269 |
|
} |
270 |
|
} |
271 |
|
} |
272 |
|
|
273 |
void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) { |
void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) { |
274 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount)); |
275 |
} |
} |
306 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount)); |
307 |
} |
} |
308 |
|
|
309 |
|
void LSCPServer::EventHandler::TotalStreamCountChanged(int NewCount) { |
310 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_stream_count, NewCount)); |
311 |
|
} |
312 |
|
|
313 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
314 |
void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) { |
void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) { |
315 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, InstrumentsDb::toEscapedPath(Dir))); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, InstrumentsDb::toEscapedPath(Dir))); |
344 |
} |
} |
345 |
#endif // HAVE_SQLITE3 |
#endif // HAVE_SQLITE3 |
346 |
|
|
347 |
|
void LSCPServer::RemoveListeners() { |
348 |
|
pSampler->RemoveChannelCountListener(&eventHandler); |
349 |
|
pSampler->RemoveAudioDeviceCountListener(&eventHandler); |
350 |
|
pSampler->RemoveMidiDeviceCountListener(&eventHandler); |
351 |
|
pSampler->RemoveVoiceCountListener(&eventHandler); |
352 |
|
pSampler->RemoveStreamCountListener(&eventHandler); |
353 |
|
pSampler->RemoveBufferFillListener(&eventHandler); |
354 |
|
pSampler->RemoveTotalStreamCountListener(&eventHandler); |
355 |
|
pSampler->RemoveTotalVoiceCountListener(&eventHandler); |
356 |
|
pSampler->RemoveFxSendCountListener(&eventHandler); |
357 |
|
MidiInstrumentMapper::RemoveMidiInstrumentCountListener(&eventHandler); |
358 |
|
MidiInstrumentMapper::RemoveMidiInstrumentInfoListener(&eventHandler); |
359 |
|
MidiInstrumentMapper::RemoveMidiInstrumentMapCountListener(&eventHandler); |
360 |
|
MidiInstrumentMapper::RemoveMidiInstrumentMapInfoListener(&eventHandler); |
361 |
|
#if HAVE_SQLITE3 |
362 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveInstrumentsDbListener(&dbInstrumentsEventHandler); |
363 |
|
#endif |
364 |
|
} |
365 |
|
|
366 |
/** |
/** |
367 |
* Blocks the calling thread until the LSCP Server is initialized and |
* Blocks the calling thread until the LSCP Server is initialized and |
424 |
pSampler->AddVoiceCountListener(&eventHandler); |
pSampler->AddVoiceCountListener(&eventHandler); |
425 |
pSampler->AddStreamCountListener(&eventHandler); |
pSampler->AddStreamCountListener(&eventHandler); |
426 |
pSampler->AddBufferFillListener(&eventHandler); |
pSampler->AddBufferFillListener(&eventHandler); |
427 |
|
pSampler->AddTotalStreamCountListener(&eventHandler); |
428 |
pSampler->AddTotalVoiceCountListener(&eventHandler); |
pSampler->AddTotalVoiceCountListener(&eventHandler); |
429 |
pSampler->AddFxSendCountListener(&eventHandler); |
pSampler->AddFxSendCountListener(&eventHandler); |
430 |
MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler); |
MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler); |
444 |
timeval timeout; |
timeval timeout; |
445 |
|
|
446 |
while (true) { |
while (true) { |
447 |
|
#if CONFIG_PTHREAD_TESTCANCEL |
448 |
|
TestCancel(); |
449 |
|
#endif |
450 |
// check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers |
// check if some engine channel's parameter / status changed, if so notify the respective LSCP event subscribers |
451 |
{ |
{ |
452 |
|
LockGuard lock(EngineChannelFactory::EngineChannelsMutex); |
453 |
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
454 |
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
455 |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
456 |
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
457 |
if ((*itEngineChannel)->StatusChanged()) { |
if ((*itEngineChannel)->StatusChanged()) { |
458 |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->GetSamplerChannel()->Index())); |
459 |
} |
} |
460 |
|
|
461 |
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
462 |
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
463 |
if(fxs != NULL && fxs->IsInfoChanged()) { |
if(fxs != NULL && fxs->IsInfoChanged()) { |
464 |
int chn = (*itEngineChannel)->iSamplerChannelIndex; |
int chn = (*itEngineChannel)->GetSamplerChannel()->Index(); |
465 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id())); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id())); |
466 |
fxs->SetInfoChanged(false); |
fxs->SetInfoChanged(false); |
467 |
} |
} |
469 |
} |
} |
470 |
} |
} |
471 |
|
|
472 |
//Now let's deliver late notifies (if any) |
// check if MIDI data arrived on some engine channel |
473 |
NotifyBufferMutex.Lock(); |
for (int i = 0; i < eventHandler.channelMidiListeners.size(); ++i) { |
474 |
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
const EventHandler::midi_listener_entry entry = |
475 |
|
eventHandler.channelMidiListeners[i]; |
476 |
|
VirtualMidiDevice* pMidiListener = entry.pMidiListener; |
477 |
|
if (pMidiListener->NotesChanged()) { |
478 |
|
for (int iNote = 0; iNote < 128; iNote++) { |
479 |
|
if (pMidiListener->NoteChanged(iNote)) { |
480 |
|
const bool bActive = pMidiListener->NoteIsActive(iNote); |
481 |
|
LSCPServer::SendLSCPNotify( |
482 |
|
LSCPEvent( |
483 |
|
LSCPEvent::event_channel_midi, |
484 |
|
entry.pSamplerChannel->Index(), |
485 |
|
std::string(bActive ? "NOTE_ON" : "NOTE_OFF"), |
486 |
|
iNote, |
487 |
|
bActive ? pMidiListener->NoteOnVelocity(iNote) |
488 |
|
: pMidiListener->NoteOffVelocity(iNote) |
489 |
|
) |
490 |
|
); |
491 |
|
} |
492 |
|
} |
493 |
|
} |
494 |
|
} |
495 |
|
|
496 |
|
// check if MIDI data arrived on some MIDI device |
497 |
|
for (int i = 0; i < eventHandler.deviceMidiListeners.size(); ++i) { |
498 |
|
const EventHandler::device_midi_listener_entry entry = |
499 |
|
eventHandler.deviceMidiListeners[i]; |
500 |
|
VirtualMidiDevice* pMidiListener = entry.pMidiListener; |
501 |
|
if (pMidiListener->NotesChanged()) { |
502 |
|
for (int iNote = 0; iNote < 128; iNote++) { |
503 |
|
if (pMidiListener->NoteChanged(iNote)) { |
504 |
|
const bool bActive = pMidiListener->NoteIsActive(iNote); |
505 |
|
LSCPServer::SendLSCPNotify( |
506 |
|
LSCPEvent( |
507 |
|
LSCPEvent::event_device_midi, |
508 |
|
entry.uiDeviceID, |
509 |
|
entry.pPort->GetPortNumber(), |
510 |
|
std::string(bActive ? "NOTE_ON" : "NOTE_OFF"), |
511 |
|
iNote, |
512 |
|
bActive ? pMidiListener->NoteOnVelocity(iNote) |
513 |
|
: pMidiListener->NoteOffVelocity(iNote) |
514 |
|
) |
515 |
|
); |
516 |
|
} |
517 |
|
} |
518 |
|
} |
519 |
|
} |
520 |
|
|
521 |
|
//Now let's deliver late notifies (if any) |
522 |
|
{ |
523 |
|
LockGuard lock(NotifyBufferMutex); |
524 |
|
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
525 |
#ifdef MSG_NOSIGNAL |
#ifdef MSG_NOSIGNAL |
526 |
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL); |
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL); |
527 |
#else |
#else |
528 |
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); |
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); |
529 |
#endif |
#endif |
530 |
} |
} |
531 |
bufferedNotifies.clear(); |
bufferedNotifies.clear(); |
532 |
NotifyBufferMutex.Unlock(); |
} |
533 |
|
|
534 |
fd_set selectSet = fdSet; |
fd_set selectSet = fdSet; |
535 |
timeout.tv_sec = 0; |
timeout.tv_sec = 0; |
537 |
|
|
538 |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
539 |
|
|
540 |
if (retval == 0) |
if (retval == 0 || (retval == -1 && errno == EINTR)) |
541 |
continue; //Nothing try again |
continue; //Nothing try again |
542 |
if (retval == -1) { |
if (retval == -1) { |
543 |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
563 |
std::cerr << "LSCPServer: ioctlsocket: set FIONBIO failed. Error " << WSAGetLastError() << std::endl; |
std::cerr << "LSCPServer: ioctlsocket: set FIONBIO failed. Error " << WSAGetLastError() << std::endl; |
564 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
565 |
} |
} |
566 |
#else |
#else |
567 |
|
struct linger linger; |
568 |
|
linger.l_onoff = 1; |
569 |
|
linger.l_linger = 0; |
570 |
|
if(setsockopt(socket, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger))) { |
571 |
|
std::cerr << "LSCPServer: Failed to set SO_LINGER\n"; |
572 |
|
} |
573 |
|
|
574 |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
575 |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
576 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
594 |
//Something was selected and it was not the hSocket, so it must be some command(s) coming. |
//Something was selected and it was not the hSocket, so it must be some command(s) coming. |
595 |
for (std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); iter != Sessions.end(); iter++) { |
for (std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); iter != Sessions.end(); iter++) { |
596 |
if (FD_ISSET((*iter).hSession, &selectSet)) { //Was it this socket? |
if (FD_ISSET((*iter).hSession, &selectSet)) { //Was it this socket? |
597 |
|
currentSocket = (*iter).hSession; //a hack |
598 |
if (GetLSCPCommand(iter)) { //Have we read the entire command? |
if (GetLSCPCommand(iter)) { //Have we read the entire command? |
599 |
dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket)); |
dmsg(3,("LSCPServer: Got command on socket %d, calling parser.\n", currentSocket)); |
600 |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
int dummy; // just a temporary hack to fulfill the restart() function prototype |
601 |
restart(NULL, dummy); // restart the 'scanner' |
restart(NULL, dummy); // restart the 'scanner' |
|
currentSocket = (*iter).hSession; //a hack |
|
602 |
itCurrentSession = iter; // another hack |
itCurrentSession = iter; // another hack |
603 |
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
dmsg(2,("LSCPServer: [%s]\n",bufferedCommands[currentSocket].c_str())); |
604 |
if ((*iter).bVerbose) { // if echo mode enabled |
if ((*iter).bVerbose) { // if echo mode enabled |
612 |
CloseConnection(iter); |
CloseConnection(iter); |
613 |
} |
} |
614 |
} |
} |
615 |
|
currentSocket = -1; //continuation of a hack |
616 |
//socket may have been closed, iter may be invalid, get out of the loop for now. |
//socket may have been closed, iter may be invalid, get out of the loop for now. |
617 |
//we'll be back if there is data. |
//we'll be back if there is data. |
618 |
break; |
break; |
627 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket)); |
628 |
Sessions.erase(iter); |
Sessions.erase(iter); |
629 |
FD_CLR(socket, &fdSet); |
FD_CLR(socket, &fdSet); |
630 |
SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any) |
{ |
631 |
for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) { |
LockGuard lock(SubscriptionMutex); |
632 |
iter->second.remove(socket); |
// Must unsubscribe this socket from all events (if any) |
633 |
} |
for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) { |
634 |
SubscriptionMutex.Unlock(); |
iter->second.remove(socket); |
635 |
NotifyMutex.Lock(); |
} |
636 |
|
} |
637 |
|
LockGuard lock(NotifyMutex); |
638 |
bufferedCommands.erase(socket); |
bufferedCommands.erase(socket); |
639 |
bufferedNotifies.erase(socket); |
bufferedNotifies.erase(socket); |
640 |
#if defined(WIN32) |
#if defined(WIN32) |
642 |
#else |
#else |
643 |
close(socket); |
close(socket); |
644 |
#endif |
#endif |
645 |
NotifyMutex.Unlock(); |
} |
646 |
|
|
647 |
|
void LSCPServer::CloseAllConnections() { |
648 |
|
std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); |
649 |
|
while(iter != Sessions.end()) { |
650 |
|
CloseConnection(iter); |
651 |
|
iter = Sessions.begin(); |
652 |
|
} |
653 |
} |
} |
654 |
|
|
655 |
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
656 |
int subs = 0; |
int subs = 0; |
657 |
SubscriptionMutex.Lock(); |
LockGuard lock(SubscriptionMutex); |
658 |
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
659 |
iter != events.end(); iter++) |
iter != events.end(); iter++) |
660 |
{ |
{ |
661 |
subs += eventSubscriptions.count(*iter); |
subs += eventSubscriptions.count(*iter); |
662 |
} |
} |
|
SubscriptionMutex.Unlock(); |
|
663 |
return subs; |
return subs; |
664 |
} |
} |
665 |
|
|
666 |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
667 |
SubscriptionMutex.Lock(); |
LockGuard lock(SubscriptionMutex); |
668 |
if (eventSubscriptions.count(event.GetType()) == 0) { |
if (eventSubscriptions.count(event.GetType()) == 0) { |
669 |
SubscriptionMutex.Unlock(); //Nobody is subscribed to this event |
// Nobody is subscribed to this event |
670 |
return; |
return; |
671 |
} |
} |
672 |
std::list<int>::iterator iter = eventSubscriptions[event.GetType()].begin(); |
std::list<int>::iterator iter = eventSubscriptions[event.GetType()].begin(); |
692 |
} |
} |
693 |
} |
} |
694 |
} |
} |
|
SubscriptionMutex.Unlock(); |
|
695 |
} |
} |
696 |
|
|
697 |
extern int GetLSCPCommand( void *buf, int max_size ) { |
extern int GetLSCPCommand( void *buf, int max_size ) { |
722 |
*/ |
*/ |
723 |
bool LSCPServer::GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ) { |
bool LSCPServer::GetLSCPCommand( std::vector<yyparse_param_t>::iterator iter ) { |
724 |
int socket = (*iter).hSession; |
int socket = (*iter).hSession; |
725 |
|
int result; |
726 |
char c; |
char c; |
727 |
int i = 0; |
std::vector<char> input; |
728 |
|
|
729 |
|
// first get as many character as possible and add it to the 'input' buffer |
730 |
while (true) { |
while (true) { |
731 |
#if defined(WIN32) |
#if defined(WIN32) |
732 |
int result = recv(socket, (char *)&c, 1, 0); //Read one character at a time for now |
result = recv(socket, (char *)&c, 1, 0); //Read one character at a time for now |
733 |
#else |
#else |
734 |
int result = recv(socket, (void *)&c, 1, 0); //Read one character at a time for now |
result = recv(socket, (void *)&c, 1, 0); //Read one character at a time for now |
735 |
#endif |
#endif |
736 |
if (result == 0) { //socket was selected, so 0 here means client has closed the connection |
if (result == 1) input.push_back(c); |
737 |
CloseConnection(iter); |
else break; // end of input or some error |
738 |
break; |
if (c == '\n') break; // process line by line |
739 |
} |
} |
740 |
if (result == 1) { |
|
741 |
if (c == '\r') |
// process input buffer |
742 |
continue; //Ignore CR |
for (int i = 0; i < input.size(); ++i) { |
743 |
if (c == '\n') { |
c = input[i]; |
744 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket)); |
if (c == '\r') continue; //Ignore CR |
745 |
bufferedCommands[socket] += "\r\n"; |
if (c == '\n') { |
746 |
return true; //Complete command was read |
// only if the other side is the LSCP shell application: |
747 |
|
// check the current (incomplete) command line for syntax errors, |
748 |
|
// possible completions and report everything back to the shell |
749 |
|
if ((*iter).bShellInteract || (*iter).bShellAutoCorrect) { |
750 |
|
String s = lscpParserProcessShellInteraction(bufferedCommands[socket], &(*iter), false); |
751 |
|
if (!s.empty() && (*iter).bShellInteract) AnswerClient(s + "\n"); |
752 |
|
} |
753 |
|
|
754 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Received \'" + bufferedCommands[socket] + "\' on socket", socket)); |
755 |
|
bufferedCommands[socket] += "\r\n"; |
756 |
|
return true; //Complete command was read |
757 |
|
} else if (c == 2) { // custom ASCII code usage for moving cursor left (LSCP shell) |
758 |
|
if (iter->iCursorOffset + bufferedCommands[socket].size() > 0) |
759 |
|
iter->iCursorOffset--; |
760 |
|
} else if (c == 3) { // custom ASCII code usage for moving cursor right (LSCP shell) |
761 |
|
if (iter->iCursorOffset < 0) iter->iCursorOffset++; |
762 |
|
} else { |
763 |
|
size_t cursorPos = bufferedCommands[socket].size() + iter->iCursorOffset; |
764 |
|
// backspace character - should only happen with shell |
765 |
|
if (c == '\b') { |
766 |
|
if (!bufferedCommands[socket].empty() && cursorPos > 0) |
767 |
|
bufferedCommands[socket].erase(cursorPos - 1, 1); |
768 |
|
} else { // append (or insert) new character (at current cursor position) ... |
769 |
|
if (cursorPos >= 0) |
770 |
|
bufferedCommands[socket].insert(cursorPos, String(1,c)); // insert |
771 |
|
else |
772 |
|
bufferedCommands[socket] += c; // append |
773 |
} |
} |
|
bufferedCommands[socket] += c; |
|
774 |
} |
} |
775 |
#if defined(WIN32) |
// only if the other side is the LSCP shell application: |
776 |
if (result == SOCKET_ERROR) { |
// check the current (incomplete) command line for syntax errors, |
777 |
int wsa_lasterror = WSAGetLastError(); |
// possible completions and report everything back to the shell |
778 |
if (wsa_lasterror == WSAEWOULDBLOCK) //Would block, try again later. |
if ((*iter).bShellInteract || (*iter).bShellAutoCorrect) { |
779 |
return false; |
String s = lscpParserProcessShellInteraction(bufferedCommands[socket], &(*iter), true); |
780 |
dmsg(2,("LSCPScanner: Socket error after recv() Error %d.\n", wsa_lasterror)); |
if (!s.empty() && (*iter).bShellInteract && i == input.size() - 1) |
781 |
CloseConnection(iter); |
AnswerClient(s + "\n"); |
|
break; |
|
782 |
} |
} |
783 |
#else |
} |
784 |
if (result == -1) { |
|
785 |
if (errno == EAGAIN) //Would block, try again later. |
// handle network errors ... |
786 |
|
if (result == 0) { //socket was selected, so 0 here means client has closed the connection |
787 |
|
CloseConnection(iter); |
788 |
|
return false; |
789 |
|
} |
790 |
|
#if defined(WIN32) |
791 |
|
if (result == SOCKET_ERROR) { |
792 |
|
int wsa_lasterror = WSAGetLastError(); |
793 |
|
if (wsa_lasterror == WSAEWOULDBLOCK) //Would block, try again later. |
794 |
|
return false; |
795 |
|
dmsg(2,("LSCPScanner: Socket error after recv() Error %d.\n", wsa_lasterror)); |
796 |
|
CloseConnection(iter); |
797 |
|
return false; |
798 |
|
} |
799 |
|
#else |
800 |
|
if (result == -1) { |
801 |
|
if (errno == EAGAIN) //Would block, try again later. |
802 |
|
return false; |
803 |
|
switch(errno) { |
804 |
|
case EBADF: |
805 |
|
dmsg(2,("LSCPScanner: The argument s is an invalid descriptor.\n")); |
806 |
|
return false; |
807 |
|
case ECONNREFUSED: |
808 |
|
dmsg(2,("LSCPScanner: A remote host refused to allow the network connection (typically because it is not running the requested service).\n")); |
809 |
|
return false; |
810 |
|
case ENOTCONN: |
811 |
|
dmsg(2,("LSCPScanner: The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2)).\n")); |
812 |
|
return false; |
813 |
|
case ENOTSOCK: |
814 |
|
dmsg(2,("LSCPScanner: The argument s does not refer to a socket.\n")); |
815 |
|
return false; |
816 |
|
case EAGAIN: |
817 |
|
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")); |
818 |
|
return false; |
819 |
|
case EINTR: |
820 |
|
dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n")); |
821 |
|
return false; |
822 |
|
case EFAULT: |
823 |
|
dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n")); |
824 |
|
return false; |
825 |
|
case EINVAL: |
826 |
|
dmsg(2,("LSCPScanner: Invalid argument passed.\n")); |
827 |
|
return false; |
828 |
|
case ENOMEM: |
829 |
|
dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n")); |
830 |
|
return false; |
831 |
|
default: |
832 |
|
dmsg(2,("LSCPScanner: Unknown recv() error.\n")); |
833 |
return false; |
return false; |
|
switch(errno) { |
|
|
case EBADF: |
|
|
dmsg(2,("LSCPScanner: The argument s is an invalid descriptor.\n")); |
|
|
break; |
|
|
case ECONNREFUSED: |
|
|
dmsg(2,("LSCPScanner: A remote host refused to allow the network connection (typically because it is not running the requested service).\n")); |
|
|
break; |
|
|
case ENOTCONN: |
|
|
dmsg(2,("LSCPScanner: The socket is associated with a connection-oriented protocol and has not been connected (see connect(2) and accept(2)).\n")); |
|
|
break; |
|
|
case ENOTSOCK: |
|
|
dmsg(2,("LSCPScanner: The argument s does not refer to a socket.\n")); |
|
|
break; |
|
|
case EAGAIN: |
|
|
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")); |
|
|
break; |
|
|
case EINTR: |
|
|
dmsg(2,("LSCPScanner: The receive was interrupted by delivery of a signal before any data were available.\n")); |
|
|
break; |
|
|
case EFAULT: |
|
|
dmsg(2,("LSCPScanner: The receive buffer pointer(s) point outside the process's address space.\n")); |
|
|
break; |
|
|
case EINVAL: |
|
|
dmsg(2,("LSCPScanner: Invalid argument passed.\n")); |
|
|
break; |
|
|
case ENOMEM: |
|
|
dmsg(2,("LSCPScanner: Could not allocate memory for recvmsg.\n")); |
|
|
break; |
|
|
default: |
|
|
dmsg(2,("LSCPScanner: Unknown recv() error.\n")); |
|
|
break; |
|
|
} |
|
|
CloseConnection(iter); |
|
|
break; |
|
834 |
} |
} |
835 |
#endif |
CloseConnection(iter); |
836 |
|
return false; |
837 |
} |
} |
838 |
|
#endif |
839 |
|
|
840 |
return false; |
return false; |
841 |
} |
} |
842 |
|
|
847 |
* @param ReturnMessage - message that will be send to the client |
* @param ReturnMessage - message that will be send to the client |
848 |
*/ |
*/ |
849 |
void LSCPServer::AnswerClient(String ReturnMessage) { |
void LSCPServer::AnswerClient(String ReturnMessage) { |
850 |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage='%s')", ReturnMessage.c_str())); |
851 |
if (currentSocket != -1) { |
if (currentSocket != -1) { |
852 |
NotifyMutex.Lock(); |
LockGuard lock(NotifyMutex); |
853 |
|
|
854 |
|
// just if other side is LSCP shell: in case respose is a multi-line |
855 |
|
// one, then inform client about it before sending the actual mult-line |
856 |
|
// response |
857 |
|
if (GetCurrentYaccSession()->bShellInteract) { |
858 |
|
// check if this is a multi-line response |
859 |
|
int n = 0; |
860 |
|
for (int i = 0; i < ReturnMessage.size(); ++i) |
861 |
|
if (ReturnMessage[i] == '\n') ++n; |
862 |
|
if (n >= 2) { |
863 |
|
dmsg(2,("LSCP Shell <- expect mult-line response\n")); |
864 |
|
String s = LSCP_SHK_EXPECT_MULTI_LINE "\r\n"; |
865 |
|
#ifdef MSG_NOSIGNAL |
866 |
|
send(currentSocket, s.c_str(), s.size(), MSG_NOSIGNAL); |
867 |
|
#else |
868 |
|
send(currentSocket, s.c_str(), s.size(), 0); |
869 |
|
#endif |
870 |
|
} |
871 |
|
} |
872 |
|
|
873 |
#ifdef MSG_NOSIGNAL |
#ifdef MSG_NOSIGNAL |
874 |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL); |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL); |
875 |
#else |
#else |
876 |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
877 |
#endif |
#endif |
|
NotifyMutex.Unlock(); |
|
878 |
} |
} |
879 |
} |
} |
880 |
|
|
1024 |
try { |
try { |
1025 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1026 |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1027 |
LockRTNotify(); |
LockGuard lock(RTNotifyMutex); |
1028 |
pSamplerChannel->SetEngineType(EngineName); |
pSamplerChannel->SetEngineType(EngineName); |
1029 |
if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1); |
if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1); |
|
UnlockRTNotify(); |
|
1030 |
} |
} |
1031 |
catch (Exception e) { |
catch (Exception e) { |
1032 |
result.Error(e); |
result.Error(e); |
1066 |
*/ |
*/ |
1067 |
String LSCPServer::AddChannel() { |
String LSCPServer::AddChannel() { |
1068 |
dmsg(2,("LSCPServer: AddChannel()\n")); |
dmsg(2,("LSCPServer: AddChannel()\n")); |
1069 |
LockRTNotify(); |
SamplerChannel* pSamplerChannel; |
1070 |
SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel(); |
{ |
1071 |
UnlockRTNotify(); |
LockGuard lock(RTNotifyMutex); |
1072 |
|
pSamplerChannel = pSampler->AddSamplerChannel(); |
1073 |
|
} |
1074 |
LSCPResultSet result(pSamplerChannel->Index()); |
LSCPResultSet result(pSamplerChannel->Index()); |
1075 |
return result.Produce(); |
return result.Produce(); |
1076 |
} |
} |
1081 |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
1082 |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
1083 |
LSCPResultSet result; |
LSCPResultSet result; |
1084 |
LockRTNotify(); |
{ |
1085 |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
LockGuard lock(RTNotifyMutex); |
1086 |
UnlockRTNotify(); |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
1087 |
|
} |
1088 |
return result.Produce(); |
return result.Produce(); |
1089 |
} |
} |
1090 |
|
|
1127 |
String LSCPServer::GetEngineInfo(String EngineName) { |
String LSCPServer::GetEngineInfo(String EngineName) { |
1128 |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
1129 |
LSCPResultSet result; |
LSCPResultSet result; |
1130 |
LockRTNotify(); |
{ |
1131 |
try { |
LockGuard lock(RTNotifyMutex); |
1132 |
Engine* pEngine = EngineFactory::Create(EngineName); |
try { |
1133 |
result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description())); |
Engine* pEngine = EngineFactory::Create(EngineName); |
1134 |
result.Add("VERSION", pEngine->Version()); |
result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description())); |
1135 |
EngineFactory::Destroy(pEngine); |
result.Add("VERSION", pEngine->Version()); |
1136 |
} |
EngineFactory::Destroy(pEngine); |
1137 |
catch (Exception e) { |
} |
1138 |
result.Error(e); |
catch (Exception e) { |
1139 |
|
result.Error(e); |
1140 |
|
} |
1141 |
} |
} |
|
UnlockRTNotify(); |
|
1142 |
return result.Produce(); |
return result.Produce(); |
1143 |
} |
} |
1144 |
|
|
1237 |
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
1238 |
LSCPResultSet result; |
LSCPResultSet result; |
1239 |
try { |
try { |
1240 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine loaded on sampler channel"); |
|
1241 |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
1242 |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
1243 |
} |
} |
1255 |
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
1256 |
LSCPResultSet result; |
LSCPResultSet result; |
1257 |
try { |
try { |
1258 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
1259 |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
1260 |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
1261 |
} |
} |
1273 |
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); |
1274 |
LSCPResultSet result; |
LSCPResultSet result; |
1275 |
try { |
try { |
1276 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
1277 |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
1278 |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
1279 |
else { |
else { |
1361 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1362 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1363 |
s += iter->first; |
s += iter->first; |
1364 |
|
delete iter->second; |
1365 |
} |
} |
1366 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1367 |
} |
} |
1386 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1387 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1388 |
s += iter->first; |
s += iter->first; |
1389 |
|
delete iter->second; |
1390 |
} |
} |
1391 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1392 |
} |
} |
1417 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1418 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1419 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1420 |
|
delete pParameter; |
1421 |
} |
} |
1422 |
catch (Exception e) { |
catch (Exception e) { |
1423 |
result.Error(e); |
result.Error(e); |
1445 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1446 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1447 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1448 |
|
delete pParameter; |
1449 |
} |
} |
1450 |
catch (Exception e) { |
catch (Exception e) { |
1451 |
result.Error(e); |
result.Error(e); |
1787 |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
1788 |
dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel)); |
1789 |
LSCPResultSet result; |
LSCPResultSet result; |
1790 |
LockRTNotify(); |
{ |
1791 |
|
LockGuard lock(RTNotifyMutex); |
1792 |
|
try { |
1793 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1794 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1795 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1796 |
|
if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId)); |
1797 |
|
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
1798 |
|
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1799 |
|
} |
1800 |
|
catch (Exception e) { |
1801 |
|
result.Error(e); |
1802 |
|
} |
1803 |
|
} |
1804 |
|
return result.Produce(); |
1805 |
|
} |
1806 |
|
|
1807 |
|
String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) { |
1808 |
|
dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel)); |
1809 |
|
LSCPResultSet result; |
1810 |
|
{ |
1811 |
|
LockGuard lock(RTNotifyMutex); |
1812 |
|
try { |
1813 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1814 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1815 |
|
// Driver type name aliasing... |
1816 |
|
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
1817 |
|
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
1818 |
|
// Check if there's one audio output device already created |
1819 |
|
// for the intended audio driver type (AudioOutputDriver)... |
1820 |
|
AudioOutputDevice *pDevice = NULL; |
1821 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1822 |
|
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
1823 |
|
for (; iter != devices.end(); iter++) { |
1824 |
|
if ((iter->second)->Driver() == AudioOutputDriver) { |
1825 |
|
pDevice = iter->second; |
1826 |
|
break; |
1827 |
|
} |
1828 |
|
} |
1829 |
|
// If it doesn't exist, create a new one with default parameters... |
1830 |
|
if (pDevice == NULL) { |
1831 |
|
std::map<String,String> params; |
1832 |
|
pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params); |
1833 |
|
} |
1834 |
|
// Must have a device... |
1835 |
|
if (pDevice == NULL) |
1836 |
|
throw Exception("Internal error: could not create audio output device."); |
1837 |
|
// Set it as the current channel device... |
1838 |
|
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1839 |
|
} |
1840 |
|
catch (Exception e) { |
1841 |
|
result.Error(e); |
1842 |
|
} |
1843 |
|
} |
1844 |
|
return result.Produce(); |
1845 |
|
} |
1846 |
|
|
1847 |
|
String LSCPServer::AddChannelMidiInput(uint uiSamplerChannel, uint MIDIDeviceId, uint MIDIPort) { |
1848 |
|
dmsg(2,("LSCPServer: AddChannelMidiInput(uiSamplerChannel=%d, MIDIDeviceId=%d, MIDIPort=%d)\n",uiSamplerChannel,MIDIDeviceId,MIDIPort)); |
1849 |
|
LSCPResultSet result; |
1850 |
try { |
try { |
1851 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1852 |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1853 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
|
1854 |
if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId)); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1855 |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1856 |
pSamplerChannel->SetAudioOutputDevice(pDevice); |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1857 |
|
|
1858 |
|
MidiInputPort* pPort = pDevice->GetPort(MIDIPort); |
1859 |
|
if (!pPort) throw Exception("There is no MIDI input port with index " + ToString(MIDIPort) + " on MIDI input device with index " + ToString(MIDIDeviceId)); |
1860 |
|
|
1861 |
|
pSamplerChannel->Connect(pPort); |
1862 |
|
} catch (Exception e) { |
1863 |
|
result.Error(e); |
1864 |
} |
} |
1865 |
catch (Exception e) { |
return result.Produce(); |
1866 |
result.Error(e); |
} |
1867 |
|
|
1868 |
|
String LSCPServer::RemoveChannelMidiInput(uint uiSamplerChannel) { |
1869 |
|
dmsg(2,("LSCPServer: RemoveChannelMidiInput(uiSamplerChannel=%d)\n",uiSamplerChannel)); |
1870 |
|
LSCPResultSet result; |
1871 |
|
try { |
1872 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1873 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1874 |
|
pSamplerChannel->DisconnectAllMidiInputPorts(); |
1875 |
|
} catch (Exception e) { |
1876 |
|
result.Error(e); |
1877 |
} |
} |
|
UnlockRTNotify(); |
|
1878 |
return result.Produce(); |
return result.Produce(); |
1879 |
} |
} |
1880 |
|
|
1881 |
String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) { |
String LSCPServer::RemoveChannelMidiInput(uint uiSamplerChannel, uint MIDIDeviceId) { |
1882 |
dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel)); |
dmsg(2,("LSCPServer: RemoveChannelMidiInput(uiSamplerChannel=%d, MIDIDeviceId=%d)\n",uiSamplerChannel,MIDIDeviceId)); |
1883 |
LSCPResultSet result; |
LSCPResultSet result; |
|
LockRTNotify(); |
|
1884 |
try { |
try { |
1885 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1886 |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1887 |
// Driver type name aliasing... |
|
1888 |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1889 |
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1890 |
// Check if there's one audio output device already created |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1891 |
// for the intended audio driver type (AudioOutputDriver)... |
|
1892 |
AudioOutputDevice *pDevice = NULL; |
std::vector<MidiInputPort*> vPorts = pSamplerChannel->GetMidiInputPorts(); |
1893 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
for (int i = 0; i < vPorts.size(); ++i) |
1894 |
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
if (vPorts[i]->GetDevice() == pDevice) |
1895 |
for (; iter != devices.end(); iter++) { |
pSamplerChannel->Disconnect(vPorts[i]); |
1896 |
if ((iter->second)->Driver() == AudioOutputDriver) { |
|
1897 |
pDevice = iter->second; |
} catch (Exception e) { |
1898 |
break; |
result.Error(e); |
|
} |
|
|
} |
|
|
// If it doesn't exist, create a new one with default parameters... |
|
|
if (pDevice == NULL) { |
|
|
std::map<String,String> params; |
|
|
pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params); |
|
|
} |
|
|
// Must have a device... |
|
|
if (pDevice == NULL) |
|
|
throw Exception("Internal error: could not create audio output device."); |
|
|
// Set it as the current channel device... |
|
|
pSamplerChannel->SetAudioOutputDevice(pDevice); |
|
1899 |
} |
} |
1900 |
catch (Exception e) { |
return result.Produce(); |
1901 |
result.Error(e); |
} |
1902 |
|
|
1903 |
|
String LSCPServer::RemoveChannelMidiInput(uint uiSamplerChannel, uint MIDIDeviceId, uint MIDIPort) { |
1904 |
|
dmsg(2,("LSCPServer: RemoveChannelMidiInput(uiSamplerChannel=%d, MIDIDeviceId=%d, MIDIPort=%d)\n",uiSamplerChannel,MIDIDeviceId,MIDIPort)); |
1905 |
|
LSCPResultSet result; |
1906 |
|
try { |
1907 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1908 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1909 |
|
|
1910 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1911 |
|
if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1912 |
|
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1913 |
|
|
1914 |
|
MidiInputPort* pPort = pDevice->GetPort(MIDIPort); |
1915 |
|
if (!pPort) throw Exception("There is no MIDI input port with index " + ToString(MIDIPort) + " on MIDI input device with index " + ToString(MIDIDeviceId)); |
1916 |
|
|
1917 |
|
pSamplerChannel->Disconnect(pPort); |
1918 |
|
} catch (Exception e) { |
1919 |
|
result.Error(e); |
1920 |
|
} |
1921 |
|
return result.Produce(); |
1922 |
|
} |
1923 |
|
|
1924 |
|
String LSCPServer::ListChannelMidiInputs(uint uiSamplerChannel) { |
1925 |
|
dmsg(2,("LSCPServer: ListChannelMidiInputs(uiSamplerChannel=%d)\n",uiSamplerChannel)); |
1926 |
|
LSCPResultSet result; |
1927 |
|
try { |
1928 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1929 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1930 |
|
std::vector<MidiInputPort*> vPorts = pSamplerChannel->GetMidiInputPorts(); |
1931 |
|
|
1932 |
|
String s; |
1933 |
|
for (int i = 0; i < vPorts.size(); ++i) { |
1934 |
|
const int iDeviceID = vPorts[i]->GetDevice()->MidiInputDeviceID(); |
1935 |
|
const int iPortNr = vPorts[i]->GetPortNumber(); |
1936 |
|
if (s.size()) s += ","; |
1937 |
|
s += "{" + ToString(iDeviceID) + "," |
1938 |
|
+ ToString(iPortNr) + "}"; |
1939 |
|
} |
1940 |
|
result.Add(s); |
1941 |
|
} catch (Exception e) { |
1942 |
|
result.Error(e); |
1943 |
} |
} |
|
UnlockRTNotify(); |
|
1944 |
return result.Produce(); |
return result.Produce(); |
1945 |
} |
} |
1946 |
|
|
2014 |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
2015 |
// Make it with at least one initial port. |
// Make it with at least one initial port. |
2016 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
|
parameters["PORTS"]->SetValue("1"); |
|
2017 |
} |
} |
2018 |
// Must have a device... |
// Must have a device... |
2019 |
if (pDevice == NULL) |
if (pDevice == NULL) |
2056 |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
2057 |
LSCPResultSet result; |
LSCPResultSet result; |
2058 |
try { |
try { |
2059 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
2060 |
pEngineChannel->Volume(dVolume); |
pEngineChannel->Volume(dVolume); |
2061 |
} |
} |
2062 |
catch (Exception e) { |
catch (Exception e) { |
2072 |
dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); |
2073 |
LSCPResultSet result; |
LSCPResultSet result; |
2074 |
try { |
try { |
2075 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
|
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
2076 |
|
|
2077 |
if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); |
if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); |
2078 |
else pEngineChannel->SetMute(1); |
else pEngineChannel->SetMute(1); |
2089 |
dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel)); |
2090 |
LSCPResultSet result; |
LSCPResultSet result; |
2091 |
try { |
try { |
2092 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
|
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
2093 |
|
|
2094 |
bool oldSolo = pEngineChannel->GetSolo(); |
bool oldSolo = pEngineChannel->GetSolo(); |
2095 |
bool hadSoloChannel = HasSoloChannel(); |
bool hadSoloChannel = HasSoloChannel(); |
2209 |
dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n")); |
dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n")); |
2210 |
LSCPResultSet result; |
LSCPResultSet result; |
2211 |
try { |
try { |
2212 |
result.Add(MidiInstrumentMapper::Entries(MidiMapID).size()); |
result.Add(MidiInstrumentMapper::GetInstrumentCount(MidiMapID)); |
2213 |
} catch (Exception e) { |
} catch (Exception e) { |
2214 |
result.Error(e); |
result.Error(e); |
2215 |
} |
} |
2220 |
String LSCPServer::GetAllMidiInstrumentMappings() { |
String LSCPServer::GetAllMidiInstrumentMappings() { |
2221 |
dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n")); |
dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n")); |
2222 |
LSCPResultSet result; |
LSCPResultSet result; |
2223 |
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
try { |
2224 |
int totalMappings = 0; |
result.Add(MidiInstrumentMapper::GetInstrumentCount()); |
2225 |
for (int i = 0; i < maps.size(); i++) { |
} catch (Exception e) { |
2226 |
try { |
result.Error(e); |
|
totalMappings += MidiInstrumentMapper::Entries(maps[i]).size(); |
|
|
} catch (Exception e) { /*NOOP*/ } |
|
2227 |
} |
} |
|
result.Add(totalMappings); |
|
2228 |
return result.Produce(); |
return result.Produce(); |
2229 |
} |
} |
2230 |
|
|
2232 |
dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n")); |
dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n")); |
2233 |
LSCPResultSet result; |
LSCPResultSet result; |
2234 |
try { |
try { |
2235 |
midi_prog_index_t idx; |
MidiInstrumentMapper::entry_t entry = MidiInstrumentMapper::GetEntry(MidiMapID, MidiBank, MidiProg); |
2236 |
idx.midi_bank_msb = (MidiBank >> 7) & 0x7f; |
// convert the filename into the correct encoding as defined for LSCP |
2237 |
idx.midi_bank_lsb = MidiBank & 0x7f; |
// (especially in terms of special characters -> escape sequences) |
|
idx.midi_prog = MidiProg; |
|
|
|
|
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID); |
|
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx); |
|
|
if (iter == mappings.end()) result.Error("there is no map entry with that index"); |
|
|
else { // found |
|
|
|
|
|
// convert the filename into the correct encoding as defined for LSCP |
|
|
// (especially in terms of special characters -> escape sequences) |
|
2238 |
#if WIN32 |
#if WIN32 |
2239 |
const String instrumentFileName = Path::fromWindows(iter->second.InstrumentFile).toLscp(); |
const String instrumentFileName = Path::fromWindows(entry.InstrumentFile).toLscp(); |
2240 |
#else |
#else |
2241 |
// assuming POSIX |
// assuming POSIX |
2242 |
const String instrumentFileName = Path::fromPosix(iter->second.InstrumentFile).toLscp(); |
const String instrumentFileName = Path::fromPosix(entry.InstrumentFile).toLscp(); |
2243 |
#endif |
#endif |
2244 |
|
|
2245 |
result.Add("NAME", _escapeLscpResponse(iter->second.Name)); |
result.Add("NAME", _escapeLscpResponse(entry.Name)); |
2246 |
result.Add("ENGINE_NAME", iter->second.EngineName); |
result.Add("ENGINE_NAME", entry.EngineName); |
2247 |
result.Add("INSTRUMENT_FILE", instrumentFileName); |
result.Add("INSTRUMENT_FILE", instrumentFileName); |
2248 |
result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex); |
result.Add("INSTRUMENT_NR", (int) entry.InstrumentIndex); |
2249 |
String instrumentName; |
String instrumentName; |
2250 |
Engine* pEngine = EngineFactory::Create(iter->second.EngineName); |
Engine* pEngine = EngineFactory::Create(entry.EngineName); |
2251 |
if (pEngine) { |
if (pEngine) { |
2252 |
if (pEngine->GetInstrumentManager()) { |
if (pEngine->GetInstrumentManager()) { |
2253 |
InstrumentManager::instrument_id_t instrID; |
InstrumentManager::instrument_id_t instrID; |
2254 |
instrID.FileName = iter->second.InstrumentFile; |
instrID.FileName = entry.InstrumentFile; |
2255 |
instrID.Index = iter->second.InstrumentIndex; |
instrID.Index = entry.InstrumentIndex; |
2256 |
instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID); |
instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID); |
|
} |
|
|
EngineFactory::Destroy(pEngine); |
|
2257 |
} |
} |
2258 |
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName)); |
EngineFactory::Destroy(pEngine); |
2259 |
switch (iter->second.LoadMode) { |
} |
2260 |
case MidiInstrumentMapper::ON_DEMAND: |
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName)); |
2261 |
result.Add("LOAD_MODE", "ON_DEMAND"); |
switch (entry.LoadMode) { |
2262 |
break; |
case MidiInstrumentMapper::ON_DEMAND: |
2263 |
case MidiInstrumentMapper::ON_DEMAND_HOLD: |
result.Add("LOAD_MODE", "ON_DEMAND"); |
2264 |
result.Add("LOAD_MODE", "ON_DEMAND_HOLD"); |
break; |
2265 |
break; |
case MidiInstrumentMapper::ON_DEMAND_HOLD: |
2266 |
case MidiInstrumentMapper::PERSISTENT: |
result.Add("LOAD_MODE", "ON_DEMAND_HOLD"); |
2267 |
result.Add("LOAD_MODE", "PERSISTENT"); |
break; |
2268 |
break; |
case MidiInstrumentMapper::PERSISTENT: |
2269 |
default: |
result.Add("LOAD_MODE", "PERSISTENT"); |
2270 |
throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!"); |
break; |
2271 |
} |
default: |
2272 |
result.Add("VOLUME", iter->second.Volume); |
throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!"); |
2273 |
} |
} |
2274 |
|
result.Add("VOLUME", entry.Volume); |
2275 |
} catch (Exception e) { |
} catch (Exception e) { |
2276 |
result.Error(e); |
result.Error(e); |
2277 |
} |
} |
2442 |
dmsg(2,("LSCPServer: SetChannelMap()\n")); |
dmsg(2,("LSCPServer: SetChannelMap()\n")); |
2443 |
LSCPResultSet result; |
LSCPResultSet result; |
2444 |
try { |
try { |
2445 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
|
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); |
|
2446 |
|
|
2447 |
if (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone(); |
if (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone(); |
2448 |
else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault(); |
else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault(); |
2550 |
AudioRouting += ToString(pFxSend->DestinationChannel(chan)); |
AudioRouting += ToString(pFxSend->DestinationChannel(chan)); |
2551 |
} |
} |
2552 |
|
|
2553 |
|
const String sEffectRouting = |
2554 |
|
(pFxSend->DestinationEffectChain() >= 0 && pFxSend->DestinationEffectChainPosition() >= 0) |
2555 |
|
? ToString(pFxSend->DestinationEffectChain()) + "," + ToString(pFxSend->DestinationEffectChainPosition()) |
2556 |
|
: "NONE"; |
2557 |
|
|
2558 |
// success |
// success |
2559 |
result.Add("NAME", _escapeLscpResponse(pFxSend->Name())); |
result.Add("NAME", _escapeLscpResponse(pFxSend->Name())); |
2560 |
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
2561 |
result.Add("LEVEL", ToString(pFxSend->Level())); |
result.Add("LEVEL", ToString(pFxSend->Level())); |
2562 |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
2563 |
|
result.Add("EFFECT", sEffectRouting); |
2564 |
} catch (Exception e) { |
} catch (Exception e) { |
2565 |
result.Error(e); |
result.Error(e); |
2566 |
} |
} |
2623 |
return result.Produce(); |
return result.Produce(); |
2624 |
} |
} |
2625 |
|
|
2626 |
|
String LSCPServer::SetFxSendEffect(uint uiSamplerChannel, uint FxSendID, int iSendEffectChain, int iEffectChainPosition) { |
2627 |
|
dmsg(2,("LSCPServer: SetFxSendEffect(%d,%d)\n", iSendEffectChain, iEffectChainPosition)); |
2628 |
|
LSCPResultSet result; |
2629 |
|
try { |
2630 |
|
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2631 |
|
|
2632 |
|
pFxSend->SetDestinationEffect(iSendEffectChain, iEffectChainPosition); |
2633 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2634 |
|
} catch (Exception e) { |
2635 |
|
result.Error(e); |
2636 |
|
} |
2637 |
|
return result.Produce(); |
2638 |
|
} |
2639 |
|
|
2640 |
|
String LSCPServer::GetAvailableEffects() { |
2641 |
|
dmsg(2,("LSCPServer: GetAvailableEffects()\n")); |
2642 |
|
LSCPResultSet result; |
2643 |
|
try { |
2644 |
|
int n = EffectFactory::AvailableEffectsCount(); |
2645 |
|
result.Add(n); |
2646 |
|
} |
2647 |
|
catch (Exception e) { |
2648 |
|
result.Error(e); |
2649 |
|
} |
2650 |
|
return result.Produce(); |
2651 |
|
} |
2652 |
|
|
2653 |
|
String LSCPServer::ListAvailableEffects() { |
2654 |
|
dmsg(2,("LSCPServer: ListAvailableEffects()\n")); |
2655 |
|
LSCPResultSet result; |
2656 |
|
String list; |
2657 |
|
try { |
2658 |
|
//FIXME: for now we simply enumerate from 0 .. EffectFactory::AvailableEffectsCount() here, in future we should use unique IDs for effects during the whole sampler session. This issue comes into game when the user forces a reload of available effect plugins |
2659 |
|
int n = EffectFactory::AvailableEffectsCount(); |
2660 |
|
for (int i = 0; i < n; i++) { |
2661 |
|
if (i) list += ","; |
2662 |
|
list += ToString(i); |
2663 |
|
} |
2664 |
|
} |
2665 |
|
catch (Exception e) { |
2666 |
|
result.Error(e); |
2667 |
|
} |
2668 |
|
result.Add(list); |
2669 |
|
return result.Produce(); |
2670 |
|
} |
2671 |
|
|
2672 |
|
String LSCPServer::GetEffectInfo(int iEffectIndex) { |
2673 |
|
dmsg(2,("LSCPServer: GetEffectInfo(%d)\n", iEffectIndex)); |
2674 |
|
LSCPResultSet result; |
2675 |
|
try { |
2676 |
|
EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(iEffectIndex); |
2677 |
|
if (!pEffectInfo) |
2678 |
|
throw Exception("There is no effect with index " + ToString(iEffectIndex)); |
2679 |
|
|
2680 |
|
// convert the filename into the correct encoding as defined for LSCP |
2681 |
|
// (especially in terms of special characters -> escape sequences) |
2682 |
|
#if WIN32 |
2683 |
|
const String dllFileName = Path::fromWindows(pEffectInfo->Module()).toLscp(); |
2684 |
|
#else |
2685 |
|
// assuming POSIX |
2686 |
|
const String dllFileName = Path::fromPosix(pEffectInfo->Module()).toLscp(); |
2687 |
|
#endif |
2688 |
|
|
2689 |
|
result.Add("SYSTEM", pEffectInfo->EffectSystem()); |
2690 |
|
result.Add("MODULE", dllFileName); |
2691 |
|
result.Add("NAME", _escapeLscpResponse(pEffectInfo->Name())); |
2692 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(pEffectInfo->Description())); |
2693 |
|
} |
2694 |
|
catch (Exception e) { |
2695 |
|
result.Error(e); |
2696 |
|
} |
2697 |
|
return result.Produce(); |
2698 |
|
} |
2699 |
|
|
2700 |
|
String LSCPServer::GetEffectInstanceInfo(int iEffectInstance) { |
2701 |
|
dmsg(2,("LSCPServer: GetEffectInstanceInfo(%d)\n", iEffectInstance)); |
2702 |
|
LSCPResultSet result; |
2703 |
|
try { |
2704 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2705 |
|
if (!pEffect) |
2706 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2707 |
|
|
2708 |
|
EffectInfo* pEffectInfo = pEffect->GetEffectInfo(); |
2709 |
|
|
2710 |
|
// convert the filename into the correct encoding as defined for LSCP |
2711 |
|
// (especially in terms of special characters -> escape sequences) |
2712 |
|
#if WIN32 |
2713 |
|
const String dllFileName = Path::fromWindows(pEffectInfo->Module()).toLscp(); |
2714 |
|
#else |
2715 |
|
// assuming POSIX |
2716 |
|
const String dllFileName = Path::fromPosix(pEffectInfo->Module()).toLscp(); |
2717 |
|
#endif |
2718 |
|
|
2719 |
|
result.Add("SYSTEM", pEffectInfo->EffectSystem()); |
2720 |
|
result.Add("MODULE", dllFileName); |
2721 |
|
result.Add("NAME", _escapeLscpResponse(pEffectInfo->Name())); |
2722 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(pEffectInfo->Description())); |
2723 |
|
result.Add("INPUT_CONTROLS", ToString(pEffect->InputControlCount())); |
2724 |
|
} |
2725 |
|
catch (Exception e) { |
2726 |
|
result.Error(e); |
2727 |
|
} |
2728 |
|
return result.Produce(); |
2729 |
|
} |
2730 |
|
|
2731 |
|
String LSCPServer::GetEffectInstanceInputControlInfo(int iEffectInstance, int iInputControlIndex) { |
2732 |
|
dmsg(2,("LSCPServer: GetEffectInstanceInputControlInfo(%d,%d)\n", iEffectInstance, iInputControlIndex)); |
2733 |
|
LSCPResultSet result; |
2734 |
|
try { |
2735 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2736 |
|
if (!pEffect) |
2737 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2738 |
|
|
2739 |
|
EffectControl* pEffectControl = pEffect->InputControl(iInputControlIndex); |
2740 |
|
if (!pEffectControl) |
2741 |
|
throw Exception( |
2742 |
|
"Effect instance " + ToString(iEffectInstance) + |
2743 |
|
" does not have an input control with index " + |
2744 |
|
ToString(iInputControlIndex) |
2745 |
|
); |
2746 |
|
|
2747 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(pEffectControl->Description())); |
2748 |
|
result.Add("VALUE", pEffectControl->Value()); |
2749 |
|
if (pEffectControl->MinValue()) |
2750 |
|
result.Add("RANGE_MIN", *pEffectControl->MinValue()); |
2751 |
|
if (pEffectControl->MaxValue()) |
2752 |
|
result.Add("RANGE_MAX", *pEffectControl->MaxValue()); |
2753 |
|
if (!pEffectControl->Possibilities().empty()) |
2754 |
|
result.Add("POSSIBILITIES", pEffectControl->Possibilities()); |
2755 |
|
if (pEffectControl->DefaultValue()) |
2756 |
|
result.Add("DEFAULT", *pEffectControl->DefaultValue()); |
2757 |
|
} catch (Exception e) { |
2758 |
|
result.Error(e); |
2759 |
|
} |
2760 |
|
return result.Produce(); |
2761 |
|
} |
2762 |
|
|
2763 |
|
String LSCPServer::SetEffectInstanceInputControlValue(int iEffectInstance, int iInputControlIndex, double dValue) { |
2764 |
|
dmsg(2,("LSCPServer: SetEffectInstanceInputControlValue(%d,%d,%f)\n", iEffectInstance, iInputControlIndex, dValue)); |
2765 |
|
LSCPResultSet result; |
2766 |
|
try { |
2767 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2768 |
|
if (!pEffect) |
2769 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2770 |
|
|
2771 |
|
EffectControl* pEffectControl = pEffect->InputControl(iInputControlIndex); |
2772 |
|
if (!pEffectControl) |
2773 |
|
throw Exception( |
2774 |
|
"Effect instance " + ToString(iEffectInstance) + |
2775 |
|
" does not have an input control with index " + |
2776 |
|
ToString(iInputControlIndex) |
2777 |
|
); |
2778 |
|
|
2779 |
|
pEffectControl->SetValue(dValue); |
2780 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_info, iEffectInstance)); |
2781 |
|
} catch (Exception e) { |
2782 |
|
result.Error(e); |
2783 |
|
} |
2784 |
|
return result.Produce(); |
2785 |
|
} |
2786 |
|
|
2787 |
|
String LSCPServer::CreateEffectInstance(int iEffectIndex) { |
2788 |
|
dmsg(2,("LSCPServer: CreateEffectInstance(%d)\n", iEffectIndex)); |
2789 |
|
LSCPResultSet result; |
2790 |
|
try { |
2791 |
|
EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(iEffectIndex); |
2792 |
|
if (!pEffectInfo) |
2793 |
|
throw Exception("There is no effect with index " + ToString(iEffectIndex)); |
2794 |
|
Effect* pEffect = EffectFactory::Create(pEffectInfo); |
2795 |
|
result = pEffect->ID(); // success |
2796 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount())); |
2797 |
|
} catch (Exception e) { |
2798 |
|
result.Error(e); |
2799 |
|
} |
2800 |
|
return result.Produce(); |
2801 |
|
} |
2802 |
|
|
2803 |
|
String LSCPServer::CreateEffectInstance(String effectSystem, String module, String effectName) { |
2804 |
|
dmsg(2,("LSCPServer: CreateEffectInstance('%s','%s','%s')\n", effectSystem.c_str(), module.c_str(), effectName.c_str())); |
2805 |
|
LSCPResultSet result; |
2806 |
|
try { |
2807 |
|
// to allow loading the same LSCP session file on different systems |
2808 |
|
// successfully, probably with different effect plugin DLL paths or even |
2809 |
|
// running completely different operating systems, we do the following |
2810 |
|
// for finding the right effect: |
2811 |
|
// |
2812 |
|
// first try to search for an exact match of the effect plugin DLL |
2813 |
|
// (a.k.a 'module'), to avoid picking the wrong DLL with the same |
2814 |
|
// effect name ... |
2815 |
|
EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_MATCH_EXACTLY); |
2816 |
|
// ... if no effect with exactly matchin DLL filename was found, then |
2817 |
|
// try to lower the restrictions of matching the effect plugin DLL |
2818 |
|
// filename and try again and again ... |
2819 |
|
if (!pEffectInfo) { |
2820 |
|
dmsg(2,("no exact module match, trying MODULE_IGNORE_PATH\n")); |
2821 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_PATH); |
2822 |
|
} |
2823 |
|
if (!pEffectInfo) { |
2824 |
|
dmsg(2,("no module match, trying MODULE_IGNORE_PATH | MODULE_IGNORE_CASE\n")); |
2825 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_PATH | EffectFactory::MODULE_IGNORE_CASE); |
2826 |
|
} |
2827 |
|
if (!pEffectInfo) { |
2828 |
|
dmsg(2,("no module match, trying MODULE_IGNORE_PATH | MODULE_IGNORE_CASE | MODULE_IGNORE_EXTENSION\n")); |
2829 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_PATH | EffectFactory::MODULE_IGNORE_CASE | EffectFactory::MODULE_IGNORE_EXTENSION); |
2830 |
|
} |
2831 |
|
// ... if there was still no effect found, then completely ignore the |
2832 |
|
// DLL plugin filename argument and just search for the matching effect |
2833 |
|
// system type and effect name |
2834 |
|
if (!pEffectInfo) { |
2835 |
|
dmsg(2,("no module match, trying MODULE_IGNORE_ALL\n")); |
2836 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_ALL); |
2837 |
|
} |
2838 |
|
if (!pEffectInfo) |
2839 |
|
throw Exception("There is no such effect '" + effectSystem + "' '" + module + "' '" + effectName + "'"); |
2840 |
|
|
2841 |
|
Effect* pEffect = EffectFactory::Create(pEffectInfo); |
2842 |
|
result = LSCPResultSet(pEffect->ID()); |
2843 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount())); |
2844 |
|
} catch (Exception e) { |
2845 |
|
result.Error(e); |
2846 |
|
} |
2847 |
|
return result.Produce(); |
2848 |
|
} |
2849 |
|
|
2850 |
|
String LSCPServer::DestroyEffectInstance(int iEffectInstance) { |
2851 |
|
dmsg(2,("LSCPServer: DestroyEffectInstance(%d)\n", iEffectInstance)); |
2852 |
|
LSCPResultSet result; |
2853 |
|
try { |
2854 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2855 |
|
if (!pEffect) |
2856 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2857 |
|
EffectFactory::Destroy(pEffect); |
2858 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount())); |
2859 |
|
} catch (Exception e) { |
2860 |
|
result.Error(e); |
2861 |
|
} |
2862 |
|
return result.Produce(); |
2863 |
|
} |
2864 |
|
|
2865 |
|
String LSCPServer::GetEffectInstances() { |
2866 |
|
dmsg(2,("LSCPServer: GetEffectInstances()\n")); |
2867 |
|
LSCPResultSet result; |
2868 |
|
try { |
2869 |
|
int n = EffectFactory::EffectInstancesCount(); |
2870 |
|
result.Add(n); |
2871 |
|
} catch (Exception e) { |
2872 |
|
result.Error(e); |
2873 |
|
} |
2874 |
|
return result.Produce(); |
2875 |
|
} |
2876 |
|
|
2877 |
|
String LSCPServer::ListEffectInstances() { |
2878 |
|
dmsg(2,("LSCPServer: ListEffectInstances()\n")); |
2879 |
|
LSCPResultSet result; |
2880 |
|
String list; |
2881 |
|
try { |
2882 |
|
int n = EffectFactory::EffectInstancesCount(); |
2883 |
|
for (int i = 0; i < n; i++) { |
2884 |
|
Effect* pEffect = EffectFactory::GetEffectInstance(i); |
2885 |
|
if (i) list += ","; |
2886 |
|
list += ToString(pEffect->ID()); |
2887 |
|
} |
2888 |
|
} catch (Exception e) { |
2889 |
|
result.Error(e); |
2890 |
|
} |
2891 |
|
result.Add(list); |
2892 |
|
return result.Produce(); |
2893 |
|
} |
2894 |
|
|
2895 |
|
String LSCPServer::GetSendEffectChains(int iAudioOutputDevice) { |
2896 |
|
dmsg(2,("LSCPServer: GetSendEffectChains(%d)\n", iAudioOutputDevice)); |
2897 |
|
LSCPResultSet result; |
2898 |
|
try { |
2899 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2900 |
|
if (!devices.count(iAudioOutputDevice)) |
2901 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2902 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2903 |
|
int n = pDevice->SendEffectChainCount(); |
2904 |
|
result.Add(n); |
2905 |
|
} catch (Exception e) { |
2906 |
|
result.Error(e); |
2907 |
|
} |
2908 |
|
return result.Produce(); |
2909 |
|
} |
2910 |
|
|
2911 |
|
String LSCPServer::ListSendEffectChains(int iAudioOutputDevice) { |
2912 |
|
dmsg(2,("LSCPServer: ListSendEffectChains(%d)\n", iAudioOutputDevice)); |
2913 |
|
LSCPResultSet result; |
2914 |
|
String list; |
2915 |
|
try { |
2916 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2917 |
|
if (!devices.count(iAudioOutputDevice)) |
2918 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2919 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2920 |
|
int n = pDevice->SendEffectChainCount(); |
2921 |
|
for (int i = 0; i < n; i++) { |
2922 |
|
EffectChain* pEffectChain = pDevice->SendEffectChain(i); |
2923 |
|
if (i) list += ","; |
2924 |
|
list += ToString(pEffectChain->ID()); |
2925 |
|
} |
2926 |
|
} catch (Exception e) { |
2927 |
|
result.Error(e); |
2928 |
|
} |
2929 |
|
result.Add(list); |
2930 |
|
return result.Produce(); |
2931 |
|
} |
2932 |
|
|
2933 |
|
String LSCPServer::AddSendEffectChain(int iAudioOutputDevice) { |
2934 |
|
dmsg(2,("LSCPServer: AddSendEffectChain(%d)\n", iAudioOutputDevice)); |
2935 |
|
LSCPResultSet result; |
2936 |
|
try { |
2937 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2938 |
|
if (!devices.count(iAudioOutputDevice)) |
2939 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2940 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2941 |
|
EffectChain* pEffectChain = pDevice->AddSendEffectChain(); |
2942 |
|
result = pEffectChain->ID(); |
2943 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_count, iAudioOutputDevice, pDevice->SendEffectChainCount())); |
2944 |
|
} catch (Exception e) { |
2945 |
|
result.Error(e); |
2946 |
|
} |
2947 |
|
return result.Produce(); |
2948 |
|
} |
2949 |
|
|
2950 |
|
String LSCPServer::RemoveSendEffectChain(int iAudioOutputDevice, int iSendEffectChain) { |
2951 |
|
dmsg(2,("LSCPServer: RemoveSendEffectChain(%d,%d)\n", iAudioOutputDevice, iSendEffectChain)); |
2952 |
|
LSCPResultSet result; |
2953 |
|
try { |
2954 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2955 |
|
if (!devices.count(iAudioOutputDevice)) |
2956 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2957 |
|
|
2958 |
|
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
2959 |
|
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
2960 |
|
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
2961 |
|
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
2962 |
|
AudioOutputDevice* pDev = (*itEngineChannel)->GetAudioOutputDevice(); |
2963 |
|
if (pDev != NULL && pDev->deviceId() == iAudioOutputDevice) { |
2964 |
|
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
2965 |
|
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
2966 |
|
if(fxs != NULL && fxs->DestinationEffectChain() == iSendEffectChain) { |
2967 |
|
throw Exception("The effect chain is still in use by channel " + ToString((*itEngineChannel)->GetSamplerChannel()->Index())); |
2968 |
|
} |
2969 |
|
} |
2970 |
|
} |
2971 |
|
} |
2972 |
|
|
2973 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2974 |
|
for (int i = 0; i < pDevice->SendEffectChainCount(); i++) { |
2975 |
|
EffectChain* pEffectChain = pDevice->SendEffectChain(i); |
2976 |
|
if (pEffectChain->ID() == iSendEffectChain) { |
2977 |
|
pDevice->RemoveSendEffectChain(i); |
2978 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_count, iAudioOutputDevice, pDevice->SendEffectChainCount())); |
2979 |
|
return result.Produce(); |
2980 |
|
} |
2981 |
|
} |
2982 |
|
throw Exception( |
2983 |
|
"There is no send effect chain with ID " + |
2984 |
|
ToString(iSendEffectChain) + " for audio output device " + |
2985 |
|
ToString(iAudioOutputDevice) + "." |
2986 |
|
); |
2987 |
|
} catch (Exception e) { |
2988 |
|
result.Error(e); |
2989 |
|
} |
2990 |
|
return result.Produce(); |
2991 |
|
} |
2992 |
|
|
2993 |
|
static EffectChain* _getSendEffectChain(Sampler* pSampler, int iAudioOutputDevice, int iSendEffectChain) throw (Exception) { |
2994 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2995 |
|
if (!devices.count(iAudioOutputDevice)) |
2996 |
|
throw Exception( |
2997 |
|
"There is no audio output device with index " + |
2998 |
|
ToString(iAudioOutputDevice) + "." |
2999 |
|
); |
3000 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
3001 |
|
EffectChain* pEffectChain = pDevice->SendEffectChainByID(iSendEffectChain); |
3002 |
|
if(pEffectChain != NULL) return pEffectChain; |
3003 |
|
throw Exception( |
3004 |
|
"There is no send effect chain with ID " + |
3005 |
|
ToString(iSendEffectChain) + " for audio output device " + |
3006 |
|
ToString(iAudioOutputDevice) + "." |
3007 |
|
); |
3008 |
|
} |
3009 |
|
|
3010 |
|
String LSCPServer::GetSendEffectChainInfo(int iAudioOutputDevice, int iSendEffectChain) { |
3011 |
|
dmsg(2,("LSCPServer: GetSendEffectChainInfo(%d,%d)\n", iAudioOutputDevice, iSendEffectChain)); |
3012 |
|
LSCPResultSet result; |
3013 |
|
try { |
3014 |
|
EffectChain* pEffectChain = |
3015 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
3016 |
|
String sEffectSequence; |
3017 |
|
for (int i = 0; i < pEffectChain->EffectCount(); i++) { |
3018 |
|
if (i) sEffectSequence += ","; |
3019 |
|
sEffectSequence += ToString(pEffectChain->GetEffect(i)->ID()); |
3020 |
|
} |
3021 |
|
result.Add("EFFECT_COUNT", pEffectChain->EffectCount()); |
3022 |
|
result.Add("EFFECT_SEQUENCE", sEffectSequence); |
3023 |
|
} catch (Exception e) { |
3024 |
|
result.Error(e); |
3025 |
|
} |
3026 |
|
return result.Produce(); |
3027 |
|
} |
3028 |
|
|
3029 |
|
String LSCPServer::AppendSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectInstance) { |
3030 |
|
dmsg(2,("LSCPServer: AppendSendEffectChainEffect(%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectInstance)); |
3031 |
|
LSCPResultSet result; |
3032 |
|
try { |
3033 |
|
EffectChain* pEffectChain = |
3034 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
3035 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
3036 |
|
if (!pEffect) |
3037 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
3038 |
|
pEffectChain->AppendEffect(pEffect); |
3039 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount())); |
3040 |
|
} catch (Exception e) { |
3041 |
|
result.Error(e); |
3042 |
|
} |
3043 |
|
return result.Produce(); |
3044 |
|
} |
3045 |
|
|
3046 |
|
String LSCPServer::InsertSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectChainPosition, int iEffectInstance) { |
3047 |
|
dmsg(2,("LSCPServer: InsertSendEffectChainEffect(%d,%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectChainPosition, iEffectInstance)); |
3048 |
|
LSCPResultSet result; |
3049 |
|
try { |
3050 |
|
EffectChain* pEffectChain = |
3051 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
3052 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
3053 |
|
if (!pEffect) |
3054 |
|
throw Exception("There is no effect instance with index " + ToString(iEffectInstance)); |
3055 |
|
pEffectChain->InsertEffect(pEffect, iEffectChainPosition); |
3056 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount())); |
3057 |
|
} catch (Exception e) { |
3058 |
|
result.Error(e); |
3059 |
|
} |
3060 |
|
return result.Produce(); |
3061 |
|
} |
3062 |
|
|
3063 |
|
String LSCPServer::RemoveSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectChainPosition) { |
3064 |
|
dmsg(2,("LSCPServer: RemoveSendEffectChainEffect(%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectChainPosition)); |
3065 |
|
LSCPResultSet result; |
3066 |
|
try { |
3067 |
|
EffectChain* pEffectChain = |
3068 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
3069 |
|
|
3070 |
|
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
3071 |
|
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
3072 |
|
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
3073 |
|
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
3074 |
|
AudioOutputDevice* pDev = (*itEngineChannel)->GetAudioOutputDevice(); |
3075 |
|
if (pDev != NULL && pDev->deviceId() == iAudioOutputDevice) { |
3076 |
|
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
3077 |
|
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
3078 |
|
if(fxs != NULL && fxs->DestinationEffectChain() == iSendEffectChain && fxs->DestinationEffectChainPosition() == iEffectChainPosition) { |
3079 |
|
throw Exception("The effect instance is still in use by channel " + ToString((*itEngineChannel)->GetSamplerChannel()->Index())); |
3080 |
|
} |
3081 |
|
} |
3082 |
|
} |
3083 |
|
} |
3084 |
|
|
3085 |
|
pEffectChain->RemoveEffect(iEffectChainPosition); |
3086 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount())); |
3087 |
|
} catch (Exception e) { |
3088 |
|
result.Error(e); |
3089 |
|
} |
3090 |
|
return result.Produce(); |
3091 |
|
} |
3092 |
|
|
3093 |
String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) { |
String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) { |
3094 |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
3095 |
LSCPResultSet result; |
LSCPResultSet result; |
3096 |
try { |
try { |
3097 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
3098 |
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
3099 |
Engine* pEngine = pEngineChannel->GetEngine(); |
Engine* pEngine = pEngineChannel->GetEngine(); |
3100 |
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
3109 |
return result.Produce(); |
return result.Produce(); |
3110 |
} |
} |
3111 |
|
|
3112 |
|
String LSCPServer::SendChannelMidiData(String MidiMsg, uint uiSamplerChannel, uint Arg1, uint Arg2) { |
3113 |
|
dmsg(2,("LSCPServer: SendChannelMidiData(MidiMsg=%s,uiSamplerChannel=%d,Arg1=%d,Arg2=%d)\n", MidiMsg.c_str(), uiSamplerChannel, Arg1, Arg2)); |
3114 |
|
LSCPResultSet result; |
3115 |
|
try { |
3116 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
3117 |
|
|
3118 |
|
if (Arg1 > 127 || Arg2 > 127) { |
3119 |
|
throw Exception("Invalid MIDI message"); |
3120 |
|
} |
3121 |
|
|
3122 |
|
VirtualMidiDevice* pMidiDevice = NULL; |
3123 |
|
std::vector<EventHandler::midi_listener_entry>::iterator iter = eventHandler.channelMidiListeners.begin(); |
3124 |
|
for (; iter != eventHandler.channelMidiListeners.end(); ++iter) { |
3125 |
|
if ((*iter).pEngineChannel == pEngineChannel) { |
3126 |
|
pMidiDevice = (*iter).pMidiListener; |
3127 |
|
break; |
3128 |
|
} |
3129 |
|
} |
3130 |
|
|
3131 |
|
if(pMidiDevice == NULL) throw Exception("Couldn't find virtual MIDI device"); |
3132 |
|
|
3133 |
|
if (MidiMsg == "NOTE_ON") { |
3134 |
|
pMidiDevice->SendNoteOnToDevice(Arg1, Arg2); |
3135 |
|
bool b = pMidiDevice->SendNoteOnToSampler(Arg1, Arg2); |
3136 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
3137 |
|
} else if (MidiMsg == "NOTE_OFF") { |
3138 |
|
pMidiDevice->SendNoteOffToDevice(Arg1, Arg2); |
3139 |
|
bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2); |
3140 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
3141 |
|
} else if (MidiMsg == "CC") { |
3142 |
|
pMidiDevice->SendCCToDevice(Arg1, Arg2); |
3143 |
|
bool b = pMidiDevice->SendCCToSampler(Arg1, Arg2); |
3144 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
3145 |
|
} else { |
3146 |
|
throw Exception("Unknown MIDI message type: " + MidiMsg); |
3147 |
|
} |
3148 |
|
} catch (Exception e) { |
3149 |
|
result.Error(e); |
3150 |
|
} |
3151 |
|
return result.Produce(); |
3152 |
|
} |
3153 |
|
|
3154 |
/** |
/** |
3155 |
* Will be called by the parser to reset a particular sampler channel. |
* Will be called by the parser to reset a particular sampler channel. |
3156 |
*/ |
*/ |
3158 |
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
3159 |
LSCPResultSet result; |
LSCPResultSet result; |
3160 |
try { |
try { |
3161 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
3162 |
pEngineChannel->Reset(); |
pEngineChannel->Reset(); |
3163 |
} |
} |
3164 |
catch (Exception e) { |
catch (Exception e) { |
3199 |
} |
} |
3200 |
|
|
3201 |
/** |
/** |
3202 |
|
* Will be called by the parser to return the current number of all active streams. |
3203 |
|
*/ |
3204 |
|
String LSCPServer::GetTotalStreamCount() { |
3205 |
|
dmsg(2,("LSCPServer: GetTotalStreamCount()\n")); |
3206 |
|
LSCPResultSet result; |
3207 |
|
result.Add(pSampler->GetDiskStreamCount()); |
3208 |
|
return result.Produce(); |
3209 |
|
} |
3210 |
|
|
3211 |
|
/** |
3212 |
* Will be called by the parser to return the current number of all active voices. |
* Will be called by the parser to return the current number of all active voices. |
3213 |
*/ |
*/ |
3214 |
String LSCPServer::GetTotalVoiceCount() { |
String LSCPServer::GetTotalVoiceCount() { |
3224 |
String LSCPServer::GetTotalVoiceCountMax() { |
String LSCPServer::GetTotalVoiceCountMax() { |
3225 |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
3226 |
LSCPResultSet result; |
LSCPResultSet result; |
3227 |
result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES); |
result.Add(EngineFactory::EngineInstances().size() * pSampler->GetGlobalMaxVoices()); |
3228 |
|
return result.Produce(); |
3229 |
|
} |
3230 |
|
|
3231 |
|
/** |
3232 |
|
* Will be called by the parser to return the sampler global maximum |
3233 |
|
* allowed number of voices. |
3234 |
|
*/ |
3235 |
|
String LSCPServer::GetGlobalMaxVoices() { |
3236 |
|
dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n")); |
3237 |
|
LSCPResultSet result; |
3238 |
|
result.Add(pSampler->GetGlobalMaxVoices()); |
3239 |
|
return result.Produce(); |
3240 |
|
} |
3241 |
|
|
3242 |
|
/** |
3243 |
|
* Will be called by the parser to set the sampler global maximum number of |
3244 |
|
* voices. |
3245 |
|
*/ |
3246 |
|
String LSCPServer::SetGlobalMaxVoices(int iVoices) { |
3247 |
|
dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices)); |
3248 |
|
LSCPResultSet result; |
3249 |
|
try { |
3250 |
|
pSampler->SetGlobalMaxVoices(iVoices); |
3251 |
|
LSCPServer::SendLSCPNotify( |
3252 |
|
LSCPEvent(LSCPEvent::event_global_info, "VOICES", pSampler->GetGlobalMaxVoices()) |
3253 |
|
); |
3254 |
|
} catch (Exception e) { |
3255 |
|
result.Error(e); |
3256 |
|
} |
3257 |
|
return result.Produce(); |
3258 |
|
} |
3259 |
|
|
3260 |
|
/** |
3261 |
|
* Will be called by the parser to return the sampler global maximum |
3262 |
|
* allowed number of disk streams. |
3263 |
|
*/ |
3264 |
|
String LSCPServer::GetGlobalMaxStreams() { |
3265 |
|
dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n")); |
3266 |
|
LSCPResultSet result; |
3267 |
|
result.Add(pSampler->GetGlobalMaxStreams()); |
3268 |
|
return result.Produce(); |
3269 |
|
} |
3270 |
|
|
3271 |
|
/** |
3272 |
|
* Will be called by the parser to set the sampler global maximum number of |
3273 |
|
* disk streams. |
3274 |
|
*/ |
3275 |
|
String LSCPServer::SetGlobalMaxStreams(int iStreams) { |
3276 |
|
dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams)); |
3277 |
|
LSCPResultSet result; |
3278 |
|
try { |
3279 |
|
pSampler->SetGlobalMaxStreams(iStreams); |
3280 |
|
LSCPServer::SendLSCPNotify( |
3281 |
|
LSCPEvent(LSCPEvent::event_global_info, "STREAMS", pSampler->GetGlobalMaxStreams()) |
3282 |
|
); |
3283 |
|
} catch (Exception e) { |
3284 |
|
result.Error(e); |
3285 |
|
} |
3286 |
return result.Produce(); |
return result.Produce(); |
3287 |
} |
} |
3288 |
|
|
3296 |
LSCPResultSet result; |
LSCPResultSet result; |
3297 |
try { |
try { |
3298 |
if (dVolume < 0) throw Exception("Volume may not be negative"); |
if (dVolume < 0) throw Exception("Volume may not be negative"); |
3299 |
GLOBAL_VOLUME = dVolume; // see common/global.cpp |
GLOBAL_VOLUME = dVolume; // see common/global_private.cpp |
3300 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME)); |
3301 |
} catch (Exception e) { |
} catch (Exception e) { |
3302 |
result.Error(e); |
result.Error(e); |
3395 |
id.Index = InstrumentID; |
id.Index = InstrumentID; |
3396 |
// try to find a sampler engine that can handle the file |
// try to find a sampler engine that can handle the file |
3397 |
bool bFound = false; |
bool bFound = false; |
3398 |
|
bool bFatalErr = false; |
3399 |
std::vector<String> engineTypes = EngineFactory::AvailableEngineTypes(); |
std::vector<String> engineTypes = EngineFactory::AvailableEngineTypes(); |
3400 |
for (int i = 0; !bFound && i < engineTypes.size(); i++) { |
for (int i = 0; !bFound && !bFatalErr && i < engineTypes.size(); i++) { |
3401 |
Engine* pEngine = NULL; |
Engine* pEngine = NULL; |
3402 |
try { |
try { |
3403 |
pEngine = EngineFactory::Create(engineTypes[i]); |
pEngine = EngineFactory::Create(engineTypes[i]); |
3404 |
if (!pEngine) throw Exception("Internal error: could not create '" + engineTypes[i] + "' engine"); |
if (!pEngine) throw Exception("Internal error: could not create '" + engineTypes[i] + "' engine"); |
3405 |
InstrumentManager* pManager = pEngine->GetInstrumentManager(); |
InstrumentManager* pManager = pEngine->GetInstrumentManager(); |
3406 |
if (pManager) { |
if (pManager) { |
3407 |
|
// check if the instrument index is valid |
3408 |
|
// FIXME: this won't work if an engine only supports parts of the instrument file |
3409 |
|
std::vector<InstrumentManager::instrument_id_t> IDs = |
3410 |
|
pManager->GetInstrumentFileContent(Filename); |
3411 |
|
if (std::find(IDs.begin(), IDs.end(), id) == IDs.end()) { |
3412 |
|
std::stringstream ss; |
3413 |
|
ss << "Invalid instrument index " << InstrumentID << " for instrument file '" << Filename << "'"; |
3414 |
|
bFatalErr = true; |
3415 |
|
throw Exception(ss.str()); |
3416 |
|
} |
3417 |
|
// get the info of the requested instrument |
3418 |
InstrumentManager::instrument_info_t info = |
InstrumentManager::instrument_info_t info = |
3419 |
pManager->GetInstrumentInfo(id); |
pManager->GetInstrumentInfo(id); |
3420 |
// return detailed informations about the file |
// return detailed informations about the file |
3423 |
result.Add("FORMAT_VERSION", info.FormatVersion); |
result.Add("FORMAT_VERSION", info.FormatVersion); |
3424 |
result.Add("PRODUCT", info.Product); |
result.Add("PRODUCT", info.Product); |
3425 |
result.Add("ARTISTS", info.Artists); |
result.Add("ARTISTS", info.Artists); |
3426 |
|
|
3427 |
|
std::stringstream ss; |
3428 |
|
bool b = false; |
3429 |
|
for (int i = 0; i < 128; i++) { |
3430 |
|
if (info.KeyBindings[i]) { |
3431 |
|
if (b) ss << ','; |
3432 |
|
ss << i; b = true; |
3433 |
|
} |
3434 |
|
} |
3435 |
|
result.Add("KEY_BINDINGS", ss.str()); |
3436 |
|
|
3437 |
|
b = false; |
3438 |
|
std::stringstream ss2; |
3439 |
|
for (int i = 0; i < 128; i++) { |
3440 |
|
if (info.KeySwitchBindings[i]) { |
3441 |
|
if (b) ss2 << ','; |
3442 |
|
ss2 << i; b = true; |
3443 |
|
} |
3444 |
|
} |
3445 |
|
result.Add("KEYSWITCH_BINDINGS", ss2.str()); |
3446 |
// no more need to ask other engine types |
// no more need to ask other engine types |
3447 |
bFound = true; |
bFound = true; |
3448 |
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
3449 |
} catch (Exception e) { |
} catch (Exception e) { |
3450 |
// NOOP, as exception is thrown if engine doesn't support file |
// usually NOOP, as exception is thrown if engine doesn't support file |
3451 |
|
if (bFatalErr) result.Error(e); |
3452 |
} |
} |
3453 |
if (pEngine) EngineFactory::Destroy(pEngine); |
if (pEngine) EngineFactory::Destroy(pEngine); |
3454 |
} |
} |
3455 |
|
|
3456 |
if (!bFound) result.Error("Unknown file format"); |
if (!bFound && !bFatalErr) result.Error("Unknown file format"); |
3457 |
return result.Produce(); |
return result.Produce(); |
3458 |
} |
} |
3459 |
|
|
3460 |
void LSCPServer::VerifyFile(String Filename) { |
void LSCPServer::VerifyFile(String Filename) { |
3461 |
struct stat statBuf; |
#if WIN32 |
3462 |
int res = stat(Filename.c_str(), &statBuf); |
WIN32_FIND_DATA win32FileAttributeData; |
3463 |
if (res) { |
BOOL res = GetFileAttributesEx( Filename.c_str(), GetFileExInfoStandard, &win32FileAttributeData ); |
3464 |
|
if (!res) { |
3465 |
std::stringstream ss; |
std::stringstream ss; |
3466 |
ss << "Fail to stat `" << Filename << "`: " << strerror(errno); |
ss << "File does not exist, GetFileAttributesEx failed `" << Filename << "`: Error " << GetLastError(); |
3467 |
throw Exception(ss.str()); |
throw Exception(ss.str()); |
3468 |
} |
} |
3469 |
|
if ( win32FileAttributeData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { |
|
if (S_ISDIR(statBuf.st_mode)) { |
|
3470 |
throw Exception("Directory is specified"); |
throw Exception("Directory is specified"); |
3471 |
} |
} |
3472 |
|
#else |
3473 |
|
File f(Filename); |
3474 |
|
if(!f.Exist()) throw Exception(f.GetErrorMsg()); |
3475 |
|
if (f.IsDirectory()) throw Exception("Directory is specified"); |
3476 |
|
#endif |
3477 |
} |
} |
3478 |
|
|
3479 |
/** |
/** |
3483 |
String LSCPServer::SubscribeNotification(LSCPEvent::event_t type) { |
String LSCPServer::SubscribeNotification(LSCPEvent::event_t type) { |
3484 |
dmsg(2,("LSCPServer: SubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
dmsg(2,("LSCPServer: SubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
3485 |
LSCPResultSet result; |
LSCPResultSet result; |
3486 |
SubscriptionMutex.Lock(); |
{ |
3487 |
eventSubscriptions[type].push_back(currentSocket); |
LockGuard lock(SubscriptionMutex); |
3488 |
SubscriptionMutex.Unlock(); |
eventSubscriptions[type].push_back(currentSocket); |
3489 |
|
} |
3490 |
return result.Produce(); |
return result.Produce(); |
3491 |
} |
} |
3492 |
|
|
3497 |
String LSCPServer::UnsubscribeNotification(LSCPEvent::event_t type) { |
String LSCPServer::UnsubscribeNotification(LSCPEvent::event_t type) { |
3498 |
dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
3499 |
LSCPResultSet result; |
LSCPResultSet result; |
3500 |
SubscriptionMutex.Lock(); |
{ |
3501 |
eventSubscriptions[type].remove(currentSocket); |
LockGuard lock(SubscriptionMutex); |
3502 |
SubscriptionMutex.Unlock(); |
eventSubscriptions[type].remove(currentSocket); |
3503 |
|
} |
3504 |
return result.Produce(); |
return result.Produce(); |
3505 |
} |
} |
3506 |
|
|
3669 |
return result.Produce(); |
return result.Produce(); |
3670 |
} |
} |
3671 |
|
|
3672 |
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) { |
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground, bool insDir) { |
3673 |
dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground)); |
dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d,insDir=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground, insDir)); |
3674 |
LSCPResultSet result; |
LSCPResultSet result; |
3675 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
3676 |
try { |
try { |
3677 |
int id; |
int id; |
3678 |
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
3679 |
if (ScanMode.compare("RECURSIVE") == 0) { |
if (ScanMode.compare("RECURSIVE") == 0) { |
3680 |
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground); |
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground, insDir); |
3681 |
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
3682 |
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground); |
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground, insDir); |
3683 |
} else if (ScanMode.compare("FLAT") == 0) { |
} else if (ScanMode.compare("FLAT") == 0) { |
3684 |
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground); |
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground, insDir); |
3685 |
} else { |
} else { |
3686 |
throw Exception("Unknown scan mode: " + ScanMode); |
throw Exception("Unknown scan mode: " + ScanMode); |
3687 |
} |
} |
3857 |
return result.Produce(); |
return result.Produce(); |
3858 |
} |
} |
3859 |
|
|
3860 |
|
String LSCPServer::SetDbInstrumentFilePath(String OldPath, String NewPath) { |
3861 |
|
dmsg(2,("LSCPServer: SetDbInstrumentFilePath(OldPath=%s,NewPath=%s)\n", OldPath.c_str(), NewPath.c_str())); |
3862 |
|
LSCPResultSet result; |
3863 |
|
#if HAVE_SQLITE3 |
3864 |
|
try { |
3865 |
|
InstrumentsDb::GetInstrumentsDb()->SetInstrumentFilePath(OldPath, NewPath); |
3866 |
|
} catch (Exception e) { |
3867 |
|
result.Error(e); |
3868 |
|
} |
3869 |
|
#else |
3870 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3871 |
|
#endif |
3872 |
|
return result.Produce(); |
3873 |
|
} |
3874 |
|
|
3875 |
|
String LSCPServer::FindLostDbInstrumentFiles() { |
3876 |
|
dmsg(2,("LSCPServer: FindLostDbInstrumentFiles()\n")); |
3877 |
|
LSCPResultSet result; |
3878 |
|
#if HAVE_SQLITE3 |
3879 |
|
try { |
3880 |
|
String list; |
3881 |
|
StringListPtr pLostFiles = InstrumentsDb::GetInstrumentsDb()->FindLostInstrumentFiles(); |
3882 |
|
|
3883 |
|
for (int i = 0; i < pLostFiles->size(); i++) { |
3884 |
|
if (list != "") list += ","; |
3885 |
|
list += "'" + pLostFiles->at(i) + "'"; |
3886 |
|
} |
3887 |
|
|
3888 |
|
result.Add(list); |
3889 |
|
} catch (Exception e) { |
3890 |
|
result.Error(e); |
3891 |
|
} |
3892 |
|
#else |
3893 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3894 |
|
#endif |
3895 |
|
return result.Produce(); |
3896 |
|
} |
3897 |
|
|
3898 |
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
3899 |
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
3900 |
LSCPResultSet result; |
LSCPResultSet result; |
4025 |
} |
} |
4026 |
return result.Produce(); |
return result.Produce(); |
4027 |
} |
} |
4028 |
|
|
4029 |
|
String LSCPServer::SetShellInteract(yyparse_param_t* pSession, double boolean_value) { |
4030 |
|
dmsg(2,("LSCPServer: SetShellInteract(val=%f)\n", boolean_value)); |
4031 |
|
LSCPResultSet result; |
4032 |
|
try { |
4033 |
|
if (boolean_value == 0) pSession->bShellInteract = false; |
4034 |
|
else if (boolean_value == 1) pSession->bShellInteract = true; |
4035 |
|
else throw Exception("Not a boolean value, must either be 0 or 1"); |
4036 |
|
} catch (Exception e) { |
4037 |
|
result.Error(e); |
4038 |
|
} |
4039 |
|
return result.Produce(); |
4040 |
|
} |
4041 |
|
|
4042 |
|
String LSCPServer::SetShellAutoCorrect(yyparse_param_t* pSession, double boolean_value) { |
4043 |
|
dmsg(2,("LSCPServer: SetShellAutoCorrect(val=%f)\n", boolean_value)); |
4044 |
|
LSCPResultSet result; |
4045 |
|
try { |
4046 |
|
if (boolean_value == 0) pSession->bShellAutoCorrect = false; |
4047 |
|
else if (boolean_value == 1) pSession->bShellAutoCorrect = true; |
4048 |
|
else throw Exception("Not a boolean value, must either be 0 or 1"); |
4049 |
|
} catch (Exception e) { |
4050 |
|
result.Error(e); |
4051 |
|
} |
4052 |
|
return result.Produce(); |
4053 |
|
} |
4054 |
|
|
4055 |
|
} |