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 - 2008 Christian Schoenebeck * |
* Copyright (C) 2005 - 2010 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This library is free software; you can redistribute it and/or modify * |
* This library is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
24 |
#include <algorithm> |
#include <algorithm> |
25 |
#include <string> |
#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" |
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 { |
namespace LinuxSampler { |
49 |
|
|
138 |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
139 |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_midi, "CHANNEL_MIDI"); |
140 |
LSCPEvent::RegisterEvent(LSCPEvent::event_device_midi, "DEVICE_MIDI"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_device_midi, "DEVICE_MIDI"); |
141 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_fx_instance_count, "EFFECT_INSTANCE_COUNT"); |
142 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_fx_instance_info, "EFFECT_INSTANCE_INFO"); |
143 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_send_fx_chain_count, "SEND_EFFECT_CHAIN_COUNT"); |
144 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_send_fx_chain_info, "SEND_EFFECT_CHAIN_INFO"); |
145 |
hSocket = -1; |
hSocket = -1; |
146 |
} |
} |
147 |
|
|
148 |
LSCPServer::~LSCPServer() { |
LSCPServer::~LSCPServer() { |
149 |
|
CloseAllConnections(); |
150 |
|
InstrumentManager::StopBackgroundThread(); |
151 |
#if defined(WIN32) |
#if defined(WIN32) |
152 |
if (hSocket >= 0) closesocket(hSocket); |
if (hSocket >= 0) closesocket(hSocket); |
153 |
#else |
#else |
342 |
} |
} |
343 |
#endif // HAVE_SQLITE3 |
#endif // HAVE_SQLITE3 |
344 |
|
|
345 |
|
void LSCPServer::RemoveListeners() { |
346 |
|
pSampler->RemoveChannelCountListener(&eventHandler); |
347 |
|
pSampler->RemoveAudioDeviceCountListener(&eventHandler); |
348 |
|
pSampler->RemoveMidiDeviceCountListener(&eventHandler); |
349 |
|
pSampler->RemoveVoiceCountListener(&eventHandler); |
350 |
|
pSampler->RemoveStreamCountListener(&eventHandler); |
351 |
|
pSampler->RemoveBufferFillListener(&eventHandler); |
352 |
|
pSampler->RemoveTotalStreamCountListener(&eventHandler); |
353 |
|
pSampler->RemoveTotalVoiceCountListener(&eventHandler); |
354 |
|
pSampler->RemoveFxSendCountListener(&eventHandler); |
355 |
|
MidiInstrumentMapper::RemoveMidiInstrumentCountListener(&eventHandler); |
356 |
|
MidiInstrumentMapper::RemoveMidiInstrumentInfoListener(&eventHandler); |
357 |
|
MidiInstrumentMapper::RemoveMidiInstrumentMapCountListener(&eventHandler); |
358 |
|
MidiInstrumentMapper::RemoveMidiInstrumentMapInfoListener(&eventHandler); |
359 |
|
#if HAVE_SQLITE3 |
360 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveInstrumentsDbListener(&dbInstrumentsEventHandler); |
361 |
|
#endif |
362 |
|
} |
363 |
|
|
364 |
/** |
/** |
365 |
* Blocks the calling thread until the LSCP Server is initialized and |
* Blocks the calling thread until the LSCP Server is initialized and |
560 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
561 |
} |
} |
562 |
#else |
#else |
563 |
|
struct linger linger; |
564 |
|
linger.l_onoff = 1; |
565 |
|
linger.l_linger = 0; |
566 |
|
if(setsockopt(socket, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger))) { |
567 |
|
std::cerr << "LSCPServer: Failed to set SO_LINGER\n"; |
568 |
|
} |
569 |
|
|
570 |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
571 |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
572 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
638 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
639 |
} |
} |
640 |
|
|
641 |
|
void LSCPServer::CloseAllConnections() { |
642 |
|
std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); |
643 |
|
while(iter != Sessions.end()) { |
644 |
|
CloseConnection(iter); |
645 |
|
iter = Sessions.begin(); |
646 |
|
} |
647 |
|
} |
648 |
|
|
649 |
void LSCPServer::LockRTNotify() { |
void LSCPServer::LockRTNotify() { |
650 |
RTNotifyMutex.Lock(); |
RTNotifyMutex.Lock(); |
651 |
} |
} |
1300 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1301 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1302 |
s += iter->first; |
s += iter->first; |
1303 |
|
delete iter->second; |
1304 |
} |
} |
1305 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1306 |
} |
} |
1325 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1326 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1327 |
s += iter->first; |
s += iter->first; |
1328 |
|
delete iter->second; |
1329 |
} |
} |
1330 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1331 |
} |
} |
1356 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1357 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1358 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1359 |
|
delete pParameter; |
1360 |
} |
} |
1361 |
catch (Exception e) { |
catch (Exception e) { |
1362 |
result.Error(e); |
result.Error(e); |
1384 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1385 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1386 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1387 |
|
delete pParameter; |
1388 |
} |
} |
1389 |
catch (Exception e) { |
catch (Exception e) { |
1390 |
result.Error(e); |
result.Error(e); |
1851 |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
1852 |
// Make it with at least one initial port. |
// Make it with at least one initial port. |
1853 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
|
parameters["PORTS"]->SetValue("1"); |
|
1854 |
} |
} |
1855 |
// Must have a device... |
// Must have a device... |
1856 |
if (pDevice == NULL) |
if (pDevice == NULL) |
2387 |
AudioRouting += ToString(pFxSend->DestinationChannel(chan)); |
AudioRouting += ToString(pFxSend->DestinationChannel(chan)); |
2388 |
} |
} |
2389 |
|
|
2390 |
|
const String sEffectRouting = |
2391 |
|
(pFxSend->DestinationEffectChain() >= 0 && pFxSend->DestinationEffectChainPosition() >= 0) |
2392 |
|
? ToString(pFxSend->DestinationEffectChain()) + "," + ToString(pFxSend->DestinationEffectChainPosition()) |
2393 |
|
: "NONE"; |
2394 |
|
|
2395 |
// success |
// success |
2396 |
result.Add("NAME", _escapeLscpResponse(pFxSend->Name())); |
result.Add("NAME", _escapeLscpResponse(pFxSend->Name())); |
2397 |
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
2398 |
result.Add("LEVEL", ToString(pFxSend->Level())); |
result.Add("LEVEL", ToString(pFxSend->Level())); |
2399 |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
2400 |
|
result.Add("EFFECT", sEffectRouting); |
2401 |
} catch (Exception e) { |
} catch (Exception e) { |
2402 |
result.Error(e); |
result.Error(e); |
2403 |
} |
} |
2460 |
return result.Produce(); |
return result.Produce(); |
2461 |
} |
} |
2462 |
|
|
2463 |
|
String LSCPServer::SetFxSendEffect(uint uiSamplerChannel, uint FxSendID, int iSendEffectChain, int iEffectChainPosition) { |
2464 |
|
dmsg(2,("LSCPServer: SetFxSendEffect(%d,%d)\n", iSendEffectChain, iEffectChainPosition)); |
2465 |
|
LSCPResultSet result; |
2466 |
|
try { |
2467 |
|
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2468 |
|
|
2469 |
|
pFxSend->SetDestinationEffect(iSendEffectChain, iEffectChainPosition); |
2470 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2471 |
|
} catch (Exception e) { |
2472 |
|
result.Error(e); |
2473 |
|
} |
2474 |
|
return result.Produce(); |
2475 |
|
} |
2476 |
|
|
2477 |
|
String LSCPServer::GetAvailableEffects() { |
2478 |
|
dmsg(2,("LSCPServer: GetAvailableEffects()\n")); |
2479 |
|
LSCPResultSet result; |
2480 |
|
try { |
2481 |
|
int n = EffectFactory::AvailableEffectsCount(); |
2482 |
|
result.Add(n); |
2483 |
|
} |
2484 |
|
catch (Exception e) { |
2485 |
|
result.Error(e); |
2486 |
|
} |
2487 |
|
return result.Produce(); |
2488 |
|
} |
2489 |
|
|
2490 |
|
String LSCPServer::ListAvailableEffects() { |
2491 |
|
dmsg(2,("LSCPServer: ListAvailableEffects()\n")); |
2492 |
|
LSCPResultSet result; |
2493 |
|
String list; |
2494 |
|
try { |
2495 |
|
//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 |
2496 |
|
int n = EffectFactory::AvailableEffectsCount(); |
2497 |
|
for (int i = 0; i < n; i++) { |
2498 |
|
if (i) list += ","; |
2499 |
|
list += ToString(i); |
2500 |
|
} |
2501 |
|
} |
2502 |
|
catch (Exception e) { |
2503 |
|
result.Error(e); |
2504 |
|
} |
2505 |
|
result.Add(list); |
2506 |
|
return result.Produce(); |
2507 |
|
} |
2508 |
|
|
2509 |
|
String LSCPServer::GetEffectInfo(int iEffectIndex) { |
2510 |
|
dmsg(2,("LSCPServer: GetEffectInfo(%d)\n", iEffectIndex)); |
2511 |
|
LSCPResultSet result; |
2512 |
|
try { |
2513 |
|
EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(iEffectIndex); |
2514 |
|
if (!pEffectInfo) |
2515 |
|
throw Exception("There is no effect with index " + ToString(iEffectIndex)); |
2516 |
|
|
2517 |
|
// convert the filename into the correct encoding as defined for LSCP |
2518 |
|
// (especially in terms of special characters -> escape sequences) |
2519 |
|
#if WIN32 |
2520 |
|
const String dllFileName = Path::fromWindows(pEffectInfo->Module()).toLscp(); |
2521 |
|
#else |
2522 |
|
// assuming POSIX |
2523 |
|
const String dllFileName = Path::fromPosix(pEffectInfo->Module()).toLscp(); |
2524 |
|
#endif |
2525 |
|
|
2526 |
|
result.Add("SYSTEM", pEffectInfo->EffectSystem()); |
2527 |
|
result.Add("MODULE", dllFileName); |
2528 |
|
result.Add("NAME", _escapeLscpResponse(pEffectInfo->Name())); |
2529 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(pEffectInfo->Description())); |
2530 |
|
} |
2531 |
|
catch (Exception e) { |
2532 |
|
result.Error(e); |
2533 |
|
} |
2534 |
|
return result.Produce(); |
2535 |
|
} |
2536 |
|
|
2537 |
|
String LSCPServer::GetEffectInstanceInfo(int iEffectInstance) { |
2538 |
|
dmsg(2,("LSCPServer: GetEffectInstanceInfo(%d)\n", iEffectInstance)); |
2539 |
|
LSCPResultSet result; |
2540 |
|
try { |
2541 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2542 |
|
if (!pEffect) |
2543 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2544 |
|
|
2545 |
|
EffectInfo* pEffectInfo = pEffect->GetEffectInfo(); |
2546 |
|
|
2547 |
|
// convert the filename into the correct encoding as defined for LSCP |
2548 |
|
// (especially in terms of special characters -> escape sequences) |
2549 |
|
#if WIN32 |
2550 |
|
const String dllFileName = Path::fromWindows(pEffectInfo->Module()).toLscp(); |
2551 |
|
#else |
2552 |
|
// assuming POSIX |
2553 |
|
const String dllFileName = Path::fromPosix(pEffectInfo->Module()).toLscp(); |
2554 |
|
#endif |
2555 |
|
|
2556 |
|
result.Add("SYSTEM", pEffectInfo->EffectSystem()); |
2557 |
|
result.Add("MODULE", dllFileName); |
2558 |
|
result.Add("NAME", _escapeLscpResponse(pEffectInfo->Name())); |
2559 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(pEffectInfo->Description())); |
2560 |
|
result.Add("INPUT_CONTROLS", ToString(pEffect->InputControlCount())); |
2561 |
|
} |
2562 |
|
catch (Exception e) { |
2563 |
|
result.Error(e); |
2564 |
|
} |
2565 |
|
return result.Produce(); |
2566 |
|
} |
2567 |
|
|
2568 |
|
String LSCPServer::GetEffectInstanceInputControlInfo(int iEffectInstance, int iInputControlIndex) { |
2569 |
|
dmsg(2,("LSCPServer: GetEffectInstanceInputControlInfo(%d,%d)\n", iEffectInstance, iInputControlIndex)); |
2570 |
|
LSCPResultSet result; |
2571 |
|
try { |
2572 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2573 |
|
if (!pEffect) |
2574 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2575 |
|
|
2576 |
|
EffectControl* pEffectControl = pEffect->InputControl(iInputControlIndex); |
2577 |
|
if (!pEffectControl) |
2578 |
|
throw Exception( |
2579 |
|
"Effect instance " + ToString(iEffectInstance) + |
2580 |
|
" does not have an input control with index " + |
2581 |
|
ToString(iInputControlIndex) |
2582 |
|
); |
2583 |
|
|
2584 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(pEffectControl->Description())); |
2585 |
|
result.Add("VALUE", pEffectControl->Value()); |
2586 |
|
if (pEffectControl->MinValue()) |
2587 |
|
result.Add("RANGE_MIN", *pEffectControl->MinValue()); |
2588 |
|
if (pEffectControl->MaxValue()) |
2589 |
|
result.Add("RANGE_MAX", *pEffectControl->MaxValue()); |
2590 |
|
if (!pEffectControl->Possibilities().empty()) |
2591 |
|
result.Add("POSSIBILITIES", pEffectControl->Possibilities()); |
2592 |
|
if (pEffectControl->DefaultValue()) |
2593 |
|
result.Add("DEFAULT", *pEffectControl->DefaultValue()); |
2594 |
|
} catch (Exception e) { |
2595 |
|
result.Error(e); |
2596 |
|
} |
2597 |
|
return result.Produce(); |
2598 |
|
} |
2599 |
|
|
2600 |
|
String LSCPServer::SetEffectInstanceInputControlValue(int iEffectInstance, int iInputControlIndex, double dValue) { |
2601 |
|
dmsg(2,("LSCPServer: SetEffectInstanceInputControlValue(%d,%d,%f)\n", iEffectInstance, iInputControlIndex, dValue)); |
2602 |
|
LSCPResultSet result; |
2603 |
|
try { |
2604 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2605 |
|
if (!pEffect) |
2606 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2607 |
|
|
2608 |
|
EffectControl* pEffectControl = pEffect->InputControl(iInputControlIndex); |
2609 |
|
if (!pEffectControl) |
2610 |
|
throw Exception( |
2611 |
|
"Effect instance " + ToString(iEffectInstance) + |
2612 |
|
" does not have an input control with index " + |
2613 |
|
ToString(iInputControlIndex) |
2614 |
|
); |
2615 |
|
|
2616 |
|
pEffectControl->SetValue(dValue); |
2617 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_info, iEffectInstance)); |
2618 |
|
} catch (Exception e) { |
2619 |
|
result.Error(e); |
2620 |
|
} |
2621 |
|
return result.Produce(); |
2622 |
|
} |
2623 |
|
|
2624 |
|
String LSCPServer::CreateEffectInstance(int iEffectIndex) { |
2625 |
|
dmsg(2,("LSCPServer: CreateEffectInstance(%d)\n", iEffectIndex)); |
2626 |
|
LSCPResultSet result; |
2627 |
|
try { |
2628 |
|
EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(iEffectIndex); |
2629 |
|
if (!pEffectInfo) |
2630 |
|
throw Exception("There is no effect with index " + ToString(iEffectIndex)); |
2631 |
|
Effect* pEffect = EffectFactory::Create(pEffectInfo); |
2632 |
|
result = pEffect->ID(); // success |
2633 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount())); |
2634 |
|
} catch (Exception e) { |
2635 |
|
result.Error(e); |
2636 |
|
} |
2637 |
|
return result.Produce(); |
2638 |
|
} |
2639 |
|
|
2640 |
|
String LSCPServer::CreateEffectInstance(String effectSystem, String module, String effectName) { |
2641 |
|
dmsg(2,("LSCPServer: CreateEffectInstance('%s','%s','%s')\n", effectSystem.c_str(), module.c_str(), effectName.c_str())); |
2642 |
|
LSCPResultSet result; |
2643 |
|
try { |
2644 |
|
// to allow loading the same LSCP session file on different systems |
2645 |
|
// successfully, probably with different effect plugin DLL paths or even |
2646 |
|
// running completely different operating systems, we do the following |
2647 |
|
// for finding the right effect: |
2648 |
|
// |
2649 |
|
// first try to search for an exact match of the effect plugin DLL |
2650 |
|
// (a.k.a 'module'), to avoid picking the wrong DLL with the same |
2651 |
|
// effect name ... |
2652 |
|
EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_MATCH_EXACTLY); |
2653 |
|
// ... if no effect with exactly matchin DLL filename was found, then |
2654 |
|
// try to lower the restrictions of matching the effect plugin DLL |
2655 |
|
// filename and try again and again ... |
2656 |
|
if (!pEffectInfo) { |
2657 |
|
dmsg(2,("no exact module match, trying MODULE_IGNORE_PATH\n")); |
2658 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_PATH); |
2659 |
|
} |
2660 |
|
if (!pEffectInfo) { |
2661 |
|
dmsg(2,("no module match, trying MODULE_IGNORE_PATH | MODULE_IGNORE_CASE\n")); |
2662 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_PATH | EffectFactory::MODULE_IGNORE_CASE); |
2663 |
|
} |
2664 |
|
if (!pEffectInfo) { |
2665 |
|
dmsg(2,("no module match, trying MODULE_IGNORE_PATH | MODULE_IGNORE_CASE | MODULE_IGNORE_EXTENSION\n")); |
2666 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_PATH | EffectFactory::MODULE_IGNORE_CASE | EffectFactory::MODULE_IGNORE_EXTENSION); |
2667 |
|
} |
2668 |
|
// ... if there was still no effect found, then completely ignore the |
2669 |
|
// DLL plugin filename argument and just search for the matching effect |
2670 |
|
// system type and effect name |
2671 |
|
if (!pEffectInfo) { |
2672 |
|
dmsg(2,("no module match, trying MODULE_IGNORE_ALL\n")); |
2673 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_ALL); |
2674 |
|
} |
2675 |
|
if (!pEffectInfo) |
2676 |
|
throw Exception("There is no such effect '" + effectSystem + "' '" + module + "' '" + effectName + "'"); |
2677 |
|
|
2678 |
|
Effect* pEffect = EffectFactory::Create(pEffectInfo); |
2679 |
|
result = LSCPResultSet(pEffect->ID()); |
2680 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount())); |
2681 |
|
} catch (Exception e) { |
2682 |
|
result.Error(e); |
2683 |
|
} |
2684 |
|
return result.Produce(); |
2685 |
|
} |
2686 |
|
|
2687 |
|
String LSCPServer::DestroyEffectInstance(int iEffectInstance) { |
2688 |
|
dmsg(2,("LSCPServer: DestroyEffectInstance(%d)\n", iEffectInstance)); |
2689 |
|
LSCPResultSet result; |
2690 |
|
try { |
2691 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2692 |
|
if (!pEffect) |
2693 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2694 |
|
EffectFactory::Destroy(pEffect); |
2695 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount())); |
2696 |
|
} catch (Exception e) { |
2697 |
|
result.Error(e); |
2698 |
|
} |
2699 |
|
return result.Produce(); |
2700 |
|
} |
2701 |
|
|
2702 |
|
String LSCPServer::GetEffectInstances() { |
2703 |
|
dmsg(2,("LSCPServer: GetEffectInstances()\n")); |
2704 |
|
LSCPResultSet result; |
2705 |
|
try { |
2706 |
|
int n = EffectFactory::EffectInstancesCount(); |
2707 |
|
result.Add(n); |
2708 |
|
} catch (Exception e) { |
2709 |
|
result.Error(e); |
2710 |
|
} |
2711 |
|
return result.Produce(); |
2712 |
|
} |
2713 |
|
|
2714 |
|
String LSCPServer::ListEffectInstances() { |
2715 |
|
dmsg(2,("LSCPServer: ListEffectInstances()\n")); |
2716 |
|
LSCPResultSet result; |
2717 |
|
String list; |
2718 |
|
try { |
2719 |
|
int n = EffectFactory::EffectInstancesCount(); |
2720 |
|
for (int i = 0; i < n; i++) { |
2721 |
|
Effect* pEffect = EffectFactory::GetEffectInstance(i); |
2722 |
|
if (i) list += ","; |
2723 |
|
list += ToString(pEffect->ID()); |
2724 |
|
} |
2725 |
|
} catch (Exception e) { |
2726 |
|
result.Error(e); |
2727 |
|
} |
2728 |
|
result.Add(list); |
2729 |
|
return result.Produce(); |
2730 |
|
} |
2731 |
|
|
2732 |
|
String LSCPServer::GetSendEffectChains(int iAudioOutputDevice) { |
2733 |
|
dmsg(2,("LSCPServer: GetSendEffectChains(%d)\n", iAudioOutputDevice)); |
2734 |
|
LSCPResultSet result; |
2735 |
|
try { |
2736 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2737 |
|
if (!devices.count(iAudioOutputDevice)) |
2738 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2739 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2740 |
|
int n = pDevice->SendEffectChainCount(); |
2741 |
|
result.Add(n); |
2742 |
|
} catch (Exception e) { |
2743 |
|
result.Error(e); |
2744 |
|
} |
2745 |
|
return result.Produce(); |
2746 |
|
} |
2747 |
|
|
2748 |
|
String LSCPServer::ListSendEffectChains(int iAudioOutputDevice) { |
2749 |
|
dmsg(2,("LSCPServer: ListSendEffectChains(%d)\n", iAudioOutputDevice)); |
2750 |
|
LSCPResultSet result; |
2751 |
|
String list; |
2752 |
|
try { |
2753 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2754 |
|
if (!devices.count(iAudioOutputDevice)) |
2755 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2756 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2757 |
|
int n = pDevice->SendEffectChainCount(); |
2758 |
|
for (int i = 0; i < n; i++) { |
2759 |
|
EffectChain* pEffectChain = pDevice->SendEffectChain(i); |
2760 |
|
if (i) list += ","; |
2761 |
|
list += ToString(pEffectChain->ID()); |
2762 |
|
} |
2763 |
|
} catch (Exception e) { |
2764 |
|
result.Error(e); |
2765 |
|
} |
2766 |
|
result.Add(list); |
2767 |
|
return result.Produce(); |
2768 |
|
} |
2769 |
|
|
2770 |
|
String LSCPServer::AddSendEffectChain(int iAudioOutputDevice) { |
2771 |
|
dmsg(2,("LSCPServer: AddSendEffectChain(%d)\n", iAudioOutputDevice)); |
2772 |
|
LSCPResultSet result; |
2773 |
|
try { |
2774 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2775 |
|
if (!devices.count(iAudioOutputDevice)) |
2776 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2777 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2778 |
|
EffectChain* pEffectChain = pDevice->AddSendEffectChain(); |
2779 |
|
result = pEffectChain->ID(); |
2780 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_count, iAudioOutputDevice, pDevice->SendEffectChainCount())); |
2781 |
|
} catch (Exception e) { |
2782 |
|
result.Error(e); |
2783 |
|
} |
2784 |
|
return result.Produce(); |
2785 |
|
} |
2786 |
|
|
2787 |
|
String LSCPServer::RemoveSendEffectChain(int iAudioOutputDevice, int iSendEffectChain) { |
2788 |
|
dmsg(2,("LSCPServer: RemoveSendEffectChain(%d,%d)\n", iAudioOutputDevice, iSendEffectChain)); |
2789 |
|
LSCPResultSet result; |
2790 |
|
try { |
2791 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2792 |
|
if (!devices.count(iAudioOutputDevice)) |
2793 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2794 |
|
|
2795 |
|
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
2796 |
|
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
2797 |
|
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
2798 |
|
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
2799 |
|
AudioOutputDevice* pDev = (*itEngineChannel)->GetAudioOutputDevice(); |
2800 |
|
if (pDev != NULL && pDev->deviceId() == iAudioOutputDevice) { |
2801 |
|
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
2802 |
|
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
2803 |
|
if(fxs != NULL && fxs->DestinationEffectChain() == iSendEffectChain) { |
2804 |
|
throw Exception("The effect chain is still in use by channel " + ToString((*itEngineChannel)->GetSamplerChannel()->Index())); |
2805 |
|
} |
2806 |
|
} |
2807 |
|
} |
2808 |
|
} |
2809 |
|
|
2810 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2811 |
|
for (int i = 0; i < pDevice->SendEffectChainCount(); i++) { |
2812 |
|
EffectChain* pEffectChain = pDevice->SendEffectChain(i); |
2813 |
|
if (pEffectChain->ID() == iSendEffectChain) { |
2814 |
|
pDevice->RemoveSendEffectChain(i); |
2815 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_count, iAudioOutputDevice, pDevice->SendEffectChainCount())); |
2816 |
|
return result.Produce(); |
2817 |
|
} |
2818 |
|
} |
2819 |
|
throw Exception( |
2820 |
|
"There is no send effect chain with ID " + |
2821 |
|
ToString(iSendEffectChain) + " for audio output device " + |
2822 |
|
ToString(iAudioOutputDevice) + "." |
2823 |
|
); |
2824 |
|
} catch (Exception e) { |
2825 |
|
result.Error(e); |
2826 |
|
} |
2827 |
|
return result.Produce(); |
2828 |
|
} |
2829 |
|
|
2830 |
|
static EffectChain* _getSendEffectChain(Sampler* pSampler, int iAudioOutputDevice, int iSendEffectChain) throw (Exception) { |
2831 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2832 |
|
if (!devices.count(iAudioOutputDevice)) |
2833 |
|
throw Exception( |
2834 |
|
"There is no audio output device with index " + |
2835 |
|
ToString(iAudioOutputDevice) + "." |
2836 |
|
); |
2837 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2838 |
|
EffectChain* pEffectChain = pDevice->SendEffectChainByID(iSendEffectChain); |
2839 |
|
if(pEffectChain != NULL) return pEffectChain; |
2840 |
|
throw Exception( |
2841 |
|
"There is no send effect chain with ID " + |
2842 |
|
ToString(iSendEffectChain) + " for audio output device " + |
2843 |
|
ToString(iAudioOutputDevice) + "." |
2844 |
|
); |
2845 |
|
} |
2846 |
|
|
2847 |
|
String LSCPServer::GetSendEffectChainInfo(int iAudioOutputDevice, int iSendEffectChain) { |
2848 |
|
dmsg(2,("LSCPServer: GetSendEffectChainInfo(%d,%d)\n", iAudioOutputDevice, iSendEffectChain)); |
2849 |
|
LSCPResultSet result; |
2850 |
|
try { |
2851 |
|
EffectChain* pEffectChain = |
2852 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
2853 |
|
String sEffectSequence; |
2854 |
|
for (int i = 0; i < pEffectChain->EffectCount(); i++) { |
2855 |
|
if (i) sEffectSequence += ","; |
2856 |
|
sEffectSequence += ToString(pEffectChain->GetEffect(i)->ID()); |
2857 |
|
} |
2858 |
|
result.Add("EFFECT_COUNT", pEffectChain->EffectCount()); |
2859 |
|
result.Add("EFFECT_SEQUENCE", sEffectSequence); |
2860 |
|
} catch (Exception e) { |
2861 |
|
result.Error(e); |
2862 |
|
} |
2863 |
|
return result.Produce(); |
2864 |
|
} |
2865 |
|
|
2866 |
|
String LSCPServer::AppendSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectInstance) { |
2867 |
|
dmsg(2,("LSCPServer: AppendSendEffectChainEffect(%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectInstance)); |
2868 |
|
LSCPResultSet result; |
2869 |
|
try { |
2870 |
|
EffectChain* pEffectChain = |
2871 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
2872 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2873 |
|
if (!pEffect) |
2874 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2875 |
|
pEffectChain->AppendEffect(pEffect); |
2876 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount())); |
2877 |
|
} catch (Exception e) { |
2878 |
|
result.Error(e); |
2879 |
|
} |
2880 |
|
return result.Produce(); |
2881 |
|
} |
2882 |
|
|
2883 |
|
String LSCPServer::InsertSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectChainPosition, int iEffectInstance) { |
2884 |
|
dmsg(2,("LSCPServer: InsertSendEffectChainEffect(%d,%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectChainPosition, iEffectInstance)); |
2885 |
|
LSCPResultSet result; |
2886 |
|
try { |
2887 |
|
EffectChain* pEffectChain = |
2888 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
2889 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2890 |
|
if (!pEffect) |
2891 |
|
throw Exception("There is no effect instance with index " + ToString(iEffectInstance)); |
2892 |
|
pEffectChain->InsertEffect(pEffect, iEffectChainPosition); |
2893 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount())); |
2894 |
|
} catch (Exception e) { |
2895 |
|
result.Error(e); |
2896 |
|
} |
2897 |
|
return result.Produce(); |
2898 |
|
} |
2899 |
|
|
2900 |
|
String LSCPServer::RemoveSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectChainPosition) { |
2901 |
|
dmsg(2,("LSCPServer: RemoveSendEffectChainEffect(%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectChainPosition)); |
2902 |
|
LSCPResultSet result; |
2903 |
|
try { |
2904 |
|
EffectChain* pEffectChain = |
2905 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
2906 |
|
|
2907 |
|
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
2908 |
|
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
2909 |
|
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
2910 |
|
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
2911 |
|
AudioOutputDevice* pDev = (*itEngineChannel)->GetAudioOutputDevice(); |
2912 |
|
if (pDev != NULL && pDev->deviceId() == iAudioOutputDevice) { |
2913 |
|
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
2914 |
|
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
2915 |
|
if(fxs != NULL && fxs->DestinationEffectChain() == iSendEffectChain && fxs->DestinationEffectChainPosition() == iEffectChainPosition) { |
2916 |
|
throw Exception("The effect instance is still in use by channel " + ToString((*itEngineChannel)->GetSamplerChannel()->Index())); |
2917 |
|
} |
2918 |
|
} |
2919 |
|
} |
2920 |
|
} |
2921 |
|
|
2922 |
|
pEffectChain->RemoveEffect(iEffectChainPosition); |
2923 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount())); |
2924 |
|
} catch (Exception e) { |
2925 |
|
result.Error(e); |
2926 |
|
} |
2927 |
|
return result.Produce(); |
2928 |
|
} |
2929 |
|
|
2930 |
String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) { |
String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) { |
2931 |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
2932 |
LSCPResultSet result; |
LSCPResultSet result; |
2975 |
pMidiDevice->SendNoteOffToDevice(Arg1, Arg2); |
pMidiDevice->SendNoteOffToDevice(Arg1, Arg2); |
2976 |
bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2); |
bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2); |
2977 |
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2978 |
|
} else if (MidiMsg == "CC") { |
2979 |
|
pMidiDevice->SendCCToDevice(Arg1, Arg2); |
2980 |
|
bool b = pMidiDevice->SendCCToSampler(Arg1, Arg2); |
2981 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2982 |
} else { |
} else { |
2983 |
throw Exception("Unknown MIDI message type: " + MidiMsg); |
throw Exception("Unknown MIDI message type: " + MidiMsg); |
2984 |
} |
} |
3321 |
throw Exception("Directory is specified"); |
throw Exception("Directory is specified"); |
3322 |
} |
} |
3323 |
#else |
#else |
3324 |
struct stat statBuf; |
File f(Filename); |
3325 |
int res = stat(Filename.c_str(), &statBuf); |
if(!f.Exist()) throw Exception(f.GetErrorMsg()); |
3326 |
if (res) { |
if (f.IsDirectory()) throw Exception("Directory is specified"); |
|
std::stringstream ss; |
|
|
ss << "Fail to stat `" << Filename << "`: " << strerror(errno); |
|
|
throw Exception(ss.str()); |
|
|
} |
|
|
|
|
|
if (S_ISDIR(statBuf.st_mode)) { |
|
|
throw Exception("Directory is specified"); |
|
|
} |
|
3327 |
#endif |
#endif |
3328 |
} |
} |
3329 |
|
|