Showing the changes to interface/src/scripting/AudioDeviceScriptingInterface.cpp (1 of 7 files). Show all
Unified · Split
| @@ -11,21 +11,19 @@ · 10 unmodified lines | |||
| 11 | 11 | ||
| 12 | #include "AudioClient.h" | 12 | #include "AudioClient.h" |
| 13 | #include "AudioDeviceScriptingInterface.h" | 13 | #include "AudioDeviceScriptingInterface.h" |
| 14 | 14 | #include "SettingsScriptingInterface.h" | |
| 15 | 15 | ||
| 16 | AudioDeviceScriptingInterface* AudioDeviceScriptingInterface::getInstance() { | 16 | AudioDeviceScriptingInterface* AudioDeviceScriptingInterface::getInstance() { |
| 17 | static AudioDeviceScriptingInterface sharedInstance; | 17 | static AudioDeviceScriptingInterface sharedInstance; |
| 18 | return &sharedInstance; | 18 | return &sharedInstance; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | QStringList AudioDeviceScriptingInterface::inputAudioDevices() const | 21 | QStringList AudioDeviceScriptingInterface::inputAudioDevices() const { |
| 22 | { | 22 | return _inputAudioDevices; |
| 23 | return DependencyManager::get<AudioClient>()->getDeviceNames(QAudio::AudioInput).toList();; | ||
| 24 | } | 23 | } |
| 25 | 24 | ||
| 26 | QStringList AudioDeviceScriptingInterface::outputAudioDevices() const | 25 | QStringList AudioDeviceScriptingInterface::outputAudioDevices() const { |
| 27 | { | 26 | return _outputAudioDevices; |
| 28 | return DependencyManager::get<AudioClient>()->getDeviceNames(QAudio::AudioOutput).toList();; | ||
| 29 | } | 27 | } |
| 30 | 28 | ||
| 31 | bool AudioDeviceScriptingInterface::muted() | 29 | bool AudioDeviceScriptingInterface::muted() |
| @@ -44,6 +42,16 @@ AudioDeviceScriptingInterface::AudioDeviceScriptingInterface(): QAbstractListMod · 12 unmodified lines | |||
| 44 | this, &AudioDeviceScriptingInterface::onCurrentOutputDeviceChanged, Qt::QueuedConnection); | 42 | this, &AudioDeviceScriptingInterface::onCurrentOutputDeviceChanged, Qt::QueuedConnection); |
| 45 | //fill up model | 43 | //fill up model |
| 46 | onDeviceChanged(); | 44 | onDeviceChanged(); |
| 45 | //set up previously saved device | ||
| 46 | SettingsScriptingInterface *settings = SettingsScriptingInterface::getInstance(); | ||
| 47 | const QString inDevice = settings->getValue("audio_input_device").toString(); | ||
| 48 | if (inDevice != _currentInputDevice) { | ||
| 49 | setInputDeviceAsync(inDevice); | ||
| 50 | } | ||
| 51 | const QString outDevice = settings->getValue("audio_output_device").toString(); | ||
| 52 | if (outDevice != _currentOutputDevice) { | ||
| 53 | setOutputDeviceAsync(outDevice); | ||
| 54 | } | ||
| 47 | } | 55 | } |
| 48 | 56 | ||
| 49 | bool AudioDeviceScriptingInterface::setInputDevice(const QString& deviceName) { | 57 | bool AudioDeviceScriptingInterface::setInputDevice(const QString& deviceName) { |
| @@ -64,6 +72,31 @@ bool AudioDeviceScriptingInterface::setOutputDevice(const QString& deviceName) { · 14 unmodified lines | |||
| 64 | return result; | 72 | return result; |
| 65 | } | 73 | } |
| 66 | 74 | ||
| 75 | bool AudioDeviceScriptingInterface::setDeviceFromMenu(const QString &deviceMenuName) { | ||
| 76 | QAudio::Mode mode; | ||
| 77 | |||
| 78 | if (deviceMenuName.indexOf("for Output") != -1) { | ||
| 79 | mode = QAudio::AudioOutput; | ||
| 80 | } else if (deviceMenuName.indexOf("for Input") != -1) { | ||
| 81 | mode = QAudio::AudioInput; | ||
| 82 | } else { | ||
| 83 | return false; | ||
| 84 | } | ||
| 85 | |||
| 86 | for (ScriptingAudioDeviceInfo di: _devices) { | ||
| 87 | if (mode == di.mode && deviceMenuName.contains(di.name)) { | ||
| 88 | if (mode == QAudio::AudioOutput) { | ||
| 89 | setOutputDeviceAsync(di.name); | ||
| 90 | } else { | ||
| 91 | setInputDeviceAsync(di.name); | ||
| 92 | } | ||
| 93 | return true; | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | return false; | ||
| 98 | } | ||
| 99 | |||
| 67 | void AudioDeviceScriptingInterface::setInputDeviceAsync(const QString& deviceName) { | 100 | void AudioDeviceScriptingInterface::setInputDeviceAsync(const QString& deviceName) { |
| 68 | QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), "switchInputToAudioDevice", | 101 | QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(), "switchInputToAudioDevice", |
| 69 | Qt::QueuedConnection, | 102 | Qt::QueuedConnection, |
| @@ -167,38 +200,51 @@ QHash<int, QByteArray> AudioDeviceScriptingInterface::roleNames() const { · 97 unmodified lines | |||
| 167 | void AudioDeviceScriptingInterface::onDeviceChanged() | 200 | void AudioDeviceScriptingInterface::onDeviceChanged() |
| 168 | { | 201 | { |
| 169 | beginResetModel(); | 202 | beginResetModel(); |
| 203 | _outputAudioDevices.clear(); | ||
| 170 | _devices.clear(); | 204 | _devices.clear(); |
| 171 | const QString &outDevice = getOutputDevice(); | 205 | _currentOutputDevice = getOutputDevice(); |
| 172 | for (QString name: getOutputDevices()) { | 206 | for (QString name: getOutputDevices()) { |
| 173 | AudioDeviceInfo di; | 207 | ScriptingAudioDeviceInfo di; |
| 174 | di.name = name; | 208 | di.name = name; |
| 175 | di.selected = (name == outDevice); | 209 | di.selected = (name == _currentOutputDevice); |
| 176 | di.mode = QAudio::AudioOutput; | 210 | di.mode = QAudio::AudioOutput; |
| 177 | _devices.append(di); | 211 | _devices.append(di); |
| 212 | _outputAudioDevices.append(name); | ||
| 178 | } | 213 | } |
| 179 | const QString &inDevice = getInputDevice(); | 214 | emit outputAudioDevicesChanged(_outputAudioDevices); |
| 215 | |||
| 216 | _inputAudioDevices.clear(); | ||
| 217 | _currentInputDevice = getInputDevice(); | ||
| 180 | for (QString name: getInputDevices()) { | 218 | for (QString name: getInputDevices()) { |
| 181 | AudioDeviceInfo di; | 219 | ScriptingAudioDeviceInfo di; |
| 182 | di.name = name; | 220 | di.name = name; |
| 183 | di.selected = (name == inDevice); | 221 | di.selected = (name == _currentInputDevice); |
| 184 | di.mode = QAudio::AudioInput; | 222 | di.mode = QAudio::AudioInput; |
| 185 | _devices.append(di); | 223 | _devices.append(di); |
| 224 | _inputAudioDevices.append(name); | ||
| 186 | } | 225 | } |
| 226 | emit inputAudioDevicesChanged(_inputAudioDevices); | ||
| 187 | 227 | ||
| 188 | endResetModel(); | 228 | endResetModel(); |
| 189 | emit deviceChanged(); | 229 | emit deviceChanged(); |
| 190 | } | 230 | } |
| 191 | 231 | ||
| 192 | void AudioDeviceScriptingInterface::onCurrentInputDeviceChanged() | 232 | void AudioDeviceScriptingInterface::onCurrentInputDeviceChanged(const QString &name) |
| 193 | { | 233 | { |
| 194 | currentDeviceUpdate(getInputDevice(), QAudio::AudioInput); | 234 | currentDeviceUpdate(name, QAudio::AudioInput); |
| 195 | emit currentInputDeviceChanged(); | 235 | //we got a signal that device changed. Save it now |
| 236 | SettingsScriptingInterface *settings = SettingsScriptingInterface::getInstance(); | ||
| 237 | settings->setValue("audio_input_device", name); | ||
| 238 | emit currentInputDeviceChanged(name); | ||
| 196 | } | 239 | } |
| 197 | 240 | ||
| 198 | void AudioDeviceScriptingInterface::onCurrentOutputDeviceChanged() | 241 | void AudioDeviceScriptingInterface::onCurrentOutputDeviceChanged(const QString &name) |
| 199 | { | 242 | { |
| 200 | currentDeviceUpdate(getOutputDevice(), QAudio::AudioOutput); | 243 | currentDeviceUpdate(name, QAudio::AudioOutput); |
| 201 | emit currentOutputDeviceChanged(); | 244 | //we got a signal that device changed. Save it now |
| 245 | SettingsScriptingInterface *settings = SettingsScriptingInterface::getInstance(); | ||
| 246 | settings->setValue("audio_output_device", name); | ||
| 247 | emit currentOutputDeviceChanged(name); | ||
| 202 | } | 248 | } |
| 203 | 249 | ||
| 204 | void AudioDeviceScriptingInterface::currentDeviceUpdate(const QString &name, QAudio::Mode mode) | 250 | void AudioDeviceScriptingInterface::currentDeviceUpdate(const QString &name, QAudio::Mode mode) |
| @@ -207,7 +253,7 @@ void AudioDeviceScriptingInterface::currentDeviceUpdate(const QString &name, QAu · 2 unmodified lines | |||
| 207 | role.append(SelectedRole); | 253 | role.append(SelectedRole); |
| 208 | 254 | ||
| 209 | for (int i = 0; i < _devices.size(); i++) { | 255 | for (int i = 0; i < _devices.size(); i++) { |
| 210 | AudioDeviceInfo di = _devices.at(i); | 256 | ScriptingAudioDeviceInfo di = _devices.at(i); |
| 211 | if (di.mode != mode) | 257 | if (di.mode != mode) |
| 212 | continue; | 258 | continue; |
| 213 | if (di.selected && di.name != name ) { | 259 | if (di.selected && di.name != name ) { |