21 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
***************************************************************************/ |
23 |
|
|
24 |
|
#include <algorithm> |
25 |
|
|
26 |
#include "lscpserver.h" |
#include "lscpserver.h" |
27 |
#include "lscpresultset.h" |
#include "lscpresultset.h" |
28 |
#include "lscpevent.h" |
#include "lscpevent.h" |
42 |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
#include "../drivers/audio/AudioOutputDeviceFactory.h" |
43 |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
#include "../drivers/midi/MidiInputDeviceFactory.h" |
44 |
|
|
45 |
|
namespace LinuxSampler { |
46 |
|
|
47 |
/** |
/** |
48 |
* Returns a copy of the given string where all special characters are |
* Returns a copy of the given string where all special characters are |
425 |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
std::set<EngineChannel*>::iterator itEnd = engineChannels.end(); |
426 |
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
for (; itEngineChannel != itEnd; ++itEngineChannel) { |
427 |
if ((*itEngineChannel)->StatusChanged()) { |
if ((*itEngineChannel)->StatusChanged()) { |
428 |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->GetSamplerChannel()->Index())); |
429 |
} |
} |
430 |
|
|
431 |
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
432 |
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
433 |
if(fxs != NULL && fxs->IsInfoChanged()) { |
if(fxs != NULL && fxs->IsInfoChanged()) { |
434 |
int chn = (*itEngineChannel)->iSamplerChannelIndex; |
int chn = (*itEngineChannel)->GetSamplerChannel()->Index(); |
435 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id())); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id())); |
436 |
fxs->SetInfoChanged(false); |
fxs->SetInfoChanged(false); |
437 |
} |
} |
2021 |
dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n")); |
dmsg(2,("LSCPServer: GetMidiInstrumentMappings()\n")); |
2022 |
LSCPResultSet result; |
LSCPResultSet result; |
2023 |
try { |
try { |
2024 |
result.Add(MidiInstrumentMapper::Entries(MidiMapID).size()); |
result.Add(MidiInstrumentMapper::GetInstrumentCount(MidiMapID)); |
2025 |
} catch (Exception e) { |
} catch (Exception e) { |
2026 |
result.Error(e); |
result.Error(e); |
2027 |
} |
} |
2032 |
String LSCPServer::GetAllMidiInstrumentMappings() { |
String LSCPServer::GetAllMidiInstrumentMappings() { |
2033 |
dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n")); |
dmsg(2,("LSCPServer: GetAllMidiInstrumentMappings()\n")); |
2034 |
LSCPResultSet result; |
LSCPResultSet result; |
2035 |
std::vector<int> maps = MidiInstrumentMapper::Maps(); |
try { |
2036 |
int totalMappings = 0; |
result.Add(MidiInstrumentMapper::GetInstrumentCount()); |
2037 |
for (int i = 0; i < maps.size(); i++) { |
} catch (Exception e) { |
2038 |
try { |
result.Error(e); |
|
totalMappings += MidiInstrumentMapper::Entries(maps[i]).size(); |
|
|
} catch (Exception e) { /*NOOP*/ } |
|
2039 |
} |
} |
|
result.Add(totalMappings); |
|
2040 |
return result.Produce(); |
return result.Produce(); |
2041 |
} |
} |
2042 |
|
|
2044 |
dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n")); |
dmsg(2,("LSCPServer: GetMidiIstrumentMapping()\n")); |
2045 |
LSCPResultSet result; |
LSCPResultSet result; |
2046 |
try { |
try { |
2047 |
midi_prog_index_t idx; |
MidiInstrumentMapper::entry_t entry = MidiInstrumentMapper::GetEntry(MidiMapID, MidiBank, MidiProg); |
2048 |
idx.midi_bank_msb = (MidiBank >> 7) & 0x7f; |
// convert the filename into the correct encoding as defined for LSCP |
2049 |
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) |
|
2050 |
#if WIN32 |
#if WIN32 |
2051 |
const String instrumentFileName = Path::fromWindows(iter->second.InstrumentFile).toLscp(); |
const String instrumentFileName = Path::fromWindows(entry.InstrumentFile).toLscp(); |
2052 |
#else |
#else |
2053 |
// assuming POSIX |
// assuming POSIX |
2054 |
const String instrumentFileName = Path::fromPosix(iter->second.InstrumentFile).toLscp(); |
const String instrumentFileName = Path::fromPosix(entry.InstrumentFile).toLscp(); |
2055 |
#endif |
#endif |
2056 |
|
|
2057 |
result.Add("NAME", _escapeLscpResponse(iter->second.Name)); |
result.Add("NAME", _escapeLscpResponse(entry.Name)); |
2058 |
result.Add("ENGINE_NAME", iter->second.EngineName); |
result.Add("ENGINE_NAME", entry.EngineName); |
2059 |
result.Add("INSTRUMENT_FILE", instrumentFileName); |
result.Add("INSTRUMENT_FILE", instrumentFileName); |
2060 |
result.Add("INSTRUMENT_NR", (int) iter->second.InstrumentIndex); |
result.Add("INSTRUMENT_NR", (int) entry.InstrumentIndex); |
2061 |
String instrumentName; |
String instrumentName; |
2062 |
Engine* pEngine = EngineFactory::Create(iter->second.EngineName); |
Engine* pEngine = EngineFactory::Create(entry.EngineName); |
2063 |
if (pEngine) { |
if (pEngine) { |
2064 |
if (pEngine->GetInstrumentManager()) { |
if (pEngine->GetInstrumentManager()) { |
2065 |
InstrumentManager::instrument_id_t instrID; |
InstrumentManager::instrument_id_t instrID; |
2066 |
instrID.FileName = iter->second.InstrumentFile; |
instrID.FileName = entry.InstrumentFile; |
2067 |
instrID.Index = iter->second.InstrumentIndex; |
instrID.Index = entry.InstrumentIndex; |
2068 |
instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID); |
instrumentName = pEngine->GetInstrumentManager()->GetInstrumentName(instrID); |
|
} |
|
|
EngineFactory::Destroy(pEngine); |
|
2069 |
} |
} |
2070 |
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName)); |
EngineFactory::Destroy(pEngine); |
2071 |
switch (iter->second.LoadMode) { |
} |
2072 |
case MidiInstrumentMapper::ON_DEMAND: |
result.Add("INSTRUMENT_NAME", _escapeLscpResponse(instrumentName)); |
2073 |
result.Add("LOAD_MODE", "ON_DEMAND"); |
switch (entry.LoadMode) { |
2074 |
break; |
case MidiInstrumentMapper::ON_DEMAND: |
2075 |
case MidiInstrumentMapper::ON_DEMAND_HOLD: |
result.Add("LOAD_MODE", "ON_DEMAND"); |
2076 |
result.Add("LOAD_MODE", "ON_DEMAND_HOLD"); |
break; |
2077 |
break; |
case MidiInstrumentMapper::ON_DEMAND_HOLD: |
2078 |
case MidiInstrumentMapper::PERSISTENT: |
result.Add("LOAD_MODE", "ON_DEMAND_HOLD"); |
2079 |
result.Add("LOAD_MODE", "PERSISTENT"); |
break; |
2080 |
break; |
case MidiInstrumentMapper::PERSISTENT: |
2081 |
default: |
result.Add("LOAD_MODE", "PERSISTENT"); |
2082 |
throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!"); |
break; |
2083 |
} |
default: |
2084 |
result.Add("VOLUME", iter->second.Volume); |
throw Exception("entry reflects invalid LOAD_MODE, consider this as a bug!"); |
2085 |
} |
} |
2086 |
|
result.Add("VOLUME", entry.Volume); |
2087 |
} catch (Exception e) { |
} catch (Exception e) { |
2088 |
result.Error(e); |
result.Error(e); |
2089 |
} |
} |
2545 |
LSCPResultSet result; |
LSCPResultSet result; |
2546 |
try { |
try { |
2547 |
if (dVolume < 0) throw Exception("Volume may not be negative"); |
if (dVolume < 0) throw Exception("Volume may not be negative"); |
2548 |
GLOBAL_VOLUME = dVolume; // see common/global.cpp |
GLOBAL_VOLUME = dVolume; // see common/global_private.cpp |
2549 |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME)); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME)); |
2550 |
} catch (Exception e) { |
} catch (Exception e) { |
2551 |
result.Error(e); |
result.Error(e); |
3092 |
return result.Produce(); |
return result.Produce(); |
3093 |
} |
} |
3094 |
|
|
3095 |
|
String LSCPServer::SetDbInstrumentFilePath(String OldPath, String NewPath) { |
3096 |
|
dmsg(2,("LSCPServer: SetDbInstrumentFilePath(OldPath=%s,NewPath=%s)\n", OldPath.c_str(), NewPath.c_str())); |
3097 |
|
LSCPResultSet result; |
3098 |
|
#if HAVE_SQLITE3 |
3099 |
|
try { |
3100 |
|
InstrumentsDb::GetInstrumentsDb()->SetInstrumentFilePath(OldPath, NewPath); |
3101 |
|
} catch (Exception e) { |
3102 |
|
result.Error(e); |
3103 |
|
} |
3104 |
|
#else |
3105 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3106 |
|
#endif |
3107 |
|
return result.Produce(); |
3108 |
|
} |
3109 |
|
|
3110 |
|
String LSCPServer::FindLostDbInstrumentFiles() { |
3111 |
|
dmsg(2,("LSCPServer: FindLostDbInstrumentFiles()\n")); |
3112 |
|
LSCPResultSet result; |
3113 |
|
#if HAVE_SQLITE3 |
3114 |
|
try { |
3115 |
|
String list; |
3116 |
|
StringListPtr pLostFiles = InstrumentsDb::GetInstrumentsDb()->FindLostInstrumentFiles(); |
3117 |
|
|
3118 |
|
for (int i = 0; i < pLostFiles->size(); i++) { |
3119 |
|
if (list != "") list += ","; |
3120 |
|
list += "'" + pLostFiles->at(i) + "'"; |
3121 |
|
} |
3122 |
|
|
3123 |
|
result.Add(list); |
3124 |
|
} catch (Exception e) { |
3125 |
|
result.Error(e); |
3126 |
|
} |
3127 |
|
#else |
3128 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
3129 |
|
#endif |
3130 |
|
return result.Produce(); |
3131 |
|
} |
3132 |
|
|
3133 |
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
3134 |
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
3135 |
LSCPResultSet result; |
LSCPResultSet result; |
3260 |
} |
} |
3261 |
return result.Produce(); |
return result.Produce(); |
3262 |
} |
} |
3263 |
|
|
3264 |
|
} |