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 - 2009 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This library is free software; you can redistribute it and/or modify * |
* This library is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
21 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
***************************************************************************/ |
23 |
|
|
24 |
|
#include <algorithm> |
25 |
|
#include <string> |
26 |
|
|
27 |
|
#include "../common/File.h" |
28 |
#include "lscpserver.h" |
#include "lscpserver.h" |
29 |
#include "lscpresultset.h" |
#include "lscpresultset.h" |
30 |
#include "lscpevent.h" |
#include "lscpevent.h" |
44 |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
45 |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
46 |
|
|
47 |
|
namespace LinuxSampler { |
48 |
|
|
49 |
/** |
/** |
50 |
* Returns a copy of the given string where all special characters are |
* Returns a copy of the given string where all special characters are |
141 |
} |
} |
142 |
|
|
143 |
LSCPServer::~LSCPServer() { |
LSCPServer::~LSCPServer() { |
144 |
|
CloseAllConnections(); |
145 |
|
InstrumentManager::StopBackgroundThread(); |
146 |
#if defined(WIN32) |
#if defined(WIN32) |
147 |
if (hSocket >= 0) closesocket(hSocket); |
if (hSocket >= 0) closesocket(hSocket); |
148 |
#else |
#else |
337 |
} |
} |
338 |
#endif // HAVE_SQLITE3 |
#endif // HAVE_SQLITE3 |
339 |
|
|
340 |
|
void LSCPServer::RemoveListeners() { |
341 |
|
pSampler->RemoveChannelCountListener(&eventHandler); |
342 |
|
pSampler->RemoveAudioDeviceCountListener(&eventHandler); |
343 |
|
pSampler->RemoveMidiDeviceCountListener(&eventHandler); |
344 |
|
pSampler->RemoveVoiceCountListener(&eventHandler); |
345 |
|
pSampler->RemoveStreamCountListener(&eventHandler); |
346 |
|
pSampler->RemoveBufferFillListener(&eventHandler); |
347 |
|
pSampler->RemoveTotalStreamCountListener(&eventHandler); |
348 |
|
pSampler->RemoveTotalVoiceCountListener(&eventHandler); |
349 |
|
pSampler->RemoveFxSendCountListener(&eventHandler); |
350 |
|
MidiInstrumentMapper::RemoveMidiInstrumentCountListener(&eventHandler); |
351 |
|
MidiInstrumentMapper::RemoveMidiInstrumentInfoListener(&eventHandler); |
352 |
|
MidiInstrumentMapper::RemoveMidiInstrumentMapCountListener(&eventHandler); |
353 |
|
MidiInstrumentMapper::RemoveMidiInstrumentMapInfoListener(&eventHandler); |
354 |
|
#if HAVE_SQLITE3 |
355 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveInstrumentsDbListener(&dbInstrumentsEventHandler); |
356 |
|
#endif |
357 |
|
} |
358 |
|
|
359 |
/** |
/** |
360 |
* Blocks the calling thread until the LSCP Server is initialized and |
* Blocks the calling thread until the LSCP Server is initialized and |
447 |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
448 |
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
449 |
if ((*itEngineChannel)->StatusChanged()) { |
if ((*itEngineChannel)->StatusChanged()) { |
450 |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->GetSamplerChannel()->Index())); |
451 |
} |
} |
452 |
|
|
453 |
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
454 |
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
455 |
if(fxs != NULL && fxs->IsInfoChanged()) { |
if(fxs != NULL && fxs->IsInfoChanged()) { |
456 |
int chn = (*itEngineChannel)->iSamplerChannelIndex; |
int chn = (*itEngineChannel)->GetSamplerChannel()->Index(); |
457 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id())); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id())); |
458 |
fxs->SetInfoChanged(false); |
fxs->SetInfoChanged(false); |
459 |
} |
} |
528 |
|
|
529 |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
530 |
|
|
531 |
if (retval == 0) |
if (retval == 0 || (retval == -1 && errno == EINTR)) |
532 |
continue; //Nothing try again |
continue; //Nothing try again |
533 |
if (retval == -1) { |
if (retval == -1) { |
534 |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
626 |
NotifyMutex.Unlock(); |
NotifyMutex.Unlock(); |
627 |
} |
} |
628 |
|
|
629 |
|
void LSCPServer::CloseAllConnections() { |
630 |
|
std::vector<yyparse_param_t>::iterator iter = Sessions.begin(); |
631 |
|
while(iter != Sessions.end()) { |
632 |
|
CloseConnection(iter); |
633 |
|
iter = Sessions.begin(); |
634 |
|
} |
635 |
|
} |
636 |
|
|
637 |
void LSCPServer::LockRTNotify() { |
void LSCPServer::LockRTNotify() { |
638 |
RTNotifyMutex.Lock(); |
RTNotifyMutex.Lock(); |
639 |
} |
} |
1164 |
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
1165 |
LSCPResultSet result; |
LSCPResultSet result; |
1166 |
try { |
try { |
1167 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine loaded on sampler channel"); |
|
1168 |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
1169 |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
1170 |
} |
} |
1182 |
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
1183 |
LSCPResultSet result; |
LSCPResultSet result; |
1184 |
try { |
try { |
1185 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
1186 |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
1187 |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
1188 |
} |
} |
1200 |
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); |
1201 |
LSCPResultSet result; |
LSCPResultSet result; |
1202 |
try { |
try { |
1203 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
1204 |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
if (!pEngineChannel->GetEngine()) throw Exception("No audio output device connected to sampler channel"); |
1205 |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
1206 |
else { |
else { |
1288 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1289 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1290 |
s += iter->first; |
s += iter->first; |
1291 |
|
delete iter->second; |
1292 |
} |
} |
1293 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1294 |
} |
} |
1313 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1314 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1315 |
s += iter->first; |
s += iter->first; |
1316 |
|
delete iter->second; |
1317 |
} |
} |
1318 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1319 |
} |
} |
1344 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1345 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1346 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1347 |
|
delete pParameter; |
1348 |
} |
} |
1349 |
catch (Exception e) { |
catch (Exception e) { |
1350 |
result.Error(e); |
result.Error(e); |
1372 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1373 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1374 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1375 |
|
delete pParameter; |
1376 |
} |
} |
1377 |
catch (Exception e) { |
catch (Exception e) { |
1378 |
result.Error(e); |
result.Error(e); |
1882 |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
1883 |
LSCPResultSet result; |
LSCPResultSet result; |
1884 |
try { |
try { |
1885 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
1886 |
pEngineChannel->Volume(dVolume); |
pEngineChannel->Volume(dVolume); |
1887 |
} |
} |
1888 |
catch (Exception e) { |
catch (Exception e) { |
1898 |
dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); |
1899 |
LSCPResultSet result; |
LSCPResultSet result; |
1900 |
try { |
try { |
1901 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
|
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
1902 |
|
|
1903 |
if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); |
if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); |
1904 |
else pEngineChannel->SetMute(1); |
else pEngineChannel->SetMute(1); |
1915 |
dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel)); |
1916 |
LSCPResultSet result; |
LSCPResultSet result; |
1917 |
try { |
try { |
1918 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
|
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
1919 |
|
|
1920 |
bool oldSolo = pEngineChannel->GetSolo(); |
bool oldSolo = pEngineChannel->GetSolo(); |
1921 |
bool hadSoloChannel = HasSoloChannel(); |
bool hadSoloChannel = HasSoloChannel(); |
2035 |
dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n")); |
dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n")); |
2036 |
LSCPResultSet result; |
LSCPResultSet result; |
2037 |
try { |
try { |
2038 |
result.Add(MidiInstrumentMapper::Entries(MidiMapID).size()); |
result.Add(MidiInstrumentMapper::GetInstrumentCount(MidiMapID)); |
2039 |
} catch (Exception e) { |
} catch (Exception e) { |
2040 |
result.Error(e); |
result.Error(e); |
2041 |
} |
} |
2046 |
String LSCPServer::GetAllMidiInstrumentMappings() { |
String LSCPServer::GetAllMidiInstrumentMappings() { |
2047 |
dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n")); |
dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n")); |
2048 |
LSCPResultSet result; |
LSCPResultSet result; |
2049 |
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
try { |
2050 |
int totalMappings = 0; |
result.Add(MidiInstrumentMapper::GetInstrumentCount()); |
2051 |
for (int i = 0; i < maps.size(); i++) { |
} catch (Exception e) { |
2052 |
try { |
result.Error(e); |
|
totalMappings += MidiInstrumentMapper::Entries(maps[i]).size(); |
|
|
} catch (Exception e) { /*NOOP*/ } |
|
2053 |
} |
} |
|
result.Add(totalMappings); |
|
2054 |
return result.Produce(); |
return result.Produce(); |
2055 |
} |
} |
2056 |
|
|
2058 |
dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n")); |
dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n")); |
2059 |
LSCPResultSet result; |
LSCPResultSet result; |
2060 |
try { |
try { |
2061 |
midi_prog_index_t idx; |
MidiInstrumentMapper::entry_t entry = MidiInstrumentMapper::GetEntry(MidiMapID, MidiBank, MidiProg); |
2062 |
idx.midi_bank_msb = (MidiBank >> 7) & 0x7f; |
// convert the filename into the correct encoding as defined for LSCP |
2063 |
idx.midi_bank_lsb = MidiBank & 0x7f; |
// (especially in terms of special characters -> escape sequences) |
|
idx.midi_prog = MidiProg; |
|
|
|
|
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t> mappings = MidiInstrumentMapper::Entries(MidiMapID); |
|
|
std::map<midi_prog_index_t,MidiInstrumentMapper::entry_t>::iterator iter = mappings.find(idx); |
|
|
if (iter == mappings.end()) result.Error("there is no map entry with that index"); |
|
|
else { // found |
|
|
|
|
|
// convert the filename into the correct encoding as defined for LSCP |
|
|
// (especially in terms of special characters -> escape sequences) |
|
2064 |
#if WIN32 |
#if WIN32 |
2065 |
const String instrumentFileName = Path::fromWindows(iter->second.InstrumentFile).toLscp(); |
const String instrumentFileName = Path::fromWindows(entry.InstrumentFile).toLscp(); |
2066 |
#else |
#else |
2067 |
// assuming POSIX |
// assuming POSIX |
2068 |
const String instrumentFileName = Path::fromPosix(iter->second.InstrumentFile).toLscp(); |
const String instrumentFileName = Path::fromPosix(entry.InstrumentFile).toLscp(); |
2069 |
#endif |
#endif |
2070 |
|
|
2071 |
result.Add("NAME", _escapeLscpResponse(iter->second.Name)); |
result.Add("NAME", _escapeLscpResponse(entry.Name)); |
2072 |
result.Add("ENGINE_NAME", iter->second.EngineName); |
result.Add("ENGINE_NAME", entry.EngineName); |
2073 |
result.Add("INSTRUMENT_FILE", instrumentFileName); |
result.Add("INSTRUMENT_FILE", instrumentFileName); |
2074 |
result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex); |
result.Add("INSTRUMENT_NR", (int) entry.InstrumentIndex); |
2075 |
String instrumentName; |
String instrumentName; |
2076 |
Engine* pEngine = EngineFactory::Create(iter->second.EngineName); |
Engine* pEngine = EngineFactory::Create(entry.EngineName); |
2077 |
if (pEngine) { |
if (pEngine) { |
2078 |
if (pEngine->GetInstrumentManager()) { |
if (pEngine->GetInstrumentManager()) { |
2079 |
InstrumentManager::instrument_id_t instrID; |
InstrumentManager::instrument_id_t instrID; |
2080 |
instrID.FileName = iter->second.InstrumentFile; |
instrID.FileName = entry.InstrumentFile; |
2081 |
instrID.Index = iter->second.InstrumentIndex; |
instrID.Index = entry.InstrumentIndex; |
2082 |
instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID); |
instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID); |
|
} |
|
|
EngineFactory::Destroy(pEngine); |
|
2083 |
} |
} |
2084 |
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName)); |
EngineFactory::Destroy(pEngine); |
|
switch (iter->second.LoadMode) { |
|
|
case MidiInstrumentMapper::ON_DEMAND: |
|
|
result.Add("LOAD_MODE", "ON_DEMAND"); |
|
|
break; |
|
|
case MidiInstrumentMapper::ON_DEMAND_HOLD: |
|
|
result.Add("LOAD_MODE", "ON_DEMAND_HOLD"); |
|
|
break; |
|
|
case MidiInstrumentMapper::PERSISTENT: |
|
|
result.Add("LOAD_MODE", "PERSISTENT"); |
|
|
break; |
|
|
default: |
|
|
throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!"); |
|
|
} |
|
|
result.Add("VOLUME", iter->second.Volume); |
|
2085 |
} |
} |
2086 |
|
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName)); |
2087 |
|
switch (entry.LoadMode) { |
2088 |
|
case MidiInstrumentMapper::ON_DEMAND: |
2089 |
|
result.Add("LOAD_MODE", "ON_DEMAND"); |
2090 |
|
break; |
2091 |
|
case MidiInstrumentMapper::ON_DEMAND_HOLD: |
2092 |
|
result.Add("LOAD_MODE", "ON_DEMAND_HOLD"); |
2093 |
|
break; |
2094 |
|
case MidiInstrumentMapper::PERSISTENT: |
2095 |
|
result.Add("LOAD_MODE", "PERSISTENT"); |
2096 |
|
break; |
2097 |
|
default: |
2098 |
|
throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!"); |
2099 |
|
} |
2100 |
|
result.Add("VOLUME", entry.Volume); |
2101 |
} catch (Exception e) { |
} catch (Exception e) { |
2102 |
result.Error(e); |
result.Error(e); |
2103 |
} |
} |
2268 |
dmsg(2,("LSCPServer: SetChannelMap()\n")); |
dmsg(2,("LSCPServer: SetChannelMap()\n")); |
2269 |
LSCPResultSet result; |
LSCPResultSet result; |
2270 |
try { |
try { |
2271 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
|
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); |
|
2272 |
|
|
2273 |
if (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone(); |
if (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone(); |
2274 |
else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault(); |
else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault(); |
2447 |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
2448 |
LSCPResultSet result; |
LSCPResultSet result; |
2449 |
try { |
try { |
2450 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
2451 |
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
2452 |
Engine* pEngine = pEngineChannel->GetEngine(); |
Engine* pEngine = pEngineChannel->GetEngine(); |
2453 |
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
2462 |
return result.Produce(); |
return result.Produce(); |
2463 |
} |
} |
2464 |
|
|
2465 |
|
String LSCPServer::SendChannelMidiData(String MidiMsg, uint uiSamplerChannel, uint Arg1, uint Arg2) { |
2466 |
|
dmsg(2,("LSCPServer: SendChannelMidiData(MidiMsg=%s,uiSamplerChannel=%d,Arg1=%d,Arg2=%d)\n", MidiMsg.c_str(), uiSamplerChannel, Arg1, Arg2)); |
2467 |
|
LSCPResultSet result; |
2468 |
|
try { |
2469 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2470 |
|
|
2471 |
|
if (Arg1 > 127 || Arg2 > 127) { |
2472 |
|
throw Exception("Invalid MIDI message"); |
2473 |
|
} |
2474 |
|
|
2475 |
|
VirtualMidiDevice* pMidiDevice = NULL; |
2476 |
|
std::vector<EventHandler::midi_listener_entry>::iterator iter = eventHandler.channelMidiListeners.begin(); |
2477 |
|
for (; iter != eventHandler.channelMidiListeners.end(); ++iter) { |
2478 |
|
if ((*iter).pEngineChannel == pEngineChannel) { |
2479 |
|
pMidiDevice = (*iter).pMidiListener; |
2480 |
|
break; |
2481 |
|
} |
2482 |
|
} |
2483 |
|
|
2484 |
|
if(pMidiDevice == NULL) throw Exception("Couldn't find virtual MIDI device"); |
2485 |
|
|
2486 |
|
if (MidiMsg == "NOTE_ON") { |
2487 |
|
pMidiDevice->SendNoteOnToDevice(Arg1, Arg2); |
2488 |
|
bool b = pMidiDevice->SendNoteOnToSampler(Arg1, Arg2); |
2489 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2490 |
|
} else if (MidiMsg == "NOTE_OFF") { |
2491 |
|
pMidiDevice->SendNoteOffToDevice(Arg1, Arg2); |
2492 |
|
bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2); |
2493 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2494 |
|
} else { |
2495 |
|
throw Exception("Unknown MIDI message type: " + MidiMsg); |
2496 |
|
} |
2497 |
|
} catch (Exception e) { |
2498 |
|
result.Error(e); |
2499 |
|
} |
2500 |
|
return result.Produce(); |
2501 |
|
} |
2502 |
|
|
2503 |
/** |
/** |
2504 |
* Will be called by the parser to reset a particular sampler channel. |
* Will be called by the parser to reset a particular sampler channel. |
2505 |
*/ |
*/ |
2507 |
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
2508 |
LSCPResultSet result; |
LSCPResultSet result; |
2509 |
try { |
try { |
2510 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("No engine type assigned to sampler channel"); |
|
2511 |
pEngineChannel->Reset(); |
pEngineChannel->Reset(); |
2512 |
} |
} |
2513 |
catch (Exception e) { |
catch (Exception e) { |
2573 |
String LSCPServer::GetTotalVoiceCountMax() { |
String LSCPServer::GetTotalVoiceCountMax() { |
2574 |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
2575 |
LSCPResultSet result; |
LSCPResultSet result; |
2576 |
result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES); |
result.Add(EngineFactory::EngineInstances().size() * GLOBAL_MAX_VOICES); |
2577 |
|
return result.Produce(); |
2578 |
|
} |
2579 |
|
|
2580 |
|
/** |
2581 |
|
* Will be called by the parser to return the sampler global maximum |
2582 |
|
* allowed number of voices. |
2583 |
|
*/ |
2584 |
|
String LSCPServer::GetGlobalMaxVoices() { |
2585 |
|
dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n")); |
2586 |
|
LSCPResultSet result; |
2587 |
|
result.Add(GLOBAL_MAX_VOICES); |
2588 |
|
return result.Produce(); |
2589 |
|
} |
2590 |
|
|
2591 |
|
/** |
2592 |
|
* Will be called by the parser to set the sampler global maximum number of |
2593 |
|
* voices. |
2594 |
|
*/ |
2595 |
|
String LSCPServer::SetGlobalMaxVoices(int iVoices) { |
2596 |
|
dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices)); |
2597 |
|
LSCPResultSet result; |
2598 |
|
try { |
2599 |
|
if (iVoices < 1) throw Exception("Maximum voices may not be less than 1"); |
2600 |
|
GLOBAL_MAX_VOICES = iVoices; // see common/global_private.cpp |
2601 |
|
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
2602 |
|
if (engines.size() > 0) { |
2603 |
|
std::set<Engine*>::iterator iter = engines.begin(); |
2604 |
|
std::set<Engine*>::iterator end = engines.end(); |
2605 |
|
for (; iter != end; ++iter) { |
2606 |
|
(*iter)->SetMaxVoices(iVoices); |
2607 |
|
} |
2608 |
|
} |
2609 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOICES", GLOBAL_MAX_VOICES)); |
2610 |
|
} catch (Exception e) { |
2611 |
|
result.Error(e); |
2612 |
|
} |
2613 |
|
return result.Produce(); |
2614 |
|
} |
2615 |
|
|
2616 |
|
/** |
2617 |
|
* Will be called by the parser to return the sampler global maximum |
2618 |
|
* allowed number of disk streams. |
2619 |
|
*/ |
2620 |
|
String LSCPServer::GetGlobalMaxStreams() { |
2621 |
|
dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n")); |
2622 |
|
LSCPResultSet result; |
2623 |
|
result.Add(GLOBAL_MAX_STREAMS); |
2624 |
|
return result.Produce(); |
2625 |
|
} |
2626 |
|
|
2627 |
|
/** |
2628 |
|
* Will be called by the parser to set the sampler global maximum number of |
2629 |
|
* disk streams. |
2630 |
|
*/ |
2631 |
|
String LSCPServer::SetGlobalMaxStreams(int iStreams) { |
2632 |
|
dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams)); |
2633 |
|
LSCPResultSet result; |
2634 |
|
try { |
2635 |
|
if (iStreams < 0) throw Exception("Maximum disk streams may not be negative"); |
2636 |
|
GLOBAL_MAX_STREAMS = iStreams; // see common/global_private.cpp |
2637 |
|
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
2638 |
|
if (engines.size() > 0) { |
2639 |
|
std::set<Engine*>::iterator iter = engines.begin(); |
2640 |
|
std::set<Engine*>::iterator end = engines.end(); |
2641 |
|
for (; iter != end; ++iter) { |
2642 |
|
(*iter)->SetMaxDiskStreams(iStreams); |
2643 |
|
} |
2644 |
|
} |
2645 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "STREAMS", GLOBAL_MAX_STREAMS)); |
2646 |
|
} catch (Exception e) { |
2647 |
|
result.Error(e); |
2648 |
|
} |
2649 |
return result.Produce(); |
return result.Produce(); |
2650 |
} |
} |
2651 |
|
|
2659 |
LSCPResultSet result; |
LSCPResultSet result; |
2660 |
try { |
try { |
2661 |
if (dVolume < 0) throw Exception("Volume may not be negative"); |
if (dVolume < 0) throw Exception("Volume may not be negative"); |
2662 |
GLOBAL_VOLUME = dVolume; // see common/global.cpp |
GLOBAL_VOLUME = dVolume; // see common/global_private.cpp |
2663 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME)); |
2664 |
} catch (Exception e) { |
} catch (Exception e) { |
2665 |
result.Error(e); |
result.Error(e); |
2786 |
result.Add("FORMAT_VERSION", info.FormatVersion); |
result.Add("FORMAT_VERSION", info.FormatVersion); |
2787 |
result.Add("PRODUCT", info.Product); |
result.Add("PRODUCT", info.Product); |
2788 |
result.Add("ARTISTS", info.Artists); |
result.Add("ARTISTS", info.Artists); |
2789 |
|
|
2790 |
|
std::stringstream ss; |
2791 |
|
bool b = false; |
2792 |
|
for (int i = 0; i < 128; i++) { |
2793 |
|
if (info.KeyBindings[i]) { |
2794 |
|
if (b) ss << ','; |
2795 |
|
ss << i; b = true; |
2796 |
|
} |
2797 |
|
} |
2798 |
|
result.Add("KEY_BINDINGS", ss.str()); |
2799 |
|
|
2800 |
|
b = false; |
2801 |
|
std::stringstream ss2; |
2802 |
|
for (int i = 0; i < 128; i++) { |
2803 |
|
if (info.KeySwitchBindings[i]) { |
2804 |
|
if (b) ss2 << ','; |
2805 |
|
ss2 << i; b = true; |
2806 |
|
} |
2807 |
|
} |
2808 |
|
result.Add("KEYSWITCH_BINDINGS", ss2.str()); |
2809 |
// no more need to ask other engine types |
// no more need to ask other engine types |
2810 |
bFound = true; |
bFound = true; |
2811 |
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
} else dmsg(1,("Warning: engine '%s' does not provide an instrument manager\n", engineTypes[i].c_str())); |
2833 |
throw Exception("Directory is specified"); |
throw Exception("Directory is specified"); |
2834 |
} |
} |
2835 |
#else |
#else |
2836 |
struct stat statBuf; |
File f(Filename); |
2837 |
int res = stat(Filename.c_str(), &statBuf); |
if(!f.Exist()) throw Exception(f.GetErrorMsg()); |
2838 |
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"); |
|
|
} |
|
2839 |
#endif |
#endif |
2840 |
} |
} |
2841 |
|
|
3030 |
return result.Produce(); |
return result.Produce(); |
3031 |
} |
} |
3032 |
|
|
3033 |
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) { |
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground, bool insDir) { |
3034 |
dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground)); |
dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d,insDir=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground, insDir)); |
3035 |
LSCPResultSet result; |
LSCPResultSet result; |
3036 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
3037 |
try { |
try { |
3038 |
int id; |
int id; |
3039 |
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
3040 |
if (ScanMode.compare("RECURSIVE") == 0) { |
if (ScanMode.compare("RECURSIVE") == 0) { |
3041 |
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground); |
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground, insDir); |
3042 |
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
3043 |
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground); |
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground, insDir); |
3044 |
} else if (ScanMode.compare("FLAT") == 0) { |
} else if (ScanMode.compare("FLAT") == 0) { |
3045 |
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground); |
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground, insDir); |
3046 |
} else { |
} else { |
3047 |
throw Exception("Unknown scan mode: " + ScanMode); |
throw Exception("Unknown scan mode: " + ScanMode); |
3048 |
} |
} |
3218 |
return result.Produce(); |
return result.Produce(); |
3219 |
} |
} |
3220 |
|
|
3221 |
|
String LSCPServer::SetDbInstrumentFilePath(String OldPath, String NewPath) { |
3222 |
|
dmsg(2,("LSCPServer: SetDbInstrumentFilePath(OldPath=%s,NewPath=%s)\n", OldPath.c_str(), NewPath.c_str())); |
3223 |
|
LSCPResultSet result; |
3224 |
|
#if HAVE_SQLITE3 |
3225 |
|
try { |
3226 |
|
InstrumentsDb::GetInstrumentsDb()->SetInstrumentFilePath(OldPath, NewPath); |
3227 |
|
} catch (Exception e) { |
3228 |
|
result.Error(e); |
3229 |
|
} |
3230 |
|
#else |
3231 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3232 |
|
#endif |
3233 |
|
return result.Produce(); |
3234 |
|
} |
3235 |
|
|
3236 |
|
String LSCPServer::FindLostDbInstrumentFiles() { |
3237 |
|
dmsg(2,("LSCPServer: FindLostDbInstrumentFiles()\n")); |
3238 |
|
LSCPResultSet result; |
3239 |
|
#if HAVE_SQLITE3 |
3240 |
|
try { |
3241 |
|
String list; |
3242 |
|
StringListPtr pLostFiles = InstrumentsDb::GetInstrumentsDb()->FindLostInstrumentFiles(); |
3243 |
|
|
3244 |
|
for (int i = 0; i < pLostFiles->size(); i++) { |
3245 |
|
if (list != "") list += ","; |
3246 |
|
list += "'" + pLostFiles->at(i) + "'"; |
3247 |
|
} |
3248 |
|
|
3249 |
|
result.Add(list); |
3250 |
|
} catch (Exception e) { |
3251 |
|
result.Error(e); |
3252 |
|
} |
3253 |
|
#else |
3254 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3255 |
|
#endif |
3256 |
|
return result.Produce(); |
3257 |
|
} |
3258 |
|
|
3259 |
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
3260 |
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
3261 |
LSCPResultSet result; |
LSCPResultSet result; |
3386 |
} |
} |
3387 |
return result.Produce(); |
return result.Produce(); |
3388 |
} |
} |
3389 |
|
|
3390 |
|
} |