diff --git a/interface/src/scripting/AudioDeviceScriptingInterface.cpp b/interface/src/scripting/AudioDeviceScriptingInterface.cpp deleted file mode 100644 index 51650b046f..0000000000 --- a/interface/src/scripting/AudioDeviceScriptingInterface.cpp +++ /dev/null @@ -1,273 +0,0 @@ -// -// AudioDeviceScriptingInterface.cpp -// interface/src/scripting -// -// Created by Brad Hefta-Gaub on 3/23/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include "AudioClient.h" -/* -#include "AudioDeviceScriptingInterface.h" -#include "SettingsScriptingInterface.h" - -AudioDeviceScriptingInterface* AudioDeviceScriptingInterface::getInstance() { - static AudioDeviceScriptingInterface sharedInstance; - return &sharedInstance; -} - -QStringList AudioDeviceScriptingInterface::inputAudioDevices() const { - return _inputAudioDevices; -} - -QStringList AudioDeviceScriptingInterface::outputAudioDevices() const { - return _outputAudioDevices; -} - -bool AudioDeviceScriptingInterface::muted() -{ - return getMuted(); -} - -AudioDeviceScriptingInterface::AudioDeviceScriptingInterface(): QAbstractListModel(nullptr) { - connect(DependencyManager::get().data(), &AudioClient::muteToggled, - this, &AudioDeviceScriptingInterface::muteToggled); - connect(DependencyManager::get().data(), &AudioClient::deviceChanged, - this, &AudioDeviceScriptingInterface::onDeviceChanged, Qt::QueuedConnection); - connect(DependencyManager::get().data(), &AudioClient::currentInputDeviceChanged, - this, &AudioDeviceScriptingInterface::onCurrentInputDeviceChanged, Qt::QueuedConnection); - connect(DependencyManager::get().data(), &AudioClient::currentOutputDeviceChanged, - this, &AudioDeviceScriptingInterface::onCurrentOutputDeviceChanged, Qt::QueuedConnection); - //fill up model - onDeviceChanged(); - //set up previously saved device - SettingsScriptingInterface* settings = SettingsScriptingInterface::getInstance(); - const QString inDevice = settings->getValue("audio_input_device").toString(); - if (inDevice != _currentInputDevice) { - setInputDeviceAsync(inDevice); - } - const QString outDevice = settings->getValue("audio_output_device").toString(); - if (outDevice != _currentOutputDevice) { - setOutputDeviceAsync(outDevice); - } -} - -bool AudioDeviceScriptingInterface::setInputDevice(const QString& deviceName) { - bool result; - QMetaObject::invokeMethod(DependencyManager::get().data(), "switchInputToAudioDevice", - Qt::BlockingQueuedConnection, - Q_RETURN_ARG(bool, result), - Q_ARG(const QString&, deviceName)); - return result; -} - -bool AudioDeviceScriptingInterface::setOutputDevice(const QString& deviceName) { - bool result; - QMetaObject::invokeMethod(DependencyManager::get().data(), "switchOutputToAudioDevice", - Qt::BlockingQueuedConnection, - Q_RETURN_ARG(bool, result), - Q_ARG(const QString&, deviceName)); - return result; -} - -bool AudioDeviceScriptingInterface::setDeviceFromMenu(const QString& deviceMenuName) { - QAudio::Mode mode; - - if (deviceMenuName.indexOf("for Output") != -1) { - mode = QAudio::AudioOutput; - } else if (deviceMenuName.indexOf("for Input") != -1) { - mode = QAudio::AudioInput; - } else { - return false; - } - - for (ScriptingAudioDeviceInfo di: _devices) { - if (mode == di.mode && deviceMenuName.contains(di.name)) { - if (mode == QAudio::AudioOutput) { - setOutputDeviceAsync(di.name); - } else { - setInputDeviceAsync(di.name); - } - return true; - } - } - - return false; -} - -void AudioDeviceScriptingInterface::setInputDeviceAsync(const QString& deviceName) { - QMetaObject::invokeMethod(DependencyManager::get().data(), "switchInputToAudioDevice", - Qt::QueuedConnection, - Q_ARG(const QString&, deviceName)); -} - -void AudioDeviceScriptingInterface::setOutputDeviceAsync(const QString& deviceName) { - QMetaObject::invokeMethod(DependencyManager::get().data(), "switchOutputToAudioDevice", - Qt::QueuedConnection, - Q_ARG(const QString&, deviceName)); -} - -QString AudioDeviceScriptingInterface::getInputDevice() { - return DependencyManager::get()->getDeviceName(QAudio::AudioInput); -} - -QString AudioDeviceScriptingInterface::getOutputDevice() { - return DependencyManager::get()->getDeviceName(QAudio::AudioOutput); -} - -QString AudioDeviceScriptingInterface::getDefaultInputDevice() { - return DependencyManager::get()->getDefaultDeviceName(QAudio::AudioInput); -} - -QString AudioDeviceScriptingInterface::getDefaultOutputDevice() { - return DependencyManager::get()->getDefaultDeviceName(QAudio::AudioOutput); -} - -QVector AudioDeviceScriptingInterface::getInputDevices() { - return DependencyManager::get()->getDeviceNames(QAudio::AudioInput); -} - -QVector AudioDeviceScriptingInterface::getOutputDevices() { - return DependencyManager::get()->getDeviceNames(QAudio::AudioOutput); -} - -float AudioDeviceScriptingInterface::getInputVolume() { - return DependencyManager::get()->getInputVolume(); -} - -void AudioDeviceScriptingInterface::setInputVolume(float volume) { - DependencyManager::get()->setInputVolume(volume); -} - -void AudioDeviceScriptingInterface::setReverb(bool reverb) { - DependencyManager::get()->setReverb(reverb); -} - -void AudioDeviceScriptingInterface::setReverbOptions(const AudioEffectOptions* options) { - DependencyManager::get()->setReverbOptions(options); -} - -void AudioDeviceScriptingInterface::toggleMute() { - DependencyManager::get()->toggleMute(); -} - -void AudioDeviceScriptingInterface::setMuted(bool muted) -{ - bool lMuted = getMuted(); - if (lMuted == muted) - return; - - toggleMute(); - lMuted = getMuted(); - emit mutedChanged(lMuted); -} - -bool AudioDeviceScriptingInterface::getMuted() { - return DependencyManager::get()->isMuted(); -} - -QVariant AudioDeviceScriptingInterface::data(const QModelIndex& index, int role) const { - //sanity - if (!index.isValid() || index.row() >= _devices.size()) - return QVariant(); - - - if (role == Qt::DisplayRole || role == DisplayNameRole) { - return _devices.at(index.row()).name; - } else if (role == SelectedRole) { - return _devices.at(index.row()).selected; - } else if (role == AudioModeRole) { - return (int)_devices.at(index.row()).mode; - } - return QVariant(); -} - -int AudioDeviceScriptingInterface::rowCount(const QModelIndex& parent) const { - Q_UNUSED(parent) - return _devices.size(); -} - -QHash AudioDeviceScriptingInterface::roleNames() const { - QHash roles; - roles.insert(DisplayNameRole, "devicename"); - roles.insert(SelectedRole, "devicechecked"); - roles.insert(AudioModeRole, "devicemode"); - return roles; -} - -void AudioDeviceScriptingInterface::onDeviceChanged() -{ - beginResetModel(); - _outputAudioDevices.clear(); - _devices.clear(); - _currentOutputDevice = getOutputDevice(); - for (QString name: getOutputDevices()) { - ScriptingAudioDeviceInfo di; - di.name = name; - di.selected = (name == _currentOutputDevice); - di.mode = QAudio::AudioOutput; - _devices.append(di); - _outputAudioDevices.append(name); - } - emit outputAudioDevicesChanged(_outputAudioDevices); - - _inputAudioDevices.clear(); - _currentInputDevice = getInputDevice(); - for (QString name: getInputDevices()) { - ScriptingAudioDeviceInfo di; - di.name = name; - di.selected = (name == _currentInputDevice); - di.mode = QAudio::AudioInput; - _devices.append(di); - _inputAudioDevices.append(name); - } - emit inputAudioDevicesChanged(_inputAudioDevices); - - endResetModel(); - emit deviceChanged(); -} - -void AudioDeviceScriptingInterface::onCurrentInputDeviceChanged(const QString& name) -{ - currentDeviceUpdate(name, QAudio::AudioInput); - //we got a signal that device changed. Save it now - SettingsScriptingInterface* settings = SettingsScriptingInterface::getInstance(); - settings->setValue("audio_input_device", name); - emit currentInputDeviceChanged(name); -} - -void AudioDeviceScriptingInterface::onCurrentOutputDeviceChanged(const QString& name) -{ - currentDeviceUpdate(name, QAudio::AudioOutput); - //we got a signal that device changed. Save it now - SettingsScriptingInterface* settings = SettingsScriptingInterface::getInstance(); - settings->setValue("audio_output_device", name); - emit currentOutputDeviceChanged(name); -} - -void AudioDeviceScriptingInterface::currentDeviceUpdate(const QString& name, QAudio::Mode mode) -{ - QVector role; - role.append(SelectedRole); - - for (int i = 0; i < _devices.size(); i++) { - ScriptingAudioDeviceInfo di = _devices.at(i); - if (di.mode != mode) { - continue; - } - if (di.selected && di.name != name ) { - di.selected = false; - _devices[i] = di; - emit dataChanged(index(i, 0), index(i, 0), role); - } - if (di.name == name) { - di.selected = true; - _devices[i] = di; - emit dataChanged(index(i, 0), index(i, 0), role); - } - } -} -*/ diff --git a/interface/src/scripting/AudioDeviceScriptingInterface.h b/interface/src/scripting/AudioDeviceScriptingInterface.h deleted file mode 100644 index cff7567bbc..0000000000 --- a/interface/src/scripting/AudioDeviceScriptingInterface.h +++ /dev/null @@ -1,109 +0,0 @@ -// -// AudioDeviceScriptingInterface.h -// interface/src/scripting -// -// Created by Brad Hefta-Gaub on 3/22/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_AudioDeviceScriptingInterface_h -#define hifi_AudioDeviceScriptingInterface_h - -/* -#include -#include -#include -#include -#include - -class AudioEffectOptions; - -struct ScriptingAudioDeviceInfo { - QString name; - bool selected; - QAudio::Mode mode; -}; - -class AudioDeviceScriptingInterface : public QAbstractListModel { - Q_OBJECT - - Q_PROPERTY(QStringList inputAudioDevices READ inputAudioDevices NOTIFY inputAudioDevicesChanged) - Q_PROPERTY(QStringList outputAudioDevices READ outputAudioDevices NOTIFY outputAudioDevicesChanged) - Q_PROPERTY(bool muted READ muted WRITE setMuted NOTIFY mutedChanged) - -public: - static AudioDeviceScriptingInterface* getInstance(); - - QStringList inputAudioDevices() const; - QStringList outputAudioDevices() const; - bool muted(); - - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; - int rowCount(const QModelIndex& parent = QModelIndex()) const override; - QHash roleNames() const override; - - enum Roles { - DisplayNameRole = Qt::UserRole, - SelectedRole, - AudioModeRole - }; - -private slots: - void onDeviceChanged(); - void onCurrentInputDeviceChanged(const QString& name); - void onCurrentOutputDeviceChanged(const QString& name); - void currentDeviceUpdate(const QString& name, QAudio::Mode mode); - -public slots: - bool setInputDevice(const QString& deviceName); - bool setOutputDevice(const QString& deviceName); - bool setDeviceFromMenu(const QString& deviceMenuName); - - QString getInputDevice(); - QString getOutputDevice(); - - QString getDefaultInputDevice(); - QString getDefaultOutputDevice(); - - QVector getInputDevices(); - QVector getOutputDevices(); - - float getInputVolume(); - void setInputVolume(float volume); - void setReverb(bool reverb); - void setReverbOptions(const AudioEffectOptions* options); - - bool getMuted(); - void toggleMute(); - - void setMuted(bool muted); - - void setInputDeviceAsync(const QString& deviceName); - void setOutputDeviceAsync(const QString& deviceName); -private: - AudioDeviceScriptingInterface(); - -signals: - void muteToggled(); - void deviceChanged(); - void currentInputDeviceChanged(const QString& name); - void currentOutputDeviceChanged(const QString& name); - void mutedChanged(bool muted); - void inputAudioDevicesChanged(QStringList inputAudioDevices); - void outputAudioDevicesChanged(QStringList outputAudioDevices); - -private: - QVector _devices; - - QStringList _inputAudioDevices; - QStringList _outputAudioDevices; - - QString _currentInputDevice; - QString _currentOutputDevice; -}; -*/ - -#endif // hifi_AudioDeviceScriptingInterface_h