12 #ifndef hifi_scripting_AudioDevices_h
13 #define hifi_scripting_AudioDevices_h
19 #include <QAbstractListModel>
20 #include <QAudioDeviceInfo>
22 #include <HifiAudioDeviceInfo.h>
28 HifiAudioDeviceInfo info;
30 bool selectedDesktop {
false };
31 bool selectedHMD {
false };
35 class AudioDeviceList :
public QAbstractListModel {
39 AudioDeviceList(QAudio::Mode mode = QAudio::AudioOutput);
40 virtual ~AudioDeviceList();
42 virtual std::shared_ptr<AudioDevice> newDevice(
const AudioDevice& device)
43 {
return std::make_shared<AudioDevice>(device); }
45 int rowCount(
const QModelIndex& parent = QModelIndex())
const override { Q_UNUSED(parent);
return _devices.size(); }
46 QHash<int, QByteArray> roleNames()
const override {
return _roles; }
47 Qt::ItemFlags flags(
const QModelIndex& index)
const override {
return _flags; }
50 QVariant data(
const QModelIndex& index,
int role)
const override;
53 void resetDevice(
bool contextIsHMD);
56 void deviceChanged(
const HifiAudioDeviceInfo& device);
57 void selectedDevicePlugged(
const HifiAudioDeviceInfo& device,
bool isHMD);
60 void onDeviceChanged(
const HifiAudioDeviceInfo& device,
bool isHMD);
61 void onDevicesChanged(QAudio::Mode mode,
const QList<HifiAudioDeviceInfo>& devices);
64 friend class AudioDevices;
66 static QHash<int, QByteArray> _roles;
67 static Qt::ItemFlags _flags;
68 const QAudio::Mode _mode;
69 HifiAudioDeviceInfo _selectedDesktopDevice;
70 HifiAudioDeviceInfo _selectedHMDDevice;
71 QString _backupSelectedDesktopDeviceName;
72 QString _backupSelectedHMDDeviceName;
73 QList<std::shared_ptr<AudioDevice>> _devices;
74 QString _hmdSavedDeviceName;
75 QString _desktopSavedDeviceName;
78 class AudioInputDevice :
public AudioDevice {
80 AudioInputDevice(
const AudioDevice& device) : AudioDevice(device) {}
84 class AudioInputDeviceList :
public AudioDeviceList {
86 Q_PROPERTY(
bool peakValuesAvailable READ peakValuesAvailable CONSTANT)
87 Q_PROPERTY(
bool peakValuesEnabled READ peakValuesEnabled WRITE setPeakValuesEnabled NOTIFY peakValuesEnabledChanged)
90 AudioInputDeviceList() : AudioDeviceList(QAudio::AudioInput) {}
91 virtual ~AudioInputDeviceList() =
default;
93 virtual std::shared_ptr<AudioDevice> newDevice(
const AudioDevice& device)
override
94 {
return std::make_shared<AudioInputDevice>(device); }
96 QVariant data(
const QModelIndex& index,
int role)
const override;
99 void peakValuesEnabledChanged(
bool enabled);
102 void onPeakValueListChanged(
const QList<float>& peakValueList);
105 friend class AudioDevices;
107 bool peakValuesAvailable();
108 std::once_flag _peakFlag;
109 bool _peakValuesAvailable;
111 bool peakValuesEnabled()
const {
return _peakValuesEnabled; }
112 void setPeakValuesEnabled(
bool enable);
113 bool _peakValuesEnabled {
false };
117 class AudioDevices :
public QObject {
119 Q_PROPERTY(AudioInputDeviceList* input READ getInputList NOTIFY nop)
120 Q_PROPERTY(AudioDeviceList* output READ getOutputList NOTIFY nop)
123 AudioDevices(
bool& contextIsHMD);
124 virtual ~AudioDevices();
130 void chooseInputDevice(
const HifiAudioDeviceInfo& device,
bool isHMD);
131 void chooseOutputDevice(
const HifiAudioDeviceInfo& device,
bool isHMD);
133 void onContextChanged(
const QString& context);
134 void onDeviceSelected(QAudio::Mode mode,
const HifiAudioDeviceInfo& device,
135 const HifiAudioDeviceInfo& previousDevice,
bool isHMD);
136 void onDeviceChanged(QAudio::Mode mode,
const HifiAudioDeviceInfo& device);
137 void onDevicesChanged(QAudio::Mode mode,
const QList<HifiAudioDeviceInfo>& devices);
142 AudioInputDeviceList* getInputList() {
return &_inputs; }
143 AudioDeviceList* getOutputList() {
return &_outputs; }
145 AudioInputDeviceList _inputs;
146 AudioDeviceList _outputs { QAudio::AudioOutput };
147 HifiAudioDeviceInfo _requestedOutputDevice;
148 HifiAudioDeviceInfo _requestedInputDevice;
150 const bool& _contextIsHMD;