Ensure the EAX functions are suitably aligned on 32-bit
[openal-soft.git] / utils / alsoft-config / mainwindow.cpp
blobbaecf52581e5a85e7fa453a8535863530aacefbb
2 #include "config.h"
4 #include "mainwindow.h"
6 #include <iostream>
7 #include <cmath>
9 #include <QFileDialog>
10 #include <QMessageBox>
11 #include <QCloseEvent>
12 #include <QSettings>
13 #include <QtGlobal>
14 #include "ui_mainwindow.h"
15 #include "verstr.h"
17 #ifdef _WIN32
18 #include <windows.h>
19 #include <shlobj.h>
20 #endif
22 namespace {
24 static const struct {
25 char backend_name[16];
26 char full_string[32];
27 } backendList[] = {
28 #ifdef HAVE_JACK
29 { "jack", "JACK" },
30 #endif
31 #ifdef HAVE_PIPEWIRE
32 { "pipewire", "PipeWire" },
33 #endif
34 #ifdef HAVE_PULSEAUDIO
35 { "pulse", "PulseAudio" },
36 #endif
37 #ifdef HAVE_ALSA
38 { "alsa", "ALSA" },
39 #endif
40 #ifdef HAVE_COREAUDIO
41 { "core", "CoreAudio" },
42 #endif
43 #ifdef HAVE_OSS
44 { "oss", "OSS" },
45 #endif
46 #ifdef HAVE_SOLARIS
47 { "solaris", "Solaris" },
48 #endif
49 #ifdef HAVE_SNDIO
50 { "sndio", "SoundIO" },
51 #endif
52 #ifdef HAVE_QSA
53 { "qsa", "QSA" },
54 #endif
55 #ifdef HAVE_WASAPI
56 { "wasapi", "WASAPI" },
57 #endif
58 #ifdef HAVE_DSOUND
59 { "dsound", "DirectSound" },
60 #endif
61 #ifdef HAVE_WINMM
62 { "winmm", "Windows Multimedia" },
63 #endif
64 #ifdef HAVE_PORTAUDIO
65 { "port", "PortAudio" },
66 #endif
67 #ifdef HAVE_OPENSL
68 { "opensl", "OpenSL" },
69 #endif
71 { "null", "Null Output" },
72 #ifdef HAVE_WAVE
73 { "wave", "Wave Writer" },
74 #endif
75 { "", "" }
78 static const struct NameValuePair {
79 const char name[64];
80 const char value[16];
81 } speakerModeList[] = {
82 { "Autodetect", "" },
83 { "Mono", "mono" },
84 { "Stereo", "stereo" },
85 { "Quadraphonic", "quad" },
86 { "5.1 Surround", "surround51" },
87 { "6.1 Surround", "surround61" },
88 { "7.1 Surround", "surround71" },
90 { "Ambisonic, 1st Order", "ambi1" },
91 { "Ambisonic, 2nd Order", "ambi2" },
92 { "Ambisonic, 3rd Order", "ambi3" },
94 { "", "" }
95 }, sampleTypeList[] = {
96 { "Autodetect", "" },
97 { "8-bit int", "int8" },
98 { "8-bit uint", "uint8" },
99 { "16-bit int", "int16" },
100 { "16-bit uint", "uint16" },
101 { "32-bit int", "int32" },
102 { "32-bit uint", "uint32" },
103 { "32-bit float", "float32" },
105 { "", "" }
106 }, resamplerList[] = {
107 { "Point", "point" },
108 { "Linear", "linear" },
109 { "Default (Linear)", "" },
110 { "Cubic Spline", "cubic" },
111 { "11th order Sinc (fast)", "fast_bsinc12" },
112 { "11th order Sinc", "bsinc12" },
113 { "23rd order Sinc (fast)", "fast_bsinc24" },
114 { "23rd order Sinc", "bsinc24" },
116 { "", "" }
117 }, stereoModeList[] = {
118 { "Autodetect", "" },
119 { "Speakers", "speakers" },
120 { "Headphones", "headphones" },
122 { "", "" }
123 }, stereoEncList[] = {
124 { "Default", "" },
125 { "Pan Pot", "panpot" },
126 { "UHJ", "uhj" },
127 { "Binaural", "hrtf" },
129 { "", "" }
130 }, ambiFormatList[] = {
131 { "Default", "" },
132 { "AmbiX (ACN, SN3D)", "ambix" },
133 { "Furse-Malham", "fuma" },
134 { "ACN, N3D", "acn+n3d" },
135 { "ACN, FuMa", "acn+fuma" },
137 { "", "" }
138 }, hrtfModeList[] = {
139 { "1st Order Ambisonic", "ambi1" },
140 { "2nd Order Ambisonic", "ambi2" },
141 { "3rd Order Ambisonic", "ambi3" },
142 { "Default (Full)", "" },
143 { "Full", "full" },
145 { "", "" }
148 static QString getDefaultConfigName()
150 #ifdef Q_OS_WIN32
151 static const char fname[] = "alsoft.ini";
152 auto get_appdata_path = []() noexcept -> QString
154 WCHAR buffer[MAX_PATH];
155 if(SHGetSpecialFolderPathW(nullptr, buffer, CSIDL_APPDATA, FALSE) != FALSE)
156 return QString::fromWCharArray(buffer);
157 return QString();
159 QString base = get_appdata_path();
160 #else
161 static const char fname[] = "alsoft.conf";
162 QByteArray base = qgetenv("XDG_CONFIG_HOME");
163 if(base.isEmpty())
165 base = qgetenv("HOME");
166 if(base.isEmpty() == false)
167 base += "/.config";
169 #endif
170 if(base.isEmpty() == false)
171 return base +'/'+ fname;
172 return fname;
175 static QString getBaseDataPath()
177 #ifdef Q_OS_WIN32
178 auto get_appdata_path = []() noexcept -> QString
180 WCHAR buffer[MAX_PATH];
181 if(SHGetSpecialFolderPathW(nullptr, buffer, CSIDL_APPDATA, FALSE) != FALSE)
182 return QString::fromWCharArray(buffer);
183 return QString();
185 QString base = get_appdata_path();
186 #else
187 QByteArray base = qgetenv("XDG_DATA_HOME");
188 if(base.isEmpty())
190 base = qgetenv("HOME");
191 if(!base.isEmpty())
192 base += "/.local/share";
194 #endif
195 return base;
198 static QStringList getAllDataPaths(const QString &append)
200 QStringList list;
201 list.append(getBaseDataPath());
202 #ifdef Q_OS_WIN32
203 // TODO: Common AppData path
204 #else
205 QString paths = qgetenv("XDG_DATA_DIRS");
206 if(paths.isEmpty())
207 paths = "/usr/local/share/:/usr/share/";
208 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
209 list += paths.split(QChar(':'), Qt::SkipEmptyParts);
210 #else
211 list += paths.split(QChar(':'), QString::SkipEmptyParts);
212 #endif
213 #endif
214 QStringList::iterator iter = list.begin();
215 while(iter != list.end())
217 if(iter->isEmpty())
218 iter = list.erase(iter);
219 else
221 iter->append(append);
222 iter++;
225 return list;
228 template<size_t N>
229 static QString getValueFromName(const NameValuePair (&list)[N], const QString &str)
231 for(size_t i = 0;i < N-1;i++)
233 if(str == list[i].name)
234 return list[i].value;
236 return QString{};
239 template<size_t N>
240 static QString getNameFromValue(const NameValuePair (&list)[N], const QString &str)
242 for(size_t i = 0;i < N-1;i++)
244 if(str == list[i].value)
245 return list[i].name;
247 return QString{};
251 Qt::CheckState getCheckState(const QVariant &var)
253 if(var.isNull())
254 return Qt::PartiallyChecked;
255 if(var.toBool())
256 return Qt::Checked;
257 return Qt::Unchecked;
260 QString getCheckValue(const QCheckBox *checkbox)
262 const Qt::CheckState state{checkbox->checkState()};
263 if(state == Qt::Checked)
264 return QString{"true"};
265 if(state == Qt::Unchecked)
266 return QString{"false"};
267 return QString{};
272 MainWindow::MainWindow(QWidget *parent) :
273 QMainWindow(parent),
274 ui(new Ui::MainWindow),
275 mPeriodSizeValidator(nullptr),
276 mPeriodCountValidator(nullptr),
277 mSourceCountValidator(nullptr),
278 mEffectSlotValidator(nullptr),
279 mSourceSendValidator(nullptr),
280 mSampleRateValidator(nullptr),
281 mJackBufferValidator(nullptr),
282 mNeedsSave(false)
284 ui->setupUi(this);
286 for(int i = 0;speakerModeList[i].name[0];i++)
287 ui->channelConfigCombo->addItem(speakerModeList[i].name);
288 ui->channelConfigCombo->adjustSize();
289 for(int i = 0;sampleTypeList[i].name[0];i++)
290 ui->sampleFormatCombo->addItem(sampleTypeList[i].name);
291 ui->sampleFormatCombo->adjustSize();
292 for(int i = 0;stereoModeList[i].name[0];i++)
293 ui->stereoModeCombo->addItem(stereoModeList[i].name);
294 ui->stereoModeCombo->adjustSize();
295 for(int i = 0;stereoEncList[i].name[0];i++)
296 ui->stereoEncodingComboBox->addItem(stereoEncList[i].name);
297 ui->stereoEncodingComboBox->adjustSize();
298 for(int i = 0;ambiFormatList[i].name[0];i++)
299 ui->ambiFormatComboBox->addItem(ambiFormatList[i].name);
300 ui->ambiFormatComboBox->adjustSize();
302 int count;
303 for(count = 0;resamplerList[count].name[0];count++) {
305 ui->resamplerSlider->setRange(0, count-1);
307 for(count = 0;hrtfModeList[count].name[0];count++) {
309 ui->hrtfmodeSlider->setRange(0, count-1);
310 ui->hrtfStateComboBox->adjustSize();
312 #if !defined(HAVE_NEON) && !defined(HAVE_SSE)
313 ui->cpuExtDisabledLabel->move(ui->cpuExtDisabledLabel->x(), ui->cpuExtDisabledLabel->y() - 60);
314 #else
315 ui->cpuExtDisabledLabel->setVisible(false);
316 #endif
318 #ifndef HAVE_NEON
320 #ifndef HAVE_SSE4_1
321 #ifndef HAVE_SSE3
322 #ifndef HAVE_SSE2
323 #ifndef HAVE_SSE
324 ui->enableSSECheckBox->setVisible(false);
325 #endif /* !SSE */
326 ui->enableSSE2CheckBox->setVisible(false);
327 #endif /* !SSE2 */
328 ui->enableSSE3CheckBox->setVisible(false);
329 #endif /* !SSE3 */
330 ui->enableSSE41CheckBox->setVisible(false);
331 #endif /* !SSE4.1 */
332 ui->enableNeonCheckBox->setVisible(false);
334 #else /* !Neon */
336 #ifndef HAVE_SSE4_1
337 #ifndef HAVE_SSE3
338 #ifndef HAVE_SSE2
339 #ifndef HAVE_SSE
340 ui->enableNeonCheckBox->move(ui->enableNeonCheckBox->x(), ui->enableNeonCheckBox->y() - 30);
341 ui->enableSSECheckBox->setVisible(false);
342 #endif /* !SSE */
343 ui->enableSSE2CheckBox->setVisible(false);
344 #endif /* !SSE2 */
345 ui->enableSSE3CheckBox->setVisible(false);
346 #endif /* !SSE3 */
347 ui->enableSSE41CheckBox->setVisible(false);
348 #endif /* !SSE4.1 */
350 #endif
352 mPeriodSizeValidator = new QIntValidator{64, 8192, this};
353 ui->periodSizeEdit->setValidator(mPeriodSizeValidator);
354 mPeriodCountValidator = new QIntValidator{2, 16, this};
355 ui->periodCountEdit->setValidator(mPeriodCountValidator);
357 mSourceCountValidator = new QIntValidator{0, 4096, this};
358 ui->srcCountLineEdit->setValidator(mSourceCountValidator);
359 mEffectSlotValidator = new QIntValidator{0, 64, this};
360 ui->effectSlotLineEdit->setValidator(mEffectSlotValidator);
361 mSourceSendValidator = new QIntValidator{0, 16, this};
362 ui->srcSendLineEdit->setValidator(mSourceSendValidator);
363 mSampleRateValidator = new QIntValidator{8000, 192000, this};
364 ui->sampleRateCombo->lineEdit()->setValidator(mSampleRateValidator);
366 mJackBufferValidator = new QIntValidator{0, 8192, this};
367 ui->jackBufferSizeLine->setValidator(mJackBufferValidator);
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->decoderNFRefDelaySpinBox, 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);
410 connect(ui->preferredHrtfComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
411 connect(ui->hrtfStateComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
412 connect(ui->hrtfmodeSlider, &QSlider::valueChanged, this, &MainWindow::updateHrtfModeLabel);
414 connect(ui->hrtfAddButton, &QPushButton::clicked, this, &MainWindow::addHrtfFile);
415 connect(ui->hrtfRemoveButton, &QPushButton::clicked, this, &MainWindow::removeHrtfFile);
416 connect(ui->hrtfFileList, &QListWidget::itemSelectionChanged, this, &MainWindow::updateHrtfRemoveButton);
417 connect(ui->defaultHrtfPathsCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
419 connect(ui->srcCountLineEdit, &QLineEdit::editingFinished, this, &MainWindow::enableApplyButton);
420 connect(ui->srcSendLineEdit, &QLineEdit::editingFinished, this, &MainWindow::enableApplyButton);
421 connect(ui->effectSlotLineEdit, &QLineEdit::editingFinished, this, &MainWindow::enableApplyButton);
423 connect(ui->enableSSECheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
424 connect(ui->enableSSE2CheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
425 connect(ui->enableSSE3CheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
426 connect(ui->enableSSE41CheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
427 connect(ui->enableNeonCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
429 ui->enabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
430 connect(ui->enabledBackendList, &QListWidget::customContextMenuRequested, this, &MainWindow::showEnabledBackendMenu);
432 ui->disabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
433 connect(ui->disabledBackendList, &QListWidget::customContextMenuRequested, this, &MainWindow::showDisabledBackendMenu);
434 connect(ui->backendCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
436 connect(ui->defaultReverbComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
437 connect(ui->enableEaxReverbCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
438 connect(ui->enableStdReverbCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
439 connect(ui->enableAutowahCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
440 connect(ui->enableChorusCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
441 connect(ui->enableCompressorCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
442 connect(ui->enableDistortionCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
443 connect(ui->enableEchoCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
444 connect(ui->enableEqualizerCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
445 connect(ui->enableFlangerCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
446 connect(ui->enableFrequencyShifterCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
447 connect(ui->enableModulatorCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
448 connect(ui->enableDedicatedCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
449 connect(ui->enablePitchShifterCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
450 connect(ui->enableVocalMorpherCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
452 connect(ui->pulseAutospawnCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
453 connect(ui->pulseAllowMovesCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
454 connect(ui->pulseFixRateCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
455 connect(ui->pulseAdjLatencyCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
457 connect(ui->pwireAssumeAudioCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
459 connect(ui->jackAutospawnCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
460 connect(ui->jackConnectPortsCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
461 connect(ui->jackRtMixCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
462 connect(ui->jackBufferSizeSlider, &QSlider::valueChanged, this, &MainWindow::updateJackBufferSizeEdit);
463 connect(ui->jackBufferSizeLine, &QLineEdit::editingFinished, this, &MainWindow::updateJackBufferSizeSlider);
465 connect(ui->alsaDefaultDeviceLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
466 connect(ui->alsaDefaultCaptureLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
467 connect(ui->alsaResamplerCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
468 connect(ui->alsaMmapCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
470 connect(ui->ossDefaultDeviceLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
471 connect(ui->ossPlaybackPushButton, &QPushButton::clicked, this, &MainWindow::selectOSSPlayback);
472 connect(ui->ossDefaultCaptureLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
473 connect(ui->ossCapturePushButton, &QPushButton::clicked, this, &MainWindow::selectOSSCapture);
475 connect(ui->solarisDefaultDeviceLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
476 connect(ui->solarisPlaybackPushButton, &QPushButton::clicked, this, &MainWindow::selectSolarisPlayback);
478 connect(ui->waveOutputLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
479 connect(ui->waveOutputButton, &QPushButton::clicked, this, &MainWindow::selectWaveOutput);
480 connect(ui->waveBFormatCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
482 ui->backendListWidget->setCurrentRow(0);
483 ui->tabWidget->setCurrentIndex(0);
485 for(int i = 1;i < ui->backendListWidget->count();i++)
486 ui->backendListWidget->setRowHidden(i, true);
487 for(int i = 0;backendList[i].backend_name[0];i++)
489 QList<QListWidgetItem*> items = ui->backendListWidget->findItems(
490 backendList[i].full_string, Qt::MatchFixedString);
491 foreach(QListWidgetItem *item, items)
492 item->setHidden(false);
495 loadConfig(getDefaultConfigName());
498 MainWindow::~MainWindow()
500 delete ui;
501 delete mPeriodSizeValidator;
502 delete mPeriodCountValidator;
503 delete mSourceCountValidator;
504 delete mEffectSlotValidator;
505 delete mSourceSendValidator;
506 delete mSampleRateValidator;
507 delete mJackBufferValidator;
510 void MainWindow::closeEvent(QCloseEvent *event)
512 if(!mNeedsSave)
513 event->accept();
514 else
516 QMessageBox::StandardButton btn = QMessageBox::warning(this,
517 tr("Apply changes?"), tr("Save changes before quitting?"),
518 QMessageBox::Save | QMessageBox::No | QMessageBox::Cancel);
519 if(btn == QMessageBox::Save)
520 saveCurrentConfig();
521 if(btn == QMessageBox::Cancel)
522 event->ignore();
523 else
524 event->accept();
528 void MainWindow::cancelCloseAction()
530 mNeedsSave = false;
531 close();
535 void MainWindow::showAboutPage()
537 QMessageBox::information(this, tr("About"),
538 tr("OpenAL Soft Configuration Utility.\nBuilt for OpenAL Soft library version ") +
539 GetVersionString());
543 QStringList MainWindow::collectHrtfs()
545 QStringList ret;
546 QStringList processed;
548 for(int i = 0;i < ui->hrtfFileList->count();i++)
550 QDir dir(ui->hrtfFileList->item(i)->text());
551 QStringList fnames = dir.entryList(QDir::Files | QDir::Readable, QDir::Name);
552 foreach(const QString &fname, fnames)
554 if(!fname.endsWith(".mhr", Qt::CaseInsensitive))
555 continue;
556 QString fullname{dir.absoluteFilePath(fname)};
557 if(processed.contains(fullname))
558 continue;
559 processed.push_back(fullname);
561 QString name{fname.left(fname.length()-4)};
562 if(!ret.contains(name))
563 ret.push_back(name);
564 else
566 size_t i{2};
567 do {
568 QString s = name+" #"+QString::number(i);
569 if(!ret.contains(s))
571 ret.push_back(s);
572 break;
574 ++i;
575 } while(1);
580 if(ui->defaultHrtfPathsCheckBox->isChecked())
582 QStringList paths = getAllDataPaths("/openal/hrtf");
583 foreach(const QString &name, paths)
585 QDir dir{name};
586 QStringList fnames{dir.entryList(QDir::Files | QDir::Readable, QDir::Name)};
587 foreach(const QString &fname, fnames)
589 if(!fname.endsWith(".mhr", Qt::CaseInsensitive))
590 continue;
591 QString fullname{dir.absoluteFilePath(fname)};
592 if(processed.contains(fullname))
593 continue;
594 processed.push_back(fullname);
596 QString name{fname.left(fname.length()-4)};
597 if(!ret.contains(name))
598 ret.push_back(name);
599 else
601 size_t i{2};
602 do {
603 QString s{name+" #"+QString::number(i)};
604 if(!ret.contains(s))
606 ret.push_back(s);
607 break;
609 ++i;
610 } while(1);
615 #ifdef ALSOFT_EMBED_HRTF_DATA
616 ret.push_back("Built-In HRTF");
617 #endif
619 return ret;
623 void MainWindow::loadConfigFromFile()
625 QString fname = QFileDialog::getOpenFileName(this, tr("Select Files"));
626 if(fname.isEmpty() == false)
627 loadConfig(fname);
630 void MainWindow::loadConfig(const QString &fname)
632 QSettings settings{fname, QSettings::IniFormat};
634 QString sampletype = settings.value("sample-type").toString();
635 ui->sampleFormatCombo->setCurrentIndex(0);
636 if(sampletype.isEmpty() == false)
638 QString str{getNameFromValue(sampleTypeList, sampletype)};
639 if(!str.isEmpty())
641 const int j{ui->sampleFormatCombo->findText(str)};
642 if(j > 0) ui->sampleFormatCombo->setCurrentIndex(j);
646 QString channelconfig{settings.value("channels").toString()};
647 ui->channelConfigCombo->setCurrentIndex(0);
648 if(channelconfig.isEmpty() == false)
650 if(channelconfig == "surround51rear")
651 channelconfig = "surround51";
652 QString str{getNameFromValue(speakerModeList, channelconfig)};
653 if(!str.isEmpty())
655 const int j{ui->channelConfigCombo->findText(str)};
656 if(j > 0) ui->channelConfigCombo->setCurrentIndex(j);
660 QString srate{settings.value("frequency").toString()};
661 if(srate.isEmpty())
662 ui->sampleRateCombo->setCurrentIndex(0);
663 else
665 ui->sampleRateCombo->lineEdit()->clear();
666 ui->sampleRateCombo->lineEdit()->insert(srate);
669 ui->srcCountLineEdit->clear();
670 ui->srcCountLineEdit->insert(settings.value("sources").toString());
671 ui->effectSlotLineEdit->clear();
672 ui->effectSlotLineEdit->insert(settings.value("slots").toString());
673 ui->srcSendLineEdit->clear();
674 ui->srcSendLineEdit->insert(settings.value("sends").toString());
676 QString resampler = settings.value("resampler").toString().trimmed();
677 ui->resamplerSlider->setValue(2);
678 ui->resamplerLabel->setText(resamplerList[2].name);
679 /* The "sinc4" and "sinc8" resamplers are no longer supported. Use "cubic"
680 * as a fallback.
682 if(resampler == "sinc4" || resampler == "sinc8")
683 resampler = "cubic";
684 /* The "bsinc" resampler name is an alias for "bsinc12". */
685 else if(resampler == "bsinc")
686 resampler = "bsinc12";
687 for(int i = 0;resamplerList[i].name[0];i++)
689 if(resampler == resamplerList[i].value)
691 ui->resamplerSlider->setValue(i);
692 ui->resamplerLabel->setText(resamplerList[i].name);
693 break;
697 QString stereomode = settings.value("stereo-mode").toString().trimmed();
698 ui->stereoModeCombo->setCurrentIndex(0);
699 if(stereomode.isEmpty() == false)
701 QString str{getNameFromValue(stereoModeList, stereomode)};
702 if(!str.isEmpty())
704 const int j{ui->stereoModeCombo->findText(str)};
705 if(j > 0) ui->stereoModeCombo->setCurrentIndex(j);
709 int periodsize{settings.value("period_size").toInt()};
710 ui->periodSizeEdit->clear();
711 if(periodsize >= 64)
713 ui->periodSizeEdit->insert(QString::number(periodsize));
714 updatePeriodSizeSlider();
717 int periodcount{settings.value("periods").toInt()};
718 ui->periodCountEdit->clear();
719 if(periodcount >= 2)
721 ui->periodCountEdit->insert(QString::number(periodcount));
722 updatePeriodCountSlider();
725 ui->outputLimiterCheckBox->setCheckState(getCheckState(settings.value("output-limiter")));
726 ui->outputDitherCheckBox->setCheckState(getCheckState(settings.value("dither")));
728 QString stereopan{settings.value("stereo-encoding").toString()};
729 ui->stereoEncodingComboBox->setCurrentIndex(0);
730 if(stereopan.isEmpty() == false)
732 QString str{getNameFromValue(stereoEncList, stereopan)};
733 if(!str.isEmpty())
735 const int j{ui->stereoEncodingComboBox->findText(str)};
736 if(j > 0) ui->stereoEncodingComboBox->setCurrentIndex(j);
740 QString ambiformat{settings.value("ambi-format").toString()};
741 ui->ambiFormatComboBox->setCurrentIndex(0);
742 if(ambiformat.isEmpty() == false)
744 QString str{getNameFromValue(ambiFormatList, ambiformat)};
745 if(!str.isEmpty())
747 const int j{ui->ambiFormatComboBox->findText(str)};
748 if(j > 0) ui->ambiFormatComboBox->setCurrentIndex(j);
752 ui->decoderHQModeCheckBox->setChecked(getCheckState(settings.value("decoder/hq-mode")));
753 ui->decoderDistCompCheckBox->setCheckState(getCheckState(settings.value("decoder/distance-comp")));
754 ui->decoderNFEffectsCheckBox->setCheckState(getCheckState(settings.value("decoder/nfc")));
755 double refdelay{settings.value("decoder/nfc-ref-delay", 0.0).toDouble()};
756 ui->decoderNFRefDelaySpinBox->setValue(refdelay);
758 ui->decoderQuadLineEdit->setText(settings.value("decoder/quad").toString());
759 ui->decoder51LineEdit->setText(settings.value("decoder/surround51").toString());
760 ui->decoder61LineEdit->setText(settings.value("decoder/surround61").toString());
761 ui->decoder71LineEdit->setText(settings.value("decoder/surround71").toString());
763 QStringList disabledCpuExts{settings.value("disable-cpu-exts").toStringList()};
764 if(disabledCpuExts.size() == 1)
765 disabledCpuExts = disabledCpuExts[0].split(QChar(','));
766 for(QString &name : disabledCpuExts)
767 name = name.trimmed();
768 ui->enableSSECheckBox->setChecked(!disabledCpuExts.contains("sse", Qt::CaseInsensitive));
769 ui->enableSSE2CheckBox->setChecked(!disabledCpuExts.contains("sse2", Qt::CaseInsensitive));
770 ui->enableSSE3CheckBox->setChecked(!disabledCpuExts.contains("sse3", Qt::CaseInsensitive));
771 ui->enableSSE41CheckBox->setChecked(!disabledCpuExts.contains("sse4.1", Qt::CaseInsensitive));
772 ui->enableNeonCheckBox->setChecked(!disabledCpuExts.contains("neon", Qt::CaseInsensitive));
774 QString hrtfmode{settings.value("hrtf-mode").toString().trimmed()};
775 ui->hrtfmodeSlider->setValue(2);
776 ui->hrtfmodeLabel->setText(hrtfModeList[3].name);
777 /* The "basic" mode name is no longer supported. Use "ambi2" instead. */
778 if(hrtfmode == "basic")
779 hrtfmode = "ambi2";
780 for(int i = 0;hrtfModeList[i].name[0];i++)
782 if(hrtfmode == hrtfModeList[i].value)
784 ui->hrtfmodeSlider->setValue(i);
785 ui->hrtfmodeLabel->setText(hrtfModeList[i].name);
786 break;
790 QStringList hrtf_paths{settings.value("hrtf-paths").toStringList()};
791 if(hrtf_paths.size() == 1)
792 hrtf_paths = hrtf_paths[0].split(QChar(','));
793 for(QString &name : hrtf_paths)
794 name = name.trimmed();
795 if(!hrtf_paths.empty() && !hrtf_paths.back().isEmpty())
796 ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Unchecked);
797 else
799 hrtf_paths.removeAll(QString());
800 ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Checked);
802 hrtf_paths.removeDuplicates();
803 ui->hrtfFileList->clear();
804 ui->hrtfFileList->addItems(hrtf_paths);
805 updateHrtfRemoveButton();
807 QString hrtfstate{settings.value("hrtf").toString().toLower()};
808 if(hrtfstate == "true")
809 ui->hrtfStateComboBox->setCurrentIndex(1);
810 else if(hrtfstate == "false")
811 ui->hrtfStateComboBox->setCurrentIndex(2);
812 else
813 ui->hrtfStateComboBox->setCurrentIndex(0);
815 ui->preferredHrtfComboBox->clear();
816 ui->preferredHrtfComboBox->addItem("- Any -");
817 if(ui->defaultHrtfPathsCheckBox->isChecked())
819 QStringList hrtfs{collectHrtfs()};
820 foreach(const QString &name, hrtfs)
821 ui->preferredHrtfComboBox->addItem(name);
824 QString defaulthrtf{settings.value("default-hrtf").toString()};
825 ui->preferredHrtfComboBox->setCurrentIndex(0);
826 if(defaulthrtf.isEmpty() == false)
828 int i{ui->preferredHrtfComboBox->findText(defaulthrtf)};
829 if(i > 0)
830 ui->preferredHrtfComboBox->setCurrentIndex(i);
831 else
833 i = ui->preferredHrtfComboBox->count();
834 ui->preferredHrtfComboBox->addItem(defaulthrtf);
835 ui->preferredHrtfComboBox->setCurrentIndex(i);
838 ui->preferredHrtfComboBox->adjustSize();
840 ui->enabledBackendList->clear();
841 ui->disabledBackendList->clear();
842 QStringList drivers{settings.value("drivers").toStringList()};
843 if(drivers.size() == 0)
844 ui->backendCheckBox->setChecked(true);
845 else
847 if(drivers.size() == 1)
848 drivers = drivers[0].split(QChar(','));
849 for(QString &name : drivers)
851 name = name.trimmed();
852 /* Convert "mmdevapi" references to "wasapi" for backwards
853 * compatibility.
855 if(name == "-mmdevapi")
856 name = "-wasapi";
857 else if(name == "mmdevapi")
858 name = "wasapi";
861 bool lastWasEmpty = false;
862 foreach(const QString &backend, drivers)
864 lastWasEmpty = backend.isEmpty();
865 if(lastWasEmpty) continue;
867 if(!backend.startsWith(QChar('-')))
868 for(int j = 0;backendList[j].backend_name[0];j++)
870 if(backend == backendList[j].backend_name)
872 ui->enabledBackendList->addItem(backendList[j].full_string);
873 break;
876 else if(backend.size() > 1)
878 QStringRef backendref{backend.rightRef(backend.size()-1)};
879 for(int j = 0;backendList[j].backend_name[0];j++)
881 if(backendref == backendList[j].backend_name)
883 ui->disabledBackendList->addItem(backendList[j].full_string);
884 break;
889 ui->backendCheckBox->setChecked(lastWasEmpty);
892 QString defaultreverb{settings.value("default-reverb").toString().toLower()};
893 ui->defaultReverbComboBox->setCurrentIndex(0);
894 if(defaultreverb.isEmpty() == false)
896 for(int i = 0;i < ui->defaultReverbComboBox->count();i++)
898 if(defaultreverb.compare(ui->defaultReverbComboBox->itemText(i).toLower()) == 0)
900 ui->defaultReverbComboBox->setCurrentIndex(i);
901 break;
906 QStringList excludefx{settings.value("excludefx").toStringList()};
907 if(excludefx.size() == 1)
908 excludefx = excludefx[0].split(QChar(','));
909 for(QString &name : excludefx)
910 name = name.trimmed();
911 ui->enableEaxReverbCheck->setChecked(!excludefx.contains("eaxreverb", Qt::CaseInsensitive));
912 ui->enableStdReverbCheck->setChecked(!excludefx.contains("reverb", Qt::CaseInsensitive));
913 ui->enableAutowahCheck->setChecked(!excludefx.contains("autowah", Qt::CaseInsensitive));
914 ui->enableChorusCheck->setChecked(!excludefx.contains("chorus", Qt::CaseInsensitive));
915 ui->enableCompressorCheck->setChecked(!excludefx.contains("compressor", Qt::CaseInsensitive));
916 ui->enableDistortionCheck->setChecked(!excludefx.contains("distortion", Qt::CaseInsensitive));
917 ui->enableEchoCheck->setChecked(!excludefx.contains("echo", Qt::CaseInsensitive));
918 ui->enableEqualizerCheck->setChecked(!excludefx.contains("equalizer", Qt::CaseInsensitive));
919 ui->enableFlangerCheck->setChecked(!excludefx.contains("flanger", Qt::CaseInsensitive));
920 ui->enableFrequencyShifterCheck->setChecked(!excludefx.contains("fshifter", Qt::CaseInsensitive));
921 ui->enableModulatorCheck->setChecked(!excludefx.contains("modulator", Qt::CaseInsensitive));
922 ui->enableDedicatedCheck->setChecked(!excludefx.contains("dedicated", Qt::CaseInsensitive));
923 ui->enablePitchShifterCheck->setChecked(!excludefx.contains("pshifter", Qt::CaseInsensitive));
924 ui->enableVocalMorpherCheck->setChecked(!excludefx.contains("vmorpher", Qt::CaseInsensitive));
926 ui->pulseAutospawnCheckBox->setCheckState(getCheckState(settings.value("pulse/spawn-server")));
927 ui->pulseAllowMovesCheckBox->setCheckState(getCheckState(settings.value("pulse/allow-moves")));
928 ui->pulseFixRateCheckBox->setCheckState(getCheckState(settings.value("pulse/fix-rate")));
929 ui->pulseAdjLatencyCheckBox->setCheckState(getCheckState(settings.value("pulse/adjust-latency")));
931 ui->pwireAssumeAudioCheckBox->setCheckState(settings.value("pipewire/assume-audio").toBool()
932 ? Qt::Checked : Qt::Unchecked);
934 ui->jackAutospawnCheckBox->setCheckState(getCheckState(settings.value("jack/spawn-server")));
935 ui->jackConnectPortsCheckBox->setCheckState(getCheckState(settings.value("jack/connect-ports")));
936 ui->jackRtMixCheckBox->setCheckState(getCheckState(settings.value("jack/rt-mix")));
937 ui->jackBufferSizeLine->setText(settings.value("jack/buffer-size", QString()).toString());
938 updateJackBufferSizeSlider();
940 ui->alsaDefaultDeviceLine->setText(settings.value("alsa/device", QString()).toString());
941 ui->alsaDefaultCaptureLine->setText(settings.value("alsa/capture", QString()).toString());
942 ui->alsaResamplerCheckBox->setCheckState(getCheckState(settings.value("alsa/allow-resampler")));
943 ui->alsaMmapCheckBox->setCheckState(getCheckState(settings.value("alsa/mmap")));
945 ui->ossDefaultDeviceLine->setText(settings.value("oss/device", QString()).toString());
946 ui->ossDefaultCaptureLine->setText(settings.value("oss/capture", QString()).toString());
948 ui->solarisDefaultDeviceLine->setText(settings.value("solaris/device", QString()).toString());
950 ui->waveOutputLine->setText(settings.value("wave/file", QString()).toString());
951 ui->waveBFormatCheckBox->setChecked(settings.value("wave/bformat", false).toBool());
953 ui->applyButton->setEnabled(false);
954 ui->closeCancelButton->setText(tr("Close"));
955 mNeedsSave = false;
958 void MainWindow::saveCurrentConfig()
960 saveConfig(getDefaultConfigName());
961 ui->applyButton->setEnabled(false);
962 ui->closeCancelButton->setText(tr("Close"));
963 mNeedsSave = false;
964 QMessageBox::information(this, tr("Information"),
965 tr("Applications using OpenAL need to be restarted for changes to take effect."));
968 void MainWindow::saveConfigAsFile()
970 QString fname{QFileDialog::getOpenFileName(this, tr("Select Files"))};
971 if(fname.isEmpty() == false)
973 saveConfig(fname);
974 ui->applyButton->setEnabled(false);
975 mNeedsSave = false;
979 void MainWindow::saveConfig(const QString &fname) const
981 QSettings settings{fname, QSettings::IniFormat};
983 /* HACK: Compound any stringlist values into a comma-separated string. */
984 QStringList allkeys{settings.allKeys()};
985 foreach(const QString &key, allkeys)
987 QStringList vals{settings.value(key).toStringList()};
988 if(vals.size() > 1)
989 settings.setValue(key, vals.join(QChar(',')));
992 settings.setValue("sample-type", getValueFromName(sampleTypeList, ui->sampleFormatCombo->currentText()));
993 settings.setValue("channels", getValueFromName(speakerModeList, ui->channelConfigCombo->currentText()));
995 uint rate{ui->sampleRateCombo->currentText().toUInt()};
996 if(rate <= 0)
997 settings.setValue("frequency", QString{});
998 else
999 settings.setValue("frequency", rate);
1001 settings.setValue("period_size", ui->periodSizeEdit->text());
1002 settings.setValue("periods", ui->periodCountEdit->text());
1004 settings.setValue("sources", ui->srcCountLineEdit->text());
1005 settings.setValue("slots", ui->effectSlotLineEdit->text());
1007 settings.setValue("resampler", resamplerList[ui->resamplerSlider->value()].value);
1009 settings.setValue("stereo-mode", getValueFromName(stereoModeList, ui->stereoModeCombo->currentText()));
1010 settings.setValue("stereo-encoding", getValueFromName(stereoEncList, ui->stereoEncodingComboBox->currentText()));
1011 settings.setValue("ambi-format", getValueFromName(ambiFormatList, ui->ambiFormatComboBox->currentText()));
1013 settings.setValue("output-limiter", getCheckValue(ui->outputLimiterCheckBox));
1014 settings.setValue("dither", getCheckValue(ui->outputDitherCheckBox));
1016 settings.setValue("decoder/hq-mode", getCheckValue(ui->decoderHQModeCheckBox));
1017 settings.setValue("decoder/distance-comp", getCheckValue(ui->decoderDistCompCheckBox));
1018 settings.setValue("decoder/nfc", getCheckValue(ui->decoderNFEffectsCheckBox));
1019 double refdelay = ui->decoderNFRefDelaySpinBox->value();
1020 settings.setValue("decoder/nfc-ref-delay",
1021 (refdelay > 0.0) ? QString::number(refdelay) : QString{}
1024 settings.setValue("decoder/quad", ui->decoderQuadLineEdit->text());
1025 settings.setValue("decoder/surround51", ui->decoder51LineEdit->text());
1026 settings.setValue("decoder/surround61", ui->decoder61LineEdit->text());
1027 settings.setValue("decoder/surround71", ui->decoder71LineEdit->text());
1029 QStringList strlist;
1030 if(!ui->enableSSECheckBox->isChecked())
1031 strlist.append("sse");
1032 if(!ui->enableSSE2CheckBox->isChecked())
1033 strlist.append("sse2");
1034 if(!ui->enableSSE3CheckBox->isChecked())
1035 strlist.append("sse3");
1036 if(!ui->enableSSE41CheckBox->isChecked())
1037 strlist.append("sse4.1");
1038 if(!ui->enableNeonCheckBox->isChecked())
1039 strlist.append("neon");
1040 settings.setValue("disable-cpu-exts", strlist.join(QChar(',')));
1042 settings.setValue("hrtf-mode", hrtfModeList[ui->hrtfmodeSlider->value()].value);
1044 if(ui->hrtfStateComboBox->currentIndex() == 1)
1045 settings.setValue("hrtf", "true");
1046 else if(ui->hrtfStateComboBox->currentIndex() == 2)
1047 settings.setValue("hrtf", "false");
1048 else
1049 settings.setValue("hrtf", QString{});
1051 if(ui->preferredHrtfComboBox->currentIndex() == 0)
1052 settings.setValue("default-hrtf", QString{});
1053 else
1055 QString str{ui->preferredHrtfComboBox->currentText()};
1056 settings.setValue("default-hrtf", str);
1059 strlist.clear();
1060 strlist.reserve(ui->hrtfFileList->count());
1061 for(int i = 0;i < ui->hrtfFileList->count();i++)
1062 strlist.append(ui->hrtfFileList->item(i)->text());
1063 if(!strlist.empty() && ui->defaultHrtfPathsCheckBox->isChecked())
1064 strlist.append(QString{});
1065 settings.setValue("hrtf-paths", strlist.join(QChar{','}));
1067 strlist.clear();
1068 for(int i = 0;i < ui->enabledBackendList->count();i++)
1070 QString label{ui->enabledBackendList->item(i)->text()};
1071 for(int j = 0;backendList[j].backend_name[0];j++)
1073 if(label == backendList[j].full_string)
1075 strlist.append(backendList[j].backend_name);
1076 break;
1080 for(int i = 0;i < ui->disabledBackendList->count();i++)
1082 QString label{ui->disabledBackendList->item(i)->text()};
1083 for(int j = 0;backendList[j].backend_name[0];j++)
1085 if(label == backendList[j].full_string)
1087 strlist.append(QChar{'-'}+QString{backendList[j].backend_name});
1088 break;
1092 if(strlist.size() == 0 && !ui->backendCheckBox->isChecked())
1093 strlist.append("-all");
1094 else if(ui->backendCheckBox->isChecked())
1095 strlist.append(QString{});
1096 settings.setValue("drivers", strlist.join(QChar(',')));
1098 // TODO: Remove check when we can properly match global values.
1099 if(ui->defaultReverbComboBox->currentIndex() == 0)
1100 settings.setValue("default-reverb", QString{});
1101 else
1103 QString str{ui->defaultReverbComboBox->currentText().toLower()};
1104 settings.setValue("default-reverb", str);
1107 strlist.clear();
1108 if(!ui->enableEaxReverbCheck->isChecked())
1109 strlist.append("eaxreverb");
1110 if(!ui->enableStdReverbCheck->isChecked())
1111 strlist.append("reverb");
1112 if(!ui->enableAutowahCheck->isChecked())
1113 strlist.append("autowah");
1114 if(!ui->enableChorusCheck->isChecked())
1115 strlist.append("chorus");
1116 if(!ui->enableDistortionCheck->isChecked())
1117 strlist.append("distortion");
1118 if(!ui->enableCompressorCheck->isChecked())
1119 strlist.append("compressor");
1120 if(!ui->enableEchoCheck->isChecked())
1121 strlist.append("echo");
1122 if(!ui->enableEqualizerCheck->isChecked())
1123 strlist.append("equalizer");
1124 if(!ui->enableFlangerCheck->isChecked())
1125 strlist.append("flanger");
1126 if(!ui->enableFrequencyShifterCheck->isChecked())
1127 strlist.append("fshifter");
1128 if(!ui->enableModulatorCheck->isChecked())
1129 strlist.append("modulator");
1130 if(!ui->enableDedicatedCheck->isChecked())
1131 strlist.append("dedicated");
1132 if(!ui->enablePitchShifterCheck->isChecked())
1133 strlist.append("pshifter");
1134 if(!ui->enableVocalMorpherCheck->isChecked())
1135 strlist.append("vmorpher");
1136 settings.setValue("excludefx", strlist.join(QChar{','}));
1138 settings.setValue("pulse/spawn-server", getCheckValue(ui->pulseAutospawnCheckBox));
1139 settings.setValue("pulse/allow-moves", getCheckValue(ui->pulseAllowMovesCheckBox));
1140 settings.setValue("pulse/fix-rate", getCheckValue(ui->pulseFixRateCheckBox));
1141 settings.setValue("pulse/adjust-latency", getCheckValue(ui->pulseAdjLatencyCheckBox));
1143 settings.setValue("pipewire/assume-audio", ui->pwireAssumeAudioCheckBox->isChecked()
1144 ? QString{"true"} : QString{/*"false"*/});
1146 settings.setValue("jack/spawn-server", getCheckValue(ui->jackAutospawnCheckBox));
1147 settings.setValue("jack/connect-ports", getCheckValue(ui->jackConnectPortsCheckBox));
1148 settings.setValue("jack/rt-mix", getCheckValue(ui->jackRtMixCheckBox));
1149 settings.setValue("jack/buffer-size", ui->jackBufferSizeLine->text());
1151 settings.setValue("alsa/device", ui->alsaDefaultDeviceLine->text());
1152 settings.setValue("alsa/capture", ui->alsaDefaultCaptureLine->text());
1153 settings.setValue("alsa/allow-resampler", getCheckValue(ui->alsaResamplerCheckBox));
1154 settings.setValue("alsa/mmap", getCheckValue(ui->alsaMmapCheckBox));
1156 settings.setValue("oss/device", ui->ossDefaultDeviceLine->text());
1157 settings.setValue("oss/capture", ui->ossDefaultCaptureLine->text());
1159 settings.setValue("solaris/device", ui->solarisDefaultDeviceLine->text());
1161 settings.setValue("wave/file", ui->waveOutputLine->text());
1162 settings.setValue("wave/bformat",
1163 ui->waveBFormatCheckBox->isChecked() ? QString{"true"} : QString{/*"false"*/}
1166 /* Remove empty keys
1167 * FIXME: Should only remove keys whose value matches the globally-specified value.
1169 allkeys = settings.allKeys();
1170 foreach(const QString &key, allkeys)
1172 QString str{settings.value(key).toString()};
1173 if(str == QString{})
1174 settings.remove(key);
1179 void MainWindow::enableApplyButton()
1181 if(!mNeedsSave)
1182 ui->applyButton->setEnabled(true);
1183 mNeedsSave = true;
1184 ui->closeCancelButton->setText(tr("Cancel"));
1188 void MainWindow::updateResamplerLabel(int num)
1190 ui->resamplerLabel->setText(resamplerList[num].name);
1191 enableApplyButton();
1195 void MainWindow::updatePeriodSizeEdit(int size)
1197 ui->periodSizeEdit->clear();
1198 if(size >= 64)
1199 ui->periodSizeEdit->insert(QString::number(size));
1200 enableApplyButton();
1203 void MainWindow::updatePeriodSizeSlider()
1205 int pos = ui->periodSizeEdit->text().toInt();
1206 if(pos >= 64)
1208 if(pos > 8192)
1209 pos = 8192;
1210 ui->periodSizeSlider->setSliderPosition(pos);
1212 enableApplyButton();
1215 void MainWindow::updatePeriodCountEdit(int count)
1217 ui->periodCountEdit->clear();
1218 if(count >= 2)
1219 ui->periodCountEdit->insert(QString::number(count));
1220 enableApplyButton();
1223 void MainWindow::updatePeriodCountSlider()
1225 int pos = ui->periodCountEdit->text().toInt();
1226 if(pos < 2)
1227 pos = 0;
1228 else if(pos > 16)
1229 pos = 16;
1230 ui->periodCountSlider->setSliderPosition(pos);
1231 enableApplyButton();
1235 void MainWindow::selectQuadDecoderFile()
1236 { selectDecoderFile(ui->decoderQuadLineEdit, "Select Quadraphonic Decoder");}
1237 void MainWindow::select51DecoderFile()
1238 { selectDecoderFile(ui->decoder51LineEdit, "Select 5.1 Surround Decoder");}
1239 void MainWindow::select61DecoderFile()
1240 { selectDecoderFile(ui->decoder61LineEdit, "Select 6.1 Surround Decoder");}
1241 void MainWindow::select71DecoderFile()
1242 { selectDecoderFile(ui->decoder71LineEdit, "Select 7.1 Surround Decoder");}
1243 void MainWindow::selectDecoderFile(QLineEdit *line, const char *caption)
1245 QString dir{line->text()};
1246 if(dir.isEmpty() || QDir::isRelativePath(dir))
1248 QStringList paths{getAllDataPaths("/openal/presets")};
1249 while(!paths.isEmpty())
1251 if(QDir{paths.last()}.exists())
1253 dir = paths.last();
1254 break;
1256 paths.removeLast();
1259 QString fname{QFileDialog::getOpenFileName(this, tr(caption),
1260 dir, tr("AmbDec Files (*.ambdec);;All Files (*.*)"))};
1261 if(!fname.isEmpty())
1263 line->setText(fname);
1264 enableApplyButton();
1269 void MainWindow::updateJackBufferSizeEdit(int size)
1271 ui->jackBufferSizeLine->clear();
1272 if(size > 0)
1273 ui->jackBufferSizeLine->insert(QString::number(1<<size));
1274 enableApplyButton();
1277 void MainWindow::updateJackBufferSizeSlider()
1279 int value{ui->jackBufferSizeLine->text().toInt()};
1280 auto pos = static_cast<int>(floor(log2(value) + 0.5));
1281 ui->jackBufferSizeSlider->setSliderPosition(pos);
1282 enableApplyButton();
1286 void MainWindow::updateHrtfModeLabel(int num)
1288 ui->hrtfmodeLabel->setText(hrtfModeList[num].name);
1289 enableApplyButton();
1293 void MainWindow::addHrtfFile()
1295 QString path{QFileDialog::getExistingDirectory(this, tr("Select HRTF Path"))};
1296 if(path.isEmpty() == false && !getAllDataPaths("/openal/hrtf").contains(path))
1298 ui->hrtfFileList->addItem(path);
1299 enableApplyButton();
1303 void MainWindow::removeHrtfFile()
1305 QList<QListWidgetItem*> selected{ui->hrtfFileList->selectedItems()};
1306 if(!selected.isEmpty())
1308 foreach(QListWidgetItem *item, selected)
1309 delete item;
1310 enableApplyButton();
1314 void MainWindow::updateHrtfRemoveButton()
1316 ui->hrtfRemoveButton->setEnabled(ui->hrtfFileList->selectedItems().size() != 0);
1319 void MainWindow::showEnabledBackendMenu(QPoint pt)
1321 QHash<QAction*,QString> actionMap;
1323 pt = ui->enabledBackendList->mapToGlobal(pt);
1325 QMenu ctxmenu;
1326 QAction *removeAction{ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove")};
1327 if(ui->enabledBackendList->selectedItems().size() == 0)
1328 removeAction->setEnabled(false);
1329 ctxmenu.addSeparator();
1330 for(size_t i = 0;backendList[i].backend_name[0];i++)
1332 QString backend{backendList[i].full_string};
1333 QAction *action{ctxmenu.addAction(QString("Add ")+backend)};
1334 actionMap[action] = backend;
1335 if(ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0 ||
1336 ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0)
1337 action->setEnabled(false);
1340 QAction *gotAction{ctxmenu.exec(pt)};
1341 if(gotAction == removeAction)
1343 QList<QListWidgetItem*> selected{ui->enabledBackendList->selectedItems()};
1344 foreach(QListWidgetItem *item, selected)
1345 delete item;
1346 enableApplyButton();
1348 else if(gotAction != nullptr)
1350 auto iter = actionMap.constFind(gotAction);
1351 if(iter != actionMap.cend())
1352 ui->enabledBackendList->addItem(iter.value());
1353 enableApplyButton();
1357 void MainWindow::showDisabledBackendMenu(QPoint pt)
1359 QHash<QAction*,QString> actionMap;
1361 pt = ui->disabledBackendList->mapToGlobal(pt);
1363 QMenu ctxmenu;
1364 QAction *removeAction{ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove")};
1365 if(ui->disabledBackendList->selectedItems().size() == 0)
1366 removeAction->setEnabled(false);
1367 ctxmenu.addSeparator();
1368 for(size_t i = 0;backendList[i].backend_name[0];i++)
1370 QString backend{backendList[i].full_string};
1371 QAction *action{ctxmenu.addAction(QString("Add ")+backend)};
1372 actionMap[action] = backend;
1373 if(ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0 ||
1374 ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0)
1375 action->setEnabled(false);
1378 QAction *gotAction{ctxmenu.exec(pt)};
1379 if(gotAction == removeAction)
1381 QList<QListWidgetItem*> selected{ui->disabledBackendList->selectedItems()};
1382 foreach(QListWidgetItem *item, selected)
1383 delete item;
1384 enableApplyButton();
1386 else if(gotAction != nullptr)
1388 auto iter = actionMap.constFind(gotAction);
1389 if(iter != actionMap.cend())
1390 ui->disabledBackendList->addItem(iter.value());
1391 enableApplyButton();
1395 void MainWindow::selectOSSPlayback()
1397 QString current{ui->ossDefaultDeviceLine->text()};
1398 if(current.isEmpty()) current = ui->ossDefaultDeviceLine->placeholderText();
1399 QString fname{QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current)};
1400 if(!fname.isEmpty())
1402 ui->ossDefaultDeviceLine->setText(fname);
1403 enableApplyButton();
1407 void MainWindow::selectOSSCapture()
1409 QString current{ui->ossDefaultCaptureLine->text()};
1410 if(current.isEmpty()) current = ui->ossDefaultCaptureLine->placeholderText();
1411 QString fname{QFileDialog::getOpenFileName(this, tr("Select Capture Device"), current)};
1412 if(!fname.isEmpty())
1414 ui->ossDefaultCaptureLine->setText(fname);
1415 enableApplyButton();
1419 void MainWindow::selectSolarisPlayback()
1421 QString current{ui->solarisDefaultDeviceLine->text()};
1422 if(current.isEmpty()) current = ui->solarisDefaultDeviceLine->placeholderText();
1423 QString fname{QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current)};
1424 if(!fname.isEmpty())
1426 ui->solarisDefaultDeviceLine->setText(fname);
1427 enableApplyButton();
1431 void MainWindow::selectWaveOutput()
1433 QString fname{QFileDialog::getSaveFileName(this, tr("Select Wave File Output"),
1434 ui->waveOutputLine->text(), tr("Wave Files (*.wav *.amb);;All Files (*.*)"))};
1435 if(!fname.isEmpty())
1437 ui->waveOutputLine->setText(fname);
1438 enableApplyButton();