| 184 | } |
| 185 | |
| 186 | void 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 |
no test coverage detected