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 * |
75 |
LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_stream_count, "STREAM_COUNT"); |
76 |
LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_buffer_fill, "BUFFER_FILL"); |
77 |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_channel_info, "CHANNEL_INFO"); |
78 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_fx_send_count, "FX_SEND_COUNT"); |
79 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_fx_send_info, "FX_SEND_INFO"); |
80 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_count, "MIDI_INSTRUMENT_MAP_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_count, "MIDI_INSTRUMENT_MAP_COUNT"); |
81 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_map_info, "MIDI_INSTRUMENT_MAP_INFO"); |
82 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_count, "MIDI_INSTRUMENT_COUNT"); |
83 |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_midi_instr_info, "MIDI_INSTRUMENT_INFO"); |
84 |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_misc, "MISCELLANEOUS"); |
85 |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
LSCPEvent::RegisterEvent(LSCPEvent::event_total_voice_count, "TOTAL_VOICE_COUNT"); |
86 |
|
LSCPEvent::RegisterEvent(LSCPEvent::event_global_info, "GLOBAL_INFO"); |
87 |
hSocket = -1; |
hSocket = -1; |
88 |
} |
} |
89 |
|
|
91 |
if (hSocket >= 0) close(hSocket); |
if (hSocket >= 0) close(hSocket); |
92 |
} |
} |
93 |
|
|
94 |
|
void LSCPServer::LscpChannelCountListener::ChannelCountChanged(int NewCount) { |
95 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_count, NewCount)); |
96 |
|
} |
97 |
|
|
98 |
|
void LSCPServer::LscpAudioDeviceCountListener::AudioDeviceCountChanged(int NewCount) { |
99 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_audio_device_count, NewCount)); |
100 |
|
} |
101 |
|
|
102 |
|
void LSCPServer::LscpMidiDeviceCountListener::MidiDeviceCountChanged(int NewCount) { |
103 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_device_count, NewCount)); |
104 |
|
} |
105 |
|
|
106 |
|
void LSCPServer::LscpMidiInstrumentCountListener::MidiInstrumentCountChanged(int MapId, int NewCount) { |
107 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_count, MapId, NewCount)); |
108 |
|
} |
109 |
|
|
110 |
|
void LSCPServer::LscpMidiInstrumentInfoListener::MidiInstrumentInfoChanged(int MapId, int Bank, int Program) { |
111 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_info, MapId, Bank, Program)); |
112 |
|
} |
113 |
|
|
114 |
|
void LSCPServer::LscpMidiInstrumentMapCountListener::MidiInstrumentMapCountChanged(int NewCount) { |
115 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_count, NewCount)); |
116 |
|
} |
117 |
|
|
118 |
|
void LSCPServer::LscpMidiInstrumentMapInfoListener::MidiInstrumentMapInfoChanged(int MapId) { |
119 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_midi_instr_map_info, MapId)); |
120 |
|
} |
121 |
|
|
122 |
|
void LSCPServer::LscpFxSendCountListener::FxSendCountChanged(int ChannelId, int NewCount) { |
123 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_count, ChannelId, NewCount)); |
124 |
|
} |
125 |
|
|
126 |
|
void LSCPServer::LscpVoiceCountListener::VoiceCountChanged(int ChannelId, int NewCount) { |
127 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_voice_count, ChannelId, NewCount)); |
128 |
|
} |
129 |
|
|
130 |
|
void LSCPServer::LscpStreamCountListener::StreamCountChanged(int ChannelId, int NewCount) { |
131 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_stream_count, ChannelId, NewCount)); |
132 |
|
} |
133 |
|
|
134 |
|
void LSCPServer::LscpBufferFillListener::BufferFillChanged(int ChannelId, String FillData) { |
135 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_buffer_fill, ChannelId, FillData)); |
136 |
|
} |
137 |
|
|
138 |
|
void LSCPServer::LscpTotalVoiceCountListener::TotalVoiceCountChanged(int NewCount) { |
139 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_total_voice_count, NewCount)); |
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
/** |
/** |
144 |
* Blocks the calling thread until the LSCP Server is initialized and |
* Blocks the calling thread until the LSCP Server is initialized and |
145 |
* accepting socket connections, if the server is already initialized then |
* accepting socket connections, if the server is already initialized then |
180 |
|
|
181 |
listen(hSocket, 1); |
listen(hSocket, 1); |
182 |
Initialized.Set(true); |
Initialized.Set(true); |
183 |
|
|
184 |
|
// Registering event listeners |
185 |
|
pSampler->AddChannelCountListener(&channelCountListener); |
186 |
|
pSampler->AddAudioDeviceCountListener(&audioDeviceCountListener); |
187 |
|
pSampler->AddMidiDeviceCountListener(&midiDeviceCountListener); |
188 |
|
pSampler->AddVoiceCountListener(&voiceCountListener); |
189 |
|
pSampler->AddStreamCountListener(&streamCountListener); |
190 |
|
pSampler->AddBufferFillListener(&bufferFillListener); |
191 |
|
pSampler->AddTotalVoiceCountListener(&totalVoiceCountListener); |
192 |
|
pSampler->AddFxSendCountListener(&fxSendCountListener); |
193 |
|
MidiInstrumentMapper::AddMidiInstrumentCountListener(&midiInstrumentCountListener); |
194 |
|
MidiInstrumentMapper::AddMidiInstrumentInfoListener(&midiInstrumentInfoListener); |
195 |
|
MidiInstrumentMapper::AddMidiInstrumentMapCountListener(&midiInstrumentMapCountListener); |
196 |
|
MidiInstrumentMapper::AddMidiInstrumentMapInfoListener(&midiInstrumentMapInfoListener); |
197 |
|
|
198 |
// now wait for client connections and handle their requests |
// now wait for client connections and handle their requests |
199 |
sockaddr_in client; |
sockaddr_in client; |
214 |
if ((*itEngineChannel)->StatusChanged()) { |
if ((*itEngineChannel)->StatusChanged()) { |
215 |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
SendLSCPNotify(LSCPEvent(LSCPEvent::event_channel_info, (*itEngineChannel)->iSamplerChannelIndex)); |
216 |
} |
} |
217 |
|
|
218 |
|
for (int i = 0; i < (*itEngineChannel)->GetFxSendCount(); i++) { |
219 |
|
FxSend* fxs = (*itEngineChannel)->GetFxSend(i); |
220 |
|
if(fxs != NULL && fxs->IsInfoChanged()) { |
221 |
|
int chn = (*itEngineChannel)->iSamplerChannelIndex; |
222 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, chn, fxs->Id())); |
223 |
|
fxs->SetInfoChanged(false); |
224 |
|
} |
225 |
|
} |
226 |
} |
} |
227 |
} |
} |
228 |
|
|
745 |
String AudioRouting; |
String AudioRouting; |
746 |
int Mute = 0; |
int Mute = 0; |
747 |
bool Solo = false; |
bool Solo = false; |
748 |
String MidiInstrumentMap; |
String MidiInstrumentMap = "NONE"; |
749 |
|
|
750 |
if (pEngineChannel) { |
if (pEngineChannel) { |
751 |
EngineName = pEngineChannel->EngineName(); |
EngineName = pEngineChannel->EngineName(); |
1577 |
|
|
1578 |
bool oldSolo = pEngineChannel->GetSolo(); |
bool oldSolo = pEngineChannel->GetSolo(); |
1579 |
bool hadSoloChannel = HasSoloChannel(); |
bool hadSoloChannel = HasSoloChannel(); |
1580 |
|
|
1581 |
pEngineChannel->SetSolo(bSolo); |
pEngineChannel->SetSolo(bSolo); |
1582 |
|
|
1583 |
if(!oldSolo && bSolo) { |
if(!oldSolo && bSolo) { |
1584 |
if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0); |
if(pEngineChannel->GetMute() == -1) pEngineChannel->SetMute(0); |
1585 |
if(!hadSoloChannel) MuteNonSoloChannels(); |
if(!hadSoloChannel) MuteNonSoloChannels(); |
1586 |
} |
} |
1587 |
|
|
1588 |
if(oldSolo && !bSolo) { |
if(oldSolo && !bSolo) { |
1589 |
if(!HasSoloChannel()) UnmuteChannels(); |
if(!HasSoloChannel()) UnmuteChannels(); |
1590 |
else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1); |
else if(!pEngineChannel->GetMute()) pEngineChannel->SetMute(-1); |
1642 |
} |
} |
1643 |
} |
} |
1644 |
|
|
1645 |
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) { |
1646 |
dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n")); |
dmsg(2,("LSCPServer: AddOrReplaceMIDIInstrumentMapping()\n")); |
1647 |
|
|
1648 |
midi_prog_index_t idx; |
midi_prog_index_t idx; |
1660 |
|
|
1661 |
LSCPResultSet result; |
LSCPResultSet result; |
1662 |
try { |
try { |
1663 |
// PERSISTENT mapping commands might bloock for a long time, so in |
// PERSISTENT mapping commands might block for a long time, so in |
1664 |
// that case we add/replace the mapping in another thread |
// that case we add/replace the mapping in another thread in case |
1665 |
bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT); |
// the NON_MODAL argument was supplied, non persistent mappings |
1666 |
|
// should return immediately, so we don't need to do that for them |
1667 |
|
bool bInBackground = (entry.LoadMode == MidiInstrumentMapper::PERSISTENT && !bModal); |
1668 |
MidiInstrumentMapper::AddOrReplaceEntry(MidiMapID, idx, entry, bInBackground); |
MidiInstrumentMapper::AddOrReplaceEntry(MidiMapID, idx, entry, bInBackground); |
1669 |
} catch (Exception e) { |
} catch (Exception e) { |
1670 |
result.Error(e); |
result.Error(e); |
1775 |
for (; iter != mappings.end(); iter++) { |
for (; iter != mappings.end(); iter++) { |
1776 |
if (s.size()) s += ","; |
if (s.size()) s += ","; |
1777 |
s += "{" + ToString(MidiMapID) + "," |
s += "{" + ToString(MidiMapID) + "," |
1778 |
+ 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)) + "," |
1779 |
+ ToString(int(iter->first.midi_prog)) + "}"; |
+ ToString(int(iter->first.midi_prog)) + "}"; |
1780 |
} |
} |
1781 |
result.Add(s); |
result.Add(s); |
1797 |
for (; iter != mappings.end(); iter++) { |
for (; iter != mappings.end(); iter++) { |
1798 |
if (s.size()) s += ","; |
if (s.size()) s += ","; |
1799 |
s += "{" + ToString(maps[i]) + "," |
s += "{" + ToString(maps[i]) + "," |
1800 |
+ 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)) + "," |
1801 |
+ ToString(int(iter->first.midi_prog)) + "}"; |
+ ToString(int(iter->first.midi_prog)) + "}"; |
1802 |
} |
} |
1803 |
} |
} |
2056 |
|
|
2057 |
// success |
// success |
2058 |
result.Add("NAME", pFxSend->Name()); |
result.Add("NAME", pFxSend->Name()); |
2059 |
|
result.Add("MIDI_CONTROLLER", pFxSend->MidiController()); |
2060 |
|
result.Add("LEVEL", ToString(pFxSend->Level())); |
2061 |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
result.Add("AUDIO_OUTPUT_ROUTING", AudioRouting); |
2062 |
} catch (Exception e) { |
} catch (Exception e) { |
2063 |
result.Error(e); |
result.Error(e); |
2085 |
if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel"); |
if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel"); |
2086 |
|
|
2087 |
pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel); |
pFxSend->SetDestinationChannel(FxSendChannel, DeviceChannel); |
2088 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2089 |
|
} catch (Exception e) { |
2090 |
|
result.Error(e); |
2091 |
|
} |
2092 |
|
return result.Produce(); |
2093 |
|
} |
2094 |
|
|
2095 |
|
String LSCPServer::SetFxSendMidiController(uint uiSamplerChannel, uint FxSendID, uint MidiController) { |
2096 |
|
dmsg(2,("LSCPServer: SetFxSendMidiController()\n")); |
2097 |
|
LSCPResultSet result; |
2098 |
|
try { |
2099 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
2100 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
2101 |
|
|
2102 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
2103 |
|
if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); |
2104 |
|
|
2105 |
|
FxSend* pFxSend = NULL; |
2106 |
|
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
2107 |
|
if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) { |
2108 |
|
pFxSend = pEngineChannel->GetFxSend(i); |
2109 |
|
break; |
2110 |
|
} |
2111 |
|
} |
2112 |
|
if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel"); |
2113 |
|
|
2114 |
|
pFxSend->SetMidiController(MidiController); |
2115 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2116 |
|
} catch (Exception e) { |
2117 |
|
result.Error(e); |
2118 |
|
} |
2119 |
|
return result.Produce(); |
2120 |
|
} |
2121 |
|
|
2122 |
|
String LSCPServer::SetFxSendLevel(uint uiSamplerChannel, uint FxSendID, double dLevel) { |
2123 |
|
dmsg(2,("LSCPServer: SetFxSendLevel()\n")); |
2124 |
|
LSCPResultSet result; |
2125 |
|
try { |
2126 |
|
SamplerChannel* pSamplerChannel = pSampler->GetSamplerChannel(uiSamplerChannel); |
2127 |
|
if (!pSamplerChannel) throw Exception("Invalid sampler channel number " + ToString(uiSamplerChannel)); |
2128 |
|
|
2129 |
|
EngineChannel* pEngineChannel = pSamplerChannel->GetEngineChannel(); |
2130 |
|
if (!pEngineChannel) throw Exception("There is no engine deployed on this sampler channel yet"); |
2131 |
|
|
2132 |
|
FxSend* pFxSend = NULL; |
2133 |
|
for (int i = 0; i < pEngineChannel->GetFxSendCount(); i++) { |
2134 |
|
if (pEngineChannel->GetFxSend(i)->Id() == FxSendID) { |
2135 |
|
pFxSend = pEngineChannel->GetFxSend(i); |
2136 |
|
break; |
2137 |
|
} |
2138 |
|
} |
2139 |
|
if (!pFxSend) throw Exception("There is no FxSend with that ID on the given sampler channel"); |
2140 |
|
|
2141 |
|
pFxSend->SetLevel((float)dLevel); |
2142 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_fx_send_info, uiSamplerChannel, FxSendID)); |
2143 |
} catch (Exception e) { |
} catch (Exception e) { |
2144 |
result.Error(e); |
result.Error(e); |
2145 |
} |
} |
2219 |
try { |
try { |
2220 |
if (dVolume < 0) throw Exception("Volume may not be negative"); |
if (dVolume < 0) throw Exception("Volume may not be negative"); |
2221 |
GLOBAL_VOLUME = dVolume; // see common/global.cpp |
GLOBAL_VOLUME = dVolume; // see common/global.cpp |
2222 |
|
LSCPServer::SendLSCPNotify(LSCPEvent(LSCPEvent::event_global_info, "VOLUME", GLOBAL_VOLUME)); |
2223 |
} catch (Exception e) { |
} catch (Exception e) { |
2224 |
result.Error(e); |
result.Error(e); |
2225 |
} |
} |