SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
audioselectdialog.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018 F4EXB //
3 // written by Edouard Griffiths //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #include "audioselectdialog.h"
20 #include "ui_audioselectdialog.h"
21 
22 AudioSelectDialog::AudioSelectDialog(AudioDeviceManager* audioDeviceManager, const QString& deviceName, bool input, QWidget* parent) :
23  QDialog(parent),
24  m_selected(false),
25  ui(new Ui::AudioSelectDialog),
26  m_audioDeviceManager(audioDeviceManager),
27  m_input(input)
28 {
29  ui->setupUi(this);
30  QTreeWidgetItem *treeItem, *defaultItem, *selectedItem = 0;
31  bool systemDefault;
32  int sampleRate;
33 
34  // panel
35 
36  QAudioDeviceInfo defaultDeviceInfo = input ? QAudioDeviceInfo::defaultInputDevice() : QAudioDeviceInfo::defaultOutputDevice();
37  defaultItem = new QTreeWidgetItem(ui->audioTree);
38  defaultItem->setText(1, AudioDeviceManager::m_defaultDeviceName);
39  bool deviceFound = getDeviceInfos(input, AudioDeviceManager::m_defaultDeviceName, systemDefault, sampleRate);
40  defaultItem->setText(0, deviceFound ? "__" : "_D");
41  defaultItem->setText(2, tr("%1").arg(sampleRate));
42  defaultItem->setTextAlignment(2, Qt::AlignRight);
43 
44  QList<QAudioDeviceInfo> devices = input ? m_audioDeviceManager->getInputDevices() : m_audioDeviceManager->getOutputDevices();
45 
46  for(QList<QAudioDeviceInfo>::const_iterator it = devices.begin(); it != devices.end(); ++it)
47  {
48  treeItem = new QTreeWidgetItem(ui->audioTree);
49  treeItem->setText(1, it->deviceName());
50  bool deviceFound = getDeviceInfos(input, it->deviceName(), systemDefault, sampleRate);
51  treeItem->setText(0, QString(systemDefault ? "S" : "_") + QString(deviceFound ? "_" : "D"));
52  treeItem->setText(2, tr("%1").arg(sampleRate));
53  treeItem->setTextAlignment(2, Qt::AlignRight);
54 
55  if (systemDefault) {
56  treeItem->setBackground(1, QBrush(qRgb(80,80,80)));
57  }
58 
59  if (deviceName == it->deviceName()) {
60  selectedItem = treeItem;
61  }
62  }
63 
64  ui->audioTree->resizeColumnToContents(0);
65  ui->audioTree->resizeColumnToContents(1);
66  ui->audioTree->resizeColumnToContents(2);
67 
68  if (selectedItem) {
69  ui->audioTree->setCurrentItem(selectedItem);
70  } else {
71  ui->audioTree->setCurrentItem(defaultItem);
72  }
73 }
74 
76 {
77  delete ui;
78 }
79 
81 {
82  int deviceIndex = ui->audioTree->indexOfTopLevelItem(ui->audioTree->currentItem()) - 1;
83 
84  if (m_input)
85  {
88  }
89  }
90  else
91  {
94  }
95 
96  qDebug("AudioSelectDialog::accept: output: %d (%s)", deviceIndex, qPrintable(m_audioDeviceName));
97  }
98 
99  m_selected = true;
100  QDialog::accept();
101 }
102 
104 {
105  QDialog::reject();
106 }
107 
108 bool AudioSelectDialog::getDeviceInfos(bool input, const QString& deviceName, bool& systemDefault, int& sampleRate)
109 {
110  bool found;
111 
112  if (input)
113  {
115  found = m_audioDeviceManager->getInputDeviceInfo(deviceName, inDeviceInfo);
116  systemDefault = deviceName == QAudioDeviceInfo::defaultInputDevice().deviceName();
117 
118  if (found) {
119  sampleRate = inDeviceInfo.sampleRate;
120  } else {
122  }
123  }
124  else
125  {
127  found = m_audioDeviceManager->getOutputDeviceInfo(deviceName, outDeviceInfo);
128  systemDefault = deviceName == QAudioDeviceInfo::defaultOutputDevice().deviceName();
129 
130  if (found) {
131  sampleRate = outDeviceInfo.sampleRate;
132  } else {
134  }
135  }
136 
137  return found;
138 }
139 
140 
static const QString m_defaultDeviceName
const QList< QAudioDeviceInfo > & getInputDevices() const
Ui::AudioSelectDialog * ui
AudioDeviceManager * m_audioDeviceManager
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
bool getInputDeviceName(int inputDeviceIndex, QString &deviceName) const
bool getInputDeviceInfo(const QString &deviceName, InputDeviceInfo &deviceInfo) const
bool getOutputDeviceInfo(const QString &deviceName, OutputDeviceInfo &deviceInfo) const
bool getOutputDeviceName(int outputDeviceIndex, QString &deviceName) const
AudioSelectDialog(AudioDeviceManager *audioDeviceManager, const QString &deviceName, bool input=false, QWidget *parent=0)
const QList< QAudioDeviceInfo > & getOutputDevices() const
static const unsigned int m_defaultAudioSampleRate
bool getDeviceInfos(bool input, const QString &deviceName, bool &systemDefault, int &sampleRate)