2018-03-23 22:36:49 -04:00
|
|
|
#include "audiodialog.h"
|
2018-03-23 13:08:38 -04:00
|
|
|
|
|
|
|
#include <audio/audiodevicemanager.h>
|
2014-05-18 11:52:39 -04:00
|
|
|
#include <QTreeWidgetItem>
|
2016-05-04 11:07:26 -04:00
|
|
|
#include "ui_audiodialog.h"
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2018-03-25 07:36:09 -04:00
|
|
|
AudioDialogX::AudioDialogX(AudioDeviceManager* audioDeviceManager, QWidget* parent) :
|
2014-05-18 11:52:39 -04:00
|
|
|
QDialog(parent),
|
2016-05-04 11:07:26 -04:00
|
|
|
ui(new Ui::AudioDialog),
|
2018-03-23 22:36:49 -04:00
|
|
|
m_audioDeviceManager(audioDeviceManager)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2017-01-06 06:43:18 -05:00
|
|
|
QTreeWidgetItem* treeItem;
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2017-01-06 06:43:18 -05:00
|
|
|
// out panel
|
|
|
|
|
2018-03-25 07:36:09 -04:00
|
|
|
QAudioDeviceInfo defaultOutputDeviceInfo = QAudioDeviceInfo::defaultOutputDevice();
|
2017-01-06 06:43:18 -05:00
|
|
|
treeItem = new QTreeWidgetItem(ui->audioOutTree);
|
2018-03-26 05:55:45 -04:00
|
|
|
treeItem->setText(0, AudioDeviceManager::m_defaultDeviceName);
|
|
|
|
ui->audioOutTree->setCurrentItem(treeItem);
|
2017-01-06 06:43:18 -05:00
|
|
|
|
2018-03-23 22:36:49 -04:00
|
|
|
const QList<QAudioDeviceInfo>& outputDevices = m_audioDeviceManager->getOutputDevices();
|
2017-01-06 06:43:18 -05:00
|
|
|
|
|
|
|
for(QList<QAudioDeviceInfo>::const_iterator it = outputDevices.begin(); it != outputDevices.end(); ++it)
|
|
|
|
{
|
|
|
|
treeItem = new QTreeWidgetItem(ui->audioOutTree);
|
2018-03-26 12:41:09 -04:00
|
|
|
treeItem->setText(0, it->deviceName());
|
|
|
|
|
|
|
|
if (it->deviceName() == defaultOutputDeviceInfo.deviceName()) {
|
|
|
|
treeItem->setBackground(0, QBrush(qRgb(96,96,96)));
|
|
|
|
}
|
2017-01-06 06:43:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// in panel
|
|
|
|
|
2018-03-25 07:36:09 -04:00
|
|
|
QAudioDeviceInfo defaultInputDeviceInfo = QAudioDeviceInfo::defaultInputDevice();
|
2017-01-06 06:43:18 -05:00
|
|
|
treeItem = new QTreeWidgetItem(ui->audioInTree);
|
2018-03-26 05:55:45 -04:00
|
|
|
treeItem->setText(0, AudioDeviceManager::m_defaultDeviceName);
|
|
|
|
ui->audioInTree->setCurrentItem(treeItem);
|
2017-01-06 06:43:18 -05:00
|
|
|
|
2018-03-23 22:36:49 -04:00
|
|
|
const QList<QAudioDeviceInfo>& inputDevices = m_audioDeviceManager->getInputDevices();
|
2017-01-06 06:43:18 -05:00
|
|
|
|
|
|
|
for(QList<QAudioDeviceInfo>::const_iterator it = inputDevices.begin(); it != inputDevices.end(); ++it)
|
|
|
|
{
|
|
|
|
treeItem = new QTreeWidgetItem(ui->audioInTree);
|
2018-03-26 12:41:09 -04:00
|
|
|
treeItem->setText(0, it->deviceName());
|
|
|
|
|
|
|
|
if (it->deviceName() == defaultInputDeviceInfo.deviceName()) {
|
|
|
|
treeItem->setBackground(0, QBrush(qRgb(96,96,96)));
|
|
|
|
}
|
2018-03-26 05:55:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
m_outputUDPPort = 9998;
|
|
|
|
m_outIndex = -1;
|
|
|
|
m_inIndex = -1;
|
2017-01-06 06:43:18 -05:00
|
|
|
|
2018-03-26 05:55:45 -04:00
|
|
|
ui->tabWidget->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioDialogX::~AudioDialogX()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDialogX::accept()
|
|
|
|
{
|
|
|
|
m_inIndex = ui->audioInTree->indexOfTopLevelItem(ui->audioInTree->currentItem());
|
|
|
|
m_outIndex = ui->audioOutTree->indexOfTopLevelItem(ui->audioOutTree->currentItem());
|
|
|
|
|
|
|
|
if (ui->tabWidget->currentIndex() == 0) // output
|
|
|
|
{
|
|
|
|
updateOutputDeviceInfo();
|
|
|
|
|
|
|
|
if (ui->outputResetKey->isChecked()) {
|
|
|
|
m_audioDeviceManager->unsetOutputDeviceInfo(m_outIndex-1);
|
|
|
|
} else {
|
|
|
|
m_audioDeviceManager->setOutputDeviceInfo(m_outIndex-1, m_outputDeviceInfo);
|
2017-01-06 06:43:18 -05:00
|
|
|
}
|
2018-03-26 05:55:45 -04:00
|
|
|
}
|
|
|
|
else if (ui->tabWidget->currentIndex() == 1) // input
|
|
|
|
{
|
|
|
|
updateInputDeviceInfo();
|
2017-01-06 06:43:18 -05:00
|
|
|
|
2018-03-26 05:55:45 -04:00
|
|
|
if (ui->inputResetKey->isChecked()) {
|
|
|
|
m_audioDeviceManager->unsetInputDeviceInfo(m_inIndex-1);
|
|
|
|
} else {
|
|
|
|
m_audioDeviceManager->setInputDeviceInfo(m_inIndex-1, m_inputDeviceInfo);
|
|
|
|
}
|
2017-01-06 06:43:18 -05:00
|
|
|
}
|
2017-01-05 21:02:57 -05:00
|
|
|
|
2018-03-26 05:55:45 -04:00
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDialogX::reject()
|
|
|
|
{
|
|
|
|
QDialog::reject();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDialogX::on_audioInTree_currentItemChanged(
|
|
|
|
QTreeWidgetItem* currentItem,
|
|
|
|
QTreeWidgetItem* previousItem)
|
|
|
|
{
|
|
|
|
AudioDeviceManager::InputDeviceInfo inDeviceInfo;
|
|
|
|
QString inDeviceName = currentItem->text(0);
|
|
|
|
int newIndex = ui->audioInTree->indexOfTopLevelItem(currentItem);
|
|
|
|
int oldIndex = ui->audioInTree->indexOfTopLevelItem(previousItem);
|
|
|
|
//qDebug("AudioDialogX::on_audioInTree_currentItemChanged: %s", qPrintable(inDeviceName));
|
|
|
|
|
|
|
|
if (newIndex != oldIndex) {
|
|
|
|
ui->inputResetKey->setChecked(false);
|
2017-09-29 22:05:32 -04:00
|
|
|
}
|
2017-01-05 21:02:57 -05:00
|
|
|
|
2018-03-26 05:55:45 -04:00
|
|
|
bool found = m_audioDeviceManager->getInputDeviceInfo(inDeviceName, inDeviceInfo);
|
|
|
|
m_inputDeviceInfo = inDeviceInfo;
|
|
|
|
ui->inputDefaultText->setText(found ? "" : "D");
|
2014-05-18 11:52:39 -04:00
|
|
|
|
2018-03-26 05:55:45 -04:00
|
|
|
updateInputDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDialogX::on_audioOutTree_currentItemChanged(
|
|
|
|
QTreeWidgetItem* currentItem,
|
|
|
|
QTreeWidgetItem* previousItem)
|
|
|
|
{
|
|
|
|
AudioDeviceManager::OutputDeviceInfo outDeviceInfo;
|
|
|
|
QString outDeviceName = currentItem->text(0);
|
|
|
|
int newIndex = ui->audioOutTree->indexOfTopLevelItem(currentItem);
|
|
|
|
int oldIndex = ui->audioOutTree->indexOfTopLevelItem(previousItem);
|
|
|
|
|
|
|
|
if (newIndex != oldIndex) {
|
|
|
|
ui->outputResetKey->setChecked(false);
|
|
|
|
}
|
2017-01-06 06:43:18 -05:00
|
|
|
|
2018-03-26 12:41:09 -04:00
|
|
|
//qDebug("AudioDialogX::on_audioOutTree_currentItemChanged: %s", qPrintable(outDeviceName));
|
2018-03-26 05:55:45 -04:00
|
|
|
bool found = m_audioDeviceManager->getOutputDeviceInfo(outDeviceName, outDeviceInfo);
|
|
|
|
m_outputDeviceInfo = outDeviceInfo;
|
|
|
|
ui->outputDefaultText->setText(found ? "" : "D");
|
|
|
|
|
|
|
|
updateOutputDisplay();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2018-03-26 05:55:45 -04:00
|
|
|
void AudioDialogX::on_inputVolume_valueChanged(int value)
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2018-03-26 05:55:45 -04:00
|
|
|
float volume = value / 100.0f;
|
|
|
|
ui->inputVolumeText->setText(QString("%1").arg(volume, 0, 'f', 2));
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
|
|
|
|
2018-03-26 05:55:45 -04:00
|
|
|
void AudioDialogX::on_inputReset_clicked(bool checked __attribute__((unused)))
|
2014-05-18 11:52:39 -04:00
|
|
|
{
|
2018-03-26 05:55:45 -04:00
|
|
|
m_inputDeviceInfo.resetToDefaults();
|
|
|
|
updateInputDisplay();
|
2014-05-18 11:52:39 -04:00
|
|
|
}
|
2017-01-05 21:13:53 -05:00
|
|
|
|
2018-03-26 05:55:45 -04:00
|
|
|
void AudioDialogX::on_inputCleanup_clicked(bool checked __attribute__((unused)))
|
|
|
|
{
|
|
|
|
m_audioDeviceManager->inputInfosCleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDialogX::updateInputDisplay()
|
|
|
|
{
|
|
|
|
ui->inputSampleRate->setValue(m_inputDeviceInfo.sampleRate);
|
|
|
|
ui->inputVolume->setValue(roundf(m_inputDeviceInfo.volume * 100.0f));
|
|
|
|
ui->inputVolumeText->setText(QString("%1").arg(m_inputDeviceInfo.volume, 0, 'f', 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDialogX::updateInputDeviceInfo()
|
|
|
|
{
|
|
|
|
m_inputDeviceInfo.sampleRate = ui->inputSampleRate->value();
|
|
|
|
m_inputDeviceInfo.volume = ui->inputVolume->value() / 100.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDialogX::on_outputUDPPort_editingFinished()
|
2017-01-05 21:13:53 -05:00
|
|
|
{
|
2018-03-26 05:55:45 -04:00
|
|
|
bool ok;
|
|
|
|
quint16 udpPort = ui->outputUDPPort->text().toInt(&ok);
|
|
|
|
|
|
|
|
if((!ok) || (udpPort < 1024)) {
|
|
|
|
udpPort = 9999;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_outputUDPPort = udpPort;
|
|
|
|
ui->outputUDPPort->setText(tr("%1").arg(m_outputDeviceInfo.udpPort));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDialogX::on_outputReset_clicked(bool checked __attribute__((unused)))
|
|
|
|
{
|
|
|
|
m_outputDeviceInfo.resetToDefaults();
|
|
|
|
updateOutputDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDialogX::on_outputCleanup_clicked(bool checked __attribute__((unused)))
|
|
|
|
{
|
|
|
|
m_audioDeviceManager->outputInfosCleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioDialogX::updateOutputDisplay()
|
|
|
|
{
|
|
|
|
ui->outputSampleRate->setValue(m_outputDeviceInfo.sampleRate);
|
|
|
|
ui->outputUDPAddress->setText(m_outputDeviceInfo.udpAddress);
|
|
|
|
ui->outputUDPPort->setText(tr("%1").arg(m_outputDeviceInfo.udpPort));
|
|
|
|
ui->outputUDPCopy->setChecked(m_outputDeviceInfo.copyToUDP);
|
|
|
|
ui->outputUDPUseRTP->setChecked(m_outputDeviceInfo.udpUseRTP);
|
2018-03-26 15:10:09 -04:00
|
|
|
ui->outputUDPChannelMode->setCurrentIndex((int) m_outputDeviceInfo.udpChannelMode);
|
2017-01-05 21:13:53 -05:00
|
|
|
}
|
2018-03-26 05:55:45 -04:00
|
|
|
|
|
|
|
void AudioDialogX::updateOutputDeviceInfo()
|
|
|
|
{
|
|
|
|
m_outputDeviceInfo.sampleRate = ui->outputSampleRate->value();
|
|
|
|
m_outputDeviceInfo.udpAddress = ui->outputUDPAddress->text();
|
|
|
|
m_outputDeviceInfo.udpPort = m_outputUDPPort;
|
|
|
|
m_outputDeviceInfo.copyToUDP = ui->outputUDPCopy->isChecked();
|
|
|
|
m_outputDeviceInfo.udpUseRTP = ui->outputUDPUseRTP->isChecked();
|
2018-03-26 15:10:09 -04:00
|
|
|
m_outputDeviceInfo.udpChannelMode = (AudioOutput::UDPChannelMode) ui->outputUDPChannelMode->currentIndex();
|
2018-03-26 05:55:45 -04:00
|
|
|
}
|
|
|
|
|