1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-17 23:28:50 -05:00

New audio devices dialog and handling (1)

This commit is contained in:
f4exb 2017-01-06 12:43:18 +01:00
parent c3b69007af
commit d8bcfb1360
4 changed files with 73 additions and 67 deletions

View File

@ -17,12 +17,11 @@
#include "audio/audiodeviceinfo.h"
AudioDeviceInfo::AudioDeviceInfo()
AudioDeviceInfo::AudioDeviceInfo() :
m_inputDeviceIndex(-1), // default device
m_outputDeviceIndex(-1), // default device
m_inputVolume(0.5f)
{
}
int AudioDeviceInfo::match(const QString& api, const QString device) const
{
// nothing found - fall back to default
return 0;
m_inputDevicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
m_outputDevicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
}

View File

@ -19,31 +19,29 @@
#define INCLUDE_AUDIODEVICEINFO_H
#include <QStringList>
#include <QList>
#include <QAudioDeviceInfo>
#include "util/export.h"
class SDRANGEL_API AudioDeviceInfo {
public:
struct Device {
QString name;
QString api;
int id;
Device(const QString& _name, const QString& _api, int _id) :
name(_name),
api(_api),
id(_id)
{ }
};
typedef QList<Device> Devices;
AudioDeviceInfo();
int match(const QString& api, const QString device) const;
const Devices& getDevices() const { return m_devices; }
const QList<QAudioDeviceInfo>& getInputDevices() const { return m_inputDevicesInfo; }
const QList<QAudioDeviceInfo>& getOutputDevices() const { return m_outputDevicesInfo; }
int getInputDeviceIndex() const { return m_inputDeviceIndex; }
int getOutputDeviceIndex() const { return m_outputDeviceIndex; }
float getInputVolume() const { return m_inputVolume; }
private:
Devices m_devices;
QList<QAudioDeviceInfo> m_inputDevicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
QList<QAudioDeviceInfo> m_outputDevicesInfo = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
int m_inputDeviceIndex;
int m_outputDeviceIndex;
float m_inputVolume;
friend class AudioDialog;
};
#endif // INCLUDE_AUDIODEVICEINFO_H

View File

@ -9,55 +9,62 @@ AudioDialog::AudioDialog(AudioDeviceInfo* audioDeviceInfo, QWidget* parent) :
m_audioDeviceInfo(audioDeviceInfo)
{
ui->setupUi(this);
QTreeWidgetItem* treeItem;
int i;
const AudioDeviceInfo::Devices& devices = audioDeviceInfo->getDevices();
// out panel
QTreeWidgetItem* api;
QStringList sl;
sl.append(tr("Default (use first suitable device)"));
api = new QTreeWidgetItem(ui->audioOutTree, sl, ATDefault);
api->setFirstColumnSpanned(true);
treeItem = new QTreeWidgetItem(ui->audioOutTree);
treeItem->setText(0, tr("Default (use first suitable device)"));
for(AudioDeviceInfo::Devices::const_iterator it = devices.begin(); it != devices.end(); ++it)
const QList<QAudioDeviceInfo>& outputDevices = m_audioDeviceInfo->getOutputDevices();
i = 0;
for(QList<QAudioDeviceInfo>::const_iterator it = outputDevices.begin(); it != outputDevices.end(); ++it)
{
int apiIndex;
sl.clear();
treeItem = new QTreeWidgetItem(ui->audioOutTree);
treeItem->setText(0, qPrintable(it->deviceName()));
for(apiIndex = 0; apiIndex < ui->audioOutTree->topLevelItemCount(); ++apiIndex)
if (i == m_audioDeviceInfo->getOutputDeviceIndex())
{
if(ui->audioOutTree->topLevelItem(apiIndex)->text(0) == it->api)
break;
ui->audioOutTree->setCurrentItem(treeItem);
}
if(apiIndex >= ui->audioOutTree->topLevelItemCount())
{
sl.append(it->api);
api = new QTreeWidgetItem(ui->audioOutTree, sl, ATInterface);
api->setExpanded(true);
api->setFirstColumnSpanned(true);
sl.clear();
}
else
{
api = ui->audioOutTree->topLevelItem(apiIndex);
i++;
}
sl.append(it->name);
new QTreeWidgetItem(api, sl, ATDevice);
// in panel
treeItem = new QTreeWidgetItem(ui->audioInTree);
treeItem->setText(0, tr("Default (use first suitable device)"));
const QList<QAudioDeviceInfo>& inputDevices = m_audioDeviceInfo->getInputDevices();
i = 0;
for(QList<QAudioDeviceInfo>::const_iterator it = inputDevices.begin(); it != inputDevices.end(); ++it)
{
treeItem = new QTreeWidgetItem(ui->audioInTree);
treeItem->setText(0, qPrintable(it->deviceName()));
if (i == m_audioDeviceInfo->getInputDeviceIndex())
{
ui->audioInTree->setCurrentItem(treeItem);
}
i++;
}
if(ui->audioOutTree->currentItem() == NULL)
ui->audioOutTree->setCurrentItem(ui->audioOutTree->topLevelItem(0));
sl.clear();
sl.append(tr("Default (use first suitable device)"));
api = new QTreeWidgetItem(ui->audioInTree, sl, ATDefault);
api->setFirstColumnSpanned(true);
if(ui->audioInTree->currentItem() == NULL)
ui->audioInTree->setCurrentItem(ui->audioInTree->topLevelItem(0));
ui->tabWidget->setCurrentIndex(0);
m_inputVolume = m_audioDeviceInfo->m_inputVolume;
ui->inputVolume->setValue((int) (m_inputVolume * 100.0f));
ui->inputVolumeText->setText(QString("%1").arg(m_inputVolume, 0, 'f', 2));
}
AudioDialog::~AudioDialog()
@ -67,11 +74,18 @@ AudioDialog::~AudioDialog()
void AudioDialog::accept()
{
int inIndex = ui->audioInTree->indexOfTopLevelItem(ui->audioInTree->currentItem());
int outIndex = ui->audioOutTree->indexOfTopLevelItem(ui->audioOutTree->currentItem());
m_audioDeviceInfo->m_inputDeviceIndex = inIndex - 1;
m_audioDeviceInfo->m_outputDeviceIndex = outIndex - 1;
m_audioDeviceInfo->m_inputVolume = m_inputVolume;
QDialog::accept();
}
void AudioDialog::on_inputVolume_valueChanged(int value)
{
float inputVolume = (float) value / 100.0f;
ui->inputVolumeText->setText(QString("%1").arg(inputVolume, 0, 'f', 2));
m_inputVolume = (float) value / 100.0f;
ui->inputVolumeText->setText(QString("%1").arg(m_inputVolume, 0, 'f', 2));
}

View File

@ -17,15 +17,10 @@ public:
~AudioDialog();
private:
enum Audio {
ATDefault,
ATInterface,
ATDevice
};
Ui::AudioDialog* ui;
AudioDeviceInfo* m_audioDeviceInfo;
float m_inputVolume;
private slots:
void accept();