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 - 2010 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 * |
97 |
*/ |
*/ |
98 |
fd_set LSCPServer::fdSet; |
fd_set LSCPServer::fdSet; |
99 |
int LSCPServer::currentSocket = -1; |
int LSCPServer::currentSocket = -1; |
100 |
std::vector<yyparse_param_t> LSCPServer::Sessions = std::vector<yyparse_param_t>(); |
std::vector<yyparse_param_t> LSCPServer::Sessions; |
101 |
std::vector<yyparse_param_t>::iterator itCurrentSession = std::vector<yyparse_param_t>::iterator(); |
std::vector<yyparse_param_t>::iterator itCurrentSession; |
102 |
std::map<int,String> LSCPServer::bufferedNotifies = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedNotifies; |
103 |
std::map<int,String> LSCPServer::bufferedCommands = std::map<int,String>(); |
std::map<int,String> LSCPServer::bufferedCommands; |
104 |
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; |
105 |
Mutex LSCPServer::NotifyMutex = Mutex(); |
Mutex LSCPServer::NotifyMutex; |
106 |
Mutex LSCPServer::NotifyBufferMutex = Mutex(); |
Mutex LSCPServer::NotifyBufferMutex; |
107 |
Mutex LSCPServer::SubscriptionMutex = Mutex(); |
Mutex LSCPServer::SubscriptionMutex; |
108 |
Mutex LSCPServer::RTNotifyMutex = Mutex(); |
Mutex LSCPServer::RTNotifyMutex; |
109 |
|
|
110 |
LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4), eventHandler(this) { |
LSCPServer::LSCPServer(Sampler* pSampler, long int addr, short int port) : Thread(true, false, 0, -4), eventHandler(this) { |
111 |
SocketAddress.sin_family = AF_INET; |
SocketAddress.sin_family = AF_INET; |
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 |
|
|
447 |
#endif |
#endif |
448 |
// 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 |
449 |
{ |
{ |
450 |
|
LockGuard lock(EngineChannelFactory::EngineChannelsMutex); |
451 |
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
452 |
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
453 |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
516 |
} |
} |
517 |
} |
} |
518 |
|
|
519 |
//Now let's deliver late notifies (if any) |
//Now let's deliver late notifies (if any) |
520 |
NotifyBufferMutex.Lock(); |
{ |
521 |
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
LockGuard lock(NotifyBufferMutex); |
522 |
|
for (std::map<int,String>::iterator iterNotify = bufferedNotifies.begin(); iterNotify != bufferedNotifies.end(); iterNotify++) { |
523 |
#ifdef MSG_NOSIGNAL |
#ifdef MSG_NOSIGNAL |
524 |
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL); |
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), MSG_NOSIGNAL); |
525 |
#else |
#else |
526 |
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); |
send(iterNotify->first, iterNotify->second.c_str(), iterNotify->second.size(), 0); |
527 |
#endif |
#endif |
528 |
} |
} |
529 |
bufferedNotifies.clear(); |
bufferedNotifies.clear(); |
530 |
NotifyBufferMutex.Unlock(); |
} |
531 |
|
|
532 |
fd_set selectSet = fdSet; |
fd_set selectSet = fdSet; |
533 |
timeout.tv_sec = 0; |
timeout.tv_sec = 0; |
624 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_misc, "Client connection terminated on socket", socket)); |
625 |
Sessions.erase(iter); |
Sessions.erase(iter); |
626 |
FD_CLR(socket, &fdSet); |
FD_CLR(socket, &fdSet); |
627 |
SubscriptionMutex.Lock(); //Must unsubscribe this socket from all events (if any) |
{ |
628 |
for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) { |
LockGuard lock(SubscriptionMutex); |
629 |
iter->second.remove(socket); |
// Must unsubscribe this socket from all events (if any) |
630 |
} |
for (std::map< LSCPEvent::event_t, std::list<int> >::iterator iter = eventSubscriptions.begin(); iter != eventSubscriptions.end(); iter++) { |
631 |
SubscriptionMutex.Unlock(); |
iter->second.remove(socket); |
632 |
NotifyMutex.Lock(); |
} |
633 |
|
} |
634 |
|
LockGuard lock(NotifyMutex); |
635 |
bufferedCommands.erase(socket); |
bufferedCommands.erase(socket); |
636 |
bufferedNotifies.erase(socket); |
bufferedNotifies.erase(socket); |
637 |
#if defined(WIN32) |
#if defined(WIN32) |
639 |
#else |
#else |
640 |
close(socket); |
close(socket); |
641 |
#endif |
#endif |
|
NotifyMutex.Unlock(); |
|
642 |
} |
} |
643 |
|
|
644 |
void LSCPServer::CloseAllConnections() { |
void LSCPServer::CloseAllConnections() { |
649 |
} |
} |
650 |
} |
} |
651 |
|
|
|
void LSCPServer::LockRTNotify() { |
|
|
RTNotifyMutex.Lock(); |
|
|
} |
|
|
|
|
|
void LSCPServer::UnlockRTNotify() { |
|
|
RTNotifyMutex.Unlock(); |
|
|
} |
|
|
|
|
652 |
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
int LSCPServer::EventSubscribers( std::list<LSCPEvent::event_t> events ) { |
653 |
int subs = 0; |
int subs = 0; |
654 |
SubscriptionMutex.Lock(); |
LockGuard lock(SubscriptionMutex); |
655 |
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
for( std::list<LSCPEvent::event_t>::iterator iter = events.begin(); |
656 |
iter != events.end(); iter++) |
iter != events.end(); iter++) |
657 |
{ |
{ |
658 |
subs += eventSubscriptions.count(*iter); |
subs += eventSubscriptions.count(*iter); |
659 |
} |
} |
|
SubscriptionMutex.Unlock(); |
|
660 |
return subs; |
return subs; |
661 |
} |
} |
662 |
|
|
663 |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
void LSCPServer::SendLSCPNotify( LSCPEvent event ) { |
664 |
SubscriptionMutex.Lock(); |
LockGuard lock(SubscriptionMutex); |
665 |
if (eventSubscriptions.count(event.GetType()) == 0) { |
if (eventSubscriptions.count(event.GetType()) == 0) { |
666 |
SubscriptionMutex.Unlock(); //Nobody is subscribed to this event |
// Nobody is subscribed to this event |
667 |
return; |
return; |
668 |
} |
} |
669 |
std::list<int>::iterator iter = eventSubscriptions[event.GetType()].begin(); |
std::list<int>::iterator iter = eventSubscriptions[event.GetType()].begin(); |
689 |
} |
} |
690 |
} |
} |
691 |
} |
} |
|
SubscriptionMutex.Unlock(); |
|
692 |
} |
} |
693 |
|
|
694 |
extern int GetLSCPCommand( void *buf, int max_size ) { |
extern int GetLSCPCommand( void *buf, int max_size ) { |
803 |
void LSCPServer::AnswerClient(String ReturnMessage) { |
void LSCPServer::AnswerClient(String ReturnMessage) { |
804 |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
dmsg(2,("LSCPServer::AnswerClient(ReturnMessage=%s)", ReturnMessage.c_str())); |
805 |
if (currentSocket != -1) { |
if (currentSocket != -1) { |
806 |
NotifyMutex.Lock(); |
LockGuard lock(NotifyMutex); |
807 |
#ifdef MSG_NOSIGNAL |
#ifdef MSG_NOSIGNAL |
808 |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL); |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), MSG_NOSIGNAL); |
809 |
#else |
#else |
810 |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
send(currentSocket, ReturnMessage.c_str(), ReturnMessage.size(), 0); |
811 |
#endif |
#endif |
|
NotifyMutex.Unlock(); |
|
812 |
} |
} |
813 |
} |
} |
814 |
|
|
958 |
try { |
try { |
959 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
960 |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
961 |
LockRTNotify(); |
LockGuard lock(RTNotifyMutex); |
962 |
pSamplerChannel->SetEngineType(EngineName); |
pSamplerChannel->SetEngineType(EngineName); |
963 |
if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1); |
if(HasSoloChannel()) pSamplerChannel->GetEngineChannel()->SetMute(-1); |
|
UnlockRTNotify(); |
|
964 |
} |
} |
965 |
catch (Exception e) { |
catch (Exception e) { |
966 |
result.Error(e); |
result.Error(e); |
1000 |
*/ |
*/ |
1001 |
String LSCPServer::AddChannel() { |
String LSCPServer::AddChannel() { |
1002 |
dmsg(2,("LSCPServer: AddChannel()\n")); |
dmsg(2,("LSCPServer: AddChannel()\n")); |
1003 |
LockRTNotify(); |
SamplerChannel* pSamplerChannel; |
1004 |
SamplerChannel* pSamplerChannel = pSampler->AddSamplerChannel(); |
{ |
1005 |
UnlockRTNotify(); |
LockGuard lock(RTNotifyMutex); |
1006 |
|
pSamplerChannel = pSampler->AddSamplerChannel(); |
1007 |
|
} |
1008 |
LSCPResultSet result(pSamplerChannel->Index()); |
LSCPResultSet result(pSamplerChannel->Index()); |
1009 |
return result.Produce(); |
return result.Produce(); |
1010 |
} |
} |
1015 |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
String LSCPServer::RemoveChannel(uint uiSamplerChannel) { |
1016 |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: RemoveChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
1017 |
LSCPResultSet result; |
LSCPResultSet result; |
1018 |
LockRTNotify(); |
{ |
1019 |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
LockGuard lock(RTNotifyMutex); |
1020 |
UnlockRTNotify(); |
pSampler->RemoveSamplerChannel(uiSamplerChannel); |
1021 |
|
} |
1022 |
return result.Produce(); |
return result.Produce(); |
1023 |
} |
} |
1024 |
|
|
1061 |
String LSCPServer::GetEngineInfo(String EngineName) { |
String LSCPServer::GetEngineInfo(String EngineName) { |
1062 |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
dmsg(2,("LSCPServer: GetEngineInfo(EngineName=%s)\n", EngineName.c_str())); |
1063 |
LSCPResultSet result; |
LSCPResultSet result; |
1064 |
LockRTNotify(); |
{ |
1065 |
try { |
LockGuard lock(RTNotifyMutex); |
1066 |
Engine* pEngine = EngineFactory::Create(EngineName); |
try { |
1067 |
result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description())); |
Engine* pEngine = EngineFactory::Create(EngineName); |
1068 |
result.Add("VERSION", pEngine->Version()); |
result.Add("DESCRIPTION", _escapeLscpResponse(pEngine->Description())); |
1069 |
EngineFactory::Destroy(pEngine); |
result.Add("VERSION", pEngine->Version()); |
1070 |
} |
EngineFactory::Destroy(pEngine); |
1071 |
catch (Exception e) { |
} |
1072 |
result.Error(e); |
catch (Exception e) { |
1073 |
|
result.Error(e); |
1074 |
|
} |
1075 |
} |
} |
|
UnlockRTNotify(); |
|
1076 |
return result.Produce(); |
return result.Produce(); |
1077 |
} |
} |
1078 |
|
|
1721 |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
String LSCPServer::SetAudioOutputDevice(uint AudioDeviceId, uint uiSamplerChannel) { |
1722 |
dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetAudiotOutputDevice(AudioDeviceId=%d, SamplerChannel=%d)\n",AudioDeviceId,uiSamplerChannel)); |
1723 |
LSCPResultSet result; |
LSCPResultSet result; |
1724 |
LockRTNotify(); |
{ |
1725 |
|
LockGuard lock(RTNotifyMutex); |
1726 |
|
try { |
1727 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1728 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1729 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1730 |
|
if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId)); |
1731 |
|
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
1732 |
|
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1733 |
|
} |
1734 |
|
catch (Exception e) { |
1735 |
|
result.Error(e); |
1736 |
|
} |
1737 |
|
} |
1738 |
|
return result.Produce(); |
1739 |
|
} |
1740 |
|
|
1741 |
|
String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) { |
1742 |
|
dmsg(2,("LSCPServer: SetAudioOutputType(String AudioOutputDriver=%s, SamplerChannel=%d)\n",AudioOutputDriver.c_str(),uiSamplerChannel)); |
1743 |
|
LSCPResultSet result; |
1744 |
|
{ |
1745 |
|
LockGuard lock(RTNotifyMutex); |
1746 |
|
try { |
1747 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1748 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1749 |
|
// Driver type name aliasing... |
1750 |
|
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
1751 |
|
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
1752 |
|
// Check if there's one audio output device already created |
1753 |
|
// for the intended audio driver type (AudioOutputDriver)... |
1754 |
|
AudioOutputDevice *pDevice = NULL; |
1755 |
|
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
1756 |
|
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
1757 |
|
for (; iter != devices.end(); iter++) { |
1758 |
|
if ((iter->second)->Driver() == AudioOutputDriver) { |
1759 |
|
pDevice = iter->second; |
1760 |
|
break; |
1761 |
|
} |
1762 |
|
} |
1763 |
|
// If it doesn't exist, create a new one with default parameters... |
1764 |
|
if (pDevice == NULL) { |
1765 |
|
std::map<String,String> params; |
1766 |
|
pDevice = pSampler->CreateAudioOutputDevice(AudioOutputDriver, params); |
1767 |
|
} |
1768 |
|
// Must have a device... |
1769 |
|
if (pDevice == NULL) |
1770 |
|
throw Exception("Internal error: could not create audio output device."); |
1771 |
|
// Set it as the current channel device... |
1772 |
|
pSamplerChannel->SetAudioOutputDevice(pDevice); |
1773 |
|
} |
1774 |
|
catch (Exception e) { |
1775 |
|
result.Error(e); |
1776 |
|
} |
1777 |
|
} |
1778 |
|
return result.Produce(); |
1779 |
|
} |
1780 |
|
|
1781 |
|
String LSCPServer::AddChannelMidiInput(uint uiSamplerChannel, uint MIDIDeviceId, uint MIDIPort) { |
1782 |
|
dmsg(2,("LSCPServer: AddChannelMidiInput(uiSamplerChannel=%d, MIDIDeviceId=%d, MIDIPort=%d)\n",uiSamplerChannel,MIDIDeviceId,MIDIPort)); |
1783 |
|
LSCPResultSet result; |
1784 |
try { |
try { |
1785 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1786 |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1787 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
|
1788 |
if (!devices.count(AudioDeviceId)) throw Exception("There is no audio output device with index " + ToString(AudioDeviceId)); |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1789 |
AudioOutputDevice* pDevice = devices[AudioDeviceId]; |
if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1790 |
pSamplerChannel->SetAudioOutputDevice(pDevice); |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1791 |
|
|
1792 |
|
MidiInputPort* pPort = pDevice->GetPort(MIDIPort); |
1793 |
|
if (!pPort) throw Exception("There is no MIDI input port with index " + ToString(MIDIPort) + " on MIDI input device with index " + ToString(MIDIDeviceId)); |
1794 |
|
|
1795 |
|
pSamplerChannel->Connect(pPort); |
1796 |
|
} catch (Exception e) { |
1797 |
|
result.Error(e); |
1798 |
} |
} |
1799 |
catch (Exception e) { |
return result.Produce(); |
1800 |
result.Error(e); |
} |
1801 |
|
|
1802 |
|
String LSCPServer::RemoveChannelMidiInput(uint uiSamplerChannel) { |
1803 |
|
dmsg(2,("LSCPServer: RemoveChannelMidiInput(uiSamplerChannel=%d)\n",uiSamplerChannel)); |
1804 |
|
LSCPResultSet result; |
1805 |
|
try { |
1806 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1807 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1808 |
|
pSamplerChannel->DisconnectAllMidiInputPorts(); |
1809 |
|
} catch (Exception e) { |
1810 |
|
result.Error(e); |
1811 |
} |
} |
|
UnlockRTNotify(); |
|
1812 |
return result.Produce(); |
return result.Produce(); |
1813 |
} |
} |
1814 |
|
|
1815 |
String LSCPServer::SetAudioOutputType(String AudioOutputDriver, uint uiSamplerChannel) { |
String LSCPServer::RemoveChannelMidiInput(uint uiSamplerChannel, uint MIDIDeviceId) { |
1816 |
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)); |
1817 |
LSCPResultSet result; |
LSCPResultSet result; |
|
LockRTNotify(); |
|
1818 |
try { |
try { |
1819 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1820 |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1821 |
// Driver type name aliasing... |
|
1822 |
if (AudioOutputDriver == "Alsa") AudioOutputDriver = "ALSA"; |
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1823 |
if (AudioOutputDriver == "Jack") AudioOutputDriver = "JACK"; |
if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1824 |
// Check if there's one audio output device already created |
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1825 |
// for the intended audio driver type (AudioOutputDriver)... |
|
1826 |
AudioOutputDevice *pDevice = NULL; |
std::vector<MidiInputPort*> vPorts = pSamplerChannel->GetMidiInputPorts(); |
1827 |
std::map<uint, AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
for (int i = 0; i < vPorts.size(); ++i) |
1828 |
std::map<uint, AudioOutputDevice*>::iterator iter = devices.begin(); |
if (vPorts[i]->GetDevice() == pDevice) |
1829 |
for (; iter != devices.end(); iter++) { |
pSamplerChannel->Disconnect(vPorts[i]); |
1830 |
if ((iter->second)->Driver() == AudioOutputDriver) { |
|
1831 |
pDevice = iter->second; |
} catch (Exception e) { |
1832 |
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); |
|
1833 |
} |
} |
1834 |
catch (Exception e) { |
return result.Produce(); |
1835 |
result.Error(e); |
} |
1836 |
|
|
1837 |
|
String LSCPServer::RemoveChannelMidiInput(uint uiSamplerChannel, uint MIDIDeviceId, uint MIDIPort) { |
1838 |
|
dmsg(2,("LSCPServer: RemoveChannelMidiInput(uiSamplerChannel=%d, MIDIDeviceId=%d, MIDIPort=%d)\n",uiSamplerChannel,MIDIDeviceId,MIDIPort)); |
1839 |
|
LSCPResultSet result; |
1840 |
|
try { |
1841 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1842 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1843 |
|
|
1844 |
|
std::map<uint, MidiInputDevice*> devices = pSampler->GetMidiInputDevices(); |
1845 |
|
if (!devices.count(MIDIDeviceId)) throw Exception("There is no MIDI input device with index " + ToString(MIDIDeviceId)); |
1846 |
|
MidiInputDevice* pDevice = devices[MIDIDeviceId]; |
1847 |
|
|
1848 |
|
MidiInputPort* pPort = pDevice->GetPort(MIDIPort); |
1849 |
|
if (!pPort) throw Exception("There is no MIDI input port with index " + ToString(MIDIPort) + " on MIDI input device with index " + ToString(MIDIDeviceId)); |
1850 |
|
|
1851 |
|
pSamplerChannel->Disconnect(pPort); |
1852 |
|
} catch (Exception e) { |
1853 |
|
result.Error(e); |
1854 |
|
} |
1855 |
|
return result.Produce(); |
1856 |
|
} |
1857 |
|
|
1858 |
|
String LSCPServer::ListChannelMidiInputs(uint uiSamplerChannel) { |
1859 |
|
dmsg(2,("LSCPServer: ListChannelMidiInputs(uiSamplerChannel=%d)\n",uiSamplerChannel)); |
1860 |
|
LSCPResultSet result; |
1861 |
|
try { |
1862 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
1863 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
1864 |
|
std::vector<MidiInputPort*> vPorts = pSamplerChannel->GetMidiInputPorts(); |
1865 |
|
|
1866 |
|
String s; |
1867 |
|
for (int i = 0; i < vPorts.size(); ++i) { |
1868 |
|
const int iDeviceID = vPorts[i]->GetDevice()->MidiInputDeviceID(); |
1869 |
|
const int iPortNr = vPorts[i]->GetPortNumber(); |
1870 |
|
if (s.size()) s += ","; |
1871 |
|
s += "{" + ToString(iDeviceID) + "," |
1872 |
|
+ ToString(iPortNr) + "}"; |
1873 |
|
} |
1874 |
|
result.Add(s); |
1875 |
|
} catch (Exception e) { |
1876 |
|
result.Error(e); |
1877 |
} |
} |
|
UnlockRTNotify(); |
|
1878 |
return result.Produce(); |
return result.Produce(); |
1879 |
} |
} |
1880 |
|
|
2711 |
); |
); |
2712 |
|
|
2713 |
pEffectControl->SetValue(dValue); |
pEffectControl->SetValue(dValue); |
2714 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_info, iEffectInstance)); |
2715 |
} catch (Exception e) { |
} catch (Exception e) { |
2716 |
result.Error(e); |
result.Error(e); |
2717 |
} |
} |
2727 |
throw Exception("There is no effect with index " + ToString(iEffectIndex)); |
throw Exception("There is no effect with index " + ToString(iEffectIndex)); |
2728 |
Effect* pEffect = EffectFactory::Create(pEffectInfo); |
Effect* pEffect = EffectFactory::Create(pEffectInfo); |
2729 |
result = pEffect->ID(); // success |
result = pEffect->ID(); // success |
2730 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount())); |
2731 |
} catch (Exception e) { |
} catch (Exception e) { |
2732 |
result.Error(e); |
result.Error(e); |
2733 |
} |
} |
2774 |
|
|
2775 |
Effect* pEffect = EffectFactory::Create(pEffectInfo); |
Effect* pEffect = EffectFactory::Create(pEffectInfo); |
2776 |
result = LSCPResultSet(pEffect->ID()); |
result = LSCPResultSet(pEffect->ID()); |
2777 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount())); |
2778 |
} catch (Exception e) { |
} catch (Exception e) { |
2779 |
result.Error(e); |
result.Error(e); |
2780 |
} |
} |
2789 |
if (!pEffect) |
if (!pEffect) |
2790 |
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2791 |
EffectFactory::Destroy(pEffect); |
EffectFactory::Destroy(pEffect); |
2792 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_instance_count, EffectFactory::EffectInstancesCount())); |
2793 |
} catch (Exception e) { |
} catch (Exception e) { |
2794 |
result.Error(e); |
result.Error(e); |
2795 |
} |
} |
2874 |
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2875 |
EffectChain* pEffectChain = pDevice->AddSendEffectChain(); |
EffectChain* pEffectChain = pDevice->AddSendEffectChain(); |
2876 |
result = pEffectChain->ID(); |
result = pEffectChain->ID(); |
2877 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_count, iAudioOutputDevice, pDevice->SendEffectChainCount())); |
2878 |
} catch (Exception e) { |
} catch (Exception e) { |
2879 |
result.Error(e); |
result.Error(e); |
2880 |
} |
} |
2888 |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
std::map<uint,AudioOutputDevice*> devices = pSampler->GetAudioOutputDevices(); |
2889 |
if (!devices.count(iAudioOutputDevice)) |
if (!devices.count(iAudioOutputDevice)) |
2890 |
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
throw Exception("There is no audio output device with index " + ToString(iAudioOutputDevice) + "."); |
2891 |
|
|
2892 |
|
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
2893 |
|
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
2894 |
|
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
2895 |
|
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
2896 |
|
AudioOutputDevice* pDev = (*itEngineChannel)->GetAudioOutputDevice(); |
2897 |
|
if (pDev != NULL && pDev->deviceId() == iAudioOutputDevice) { |
2898 |
|
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
2899 |
|
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
2900 |
|
if(fxs != NULL && fxs->DestinationEffectChain() == iSendEffectChain) { |
2901 |
|
throw Exception("The effect chain is still in use by channel " + ToString((*itEngineChannel)->GetSamplerChannel()->Index())); |
2902 |
|
} |
2903 |
|
} |
2904 |
|
} |
2905 |
|
} |
2906 |
|
|
2907 |
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2908 |
for (int i = 0; i < pDevice->SendEffectChainCount(); i++) { |
for (int i = 0; i < pDevice->SendEffectChainCount(); i++) { |
2909 |
EffectChain* pEffectChain = pDevice->SendEffectChain(i); |
EffectChain* pEffectChain = pDevice->SendEffectChain(i); |
2910 |
if (pEffectChain->ID() == iSendEffectChain) { |
if (pEffectChain->ID() == iSendEffectChain) { |
2911 |
pDevice->RemoveSendEffectChain(i); |
pDevice->RemoveSendEffectChain(i); |
2912 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_count, iAudioOutputDevice, pDevice->SendEffectChainCount())); |
2913 |
return result.Produce(); |
return result.Produce(); |
2914 |
} |
} |
2915 |
} |
} |
2932 |
ToString(iAudioOutputDevice) + "." |
ToString(iAudioOutputDevice) + "." |
2933 |
); |
); |
2934 |
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
AudioOutputDevice* pDevice = devices[iAudioOutputDevice]; |
2935 |
for (int i = 0; i < pDevice->SendEffectChainCount(); i++) { |
EffectChain* pEffectChain = pDevice->SendEffectChainByID(iSendEffectChain); |
2936 |
EffectChain* pEffectChain = pDevice->SendEffectChain(i); |
if(pEffectChain != NULL) return pEffectChain; |
|
if (pEffectChain->ID() == iSendEffectChain) { |
|
|
return pEffectChain; |
|
|
} |
|
|
} |
|
2937 |
throw Exception( |
throw Exception( |
2938 |
"There is no send effect chain with ID " + |
"There is no send effect chain with ID " + |
2939 |
ToString(iSendEffectChain) + " for audio output device " + |
ToString(iSendEffectChain) + " for audio output device " + |
2970 |
if (!pEffect) |
if (!pEffect) |
2971 |
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
throw Exception("There is no effect instance with ID " + ToString(iEffectInstance)); |
2972 |
pEffectChain->AppendEffect(pEffect); |
pEffectChain->AppendEffect(pEffect); |
2973 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount())); |
2974 |
} catch (Exception e) { |
} catch (Exception e) { |
2975 |
result.Error(e); |
result.Error(e); |
2976 |
} |
} |
2987 |
if (!pEffect) |
if (!pEffect) |
2988 |
throw Exception("There is no effect instance with index " + ToString(iEffectInstance)); |
throw Exception("There is no effect instance with index " + ToString(iEffectInstance)); |
2989 |
pEffectChain->InsertEffect(pEffect, iEffectChainPosition); |
pEffectChain->InsertEffect(pEffect, iEffectChainPosition); |
2990 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount())); |
2991 |
} catch (Exception e) { |
} catch (Exception e) { |
2992 |
result.Error(e); |
result.Error(e); |
2993 |
} |
} |
3000 |
try { |
try { |
3001 |
EffectChain* pEffectChain = |
EffectChain* pEffectChain = |
3002 |
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
_getSendEffectChain(pSampler, iAudioOutputDevice, iSendEffectChain); |
3003 |
|
|
3004 |
|
std::set<EngineChannel*> engineChannels = EngineChannelFactory::EngineChannelInstances(); |
3005 |
|
std::set<EngineChannel*>::iterator itEngineChannel = engineChannels.begin(); |
3006 |
|
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
3007 |
|
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
3008 |
|
AudioOutputDevice* pDev = (*itEngineChannel)->GetAudioOutputDevice(); |
3009 |
|
if (pDev != NULL && pDev->deviceId() == iAudioOutputDevice) { |
3010 |
|
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
3011 |
|
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
3012 |
|
if(fxs != NULL && fxs->DestinationEffectChain() == iSendEffectChain && fxs->DestinationEffectChainPosition() == iEffectChainPosition) { |
3013 |
|
throw Exception("The effect instance is still in use by channel " + ToString((*itEngineChannel)->GetSamplerChannel()->Index())); |
3014 |
|
} |
3015 |
|
} |
3016 |
|
} |
3017 |
|
} |
3018 |
|
|
3019 |
pEffectChain->RemoveEffect(iEffectChainPosition); |
pEffectChain->RemoveEffect(iEffectChainPosition); |
3020 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_send_fx_chain_info, iAudioOutputDevice, iSendEffectChain, pEffectChain->EffectCount())); |
3021 |
} catch (Exception e) { |
} catch (Exception e) { |
3022 |
result.Error(e); |
result.Error(e); |
3023 |
} |
} |
3158 |
String LSCPServer::GetTotalVoiceCountMax() { |
String LSCPServer::GetTotalVoiceCountMax() { |
3159 |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
3160 |
LSCPResultSet result; |
LSCPResultSet result; |
3161 |
result.Add(EngineFactory::EngineInstances().size() * GLOBAL_MAX_VOICES); |
result.Add(EngineFactory::EngineInstances().size() * pSampler->GetGlobalMaxVoices()); |
3162 |
return result.Produce(); |
return result.Produce(); |
3163 |
} |
} |
3164 |
|
|
3169 |
String LSCPServer::GetGlobalMaxVoices() { |
String LSCPServer::GetGlobalMaxVoices() { |
3170 |
dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n")); |
dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n")); |
3171 |
LSCPResultSet result; |
LSCPResultSet result; |
3172 |
result.Add(GLOBAL_MAX_VOICES); |
result.Add(pSampler->GetGlobalMaxVoices()); |
3173 |
return result.Produce(); |
return result.Produce(); |
3174 |
} |
} |
3175 |
|
|
3181 |
dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices)); |
dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices)); |
3182 |
LSCPResultSet result; |
LSCPResultSet result; |
3183 |
try { |
try { |
3184 |
if (iVoices < 1) throw Exception("Maximum voices may not be less than 1"); |
pSampler->SetGlobalMaxVoices(iVoices); |
3185 |
GLOBAL_MAX_VOICES = iVoices; // see common/global_private.cpp |
LSCPServer::SendLSCPNotify( |
3186 |
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
LSCPEvent(LSCPEvent::event_global_info, "VOICES", pSampler->GetGlobalMaxVoices()) |
3187 |
if (engines.size() > 0) { |
); |
|
std::set<Engine*>::iterator iter = engines.begin(); |
|
|
std::set<Engine*>::iterator end = engines.end(); |
|
|
for (; iter != end; ++iter) { |
|
|
(*iter)->SetMaxVoices(iVoices); |
|
|
} |
|
|
} |
|
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOICES", GLOBAL_MAX_VOICES)); |
|
3188 |
} catch (Exception e) { |
} catch (Exception e) { |
3189 |
result.Error(e); |
result.Error(e); |
3190 |
} |
} |
3198 |
String LSCPServer::GetGlobalMaxStreams() { |
String LSCPServer::GetGlobalMaxStreams() { |
3199 |
dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n")); |
dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n")); |
3200 |
LSCPResultSet result; |
LSCPResultSet result; |
3201 |
result.Add(GLOBAL_MAX_STREAMS); |
result.Add(pSampler->GetGlobalMaxStreams()); |
3202 |
return result.Produce(); |
return result.Produce(); |
3203 |
} |
} |
3204 |
|
|
3210 |
dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams)); |
dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams)); |
3211 |
LSCPResultSet result; |
LSCPResultSet result; |
3212 |
try { |
try { |
3213 |
if (iStreams < 0) throw Exception("Maximum disk streams may not be negative"); |
pSampler->SetGlobalMaxStreams(iStreams); |
3214 |
GLOBAL_MAX_STREAMS = iStreams; // see common/global_private.cpp |
LSCPServer::SendLSCPNotify( |
3215 |
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
LSCPEvent(LSCPEvent::event_global_info, "STREAMS", pSampler->GetGlobalMaxStreams()) |
3216 |
if (engines.size() > 0) { |
); |
|
std::set<Engine*>::iterator iter = engines.begin(); |
|
|
std::set<Engine*>::iterator end = engines.end(); |
|
|
for (; iter != end; ++iter) { |
|
|
(*iter)->SetMaxDiskStreams(iStreams); |
|
|
} |
|
|
} |
|
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "STREAMS", GLOBAL_MAX_STREAMS)); |
|
3217 |
} catch (Exception e) { |
} catch (Exception e) { |
3218 |
result.Error(e); |
result.Error(e); |
3219 |
} |
} |
3417 |
String LSCPServer::SubscribeNotification(LSCPEvent::event_t type) { |
String LSCPServer::SubscribeNotification(LSCPEvent::event_t type) { |
3418 |
dmsg(2,("LSCPServer: SubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
dmsg(2,("LSCPServer: SubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
3419 |
LSCPResultSet result; |
LSCPResultSet result; |
3420 |
SubscriptionMutex.Lock(); |
{ |
3421 |
eventSubscriptions[type].push_back(currentSocket); |
LockGuard lock(SubscriptionMutex); |
3422 |
SubscriptionMutex.Unlock(); |
eventSubscriptions[type].push_back(currentSocket); |
3423 |
|
} |
3424 |
return result.Produce(); |
return result.Produce(); |
3425 |
} |
} |
3426 |
|
|
3431 |
String LSCPServer::UnsubscribeNotification(LSCPEvent::event_t type) { |
String LSCPServer::UnsubscribeNotification(LSCPEvent::event_t type) { |
3432 |
dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
dmsg(2,("LSCPServer: UnsubscribeNotification(Event=%s)\n", LSCPEvent::Name(type).c_str())); |
3433 |
LSCPResultSet result; |
LSCPResultSet result; |
3434 |
SubscriptionMutex.Lock(); |
{ |
3435 |
eventSubscriptions[type].remove(currentSocket); |
LockGuard lock(SubscriptionMutex); |
3436 |
SubscriptionMutex.Unlock(); |
eventSubscriptions[type].remove(currentSocket); |
3437 |
|
} |
3438 |
return result.Produce(); |
return result.Produce(); |
3439 |
} |
} |
3440 |
|
|