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 |
335 |
} |
} |
336 |
#endif // HAVE_SQLITE3 |
#endif // HAVE_SQLITE3 |
337 |
|
|
338 |
|
void LSCPServer::RemoveListeners() { |
339 |
|
pSampler->RemoveChannelCountListener(&eventHandler); |
340 |
|
pSampler->RemoveAudioDeviceCountListener(&eventHandler); |
341 |
|
pSampler->RemoveMidiDeviceCountListener(&eventHandler); |
342 |
|
pSampler->RemoveVoiceCountListener(&eventHandler); |
343 |
|
pSampler->RemoveStreamCountListener(&eventHandler); |
344 |
|
pSampler->RemoveBufferFillListener(&eventHandler); |
345 |
|
pSampler->RemoveTotalStreamCountListener(&eventHandler); |
346 |
|
pSampler->RemoveTotalVoiceCountListener(&eventHandler); |
347 |
|
pSampler->RemoveFxSendCountListener(&eventHandler); |
348 |
|
MidiInstrumentMapper::RemoveMidiInstrumentCountListener(&eventHandler); |
349 |
|
MidiInstrumentMapper::RemoveMidiInstrumentInfoListener(&eventHandler); |
350 |
|
MidiInstrumentMapper::RemoveMidiInstrumentMapCountListener(&eventHandler); |
351 |
|
MidiInstrumentMapper::RemoveMidiInstrumentMapInfoListener(&eventHandler); |
352 |
|
#if HAVE_SQLITE3 |
353 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveInstrumentsDbListener(&dbInstrumentsEventHandler); |
354 |
|
#endif |
355 |
|
} |
356 |
|
|
357 |
/** |
/** |
358 |
* Blocks the calling thread until the LSCP Server is initialized and |
* Blocks the calling thread until the LSCP Server is initialized and |
445 |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
446 |
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
447 |
if ((*itEngineChannel)->StatusChanged()) { |
if ((*itEngineChannel)->StatusChanged()) { |
448 |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->GetSamplerChannel()->Index())); |
449 |
} |
} |
450 |
|
|
451 |
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
452 |
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
453 |
if(fxs != NULL && fxs->IsInfoChanged()) { |
if(fxs != NULL && fxs->IsInfoChanged()) { |
454 |
int chn = (*itEngineChannel)->iSamplerChannelIndex; |
int chn = (*itEngineChannel)->GetSamplerChannel()->Index(); |
455 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id())); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id())); |
456 |
fxs->SetInfoChanged(false); |
fxs->SetInfoChanged(false); |
457 |
} |
} |
526 |
|
|
527 |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
int retval = select(maxSessions+1, &selectSet, NULL, NULL, &timeout); |
528 |
|
|
529 |
if (retval == 0) |
if (retval == 0 || (retval == -1 && errno == EINTR)) |
530 |
continue; //Nothing try again |
continue; //Nothing try again |
531 |
if (retval == -1) { |
if (retval == -1) { |
532 |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
std::cerr << "LSCPServer: Socket select error." << std::endl; |
1154 |
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetVoiceCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
1155 |
LSCPResultSet result; |
LSCPResultSet result; |
1156 |
try { |
try { |
1157 |
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"); |
|
1158 |
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"); |
1159 |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
result.Add(pEngineChannel->GetEngine()->VoiceCount()); |
1160 |
} |
} |
1172 |
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetStreamCount(SamplerChannel=%d)\n", uiSamplerChannel)); |
1173 |
LSCPResultSet result; |
LSCPResultSet result; |
1174 |
try { |
try { |
1175 |
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"); |
|
1176 |
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"); |
1177 |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
result.Add(pEngineChannel->GetEngine()->DiskStreamCount()); |
1178 |
} |
} |
1190 |
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); |
dmsg(2,("LSCPServer: GetBufferFill(ResponseType=%d, SamplerChannel=%d)\n", ResponseType, uiSamplerChannel)); |
1191 |
LSCPResultSet result; |
LSCPResultSet result; |
1192 |
try { |
try { |
1193 |
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"); |
|
1194 |
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"); |
1195 |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
if (!pEngineChannel->GetEngine()->DiskStreamSupported()) result.Add("NA"); |
1196 |
else { |
else { |
1278 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1279 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1280 |
s += iter->first; |
s += iter->first; |
1281 |
|
delete iter->second; |
1282 |
} |
} |
1283 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1284 |
} |
} |
1303 |
for (;iter != parameters.end(); iter++) { |
for (;iter != parameters.end(); iter++) { |
1304 |
if (s != "") s += ","; |
if (s != "") s += ","; |
1305 |
s += iter->first; |
s += iter->first; |
1306 |
|
delete iter->second; |
1307 |
} |
} |
1308 |
result.Add("PARAMETERS", s); |
result.Add("PARAMETERS", s); |
1309 |
} |
} |
1334 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1335 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1336 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1337 |
|
delete pParameter; |
1338 |
} |
} |
1339 |
catch (Exception e) { |
catch (Exception e) { |
1340 |
result.Error(e); |
result.Error(e); |
1362 |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
if (oRangeMin) result.Add("RANGE_MIN", *oRangeMin); |
1363 |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
if (oRangeMax) result.Add("RANGE_MAX", *oRangeMax); |
1364 |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
if (oPossibilities) result.Add("POSSIBILITIES", *oPossibilities); |
1365 |
|
delete pParameter; |
1366 |
} |
} |
1367 |
catch (Exception e) { |
catch (Exception e) { |
1368 |
result.Error(e); |
result.Error(e); |
1872 |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetVolume(Volume=%f, SamplerChannel=%d)\n", dVolume, uiSamplerChannel)); |
1873 |
LSCPResultSet result; |
LSCPResultSet result; |
1874 |
try { |
try { |
1875 |
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"); |
|
1876 |
pEngineChannel->Volume(dVolume); |
pEngineChannel->Volume(dVolume); |
1877 |
} |
} |
1878 |
catch (Exception e) { |
catch (Exception e) { |
1888 |
dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetChannelMute(bMute=%d,uiSamplerChannel=%d)\n",bMute,uiSamplerChannel)); |
1889 |
LSCPResultSet result; |
LSCPResultSet result; |
1890 |
try { |
try { |
1891 |
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"); |
|
1892 |
|
|
1893 |
if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); |
if(!bMute) pEngineChannel->SetMute((HasSoloChannel() && !pEngineChannel->GetSolo()) ? -1 : 0); |
1894 |
else pEngineChannel->SetMute(1); |
else pEngineChannel->SetMute(1); |
1905 |
dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel)); |
dmsg(2,("LSCPServer: SetChannelSolo(bSolo=%d,uiSamplerChannel=%d)\n",bSolo,uiSamplerChannel)); |
1906 |
LSCPResultSet result; |
LSCPResultSet result; |
1907 |
try { |
try { |
1908 |
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"); |
|
1909 |
|
|
1910 |
bool oldSolo = pEngineChannel->GetSolo(); |
bool oldSolo = pEngineChannel->GetSolo(); |
1911 |
bool hadSoloChannel = HasSoloChannel(); |
bool hadSoloChannel = HasSoloChannel(); |
2025 |
dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n")); |
dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n")); |
2026 |
LSCPResultSet result; |
LSCPResultSet result; |
2027 |
try { |
try { |
2028 |
result.Add(MidiInstrumentMapper::Entries(MidiMapID).size()); |
result.Add(MidiInstrumentMapper::GetInstrumentCount(MidiMapID)); |
2029 |
} catch (Exception e) { |
} catch (Exception e) { |
2030 |
result.Error(e); |
result.Error(e); |
2031 |
} |
} |
2036 |
String LSCPServer::GetAllMidiInstrumentMappings() { |
String LSCPServer::GetAllMidiInstrumentMappings() { |
2037 |
dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n")); |
dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n")); |
2038 |
LSCPResultSet result; |
LSCPResultSet result; |
2039 |
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
try { |
2040 |
int totalMappings = 0; |
result.Add(MidiInstrumentMapper::GetInstrumentCount()); |
2041 |
for (int i = 0; i < maps.size(); i++) { |
} catch (Exception e) { |
2042 |
try { |
result.Error(e); |
|
totalMappings += MidiInstrumentMapper::Entries(maps[i]).size(); |
|
|
} catch (Exception e) { /*NOOP*/ } |
|
2043 |
} |
} |
|
result.Add(totalMappings); |
|
2044 |
return result.Produce(); |
return result.Produce(); |
2045 |
} |
} |
2046 |
|
|
2048 |
dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n")); |
dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n")); |
2049 |
LSCPResultSet result; |
LSCPResultSet result; |
2050 |
try { |
try { |
2051 |
midi_prog_index_t idx; |
MidiInstrumentMapper::entry_t entry = MidiInstrumentMapper::GetEntry(MidiMapID, MidiBank, MidiProg); |
2052 |
idx.midi_bank_msb = (MidiBank >> 7) & 0x7f; |
// convert the filename into the correct encoding as defined for LSCP |
2053 |
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) |
|
2054 |
#if WIN32 |
#if WIN32 |
2055 |
const String instrumentFileName = Path::fromWindows(iter->second.InstrumentFile).toLscp(); |
const String instrumentFileName = Path::fromWindows(entry.InstrumentFile).toLscp(); |
2056 |
#else |
#else |
2057 |
// assuming POSIX |
// assuming POSIX |
2058 |
const String instrumentFileName = Path::fromPosix(iter->second.InstrumentFile).toLscp(); |
const String instrumentFileName = Path::fromPosix(entry.InstrumentFile).toLscp(); |
2059 |
#endif |
#endif |
2060 |
|
|
2061 |
result.Add("NAME", _escapeLscpResponse(iter->second.Name)); |
result.Add("NAME", _escapeLscpResponse(entry.Name)); |
2062 |
result.Add("ENGINE_NAME", iter->second.EngineName); |
result.Add("ENGINE_NAME", entry.EngineName); |
2063 |
result.Add("INSTRUMENT_FILE", instrumentFileName); |
result.Add("INSTRUMENT_FILE", instrumentFileName); |
2064 |
result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex); |
result.Add("INSTRUMENT_NR", (int) entry.InstrumentIndex); |
2065 |
String instrumentName; |
String instrumentName; |
2066 |
Engine* pEngine = EngineFactory::Create(iter->second.EngineName); |
Engine* pEngine = EngineFactory::Create(entry.EngineName); |
2067 |
if (pEngine) { |
if (pEngine) { |
2068 |
if (pEngine->GetInstrumentManager()) { |
if (pEngine->GetInstrumentManager()) { |
2069 |
InstrumentManager::instrument_id_t instrID; |
InstrumentManager::instrument_id_t instrID; |
2070 |
instrID.FileName = iter->second.InstrumentFile; |
instrID.FileName = entry.InstrumentFile; |
2071 |
instrID.Index = iter->second.InstrumentIndex; |
instrID.Index = entry.InstrumentIndex; |
2072 |
instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID); |
instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID); |
|
} |
|
|
EngineFactory::Destroy(pEngine); |
|
2073 |
} |
} |
2074 |
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); |
|
2075 |
} |
} |
2076 |
|
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName)); |
2077 |
|
switch (entry.LoadMode) { |
2078 |
|
case MidiInstrumentMapper::ON_DEMAND: |
2079 |
|
result.Add("LOAD_MODE", "ON_DEMAND"); |
2080 |
|
break; |
2081 |
|
case MidiInstrumentMapper::ON_DEMAND_HOLD: |
2082 |
|
result.Add("LOAD_MODE", "ON_DEMAND_HOLD"); |
2083 |
|
break; |
2084 |
|
case MidiInstrumentMapper::PERSISTENT: |
2085 |
|
result.Add("LOAD_MODE", "PERSISTENT"); |
2086 |
|
break; |
2087 |
|
default: |
2088 |
|
throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!"); |
2089 |
|
} |
2090 |
|
result.Add("VOLUME", entry.Volume); |
2091 |
} catch (Exception e) { |
} catch (Exception e) { |
2092 |
result.Error(e); |
result.Error(e); |
2093 |
} |
} |
2258 |
dmsg(2,("LSCPServer: SetChannelMap()\n")); |
dmsg(2,("LSCPServer: SetChannelMap()\n")); |
2259 |
LSCPResultSet result; |
LSCPResultSet result; |
2260 |
try { |
try { |
2261 |
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"); |
|
2262 |
|
|
2263 |
if (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone(); |
if (MidiMapID == -1) pEngineChannel->SetMidiInstrumentMapToNone(); |
2264 |
else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault(); |
else if (MidiMapID == -2) pEngineChannel->SetMidiInstrumentMapToDefault(); |
2437 |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: EditSamplerChannelInstrument(SamplerChannel=%d)\n", uiSamplerChannel)); |
2438 |
LSCPResultSet result; |
LSCPResultSet result; |
2439 |
try { |
try { |
2440 |
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"); |
|
2441 |
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
if (pEngineChannel->InstrumentStatus() < 0) throw Exception("No instrument loaded to sampler channel"); |
2442 |
Engine* pEngine = pEngineChannel->GetEngine(); |
Engine* pEngine = pEngineChannel->GetEngine(); |
2443 |
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
InstrumentManager* pInstrumentManager = pEngine->GetInstrumentManager(); |
2452 |
return result.Produce(); |
return result.Produce(); |
2453 |
} |
} |
2454 |
|
|
2455 |
|
String LSCPServer::SendChannelMidiData(String MidiMsg, uint uiSamplerChannel, uint Arg1, uint Arg2) { |
2456 |
|
dmsg(2,("LSCPServer: SendChannelMidiData(MidiMsg=%s,uiSamplerChannel=%d,Arg1=%d,Arg2=%d)\n", MidiMsg.c_str(), uiSamplerChannel, Arg1, Arg2)); |
2457 |
|
LSCPResultSet result; |
2458 |
|
try { |
2459 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2460 |
|
|
2461 |
|
if (Arg1 > 127 || Arg2 > 127) { |
2462 |
|
throw Exception("Invalid MIDI message"); |
2463 |
|
} |
2464 |
|
|
2465 |
|
VirtualMidiDevice* pMidiDevice = NULL; |
2466 |
|
std::vector<EventHandler::midi_listener_entry>::iterator iter = eventHandler.channelMidiListeners.begin(); |
2467 |
|
for (; iter != eventHandler.channelMidiListeners.end(); ++iter) { |
2468 |
|
if ((*iter).pEngineChannel == pEngineChannel) { |
2469 |
|
pMidiDevice = (*iter).pMidiListener; |
2470 |
|
break; |
2471 |
|
} |
2472 |
|
} |
2473 |
|
|
2474 |
|
if(pMidiDevice == NULL) throw Exception("Couldn't find virtual MIDI device"); |
2475 |
|
|
2476 |
|
if (MidiMsg == "NOTE_ON") { |
2477 |
|
pMidiDevice->SendNoteOnToDevice(Arg1, Arg2); |
2478 |
|
bool b = pMidiDevice->SendNoteOnToSampler(Arg1, Arg2); |
2479 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2480 |
|
} else if (MidiMsg == "NOTE_OFF") { |
2481 |
|
pMidiDevice->SendNoteOffToDevice(Arg1, Arg2); |
2482 |
|
bool b = pMidiDevice->SendNoteOffToSampler(Arg1, Arg2); |
2483 |
|
if (!b) throw Exception("MIDI event failed: " + MidiMsg + " " + ToString(Arg1) + " " + ToString(Arg2)); |
2484 |
|
} else { |
2485 |
|
throw Exception("Unknown MIDI message type: " + MidiMsg); |
2486 |
|
} |
2487 |
|
} catch (Exception e) { |
2488 |
|
result.Error(e); |
2489 |
|
} |
2490 |
|
return result.Produce(); |
2491 |
|
} |
2492 |
|
|
2493 |
/** |
/** |
2494 |
* Will be called by the parser to reset a particular sampler channel. |
* Will be called by the parser to reset a particular sampler channel. |
2495 |
*/ |
*/ |
2497 |
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
dmsg(2,("LSCPServer: ResetChannel(SamplerChannel=%d)\n", uiSamplerChannel)); |
2498 |
LSCPResultSet result; |
LSCPResultSet result; |
2499 |
try { |
try { |
2500 |
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"); |
|
2501 |
pEngineChannel->Reset(); |
pEngineChannel->Reset(); |
2502 |
} |
} |
2503 |
catch (Exception e) { |
catch (Exception e) { |
2563 |
String LSCPServer::GetTotalVoiceCountMax() { |
String LSCPServer::GetTotalVoiceCountMax() { |
2564 |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
dmsg(2,("LSCPServer: GetTotalVoiceCountMax()\n")); |
2565 |
LSCPResultSet result; |
LSCPResultSet result; |
2566 |
result.Add(EngineFactory::EngineInstances().size() * CONFIG_MAX_VOICES); |
result.Add(EngineFactory::EngineInstances().size() * GLOBAL_MAX_VOICES); |
2567 |
|
return result.Produce(); |
2568 |
|
} |
2569 |
|
|
2570 |
|
/** |
2571 |
|
* Will be called by the parser to return the sampler global maximum |
2572 |
|
* allowed number of voices. |
2573 |
|
*/ |
2574 |
|
String LSCPServer::GetGlobalMaxVoices() { |
2575 |
|
dmsg(2,("LSCPServer: GetGlobalMaxVoices()\n")); |
2576 |
|
LSCPResultSet result; |
2577 |
|
result.Add(GLOBAL_MAX_VOICES); |
2578 |
|
return result.Produce(); |
2579 |
|
} |
2580 |
|
|
2581 |
|
/** |
2582 |
|
* Will be called by the parser to set the sampler global maximum number of |
2583 |
|
* voices. |
2584 |
|
*/ |
2585 |
|
String LSCPServer::SetGlobalMaxVoices(int iVoices) { |
2586 |
|
dmsg(2,("LSCPServer: SetGlobalMaxVoices(%d)\n", iVoices)); |
2587 |
|
LSCPResultSet result; |
2588 |
|
try { |
2589 |
|
if (iVoices < 1) throw Exception("Maximum voices may not be less than 1"); |
2590 |
|
GLOBAL_MAX_VOICES = iVoices; // see common/global_private.cpp |
2591 |
|
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
2592 |
|
if (engines.size() > 0) { |
2593 |
|
std::set<Engine*>::iterator iter = engines.begin(); |
2594 |
|
std::set<Engine*>::iterator end = engines.end(); |
2595 |
|
for (; iter != end; ++iter) { |
2596 |
|
(*iter)->SetMaxVoices(iVoices); |
2597 |
|
} |
2598 |
|
} |
2599 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOICES", GLOBAL_MAX_VOICES)); |
2600 |
|
} catch (Exception e) { |
2601 |
|
result.Error(e); |
2602 |
|
} |
2603 |
|
return result.Produce(); |
2604 |
|
} |
2605 |
|
|
2606 |
|
/** |
2607 |
|
* Will be called by the parser to return the sampler global maximum |
2608 |
|
* allowed number of disk streams. |
2609 |
|
*/ |
2610 |
|
String LSCPServer::GetGlobalMaxStreams() { |
2611 |
|
dmsg(2,("LSCPServer: GetGlobalMaxStreams()\n")); |
2612 |
|
LSCPResultSet result; |
2613 |
|
result.Add(GLOBAL_MAX_STREAMS); |
2614 |
|
return result.Produce(); |
2615 |
|
} |
2616 |
|
|
2617 |
|
/** |
2618 |
|
* Will be called by the parser to set the sampler global maximum number of |
2619 |
|
* disk streams. |
2620 |
|
*/ |
2621 |
|
String LSCPServer::SetGlobalMaxStreams(int iStreams) { |
2622 |
|
dmsg(2,("LSCPServer: SetGlobalMaxStreams(%d)\n", iStreams)); |
2623 |
|
LSCPResultSet result; |
2624 |
|
try { |
2625 |
|
if (iStreams < 0) throw Exception("Maximum disk streams may not be negative"); |
2626 |
|
GLOBAL_MAX_STREAMS = iStreams; // see common/global_private.cpp |
2627 |
|
const std::set<Engine*>& engines = EngineFactory::EngineInstances(); |
2628 |
|
if (engines.size() > 0) { |
2629 |
|
std::set<Engine*>::iterator iter = engines.begin(); |
2630 |
|
std::set<Engine*>::iterator end = engines.end(); |
2631 |
|
for (; iter != end; ++iter) { |
2632 |
|
(*iter)->SetMaxDiskStreams(iStreams); |
2633 |
|
} |
2634 |
|
} |
2635 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "STREAMS", GLOBAL_MAX_STREAMS)); |
2636 |
|
} catch (Exception e) { |
2637 |
|
result.Error(e); |
2638 |
|
} |
2639 |
return result.Produce(); |
return result.Produce(); |
2640 |
} |
} |
2641 |
|
|
2649 |
LSCPResultSet result; |
LSCPResultSet result; |
2650 |
try { |
try { |
2651 |
if (dVolume < 0) throw Exception("Volume may not be negative"); |
if (dVolume < 0) throw Exception("Volume may not be negative"); |
2652 |
GLOBAL_VOLUME = dVolume; // see common/global.cpp |
GLOBAL_VOLUME = dVolume; // see common/global_private.cpp |
2653 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME)); |
2654 |
} catch (Exception e) { |
} catch (Exception e) { |
2655 |
result.Error(e); |
result.Error(e); |
2776 |
result.Add("FORMAT_VERSION", info.FormatVersion); |
result.Add("FORMAT_VERSION", info.FormatVersion); |
2777 |
result.Add("PRODUCT", info.Product); |
result.Add("PRODUCT", info.Product); |
2778 |
result.Add("ARTISTS", info.Artists); |
result.Add("ARTISTS", info.Artists); |
2779 |
|
|
2780 |
|
std::stringstream ss; |
2781 |
|
bool b = false; |
2782 |
|
for (int i = 0; i < 128; i++) { |
2783 |
|
if (info.KeyBindings[i]) { |
2784 |
|
if (b) ss << ','; |
2785 |
|
ss << i; b = true; |
2786 |
|
} |
2787 |
|
} |
2788 |
|
result.Add("KEY_BINDINGS", ss.str()); |
2789 |
|
|
2790 |
|
b = false; |
2791 |
|
std::stringstream ss2; |
2792 |
|
for (int i = 0; i < 128; i++) { |
2793 |
|
if (info.KeySwitchBindings[i]) { |
2794 |
|
if (b) ss2 << ','; |
2795 |
|
ss2 << i; b = true; |
2796 |
|
} |
2797 |
|
} |
2798 |
|
result.Add("KEYSWITCH_BINDINGS", ss2.str()); |
2799 |
// no more need to ask other engine types |
// no more need to ask other engine types |
2800 |
bFound = true; |
bFound = true; |
2801 |
} 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())); |
2823 |
throw Exception("Directory is specified"); |
throw Exception("Directory is specified"); |
2824 |
} |
} |
2825 |
#else |
#else |
2826 |
struct stat statBuf; |
File f(Filename); |
2827 |
int res = stat(Filename.c_str(), &statBuf); |
if(!f.Exist()) throw Exception(f.GetErrorMsg()); |
2828 |
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"); |
|
|
} |
|
2829 |
#endif |
#endif |
2830 |
} |
} |
2831 |
|
|
3020 |
return result.Produce(); |
return result.Produce(); |
3021 |
} |
} |
3022 |
|
|
3023 |
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) { |
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground, bool insDir) { |
3024 |
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)); |
3025 |
LSCPResultSet result; |
LSCPResultSet result; |
3026 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
3027 |
try { |
try { |
3028 |
int id; |
int id; |
3029 |
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
3030 |
if (ScanMode.compare("RECURSIVE") == 0) { |
if (ScanMode.compare("RECURSIVE") == 0) { |
3031 |
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground); |
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground, insDir); |
3032 |
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
3033 |
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground); |
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground, insDir); |
3034 |
} else if (ScanMode.compare("FLAT") == 0) { |
} else if (ScanMode.compare("FLAT") == 0) { |
3035 |
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground); |
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground, insDir); |
3036 |
} else { |
} else { |
3037 |
throw Exception("Unknown scan mode: " + ScanMode); |
throw Exception("Unknown scan mode: " + ScanMode); |
3038 |
} |
} |
3208 |
return result.Produce(); |
return result.Produce(); |
3209 |
} |
} |
3210 |
|
|
3211 |
|
String LSCPServer::SetDbInstrumentFilePath(String OldPath, String NewPath) { |
3212 |
|
dmsg(2,("LSCPServer: SetDbInstrumentFilePath(OldPath=%s,NewPath=%s)\n", OldPath.c_str(), NewPath.c_str())); |
3213 |
|
LSCPResultSet result; |
3214 |
|
#if HAVE_SQLITE3 |
3215 |
|
try { |
3216 |
|
InstrumentsDb::GetInstrumentsDb()->SetInstrumentFilePath(OldPath, NewPath); |
3217 |
|
} catch (Exception e) { |
3218 |
|
result.Error(e); |
3219 |
|
} |
3220 |
|
#else |
3221 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3222 |
|
#endif |
3223 |
|
return result.Produce(); |
3224 |
|
} |
3225 |
|
|
3226 |
|
String LSCPServer::FindLostDbInstrumentFiles() { |
3227 |
|
dmsg(2,("LSCPServer: FindLostDbInstrumentFiles()\n")); |
3228 |
|
LSCPResultSet result; |
3229 |
|
#if HAVE_SQLITE3 |
3230 |
|
try { |
3231 |
|
String list; |
3232 |
|
StringListPtr pLostFiles = InstrumentsDb::GetInstrumentsDb()->FindLostInstrumentFiles(); |
3233 |
|
|
3234 |
|
for (int i = 0; i < pLostFiles->size(); i++) { |
3235 |
|
if (list != "") list += ","; |
3236 |
|
list += "'" + pLostFiles->at(i) + "'"; |
3237 |
|
} |
3238 |
|
|
3239 |
|
result.Add(list); |
3240 |
|
} catch (Exception e) { |
3241 |
|
result.Error(e); |
3242 |
|
} |
3243 |
|
#else |
3244 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3245 |
|
#endif |
3246 |
|
return result.Produce(); |
3247 |
|
} |
3248 |
|
|
3249 |
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
3250 |
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
3251 |
LSCPResultSet result; |
LSCPResultSet result; |
3376 |
} |
} |
3377 |
return result.Produce(); |
return result.Produce(); |
3378 |
} |
} |
3379 |
|
|
3380 |
|
} |