-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettingsdialog.cpp
More file actions
143 lines (115 loc) · 5.28 KB
/
settingsdialog.cpp
File metadata and controls
143 lines (115 loc) · 5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include "settingsdialog.h"
#include <QAbstractItemView>
#include <QDebug>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <QFileDialog>
#include "audio.h"
#include "mainwindow.h"
SettingsDialog::SettingsDialog(
Audio *audio,
QWidget *parent) : QDialog(parent)
, m_audioSelect(new QComboBox(this))
, m_chooseEffectsFolderButton(new QPushButton("Select Directory", this))
, m_inputDeviceComboBox(new QComboBox(this))
, m_outputDeviceComboBox(new QComboBox(this))
{
this->audio = audio;
const QList<QAudioDeviceInfo> &availableInputDevices = audio->availableAudioInputDevices();
const QList<QAudioDeviceInfo> &availableOutputDevices = audio->availableAudioOutputDevices();
QVBoxLayout *dialogLayout = new QVBoxLayout(this);
dialogLayout->setSpacing(2);
//Populate combo boxes
m_audioSelect->addItem("Qt",static_cast<AudioSystem>(0));
m_audioSelect->addItem("JACK",static_cast<AudioSystem>(1));
m_inputDeviceComboBox->setDuplicatesEnabled(false);
m_outputDeviceComboBox->setDuplicatesEnabled(false);
QAudioDeviceInfo device;
// Default in and out devices
device = audio->getDefaultInputDevice();
m_inputDeviceComboBox->addItem(device.deviceName(), QVariant::fromValue(device));
m_inputDevice = device;
device = audio->getDefaultOutputDevice();
m_outputDeviceComboBox->addItem(device.deviceName(), QVariant::fromValue(device));
m_outputDevice = device;
for (QAudioDeviceInfo device : availableInputDevices){
m_inputDeviceComboBox->addItem(device.deviceName(), QVariant::fromValue(device));
}
m_inputDeviceComboBox->setMaximumWidth(150);
m_inputDeviceComboBox->view()->setMinimumWidth(m_inputDeviceComboBox->fontMetrics().lineWidth());
for (QAudioDeviceInfo device : availableOutputDevices){
m_outputDeviceComboBox->addItem(device.deviceName(), QVariant::fromValue(device));
}
m_outputDeviceComboBox->setMaximumWidth(150);
m_outputDeviceComboBox->view()->setMinimumWidth(m_outputDeviceComboBox->fontMetrics().lineWidth());
//Initialize default devices
if (!availableInputDevices.empty())
m_inputDevice = availableInputDevices.front();
if (!availableOutputDevices.empty())
m_outputDevice = availableOutputDevices.front();
//Add widgets to layout
QHBoxLayout* audioSelectLayout(new QHBoxLayout);
QLabel* audioSelectLabel = new QLabel(tr("Audio System"), this);
audioSelectLayout->addWidget(audioSelectLabel);
audioSelectLayout->addWidget(m_audioSelect);
dialogLayout->addLayout(audioSelectLayout);
QHBoxLayout* effectsFolderPathLayout(new QHBoxLayout);
QLabel* effectsFolderPathLabel = new QLabel(tr("Effects Folder Path:"), this);
effectsFolderPathLayout->addWidget(effectsFolderPathLabel);
effectsFolderPathLayout->addWidget(m_chooseEffectsFolderButton);
dialogLayout->addLayout(effectsFolderPathLayout);
QHBoxLayout* inputDeviceLayout(new QHBoxLayout);
QLabel *inputDeviceLabel = new QLabel(tr("Input Device"), this);
inputDeviceLayout->addWidget(inputDeviceLabel);
inputDeviceLayout->addWidget(m_inputDeviceComboBox);
dialogLayout->addLayout(inputDeviceLayout);
QHBoxLayout* outputDeviceLayout(new QHBoxLayout);
QLabel *outputDeviceLabel = new QLabel(tr("Output Device"), this);
outputDeviceLayout->addWidget(outputDeviceLabel);
outputDeviceLayout->addWidget(m_outputDeviceComboBox);
dialogLayout->addLayout(outputDeviceLayout);
// Connect
connect(m_audioSelect, QOverload<int>::of(&QComboBox::activated),
this, &SettingsDialog::audioSystemChanged);
connect(m_inputDeviceComboBox, QOverload<int>::of(&QComboBox::activated),
this, &SettingsDialog::inputDeviceChanged);
connect(m_outputDeviceComboBox, QOverload<int>::of(&QComboBox::activated),
this, &SettingsDialog::outputDeviceChanged);
connect(m_chooseEffectsFolderButton, &QPushButton::pressed, [=](){
QString Directory = QFileDialog::getExistingDirectory(this,
tr("Choose Or Create Directory"));
m_effectsDirectory = Directory;
});
// Add standard buttons
QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
dialogLayout->addWidget(buttonBox);
// Connect standard buttons
connect(buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked,
this, &SettingsDialog::accept);
connect(buttonBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked,
this, &SettingsDialog::reject);
setLayout(dialogLayout);
}
SettingsDialog::~SettingsDialog()
{
}
void SettingsDialog::audioSystemChanged(int index)
{
AudioSystem audioSystem = static_cast<AudioSystem>(index);
qDebug() << "Setting audio system to " << audioSystem;
audio->setAudioSystem(audioSystem);
}
void SettingsDialog::inputDeviceChanged(int index)
{
m_inputDevice = m_inputDeviceComboBox->itemData(index).value<QAudioDeviceInfo>();
audio->setInputDevice(m_inputDevice);
}
void SettingsDialog::outputDeviceChanged(int index)
{
m_outputDevice = m_outputDeviceComboBox->itemData(index).value<QAudioDeviceInfo>();
audio->setOutputDevice(m_outputDevice);
}