Lower the priority of the JACK backend
[openal-soft.git] / utils / alsoft-config / mainwindow.cpp
blobe35f3c95398f835a8ed6ebee516724a67fe7e22a
2 #include "config.h"
3 #include "config_backends.h"
4 #include "config_simd.h"
6 #include "mainwindow.h"
8 #include <array>
9 #include <cmath>
10 #include <memory>
12 #include <QFileDialog>
13 #include <QMessageBox>
14 #include <QCloseEvent>
15 #include <QSettings>
16 #include <QtGlobal>
17 #include "ui_mainwindow.h"
18 #include "verstr.h"
20 #ifdef _WIN32
21 #include <windows.h>
22 #include <shlobj.h>
23 #endif
25 #include "almalloc.h"
26 #include "alspan.h"
28 namespace {
30 struct BackendNamePair {
31 /* NOLINTBEGIN(*-avoid-c-arrays) */
32 char backend_name[16];
33 char full_string[32];
34 /* NOLINTEND(*-avoid-c-arrays) */
36 constexpr std::array backendList{
37 #if HAVE_PIPEWIRE
38 BackendNamePair{ "pipewire", "PipeWire" },
39 #endif
40 #if HAVE_PULSEAUDIO
41 BackendNamePair{ "pulse", "PulseAudio" },
42 #endif
43 #if HAVE_WASAPI
44 BackendNamePair{ "wasapi", "WASAPI" },
45 #endif
46 #if HAVE_COREAUDIO
47 BackendNamePair{ "core", "CoreAudio" },
48 #endif
49 #if HAVE_OPENSL
50 BackendNamePair{ "opensl", "OpenSL" },
51 #endif
52 #if HAVE_ALSA
53 BackendNamePair{ "alsa", "ALSA" },
54 #endif
55 #if HAVE_SOLARIS
56 BackendNamePair{ "solaris", "Solaris" },
57 #endif
58 #if HAVE_SNDIO
59 BackendNamePair{ "sndio", "SndIO" },
60 #endif
61 #if HAVE_OSS
62 BackendNamePair{ "oss", "OSS" },
63 #endif
64 #if HAVE_DSOUND
65 BackendNamePair{ "dsound", "DirectSound" },
66 #endif
67 #if HAVE_WINMM
68 BackendNamePair{ "winmm", "Windows Multimedia" },
69 #endif
70 #if HAVE_PORTAUDIO
71 BackendNamePair{ "port", "PortAudio" },
72 #endif
73 #if HAVE_JACK
74 BackendNamePair{ "jack", "JACK" },
75 #endif
77 BackendNamePair{ "null", "Null Output" },
78 #if HAVE_WAVE
79 BackendNamePair{ "wave", "Wave Writer" },
80 #endif
83 struct NameValuePair {
84 /* NOLINTBEGIN(*-avoid-c-arrays) */
85 const char name[64];
86 const char value[16];
87 /* NOLINTEND(*-avoid-c-arrays) */
89 constexpr std::array speakerModeList{
90 NameValuePair{ "Autodetect", "" },
91 NameValuePair{ "Mono", "mono" },
92 NameValuePair{ "Stereo", "stereo" },
93 NameValuePair{ "Quadraphonic", "quad" },
94 NameValuePair{ "5.1 Surround", "surround51" },
95 NameValuePair{ "6.1 Surround", "surround61" },
96 NameValuePair{ "7.1 Surround", "surround71" },
97 NameValuePair{ "3D7.1 Surround", "surround3d71" },
99 NameValuePair{ "Ambisonic, 1st Order", "ambi1" },
100 NameValuePair{ "Ambisonic, 2nd Order", "ambi2" },
101 NameValuePair{ "Ambisonic, 3rd Order", "ambi3" },
103 constexpr std::array sampleTypeList{
104 NameValuePair{ "Autodetect", "" },
105 NameValuePair{ "8-bit int", "int8" },
106 NameValuePair{ "8-bit uint", "uint8" },
107 NameValuePair{ "16-bit int", "int16" },
108 NameValuePair{ "16-bit uint", "uint16" },
109 NameValuePair{ "32-bit int", "int32" },
110 NameValuePair{ "32-bit uint", "uint32" },
111 NameValuePair{ "32-bit float", "float32" },
113 constexpr std::array resamplerList{
114 NameValuePair{ "Point", "point" },
115 NameValuePair{ "Linear", "linear" },
116 NameValuePair{ "Cubic Spline", "spline" },
117 NameValuePair{ "4-point Gaussian", "gaussian" },
118 NameValuePair{ "Default (4-point Gaussian)", "" },
119 NameValuePair{ "11th order Sinc (fast)", "fast_bsinc12" },
120 NameValuePair{ "11th order Sinc", "bsinc12" },
121 NameValuePair{ "23rd order Sinc (fast)", "fast_bsinc24" },
122 NameValuePair{ "23rd order Sinc", "bsinc24" },
124 constexpr std::array stereoModeList{
125 NameValuePair{ "Autodetect", "" },
126 NameValuePair{ "Speakers", "speakers" },
127 NameValuePair{ "Headphones", "headphones" },
129 constexpr std::array stereoEncList{
130 NameValuePair{ "Default", "" },
131 NameValuePair{ "Basic", "panpot" },
132 NameValuePair{ "UHJ", "uhj" },
133 NameValuePair{ "Binaural", "hrtf" },
135 constexpr std::array ambiFormatList{
136 NameValuePair{ "Default", "" },
137 NameValuePair{ "AmbiX (ACN, SN3D)", "ambix" },
138 NameValuePair{ "Furse-Malham", "fuma" },
139 NameValuePair{ "ACN, N3D", "acn+n3d" },
140 NameValuePair{ "ACN, FuMa", "acn+fuma" },
142 constexpr std::array hrtfModeList{
143 NameValuePair{ "1st Order Ambisonic", "ambi1" },
144 NameValuePair{ "2nd Order Ambisonic", "ambi2" },
145 NameValuePair{ "3rd Order Ambisonic", "ambi3" },
146 NameValuePair{ "Default (Full)", "" },
147 NameValuePair{ "Full", "full" },
150 #ifdef Q_OS_WIN32
151 struct CoTaskMemDeleter {
152 void operator()(void *buffer) { CoTaskMemFree(buffer); }
154 /* NOLINTNEXTLINE(*-avoid-c-arrays) */
155 using WCharBufferPtr = std::unique_ptr<WCHAR[],CoTaskMemDeleter>;
156 #endif
158 QString getDefaultConfigName()
160 #ifdef Q_OS_WIN32
161 const char *fname{"alsoft.ini"};
162 static constexpr auto get_appdata_path = []() -> QString
164 auto buffer = WCharBufferPtr{};
165 if(const HRESULT hr{SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_DONT_UNEXPAND,
166 nullptr, al::out_ptr(buffer))}; SUCCEEDED(hr))
167 return QString::fromWCharArray(buffer.get());
168 return QString{};
170 QString base = get_appdata_path();
171 #else
172 const char *fname{"alsoft.conf"};
173 QString base = qgetenv("XDG_CONFIG_HOME");
174 if(base.isEmpty())
176 base = qgetenv("HOME");
177 if(base.isEmpty() == false)
178 base += "/.config";
180 #endif
181 if(base.isEmpty() == false)
182 return base +'/'+ fname;
183 return fname;
186 QString getBaseDataPath()
188 #ifdef Q_OS_WIN32
189 static constexpr auto get_appdata_path = []() -> QString
191 auto buffer = WCharBufferPtr{};
192 if(const HRESULT hr{SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_DONT_UNEXPAND,
193 nullptr, al::out_ptr(buffer))}; SUCCEEDED(hr))
194 return QString::fromWCharArray(buffer.get());
195 return QString{};
197 QString base = get_appdata_path();
198 #else
199 QString base = qgetenv("XDG_DATA_HOME");
200 if(base.isEmpty())
202 base = qgetenv("HOME");
203 if(!base.isEmpty())
204 base += "/.local/share";
206 #endif
207 return base;
210 QStringList getAllDataPaths(const QString &append)
212 QStringList list;
213 list.append(getBaseDataPath());
214 #ifdef Q_OS_WIN32
215 // TODO: Common AppData path
216 #else
217 QString paths = qgetenv("XDG_DATA_DIRS");
218 if(paths.isEmpty())
219 paths = "/usr/local/share/:/usr/share/";
220 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
221 list += paths.split(QChar(':'), Qt::SkipEmptyParts);
222 #else
223 list += paths.split(QChar(':'), QString::SkipEmptyParts);
224 #endif
225 #endif
226 QStringList::iterator iter = list.begin();
227 while(iter != list.end())
229 if(iter->isEmpty())
230 iter = list.erase(iter);
231 else
233 iter->append(append);
234 iter++;
237 return list;
240 QString getValueFromName(const al::span<const NameValuePair> list, const QString &str)
242 for(size_t i{0};i < list.size();++i)
244 if(str == std::data(list[i].name))
245 return std::data(list[i].value);
247 return QString{};
250 QString getNameFromValue(const al::span<const NameValuePair> list, const QString &str)
252 for(size_t i{0};i < list.size();++i)
254 if(str == std::data(list[i].value))
255 return std::data(list[i].name);
257 return QString{};
261 Qt::CheckState getCheckState(const QVariant &var)
263 if(var.isNull())
264 return Qt::PartiallyChecked;
265 if(var.toBool())
266 return Qt::Checked;
267 return Qt::Unchecked;
270 QString getCheckValue(const QCheckBox *checkbox)
272 const Qt::CheckState state{checkbox->checkState()};
273 if(state == Qt::Checked)
274 return QStringLiteral("true");
275 if(state == Qt::Unchecked)
276 return QStringLiteral("false");
277 return QString{};
282 MainWindow::MainWindow(QWidget *parent) : QMainWindow{parent}
283 , ui{std::make_unique<Ui::MainWindow>()}
285 ui->setupUi(this);
287 for(auto &item : speakerModeList)
288 ui->channelConfigCombo->addItem(std::data(item.name));
289 ui->channelConfigCombo->adjustSize();
290 for(auto &item : sampleTypeList)
291 ui->sampleFormatCombo->addItem(std::data(item.name));
292 ui->sampleFormatCombo->adjustSize();
293 for(auto &item : stereoModeList)
294 ui->stereoModeCombo->addItem(std::data(item.name));
295 ui->stereoModeCombo->adjustSize();
296 for(auto &item : stereoEncList)
297 ui->stereoEncodingComboBox->addItem(std::data(item.name));
298 ui->stereoEncodingComboBox->adjustSize();
299 for(auto &item : ambiFormatList)
300 ui->ambiFormatComboBox->addItem(std::data(item.name));
301 ui->ambiFormatComboBox->adjustSize();
303 ui->resamplerSlider->setRange(0, resamplerList.size()-1);
304 ui->hrtfmodeSlider->setRange(0, hrtfModeList.size()-1);
306 #if !HAVE_NEON && !HAVE_SSE
307 ui->cpuExtDisabledLabel->move(ui->cpuExtDisabledLabel->x(), ui->cpuExtDisabledLabel->y() - 60);
308 #else
309 ui->cpuExtDisabledLabel->setVisible(false);
310 #endif
312 #if !HAVE_NEON
314 #if !HAVE_SSE4_1
315 #if !HAVE_SSE3
316 #if !HAVE_SSE2
317 #if !HAVE_SSE
318 ui->enableSSECheckBox->setVisible(false);
319 #endif /* !SSE */
320 ui->enableSSE2CheckBox->setVisible(false);
321 #endif /* !SSE2 */
322 ui->enableSSE3CheckBox->setVisible(false);
323 #endif /* !SSE3 */
324 ui->enableSSE41CheckBox->setVisible(false);
325 #endif /* !SSE4.1 */
326 ui->enableNeonCheckBox->setVisible(false);
328 #else /* !Neon */
330 #if !HAVE_SSE4_1
331 #if !HAVE_SSE3
332 #if !HAVE_SSE2
333 #if !HAVE_SSE
334 ui->enableNeonCheckBox->move(ui->enableNeonCheckBox->x(), ui->enableNeonCheckBox->y() - 30);
335 ui->enableSSECheckBox->setVisible(false);
336 #endif /* !SSE */
337 ui->enableSSE2CheckBox->setVisible(false);
338 #endif /* !SSE2 */
339 ui->enableSSE3CheckBox->setVisible(false);
340 #endif /* !SSE3 */
341 ui->enableSSE41CheckBox->setVisible(false);
342 #endif /* !SSE4.1 */
344 #endif
346 #if !ALSOFT_EAX
347 ui->enableEaxCheck->setChecked(Qt::Unchecked);
348 ui->enableEaxCheck->setEnabled(false);
349 ui->enableEaxCheck->setVisible(false);
350 #endif
352 mPeriodSizeValidator = std::make_unique<QIntValidator>(64, 8192, this);
353 ui->periodSizeEdit->setValidator(mPeriodSizeValidator.get());
354 mPeriodCountValidator = std::make_unique<QIntValidator>(2, 16, this);
355 ui->periodCountEdit->setValidator(mPeriodCountValidator.get());
357 mSourceCountValidator = std::make_unique<QIntValidator>(0, 4096, this);
358 ui->srcCountLineEdit->setValidator(mSourceCountValidator.get());
359 mEffectSlotValidator = std::make_unique<QIntValidator>(0, 64, this);
360 ui->effectSlotLineEdit->setValidator(mEffectSlotValidator.get());
361 mSourceSendValidator = std::make_unique<QIntValidator>(0, 16, this);
362 ui->srcSendLineEdit->setValidator(mSourceSendValidator.get());
363 mSampleRateValidator = std::make_unique<QIntValidator>(8000, 192000, this);
364 ui->sampleRateCombo->lineEdit()->setValidator(mSampleRateValidator.get());
366 mJackBufferValidator = std::make_unique<QIntValidator>(0, 8192, this);
367 ui->jackBufferSizeLine->setValidator(mJackBufferValidator.get());
369 connect(ui->actionLoad, &QAction::triggered, this, &MainWindow::loadConfigFromFile);
370 connect(ui->actionSave_As, &QAction::triggered, this, &MainWindow::saveConfigAsFile);
372 connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::showAboutPage);
374 connect(ui->closeCancelButton, &QPushButton::clicked, this, &MainWindow::cancelCloseAction);
375 connect(ui->applyButton, &QPushButton::clicked, this, &MainWindow::saveCurrentConfig);
377 auto qcb_cicint = static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged);
378 connect(ui->channelConfigCombo, qcb_cicint, this, &MainWindow::enableApplyButton);
379 connect(ui->sampleFormatCombo, qcb_cicint, this, &MainWindow::enableApplyButton);
380 connect(ui->stereoModeCombo, qcb_cicint, this, &MainWindow::enableApplyButton);
381 connect(ui->sampleRateCombo, qcb_cicint, this, &MainWindow::enableApplyButton);
382 connect(ui->sampleRateCombo, &QComboBox::editTextChanged, this, &MainWindow::enableApplyButton);
384 connect(ui->resamplerSlider, &QSlider::valueChanged, this, &MainWindow::updateResamplerLabel);
386 connect(ui->periodSizeSlider, &QSlider::valueChanged, this, &MainWindow::updatePeriodSizeEdit);
387 connect(ui->periodSizeEdit, &QLineEdit::editingFinished, this, &MainWindow::updatePeriodSizeSlider);
388 connect(ui->periodCountSlider, &QSlider::valueChanged, this, &MainWindow::updatePeriodCountEdit);
389 connect(ui->periodCountEdit, &QLineEdit::editingFinished, this, &MainWindow::updatePeriodCountSlider);
391 connect(ui->stereoEncodingComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
392 connect(ui->ambiFormatComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
393 connect(ui->outputLimiterCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
394 connect(ui->outputDitherCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
396 connect(ui->decoderHQModeCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
397 connect(ui->decoderDistCompCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
398 connect(ui->decoderNFEffectsCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
399 auto qdsb_vcd = static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged);
400 connect(ui->decoderSpeakerDistSpinBox, qdsb_vcd, this, &MainWindow::enableApplyButton);
401 connect(ui->decoderQuadLineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
402 connect(ui->decoderQuadButton, &QPushButton::clicked, this, &MainWindow::selectQuadDecoderFile);
403 connect(ui->decoder51LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
404 connect(ui->decoder51Button, &QPushButton::clicked, this, &MainWindow::select51DecoderFile);
405 connect(ui->decoder61LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
406 connect(ui->decoder61Button, &QPushButton::clicked, this, &MainWindow::select61DecoderFile);
407 connect(ui->decoder71LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
408 connect(ui->decoder71Button, &QPushButton::clicked, this, &MainWindow::select71DecoderFile);
409 connect(ui->decoder3D71LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
410 connect(ui->decoder3D71Button, &QPushButton::clicked, this, &MainWindow::select3D71DecoderFile);
412 connect(ui->preferredHrtfComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
413 connect(ui->hrtfmodeSlider, &QSlider::valueChanged, this, &MainWindow::updateHrtfModeLabel);
415 connect(ui->hrtfAddButton, &QPushButton::clicked, this, &MainWindow::addHrtfFile);
416 connect(ui->hrtfRemoveButton, &QPushButton::clicked, this, &MainWindow::removeHrtfFile);
417 connect(ui->hrtfFileList, &QListWidget::itemSelectionChanged, this, &MainWindow::updateHrtfRemoveButton);
418 connect(ui->defaultHrtfPathsCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
420 connect(ui->srcCountLineEdit, &QLineEdit::editingFinished, this, &MainWindow::enableApplyButton);
421 connect(ui->srcSendLineEdit, &QLineEdit::editingFinished, this, &MainWindow::enableApplyButton);
422 connect(ui->effectSlotLineEdit, &QLineEdit::editingFinished, this, &MainWindow::enableApplyButton);
424 connect(ui->enableSSECheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
425 connect(ui->enableSSE2CheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
426 connect(ui->enableSSE3CheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
427 connect(ui->enableSSE41CheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
428 connect(ui->enableNeonCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
430 ui->enabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
431 connect(ui->enabledBackendList, &QListWidget::customContextMenuRequested, this, &MainWindow::showEnabledBackendMenu);
433 ui->disabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
434 connect(ui->disabledBackendList, &QListWidget::customContextMenuRequested, this, &MainWindow::showDisabledBackendMenu);
435 connect(ui->backendCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
437 connect(ui->defaultReverbComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
438 connect(ui->enableEaxReverbCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
439 connect(ui->enableStdReverbCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
440 connect(ui->enableAutowahCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
441 connect(ui->enableChorusCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
442 connect(ui->enableCompressorCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
443 connect(ui->enableDistortionCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
444 connect(ui->enableEchoCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
445 connect(ui->enableEqualizerCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
446 connect(ui->enableFlangerCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
447 connect(ui->enableFrequencyShifterCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
448 connect(ui->enableModulatorCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
449 connect(ui->enableDedicatedCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
450 connect(ui->enablePitchShifterCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
451 connect(ui->enableVocalMorpherCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
452 connect(ui->enableEaxCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
454 connect(ui->pulseAutospawnCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
455 connect(ui->pulseAllowMovesCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
456 connect(ui->pulseFixRateCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
457 connect(ui->pulseAdjLatencyCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
459 connect(ui->pwireAssumeAudioCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
460 connect(ui->pwireRtMixCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
462 connect(ui->wasapiResamplerCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
464 connect(ui->jackAutospawnCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
465 connect(ui->jackConnectPortsCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
466 connect(ui->jackRtMixCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
467 connect(ui->jackBufferSizeSlider, &QSlider::valueChanged, this, &MainWindow::updateJackBufferSizeEdit);
468 connect(ui->jackBufferSizeLine, &QLineEdit::editingFinished, this, &MainWindow::updateJackBufferSizeSlider);
470 connect(ui->alsaDefaultDeviceLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
471 connect(ui->alsaDefaultCaptureLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
472 connect(ui->alsaResamplerCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
473 connect(ui->alsaMmapCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
475 connect(ui->ossDefaultDeviceLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
476 connect(ui->ossPlaybackPushButton, &QPushButton::clicked, this, &MainWindow::selectOSSPlayback);
477 connect(ui->ossDefaultCaptureLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
478 connect(ui->ossCapturePushButton, &QPushButton::clicked, this, &MainWindow::selectOSSCapture);
480 connect(ui->solarisDefaultDeviceLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
481 connect(ui->solarisPlaybackPushButton, &QPushButton::clicked, this, &MainWindow::selectSolarisPlayback);
483 connect(ui->waveOutputLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
484 connect(ui->waveOutputButton, &QPushButton::clicked, this, &MainWindow::selectWaveOutput);
485 connect(ui->waveBFormatCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
487 ui->backendListWidget->setCurrentRow(0);
488 ui->tabWidget->setCurrentIndex(0);
490 for(int i = 1;i < ui->backendListWidget->count();i++)
491 ui->backendListWidget->setRowHidden(i, true);
492 for(size_t i{0};i < backendList.size();++i)
494 QList<QListWidgetItem*> items = ui->backendListWidget->findItems(
495 std::data(backendList[i].full_string), Qt::MatchFixedString);
496 Q_FOREACH(QListWidgetItem *item, items)
497 item->setHidden(false);
500 loadConfig(getDefaultConfigName());
503 MainWindow::~MainWindow() = default;
505 void MainWindow::closeEvent(QCloseEvent *event)
507 if(!mNeedsSave)
508 event->accept();
509 else
511 QMessageBox::StandardButton btn = QMessageBox::warning(this,
512 tr("Apply changes?"), tr("Save changes before quitting?"),
513 QMessageBox::Save | QMessageBox::No | QMessageBox::Cancel);
514 if(btn == QMessageBox::Save)
515 saveCurrentConfig();
516 if(btn == QMessageBox::Cancel)
517 event->ignore();
518 else
519 event->accept();
523 void MainWindow::cancelCloseAction()
525 mNeedsSave = false;
526 close();
530 void MainWindow::showAboutPage()
532 QMessageBox::information(this, tr("About"),
533 tr("OpenAL Soft Configuration Utility.\nBuilt for OpenAL Soft library version ") +
534 GetVersionString());
538 QStringList MainWindow::collectHrtfs()
540 QStringList ret;
541 QStringList processed;
543 for(int i = 0;i < ui->hrtfFileList->count();i++)
545 QDir dir(ui->hrtfFileList->item(i)->text());
546 QStringList fnames = dir.entryList(QDir::Files | QDir::Readable, QDir::Name);
547 Q_FOREACH(const QString &fname, fnames)
549 if(!fname.endsWith(QStringLiteral(".mhr"), Qt::CaseInsensitive))
550 continue;
551 QString fullname{dir.absoluteFilePath(fname)};
552 if(processed.contains(fullname))
553 continue;
554 processed.push_back(fullname);
556 QString name{fname.left(fname.length()-4)};
557 if(!ret.contains(name))
558 ret.push_back(name);
559 else
561 size_t i{2};
562 do {
563 QString s = name+" #"+QString::number(i);
564 if(!ret.contains(s))
566 ret.push_back(s);
567 break;
569 ++i;
570 } while(true);
575 if(ui->defaultHrtfPathsCheckBox->isChecked())
577 QStringList paths = getAllDataPaths(QStringLiteral("/openal/hrtf"));
578 Q_FOREACH(const QString &name, paths)
580 QDir dir{name};
581 QStringList fnames{dir.entryList(QDir::Files | QDir::Readable, QDir::Name)};
582 Q_FOREACH(const QString &fname, fnames)
584 if(!fname.endsWith(QStringLiteral(".mhr"), Qt::CaseInsensitive))
585 continue;
586 QString fullname{dir.absoluteFilePath(fname)};
587 if(processed.contains(fullname))
588 continue;
589 processed.push_back(fullname);
591 QString name{fname.left(fname.length()-4)};
592 if(!ret.contains(name))
593 ret.push_back(name);
594 else
596 size_t i{2};
597 do {
598 QString s{name+" #"+QString::number(i)};
599 if(!ret.contains(s))
601 ret.push_back(s);
602 break;
604 ++i;
605 } while(true);
610 #ifdef ALSOFT_EMBED_HRTF_DATA
611 ret.push_back(QStringLiteral("Built-In HRTF"));
612 #endif
614 return ret;
618 void MainWindow::loadConfigFromFile()
620 QString fname = QFileDialog::getOpenFileName(this, tr("Select Files"));
621 if(fname.isEmpty() == false)
622 loadConfig(fname);
625 void MainWindow::loadConfig(const QString &fname)
627 QSettings settings{fname, QSettings::IniFormat};
629 QString sampletype{settings.value(QStringLiteral("sample-type")).toString()};
630 ui->sampleFormatCombo->setCurrentIndex(0);
631 if(sampletype.isEmpty() == false)
633 QString str{getNameFromValue(sampleTypeList, sampletype)};
634 if(!str.isEmpty())
636 const int j{ui->sampleFormatCombo->findText(str)};
637 if(j > 0) ui->sampleFormatCombo->setCurrentIndex(j);
641 QString channelconfig{settings.value(QStringLiteral("channels")).toString()};
642 ui->channelConfigCombo->setCurrentIndex(0);
643 if(channelconfig.isEmpty() == false)
645 if(channelconfig == QStringLiteral("surround51rear"))
646 channelconfig = QStringLiteral("surround51");
647 QString str{getNameFromValue(speakerModeList, channelconfig)};
648 if(!str.isEmpty())
650 const int j{ui->channelConfigCombo->findText(str)};
651 if(j > 0) ui->channelConfigCombo->setCurrentIndex(j);
655 QString srate{settings.value(QStringLiteral("frequency")).toString()};
656 if(srate.isEmpty())
657 ui->sampleRateCombo->setCurrentIndex(0);
658 else
660 ui->sampleRateCombo->lineEdit()->clear();
661 ui->sampleRateCombo->lineEdit()->insert(srate);
664 ui->srcCountLineEdit->clear();
665 ui->srcCountLineEdit->insert(settings.value(QStringLiteral("sources")).toString());
666 ui->effectSlotLineEdit->clear();
667 ui->effectSlotLineEdit->insert(settings.value(QStringLiteral("slots")).toString());
668 ui->srcSendLineEdit->clear();
669 ui->srcSendLineEdit->insert(settings.value(QStringLiteral("sends")).toString());
671 QString resampler = settings.value(QStringLiteral("resampler")).toString().trimmed();
672 ui->resamplerSlider->setValue(2);
673 ui->resamplerLabel->setText(std::data(resamplerList[2].name));
674 /* "Cubic" is an alias for the 4-point spline resampler. The "sinc4" and
675 * "sinc8" resamplers are unsupported, use "gaussian" as a fallback.
677 if(resampler == QLatin1String{"cubic"})
678 resampler = QStringLiteral("spline");
679 else if(resampler == QLatin1String{"sinc4"} || resampler == QLatin1String{"sinc8"})
680 resampler = QStringLiteral("gaussian");
681 /* The "bsinc" resampler name is an alias for "bsinc12". */
682 else if(resampler == QLatin1String{"bsinc"})
683 resampler = QStringLiteral("bsinc12");
684 for(int i = 0;resamplerList[i].name[0];i++)
686 if(resampler == std::data(resamplerList[i].value))
688 ui->resamplerSlider->setValue(i);
689 ui->resamplerLabel->setText(std::data(resamplerList[i].name));
690 break;
694 QString stereomode{settings.value(QStringLiteral("stereo-mode")).toString().trimmed()};
695 ui->stereoModeCombo->setCurrentIndex(0);
696 if(stereomode.isEmpty() == false)
698 QString str{getNameFromValue(stereoModeList, stereomode)};
699 if(!str.isEmpty())
701 const int j{ui->stereoModeCombo->findText(str)};
702 if(j > 0) ui->stereoModeCombo->setCurrentIndex(j);
706 int periodsize{settings.value("period_size").toInt()};
707 ui->periodSizeEdit->clear();
708 if(periodsize >= 64)
710 ui->periodSizeEdit->insert(QString::number(periodsize));
711 updatePeriodSizeSlider();
714 int periodcount{settings.value("periods").toInt()};
715 ui->periodCountEdit->clear();
716 if(periodcount >= 2)
718 ui->periodCountEdit->insert(QString::number(periodcount));
719 updatePeriodCountSlider();
722 ui->outputLimiterCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("output-limiter"))));
723 ui->outputDitherCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("dither"))));
725 QString stereopan{settings.value(QStringLiteral("stereo-encoding")).toString()};
726 ui->stereoEncodingComboBox->setCurrentIndex(0);
727 if(stereopan.isEmpty() == false)
729 QString str{getNameFromValue(stereoEncList, stereopan)};
730 if(!str.isEmpty())
732 const int j{ui->stereoEncodingComboBox->findText(str)};
733 if(j > 0) ui->stereoEncodingComboBox->setCurrentIndex(j);
737 QString ambiformat{settings.value(QStringLiteral("ambi-format")).toString()};
738 ui->ambiFormatComboBox->setCurrentIndex(0);
739 if(ambiformat.isEmpty() == false)
741 QString str{getNameFromValue(ambiFormatList, ambiformat)};
742 if(!str.isEmpty())
744 const int j{ui->ambiFormatComboBox->findText(str)};
745 if(j > 0) ui->ambiFormatComboBox->setCurrentIndex(j);
749 ui->decoderHQModeCheckBox->setChecked(getCheckState(settings.value(QStringLiteral("decoder/hq-mode"))));
750 ui->decoderDistCompCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("decoder/distance-comp"))));
751 ui->decoderNFEffectsCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("decoder/nfc"))));
752 double speakerdist{settings.value(QStringLiteral("decoder/speaker-dist"), 1.0).toDouble()};
753 ui->decoderSpeakerDistSpinBox->setValue(speakerdist);
755 ui->decoderQuadLineEdit->setText(settings.value(QStringLiteral("decoder/quad")).toString());
756 ui->decoder51LineEdit->setText(settings.value(QStringLiteral("decoder/surround51")).toString());
757 ui->decoder61LineEdit->setText(settings.value(QStringLiteral("decoder/surround61")).toString());
758 ui->decoder71LineEdit->setText(settings.value(QStringLiteral("decoder/surround71")).toString());
759 ui->decoder3D71LineEdit->setText(settings.value(QStringLiteral("decoder/surround3d71")).toString());
761 QStringList disabledCpuExts{settings.value(QStringLiteral("disable-cpu-exts")).toStringList()};
762 if(disabledCpuExts.size() == 1)
763 disabledCpuExts = disabledCpuExts[0].split(QChar(','));
764 for(QString &name : disabledCpuExts)
765 name = name.trimmed();
766 ui->enableSSECheckBox->setChecked(!disabledCpuExts.contains(QStringLiteral("sse"), Qt::CaseInsensitive));
767 ui->enableSSE2CheckBox->setChecked(!disabledCpuExts.contains(QStringLiteral("sse2"), Qt::CaseInsensitive));
768 ui->enableSSE3CheckBox->setChecked(!disabledCpuExts.contains(QStringLiteral("sse3"), Qt::CaseInsensitive));
769 ui->enableSSE41CheckBox->setChecked(!disabledCpuExts.contains(QStringLiteral("sse4.1"), Qt::CaseInsensitive));
770 ui->enableNeonCheckBox->setChecked(!disabledCpuExts.contains(QStringLiteral("neon"), Qt::CaseInsensitive));
772 QString hrtfmode{settings.value(QStringLiteral("hrtf-mode")).toString().trimmed()};
773 ui->hrtfmodeSlider->setValue(2);
774 ui->hrtfmodeLabel->setText(std::data(hrtfModeList[3].name));
775 /* The "basic" mode name is no longer supported. Use "ambi2" instead. */
776 if(hrtfmode == QLatin1String{"basic"})
777 hrtfmode = QStringLiteral("ambi2");
778 for(size_t i{0};i < hrtfModeList.size();++i)
780 if(hrtfmode == std::data(hrtfModeList[i].value))
782 ui->hrtfmodeSlider->setValue(static_cast<int>(i));
783 ui->hrtfmodeLabel->setText(std::data(hrtfModeList[i].name));
784 break;
788 QStringList hrtf_paths{settings.value(QStringLiteral("hrtf-paths")).toStringList()};
789 if(hrtf_paths.size() == 1)
790 hrtf_paths = hrtf_paths[0].split(QChar(','));
791 for(QString &name : hrtf_paths)
792 name = name.trimmed();
793 if(!hrtf_paths.empty() && !hrtf_paths.back().isEmpty())
794 ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Unchecked);
795 else
797 hrtf_paths.removeAll(QString());
798 ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Checked);
800 hrtf_paths.removeDuplicates();
801 ui->hrtfFileList->clear();
802 ui->hrtfFileList->addItems(hrtf_paths);
803 updateHrtfRemoveButton();
805 ui->preferredHrtfComboBox->clear();
806 ui->preferredHrtfComboBox->addItem(QStringLiteral("- Any -"));
807 if(ui->defaultHrtfPathsCheckBox->isChecked())
809 QStringList hrtfs{collectHrtfs()};
810 Q_FOREACH(const QString &name, hrtfs)
811 ui->preferredHrtfComboBox->addItem(name);
814 QString defaulthrtf{settings.value(QStringLiteral("default-hrtf")).toString()};
815 ui->preferredHrtfComboBox->setCurrentIndex(0);
816 if(defaulthrtf.isEmpty() == false)
818 int i{ui->preferredHrtfComboBox->findText(defaulthrtf)};
819 if(i > 0)
820 ui->preferredHrtfComboBox->setCurrentIndex(i);
821 else
823 i = ui->preferredHrtfComboBox->count();
824 ui->preferredHrtfComboBox->addItem(defaulthrtf);
825 ui->preferredHrtfComboBox->setCurrentIndex(i);
828 ui->preferredHrtfComboBox->adjustSize();
830 ui->enabledBackendList->clear();
831 ui->disabledBackendList->clear();
832 QStringList drivers{settings.value(QStringLiteral("drivers")).toStringList()};
833 if(drivers.empty())
834 ui->backendCheckBox->setChecked(true);
835 else
837 if(drivers.size() == 1)
838 drivers = drivers[0].split(QChar(','));
839 for(QString &name : drivers)
841 name = name.trimmed();
842 /* Convert "mmdevapi" references to "wasapi" for backwards
843 * compatibility.
845 if(name == QLatin1String{"-mmdevapi"})
846 name = QStringLiteral("-wasapi");
847 else if(name == QLatin1String{"mmdevapi"})
848 name = QStringLiteral("wasapi");
851 bool lastWasEmpty{false};
852 Q_FOREACH(const QString &backend, drivers)
854 lastWasEmpty = backend.isEmpty();
855 if(lastWasEmpty) continue;
857 if(!backend.startsWith(QChar('-')))
859 for(size_t j{0};j < backendList.size();++j)
861 if(backend == std::data(backendList[j].backend_name))
863 ui->enabledBackendList->addItem(std::data(backendList[j].full_string));
864 break;
868 else if(backend.size() > 1)
870 QStringRef backendref{backend.rightRef(backend.size()-1)};
871 for(size_t j{0};j < backendList.size();++j)
873 if(backendref == std::data(backendList[j].backend_name))
875 ui->disabledBackendList->addItem(std::data(backendList[j].full_string));
876 break;
881 ui->backendCheckBox->setChecked(lastWasEmpty);
884 QString defaultreverb{settings.value(QStringLiteral("default-reverb")).toString().toLower()};
885 ui->defaultReverbComboBox->setCurrentIndex(0);
886 if(defaultreverb.isEmpty() == false)
888 for(int i = 0;i < ui->defaultReverbComboBox->count();i++)
890 if(defaultreverb.compare(ui->defaultReverbComboBox->itemText(i).toLower()) == 0)
892 ui->defaultReverbComboBox->setCurrentIndex(i);
893 break;
898 QStringList excludefx{settings.value(QStringLiteral("excludefx")).toStringList()};
899 if(excludefx.size() == 1)
900 excludefx = excludefx[0].split(QChar(','));
901 for(QString &name : excludefx)
902 name = name.trimmed();
903 ui->enableEaxReverbCheck->setChecked(!excludefx.contains(QStringLiteral("eaxreverb"), Qt::CaseInsensitive));
904 ui->enableStdReverbCheck->setChecked(!excludefx.contains(QStringLiteral("reverb"), Qt::CaseInsensitive));
905 ui->enableAutowahCheck->setChecked(!excludefx.contains(QStringLiteral("autowah"), Qt::CaseInsensitive));
906 ui->enableChorusCheck->setChecked(!excludefx.contains(QStringLiteral("chorus"), Qt::CaseInsensitive));
907 ui->enableCompressorCheck->setChecked(!excludefx.contains(QStringLiteral("compressor"), Qt::CaseInsensitive));
908 ui->enableDistortionCheck->setChecked(!excludefx.contains(QStringLiteral("distortion"), Qt::CaseInsensitive));
909 ui->enableEchoCheck->setChecked(!excludefx.contains(QStringLiteral("echo"), Qt::CaseInsensitive));
910 ui->enableEqualizerCheck->setChecked(!excludefx.contains(QStringLiteral("equalizer"), Qt::CaseInsensitive));
911 ui->enableFlangerCheck->setChecked(!excludefx.contains(QStringLiteral("flanger"), Qt::CaseInsensitive));
912 ui->enableFrequencyShifterCheck->setChecked(!excludefx.contains(QStringLiteral("fshifter"), Qt::CaseInsensitive));
913 ui->enableModulatorCheck->setChecked(!excludefx.contains(QStringLiteral("modulator"), Qt::CaseInsensitive));
914 ui->enableDedicatedCheck->setChecked(!excludefx.contains(QStringLiteral("dedicated"), Qt::CaseInsensitive));
915 ui->enablePitchShifterCheck->setChecked(!excludefx.contains(QStringLiteral("pshifter"), Qt::CaseInsensitive));
916 ui->enableVocalMorpherCheck->setChecked(!excludefx.contains(QStringLiteral("vmorpher"), Qt::CaseInsensitive));
917 if(ui->enableEaxCheck->isEnabled())
918 ui->enableEaxCheck->setChecked(getCheckState(settings.value(QStringLiteral("eax/enable"))) != Qt::Unchecked);
920 ui->pulseAutospawnCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("pulse/spawn-server"))));
921 ui->pulseAllowMovesCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("pulse/allow-moves"))));
922 ui->pulseFixRateCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("pulse/fix-rate"))));
923 ui->pulseAdjLatencyCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("pulse/adjust-latency"))));
925 ui->pwireAssumeAudioCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("pipewire/assume-audio"))));
926 ui->pwireRtMixCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("pipewire/rt-mix"))));
928 ui->wasapiResamplerCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("wasapi/allow-resampler"))));
930 ui->jackAutospawnCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("jack/spawn-server"))));
931 ui->jackConnectPortsCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("jack/connect-ports"))));
932 ui->jackRtMixCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("jack/rt-mix"))));
933 ui->jackBufferSizeLine->setText(settings.value(QStringLiteral("jack/buffer-size"), QString()).toString());
934 updateJackBufferSizeSlider();
936 ui->alsaDefaultDeviceLine->setText(settings.value(QStringLiteral("alsa/device"), QString()).toString());
937 ui->alsaDefaultCaptureLine->setText(settings.value(QStringLiteral("alsa/capture"), QString()).toString());
938 ui->alsaResamplerCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("alsa/allow-resampler"))));
939 ui->alsaMmapCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("alsa/mmap"))));
941 ui->ossDefaultDeviceLine->setText(settings.value(QStringLiteral("oss/device"), QString()).toString());
942 ui->ossDefaultCaptureLine->setText(settings.value(QStringLiteral("oss/capture"), QString()).toString());
944 ui->solarisDefaultDeviceLine->setText(settings.value(QStringLiteral("solaris/device"), QString()).toString());
946 ui->waveOutputLine->setText(settings.value(QStringLiteral("wave/file"), QString()).toString());
947 ui->waveBFormatCheckBox->setChecked(settings.value(QStringLiteral("wave/bformat"), false).toBool());
949 ui->applyButton->setEnabled(false);
950 ui->closeCancelButton->setText(tr("Close"));
951 mNeedsSave = false;
954 void MainWindow::saveCurrentConfig()
956 saveConfig(getDefaultConfigName());
957 ui->applyButton->setEnabled(false);
958 ui->closeCancelButton->setText(tr("Close"));
959 mNeedsSave = false;
960 QMessageBox::information(this, tr("Information"),
961 tr("Applications using OpenAL need to be restarted for changes to take effect."));
964 void MainWindow::saveConfigAsFile()
966 QString fname{QFileDialog::getOpenFileName(this, tr("Select Files"))};
967 if(fname.isEmpty() == false)
969 saveConfig(fname);
970 ui->applyButton->setEnabled(false);
971 mNeedsSave = false;
975 void MainWindow::saveConfig(const QString &fname) const
977 QSettings settings{fname, QSettings::IniFormat};
979 /* HACK: Compound any stringlist values into a comma-separated string. */
980 QStringList allkeys{settings.allKeys()};
981 Q_FOREACH(const QString &key, allkeys)
983 QStringList vals{settings.value(key).toStringList()};
984 if(vals.size() > 1)
985 settings.setValue(key, vals.join(QChar(',')));
988 settings.setValue(QStringLiteral("sample-type"), getValueFromName(sampleTypeList, ui->sampleFormatCombo->currentText()));
989 settings.setValue(QStringLiteral("channels"), getValueFromName(speakerModeList, ui->channelConfigCombo->currentText()));
991 uint rate{ui->sampleRateCombo->currentText().toUInt()};
992 if(rate <= 0)
993 settings.setValue(QStringLiteral("frequency"), QString{});
994 else
995 settings.setValue(QStringLiteral("frequency"), rate);
997 settings.setValue(QStringLiteral("period_size"), ui->periodSizeEdit->text());
998 settings.setValue(QStringLiteral("periods"), ui->periodCountEdit->text());
1000 settings.setValue(QStringLiteral("sources"), ui->srcCountLineEdit->text());
1001 settings.setValue(QStringLiteral("slots"), ui->effectSlotLineEdit->text());
1003 settings.setValue(QStringLiteral("resampler"), std::data(resamplerList[ui->resamplerSlider->value()].value));
1005 settings.setValue(QStringLiteral("stereo-mode"), getValueFromName(stereoModeList, ui->stereoModeCombo->currentText()));
1006 settings.setValue(QStringLiteral("stereo-encoding"), getValueFromName(stereoEncList, ui->stereoEncodingComboBox->currentText()));
1007 settings.setValue(QStringLiteral("ambi-format"), getValueFromName(ambiFormatList, ui->ambiFormatComboBox->currentText()));
1009 settings.setValue(QStringLiteral("output-limiter"), getCheckValue(ui->outputLimiterCheckBox));
1010 settings.setValue(QStringLiteral("dither"), getCheckValue(ui->outputDitherCheckBox));
1012 settings.setValue(QStringLiteral("decoder/hq-mode"), getCheckValue(ui->decoderHQModeCheckBox));
1013 settings.setValue(QStringLiteral("decoder/distance-comp"), getCheckValue(ui->decoderDistCompCheckBox));
1014 settings.setValue(QStringLiteral("decoder/nfc"), getCheckValue(ui->decoderNFEffectsCheckBox));
1015 double speakerdist{ui->decoderSpeakerDistSpinBox->value()};
1016 settings.setValue(QStringLiteral("decoder/speaker-dist"),
1017 (speakerdist != 1.0) ? QString::number(speakerdist) : QString{}
1020 settings.setValue(QStringLiteral("decoder/quad"), ui->decoderQuadLineEdit->text());
1021 settings.setValue(QStringLiteral("decoder/surround51"), ui->decoder51LineEdit->text());
1022 settings.setValue(QStringLiteral("decoder/surround61"), ui->decoder61LineEdit->text());
1023 settings.setValue(QStringLiteral("decoder/surround71"), ui->decoder71LineEdit->text());
1024 settings.setValue(QStringLiteral("decoder/surround3d71"), ui->decoder3D71LineEdit->text());
1026 QStringList strlist;
1027 if(!ui->enableSSECheckBox->isChecked())
1028 strlist.append(QStringLiteral("sse"));
1029 if(!ui->enableSSE2CheckBox->isChecked())
1030 strlist.append(QStringLiteral("sse2"));
1031 if(!ui->enableSSE3CheckBox->isChecked())
1032 strlist.append(QStringLiteral("sse3"));
1033 if(!ui->enableSSE41CheckBox->isChecked())
1034 strlist.append(QStringLiteral("sse4.1"));
1035 if(!ui->enableNeonCheckBox->isChecked())
1036 strlist.append(QStringLiteral("neon"));
1037 settings.setValue(QStringLiteral("disable-cpu-exts"), strlist.join(QChar(',')));
1039 settings.setValue(QStringLiteral("hrtf-mode"), std::data(hrtfModeList[ui->hrtfmodeSlider->value()].value));
1041 if(ui->preferredHrtfComboBox->currentIndex() == 0)
1042 settings.setValue(QStringLiteral("default-hrtf"), QString{});
1043 else
1045 QString str{ui->preferredHrtfComboBox->currentText()};
1046 settings.setValue(QStringLiteral("default-hrtf"), str);
1049 strlist.clear();
1050 strlist.reserve(ui->hrtfFileList->count());
1051 for(int i = 0;i < ui->hrtfFileList->count();i++)
1052 strlist.append(ui->hrtfFileList->item(i)->text());
1053 if(!strlist.empty() && ui->defaultHrtfPathsCheckBox->isChecked())
1054 strlist.append(QString{});
1055 settings.setValue(QStringLiteral("hrtf-paths"), strlist.join(QChar{','}));
1057 strlist.clear();
1058 for(int i = 0;i < ui->enabledBackendList->count();i++)
1060 QString label{ui->enabledBackendList->item(i)->text()};
1061 for(size_t j{0};j < backendList.size();++j)
1063 if(label == std::data(backendList[j].full_string))
1065 strlist.append(std::data(backendList[j].backend_name));
1066 break;
1070 for(int i = 0;i < ui->disabledBackendList->count();i++)
1072 QString label{ui->disabledBackendList->item(i)->text()};
1073 for(size_t j{0};j < backendList.size();++j)
1075 if(label == std::data(backendList[j].full_string))
1077 strlist.append(QChar{'-'}+QString{std::data(backendList[j].backend_name)});
1078 break;
1082 if(strlist.empty() && !ui->backendCheckBox->isChecked())
1083 strlist.append(QStringLiteral("-all"));
1084 else if(ui->backendCheckBox->isChecked())
1085 strlist.append(QString{});
1086 settings.setValue(QStringLiteral("drivers"), strlist.join(QChar(',')));
1088 // TODO: Remove check when we can properly match global values.
1089 if(ui->defaultReverbComboBox->currentIndex() == 0)
1090 settings.setValue(QStringLiteral("default-reverb"), QString{});
1091 else
1093 QString str{ui->defaultReverbComboBox->currentText().toLower()};
1094 settings.setValue(QStringLiteral("default-reverb"), str);
1097 strlist.clear();
1098 if(!ui->enableEaxReverbCheck->isChecked())
1099 strlist.append(QStringLiteral("eaxreverb"));
1100 if(!ui->enableStdReverbCheck->isChecked())
1101 strlist.append(QStringLiteral("reverb"));
1102 if(!ui->enableAutowahCheck->isChecked())
1103 strlist.append(QStringLiteral("autowah"));
1104 if(!ui->enableChorusCheck->isChecked())
1105 strlist.append(QStringLiteral("chorus"));
1106 if(!ui->enableDistortionCheck->isChecked())
1107 strlist.append(QStringLiteral("distortion"));
1108 if(!ui->enableCompressorCheck->isChecked())
1109 strlist.append(QStringLiteral("compressor"));
1110 if(!ui->enableEchoCheck->isChecked())
1111 strlist.append(QStringLiteral("echo"));
1112 if(!ui->enableEqualizerCheck->isChecked())
1113 strlist.append(QStringLiteral("equalizer"));
1114 if(!ui->enableFlangerCheck->isChecked())
1115 strlist.append(QStringLiteral("flanger"));
1116 if(!ui->enableFrequencyShifterCheck->isChecked())
1117 strlist.append(QStringLiteral("fshifter"));
1118 if(!ui->enableModulatorCheck->isChecked())
1119 strlist.append(QStringLiteral("modulator"));
1120 if(!ui->enableDedicatedCheck->isChecked())
1121 strlist.append(QStringLiteral("dedicated"));
1122 if(!ui->enablePitchShifterCheck->isChecked())
1123 strlist.append(QStringLiteral("pshifter"));
1124 if(!ui->enableVocalMorpherCheck->isChecked())
1125 strlist.append(QStringLiteral("vmorpher"));
1126 settings.setValue(QStringLiteral("excludefx"), strlist.join(QChar{','}));
1127 settings.setValue(QStringLiteral("eax/enable"),
1128 (!ui->enableEaxCheck->isEnabled() || ui->enableEaxCheck->isChecked())
1129 ? QString{/*"true"*/} : QStringLiteral("false"));
1131 settings.setValue(QStringLiteral("pipewire/assume-audio"), getCheckValue(ui->pwireAssumeAudioCheckBox));
1132 settings.setValue(QStringLiteral("pipewire/rt-mix"), getCheckValue(ui->pwireRtMixCheckBox));
1134 settings.setValue(QStringLiteral("wasapi/allow-resampler"), getCheckValue(ui->wasapiResamplerCheckBox));
1136 settings.setValue(QStringLiteral("pulse/spawn-server"), getCheckValue(ui->pulseAutospawnCheckBox));
1137 settings.setValue(QStringLiteral("pulse/allow-moves"), getCheckValue(ui->pulseAllowMovesCheckBox));
1138 settings.setValue(QStringLiteral("pulse/fix-rate"), getCheckValue(ui->pulseFixRateCheckBox));
1139 settings.setValue(QStringLiteral("pulse/adjust-latency"), getCheckValue(ui->pulseAdjLatencyCheckBox));
1141 settings.setValue(QStringLiteral("jack/spawn-server"), getCheckValue(ui->jackAutospawnCheckBox));
1142 settings.setValue(QStringLiteral("jack/connect-ports"), getCheckValue(ui->jackConnectPortsCheckBox));
1143 settings.setValue(QStringLiteral("jack/rt-mix"), getCheckValue(ui->jackRtMixCheckBox));
1144 settings.setValue(QStringLiteral("jack/buffer-size"), ui->jackBufferSizeLine->text());
1146 settings.setValue(QStringLiteral("alsa/device"), ui->alsaDefaultDeviceLine->text());
1147 settings.setValue(QStringLiteral("alsa/capture"), ui->alsaDefaultCaptureLine->text());
1148 settings.setValue(QStringLiteral("alsa/allow-resampler"), getCheckValue(ui->alsaResamplerCheckBox));
1149 settings.setValue(QStringLiteral("alsa/mmap"), getCheckValue(ui->alsaMmapCheckBox));
1151 settings.setValue(QStringLiteral("oss/device"), ui->ossDefaultDeviceLine->text());
1152 settings.setValue(QStringLiteral("oss/capture"), ui->ossDefaultCaptureLine->text());
1154 settings.setValue(QStringLiteral("solaris/device"), ui->solarisDefaultDeviceLine->text());
1156 settings.setValue(QStringLiteral("wave/file"), ui->waveOutputLine->text());
1157 settings.setValue(QStringLiteral("wave/bformat"),
1158 ui->waveBFormatCheckBox->isChecked() ? QStringLiteral("true") : QString{/*"false"*/}
1161 /* Remove empty keys
1162 * FIXME: Should only remove keys whose value matches the globally-specified value.
1164 allkeys = settings.allKeys();
1165 Q_FOREACH(const QString &key, allkeys)
1167 QString str{settings.value(key).toString()};
1168 if(str.isEmpty())
1169 settings.remove(key);
1174 void MainWindow::enableApplyButton()
1176 if(!mNeedsSave)
1177 ui->applyButton->setEnabled(true);
1178 mNeedsSave = true;
1179 ui->closeCancelButton->setText(tr("Cancel"));
1183 void MainWindow::updateResamplerLabel(int num)
1185 ui->resamplerLabel->setText(std::data(resamplerList[num].name));
1186 enableApplyButton();
1190 void MainWindow::updatePeriodSizeEdit(int size)
1192 ui->periodSizeEdit->clear();
1193 if(size >= 64)
1194 ui->periodSizeEdit->insert(QString::number(size));
1195 enableApplyButton();
1198 void MainWindow::updatePeriodSizeSlider()
1200 int pos = ui->periodSizeEdit->text().toInt();
1201 if(pos >= 64)
1203 if(pos > 8192)
1204 pos = 8192;
1205 ui->periodSizeSlider->setSliderPosition(pos);
1207 enableApplyButton();
1210 void MainWindow::updatePeriodCountEdit(int count)
1212 ui->periodCountEdit->clear();
1213 if(count >= 2)
1214 ui->periodCountEdit->insert(QString::number(count));
1215 enableApplyButton();
1218 void MainWindow::updatePeriodCountSlider()
1220 int pos = ui->periodCountEdit->text().toInt();
1221 if(pos < 2)
1222 pos = 0;
1223 else if(pos > 16)
1224 pos = 16;
1225 ui->periodCountSlider->setSliderPosition(pos);
1226 enableApplyButton();
1230 void MainWindow::selectQuadDecoderFile()
1231 { selectDecoderFile(ui->decoderQuadLineEdit, "Select Quadraphonic Decoder");}
1232 void MainWindow::select51DecoderFile()
1233 { selectDecoderFile(ui->decoder51LineEdit, "Select 5.1 Surround Decoder");}
1234 void MainWindow::select61DecoderFile()
1235 { selectDecoderFile(ui->decoder61LineEdit, "Select 6.1 Surround Decoder");}
1236 void MainWindow::select71DecoderFile()
1237 { selectDecoderFile(ui->decoder71LineEdit, "Select 7.1 Surround Decoder");}
1238 void MainWindow::select3D71DecoderFile()
1239 { selectDecoderFile(ui->decoder3D71LineEdit, "Select 3D7.1 Surround Decoder");}
1240 void MainWindow::selectDecoderFile(QLineEdit *line, const char *caption)
1242 QString dir{line->text()};
1243 if(dir.isEmpty() || QDir::isRelativePath(dir))
1245 QStringList paths{getAllDataPaths("/openal/presets")};
1246 while(!paths.isEmpty())
1248 if(QDir{paths.last()}.exists())
1250 dir = paths.last();
1251 break;
1253 paths.removeLast();
1256 QString fname{QFileDialog::getOpenFileName(this, tr(caption),
1257 dir, tr("AmbDec Files (*.ambdec);;All Files (*.*)"))};
1258 if(!fname.isEmpty())
1260 line->setText(fname);
1261 enableApplyButton();
1266 void MainWindow::updateJackBufferSizeEdit(int size)
1268 ui->jackBufferSizeLine->clear();
1269 if(size > 0)
1270 ui->jackBufferSizeLine->insert(QString::number(1<<size));
1271 enableApplyButton();
1274 void MainWindow::updateJackBufferSizeSlider()
1276 int value{ui->jackBufferSizeLine->text().toInt()};
1277 auto pos = static_cast<int>(floor(log2(value) + 0.5));
1278 ui->jackBufferSizeSlider->setSliderPosition(pos);
1279 enableApplyButton();
1283 void MainWindow::updateHrtfModeLabel(int num)
1285 ui->hrtfmodeLabel->setText(std::data(hrtfModeList[static_cast<uint>(num)].name));
1286 enableApplyButton();
1290 void MainWindow::addHrtfFile()
1292 QString path{QFileDialog::getExistingDirectory(this, tr("Select HRTF Path"))};
1293 if(path.isEmpty() == false && !getAllDataPaths(QStringLiteral("/openal/hrtf")).contains(path))
1295 ui->hrtfFileList->addItem(path);
1296 enableApplyButton();
1300 void MainWindow::removeHrtfFile()
1302 QList<gsl::owner<QListWidgetItem*>> selected{ui->hrtfFileList->selectedItems()};
1303 if(!selected.isEmpty())
1305 std::for_each(selected.begin(), selected.end(), std::default_delete<QListWidgetItem>{});
1306 enableApplyButton();
1310 void MainWindow::updateHrtfRemoveButton()
1312 ui->hrtfRemoveButton->setEnabled(!ui->hrtfFileList->selectedItems().empty());
1315 void MainWindow::showEnabledBackendMenu(QPoint pt)
1317 QHash<QAction*,QString> actionMap;
1319 pt = ui->enabledBackendList->mapToGlobal(pt);
1321 QMenu ctxmenu;
1322 QAction *removeAction{ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove")};
1323 if(ui->enabledBackendList->selectedItems().empty())
1324 removeAction->setEnabled(false);
1325 ctxmenu.addSeparator();
1326 for(size_t i{0};i < backendList.size();++i)
1328 QString backend{std::data(backendList[i].full_string)};
1329 QAction *action{ctxmenu.addAction(QString("Add ")+backend)};
1330 actionMap[action] = backend;
1331 if(!ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).empty() ||
1332 !ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).empty())
1333 action->setEnabled(false);
1336 QAction *gotAction{ctxmenu.exec(pt)};
1337 if(gotAction == removeAction)
1339 QList<gsl::owner<QListWidgetItem*>> selected{ui->enabledBackendList->selectedItems()};
1340 std::for_each(selected.begin(), selected.end(), std::default_delete<QListWidgetItem>{});
1341 enableApplyButton();
1343 else if(gotAction != nullptr)
1345 auto iter = actionMap.constFind(gotAction);
1346 if(iter != actionMap.cend())
1347 ui->enabledBackendList->addItem(iter.value());
1348 enableApplyButton();
1352 void MainWindow::showDisabledBackendMenu(QPoint pt)
1354 QHash<QAction*,QString> actionMap;
1356 pt = ui->disabledBackendList->mapToGlobal(pt);
1358 QMenu ctxmenu;
1359 QAction *removeAction{ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove")};
1360 if(ui->disabledBackendList->selectedItems().empty())
1361 removeAction->setEnabled(false);
1362 ctxmenu.addSeparator();
1363 for(size_t i{0};i < backendList.size();++i)
1365 QString backend{std::data(backendList[i].full_string)};
1366 QAction *action{ctxmenu.addAction(QString("Add ")+backend)};
1367 actionMap[action] = backend;
1368 if(!ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).empty() ||
1369 !ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).empty())
1370 action->setEnabled(false);
1373 QAction *gotAction{ctxmenu.exec(pt)};
1374 if(gotAction == removeAction)
1376 QList<gsl::owner<QListWidgetItem*>> selected{ui->disabledBackendList->selectedItems()};
1377 std::for_each(selected.begin(), selected.end(), std::default_delete<QListWidgetItem>{});
1378 enableApplyButton();
1380 else if(gotAction != nullptr)
1382 auto iter = actionMap.constFind(gotAction);
1383 if(iter != actionMap.cend())
1384 ui->disabledBackendList->addItem(iter.value());
1385 enableApplyButton();
1389 void MainWindow::selectOSSPlayback()
1391 QString current{ui->ossDefaultDeviceLine->text()};
1392 if(current.isEmpty()) current = ui->ossDefaultDeviceLine->placeholderText();
1393 QString fname{QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current)};
1394 if(!fname.isEmpty())
1396 ui->ossDefaultDeviceLine->setText(fname);
1397 enableApplyButton();
1401 void MainWindow::selectOSSCapture()
1403 QString current{ui->ossDefaultCaptureLine->text()};
1404 if(current.isEmpty()) current = ui->ossDefaultCaptureLine->placeholderText();
1405 QString fname{QFileDialog::getOpenFileName(this, tr("Select Capture Device"), current)};
1406 if(!fname.isEmpty())
1408 ui->ossDefaultCaptureLine->setText(fname);
1409 enableApplyButton();
1413 void MainWindow::selectSolarisPlayback()
1415 QString current{ui->solarisDefaultDeviceLine->text()};
1416 if(current.isEmpty()) current = ui->solarisDefaultDeviceLine->placeholderText();
1417 QString fname{QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current)};
1418 if(!fname.isEmpty())
1420 ui->solarisDefaultDeviceLine->setText(fname);
1421 enableApplyButton();
1425 void MainWindow::selectWaveOutput()
1427 QString fname{QFileDialog::getSaveFileName(this, tr("Select Wave File Output"),
1428 ui->waveOutputLine->text(), tr("Wave Files (*.wav *.amb);;All Files (*.*)"))};
1429 if(!fname.isEmpty())
1431 ui->waveOutputLine->setText(fname);
1432 enableApplyButton();