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, 2006 Christian Schoenebeck * |
* Copyright (C) 2005 - 2007 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This library is free software; you can redistribute it and/or modify * |
* This library is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
24 |
#include "lscpserver.h" |
#include "lscpserver.h" |
25 |
#include "lscpresultset.h" |
#include "lscpresultset.h" |
26 |
#include "lscpevent.h" |
#include "lscpevent.h" |
|
//#include "../common/global.h" |
|
27 |
|
|
28 |
#include <fcntl.h> |
#include <fcntl.h> |
29 |
|
|
30 |
#if HAVE_SQLITE3 |
#if ! HAVE_SQLITE3 |
31 |
# include "sqlite3.h" |
#define DOESNT_HAVE_SQLITE3 "No database support. SQLITE3 was not installed when linuxsampler was built." |
32 |
#endif |
#endif |
33 |
|
|
34 |
#include "../engines/EngineFactory.h" |
#include "../engines/EngineFactory.h" |
74 |
LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT"); |
75 |
LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL"); |
76 |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO"); |
77 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_fx_send_count, "FX_SEND_COUNT"); |
78 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_fx_send_info, "FX_SEND_INFO"); |
79 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_count, "MIDI_INSTRUMENT_MAP_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_count, "MIDI_INSTRUMENT_MAP_COUNT"); |
80 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO"); |
81 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT"); |
82 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO"); |
83 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_count, "DB_INSTRUMENT_DIRECTORY_COUNT"); |
84 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_dir_info, "DB_INSTRUMENT_DIRECTORY_INFO"); |
85 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_count, "DB_INSTRUMENT_COUNT"); |
86 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instr_info, "DB_INSTRUMENT_INFO"); |
87 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_db_instrs_job_info, "DB_INSTRUMENTS_JOB_INFO"); |
88 |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
89 |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
90 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
91 |
hSocket = -1; |
hSocket = -1; |
92 |
} |
} |
93 |
|
|
95 |
if (hSocket >= 0) close(hSocket); |
if (hSocket >= 0) close(hSocket); |
96 |
} |
} |
97 |
|
|
98 |
|
void LSCPServer::EventHandler::ChannelCountChanged(int NewCount) { |
99 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount)); |
100 |
|
} |
101 |
|
|
102 |
|
void LSCPServer::EventHandler::AudioDeviceCountChanged(int NewCount) { |
103 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount)); |
104 |
|
} |
105 |
|
|
106 |
|
void LSCPServer::EventHandler::MidiDeviceCountChanged(int NewCount) { |
107 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount)); |
108 |
|
} |
109 |
|
|
110 |
|
void LSCPServer::EventHandler::MidiInstrumentCountChanged(int MapId, int NewCount) { |
111 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount)); |
112 |
|
} |
113 |
|
|
114 |
|
void LSCPServer::EventHandler::MidiInstrumentInfoChanged(int MapId, int Bank, int Program) { |
115 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_info, MapId, Bank, Program)); |
116 |
|
} |
117 |
|
|
118 |
|
void LSCPServer::EventHandler::MidiInstrumentMapCountChanged(int NewCount) { |
119 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_count, NewCount)); |
120 |
|
} |
121 |
|
|
122 |
|
void LSCPServer::EventHandler::MidiInstrumentMapInfoChanged(int MapId) { |
123 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_info, MapId)); |
124 |
|
} |
125 |
|
|
126 |
|
void LSCPServer::EventHandler::FxSendCountChanged(int ChannelId, int NewCount) { |
127 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_count, ChannelId, NewCount)); |
128 |
|
} |
129 |
|
|
130 |
|
void LSCPServer::EventHandler::VoiceCountChanged(int ChannelId, int NewCount) { |
131 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_voice_count, ChannelId, NewCount)); |
132 |
|
} |
133 |
|
|
134 |
|
void LSCPServer::EventHandler::StreamCountChanged(int ChannelId, int NewCount) { |
135 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_stream_count, ChannelId, NewCount)); |
136 |
|
} |
137 |
|
|
138 |
|
void LSCPServer::EventHandler::BufferFillChanged(int ChannelId, String FillData) { |
139 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_buffer_fill, ChannelId, FillData)); |
140 |
|
} |
141 |
|
|
142 |
|
void LSCPServer::EventHandler::TotalVoiceCountChanged(int NewCount) { |
143 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount)); |
144 |
|
} |
145 |
|
|
146 |
|
#if HAVE_SQLITE3 |
147 |
|
void LSCPServer::DbInstrumentsEventHandler::DirectoryCountChanged(String Dir) { |
148 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_count, Dir)); |
149 |
|
} |
150 |
|
|
151 |
|
void LSCPServer::DbInstrumentsEventHandler::DirectoryInfoChanged(String Dir) { |
152 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, Dir)); |
153 |
|
} |
154 |
|
|
155 |
|
void LSCPServer::DbInstrumentsEventHandler::DirectoryNameChanged(String Dir, String NewName) { |
156 |
|
Dir = "'" + Dir + "'"; |
157 |
|
NewName = "'" + NewName + "'"; |
158 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_dir_info, "NAME", Dir, NewName)); |
159 |
|
} |
160 |
|
|
161 |
|
void LSCPServer::DbInstrumentsEventHandler::InstrumentCountChanged(String Dir) { |
162 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_count, Dir)); |
163 |
|
} |
164 |
|
|
165 |
|
void LSCPServer::DbInstrumentsEventHandler::InstrumentInfoChanged(String Instr) { |
166 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, Instr)); |
167 |
|
} |
168 |
|
|
169 |
|
void LSCPServer::DbInstrumentsEventHandler::InstrumentNameChanged(String Instr, String NewName) { |
170 |
|
Instr = "'" + Instr + "'"; |
171 |
|
NewName = "'" + NewName + "'"; |
172 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instr_info, "NAME", Instr, NewName)); |
173 |
|
} |
174 |
|
|
175 |
|
void LSCPServer::DbInstrumentsEventHandler::JobStatusChanged(int JobId) { |
176 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_db_instrs_job_info, JobId)); |
177 |
|
} |
178 |
|
#endif // HAVE_SQLITE3 |
179 |
|
|
180 |
|
|
181 |
/** |
/** |
182 |
* Blocks the calling thread until the LSCP Server is initialized and |
* Blocks the calling thread until the LSCP Server is initialized and |
183 |
* accepting socket connections, if the server is already initialized then |
* accepting socket connections, if the server is already initialized then |
218 |
|
|
219 |
listen(hSocket, 1); |
listen(hSocket, 1); |
220 |
Initialized.Set(true); |
Initialized.Set(true); |
221 |
|
|
222 |
|
// Registering event listeners |
223 |
|
pSampler->AddChannelCountListener(&eventHandler); |
224 |
|
pSampler->AddAudioDeviceCountListener(&eventHandler); |
225 |
|
pSampler->AddMidiDeviceCountListener(&eventHandler); |
226 |
|
pSampler->AddVoiceCountListener(&eventHandler); |
227 |
|
pSampler->AddStreamCountListener(&eventHandler); |
228 |
|
pSampler->AddBufferFillListener(&eventHandler); |
229 |
|
pSampler->AddTotalVoiceCountListener(&eventHandler); |
230 |
|
pSampler->AddFxSendCountListener(&eventHandler); |
231 |
|
MidiInstrumentMapper::AddMidiInstrumentCountListener(&eventHandler); |
232 |
|
MidiInstrumentMapper::AddMidiInstrumentInfoListener(&eventHandler); |
233 |
|
MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&eventHandler); |
234 |
|
MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(&eventHandler); |
235 |
|
#if HAVE_SQLITE3 |
236 |
|
InstrumentsDb::GetInstrumentsDb()->AddInstrumentsDbListener(&dbInstrumentsEventHandler); |
237 |
|
#endif |
238 |
// now wait for client connections and handle their requests |
// now wait for client connections and handle their requests |
239 |
sockaddr_in client; |
sockaddr_in client; |
240 |
int length = sizeof(client); |
int length = sizeof(client); |
254 |
if ((*itEngineChannel)->StatusChanged()) { |
if ((*itEngineChannel)->StatusChanged()) { |
255 |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
256 |
} |
} |
257 |
|
|
258 |
|
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
259 |
|
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
260 |
|
if(fxs != NULL && fxs->IsInfoChanged()) { |
261 |
|
int chn = (*itEngineChannel)->iSamplerChannelIndex; |
262 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id())); |
263 |
|
fxs->SetInfoChanged(false); |
264 |
|
} |
265 |
|
} |
266 |
} |
} |
267 |
} |
} |
268 |
|
|
605 |
return result.Produce(); |
return result.Produce(); |
606 |
} |
} |
607 |
|
|
608 |
|
EngineChannel* LSCPServer::GetEngineChannel(uint uiSamplerChannel) { |
609 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
610 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
611 |
|
|
612 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
613 |
|
if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); |
614 |
|
|
615 |
|
return pEngineChannel; |
616 |
|
} |
617 |
|
|
618 |
/** |
/** |
619 |
* Will be called by the parser to load an instrument. |
* Will be called by the parser to load an instrument. |
620 |
*/ |
*/ |
795 |
String AudioRouting; |
String AudioRouting; |
796 |
int Mute = 0; |
int Mute = 0; |
797 |
bool Solo = false; |
bool Solo = false; |
798 |
String MidiInstrumentMap; |
String MidiInstrumentMap = "NONE"; |
799 |
|
|
800 |
if (pEngineChannel) { |
if (pEngineChannel) { |
801 |
EngineName = pEngineChannel->EngineName(); |
EngineName = pEngineChannel->EngineName(); |
1627 |
|
|
1628 |
bool oldSolo = pEngineChannel->GetSolo(); |
bool oldSolo = pEngineChannel->GetSolo(); |
1629 |
bool hadSoloChannel = HasSoloChannel(); |
bool hadSoloChannel = HasSoloChannel(); |
1630 |
|
|
1631 |
pEngineChannel->SetSolo(bSolo); |
pEngineChannel->SetSolo(bSolo); |
1632 |
|
|
1633 |
if(!oldSolo && bSolo) { |
if(!oldSolo && bSolo) { |
1634 |
if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0); |
if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0); |
1635 |
if(!hadSoloChannel) MuteNonSoloChannels(); |
if(!hadSoloChannel) MuteNonSoloChannels(); |
1636 |
} |
} |
1637 |
|
|
1638 |
if(oldSolo && !bSolo) { |
if(oldSolo && !bSolo) { |
1639 |
if(!HasSoloChannel()) UnmuteChannels(); |
if(!HasSoloChannel()) UnmuteChannels(); |
1640 |
else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1); |
else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1); |
1692 |
} |
} |
1693 |
} |
} |
1694 |
|
|
1695 |
String LSCPServer::AddOrReplaceMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg, String EngineType, String InstrumentFile, uint InstrumentIndex, float Volume, MidiInstrumentMapper::mode_t LoadMode, String Name) { |
String LSCPServer::AddOrReplaceMIDIInstrumentMapping(uint MidiMapID, uint MidiBank, uint MidiProg, String EngineType, String InstrumentFile, uint InstrumentIndex, float Volume, MidiInstrumentMapper::mode_t LoadMode, String Name, bool bModal) { |
1696 |
dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n")); |
dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n")); |
1697 |
|
|
1698 |
midi_prog_index_t idx; |
midi_prog_index_t idx; |
1710 |
|
|
1711 |
LSCPResultSet result; |
LSCPResultSet result; |
1712 |
try { |
try { |
1713 |
// PERSISTENT mapping commands might bloock for a long time, so in |
// PERSISTENT mapping commands might block for a long time, so in |
1714 |
// that case we add/replace the mapping in another thread |
// that case we add/replace the mapping in another thread in case |
1715 |
bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT); |
// the NON_MODAL argument was supplied, non persistent mappings |
1716 |
|
// should return immediately, so we don't need to do that for them |
1717 |
|
bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT && !bModal); |
1718 |
MidiInstrumentMapper::AddOrReplaceEntry(MidiMapID, idx, entry, bInBackground); |
MidiInstrumentMapper::AddOrReplaceEntry(MidiMapID, idx, entry, bInBackground); |
1719 |
} catch (Exception e) { |
} catch (Exception e) { |
1720 |
result.Error(e); |
result.Error(e); |
1825 |
for (; iter != mappings.end(); iter++) { |
for (; iter != mappings.end(); iter++) { |
1826 |
if (s.size()) s += ","; |
if (s.size()) s += ","; |
1827 |
s += "{" + ToString(MidiMapID) + "," |
s += "{" + ToString(MidiMapID) + "," |
1828 |
+ ToString((int(iter->first.midi_bank_msb) << 7) & int(iter->first.midi_bank_lsb)) + "," |
+ ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + "," |
1829 |
+ ToString(int(iter->first.midi_prog)) + "}"; |
+ ToString(int(iter->first.midi_prog)) + "}"; |
1830 |
} |
} |
1831 |
result.Add(s); |
result.Add(s); |
1847 |
for (; iter != mappings.end(); iter++) { |
for (; iter != mappings.end(); iter++) { |
1848 |
if (s.size()) s += ","; |
if (s.size()) s += ","; |
1849 |
s += "{" + ToString(maps[i]) + "," |
s += "{" + ToString(maps[i]) + "," |
1850 |
+ ToString((int(iter->first.midi_bank_msb) << 7) & int(iter->first.midi_bank_lsb)) + "," |
+ ToString((int(iter->first.midi_bank_msb) << 7) | int(iter->first.midi_bank_lsb)) + "," |
1851 |
+ ToString(int(iter->first.midi_prog)) + "}"; |
+ ToString(int(iter->first.midi_prog)) + "}"; |
1852 |
} |
} |
1853 |
} |
} |
1949 |
LSCPResultSet result; |
LSCPResultSet result; |
1950 |
try { |
try { |
1951 |
result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID)); |
result.Add("NAME", MidiInstrumentMapper::MapName(MidiMapID)); |
1952 |
|
result.Add("DEFAULT", MidiInstrumentMapper::GetDefaultMap() == MidiMapID); |
1953 |
} catch (Exception e) { |
} catch (Exception e) { |
1954 |
result.Error(e); |
result.Error(e); |
1955 |
} |
} |
1998 |
dmsg(2,("LSCPServer: CreateFxSend()\n")); |
dmsg(2,("LSCPServer: CreateFxSend()\n")); |
1999 |
LSCPResultSet result; |
LSCPResultSet result; |
2000 |
try { |
try { |
2001 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2002 |
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"); |
|
|
|
|
2003 |
FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name); |
FxSend* pFxSend = pEngineChannel->AddFxSend(MidiCtrl, Name); |
2004 |
if (!pFxSend) throw Exception("Could not add FxSend, don't ask, I don't know why (probably a bug)"); |
if (!pFxSend) throw Exception("Could not add FxSend, don't ask, I don't know why (probably a bug)"); |
2005 |
|
|
2014 |
dmsg(2,("LSCPServer: DestroyFxSend()\n")); |
dmsg(2,("LSCPServer: DestroyFxSend()\n")); |
2015 |
LSCPResultSet result; |
LSCPResultSet result; |
2016 |
try { |
try { |
2017 |
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"); |
|
2018 |
|
|
2019 |
FxSend* pFxSend = NULL; |
FxSend* pFxSend = NULL; |
2020 |
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
2035 |
dmsg(2,("LSCPServer: GetFxSends()\n")); |
dmsg(2,("LSCPServer: GetFxSends()\n")); |
2036 |
LSCPResultSet result; |
LSCPResultSet result; |
2037 |
try { |
try { |
2038 |
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"); |
|
2039 |
|
|
2040 |
result.Add(pEngineChannel->GetFxSendCount()); |
result.Add(pEngineChannel->GetFxSendCount()); |
2041 |
} catch (Exception e) { |
} catch (Exception e) { |
2049 |
LSCPResultSet result; |
LSCPResultSet result; |
2050 |
String list; |
String list; |
2051 |
try { |
try { |
2052 |
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"); |
|
2053 |
|
|
2054 |
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
2055 |
FxSend* pFxSend = pEngineChannel->GetFxSend(i); |
FxSend* pFxSend = pEngineChannel->GetFxSend(i); |
2063 |
return result.Produce(); |
return result.Produce(); |
2064 |
} |
} |
2065 |
|
|
2066 |
|
FxSend* LSCPServer::GetFxSend(uint uiSamplerChannel, uint FxSendID) { |
2067 |
|
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2068 |
|
|
2069 |
|
FxSend* pFxSend = NULL; |
2070 |
|
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
2071 |
|
if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) { |
2072 |
|
pFxSend = pEngineChannel->GetFxSend(i); |
2073 |
|
break; |
2074 |
|
} |
2075 |
|
} |
2076 |
|
if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel"); |
2077 |
|
return pFxSend; |
2078 |
|
} |
2079 |
|
|
2080 |
String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) { |
String LSCPServer::GetFxSendInfo(uint uiSamplerChannel, uint FxSendID) { |
2081 |
dmsg(2,("LSCPServer: GetFxSendInfo()\n")); |
dmsg(2,("LSCPServer: GetFxSendInfo()\n")); |
2082 |
LSCPResultSet result; |
LSCPResultSet result; |
2083 |
try { |
try { |
2084 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
EngineChannel* pEngineChannel = GetEngineChannel(uiSamplerChannel); |
2085 |
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2086 |
|
|
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
|
|
if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); |
|
|
|
|
|
FxSend* pFxSend = NULL; |
|
|
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
|
|
if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) { |
|
|
pFxSend = pEngineChannel->GetFxSend(i); |
|
|
break; |
|
|
} |
|
|
} |
|
|
if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel"); |
|
|
|
|
2087 |
// gather audio routing informations |
// gather audio routing informations |
2088 |
String AudioRouting; |
String AudioRouting; |
2089 |
for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { |
for (int chan = 0; chan < pEngineChannel->Channels(); chan++) { |
2093 |
|
|
2094 |
// success |
// success |
2095 |
result.Add("NAME", pFxSend->Name()); |
result.Add("NAME", pFxSend->Name()); |
2096 |
|
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
2097 |
|
result.Add("LEVEL", ToString(pFxSend->Level())); |
2098 |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
2099 |
} catch (Exception e) { |
} catch (Exception e) { |
2100 |
result.Error(e); |
result.Error(e); |
2102 |
return result.Produce(); |
return result.Produce(); |
2103 |
} |
} |
2104 |
|
|
2105 |
|
String LSCPServer::SetFxSendName(uint uiSamplerChannel, uint FxSendID, String Name) { |
2106 |
|
dmsg(2,("LSCPServer: SetFxSendName()\n")); |
2107 |
|
LSCPResultSet result; |
2108 |
|
try { |
2109 |
|
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2110 |
|
|
2111 |
|
pFxSend->SetName(Name); |
2112 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2113 |
|
} catch (Exception e) { |
2114 |
|
result.Error(e); |
2115 |
|
} |
2116 |
|
return result.Produce(); |
2117 |
|
} |
2118 |
|
|
2119 |
String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) { |
String LSCPServer::SetFxSendAudioOutputChannel(uint uiSamplerChannel, uint FxSendID, uint FxSendChannel, uint DeviceChannel) { |
2120 |
dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n")); |
dmsg(2,("LSCPServer: SetFxSendAudioOutputChannel()\n")); |
2121 |
LSCPResultSet result; |
LSCPResultSet result; |
2122 |
try { |
try { |
2123 |
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
|
2124 |
|
|
2125 |
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel); |
2126 |
if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); |
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2127 |
|
} catch (Exception e) { |
2128 |
|
result.Error(e); |
2129 |
|
} |
2130 |
|
return result.Produce(); |
2131 |
|
} |
2132 |
|
|
2133 |
FxSend* pFxSend = NULL; |
String LSCPServer::SetFxSendMidiController(uint uiSamplerChannel, uint FxSendID, uint MidiController) { |
2134 |
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
dmsg(2,("LSCPServer: SetFxSendMidiController()\n")); |
2135 |
if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) { |
LSCPResultSet result; |
2136 |
pFxSend = pEngineChannel->GetFxSend(i); |
try { |
2137 |
break; |
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
|
} |
|
|
} |
|
|
if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel"); |
|
2138 |
|
|
2139 |
pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel); |
pFxSend->SetMidiController(MidiController); |
2140 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2141 |
|
} catch (Exception e) { |
2142 |
|
result.Error(e); |
2143 |
|
} |
2144 |
|
return result.Produce(); |
2145 |
|
} |
2146 |
|
|
2147 |
|
String LSCPServer::SetFxSendLevel(uint uiSamplerChannel, uint FxSendID, double dLevel) { |
2148 |
|
dmsg(2,("LSCPServer: SetFxSendLevel()\n")); |
2149 |
|
LSCPResultSet result; |
2150 |
|
try { |
2151 |
|
FxSend* pFxSend = GetFxSend(uiSamplerChannel, FxSendID); |
2152 |
|
|
2153 |
|
pFxSend->SetLevel((float)dLevel); |
2154 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2155 |
} catch (Exception e) { |
} catch (Exception e) { |
2156 |
result.Error(e); |
result.Error(e); |
2157 |
} |
} |
2197 |
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
result.Add("DESCRIPTION", "LinuxSampler - modular, streaming capable sampler"); |
2198 |
result.Add("VERSION", VERSION); |
result.Add("VERSION", VERSION); |
2199 |
result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR)); |
result.Add("PROTOCOL_VERSION", ToString(LSCP_RELEASE_MAJOR) + "." + ToString(LSCP_RELEASE_MINOR)); |
2200 |
|
#if HAVE_SQLITE3 |
2201 |
|
result.Add("INSTRUMENTS_DB_SUPPORT", "yes"); |
2202 |
|
#else |
2203 |
|
result.Add("INSTRUMENTS_DB_SUPPORT", "no"); |
2204 |
|
#endif |
2205 |
|
|
2206 |
return result.Produce(); |
return result.Produce(); |
2207 |
} |
} |
2208 |
|
|
2226 |
return result.Produce(); |
return result.Produce(); |
2227 |
} |
} |
2228 |
|
|
2229 |
|
String LSCPServer::GetGlobalVolume() { |
2230 |
|
LSCPResultSet result; |
2231 |
|
result.Add(ToString(GLOBAL_VOLUME)); // see common/global.cpp |
2232 |
|
return result.Produce(); |
2233 |
|
} |
2234 |
|
|
2235 |
|
String LSCPServer::SetGlobalVolume(double dVolume) { |
2236 |
|
LSCPResultSet result; |
2237 |
|
try { |
2238 |
|
if (dVolume < 0) throw Exception("Volume may not be negative"); |
2239 |
|
GLOBAL_VOLUME = dVolume; // see common/global.cpp |
2240 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME)); |
2241 |
|
} catch (Exception e) { |
2242 |
|
result.Error(e); |
2243 |
|
} |
2244 |
|
return result.Produce(); |
2245 |
|
} |
2246 |
|
|
2247 |
/** |
/** |
2248 |
* Will be called by the parser to subscribe a client (frontend) on the |
* Will be called by the parser to subscribe a client (frontend) on the |
2249 |
* server for receiving event messages. |
* server for receiving event messages. |
2270 |
return result.Produce(); |
return result.Produce(); |
2271 |
} |
} |
2272 |
|
|
2273 |
static int select_callback(void * lscpResultSet, int argc, |
String LSCPServer::AddDbInstrumentDirectory(String Dir) { |
2274 |
char **argv, char **azColName) |
dmsg(2,("LSCPServer: AddDbInstrumentDirectory(Dir=%s)\n", Dir.c_str())); |
2275 |
{ |
LSCPResultSet result; |
2276 |
LSCPResultSet* resultSet = (LSCPResultSet*) lscpResultSet; |
#if HAVE_SQLITE3 |
2277 |
resultSet->Add(argc, argv); |
try { |
2278 |
return 0; |
InstrumentsDb::GetInstrumentsDb()->AddDirectory(Dir); |
2279 |
|
} catch (Exception e) { |
2280 |
|
result.Error(e); |
2281 |
|
} |
2282 |
|
#else |
2283 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2284 |
|
#endif |
2285 |
|
return result.Produce(); |
2286 |
|
} |
2287 |
|
|
2288 |
|
String LSCPServer::RemoveDbInstrumentDirectory(String Dir, bool Force) { |
2289 |
|
dmsg(2,("LSCPServer: RemoveDbInstrumentDirectory(Dir=%s,Force=%d)\n", Dir.c_str(), Force)); |
2290 |
|
LSCPResultSet result; |
2291 |
|
#if HAVE_SQLITE3 |
2292 |
|
try { |
2293 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveDirectory(Dir, Force); |
2294 |
|
} catch (Exception e) { |
2295 |
|
result.Error(e); |
2296 |
|
} |
2297 |
|
#else |
2298 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2299 |
|
#endif |
2300 |
|
return result.Produce(); |
2301 |
|
} |
2302 |
|
|
2303 |
|
String LSCPServer::GetDbInstrumentDirectoryCount(String Dir, bool Recursive) { |
2304 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectoryCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2305 |
|
LSCPResultSet result; |
2306 |
|
#if HAVE_SQLITE3 |
2307 |
|
try { |
2308 |
|
result.Add(InstrumentsDb::GetInstrumentsDb()->GetDirectoryCount(Dir, Recursive)); |
2309 |
|
} catch (Exception e) { |
2310 |
|
result.Error(e); |
2311 |
|
} |
2312 |
|
#else |
2313 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2314 |
|
#endif |
2315 |
|
return result.Produce(); |
2316 |
|
} |
2317 |
|
|
2318 |
|
String LSCPServer::GetDbInstrumentDirectories(String Dir, bool Recursive) { |
2319 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectories(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2320 |
|
LSCPResultSet result; |
2321 |
|
#if HAVE_SQLITE3 |
2322 |
|
try { |
2323 |
|
String list; |
2324 |
|
StringListPtr dirs = InstrumentsDb::GetInstrumentsDb()->GetDirectories(Dir, Recursive); |
2325 |
|
|
2326 |
|
for (int i = 0; i < dirs->size(); i++) { |
2327 |
|
if (list != "") list += ","; |
2328 |
|
list += "'" + dirs->at(i) + "'"; |
2329 |
|
} |
2330 |
|
|
2331 |
|
result.Add(list); |
2332 |
|
} catch (Exception e) { |
2333 |
|
result.Error(e); |
2334 |
|
} |
2335 |
|
#else |
2336 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2337 |
|
#endif |
2338 |
|
return result.Produce(); |
2339 |
|
} |
2340 |
|
|
2341 |
|
String LSCPServer::GetDbInstrumentDirectoryInfo(String Dir) { |
2342 |
|
dmsg(2,("LSCPServer: GetDbInstrumentDirectoryInfo(Dir=%s)\n", Dir.c_str())); |
2343 |
|
LSCPResultSet result; |
2344 |
|
#if HAVE_SQLITE3 |
2345 |
|
try { |
2346 |
|
DbDirectory info = InstrumentsDb::GetInstrumentsDb()->GetDirectoryInfo(Dir); |
2347 |
|
|
2348 |
|
result.Add("DESCRIPTION", info.Description); |
2349 |
|
result.Add("CREATED", info.Created); |
2350 |
|
result.Add("MODIFIED", info.Modified); |
2351 |
|
} catch (Exception e) { |
2352 |
|
result.Error(e); |
2353 |
|
} |
2354 |
|
#else |
2355 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2356 |
|
#endif |
2357 |
|
return result.Produce(); |
2358 |
|
} |
2359 |
|
|
2360 |
|
String LSCPServer::SetDbInstrumentDirectoryName(String Dir, String Name) { |
2361 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDirectoryName(Dir=%s,Name=%s)\n", Dir.c_str(), Name.c_str())); |
2362 |
|
LSCPResultSet result; |
2363 |
|
#if HAVE_SQLITE3 |
2364 |
|
try { |
2365 |
|
InstrumentsDb::GetInstrumentsDb()->RenameDirectory(Dir, Name); |
2366 |
|
} catch (Exception e) { |
2367 |
|
result.Error(e); |
2368 |
|
} |
2369 |
|
#else |
2370 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2371 |
|
#endif |
2372 |
|
return result.Produce(); |
2373 |
|
} |
2374 |
|
|
2375 |
|
String LSCPServer::MoveDbInstrumentDirectory(String Dir, String Dst) { |
2376 |
|
dmsg(2,("LSCPServer: MoveDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str())); |
2377 |
|
LSCPResultSet result; |
2378 |
|
#if HAVE_SQLITE3 |
2379 |
|
try { |
2380 |
|
InstrumentsDb::GetInstrumentsDb()->MoveDirectory(Dir, Dst); |
2381 |
|
} catch (Exception e) { |
2382 |
|
result.Error(e); |
2383 |
|
} |
2384 |
|
#else |
2385 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2386 |
|
#endif |
2387 |
|
return result.Produce(); |
2388 |
|
} |
2389 |
|
|
2390 |
|
String LSCPServer::CopyDbInstrumentDirectory(String Dir, String Dst) { |
2391 |
|
dmsg(2,("LSCPServer: CopyDbInstrumentDirectory(Dir=%s,Dst=%s)\n", Dir.c_str(), Dst.c_str())); |
2392 |
|
LSCPResultSet result; |
2393 |
|
#if HAVE_SQLITE3 |
2394 |
|
try { |
2395 |
|
InstrumentsDb::GetInstrumentsDb()->CopyDirectory(Dir, Dst); |
2396 |
|
} catch (Exception e) { |
2397 |
|
result.Error(e); |
2398 |
|
} |
2399 |
|
#else |
2400 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2401 |
|
#endif |
2402 |
|
return result.Produce(); |
2403 |
|
} |
2404 |
|
|
2405 |
|
String LSCPServer::SetDbInstrumentDirectoryDescription(String Dir, String Desc) { |
2406 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDirectoryDescription(Dir=%s,Desc=%s)\n", Dir.c_str(), Desc.c_str())); |
2407 |
|
LSCPResultSet result; |
2408 |
|
#if HAVE_SQLITE3 |
2409 |
|
try { |
2410 |
|
InstrumentsDb::GetInstrumentsDb()->SetDirectoryDescription(Dir, Desc); |
2411 |
|
} catch (Exception e) { |
2412 |
|
result.Error(e); |
2413 |
|
} |
2414 |
|
#else |
2415 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2416 |
|
#endif |
2417 |
|
return result.Produce(); |
2418 |
|
} |
2419 |
|
|
2420 |
|
String LSCPServer::AddDbInstruments(String DbDir, String FilePath, int Index, bool bBackground) { |
2421 |
|
dmsg(2,("LSCPServer: AddDbInstruments(DbDir=%s,FilePath=%s,Index=%d,bBackground=%d)\n", DbDir.c_str(), FilePath.c_str(), Index, bBackground)); |
2422 |
|
LSCPResultSet result; |
2423 |
|
#if HAVE_SQLITE3 |
2424 |
|
try { |
2425 |
|
int id; |
2426 |
|
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
2427 |
|
id = db->AddInstruments(DbDir, FilePath, Index, bBackground); |
2428 |
|
if (bBackground) result = id; |
2429 |
|
} catch (Exception e) { |
2430 |
|
result.Error(e); |
2431 |
|
} |
2432 |
|
#else |
2433 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2434 |
|
#endif |
2435 |
|
return result.Produce(); |
2436 |
|
} |
2437 |
|
|
2438 |
|
String LSCPServer::AddDbInstruments(String ScanMode, String DbDir, String FsDir, bool bBackground) { |
2439 |
|
dmsg(2,("LSCPServer: AddDbInstruments(ScanMode=%s,DbDir=%s,FsDir=%s,bBackground=%d)\n", ScanMode.c_str(), DbDir.c_str(), FsDir.c_str(), bBackground)); |
2440 |
|
LSCPResultSet result; |
2441 |
|
#if HAVE_SQLITE3 |
2442 |
|
try { |
2443 |
|
int id; |
2444 |
|
InstrumentsDb* db = InstrumentsDb::GetInstrumentsDb(); |
2445 |
|
if (ScanMode.compare("RECURSIVE") == 0) { |
2446 |
|
id = db->AddInstruments(RECURSIVE, DbDir, FsDir, bBackground); |
2447 |
|
} else if (ScanMode.compare("NON_RECURSIVE") == 0) { |
2448 |
|
id = db->AddInstruments(NON_RECURSIVE, DbDir, FsDir, bBackground); |
2449 |
|
} else if (ScanMode.compare("FLAT") == 0) { |
2450 |
|
id = db->AddInstruments(FLAT, DbDir, FsDir, bBackground); |
2451 |
|
} else { |
2452 |
|
throw Exception("Unknown scan mode: " + ScanMode); |
2453 |
|
} |
2454 |
|
|
2455 |
|
if (bBackground) result = id; |
2456 |
|
} catch (Exception e) { |
2457 |
|
result.Error(e); |
2458 |
|
} |
2459 |
|
#else |
2460 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2461 |
|
#endif |
2462 |
|
return result.Produce(); |
2463 |
|
} |
2464 |
|
|
2465 |
|
String LSCPServer::RemoveDbInstrument(String Instr) { |
2466 |
|
dmsg(2,("LSCPServer: RemoveDbInstrument(Instr=%s)\n", Instr.c_str())); |
2467 |
|
LSCPResultSet result; |
2468 |
|
#if HAVE_SQLITE3 |
2469 |
|
try { |
2470 |
|
InstrumentsDb::GetInstrumentsDb()->RemoveInstrument(Instr); |
2471 |
|
} catch (Exception e) { |
2472 |
|
result.Error(e); |
2473 |
|
} |
2474 |
|
#else |
2475 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2476 |
|
#endif |
2477 |
|
return result.Produce(); |
2478 |
|
} |
2479 |
|
|
2480 |
|
String LSCPServer::GetDbInstrumentCount(String Dir, bool Recursive) { |
2481 |
|
dmsg(2,("LSCPServer: GetDbInstrumentCount(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2482 |
|
LSCPResultSet result; |
2483 |
|
#if HAVE_SQLITE3 |
2484 |
|
try { |
2485 |
|
result.Add(InstrumentsDb::GetInstrumentsDb()->GetInstrumentCount(Dir, Recursive)); |
2486 |
|
} catch (Exception e) { |
2487 |
|
result.Error(e); |
2488 |
|
} |
2489 |
|
#else |
2490 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2491 |
|
#endif |
2492 |
|
return result.Produce(); |
2493 |
|
} |
2494 |
|
|
2495 |
|
String LSCPServer::GetDbInstruments(String Dir, bool Recursive) { |
2496 |
|
dmsg(2,("LSCPServer: GetDbInstruments(Dir=%s,Recursive=%d)\n", Dir.c_str(), Recursive)); |
2497 |
|
LSCPResultSet result; |
2498 |
|
#if HAVE_SQLITE3 |
2499 |
|
try { |
2500 |
|
String list; |
2501 |
|
StringListPtr instrs = InstrumentsDb::GetInstrumentsDb()->GetInstruments(Dir, Recursive); |
2502 |
|
|
2503 |
|
for (int i = 0; i < instrs->size(); i++) { |
2504 |
|
if (list != "") list += ","; |
2505 |
|
list += "'" + instrs->at(i) + "'"; |
2506 |
|
} |
2507 |
|
|
2508 |
|
result.Add(list); |
2509 |
|
} catch (Exception e) { |
2510 |
|
result.Error(e); |
2511 |
|
} |
2512 |
|
#else |
2513 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2514 |
|
#endif |
2515 |
|
return result.Produce(); |
2516 |
} |
} |
2517 |
|
|
2518 |
String LSCPServer::QueryDatabase(String query) { |
String LSCPServer::GetDbInstrumentInfo(String Instr) { |
2519 |
|
dmsg(2,("LSCPServer: GetDbInstrumentInfo(Instr=%s)\n", Instr.c_str())); |
2520 |
LSCPResultSet result; |
LSCPResultSet result; |
2521 |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
2522 |
char* zErrMsg = NULL; |
try { |
2523 |
sqlite3 *db; |
DbInstrument info = InstrumentsDb::GetInstrumentsDb()->GetInstrumentInfo(Instr); |
|
String selectStr = "SELECT " + query; |
|
2524 |
|
|
2525 |
int rc = sqlite3_open("linuxsampler.db", &db); |
result.Add("INSTRUMENT_FILE", info.InstrFile); |
2526 |
if (rc == SQLITE_OK) |
result.Add("INSTRUMENT_NR", info.InstrNr); |
2527 |
{ |
result.Add("FORMAT_FAMILY", info.FormatFamily); |
2528 |
rc = sqlite3_exec(db, selectStr.c_str(), select_callback, &result, &zErrMsg); |
result.Add("FORMAT_VERSION", info.FormatVersion); |
2529 |
|
result.Add("SIZE", (int)info.Size); |
2530 |
|
result.Add("CREATED", info.Created); |
2531 |
|
result.Add("MODIFIED", info.Modified); |
2532 |
|
result.Add("DESCRIPTION", FilterEndlines(info.Description)); |
2533 |
|
result.Add("IS_DRUM", info.IsDrum); |
2534 |
|
result.Add("PRODUCT", FilterEndlines(info.Product)); |
2535 |
|
result.Add("ARTISTS", FilterEndlines(info.Artists)); |
2536 |
|
result.Add("KEYWORDS", FilterEndlines(info.Keywords)); |
2537 |
|
} catch (Exception e) { |
2538 |
|
result.Error(e); |
2539 |
} |
} |
2540 |
if ( rc != SQLITE_OK ) |
#else |
2541 |
{ |
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2542 |
result.Error(String(zErrMsg), rc); |
#endif |
2543 |
|
return result.Produce(); |
2544 |
|
} |
2545 |
|
|
2546 |
|
String LSCPServer::GetDbInstrumentsJobInfo(int JobId) { |
2547 |
|
dmsg(2,("LSCPServer: GetDbInstrumentsJobInfo(JobId=%d)\n", JobId)); |
2548 |
|
LSCPResultSet result; |
2549 |
|
#if HAVE_SQLITE3 |
2550 |
|
try { |
2551 |
|
ScanJob job = InstrumentsDb::GetInstrumentsDb()->Jobs.GetJobById(JobId); |
2552 |
|
|
2553 |
|
result.Add("FILES_TOTAL", job.FilesTotal); |
2554 |
|
result.Add("FILES_SCANNED", job.FilesScanned); |
2555 |
|
result.Add("SCANNING", job.Scanning); |
2556 |
|
result.Add("STATUS", job.Status); |
2557 |
|
} catch (Exception e) { |
2558 |
|
result.Error(e); |
2559 |
} |
} |
|
sqlite3_close(db); |
|
2560 |
#else |
#else |
2561 |
result.Error(String("SQLITE3 was not installed when linuxsampler was built. SELECT statement is not available."), 0); |
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2562 |
#endif |
#endif |
2563 |
return result.Produce(); |
return result.Produce(); |
2564 |
} |
} |
2565 |
|
|
2566 |
|
String LSCPServer::SetDbInstrumentName(String Instr, String Name) { |
2567 |
|
dmsg(2,("LSCPServer: SetDbInstrumentName(Instr=%s,Name=%s)\n", Instr.c_str(), Name.c_str())); |
2568 |
|
LSCPResultSet result; |
2569 |
|
#if HAVE_SQLITE3 |
2570 |
|
try { |
2571 |
|
InstrumentsDb::GetInstrumentsDb()->RenameInstrument(Instr, Name); |
2572 |
|
} catch (Exception e) { |
2573 |
|
result.Error(e); |
2574 |
|
} |
2575 |
|
#else |
2576 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2577 |
|
#endif |
2578 |
|
return result.Produce(); |
2579 |
|
} |
2580 |
|
|
2581 |
|
String LSCPServer::MoveDbInstrument(String Instr, String Dst) { |
2582 |
|
dmsg(2,("LSCPServer: MoveDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str())); |
2583 |
|
LSCPResultSet result; |
2584 |
|
#if HAVE_SQLITE3 |
2585 |
|
try { |
2586 |
|
InstrumentsDb::GetInstrumentsDb()->MoveInstrument(Instr, Dst); |
2587 |
|
} catch (Exception e) { |
2588 |
|
result.Error(e); |
2589 |
|
} |
2590 |
|
#else |
2591 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2592 |
|
#endif |
2593 |
|
return result.Produce(); |
2594 |
|
} |
2595 |
|
|
2596 |
|
String LSCPServer::CopyDbInstrument(String Instr, String Dst) { |
2597 |
|
dmsg(2,("LSCPServer: CopyDbInstrument(Instr=%s,Dst=%s)\n", Instr.c_str(), Dst.c_str())); |
2598 |
|
LSCPResultSet result; |
2599 |
|
#if HAVE_SQLITE3 |
2600 |
|
try { |
2601 |
|
InstrumentsDb::GetInstrumentsDb()->CopyInstrument(Instr, Dst); |
2602 |
|
} catch (Exception e) { |
2603 |
|
result.Error(e); |
2604 |
|
} |
2605 |
|
#else |
2606 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2607 |
|
#endif |
2608 |
|
return result.Produce(); |
2609 |
|
} |
2610 |
|
|
2611 |
|
String LSCPServer::SetDbInstrumentDescription(String Instr, String Desc) { |
2612 |
|
dmsg(2,("LSCPServer: SetDbInstrumentDescription(Instr=%s,Desc=%s)\n", Instr.c_str(), Desc.c_str())); |
2613 |
|
LSCPResultSet result; |
2614 |
|
#if HAVE_SQLITE3 |
2615 |
|
try { |
2616 |
|
InstrumentsDb::GetInstrumentsDb()->SetInstrumentDescription(Instr, Desc); |
2617 |
|
} catch (Exception e) { |
2618 |
|
result.Error(e); |
2619 |
|
} |
2620 |
|
#else |
2621 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2622 |
|
#endif |
2623 |
|
return result.Produce(); |
2624 |
|
} |
2625 |
|
|
2626 |
|
String LSCPServer::FindDbInstrumentDirectories(String Dir, std::map<String,String> Parameters, bool Recursive) { |
2627 |
|
dmsg(2,("LSCPServer: FindDbInstrumentDirectories(Dir=%s)\n", Dir.c_str())); |
2628 |
|
LSCPResultSet result; |
2629 |
|
#if HAVE_SQLITE3 |
2630 |
|
try { |
2631 |
|
SearchQuery Query; |
2632 |
|
std::map<String,String>::iterator iter; |
2633 |
|
for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { |
2634 |
|
if (iter->first.compare("NAME") == 0) { |
2635 |
|
Query.Name = iter->second; |
2636 |
|
} else if (iter->first.compare("CREATED") == 0) { |
2637 |
|
Query.SetCreated(iter->second); |
2638 |
|
} else if (iter->first.compare("MODIFIED") == 0) { |
2639 |
|
Query.SetModified(iter->second); |
2640 |
|
} else if (iter->first.compare("DESCRIPTION") == 0) { |
2641 |
|
Query.Description = iter->second; |
2642 |
|
} else { |
2643 |
|
throw Exception("Unknown search criteria: " + iter->first); |
2644 |
|
} |
2645 |
|
} |
2646 |
|
|
2647 |
|
String list; |
2648 |
|
StringListPtr pDirectories = |
2649 |
|
InstrumentsDb::GetInstrumentsDb()->FindDirectories(Dir, &Query, Recursive); |
2650 |
|
|
2651 |
|
for (int i = 0; i < pDirectories->size(); i++) { |
2652 |
|
if (list != "") list += ","; |
2653 |
|
list += "'" + pDirectories->at(i) + "'"; |
2654 |
|
} |
2655 |
|
|
2656 |
|
result.Add(list); |
2657 |
|
} catch (Exception e) { |
2658 |
|
result.Error(e); |
2659 |
|
} |
2660 |
|
#else |
2661 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2662 |
|
#endif |
2663 |
|
return result.Produce(); |
2664 |
|
} |
2665 |
|
|
2666 |
|
String LSCPServer::FindDbInstruments(String Dir, std::map<String,String> Parameters, bool Recursive) { |
2667 |
|
dmsg(2,("LSCPServer: FindDbInstruments(Dir=%s)\n", Dir.c_str())); |
2668 |
|
LSCPResultSet result; |
2669 |
|
#if HAVE_SQLITE3 |
2670 |
|
try { |
2671 |
|
SearchQuery Query; |
2672 |
|
std::map<String,String>::iterator iter; |
2673 |
|
for (iter = Parameters.begin(); iter != Parameters.end(); iter++) { |
2674 |
|
if (iter->first.compare("NAME") == 0) { |
2675 |
|
Query.Name = iter->second; |
2676 |
|
} else if (iter->first.compare("FORMAT_FAMILIES") == 0) { |
2677 |
|
Query.SetFormatFamilies(iter->second); |
2678 |
|
} else if (iter->first.compare("SIZE") == 0) { |
2679 |
|
Query.SetSize(iter->second); |
2680 |
|
} else if (iter->first.compare("CREATED") == 0) { |
2681 |
|
Query.SetCreated(iter->second); |
2682 |
|
} else if (iter->first.compare("MODIFIED") == 0) { |
2683 |
|
Query.SetModified(iter->second); |
2684 |
|
} else if (iter->first.compare("DESCRIPTION") == 0) { |
2685 |
|
Query.Description = iter->second; |
2686 |
|
} else if (iter->first.compare("IS_DRUM") == 0) { |
2687 |
|
if (!strcasecmp(iter->second.c_str(), "true")) { |
2688 |
|
Query.InstrType = SearchQuery::DRUM; |
2689 |
|
} else { |
2690 |
|
Query.InstrType = SearchQuery::CHROMATIC; |
2691 |
|
} |
2692 |
|
} else if (iter->first.compare("PRODUCT") == 0) { |
2693 |
|
Query.Product = iter->second; |
2694 |
|
} else if (iter->first.compare("ARTISTS") == 0) { |
2695 |
|
Query.Artists = iter->second; |
2696 |
|
} else if (iter->first.compare("KEYWORDS") == 0) { |
2697 |
|
Query.Keywords = iter->second; |
2698 |
|
} else { |
2699 |
|
throw Exception("Unknown search criteria: " + iter->first); |
2700 |
|
} |
2701 |
|
} |
2702 |
|
|
2703 |
|
String list; |
2704 |
|
StringListPtr pInstruments = |
2705 |
|
InstrumentsDb::GetInstrumentsDb()->FindInstruments(Dir, &Query, Recursive); |
2706 |
|
|
2707 |
|
for (int i = 0; i < pInstruments->size(); i++) { |
2708 |
|
if (list != "") list += ","; |
2709 |
|
list += "'" + pInstruments->at(i) + "'"; |
2710 |
|
} |
2711 |
|
|
2712 |
|
result.Add(list); |
2713 |
|
} catch (Exception e) { |
2714 |
|
result.Error(e); |
2715 |
|
} |
2716 |
|
#else |
2717 |
|
result.Error(String(DOESNT_HAVE_SQLITE3), 0); |
2718 |
|
#endif |
2719 |
|
return result.Produce(); |
2720 |
|
} |
2721 |
|
|
2722 |
|
|
2723 |
/** |
/** |
2724 |
* Will be called by the parser to enable or disable echo mode; if echo |
* Will be called by the parser to enable or disable echo mode; if echo |
2725 |
* mode is enabled, all commands from the client will (immediately) be |
* mode is enabled, all commands from the client will (immediately) be |
2738 |
} |
} |
2739 |
return result.Produce(); |
return result.Produce(); |
2740 |
} |
} |
2741 |
|
|
2742 |
|
String LSCPServer::FilterEndlines(String s) { |
2743 |
|
String s2 = s; |
2744 |
|
for (int i = 0; i < s2.length(); i++) { |
2745 |
|
if (s2.at(i) == '\r') s2.at(i) = ' '; |
2746 |
|
else if (s2.at(i) == '\n') s2.at(i) = ' '; |
2747 |
|
} |
2748 |
|
|
2749 |
|
return s2; |
2750 |
|
} |