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 |
|
|
142 |
} |
} |
143 |
|
|
144 |
LSCPServer::~LSCPServer() { |
LSCPServer::~LSCPServer() { |
145 |
|
CloseAllConnections(); |
146 |
|
InstrumentManager::StopBackgroundThread(); |
147 |
#if defined(WIN32) |
#if defined(WIN32) |
148 |
if (hSocket >= 0) closesocket(hSocket); |
if (hSocket >= 0) closesocket(hSocket); |
149 |
#else |
#else |
338 |
} |
} |
339 |
#endif // HAVE_SQLITE3 |
#endif // HAVE_SQLITE3 |
340 |
|
|
341 |
|
void LSCPServer::RemoveListeners() { |
342 |
|
pSampler->RemoveChannelCountListener(&eventHandler); |
343 |
|
pSampler->RemoveAudioDeviceCountListener(&eventHandler); |
344 |
|
pSampler->RemoveMidiDeviceCountListener(&eventHandler); |
345 |
|
pSampler->RemoveVoiceCountListener(&eventHandler); |
346 |
|
pSampler->RemoveStreamCountListener(&eventHandler); |
347 |
|
pSampler->RemoveBufferFillListener(&eventHandler); |
348 |
|
pSampler->RemoveTotalStreamCountListener(&eventHandler); |
349 |
|
pSampler->RemoveTotalVoiceCountListener(&eventHandler); |
350 |
|
pSampler->RemoveFxSendCountListener(&eventHandler); |
351 |
|
MidiInstrumentMapper::RemoveMidiInstrumentCountListener(&eventHandler); |
352 |
|
MidiInstrumentMapper::RemoveMidiInstrumentInfoListener(&eventHandler); |
353 |
|
MidiInstrumentMapper::RemoveMidiInstrumentMapCountListener(&eventHandler); |
354 |
|
MidiInstrumentMapper::RemoveMidiInstrumentMapInfoListener(&eventHandler); |
355 |
|
#if HAVE_SQLITE3 |
356 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveInstrumentsDbListener(&dbInstrumentsEventHandler); |
357 |
|
#endif |
358 |
|
} |
359 |
|
|
360 |
/** |
/** |
361 |
* Blocks the calling thread until the LSCP Server is initialized and |
* Blocks the calling thread until the LSCP Server is initialized and |
529 |
|
|
530 |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
531 |
|
|
532 |
if (retval == 0) |
if (retval == 0 || (retval == -1 && errno == EINTR)) |
533 |
continue; //Nothing try again |
continue; //Nothing try again |
534 |
if (retval == -1) { |
if (retval == -1) { |
535 |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
556 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
557 |
} |
} |
558 |
#else |
#else |
559 |
|
struct linger linger; |
560 |
|
linger.l_onoff = 1; |
561 |
|
linger.l_linger = 0; |
562 |
|
if(setsockopt(socket, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger))) { |
563 |
|
std::cerr << "LSCPServer: Failed to set SO_LINGER\n"; |
564 |
|
} |
565 |
|
|
566 |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
if (fcntl(socket, F_SETFL, O_NONBLOCK)) { |
567 |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
std::cerr << "LSCPServer: F_SETFL O_NONBLOCK failed." << std::endl; |
568 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
634 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
635 |
} |
} |
636 |
|
|
637 |
|
void LSCPServer::CloseAllConnections() { |
638 |
|
std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); |
639 |
|
while(iter != Sessions.end()) { |
640 |
|
CloseConnection(iter); |
641 |
|
iter = Sessions.begin(); |
642 |
|
} |
643 |
|
} |
644 |
|
|
645 |
void LSCPServer::LockRTNotify() { |
void LSCPServer::LockRTNotify() { |
646 |
RTNotifyMutex.Lock(); |
RTNotifyMutex.Lock(); |
647 |
} |
} |
1296 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1297 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1298 |
s += iter->first; |
s += iter->first; |
1299 |
|
delete iter->second; |
1300 |
} |
} |
1301 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1302 |
} |
} |
1321 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1322 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1323 |
s += iter->first; |
s += iter->first; |
1324 |
|
delete iter->second; |
1325 |
} |
} |
1326 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1327 |
} |
} |
1352 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1353 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1354 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1355 |
|
delete pParameter; |
1356 |
} |
} |
1357 |
catch (Exception e) { |
catch (Exception e) { |
1358 |
result.Error(e); |
result.Error(e); |
1380 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1381 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1382 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1383 |
|
delete pParameter; |
1384 |
} |
} |
1385 |
catch (Exception e) { |
catch (Exception e) { |
1386 |
result.Error(e); |
result.Error(e); |
1847 |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
pDevice = pSampler->CreateMidiInputDevice(MidiInputDriver, params); |
1848 |
// Make it with at least one initial port. |
// Make it with at least one initial port. |
1849 |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
std::map<String,DeviceCreationParameter*> parameters = pDevice->DeviceParameters(); |
|
parameters["PORTS"]->SetValue("1"); |
|
1850 |
} |
} |
1851 |
// Must have a device... |
// Must have a device... |
1852 |
if (pDevice == NULL) |
if (pDevice == NULL) |
2383 |
AudioRouting += ToString(pFxSend->DestinationChannel(chan)); |
AudioRouting += ToString(pFxSend->DestinationChannel(chan)); |
2384 |
} |
} |
2385 |
|
|
2386 |
|
const String sEffectRouting = |
2387 |
|
(pFxSend->DestinationEffectChain() >= 0 && pFxSend->DestinationEffectChainPosition() >= 0) |
2388 |
|
? ToString(pFxSend->DestinationEffectChain()) + "," + ToString(pFxSend->DestinationEffectChainPosition()) |
2389 |
|
: "NONE"; |
2390 |
|
|
2391 |
// success |
// success |
2392 |
result.Add("NAME", _escapeLscpResponse(pFxSend->Name())); |
result.Add("NAME", _escapeLscpResponse(pFxSend->Name())); |
2393 |
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
2394 |
result.Add("LEVEL", ToString(pFxSend->Level())); |
result.Add("LEVEL", ToString(pFxSend->Level())); |
2395 |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
2396 |
|
result.Add("EFFECT", sEffectRouting); |
2397 |
} catch (Exception e) { |
} catch (Exception e) { |
2398 |
result.Error(e); |
result.Error(e); |
2399 |
} |
} |
2456 |
return result.Produce(); |
return result.Produce(); |
2457 |
} |
} |
2458 |
|
|
2459 |
|
String LSCPServer::SetFxSendEffect(uint uiSamplerChannel, uint FxSendID, int iSendEffectChain, int iEffectChainPosition) { |
2460 |
|
dmsg(2,("LSCPServer: SetFxSendEffect(%d,%d)\n", iSendEffectChain, iEffectChainPosition)); |
2461 |
|
LSCPResultSet result; |
2462 |
|
try { |
2463 |
|
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2464 |
|
|
2465 |
|
pFxSend->SetDestinationEffect(iSendEffectChain, iEffectChainPosition); |
2466 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2467 |
|
} catch (Exception e) { |
2468 |
|
result.Error(e); |
2469 |
|
} |
2470 |
|
return result.Produce(); |
2471 |
|
} |
2472 |
|
|
2473 |
|
String LSCPServer::GetAvailableEffects() { |
2474 |
|
dmsg(2,("LSCPServer: GetAvailableEffects()\n")); |
2475 |
|
LSCPResultSet result; |
2476 |
|
try { |
2477 |
|
int n = EffectFactory::AvailableEffectsCount(); |
2478 |
|
result.Add(n); |
2479 |
|
} |
2480 |
|
catch (Exception e) { |
2481 |
|
result.Error(e); |
2482 |
|
} |
2483 |
|
return result.Produce(); |
2484 |
|
} |
2485 |
|
|
2486 |
|
String LSCPServer::ListAvailableEffects() { |
2487 |
|
dmsg(2,("LSCPServer: ListAvailableEffects()\n")); |
2488 |
|
LSCPResultSet result; |
2489 |
|
String list; |
2490 |
|
try { |
2491 |
|
//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 |
2492 |
|
int n = EffectFactory::AvailableEffectsCount(); |
2493 |
|
for (int i = 0; i < n; i++) { |
2494 |
|
if (i) list += ","; |
2495 |
|
list += ToString(i); |
2496 |
|
} |
2497 |
|
} |
2498 |
|
catch (Exception e) { |
2499 |
|
result.Error(e); |
2500 |
|
} |
2501 |
|
result.Add(list); |
2502 |
|
return result.Produce(); |
2503 |
|
} |
2504 |
|
|
2505 |
|
String LSCPServer::GetEffectInfo(int iEffectIndex) { |
2506 |
|
dmsg(2,("LSCPServer: GetEffectInfo(%d)\n", iEffectIndex)); |
2507 |
|
LSCPResultSet result; |
2508 |
|
try { |
2509 |
|
EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(iEffectIndex); |
2510 |
|
if (!pEffectInfo) |
2511 |
|
throw Exception("There is no effect with index " + ToString(iEffectIndex)); |
2512 |
|
|
2513 |
|
// convert the filename into the correct encoding as defined for LSCP |
2514 |
|
// (especially in terms of special characters -> escape sequences) |
2515 |
|
#if WIN32 |
2516 |
|
const String dllFileName = Path::fromWindows(pEffectInfo->Module()).toLscp(); |
2517 |
|
#else |
2518 |
|
// assuming POSIX |
2519 |
|
const String dllFileName = Path::fromPosix(pEffectInfo->Module()).toLscp(); |
2520 |
|
#endif |
2521 |
|
|
2522 |
|
result.Add("SYSTEM", pEffectInfo->EffectSystem()); |
2523 |
|
result.Add("MODULE", dllFileName); |
2524 |
|
result.Add("NAME", _escapeLscpResponse(pEffectInfo->Name())); |
2525 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(pEffectInfo->Description())); |
2526 |
|
} |
2527 |
|
catch (Exception e) { |
2528 |
|
result.Error(e); |
2529 |
|
} |
2530 |
|
return result.Produce(); |
2531 |
|
} |
2532 |
|
|
2533 |
|
String LSCPServer::GetEffectInstanceInfo(int iEffectInstance) { |
2534 |
|
dmsg(2,("LSCPServer: GetEffectInstanceInfo(%d)\n", iEffectInstance)); |
2535 |
|
LSCPResultSet result; |
2536 |
|
try { |
2537 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2538 |
|
if (!pEffect) |
2539 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2540 |
|
|
2541 |
|
EffectInfo* pEffectInfo = pEffect->GetEffectInfo(); |
2542 |
|
|
2543 |
|
// convert the filename into the correct encoding as defined for LSCP |
2544 |
|
// (especially in terms of special characters -> escape sequences) |
2545 |
|
#if WIN32 |
2546 |
|
const String dllFileName = Path::fromWindows(pEffectInfo->Module()).toLscp(); |
2547 |
|
#else |
2548 |
|
// assuming POSIX |
2549 |
|
const String dllFileName = Path::fromPosix(pEffectInfo->Module()).toLscp(); |
2550 |
|
#endif |
2551 |
|
|
2552 |
|
result.Add("SYSTEM", pEffectInfo->EffectSystem()); |
2553 |
|
result.Add("MODULE", dllFileName); |
2554 |
|
result.Add("NAME", _escapeLscpResponse(pEffectInfo->Name())); |
2555 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(pEffectInfo->Description())); |
2556 |
|
result.Add("INPUT_CONTROLS", ToString(pEffect->InputControlCount())); |
2557 |
|
} |
2558 |
|
catch (Exception e) { |
2559 |
|
result.Error(e); |
2560 |
|
} |
2561 |
|
return result.Produce(); |
2562 |
|
} |
2563 |
|
|
2564 |
|
String LSCPServer::GetEffectInstanceInputControlInfo(int iEffectInstance, int iInputControlIndex) { |
2565 |
|
dmsg(2,("LSCPServer: GetEffectInstanceInputControlInfo(%d,%d)\n", iEffectInstance, iInputControlIndex)); |
2566 |
|
LSCPResultSet result; |
2567 |
|
try { |
2568 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2569 |
|
if (!pEffect) |
2570 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2571 |
|
|
2572 |
|
EffectControl* pEffectControl = pEffect->InputControl(iInputControlIndex); |
2573 |
|
if (!pEffectControl) |
2574 |
|
throw Exception( |
2575 |
|
"Effect instance " + ToString(iEffectInstance) + |
2576 |
|
" does not have an input control with index " + |
2577 |
|
ToString(iInputControlIndex) |
2578 |
|
); |
2579 |
|
|
2580 |
|
result.Add("DESCRIPTION", _escapeLscpResponse(pEffectControl->Description())); |
2581 |
|
result.Add("VALUE", pEffectControl->Value()); |
2582 |
|
if (pEffectControl->MinValue()) |
2583 |
|
result.Add("RANGE_MIN", *pEffectControl->MinValue()); |
2584 |
|
if (pEffectControl->MaxValue()) |
2585 |
|
result.Add("RANGE_MAX", *pEffectControl->MaxValue()); |
2586 |
|
if (!pEffectControl->Possibilities().empty()) |
2587 |
|
result.Add("POSSIBILITIES", pEffectControl->Possibilities()); |
2588 |
|
if (pEffectControl->DefaultValue()) |
2589 |
|
result.Add("DEFAULT", *pEffectControl->DefaultValue()); |
2590 |
|
} catch (Exception e) { |
2591 |
|
result.Error(e); |
2592 |
|
} |
2593 |
|
return result.Produce(); |
2594 |
|
} |
2595 |
|
|
2596 |
|
String LSCPServer::SetEffectInstanceInputControlValue(int iEffectInstance, int iInputControlIndex, double dValue) { |
2597 |
|
dmsg(2,("LSCPServer: SetEffectInstanceInputControlValue(%d,%d,%f)\n", iEffectInstance, iInputControlIndex, dValue)); |
2598 |
|
LSCPResultSet result; |
2599 |
|
try { |
2600 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2601 |
|
if (!pEffect) |
2602 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2603 |
|
|
2604 |
|
EffectControl* pEffectControl = pEffect->InputControl(iInputControlIndex); |
2605 |
|
if (!pEffectControl) |
2606 |
|
throw Exception( |
2607 |
|
"Effect instance " + ToString(iEffectInstance) + |
2608 |
|
" does not have an input control with index " + |
2609 |
|
ToString(iInputControlIndex) |
2610 |
|
); |
2611 |
|
|
2612 |
|
pEffectControl->SetValue(dValue); |
2613 |
|
} catch (Exception e) { |
2614 |
|
result.Error(e); |
2615 |
|
} |
2616 |
|
return result.Produce(); |
2617 |
|
} |
2618 |
|
|
2619 |
|
String LSCPServer::CreateEffectInstance(int iEffectIndex) { |
2620 |
|
dmsg(2,("LSCPServer: CreateEffectInstance(%d)\n", iEffectIndex)); |
2621 |
|
LSCPResultSet result; |
2622 |
|
try { |
2623 |
|
EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(iEffectIndex); |
2624 |
|
if (!pEffectInfo) |
2625 |
|
throw Exception("There is no effect with index " + ToString(iEffectIndex)); |
2626 |
|
Effect* pEffect = EffectFactory::Create(pEffectInfo); |
2627 |
|
result = pEffect->ID(); // success |
2628 |
|
} catch (Exception e) { |
2629 |
|
result.Error(e); |
2630 |
|
} |
2631 |
|
return result.Produce(); |
2632 |
|
} |
2633 |
|
|
2634 |
|
String LSCPServer::CreateEffectInstance(String effectSystem, String module, String effectName) { |
2635 |
|
dmsg(2,("LSCPServer: CreateEffectInstance('%s','%s','%s')\n", effectSystem.c_str(), module.c_str(), effectName.c_str())); |
2636 |
|
LSCPResultSet result; |
2637 |
|
try { |
2638 |
|
// to allow loading the same LSCP session file on different systems |
2639 |
|
// successfully, probably with different effect plugin DLL paths or even |
2640 |
|
// running completely different operating systems, we do the following |
2641 |
|
// for finding the right effect: |
2642 |
|
// |
2643 |
|
// first try to search for an exact match of the effect plugin DLL |
2644 |
|
// (a.k.a 'module'), to avoid picking the wrong DLL with the same |
2645 |
|
// effect name ... |
2646 |
|
EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_MATCH_EXACTLY); |
2647 |
|
// ... if no effect with exactly matchin DLL filename was found, then |
2648 |
|
// try to lower the restrictions of matching the effect plugin DLL |
2649 |
|
// filename and try again and again ... |
2650 |
|
if (!pEffectInfo) { |
2651 |
|
dmsg(2,("no exact module match, trying MODULE_IGNORE_PATH\n")); |
2652 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_PATH); |
2653 |
|
} |
2654 |
|
if (!pEffectInfo) { |
2655 |
|
dmsg(2,("no module match, trying MODULE_IGNORE_PATH | MODULE_IGNORE_CASE\n")); |
2656 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_PATH | EffectFactory::MODULE_IGNORE_CASE); |
2657 |
|
} |
2658 |
|
if (!pEffectInfo) { |
2659 |
|
dmsg(2,("no module match, trying MODULE_IGNORE_PATH | MODULE_IGNORE_CASE | MODULE_IGNORE_EXTENSION\n")); |
2660 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_PATH | EffectFactory::MODULE_IGNORE_CASE | EffectFactory::MODULE_IGNORE_EXTENSION); |
2661 |
|
} |
2662 |
|
// ... if there was still no effect found, then completely ignore the |
2663 |
|
// DLL plugin filename argument and just search for the matching effect |
2664 |
|
// system type and effect name |
2665 |
|
if (!pEffectInfo) { |
2666 |
|
dmsg(2,("no module match, trying MODULE_IGNORE_ALL\n")); |
2667 |
|
pEffectInfo = EffectFactory::GetEffectInfo(effectSystem, module, effectName, EffectFactory::MODULE_IGNORE_ALL); |
2668 |
|
} |
2669 |
|
if (!pEffectInfo) |
2670 |
|
throw Exception("There is no such effect '" + effectSystem + "' '" + module + "' '" + effectName + "'"); |
2671 |
|
|
2672 |
|
Effect* pEffect = EffectFactory::Create(pEffectInfo); |
2673 |
|
result = LSCPResultSet(pEffect->ID()); |
2674 |
|
} catch (Exception e) { |
2675 |
|
result.Error(e); |
2676 |
|
} |
2677 |
|
return result.Produce(); |
2678 |
|
} |
2679 |
|
|
2680 |
|
String LSCPServer::DestroyEffectInstance(int iEffectInstance) { |
2681 |
|
dmsg(2,("LSCPServer: DestroyEffectInstance(%d)\n", iEffectInstance)); |
2682 |
|
LSCPResultSet result; |
2683 |
|
try { |
2684 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2685 |
|
if (!pEffect) |
2686 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2687 |
|
EffectFactory::Destroy(pEffect); |
2688 |
|
} catch (Exception e) { |
2689 |
|
result.Error(e); |
2690 |
|
} |
2691 |
|
return result.Produce(); |
2692 |
|
} |
2693 |
|
|
2694 |
|
String LSCPServer::GetEffectInstances() { |
2695 |
|
dmsg(2,("LSCPServer: GetEffectInstances()\n")); |
2696 |
|
LSCPResultSet result; |
2697 |
|
try { |
2698 |
|
int n = EffectFactory::EffectInstancesCount(); |
2699 |
|
result.Add(n); |
2700 |
|
} catch (Exception e) { |
2701 |
|
result.Error(e); |
2702 |
|
} |
2703 |
|
return result.Produce(); |
2704 |
|
} |
2705 |
|
|
2706 |
|
String LSCPServer::ListEffectInstances() { |
2707 |
|
dmsg(2,("LSCPServer: ListEffectInstances()\n")); |
2708 |
|
LSCPResultSet result; |
2709 |
|
String list; |
2710 |
|
try { |
2711 |
|
int n = EffectFactory::EffectInstancesCount(); |
2712 |
|
for (int i = 0; i < n; i++) { |
2713 |
|
Effect* pEffect = EffectFactory::GetEffectInstance(i); |
2714 |
|
if (i) list += ","; |
2715 |
|
list += ToString(pEffect->ID()); |
2716 |
|
} |
2717 |
|
} catch (Exception e) { |
2718 |
|
result.Error(e); |
2719 |
|
} |
2720 |
|
result.Add(list); |
2721 |
|
return result.Produce(); |
2722 |
|
} |
2723 |
|
|
2724 |
|
String LSCPServer::GetSendEffectChains(int iAudioOutputDevice) { |
2725 |
|
dmsg(2,("LSCPServer: GetSendEffectChains(%d)\n", iAudioOutputDevice)); |
2726 |
|
LSCPResultSet result; |
2727 |
|
try { |
2728 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2729 |
|
if (!devices.count(iAudioOutputDevice)) |
2730 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2731 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2732 |
|
int n = pDevice->SendEffectChainCount(); |
2733 |
|
result.Add(n); |
2734 |
|
} catch (Exception e) { |
2735 |
|
result.Error(e); |
2736 |
|
} |
2737 |
|
return result.Produce(); |
2738 |
|
} |
2739 |
|
|
2740 |
|
String LSCPServer::ListSendEffectChains(int iAudioOutputDevice) { |
2741 |
|
dmsg(2,("LSCPServer: ListSendEffectChains(%d)\n", iAudioOutputDevice)); |
2742 |
|
LSCPResultSet result; |
2743 |
|
String list; |
2744 |
|
try { |
2745 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2746 |
|
if (!devices.count(iAudioOutputDevice)) |
2747 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2748 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2749 |
|
int n = pDevice->SendEffectChainCount(); |
2750 |
|
for (int i = 0; i < n; i++) { |
2751 |
|
EffectChain* pEffectChain = pDevice->SendEffectChain(i); |
2752 |
|
if (i) list += ","; |
2753 |
|
list += ToString(pEffectChain->ID()); |
2754 |
|
} |
2755 |
|
} catch (Exception e) { |
2756 |
|
result.Error(e); |
2757 |
|
} |
2758 |
|
result.Add(list); |
2759 |
|
return result.Produce(); |
2760 |
|
} |
2761 |
|
|
2762 |
|
String LSCPServer::AddSendEffectChain(int iAudioOutputDevice) { |
2763 |
|
dmsg(2,("LSCPServer: AddSendEffectChain(%d)\n", iAudioOutputDevice)); |
2764 |
|
LSCPResultSet result; |
2765 |
|
try { |
2766 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2767 |
|
if (!devices.count(iAudioOutputDevice)) |
2768 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2769 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2770 |
|
EffectChain* pEffectChain = pDevice->AddSendEffectChain(); |
2771 |
|
result = pEffectChain->ID(); |
2772 |
|
} catch (Exception e) { |
2773 |
|
result.Error(e); |
2774 |
|
} |
2775 |
|
return result.Produce(); |
2776 |
|
} |
2777 |
|
|
2778 |
|
String LSCPServer::RemoveSendEffectChain(int iAudioOutputDevice, int iSendEffectChain) { |
2779 |
|
dmsg(2,("LSCPServer: RemoveSendEffectChain(%d,%d)\n", iAudioOutputDevice, iSendEffectChain)); |
2780 |
|
LSCPResultSet result; |
2781 |
|
try { |
2782 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2783 |
|
if (!devices.count(iAudioOutputDevice)) |
2784 |
|
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2785 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2786 |
|
for (int i = 0; i < pDevice->SendEffectChainCount(); i++) { |
2787 |
|
EffectChain* pEffectChain = pDevice->SendEffectChain(i); |
2788 |
|
if (pEffectChain->ID() == iSendEffectChain) { |
2789 |
|
pDevice->RemoveSendEffectChain(i); |
2790 |
|
return result.Produce(); |
2791 |
|
} |
2792 |
|
} |
2793 |
|
throw Exception( |
2794 |
|
"There is no send effect chain with ID " + |
2795 |
|
ToString(iSendEffectChain) + " for audio output device " + |
2796 |
|
ToString(iAudioOutputDevice) + "." |
2797 |
|
); |
2798 |
|
} catch (Exception e) { |
2799 |
|
result.Error(e); |
2800 |
|
} |
2801 |
|
return result.Produce(); |
2802 |
|
} |
2803 |
|
|
2804 |
|
static EffectChain* _getSendEffectChain(Sampler* pSampler, int iAudioOutputDevice, int iSendEffectChain) throw (Exception) { |
2805 |
|
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2806 |
|
if (!devices.count(iAudioOutputDevice)) |
2807 |
|
throw Exception( |
2808 |
|
"There is no audio output device with index " + |
2809 |
|
ToString(iAudioOutputDevice) + "." |
2810 |
|
); |
2811 |
|
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2812 |
|
for (int i = 0; i < pDevice->SendEffectChainCount(); i++) { |
2813 |
|
EffectChain* pEffectChain = pDevice->SendEffectChain(i); |
2814 |
|
if (pEffectChain->ID() == iSendEffectChain) { |
2815 |
|
return pEffectChain; |
2816 |
|
} |
2817 |
|
} |
2818 |
|
throw Exception( |
2819 |
|
"There is no send effect chain with ID " + |
2820 |
|
ToString(iSendEffectChain) + " for audio output device " + |
2821 |
|
ToString(iAudioOutputDevice) + "." |
2822 |
|
); |
2823 |
|
} |
2824 |
|
|
2825 |
|
String LSCPServer::GetSendEffectChainInfo(int iAudioOutputDevice, int iSendEffectChain) { |
2826 |
|
dmsg(2,("LSCPServer: GetSendEffectChainInfo(%d,%d)\n", iAudioOutputDevice, iSendEffectChain)); |
2827 |
|
LSCPResultSet result; |
2828 |
|
try { |
2829 |
|
EffectChain* pEffectChain = |
2830 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
2831 |
|
String sEffectSequence; |
2832 |
|
for (int i = 0; i < pEffectChain->EffectCount(); i++) { |
2833 |
|
if (i) sEffectSequence += ","; |
2834 |
|
sEffectSequence += ToString(pEffectChain->GetEffect(i)->ID()); |
2835 |
|
} |
2836 |
|
result.Add("EFFECT_COUNT", pEffectChain->EffectCount()); |
2837 |
|
result.Add("EFFECT_SEQUENCE", sEffectSequence); |
2838 |
|
} catch (Exception e) { |
2839 |
|
result.Error(e); |
2840 |
|
} |
2841 |
|
return result.Produce(); |
2842 |
|
} |
2843 |
|
|
2844 |
|
String LSCPServer::AppendSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectInstance) { |
2845 |
|
dmsg(2,("LSCPServer: AppendSendEffectChainEffect(%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectInstance)); |
2846 |
|
LSCPResultSet result; |
2847 |
|
try { |
2848 |
|
EffectChain* pEffectChain = |
2849 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
2850 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2851 |
|
if (!pEffect) |
2852 |
|
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2853 |
|
pEffectChain->AppendEffect(pEffect); |
2854 |
|
} catch (Exception e) { |
2855 |
|
result.Error(e); |
2856 |
|
} |
2857 |
|
return result.Produce(); |
2858 |
|
} |
2859 |
|
|
2860 |
|
String LSCPServer::InsertSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectChainPosition, int iEffectInstance) { |
2861 |
|
dmsg(2,("LSCPServer: InsertSendEffectChainEffect(%d,%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectChainPosition, iEffectInstance)); |
2862 |
|
LSCPResultSet result; |
2863 |
|
try { |
2864 |
|
EffectChain* pEffectChain = |
2865 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
2866 |
|
Effect* pEffect = EffectFactory::GetEffectInstanceByID(iEffectInstance); |
2867 |
|
if (!pEffect) |
2868 |
|
throw Exception("There is no effect instance with index " + ToString(iEffectInstance)); |
2869 |
|
pEffectChain->InsertEffect(pEffect, iEffectChainPosition); |
2870 |
|
} catch (Exception e) { |
2871 |
|
result.Error(e); |
2872 |
|
} |
2873 |
|
return result.Produce(); |
2874 |
|
} |
2875 |
|
|
2876 |
|
String LSCPServer::RemoveSendEffectChainEffect(int iAudioOutputDevice, int iSendEffectChain, int iEffectChainPosition) { |
2877 |
|
dmsg(2,("LSCPServer: RemoveSendEffectChainEffect(%d,%d,%d)\n", iAudioOutputDevice, iSendEffectChain, iEffectChainPosition)); |
2878 |
|
LSCPResultSet result; |
2879 |
|
try { |
2880 |
|
EffectChain* pEffectChain = |
2881 |
|
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
2882 |
|
pEffectChain->RemoveEffect(iEffectChainPosition); |
2883 |
|
} catch (Exception e) { |
2884 |
|
result.Error(e); |
2885 |
|
} |
2886 |
|
return result.Produce(); |
2887 |
|
} |
2888 |
|
|
2889 |
String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) { |
String LSCPServer::EditSamplerChannelInstrument(uint uiSamplerChannel) { |
2890 |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
2891 |
LSCPResultSet result; |
LSCPResultSet result; |
2934 |
pMidiDevice->SendNoteOffToDevice(Arg1, Arg2); |
pMidiDevice->SendNoteOffToDevice(Arg1, Arg2); |
2935 |
bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2); |
bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2); |
2936 |
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2937 |
|
} else if (MidiMsg == "CC") { |
2938 |
|
pMidiDevice->SendCCToDevice(Arg1, Arg2); |
2939 |
|
bool b = pMidiDevice->SendCCToSampler(Arg1, Arg2); |
2940 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2941 |
} else { |
} else { |
2942 |
throw Exception("Unknown MIDI message type: " + MidiMsg); |
throw Exception("Unknown MIDI message type: " + MidiMsg); |
2943 |
} |
} |
3020 |
String LSCPServer::GetTotalVoiceCountMax() { |
String LSCPServer::GetTotalVoiceCountMax() { |
3021 |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
3022 |
LSCPResultSet result; |
LSCPResultSet result; |
3023 |
result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES); |
result.Add(EngineFactory::EngineInstances().size() * GLOBAL_MAX_VOICES); |
3024 |
|
return result.Produce(); |
3025 |
|
} |
3026 |
|
|
3027 |
|
/** |
3028 |
|
* Will be called by the parser to return the sampler global maximum |
3029 |
|
* allowed number of voices. |
3030 |
|
*/ |
3031 |
|
String LSCPServer::GetGlobalMaxVoices() { |
3032 |
|
dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n")); |
3033 |
|
LSCPResultSet result; |
3034 |
|
result.Add(GLOBAL_MAX_VOICES); |
3035 |
|
return result.Produce(); |
3036 |
|
} |
3037 |
|
|
3038 |
|
/** |
3039 |
|
* Will be called by the parser to set the sampler global maximum number of |
3040 |
|
* voices. |
3041 |
|
*/ |
3042 |
|
String LSCPServer::SetGlobalMaxVoices(int iVoices) { |
3043 |
|
dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices)); |
3044 |
|
LSCPResultSet result; |
3045 |
|
try { |
3046 |
|
if (iVoices < 1) throw Exception("Maximum voices may not be less than 1"); |
3047 |
|
GLOBAL_MAX_VOICES = iVoices; // see common/global_private.cpp |
3048 |
|
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
3049 |
|
if (engines.size() > 0) { |
3050 |
|
std::set<Engine*>::iterator iter = engines.begin(); |
3051 |
|
std::set<Engine*>::iterator end = engines.end(); |
3052 |
|
for (; iter != end; ++iter) { |
3053 |
|
(*iter)->SetMaxVoices(iVoices); |
3054 |
|
} |
3055 |
|
} |
3056 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOICES", GLOBAL_MAX_VOICES)); |
3057 |
|
} catch (Exception e) { |
3058 |
|
result.Error(e); |
3059 |
|
} |
3060 |
|
return result.Produce(); |
3061 |
|
} |
3062 |
|
|
3063 |
|
/** |
3064 |
|
* Will be called by the parser to return the sampler global maximum |
3065 |
|
* allowed number of disk streams. |
3066 |
|
*/ |
3067 |
|
String LSCPServer::GetGlobalMaxStreams() { |
3068 |
|
dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n")); |
3069 |
|
LSCPResultSet result; |
3070 |
|
result.Add(GLOBAL_MAX_STREAMS); |
3071 |
|
return result.Produce(); |
3072 |
|
} |
3073 |
|
|
3074 |
|
/** |
3075 |
|
* Will be called by the parser to set the sampler global maximum number of |
3076 |
|
* disk streams. |
3077 |
|
*/ |
3078 |
|
String LSCPServer::SetGlobalMaxStreams(int iStreams) { |
3079 |
|
dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams)); |
3080 |
|
LSCPResultSet result; |
3081 |
|
try { |
3082 |
|
if (iStreams < 0) throw Exception("Maximum disk streams may not be negative"); |
3083 |
|
GLOBAL_MAX_STREAMS = iStreams; // see common/global_private.cpp |
3084 |
|
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
3085 |
|
if (engines.size() > 0) { |
3086 |
|
std::set<Engine*>::iterator iter = engines.begin(); |
3087 |
|
std::set<Engine*>::iterator end = engines.end(); |
3088 |
|
for (; iter != end; ++iter) { |
3089 |
|
(*iter)->SetMaxDiskStreams(iStreams); |
3090 |
|
} |
3091 |
|
} |
3092 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "STREAMS", GLOBAL_MAX_STREAMS)); |
3093 |
|
} catch (Exception e) { |
3094 |
|
result.Error(e); |
3095 |
|
} |
3096 |
return result.Produce(); |
return result.Produce(); |
3097 |
} |
} |
3098 |
|
|
3280 |
throw Exception("Directory is specified"); |
throw Exception("Directory is specified"); |
3281 |
} |
} |
3282 |
#else |
#else |
3283 |
struct stat statBuf; |
File f(Filename); |
3284 |
int res = stat(Filename.c_str(), &statBuf); |
if(!f.Exist()) throw Exception(f.GetErrorMsg()); |
3285 |
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"); |
|
|
} |
|
3286 |
#endif |
#endif |
3287 |
} |
} |
3288 |
|
|