MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / loadJson

Method loadJson

source/frontend/StarVoice.cpp:186–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

184}
185
186void Voice::loadJson(Json const& config, bool skipSave) {
187 // Not all keys are required
188
189 bool changed = false;
190 bool shouldResetDevice = false;
191 {
192 bool enabled = shouldEnableInput();
193 m_enabled = config.getBool("enabled", m_enabled);
194 m_inputEnabled = config.getBool("inputEnabled", m_inputEnabled);
195 if (shouldEnableInput() != enabled)
196 shouldResetDevice = changed = true;
197 }
198
199 if (config.contains("deviceName") // Make sure null-type key exists
200 && change(m_deviceName, config.optString("deviceName"), changed))
201 shouldResetDevice = true;
202
203 m_threshold = config.getFloat("threshold", m_threshold);
204 m_inputAmplitude = perceptualToAmplitude(
205 m_inputVolume = config.getFloat("inputVolume", m_inputVolume));
206 m_outputAmplitude = perceptualToAmplitude(
207 m_outputVolume = config.getFloat("outputVolume", m_outputVolume));
208
209 if (change(m_loopback, config.getBool("loopback", m_loopback), changed))
210 m_clientSpeaker->playing = false;
211
212 if (auto inputMode = config.optString("inputMode")) {
213 if (change(m_inputMode, VoiceInputModeNames.getLeft(*inputMode), changed))
214 m_lastInputTime = 0;
215 }
216
217 bool shouldResetEncoder = false;
218 if (auto channelMode = config.optString("channelMode")) {
219 if (change(m_channelMode, VoiceChannelModeNames.getLeft(*channelMode), changed)) {
220 closeDevice();
221 shouldResetEncoder = true;
222 shouldResetDevice = true;
223 }
224 }
225
226 // not saving this setting to disk, as it's just for audiophiles
227 // don't want someone fudging their bitrate from the intended defaults and forgetting
228 if (auto bitrate = config.opt("bitrate")) {
229 unsigned newBitrate = bitrate->canConvert(Json::Type::Int)
230 ? clamp((unsigned)bitrate->toUInt(), 6000u, 510000u) : 0;
231 shouldResetEncoder |= change(m_bitrate, newBitrate, changed);
232 }
233
234 if (shouldResetEncoder)
235 resetEncoder();
236
237 if (shouldResetDevice)
238 resetDevice();
239
240 if (changed && !skipSave)
241 scheduleSave();
242}
243

Callers 3

makeVoiceCallbacksMethod · 0.45
ChatBubbleManagerMethod · 0.45
addChatActionsMethod · 0.45

Calls 10

changeFunction · 0.85
perceptualToAmplitudeFunction · 0.85
clampFunction · 0.85
getBoolMethod · 0.80
optStringMethod · 0.80
getFloatMethod · 0.80
canConvertMethod · 0.80
toUIntMethod · 0.80
containsMethod · 0.45
optMethod · 0.45

Tested by

no test coverage detected