Add missing alGetPointerEXT and alGetPointervEXT
[openal-soft.git] / utils / alsoft-config / mainwindow.cpp
blob95f9bd0c4221b90e8fe8575eb2d12361a083fc91
2 #include "config.h"
4 #include "mainwindow.h"
6 #include <array>
7 #include <cmath>
8 #include <iostream>
10 #include <QFileDialog>
11 #include <QMessageBox>
12 #include <QCloseEvent>
13 #include <QSettings>
14 #include <QtGlobal>
15 #include "ui_mainwindow.h"
16 #include "verstr.h"
18 #ifdef _WIN32
19 #include <windows.h>
20 #include <shlobj.h>
21 #endif
23 #include "almalloc.h"
24 #include "alspan.h"
26 namespace {
28 struct BackendNamePair {
29 /* NOLINTBEGIN(*-avoid-c-arrays) */
30 char backend_name[16];
31 char full_string[32];
32 /* NOLINTEND(*-avoid-c-arrays) */
34 constexpr std::array backendList{
35 #ifdef HAVE_PIPEWIRE
36 BackendNamePair{ "pipewire", "PipeWire" },
37 #endif
38 #ifdef HAVE_PULSEAUDIO
39 BackendNamePair{ "pulse", "PulseAudio" },
40 #endif
41 #ifdef HAVE_ALSA
42 BackendNamePair{ "alsa", "ALSA" },
43 #endif
44 #ifdef HAVE_JACK
45 BackendNamePair{ "jack", "JACK" },
46 #endif
47 #ifdef HAVE_COREAUDIO
48 BackendNamePair{ "core", "CoreAudio" },
49 #endif
50 #ifdef HAVE_OSS
51 BackendNamePair{ "oss", "OSS" },
52 #endif
53 #ifdef HAVE_SOLARIS
54 BackendNamePair{ "solaris", "Solaris" },
55 #endif
56 #ifdef HAVE_SNDIO
57 BackendNamePair{ "sndio", "SndIO" },
58 #endif
59 #ifdef HAVE_WASAPI
60 BackendNamePair{ "wasapi", "WASAPI" },
61 #endif
62 #ifdef HAVE_DSOUND
63 BackendNamePair{ "dsound", "DirectSound" },
64 #endif
65 #ifdef HAVE_WINMM
66 BackendNamePair{ "winmm", "Windows Multimedia" },
67 #endif
68 #ifdef HAVE_PORTAUDIO
69 BackendNamePair{ "port", "PortAudio" },
70 #endif
71 #ifdef HAVE_OPENSL
72 BackendNamePair{ "opensl", "OpenSL" },
73 #endif
75 BackendNamePair{ "null", "Null Output" },
76 #ifdef HAVE_WAVE
77 BackendNamePair{ "wave", "Wave Writer" },
78 #endif
81 struct NameValuePair {
82 /* NOLINTBEGIN(*-avoid-c-arrays) */
83 const char name[64];
84 const char value[16];
85 /* NOLINTEND(*-avoid-c-arrays) */
87 constexpr std::array speakerModeList{
88 NameValuePair{ "Autodetect", "" },
89 NameValuePair{ "Mono", "mono" },
90 NameValuePair{ "Stereo", "stereo" },
91 NameValuePair{ "Quadraphonic", "quad" },
92 NameValuePair{ "5.1 Surround", "surround51" },
93 NameValuePair{ "6.1 Surround", "surround61" },
94 NameValuePair{ "7.1 Surround", "surround71" },
95 NameValuePair{ "3D7.1 Surround", "surround3d71" },
97 NameValuePair{ "Ambisonic, 1st Order", "ambi1" },
98 NameValuePair{ "Ambisonic, 2nd Order", "ambi2" },
99 NameValuePair{ "Ambisonic, 3rd Order", "ambi3" },
101 constexpr std::array sampleTypeList{
102 NameValuePair{ "Autodetect", "" },
103 NameValuePair{ "8-bit int", "int8" },
104 NameValuePair{ "8-bit uint", "uint8" },
105 NameValuePair{ "16-bit int", "int16" },
106 NameValuePair{ "16-bit uint", "uint16" },
107 NameValuePair{ "32-bit int", "int32" },
108 NameValuePair{ "32-bit uint", "uint32" },
109 NameValuePair{ "32-bit float", "float32" },
111 constexpr std::array resamplerList{
112 NameValuePair{ "Point", "point" },
113 NameValuePair{ "Linear", "linear" },
114 NameValuePair{ "Cubic Spline", "spline" },
115 NameValuePair{ "4-point Gaussian", "gaussian" },
116 NameValuePair{ "Default (4-point Gaussian)", "" },
117 NameValuePair{ "11th order Sinc (fast)", "fast_bsinc12" },
118 NameValuePair{ "11th order Sinc", "bsinc12" },
119 NameValuePair{ "23rd order Sinc (fast)", "fast_bsinc24" },
120 NameValuePair{ "23rd order Sinc", "bsinc24" },
122 constexpr std::array stereoModeList{
123 NameValuePair{ "Autodetect", "" },
124 NameValuePair{ "Speakers", "speakers" },
125 NameValuePair{ "Headphones", "headphones" },
127 constexpr std::array stereoEncList{
128 NameValuePair{ "Default", "" },
129 NameValuePair{ "Basic", "panpot" },
130 NameValuePair{ "UHJ", "uhj" },
131 NameValuePair{ "Binaural", "hrtf" },
133 constexpr std::array ambiFormatList{
134 NameValuePair{ "Default", "" },
135 NameValuePair{ "AmbiX (ACN, SN3D)", "ambix" },
136 NameValuePair{ "Furse-Malham", "fuma" },
137 NameValuePair{ "ACN, N3D", "acn+n3d" },
138 NameValuePair{ "ACN, FuMa", "acn+fuma" },
140 constexpr std::array hrtfModeList{
141 NameValuePair{ "1st Order Ambisonic", "ambi1" },
142 NameValuePair{ "2nd Order Ambisonic", "ambi2" },
143 NameValuePair{ "3rd Order Ambisonic", "ambi3" },
144 NameValuePair{ "Default (Full)", "" },
145 NameValuePair{ "Full", "full" },
148 QString getDefaultConfigName()
150 #ifdef Q_OS_WIN32
151 const char *fname{"alsoft.ini"};
152 auto get_appdata_path = []() noexcept -> QString
154 QString ret;
155 WCHAR *buffer{};
156 if(const HRESULT hr{SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_DONT_UNEXPAND,
157 nullptr, &buffer)}; SUCCEEDED(hr))
158 ret = QString::fromWCharArray(buffer);
159 CoTaskMemFree(buffer);
160 return ret;
162 QString base = get_appdata_path();
163 #else
164 const char *fname{"alsoft.conf"};
165 QString base = qgetenv("XDG_CONFIG_HOME");
166 if(base.isEmpty())
168 base = qgetenv("HOME");
169 if(base.isEmpty() == false)
170 base += "/.config";
172 #endif
173 if(base.isEmpty() == false)
174 return base +'/'+ fname;
175 return fname;
178 QString getBaseDataPath()
180 #ifdef Q_OS_WIN32
181 auto get_appdata_path = []() noexcept -> QString
183 QString ret;
184 WCHAR *buffer{};
185 if(const HRESULT hr{SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_DONT_UNEXPAND,
186 nullptr, &buffer)}; SUCCEEDED(hr))
187 ret = QString::fromWCharArray(buffer);
188 CoTaskMemFree(buffer);
189 return ret;
191 QString base = get_appdata_path();
192 #else
193 QString base = qgetenv("XDG_DATA_HOME");
194 if(base.isEmpty())
196 base = qgetenv("HOME");
197 if(!base.isEmpty())
198 base += "/.local/share";
200 #endif
201 return base;
204 QStringList getAllDataPaths(const QString &append)
206 QStringList list;
207 list.append(getBaseDataPath());
208 #ifdef Q_OS_WIN32
209 // TODO: Common AppData path
210 #else
211 QString paths = qgetenv("XDG_DATA_DIRS");
212 if(paths.isEmpty())
213 paths = "/usr/local/share/:/usr/share/";
214 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
215 list += paths.split(QChar(':'), Qt::SkipEmptyParts);
216 #else
217 list += paths.split(QChar(':'), QString::SkipEmptyParts);
218 #endif
219 #endif
220 QStringList::iterator iter = list.begin();
221 while(iter != list.end())
223 if(iter->isEmpty())
224 iter = list.erase(iter);
225 else
227 iter->append(append);
228 iter++;
231 return list;
234 QString getValueFromName(const al::span<const NameValuePair> list, const QString &str)
236 for(size_t i{0};i < list.size();++i)
238 if(str == std::data(list[i].name))
239 return std::data(list[i].value);
241 return QString{};
244 QString getNameFromValue(const al::span<const NameValuePair> list, const QString &str)
246 for(size_t i{0};i < list.size();++i)
248 if(str == std::data(list[i].value))
249 return std::data(list[i].name);
251 return QString{};
255 Qt::CheckState getCheckState(const QVariant &var)
257 if(var.isNull())
258 return Qt::PartiallyChecked;
259 if(var.toBool())
260 return Qt::Checked;
261 return Qt::Unchecked;
264 QString getCheckValue(const QCheckBox *checkbox)
266 const Qt::CheckState state{checkbox->checkState()};
267 if(state == Qt::Checked)
268 return QStringLiteral("true");
269 if(state == Qt::Unchecked)
270 return QStringLiteral("false");
271 return QString{};
276 MainWindow::MainWindow(QWidget *parent) : QMainWindow{parent}
277 , ui{std::make_unique<Ui::MainWindow>()}
279 ui->setupUi(this);
281 for(auto &item : speakerModeList)
282 ui->channelConfigCombo->addItem(std::data(item.name));
283 ui->channelConfigCombo->adjustSize();
284 for(auto &item : sampleTypeList)
285 ui->sampleFormatCombo->addItem(std::data(item.name));
286 ui->sampleFormatCombo->adjustSize();
287 for(auto &item : stereoModeList)
288 ui->stereoModeCombo->addItem(std::data(item.name));
289 ui->stereoModeCombo->adjustSize();
290 for(auto &item : stereoEncList)
291 ui->stereoEncodingComboBox->addItem(std::data(item.name));
292 ui->stereoEncodingComboBox->adjustSize();
293 for(auto &item : ambiFormatList)
294 ui->ambiFormatComboBox->addItem(std::data(item.name));
295 ui->ambiFormatComboBox->adjustSize();
297 ui->resamplerSlider->setRange(0, resamplerList.size()-1);
298 ui->hrtfmodeSlider->setRange(0, hrtfModeList.size()-1);
300 #if !defined(HAVE_NEON) && !defined(HAVE_SSE)
301 ui->cpuExtDisabledLabel->move(ui->cpuExtDisabledLabel->x(), ui->cpuExtDisabledLabel->y() - 60);
302 #else
303 ui->cpuExtDisabledLabel->setVisible(false);
304 #endif
306 #ifndef HAVE_NEON
308 #ifndef HAVE_SSE4_1
309 #ifndef HAVE_SSE3
310 #ifndef HAVE_SSE2
311 #ifndef HAVE_SSE
312 ui->enableSSECheckBox->setVisible(false);
313 #endif /* !SSE */
314 ui->enableSSE2CheckBox->setVisible(false);
315 #endif /* !SSE2 */
316 ui->enableSSE3CheckBox->setVisible(false);
317 #endif /* !SSE3 */
318 ui->enableSSE41CheckBox->setVisible(false);
319 #endif /* !SSE4.1 */
320 ui->enableNeonCheckBox->setVisible(false);
322 #else /* !Neon */
324 #ifndef HAVE_SSE4_1
325 #ifndef HAVE_SSE3
326 #ifndef HAVE_SSE2
327 #ifndef HAVE_SSE
328 ui->enableNeonCheckBox->move(ui->enableNeonCheckBox->x(), ui->enableNeonCheckBox->y() - 30);
329 ui->enableSSECheckBox->setVisible(false);
330 #endif /* !SSE */
331 ui->enableSSE2CheckBox->setVisible(false);
332 #endif /* !SSE2 */
333 ui->enableSSE3CheckBox->setVisible(false);
334 #endif /* !SSE3 */
335 ui->enableSSE41CheckBox->setVisible(false);
336 #endif /* !SSE4.1 */
338 #endif
340 #ifndef ALSOFT_EAX
341 ui->enableEaxCheck->setChecked(Qt::Unchecked);
342 ui->enableEaxCheck->setEnabled(false);
343 ui->enableEaxCheck->setVisible(false);
344 #endif
346 mPeriodSizeValidator = std::make_unique<QIntValidator>(64, 8192, this);
347 ui->periodSizeEdit->setValidator(mPeriodSizeValidator.get());
348 mPeriodCountValidator = std::make_unique<QIntValidator>(2, 16, this);
349 ui->periodCountEdit->setValidator(mPeriodCountValidator.get());
351 mSourceCountValidator = std::make_unique<QIntValidator>(0, 4096, this);
352 ui->srcCountLineEdit->setValidator(mSourceCountValidator.get());
353 mEffectSlotValidator = std::make_unique<QIntValidator>(0, 64, this);
354 ui->effectSlotLineEdit->setValidator(mEffectSlotValidator.get());
355 mSourceSendValidator = std::make_unique<QIntValidator>(0, 16, this);
356 ui->srcSendLineEdit->setValidator(mSourceSendValidator.get());
357 mSampleRateValidator = std::make_unique<QIntValidator>(8000, 192000, this);
358 ui->sampleRateCombo->lineEdit()->setValidator(mSampleRateValidator.get());
360 mJackBufferValidator = std::make_unique<QIntValidator>(0, 8192, this);
361 ui->jackBufferSizeLine->setValidator(mJackBufferValidator.get());
363 connect(ui->actionLoad, &QAction::triggered, this, &MainWindow::loadConfigFromFile);
364 connect(ui->actionSave_As, &QAction::triggered, this, &MainWindow::saveConfigAsFile);
366 connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::showAboutPage);
368 connect(ui->closeCancelButton, &QPushButton::clicked, this, &MainWindow::cancelCloseAction);
369 connect(ui->applyButton, &QPushButton::clicked, this, &MainWindow::saveCurrentConfig);
371 auto qcb_cicint = static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged);
372 connect(ui->channelConfigCombo, qcb_cicint, this, &MainWindow::enableApplyButton);
373 connect(ui->sampleFormatCombo, qcb_cicint, this, &MainWindow::enableApplyButton);
374 connect(ui->stereoModeCombo, qcb_cicint, this, &MainWindow::enableApplyButton);
375 connect(ui->sampleRateCombo, qcb_cicint, this, &MainWindow::enableApplyButton);
376 connect(ui->sampleRateCombo, &QComboBox::editTextChanged, this, &MainWindow::enableApplyButton);
378 connect(ui->resamplerSlider, &QSlider::valueChanged, this, &MainWindow::updateResamplerLabel);
380 connect(ui->periodSizeSlider, &QSlider::valueChanged, this, &MainWindow::updatePeriodSizeEdit);
381 connect(ui->periodSizeEdit, &QLineEdit::editingFinished, this, &MainWindow::updatePeriodSizeSlider);
382 connect(ui->periodCountSlider, &QSlider::valueChanged, this, &MainWindow::updatePeriodCountEdit);
383 connect(ui->periodCountEdit, &QLineEdit::editingFinished, this, &MainWindow::updatePeriodCountSlider);
385 connect(ui->stereoEncodingComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
386 connect(ui->ambiFormatComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
387 connect(ui->outputLimiterCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
388 connect(ui->outputDitherCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
390 connect(ui->decoderHQModeCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
391 connect(ui->decoderDistCompCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
392 connect(ui->decoderNFEffectsCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
393 auto qdsb_vcd = static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged);
394 connect(ui->decoderSpeakerDistSpinBox, qdsb_vcd, this, &MainWindow::enableApplyButton);
395 connect(ui->decoderQuadLineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
396 connect(ui->decoderQuadButton, &QPushButton::clicked, this, &MainWindow::selectQuadDecoderFile);
397 connect(ui->decoder51LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
398 connect(ui->decoder51Button, &QPushButton::clicked, this, &MainWindow::select51DecoderFile);
399 connect(ui->decoder61LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
400 connect(ui->decoder61Button, &QPushButton::clicked, this, &MainWindow::select61DecoderFile);
401 connect(ui->decoder71LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
402 connect(ui->decoder71Button, &QPushButton::clicked, this, &MainWindow::select71DecoderFile);
403 connect(ui->decoder3D71LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
404 connect(ui->decoder3D71Button, &QPushButton::clicked, this, &MainWindow::select3D71DecoderFile);
406 connect(ui->preferredHrtfComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
407 connect(ui->hrtfmodeSlider, &QSlider::valueChanged, this, &MainWindow::updateHrtfModeLabel);
409 connect(ui->hrtfAddButton, &QPushButton::clicked, this, &MainWindow::addHrtfFile);
410 connect(ui->hrtfRemoveButton, &QPushButton::clicked, this, &MainWindow::removeHrtfFile);
411 connect(ui->hrtfFileList, &QListWidget::itemSelectionChanged, this, &MainWindow::updateHrtfRemoveButton);
412 connect(ui->defaultHrtfPathsCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
414 connect(ui->srcCountLineEdit, &QLineEdit::editingFinished, this, &MainWindow::enableApplyButton);
415 connect(ui->srcSendLineEdit, &QLineEdit::editingFinished, this, &MainWindow::enableApplyButton);
416 connect(ui->effectSlotLineEdit, &QLineEdit::editingFinished, this, &MainWindow::enableApplyButton);
418 connect(ui->enableSSECheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
419 connect(ui->enableSSE2CheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
420 connect(ui->enableSSE3CheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
421 connect(ui->enableSSE41CheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
422 connect(ui->enableNeonCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
424 ui->enabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
425 connect(ui->enabledBackendList, &QListWidget::customContextMenuRequested, this, &MainWindow::showEnabledBackendMenu);
427 ui->disabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
428 connect(ui->disabledBackendList, &QListWidget::customContextMenuRequested, this, &MainWindow::showDisabledBackendMenu);
429 connect(ui->backendCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
431 connect(ui->defaultReverbComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
432 connect(ui->enableEaxReverbCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
433 connect(ui->enableStdReverbCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
434 connect(ui->enableAutowahCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
435 connect(ui->enableChorusCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
436 connect(ui->enableCompressorCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
437 connect(ui->enableDistortionCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
438 connect(ui->enableEchoCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
439 connect(ui->enableEqualizerCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
440 connect(ui->enableFlangerCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
441 connect(ui->enableFrequencyShifterCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
442 connect(ui->enableModulatorCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
443 connect(ui->enableDedicatedCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
444 connect(ui->enablePitchShifterCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
445 connect(ui->enableVocalMorpherCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
446 connect(ui->enableEaxCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
448 connect(ui->pulseAutospawnCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
449 connect(ui->pulseAllowMovesCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
450 connect(ui->pulseFixRateCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
451 connect(ui->pulseAdjLatencyCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
453 connect(ui->pwireAssumeAudioCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
454 connect(ui->pwireRtMixCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
456 connect(ui->wasapiResamplerCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
458 connect(ui->jackAutospawnCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
459 connect(ui->jackConnectPortsCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
460 connect(ui->jackRtMixCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
461 connect(ui->jackBufferSizeSlider, &QSlider::valueChanged, this, &MainWindow::updateJackBufferSizeEdit);
462 connect(ui->jackBufferSizeLine, &QLineEdit::editingFinished, this, &MainWindow::updateJackBufferSizeSlider);
464 connect(ui->alsaDefaultDeviceLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
465 connect(ui->alsaDefaultCaptureLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
466 connect(ui->alsaResamplerCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
467 connect(ui->alsaMmapCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
469 connect(ui->ossDefaultDeviceLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
470 connect(ui->ossPlaybackPushButton, &QPushButton::clicked, this, &MainWindow::selectOSSPlayback);
471 connect(ui->ossDefaultCaptureLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
472 connect(ui->ossCapturePushButton, &QPushButton::clicked, this, &MainWindow::selectOSSCapture);
474 connect(ui->solarisDefaultDeviceLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
475 connect(ui->solarisPlaybackPushButton, &QPushButton::clicked, this, &MainWindow::selectSolarisPlayback);
477 connect(ui->waveOutputLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
478 connect(ui->waveOutputButton, &QPushButton::clicked, this, &MainWindow::selectWaveOutput);
479 connect(ui->waveBFormatCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
481 ui->backendListWidget->setCurrentRow(0);
482 ui->tabWidget->setCurrentIndex(0);
484 for(int i = 1;i < ui->backendListWidget->count();i++)
485 ui->backendListWidget->setRowHidden(i, true);
486 for(size_t i{0};i < backendList.size();++i)
488 QList<QListWidgetItem*> items = ui->backendListWidget->findItems(
489 std::data(backendList[i].full_string), Qt::MatchFixedString);
490 Q_FOREACH(QListWidgetItem *item, items)
491 item->setHidden(false);
494 loadConfig(getDefaultConfigName());
497 MainWindow::~MainWindow() = default;
499 void MainWindow::closeEvent(QCloseEvent *event)
501 if(!mNeedsSave)
502 event->accept();
503 else
505 QMessageBox::StandardButton btn = QMessageBox::warning(this,
506 tr("Apply changes?"), tr("Save changes before quitting?"),
507 QMessageBox::Save | QMessageBox::No | QMessageBox::Cancel);
508 if(btn == QMessageBox::Save)
509 saveCurrentConfig();
510 if(btn == QMessageBox::Cancel)
511 event->ignore();
512 else
513 event->accept();
517 void MainWindow::cancelCloseAction()
519 mNeedsSave = false;
520 close();
524 void MainWindow::showAboutPage()
526 QMessageBox::information(this, tr("About"),
527 tr("OpenAL Soft Configuration Utility.\nBuilt for OpenAL Soft library version ") +
528 GetVersionString());
532 QStringList MainWindow::collectHrtfs()
534 QStringList ret;
535 QStringList processed;
537 for(int i = 0;i < ui->hrtfFileList->count();i++)
539 QDir dir(ui->hrtfFileList->item(i)->text());
540 QStringList fnames = dir.entryList(QDir::Files | QDir::Readable, QDir::Name);
541 Q_FOREACH(const QString &fname, fnames)
543 if(!fname.endsWith(QStringLiteral(".mhr"), Qt::CaseInsensitive))
544 continue;
545 QString fullname{dir.absoluteFilePath(fname)};
546 if(processed.contains(fullname))
547 continue;
548 processed.push_back(fullname);
550 QString name{fname.left(fname.length()-4)};
551 if(!ret.contains(name))
552 ret.push_back(name);
553 else
555 size_t i{2};
556 do {
557 QString s = name+" #"+QString::number(i);
558 if(!ret.contains(s))
560 ret.push_back(s);
561 break;
563 ++i;
564 } while(true);
569 if(ui->defaultHrtfPathsCheckBox->isChecked())
571 QStringList paths = getAllDataPaths(QStringLiteral("/openal/hrtf"));
572 Q_FOREACH(const QString &name, paths)
574 QDir dir{name};
575 QStringList fnames{dir.entryList(QDir::Files | QDir::Readable, QDir::Name)};
576 Q_FOREACH(const QString &fname, fnames)
578 if(!fname.endsWith(QStringLiteral(".mhr"), Qt::CaseInsensitive))
579 continue;
580 QString fullname{dir.absoluteFilePath(fname)};
581 if(processed.contains(fullname))
582 continue;
583 processed.push_back(fullname);
585 QString name{fname.left(fname.length()-4)};
586 if(!ret.contains(name))
587 ret.push_back(name);
588 else
590 size_t i{2};
591 do {
592 QString s{name+" #"+QString::number(i)};
593 if(!ret.contains(s))
595 ret.push_back(s);
596 break;
598 ++i;
599 } while(true);
604 #ifdef ALSOFT_EMBED_HRTF_DATA
605 ret.push_back(QStringLiteral("Built-In HRTF"));
606 #endif
608 return ret;
612 void MainWindow::loadConfigFromFile()
614 QString fname = QFileDialog::getOpenFileName(this, tr("Select Files"));
615 if(fname.isEmpty() == false)
616 loadConfig(fname);
619 void MainWindow::loadConfig(const QString &fname)
621 QSettings settings{fname, QSettings::IniFormat};
623 QString sampletype{settings.value(QStringLiteral("sample-type")).toString()};
624 ui->sampleFormatCombo->setCurrentIndex(0);
625 if(sampletype.isEmpty() == false)
627 QString str{getNameFromValue(sampleTypeList, sampletype)};
628 if(!str.isEmpty())
630 const int j{ui->sampleFormatCombo->findText(str)};
631 if(j > 0) ui->sampleFormatCombo->setCurrentIndex(j);
635 QString channelconfig{settings.value(QStringLiteral("channels")).toString()};
636 ui->channelConfigCombo->setCurrentIndex(0);
637 if(channelconfig.isEmpty() == false)
639 if(channelconfig == QStringLiteral("surround51rear"))
640 channelconfig = QStringLiteral("surround51");
641 QString str{getNameFromValue(speakerModeList, channelconfig)};
642 if(!str.isEmpty())
644 const int j{ui->channelConfigCombo->findText(str)};
645 if(j > 0) ui->channelConfigCombo->setCurrentIndex(j);
649 QString srate{settings.value(QStringLiteral("frequency")).toString()};
650 if(srate.isEmpty())
651 ui->sampleRateCombo->setCurrentIndex(0);
652 else
654 ui->sampleRateCombo->lineEdit()->clear();
655 ui->sampleRateCombo->lineEdit()->insert(srate);
658 ui->srcCountLineEdit->clear();
659 ui->srcCountLineEdit->insert(settings.value(QStringLiteral("sources")).toString());
660 ui->effectSlotLineEdit->clear();
661 ui->effectSlotLineEdit->insert(settings.value(QStringLiteral("slots")).toString());
662 ui->srcSendLineEdit->clear();
663 ui->srcSendLineEdit->insert(settings.value(QStringLiteral("sends")).toString());
665 QString resampler = settings.value(QStringLiteral("resampler")).toString().trimmed();
666 ui->resamplerSlider->setValue(2);
667 ui->resamplerLabel->setText(std::data(resamplerList[2].name));
668 /* "Cubic" is an alias for the 4-point spline resampler. The "sinc4" and
669 * "sinc8" resamplers are unsupported, use "gaussian" as a fallback.
671 if(resampler == QLatin1String{"cubic"})
672 resampler = QStringLiteral("spline");
673 else if(resampler == QLatin1String{"sinc4"} || resampler == QLatin1String{"sinc8"})
674 resampler = QStringLiteral("gaussian");
675 /* The "bsinc" resampler name is an alias for "bsinc12". */
676 else if(resampler == QLatin1String{"bsinc"})
677 resampler = QStringLiteral("bsinc12");
678 for(int i = 0;resamplerList[i].name[0];i++)
680 if(resampler == std::data(resamplerList[i].value))
682 ui->resamplerSlider->setValue(i);
683 ui->resamplerLabel->setText(std::data(resamplerList[i].name));
684 break;
688 QString stereomode{settings.value(QStringLiteral("stereo-mode")).toString().trimmed()};
689 ui->stereoModeCombo->setCurrentIndex(0);
690 if(stereomode.isEmpty() == false)
692 QString str{getNameFromValue(stereoModeList, stereomode)};
693 if(!str.isEmpty())
695 const int j{ui->stereoModeCombo->findText(str)};
696 if(j > 0) ui->stereoModeCombo->setCurrentIndex(j);
700 int periodsize{settings.value("period_size").toInt()};
701 ui->periodSizeEdit->clear();
702 if(periodsize >= 64)
704 ui->periodSizeEdit->insert(QString::number(periodsize));
705 updatePeriodSizeSlider();
708 int periodcount{settings.value("periods").toInt()};
709 ui->periodCountEdit->clear();
710 if(periodcount >= 2)
712 ui->periodCountEdit->insert(QString::number(periodcount));
713 updatePeriodCountSlider();
716 ui->outputLimiterCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("output-limiter"))));
717 ui->outputDitherCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("dither"))));
719 QString stereopan{settings.value(QStringLiteral("stereo-encoding")).toString()};
720 ui->stereoEncodingComboBox->setCurrentIndex(0);
721 if(stereopan.isEmpty() == false)
723 QString str{getNameFromValue(stereoEncList, stereopan)};
724 if(!str.isEmpty())
726 const int j{ui->stereoEncodingComboBox->findText(str)};
727 if(j > 0) ui->stereoEncodingComboBox->setCurrentIndex(j);
731 QString ambiformat{settings.value(QStringLiteral("ambi-format")).toString()};
732 ui->ambiFormatComboBox->setCurrentIndex(0);
733 if(ambiformat.isEmpty() == false)
735 QString str{getNameFromValue(ambiFormatList, ambiformat)};
736 if(!str.isEmpty())
738 const int j{ui->ambiFormatComboBox->findText(str)};
739 if(j > 0) ui->ambiFormatComboBox->setCurrentIndex(j);
743 ui->decoderHQModeCheckBox->setChecked(getCheckState(settings.value(QStringLiteral("decoder/hq-mode"))));
744 ui->decoderDistCompCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("decoder/distance-comp"))));
745 ui->decoderNFEffectsCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("decoder/nfc"))));
746 double speakerdist{settings.value(QStringLiteral("decoder/speaker-dist"), 1.0).toDouble()};
747 ui->decoderSpeakerDistSpinBox->setValue(speakerdist);
749 ui->decoderQuadLineEdit->setText(settings.value(QStringLiteral("decoder/quad")).toString());
750 ui->decoder51LineEdit->setText(settings.value(QStringLiteral("decoder/surround51")).toString());
751 ui->decoder61LineEdit->setText(settings.value(QStringLiteral("decoder/surround61")).toString());
752 ui->decoder71LineEdit->setText(settings.value(QStringLiteral("decoder/surround71")).toString());
753 ui->decoder3D71LineEdit->setText(settings.value(QStringLiteral("decoder/surround3d71")).toString());
755 QStringList disabledCpuExts{settings.value(QStringLiteral("disable-cpu-exts")).toStringList()};
756 if(disabledCpuExts.size() == 1)
757 disabledCpuExts = disabledCpuExts[0].split(QChar(','));
758 for(QString &name : disabledCpuExts)
759 name = name.trimmed();
760 ui->enableSSECheckBox->setChecked(!disabledCpuExts.contains(QStringLiteral("sse"), Qt::CaseInsensitive));
761 ui->enableSSE2CheckBox->setChecked(!disabledCpuExts.contains(QStringLiteral("sse2"), Qt::CaseInsensitive));
762 ui->enableSSE3CheckBox->setChecked(!disabledCpuExts.contains(QStringLiteral("sse3"), Qt::CaseInsensitive));
763 ui->enableSSE41CheckBox->setChecked(!disabledCpuExts.contains(QStringLiteral("sse4.1"), Qt::CaseInsensitive));
764 ui->enableNeonCheckBox->setChecked(!disabledCpuExts.contains(QStringLiteral("neon"), Qt::CaseInsensitive));
766 QString hrtfmode{settings.value(QStringLiteral("hrtf-mode")).toString().trimmed()};
767 ui->hrtfmodeSlider->setValue(2);
768 ui->hrtfmodeLabel->setText(std::data(hrtfModeList[3].name));
769 /* The "basic" mode name is no longer supported. Use "ambi2" instead. */
770 if(hrtfmode == QLatin1String{"basic"})
771 hrtfmode = QStringLiteral("ambi2");
772 for(size_t i{0};i < hrtfModeList.size();++i)
774 if(hrtfmode == std::data(hrtfModeList[i].value))
776 ui->hrtfmodeSlider->setValue(static_cast<int>(i));
777 ui->hrtfmodeLabel->setText(std::data(hrtfModeList[i].name));
778 break;
782 QStringList hrtf_paths{settings.value(QStringLiteral("hrtf-paths")).toStringList()};
783 if(hrtf_paths.size() == 1)
784 hrtf_paths = hrtf_paths[0].split(QChar(','));
785 for(QString &name : hrtf_paths)
786 name = name.trimmed();
787 if(!hrtf_paths.empty() && !hrtf_paths.back().isEmpty())
788 ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Unchecked);
789 else
791 hrtf_paths.removeAll(QString());
792 ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Checked);
794 hrtf_paths.removeDuplicates();
795 ui->hrtfFileList->clear();
796 ui->hrtfFileList->addItems(hrtf_paths);
797 updateHrtfRemoveButton();
799 ui->preferredHrtfComboBox->clear();
800 ui->preferredHrtfComboBox->addItem(QStringLiteral("- Any -"));
801 if(ui->defaultHrtfPathsCheckBox->isChecked())
803 QStringList hrtfs{collectHrtfs()};
804 Q_FOREACH(const QString &name, hrtfs)
805 ui->preferredHrtfComboBox->addItem(name);
808 QString defaulthrtf{settings.value(QStringLiteral("default-hrtf")).toString()};
809 ui->preferredHrtfComboBox->setCurrentIndex(0);
810 if(defaulthrtf.isEmpty() == false)
812 int i{ui->preferredHrtfComboBox->findText(defaulthrtf)};
813 if(i > 0)
814 ui->preferredHrtfComboBox->setCurrentIndex(i);
815 else
817 i = ui->preferredHrtfComboBox->count();
818 ui->preferredHrtfComboBox->addItem(defaulthrtf);
819 ui->preferredHrtfComboBox->setCurrentIndex(i);
822 ui->preferredHrtfComboBox->adjustSize();
824 ui->enabledBackendList->clear();
825 ui->disabledBackendList->clear();
826 QStringList drivers{settings.value(QStringLiteral("drivers")).toStringList()};
827 if(drivers.empty())
828 ui->backendCheckBox->setChecked(true);
829 else
831 if(drivers.size() == 1)
832 drivers = drivers[0].split(QChar(','));
833 for(QString &name : drivers)
835 name = name.trimmed();
836 /* Convert "mmdevapi" references to "wasapi" for backwards
837 * compatibility.
839 if(name == QLatin1String{"-mmdevapi"})
840 name = QStringLiteral("-wasapi");
841 else if(name == QLatin1String{"mmdevapi"})
842 name = QStringLiteral("wasapi");
845 bool lastWasEmpty{false};
846 Q_FOREACH(const QString &backend, drivers)
848 lastWasEmpty = backend.isEmpty();
849 if(lastWasEmpty) continue;
851 if(!backend.startsWith(QChar('-')))
853 for(size_t j{0};j < backendList.size();++j)
855 if(backend == std::data(backendList[j].backend_name))
857 ui->enabledBackendList->addItem(std::data(backendList[j].full_string));
858 break;
862 else if(backend.size() > 1)
864 QStringRef backendref{backend.rightRef(backend.size()-1)};
865 for(size_t j{0};j < backendList.size();++j)
867 if(backendref == std::data(backendList[j].backend_name))
869 ui->disabledBackendList->addItem(std::data(backendList[j].full_string));
870 break;
875 ui->backendCheckBox->setChecked(lastWasEmpty);
878 QString defaultreverb{settings.value(QStringLiteral("default-reverb")).toString().toLower()};
879 ui->defaultReverbComboBox->setCurrentIndex(0);
880 if(defaultreverb.isEmpty() == false)
882 for(int i = 0;i < ui->defaultReverbComboBox->count();i++)
884 if(defaultreverb.compare(ui->defaultReverbComboBox->itemText(i).toLower()) == 0)
886 ui->defaultReverbComboBox->setCurrentIndex(i);
887 break;
892 QStringList excludefx{settings.value(QStringLiteral("excludefx")).toStringList()};
893 if(excludefx.size() == 1)
894 excludefx = excludefx[0].split(QChar(','));
895 for(QString &name : excludefx)
896 name = name.trimmed();
897 ui->enableEaxReverbCheck->setChecked(!excludefx.contains(QStringLiteral("eaxreverb"), Qt::CaseInsensitive));
898 ui->enableStdReverbCheck->setChecked(!excludefx.contains(QStringLiteral("reverb"), Qt::CaseInsensitive));
899 ui->enableAutowahCheck->setChecked(!excludefx.contains(QStringLiteral("autowah"), Qt::CaseInsensitive));
900 ui->enableChorusCheck->setChecked(!excludefx.contains(QStringLiteral("chorus"), Qt::CaseInsensitive));
901 ui->enableCompressorCheck->setChecked(!excludefx.contains(QStringLiteral("compressor"), Qt::CaseInsensitive));
902 ui->enableDistortionCheck->setChecked(!excludefx.contains(QStringLiteral("distortion"), Qt::CaseInsensitive));
903 ui->enableEchoCheck->setChecked(!excludefx.contains(QStringLiteral("echo"), Qt::CaseInsensitive));
904 ui->enableEqualizerCheck->setChecked(!excludefx.contains(QStringLiteral("equalizer"), Qt::CaseInsensitive));
905 ui->enableFlangerCheck->setChecked(!excludefx.contains(QStringLiteral("flanger"), Qt::CaseInsensitive));
906 ui->enableFrequencyShifterCheck->setChecked(!excludefx.contains(QStringLiteral("fshifter"), Qt::CaseInsensitive));
907 ui->enableModulatorCheck->setChecked(!excludefx.contains(QStringLiteral("modulator"), Qt::CaseInsensitive));
908 ui->enableDedicatedCheck->setChecked(!excludefx.contains(QStringLiteral("dedicated"), Qt::CaseInsensitive));
909 ui->enablePitchShifterCheck->setChecked(!excludefx.contains(QStringLiteral("pshifter"), Qt::CaseInsensitive));
910 ui->enableVocalMorpherCheck->setChecked(!excludefx.contains(QStringLiteral("vmorpher"), Qt::CaseInsensitive));
911 if(ui->enableEaxCheck->isEnabled())
912 ui->enableEaxCheck->setChecked(getCheckState(settings.value(QStringLiteral("eax/enable"))) != Qt::Unchecked);
914 ui->pulseAutospawnCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("pulse/spawn-server"))));
915 ui->pulseAllowMovesCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("pulse/allow-moves"))));
916 ui->pulseFixRateCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("pulse/fix-rate"))));
917 ui->pulseAdjLatencyCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("pulse/adjust-latency"))));
919 ui->pwireAssumeAudioCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("pipewire/assume-audio"))));
920 ui->pwireRtMixCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("pipewire/rt-mix"))));
922 ui->wasapiResamplerCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("wasapi/allow-resampler"))));
924 ui->jackAutospawnCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("jack/spawn-server"))));
925 ui->jackConnectPortsCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("jack/connect-ports"))));
926 ui->jackRtMixCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("jack/rt-mix"))));
927 ui->jackBufferSizeLine->setText(settings.value(QStringLiteral("jack/buffer-size"), QString()).toString());
928 updateJackBufferSizeSlider();
930 ui->alsaDefaultDeviceLine->setText(settings.value(QStringLiteral("alsa/device"), QString()).toString());
931 ui->alsaDefaultCaptureLine->setText(settings.value(QStringLiteral("alsa/capture"), QString()).toString());
932 ui->alsaResamplerCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("alsa/allow-resampler"))));
933 ui->alsaMmapCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("alsa/mmap"))));
935 ui->ossDefaultDeviceLine->setText(settings.value(QStringLiteral("oss/device"), QString()).toString());
936 ui->ossDefaultCaptureLine->setText(settings.value(QStringLiteral("oss/capture"), QString()).toString());
938 ui->solarisDefaultDeviceLine->setText(settings.value(QStringLiteral("solaris/device"), QString()).toString());
940 ui->waveOutputLine->setText(settings.value(QStringLiteral("wave/file"), QString()).toString());
941 ui->waveBFormatCheckBox->setChecked(settings.value(QStringLiteral("wave/bformat"), false).toBool());
943 ui->applyButton->setEnabled(false);
944 ui->closeCancelButton->setText(tr("Close"));
945 mNeedsSave = false;
948 void MainWindow::saveCurrentConfig()
950 saveConfig(getDefaultConfigName());
951 ui->applyButton->setEnabled(false);
952 ui->closeCancelButton->setText(tr("Close"));
953 mNeedsSave = false;
954 QMessageBox::information(this, tr("Information"),
955 tr("Applications using OpenAL need to be restarted for changes to take effect."));
958 void MainWindow::saveConfigAsFile()
960 QString fname{QFileDialog::getOpenFileName(this, tr("Select Files"))};
961 if(fname.isEmpty() == false)
963 saveConfig(fname);
964 ui->applyButton->setEnabled(false);
965 mNeedsSave = false;
969 void MainWindow::saveConfig(const QString &fname) const
971 QSettings settings{fname, QSettings::IniFormat};
973 /* HACK: Compound any stringlist values into a comma-separated string. */
974 QStringList allkeys{settings.allKeys()};
975 Q_FOREACH(const QString &key, allkeys)
977 QStringList vals{settings.value(key).toStringList()};
978 if(vals.size() > 1)
979 settings.setValue(key, vals.join(QChar(',')));
982 settings.setValue(QStringLiteral("sample-type"), getValueFromName(sampleTypeList, ui->sampleFormatCombo->currentText()));
983 settings.setValue(QStringLiteral("channels"), getValueFromName(speakerModeList, ui->channelConfigCombo->currentText()));
985 uint rate{ui->sampleRateCombo->currentText().toUInt()};
986 if(rate <= 0)
987 settings.setValue(QStringLiteral("frequency"), QString{});
988 else
989 settings.setValue(QStringLiteral("frequency"), rate);
991 settings.setValue(QStringLiteral("period_size"), ui->periodSizeEdit->text());
992 settings.setValue(QStringLiteral("periods"), ui->periodCountEdit->text());
994 settings.setValue(QStringLiteral("sources"), ui->srcCountLineEdit->text());
995 settings.setValue(QStringLiteral("slots"), ui->effectSlotLineEdit->text());
997 settings.setValue(QStringLiteral("resampler"), std::data(resamplerList[ui->resamplerSlider->value()].value));
999 settings.setValue(QStringLiteral("stereo-mode"), getValueFromName(stereoModeList, ui->stereoModeCombo->currentText()));
1000 settings.setValue(QStringLiteral("stereo-encoding"), getValueFromName(stereoEncList, ui->stereoEncodingComboBox->currentText()));
1001 settings.setValue(QStringLiteral("ambi-format"), getValueFromName(ambiFormatList, ui->ambiFormatComboBox->currentText()));
1003 settings.setValue(QStringLiteral("output-limiter"), getCheckValue(ui->outputLimiterCheckBox));
1004 settings.setValue(QStringLiteral("dither"), getCheckValue(ui->outputDitherCheckBox));
1006 settings.setValue(QStringLiteral("decoder/hq-mode"), getCheckValue(ui->decoderHQModeCheckBox));
1007 settings.setValue(QStringLiteral("decoder/distance-comp"), getCheckValue(ui->decoderDistCompCheckBox));
1008 settings.setValue(QStringLiteral("decoder/nfc"), getCheckValue(ui->decoderNFEffectsCheckBox));
1009 double speakerdist{ui->decoderSpeakerDistSpinBox->value()};
1010 settings.setValue(QStringLiteral("decoder/speaker-dist"),
1011 (speakerdist != 1.0) ? QString::number(speakerdist) : QString{}
1014 settings.setValue(QStringLiteral("decoder/quad"), ui->decoderQuadLineEdit->text());
1015 settings.setValue(QStringLiteral("decoder/surround51"), ui->decoder51LineEdit->text());
1016 settings.setValue(QStringLiteral("decoder/surround61"), ui->decoder61LineEdit->text());
1017 settings.setValue(QStringLiteral("decoder/surround71"), ui->decoder71LineEdit->text());
1018 settings.setValue(QStringLiteral("decoder/surround3d71"), ui->decoder3D71LineEdit->text());
1020 QStringList strlist;
1021 if(!ui->enableSSECheckBox->isChecked())
1022 strlist.append(QStringLiteral("sse"));
1023 if(!ui->enableSSE2CheckBox->isChecked())
1024 strlist.append(QStringLiteral("sse2"));
1025 if(!ui->enableSSE3CheckBox->isChecked())
1026 strlist.append(QStringLiteral("sse3"));
1027 if(!ui->enableSSE41CheckBox->isChecked())
1028 strlist.append(QStringLiteral("sse4.1"));
1029 if(!ui->enableNeonCheckBox->isChecked())
1030 strlist.append(QStringLiteral("neon"));
1031 settings.setValue(QStringLiteral("disable-cpu-exts"), strlist.join(QChar(',')));
1033 settings.setValue(QStringLiteral("hrtf-mode"), std::data(hrtfModeList[ui->hrtfmodeSlider->value()].value));
1035 if(ui->preferredHrtfComboBox->currentIndex() == 0)
1036 settings.setValue(QStringLiteral("default-hrtf"), QString{});
1037 else
1039 QString str{ui->preferredHrtfComboBox->currentText()};
1040 settings.setValue(QStringLiteral("default-hrtf"), str);
1043 strlist.clear();
1044 strlist.reserve(ui->hrtfFileList->count());
1045 for(int i = 0;i < ui->hrtfFileList->count();i++)
1046 strlist.append(ui->hrtfFileList->item(i)->text());
1047 if(!strlist.empty() && ui->defaultHrtfPathsCheckBox->isChecked())
1048 strlist.append(QString{});
1049 settings.setValue(QStringLiteral("hrtf-paths"), strlist.join(QChar{','}));
1051 strlist.clear();
1052 for(int i = 0;i < ui->enabledBackendList->count();i++)
1054 QString label{ui->enabledBackendList->item(i)->text()};
1055 for(size_t j{0};j < backendList.size();++j)
1057 if(label == std::data(backendList[j].full_string))
1059 strlist.append(std::data(backendList[j].backend_name));
1060 break;
1064 for(int i = 0;i < ui->disabledBackendList->count();i++)
1066 QString label{ui->disabledBackendList->item(i)->text()};
1067 for(size_t j{0};j < backendList.size();++j)
1069 if(label == std::data(backendList[j].full_string))
1071 strlist.append(QChar{'-'}+QString{std::data(backendList[j].backend_name)});
1072 break;
1076 if(strlist.empty() && !ui->backendCheckBox->isChecked())
1077 strlist.append(QStringLiteral("-all"));
1078 else if(ui->backendCheckBox->isChecked())
1079 strlist.append(QString{});
1080 settings.setValue(QStringLiteral("drivers"), strlist.join(QChar(',')));
1082 // TODO: Remove check when we can properly match global values.
1083 if(ui->defaultReverbComboBox->currentIndex() == 0)
1084 settings.setValue(QStringLiteral("default-reverb"), QString{});
1085 else
1087 QString str{ui->defaultReverbComboBox->currentText().toLower()};
1088 settings.setValue(QStringLiteral("default-reverb"), str);
1091 strlist.clear();
1092 if(!ui->enableEaxReverbCheck->isChecked())
1093 strlist.append(QStringLiteral("eaxreverb"));
1094 if(!ui->enableStdReverbCheck->isChecked())
1095 strlist.append(QStringLiteral("reverb"));
1096 if(!ui->enableAutowahCheck->isChecked())
1097 strlist.append(QStringLiteral("autowah"));
1098 if(!ui->enableChorusCheck->isChecked())
1099 strlist.append(QStringLiteral("chorus"));
1100 if(!ui->enableDistortionCheck->isChecked())
1101 strlist.append(QStringLiteral("distortion"));
1102 if(!ui->enableCompressorCheck->isChecked())
1103 strlist.append(QStringLiteral("compressor"));
1104 if(!ui->enableEchoCheck->isChecked())
1105 strlist.append(QStringLiteral("echo"));
1106 if(!ui->enableEqualizerCheck->isChecked())
1107 strlist.append(QStringLiteral("equalizer"));
1108 if(!ui->enableFlangerCheck->isChecked())
1109 strlist.append(QStringLiteral("flanger"));
1110 if(!ui->enableFrequencyShifterCheck->isChecked())
1111 strlist.append(QStringLiteral("fshifter"));
1112 if(!ui->enableModulatorCheck->isChecked())
1113 strlist.append(QStringLiteral("modulator"));
1114 if(!ui->enableDedicatedCheck->isChecked())
1115 strlist.append(QStringLiteral("dedicated"));
1116 if(!ui->enablePitchShifterCheck->isChecked())
1117 strlist.append(QStringLiteral("pshifter"));
1118 if(!ui->enableVocalMorpherCheck->isChecked())
1119 strlist.append(QStringLiteral("vmorpher"));
1120 settings.setValue(QStringLiteral("excludefx"), strlist.join(QChar{','}));
1121 settings.setValue(QStringLiteral("eax/enable"),
1122 (!ui->enableEaxCheck->isEnabled() || ui->enableEaxCheck->isChecked())
1123 ? QString{/*"true"*/} : QStringLiteral("false"));
1125 settings.setValue(QStringLiteral("pipewire/assume-audio"), getCheckValue(ui->pwireAssumeAudioCheckBox));
1126 settings.setValue(QStringLiteral("pipewire/rt-mix"), getCheckValue(ui->pwireRtMixCheckBox));
1128 settings.setValue(QStringLiteral("wasapi/allow-resampler"), getCheckValue(ui->wasapiResamplerCheckBox));
1130 settings.setValue(QStringLiteral("pulse/spawn-server"), getCheckValue(ui->pulseAutospawnCheckBox));
1131 settings.setValue(QStringLiteral("pulse/allow-moves"), getCheckValue(ui->pulseAllowMovesCheckBox));
1132 settings.setValue(QStringLiteral("pulse/fix-rate"), getCheckValue(ui->pulseFixRateCheckBox));
1133 settings.setValue(QStringLiteral("pulse/adjust-latency"), getCheckValue(ui->pulseAdjLatencyCheckBox));
1135 settings.setValue(QStringLiteral("jack/spawn-server"), getCheckValue(ui->jackAutospawnCheckBox));
1136 settings.setValue(QStringLiteral("jack/connect-ports"), getCheckValue(ui->jackConnectPortsCheckBox));
1137 settings.setValue(QStringLiteral("jack/rt-mix"), getCheckValue(ui->jackRtMixCheckBox));
1138 settings.setValue(QStringLiteral("jack/buffer-size"), ui->jackBufferSizeLine->text());
1140 settings.setValue(QStringLiteral("alsa/device"), ui->alsaDefaultDeviceLine->text());
1141 settings.setValue(QStringLiteral("alsa/capture"), ui->alsaDefaultCaptureLine->text());
1142 settings.setValue(QStringLiteral("alsa/allow-resampler"), getCheckValue(ui->alsaResamplerCheckBox));
1143 settings.setValue(QStringLiteral("alsa/mmap"), getCheckValue(ui->alsaMmapCheckBox));
1145 settings.setValue(QStringLiteral("oss/device"), ui->ossDefaultDeviceLine->text());
1146 settings.setValue(QStringLiteral("oss/capture"), ui->ossDefaultCaptureLine->text());
1148 settings.setValue(QStringLiteral("solaris/device"), ui->solarisDefaultDeviceLine->text());
1150 settings.setValue(QStringLiteral("wave/file"), ui->waveOutputLine->text());
1151 settings.setValue(QStringLiteral("wave/bformat"),
1152 ui->waveBFormatCheckBox->isChecked() ? QStringLiteral("true") : QString{/*"false"*/}
1155 /* Remove empty keys
1156 * FIXME: Should only remove keys whose value matches the globally-specified value.
1158 allkeys = settings.allKeys();
1159 Q_FOREACH(const QString &key, allkeys)
1161 QString str{settings.value(key).toString()};
1162 if(str.isEmpty())
1163 settings.remove(key);
1168 void MainWindow::enableApplyButton()
1170 if(!mNeedsSave)
1171 ui->applyButton->setEnabled(true);
1172 mNeedsSave = true;
1173 ui->closeCancelButton->setText(tr("Cancel"));
1177 void MainWindow::updateResamplerLabel(int num)
1179 ui->resamplerLabel->setText(std::data(resamplerList[num].name));
1180 enableApplyButton();
1184 void MainWindow::updatePeriodSizeEdit(int size)
1186 ui->periodSizeEdit->clear();
1187 if(size >= 64)
1188 ui->periodSizeEdit->insert(QString::number(size));
1189 enableApplyButton();
1192 void MainWindow::updatePeriodSizeSlider()
1194 int pos = ui->periodSizeEdit->text().toInt();
1195 if(pos >= 64)
1197 if(pos > 8192)
1198 pos = 8192;
1199 ui->periodSizeSlider->setSliderPosition(pos);
1201 enableApplyButton();
1204 void MainWindow::updatePeriodCountEdit(int count)
1206 ui->periodCountEdit->clear();
1207 if(count >= 2)
1208 ui->periodCountEdit->insert(QString::number(count));
1209 enableApplyButton();
1212 void MainWindow::updatePeriodCountSlider()
1214 int pos = ui->periodCountEdit->text().toInt();
1215 if(pos < 2)
1216 pos = 0;
1217 else if(pos > 16)
1218 pos = 16;
1219 ui->periodCountSlider->setSliderPosition(pos);
1220 enableApplyButton();
1224 void MainWindow::selectQuadDecoderFile()
1225 { selectDecoderFile(ui->decoderQuadLineEdit, "Select Quadraphonic Decoder");}
1226 void MainWindow::select51DecoderFile()
1227 { selectDecoderFile(ui->decoder51LineEdit, "Select 5.1 Surround Decoder");}
1228 void MainWindow::select61DecoderFile()
1229 { selectDecoderFile(ui->decoder61LineEdit, "Select 6.1 Surround Decoder");}
1230 void MainWindow::select71DecoderFile()
1231 { selectDecoderFile(ui->decoder71LineEdit, "Select 7.1 Surround Decoder");}
1232 void MainWindow::select3D71DecoderFile()
1233 { selectDecoderFile(ui->decoder3D71LineEdit, "Select 3D7.1 Surround Decoder");}
1234 void MainWindow::selectDecoderFile(QLineEdit *line, const char *caption)
1236 QString dir{line->text()};
1237 if(dir.isEmpty() || QDir::isRelativePath(dir))
1239 QStringList paths{getAllDataPaths("/openal/presets")};
1240 while(!paths.isEmpty())
1242 if(QDir{paths.last()}.exists())
1244 dir = paths.last();
1245 break;
1247 paths.removeLast();
1250 QString fname{QFileDialog::getOpenFileName(this, tr(caption),
1251 dir, tr("AmbDec Files (*.ambdec);;All Files (*.*)"))};
1252 if(!fname.isEmpty())
1254 line->setText(fname);
1255 enableApplyButton();
1260 void MainWindow::updateJackBufferSizeEdit(int size)
1262 ui->jackBufferSizeLine->clear();
1263 if(size > 0)
1264 ui->jackBufferSizeLine->insert(QString::number(1<<size));
1265 enableApplyButton();
1268 void MainWindow::updateJackBufferSizeSlider()
1270 int value{ui->jackBufferSizeLine->text().toInt()};
1271 auto pos = static_cast<int>(floor(log2(value) + 0.5));
1272 ui->jackBufferSizeSlider->setSliderPosition(pos);
1273 enableApplyButton();
1277 void MainWindow::updateHrtfModeLabel(int num)
1279 ui->hrtfmodeLabel->setText(std::data(hrtfModeList[static_cast<uint>(num)].name));
1280 enableApplyButton();
1284 void MainWindow::addHrtfFile()
1286 QString path{QFileDialog::getExistingDirectory(this, tr("Select HRTF Path"))};
1287 if(path.isEmpty() == false && !getAllDataPaths(QStringLiteral("/openal/hrtf")).contains(path))
1289 ui->hrtfFileList->addItem(path);
1290 enableApplyButton();
1294 void MainWindow::removeHrtfFile()
1296 QList<gsl::owner<QListWidgetItem*>> selected{ui->hrtfFileList->selectedItems()};
1297 if(!selected.isEmpty())
1299 std::for_each(selected.begin(), selected.end(), std::default_delete<QListWidgetItem>{});
1300 enableApplyButton();
1304 void MainWindow::updateHrtfRemoveButton()
1306 ui->hrtfRemoveButton->setEnabled(!ui->hrtfFileList->selectedItems().empty());
1309 void MainWindow::showEnabledBackendMenu(QPoint pt)
1311 QHash<QAction*,QString> actionMap;
1313 pt = ui->enabledBackendList->mapToGlobal(pt);
1315 QMenu ctxmenu;
1316 QAction *removeAction{ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove")};
1317 if(ui->enabledBackendList->selectedItems().empty())
1318 removeAction->setEnabled(false);
1319 ctxmenu.addSeparator();
1320 for(size_t i{0};i < backendList.size();++i)
1322 QString backend{std::data(backendList[i].full_string)};
1323 QAction *action{ctxmenu.addAction(QString("Add ")+backend)};
1324 actionMap[action] = backend;
1325 if(!ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).empty() ||
1326 !ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).empty())
1327 action->setEnabled(false);
1330 QAction *gotAction{ctxmenu.exec(pt)};
1331 if(gotAction == removeAction)
1333 QList<gsl::owner<QListWidgetItem*>> selected{ui->enabledBackendList->selectedItems()};
1334 std::for_each(selected.begin(), selected.end(), std::default_delete<QListWidgetItem>{});
1335 enableApplyButton();
1337 else if(gotAction != nullptr)
1339 auto iter = actionMap.constFind(gotAction);
1340 if(iter != actionMap.cend())
1341 ui->enabledBackendList->addItem(iter.value());
1342 enableApplyButton();
1346 void MainWindow::showDisabledBackendMenu(QPoint pt)
1348 QHash<QAction*,QString> actionMap;
1350 pt = ui->disabledBackendList->mapToGlobal(pt);
1352 QMenu ctxmenu;
1353 QAction *removeAction{ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove")};
1354 if(ui->disabledBackendList->selectedItems().empty())
1355 removeAction->setEnabled(false);
1356 ctxmenu.addSeparator();
1357 for(size_t i{0};i < backendList.size();++i)
1359 QString backend{std::data(backendList[i].full_string)};
1360 QAction *action{ctxmenu.addAction(QString("Add ")+backend)};
1361 actionMap[action] = backend;
1362 if(!ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).empty() ||
1363 !ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).empty())
1364 action->setEnabled(false);
1367 QAction *gotAction{ctxmenu.exec(pt)};
1368 if(gotAction == removeAction)
1370 QList<gsl::owner<QListWidgetItem*>> selected{ui->disabledBackendList->selectedItems()};
1371 std::for_each(selected.begin(), selected.end(), std::default_delete<QListWidgetItem>{});
1372 enableApplyButton();
1374 else if(gotAction != nullptr)
1376 auto iter = actionMap.constFind(gotAction);
1377 if(iter != actionMap.cend())
1378 ui->disabledBackendList->addItem(iter.value());
1379 enableApplyButton();
1383 void MainWindow::selectOSSPlayback()
1385 QString current{ui->ossDefaultDeviceLine->text()};
1386 if(current.isEmpty()) current = ui->ossDefaultDeviceLine->placeholderText();
1387 QString fname{QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current)};
1388 if(!fname.isEmpty())
1390 ui->ossDefaultDeviceLine->setText(fname);
1391 enableApplyButton();
1395 void MainWindow::selectOSSCapture()
1397 QString current{ui->ossDefaultCaptureLine->text()};
1398 if(current.isEmpty()) current = ui->ossDefaultCaptureLine->placeholderText();
1399 QString fname{QFileDialog::getOpenFileName(this, tr("Select Capture Device"), current)};
1400 if(!fname.isEmpty())
1402 ui->ossDefaultCaptureLine->setText(fname);
1403 enableApplyButton();
1407 void MainWindow::selectSolarisPlayback()
1409 QString current{ui->solarisDefaultDeviceLine->text()};
1410 if(current.isEmpty()) current = ui->solarisDefaultDeviceLine->placeholderText();
1411 QString fname{QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current)};
1412 if(!fname.isEmpty())
1414 ui->solarisDefaultDeviceLine->setText(fname);
1415 enableApplyButton();
1419 void MainWindow::selectWaveOutput()
1421 QString fname{QFileDialog::getSaveFileName(this, tr("Select Wave File Output"),
1422 ui->waveOutputLine->text(), tr("Wave Files (*.wav *.amb);;All Files (*.*)"))};
1423 if(!fname.isEmpty())
1425 ui->waveOutputLine->setText(fname);
1426 enableApplyButton();