12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427 |
- #include "config.h"
- #include "mainwindow.h"
- #include <array>
- #include <cmath>
- #include <iostream>
- #include <QFileDialog>
- #include <QMessageBox>
- #include <QCloseEvent>
- #include <QSettings>
- #include <QtGlobal>
- #include "ui_mainwindow.h"
- #include "verstr.h"
- #ifdef _WIN32
- #include <windows.h>
- #include <shlobj.h>
- #endif
- #include "almalloc.h"
- #include "alspan.h"
- namespace {
- struct BackendNamePair {
- /* NOLINTBEGIN(*-avoid-c-arrays) */
- char backend_name[16];
- char full_string[32];
- /* NOLINTEND(*-avoid-c-arrays) */
- };
- constexpr std::array backendList{
- #ifdef HAVE_PIPEWIRE
- BackendNamePair{ "pipewire", "PipeWire" },
- #endif
- #ifdef HAVE_PULSEAUDIO
- BackendNamePair{ "pulse", "PulseAudio" },
- #endif
- #ifdef HAVE_ALSA
- BackendNamePair{ "alsa", "ALSA" },
- #endif
- #ifdef HAVE_JACK
- BackendNamePair{ "jack", "JACK" },
- #endif
- #ifdef HAVE_COREAUDIO
- BackendNamePair{ "core", "CoreAudio" },
- #endif
- #ifdef HAVE_OSS
- BackendNamePair{ "oss", "OSS" },
- #endif
- #ifdef HAVE_SOLARIS
- BackendNamePair{ "solaris", "Solaris" },
- #endif
- #ifdef HAVE_SNDIO
- BackendNamePair{ "sndio", "SndIO" },
- #endif
- #ifdef HAVE_WASAPI
- BackendNamePair{ "wasapi", "WASAPI" },
- #endif
- #ifdef HAVE_DSOUND
- BackendNamePair{ "dsound", "DirectSound" },
- #endif
- #ifdef HAVE_WINMM
- BackendNamePair{ "winmm", "Windows Multimedia" },
- #endif
- #ifdef HAVE_PORTAUDIO
- BackendNamePair{ "port", "PortAudio" },
- #endif
- #ifdef HAVE_OPENSL
- BackendNamePair{ "opensl", "OpenSL" },
- #endif
- BackendNamePair{ "null", "Null Output" },
- #ifdef HAVE_WAVE
- BackendNamePair{ "wave", "Wave Writer" },
- #endif
- };
- struct NameValuePair {
- /* NOLINTBEGIN(*-avoid-c-arrays) */
- const char name[64];
- const char value[16];
- /* NOLINTEND(*-avoid-c-arrays) */
- };
- constexpr std::array speakerModeList{
- NameValuePair{ "Autodetect", "" },
- NameValuePair{ "Mono", "mono" },
- NameValuePair{ "Stereo", "stereo" },
- NameValuePair{ "Quadraphonic", "quad" },
- NameValuePair{ "5.1 Surround", "surround51" },
- NameValuePair{ "6.1 Surround", "surround61" },
- NameValuePair{ "7.1 Surround", "surround71" },
- NameValuePair{ "3D7.1 Surround", "surround3d71" },
- NameValuePair{ "Ambisonic, 1st Order", "ambi1" },
- NameValuePair{ "Ambisonic, 2nd Order", "ambi2" },
- NameValuePair{ "Ambisonic, 3rd Order", "ambi3" },
- };
- constexpr std::array sampleTypeList{
- NameValuePair{ "Autodetect", "" },
- NameValuePair{ "8-bit int", "int8" },
- NameValuePair{ "8-bit uint", "uint8" },
- NameValuePair{ "16-bit int", "int16" },
- NameValuePair{ "16-bit uint", "uint16" },
- NameValuePair{ "32-bit int", "int32" },
- NameValuePair{ "32-bit uint", "uint32" },
- NameValuePair{ "32-bit float", "float32" },
- };
- constexpr std::array resamplerList{
- NameValuePair{ "Point", "point" },
- NameValuePair{ "Linear", "linear" },
- NameValuePair{ "Cubic Spline", "spline" },
- NameValuePair{ "4-point Gaussian", "gaussian" },
- NameValuePair{ "Default (4-point Gaussian)", "" },
- NameValuePair{ "11th order Sinc (fast)", "fast_bsinc12" },
- NameValuePair{ "11th order Sinc", "bsinc12" },
- NameValuePair{ "23rd order Sinc (fast)", "fast_bsinc24" },
- NameValuePair{ "23rd order Sinc", "bsinc24" },
- };
- constexpr std::array stereoModeList{
- NameValuePair{ "Autodetect", "" },
- NameValuePair{ "Speakers", "speakers" },
- NameValuePair{ "Headphones", "headphones" },
- };
- constexpr std::array stereoEncList{
- NameValuePair{ "Default", "" },
- NameValuePair{ "Basic", "panpot" },
- NameValuePair{ "UHJ", "uhj" },
- NameValuePair{ "Binaural", "hrtf" },
- };
- constexpr std::array ambiFormatList{
- NameValuePair{ "Default", "" },
- NameValuePair{ "AmbiX (ACN, SN3D)", "ambix" },
- NameValuePair{ "Furse-Malham", "fuma" },
- NameValuePair{ "ACN, N3D", "acn+n3d" },
- NameValuePair{ "ACN, FuMa", "acn+fuma" },
- };
- constexpr std::array hrtfModeList{
- NameValuePair{ "1st Order Ambisonic", "ambi1" },
- NameValuePair{ "2nd Order Ambisonic", "ambi2" },
- NameValuePair{ "3rd Order Ambisonic", "ambi3" },
- NameValuePair{ "Default (Full)", "" },
- NameValuePair{ "Full", "full" },
- };
- QString getDefaultConfigName()
- {
- #ifdef Q_OS_WIN32
- const char *fname{"alsoft.ini"};
- auto get_appdata_path = []() noexcept -> QString
- {
- QString ret;
- WCHAR *buffer{};
- if(const HRESULT hr{SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_DONT_UNEXPAND,
- nullptr, &buffer)}; SUCCEEDED(hr))
- ret = QString::fromWCharArray(buffer);
- CoTaskMemFree(buffer);
- return ret;
- };
- QString base = get_appdata_path();
- #else
- const char *fname{"alsoft.conf"};
- QString base = qgetenv("XDG_CONFIG_HOME");
- if(base.isEmpty())
- {
- base = qgetenv("HOME");
- if(base.isEmpty() == false)
- base += "/.config";
- }
- #endif
- if(base.isEmpty() == false)
- return base +'/'+ fname;
- return fname;
- }
- QString getBaseDataPath()
- {
- #ifdef Q_OS_WIN32
- auto get_appdata_path = []() noexcept -> QString
- {
- QString ret;
- WCHAR *buffer{};
- if(const HRESULT hr{SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_DONT_UNEXPAND,
- nullptr, &buffer)}; SUCCEEDED(hr))
- ret = QString::fromWCharArray(buffer);
- CoTaskMemFree(buffer);
- return ret;
- };
- QString base = get_appdata_path();
- #else
- QString base = qgetenv("XDG_DATA_HOME");
- if(base.isEmpty())
- {
- base = qgetenv("HOME");
- if(!base.isEmpty())
- base += "/.local/share";
- }
- #endif
- return base;
- }
- QStringList getAllDataPaths(const QString &append)
- {
- QStringList list;
- list.append(getBaseDataPath());
- #ifdef Q_OS_WIN32
- // TODO: Common AppData path
- #else
- QString paths = qgetenv("XDG_DATA_DIRS");
- if(paths.isEmpty())
- paths = "/usr/local/share/:/usr/share/";
- #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
- list += paths.split(QChar(':'), Qt::SkipEmptyParts);
- #else
- list += paths.split(QChar(':'), QString::SkipEmptyParts);
- #endif
- #endif
- QStringList::iterator iter = list.begin();
- while(iter != list.end())
- {
- if(iter->isEmpty())
- iter = list.erase(iter);
- else
- {
- iter->append(append);
- iter++;
- }
- }
- return list;
- }
- QString getValueFromName(const al::span<const NameValuePair> list, const QString &str)
- {
- for(size_t i{0};i < list.size();++i)
- {
- if(str == std::data(list[i].name))
- return std::data(list[i].value);
- }
- return QString{};
- }
- QString getNameFromValue(const al::span<const NameValuePair> list, const QString &str)
- {
- for(size_t i{0};i < list.size();++i)
- {
- if(str == std::data(list[i].value))
- return std::data(list[i].name);
- }
- return QString{};
- }
- Qt::CheckState getCheckState(const QVariant &var)
- {
- if(var.isNull())
- return Qt::PartiallyChecked;
- if(var.toBool())
- return Qt::Checked;
- return Qt::Unchecked;
- }
- QString getCheckValue(const QCheckBox *checkbox)
- {
- const Qt::CheckState state{checkbox->checkState()};
- if(state == Qt::Checked)
- return QStringLiteral("true");
- if(state == Qt::Unchecked)
- return QStringLiteral("false");
- return QString{};
- }
- }
- MainWindow::MainWindow(QWidget *parent) : QMainWindow{parent}
- , ui{std::make_unique<Ui::MainWindow>()}
- {
- ui->setupUi(this);
- for(auto &item : speakerModeList)
- ui->channelConfigCombo->addItem(std::data(item.name));
- ui->channelConfigCombo->adjustSize();
- for(auto &item : sampleTypeList)
- ui->sampleFormatCombo->addItem(std::data(item.name));
- ui->sampleFormatCombo->adjustSize();
- for(auto &item : stereoModeList)
- ui->stereoModeCombo->addItem(std::data(item.name));
- ui->stereoModeCombo->adjustSize();
- for(auto &item : stereoEncList)
- ui->stereoEncodingComboBox->addItem(std::data(item.name));
- ui->stereoEncodingComboBox->adjustSize();
- for(auto &item : ambiFormatList)
- ui->ambiFormatComboBox->addItem(std::data(item.name));
- ui->ambiFormatComboBox->adjustSize();
- ui->resamplerSlider->setRange(0, resamplerList.size()-1);
- ui->hrtfmodeSlider->setRange(0, hrtfModeList.size()-1);
- #if !defined(HAVE_NEON) && !defined(HAVE_SSE)
- ui->cpuExtDisabledLabel->move(ui->cpuExtDisabledLabel->x(), ui->cpuExtDisabledLabel->y() - 60);
- #else
- ui->cpuExtDisabledLabel->setVisible(false);
- #endif
- #ifndef HAVE_NEON
- #ifndef HAVE_SSE4_1
- #ifndef HAVE_SSE3
- #ifndef HAVE_SSE2
- #ifndef HAVE_SSE
- ui->enableSSECheckBox->setVisible(false);
- #endif /* !SSE */
- ui->enableSSE2CheckBox->setVisible(false);
- #endif /* !SSE2 */
- ui->enableSSE3CheckBox->setVisible(false);
- #endif /* !SSE3 */
- ui->enableSSE41CheckBox->setVisible(false);
- #endif /* !SSE4.1 */
- ui->enableNeonCheckBox->setVisible(false);
- #else /* !Neon */
- #ifndef HAVE_SSE4_1
- #ifndef HAVE_SSE3
- #ifndef HAVE_SSE2
- #ifndef HAVE_SSE
- ui->enableNeonCheckBox->move(ui->enableNeonCheckBox->x(), ui->enableNeonCheckBox->y() - 30);
- ui->enableSSECheckBox->setVisible(false);
- #endif /* !SSE */
- ui->enableSSE2CheckBox->setVisible(false);
- #endif /* !SSE2 */
- ui->enableSSE3CheckBox->setVisible(false);
- #endif /* !SSE3 */
- ui->enableSSE41CheckBox->setVisible(false);
- #endif /* !SSE4.1 */
- #endif
- #ifndef ALSOFT_EAX
- ui->enableEaxCheck->setChecked(Qt::Unchecked);
- ui->enableEaxCheck->setEnabled(false);
- ui->enableEaxCheck->setVisible(false);
- #endif
- mPeriodSizeValidator = std::make_unique<QIntValidator>(64, 8192, this);
- ui->periodSizeEdit->setValidator(mPeriodSizeValidator.get());
- mPeriodCountValidator = std::make_unique<QIntValidator>(2, 16, this);
- ui->periodCountEdit->setValidator(mPeriodCountValidator.get());
- mSourceCountValidator = std::make_unique<QIntValidator>(0, 4096, this);
- ui->srcCountLineEdit->setValidator(mSourceCountValidator.get());
- mEffectSlotValidator = std::make_unique<QIntValidator>(0, 64, this);
- ui->effectSlotLineEdit->setValidator(mEffectSlotValidator.get());
- mSourceSendValidator = std::make_unique<QIntValidator>(0, 16, this);
- ui->srcSendLineEdit->setValidator(mSourceSendValidator.get());
- mSampleRateValidator = std::make_unique<QIntValidator>(8000, 192000, this);
- ui->sampleRateCombo->lineEdit()->setValidator(mSampleRateValidator.get());
- mJackBufferValidator = std::make_unique<QIntValidator>(0, 8192, this);
- ui->jackBufferSizeLine->setValidator(mJackBufferValidator.get());
- connect(ui->actionLoad, &QAction::triggered, this, &MainWindow::loadConfigFromFile);
- connect(ui->actionSave_As, &QAction::triggered, this, &MainWindow::saveConfigAsFile);
- connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::showAboutPage);
- connect(ui->closeCancelButton, &QPushButton::clicked, this, &MainWindow::cancelCloseAction);
- connect(ui->applyButton, &QPushButton::clicked, this, &MainWindow::saveCurrentConfig);
- auto qcb_cicint = static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged);
- connect(ui->channelConfigCombo, qcb_cicint, this, &MainWindow::enableApplyButton);
- connect(ui->sampleFormatCombo, qcb_cicint, this, &MainWindow::enableApplyButton);
- connect(ui->stereoModeCombo, qcb_cicint, this, &MainWindow::enableApplyButton);
- connect(ui->sampleRateCombo, qcb_cicint, this, &MainWindow::enableApplyButton);
- connect(ui->sampleRateCombo, &QComboBox::editTextChanged, this, &MainWindow::enableApplyButton);
- connect(ui->resamplerSlider, &QSlider::valueChanged, this, &MainWindow::updateResamplerLabel);
- connect(ui->periodSizeSlider, &QSlider::valueChanged, this, &MainWindow::updatePeriodSizeEdit);
- connect(ui->periodSizeEdit, &QLineEdit::editingFinished, this, &MainWindow::updatePeriodSizeSlider);
- connect(ui->periodCountSlider, &QSlider::valueChanged, this, &MainWindow::updatePeriodCountEdit);
- connect(ui->periodCountEdit, &QLineEdit::editingFinished, this, &MainWindow::updatePeriodCountSlider);
- connect(ui->stereoEncodingComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
- connect(ui->ambiFormatComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
- connect(ui->outputLimiterCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->outputDitherCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->decoderHQModeCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->decoderDistCompCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->decoderNFEffectsCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- auto qdsb_vcd = static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged);
- connect(ui->decoderSpeakerDistSpinBox, qdsb_vcd, this, &MainWindow::enableApplyButton);
- connect(ui->decoderQuadLineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
- connect(ui->decoderQuadButton, &QPushButton::clicked, this, &MainWindow::selectQuadDecoderFile);
- connect(ui->decoder51LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
- connect(ui->decoder51Button, &QPushButton::clicked, this, &MainWindow::select51DecoderFile);
- connect(ui->decoder61LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
- connect(ui->decoder61Button, &QPushButton::clicked, this, &MainWindow::select61DecoderFile);
- connect(ui->decoder71LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
- connect(ui->decoder71Button, &QPushButton::clicked, this, &MainWindow::select71DecoderFile);
- connect(ui->decoder3D71LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
- connect(ui->decoder3D71Button, &QPushButton::clicked, this, &MainWindow::select3D71DecoderFile);
- connect(ui->preferredHrtfComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
- connect(ui->hrtfmodeSlider, &QSlider::valueChanged, this, &MainWindow::updateHrtfModeLabel);
- connect(ui->hrtfAddButton, &QPushButton::clicked, this, &MainWindow::addHrtfFile);
- connect(ui->hrtfRemoveButton, &QPushButton::clicked, this, &MainWindow::removeHrtfFile);
- connect(ui->hrtfFileList, &QListWidget::itemSelectionChanged, this, &MainWindow::updateHrtfRemoveButton);
- connect(ui->defaultHrtfPathsCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->srcCountLineEdit, &QLineEdit::editingFinished, this, &MainWindow::enableApplyButton);
- connect(ui->srcSendLineEdit, &QLineEdit::editingFinished, this, &MainWindow::enableApplyButton);
- connect(ui->effectSlotLineEdit, &QLineEdit::editingFinished, this, &MainWindow::enableApplyButton);
- connect(ui->enableSSECheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->enableSSE2CheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->enableSSE3CheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->enableSSE41CheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->enableNeonCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- ui->enabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(ui->enabledBackendList, &QListWidget::customContextMenuRequested, this, &MainWindow::showEnabledBackendMenu);
- ui->disabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(ui->disabledBackendList, &QListWidget::customContextMenuRequested, this, &MainWindow::showDisabledBackendMenu);
- connect(ui->backendCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->defaultReverbComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
- connect(ui->enableEaxReverbCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->enableStdReverbCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->enableAutowahCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->enableChorusCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->enableCompressorCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->enableDistortionCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->enableEchoCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->enableEqualizerCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->enableFlangerCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->enableFrequencyShifterCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->enableModulatorCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->enableDedicatedCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->enablePitchShifterCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->enableVocalMorpherCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->enableEaxCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->pulseAutospawnCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->pulseAllowMovesCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->pulseFixRateCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->pulseAdjLatencyCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->pwireAssumeAudioCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->pwireRtMixCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->wasapiResamplerCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->jackAutospawnCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->jackConnectPortsCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->jackRtMixCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->jackBufferSizeSlider, &QSlider::valueChanged, this, &MainWindow::updateJackBufferSizeEdit);
- connect(ui->jackBufferSizeLine, &QLineEdit::editingFinished, this, &MainWindow::updateJackBufferSizeSlider);
- connect(ui->alsaDefaultDeviceLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
- connect(ui->alsaDefaultCaptureLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
- connect(ui->alsaResamplerCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->alsaMmapCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- connect(ui->ossDefaultDeviceLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
- connect(ui->ossPlaybackPushButton, &QPushButton::clicked, this, &MainWindow::selectOSSPlayback);
- connect(ui->ossDefaultCaptureLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
- connect(ui->ossCapturePushButton, &QPushButton::clicked, this, &MainWindow::selectOSSCapture);
- connect(ui->solarisDefaultDeviceLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
- connect(ui->solarisPlaybackPushButton, &QPushButton::clicked, this, &MainWindow::selectSolarisPlayback);
- connect(ui->waveOutputLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
- connect(ui->waveOutputButton, &QPushButton::clicked, this, &MainWindow::selectWaveOutput);
- connect(ui->waveBFormatCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
- ui->backendListWidget->setCurrentRow(0);
- ui->tabWidget->setCurrentIndex(0);
- for(int i = 1;i < ui->backendListWidget->count();i++)
- ui->backendListWidget->setRowHidden(i, true);
- for(size_t i{0};i < backendList.size();++i)
- {
- QList<QListWidgetItem*> items = ui->backendListWidget->findItems(
- std::data(backendList[i].full_string), Qt::MatchFixedString);
- Q_FOREACH(QListWidgetItem *item, items)
- item->setHidden(false);
- }
- loadConfig(getDefaultConfigName());
- }
- MainWindow::~MainWindow() = default;
- void MainWindow::closeEvent(QCloseEvent *event)
- {
- if(!mNeedsSave)
- event->accept();
- else
- {
- QMessageBox::StandardButton btn = QMessageBox::warning(this,
- tr("Apply changes?"), tr("Save changes before quitting?"),
- QMessageBox::Save | QMessageBox::No | QMessageBox::Cancel);
- if(btn == QMessageBox::Save)
- saveCurrentConfig();
- if(btn == QMessageBox::Cancel)
- event->ignore();
- else
- event->accept();
- }
- }
- void MainWindow::cancelCloseAction()
- {
- mNeedsSave = false;
- close();
- }
- void MainWindow::showAboutPage()
- {
- QMessageBox::information(this, tr("About"),
- tr("OpenAL Soft Configuration Utility.\nBuilt for OpenAL Soft library version ") +
- GetVersionString());
- }
- QStringList MainWindow::collectHrtfs()
- {
- QStringList ret;
- QStringList processed;
- for(int i = 0;i < ui->hrtfFileList->count();i++)
- {
- QDir dir(ui->hrtfFileList->item(i)->text());
- QStringList fnames = dir.entryList(QDir::Files | QDir::Readable, QDir::Name);
- Q_FOREACH(const QString &fname, fnames)
- {
- if(!fname.endsWith(QStringLiteral(".mhr"), Qt::CaseInsensitive))
- continue;
- QString fullname{dir.absoluteFilePath(fname)};
- if(processed.contains(fullname))
- continue;
- processed.push_back(fullname);
- QString name{fname.left(fname.length()-4)};
- if(!ret.contains(name))
- ret.push_back(name);
- else
- {
- size_t i{2};
- do {
- QString s = name+" #"+QString::number(i);
- if(!ret.contains(s))
- {
- ret.push_back(s);
- break;
- }
- ++i;
- } while(true);
- }
- }
- }
- if(ui->defaultHrtfPathsCheckBox->isChecked())
- {
- QStringList paths = getAllDataPaths(QStringLiteral("/openal/hrtf"));
- Q_FOREACH(const QString &name, paths)
- {
- QDir dir{name};
- QStringList fnames{dir.entryList(QDir::Files | QDir::Readable, QDir::Name)};
- Q_FOREACH(const QString &fname, fnames)
- {
- if(!fname.endsWith(QStringLiteral(".mhr"), Qt::CaseInsensitive))
- continue;
- QString fullname{dir.absoluteFilePath(fname)};
- if(processed.contains(fullname))
- continue;
- processed.push_back(fullname);
- QString name{fname.left(fname.length()-4)};
- if(!ret.contains(name))
- ret.push_back(name);
- else
- {
- size_t i{2};
- do {
- QString s{name+" #"+QString::number(i)};
- if(!ret.contains(s))
- {
- ret.push_back(s);
- break;
- }
- ++i;
- } while(true);
- }
- }
- }
- #ifdef ALSOFT_EMBED_HRTF_DATA
- ret.push_back(QStringLiteral("Built-In HRTF"));
- #endif
- }
- return ret;
- }
- void MainWindow::loadConfigFromFile()
- {
- QString fname = QFileDialog::getOpenFileName(this, tr("Select Files"));
- if(fname.isEmpty() == false)
- loadConfig(fname);
- }
- void MainWindow::loadConfig(const QString &fname)
- {
- QSettings settings{fname, QSettings::IniFormat};
- QString sampletype{settings.value(QStringLiteral("sample-type")).toString()};
- ui->sampleFormatCombo->setCurrentIndex(0);
- if(sampletype.isEmpty() == false)
- {
- QString str{getNameFromValue(sampleTypeList, sampletype)};
- if(!str.isEmpty())
- {
- const int j{ui->sampleFormatCombo->findText(str)};
- if(j > 0) ui->sampleFormatCombo->setCurrentIndex(j);
- }
- }
- QString channelconfig{settings.value(QStringLiteral("channels")).toString()};
- ui->channelConfigCombo->setCurrentIndex(0);
- if(channelconfig.isEmpty() == false)
- {
- if(channelconfig == QStringLiteral("surround51rear"))
- channelconfig = QStringLiteral("surround51");
- QString str{getNameFromValue(speakerModeList, channelconfig)};
- if(!str.isEmpty())
- {
- const int j{ui->channelConfigCombo->findText(str)};
- if(j > 0) ui->channelConfigCombo->setCurrentIndex(j);
- }
- }
- QString srate{settings.value(QStringLiteral("frequency")).toString()};
- if(srate.isEmpty())
- ui->sampleRateCombo->setCurrentIndex(0);
- else
- {
- ui->sampleRateCombo->lineEdit()->clear();
- ui->sampleRateCombo->lineEdit()->insert(srate);
- }
- ui->srcCountLineEdit->clear();
- ui->srcCountLineEdit->insert(settings.value(QStringLiteral("sources")).toString());
- ui->effectSlotLineEdit->clear();
- ui->effectSlotLineEdit->insert(settings.value(QStringLiteral("slots")).toString());
- ui->srcSendLineEdit->clear();
- ui->srcSendLineEdit->insert(settings.value(QStringLiteral("sends")).toString());
- QString resampler = settings.value(QStringLiteral("resampler")).toString().trimmed();
- ui->resamplerSlider->setValue(2);
- ui->resamplerLabel->setText(std::data(resamplerList[2].name));
- /* "Cubic" is an alias for the 4-point gaussian resampler. The "sinc4" and
- * "sinc8" resamplers are unsupported, use "gaussian" as a fallback.
- */
- if(resampler == QLatin1String{"cubic"} || resampler == QLatin1String{"sinc4"}
- || resampler == QLatin1String{"sinc8"})
- resampler = QStringLiteral("gaussian");
- /* The "bsinc" resampler name is an alias for "bsinc12". */
- else if(resampler == QLatin1String{"bsinc"})
- resampler = QStringLiteral("bsinc12");
- for(int i = 0;resamplerList[i].name[0];i++)
- {
- if(resampler == std::data(resamplerList[i].value))
- {
- ui->resamplerSlider->setValue(i);
- ui->resamplerLabel->setText(std::data(resamplerList[i].name));
- break;
- }
- }
- QString stereomode{settings.value(QStringLiteral("stereo-mode")).toString().trimmed()};
- ui->stereoModeCombo->setCurrentIndex(0);
- if(stereomode.isEmpty() == false)
- {
- QString str{getNameFromValue(stereoModeList, stereomode)};
- if(!str.isEmpty())
- {
- const int j{ui->stereoModeCombo->findText(str)};
- if(j > 0) ui->stereoModeCombo->setCurrentIndex(j);
- }
- }
- int periodsize{settings.value("period_size").toInt()};
- ui->periodSizeEdit->clear();
- if(periodsize >= 64)
- {
- ui->periodSizeEdit->insert(QString::number(periodsize));
- updatePeriodSizeSlider();
- }
- int periodcount{settings.value("periods").toInt()};
- ui->periodCountEdit->clear();
- if(periodcount >= 2)
- {
- ui->periodCountEdit->insert(QString::number(periodcount));
- updatePeriodCountSlider();
- }
- ui->outputLimiterCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("output-limiter"))));
- ui->outputDitherCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("dither"))));
- QString stereopan{settings.value(QStringLiteral("stereo-encoding")).toString()};
- ui->stereoEncodingComboBox->setCurrentIndex(0);
- if(stereopan.isEmpty() == false)
- {
- QString str{getNameFromValue(stereoEncList, stereopan)};
- if(!str.isEmpty())
- {
- const int j{ui->stereoEncodingComboBox->findText(str)};
- if(j > 0) ui->stereoEncodingComboBox->setCurrentIndex(j);
- }
- }
- QString ambiformat{settings.value(QStringLiteral("ambi-format")).toString()};
- ui->ambiFormatComboBox->setCurrentIndex(0);
- if(ambiformat.isEmpty() == false)
- {
- QString str{getNameFromValue(ambiFormatList, ambiformat)};
- if(!str.isEmpty())
- {
- const int j{ui->ambiFormatComboBox->findText(str)};
- if(j > 0) ui->ambiFormatComboBox->setCurrentIndex(j);
- }
- }
- ui->decoderHQModeCheckBox->setChecked(getCheckState(settings.value(QStringLiteral("decoder/hq-mode"))));
- ui->decoderDistCompCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("decoder/distance-comp"))));
- ui->decoderNFEffectsCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("decoder/nfc"))));
- double speakerdist{settings.value(QStringLiteral("decoder/speaker-dist"), 1.0).toDouble()};
- ui->decoderSpeakerDistSpinBox->setValue(speakerdist);
- ui->decoderQuadLineEdit->setText(settings.value(QStringLiteral("decoder/quad")).toString());
- ui->decoder51LineEdit->setText(settings.value(QStringLiteral("decoder/surround51")).toString());
- ui->decoder61LineEdit->setText(settings.value(QStringLiteral("decoder/surround61")).toString());
- ui->decoder71LineEdit->setText(settings.value(QStringLiteral("decoder/surround71")).toString());
- ui->decoder3D71LineEdit->setText(settings.value(QStringLiteral("decoder/surround3d71")).toString());
- QStringList disabledCpuExts{settings.value(QStringLiteral("disable-cpu-exts")).toStringList()};
- if(disabledCpuExts.size() == 1)
- disabledCpuExts = disabledCpuExts[0].split(QChar(','));
- for(QString &name : disabledCpuExts)
- name = name.trimmed();
- ui->enableSSECheckBox->setChecked(!disabledCpuExts.contains(QStringLiteral("sse"), Qt::CaseInsensitive));
- ui->enableSSE2CheckBox->setChecked(!disabledCpuExts.contains(QStringLiteral("sse2"), Qt::CaseInsensitive));
- ui->enableSSE3CheckBox->setChecked(!disabledCpuExts.contains(QStringLiteral("sse3"), Qt::CaseInsensitive));
- ui->enableSSE41CheckBox->setChecked(!disabledCpuExts.contains(QStringLiteral("sse4.1"), Qt::CaseInsensitive));
- ui->enableNeonCheckBox->setChecked(!disabledCpuExts.contains(QStringLiteral("neon"), Qt::CaseInsensitive));
- QString hrtfmode{settings.value(QStringLiteral("hrtf-mode")).toString().trimmed()};
- ui->hrtfmodeSlider->setValue(2);
- ui->hrtfmodeLabel->setText(std::data(hrtfModeList[3].name));
- /* The "basic" mode name is no longer supported. Use "ambi2" instead. */
- if(hrtfmode == QLatin1String{"basic"})
- hrtfmode = QStringLiteral("ambi2");
- for(size_t i{0};i < hrtfModeList.size();++i)
- {
- if(hrtfmode == std::data(hrtfModeList[i].value))
- {
- ui->hrtfmodeSlider->setValue(static_cast<int>(i));
- ui->hrtfmodeLabel->setText(std::data(hrtfModeList[i].name));
- break;
- }
- }
- QStringList hrtf_paths{settings.value(QStringLiteral("hrtf-paths")).toStringList()};
- if(hrtf_paths.size() == 1)
- hrtf_paths = hrtf_paths[0].split(QChar(','));
- for(QString &name : hrtf_paths)
- name = name.trimmed();
- if(!hrtf_paths.empty() && !hrtf_paths.back().isEmpty())
- ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Unchecked);
- else
- {
- hrtf_paths.removeAll(QString());
- ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Checked);
- }
- hrtf_paths.removeDuplicates();
- ui->hrtfFileList->clear();
- ui->hrtfFileList->addItems(hrtf_paths);
- updateHrtfRemoveButton();
- ui->preferredHrtfComboBox->clear();
- ui->preferredHrtfComboBox->addItem(QStringLiteral("- Any -"));
- if(ui->defaultHrtfPathsCheckBox->isChecked())
- {
- QStringList hrtfs{collectHrtfs()};
- Q_FOREACH(const QString &name, hrtfs)
- ui->preferredHrtfComboBox->addItem(name);
- }
- QString defaulthrtf{settings.value(QStringLiteral("default-hrtf")).toString()};
- ui->preferredHrtfComboBox->setCurrentIndex(0);
- if(defaulthrtf.isEmpty() == false)
- {
- int i{ui->preferredHrtfComboBox->findText(defaulthrtf)};
- if(i > 0)
- ui->preferredHrtfComboBox->setCurrentIndex(i);
- else
- {
- i = ui->preferredHrtfComboBox->count();
- ui->preferredHrtfComboBox->addItem(defaulthrtf);
- ui->preferredHrtfComboBox->setCurrentIndex(i);
- }
- }
- ui->preferredHrtfComboBox->adjustSize();
- ui->enabledBackendList->clear();
- ui->disabledBackendList->clear();
- QStringList drivers{settings.value(QStringLiteral("drivers")).toStringList()};
- if(drivers.empty())
- ui->backendCheckBox->setChecked(true);
- else
- {
- if(drivers.size() == 1)
- drivers = drivers[0].split(QChar(','));
- for(QString &name : drivers)
- {
- name = name.trimmed();
- /* Convert "mmdevapi" references to "wasapi" for backwards
- * compatibility.
- */
- if(name == QLatin1String{"-mmdevapi"})
- name = QStringLiteral("-wasapi");
- else if(name == QLatin1String{"mmdevapi"})
- name = QStringLiteral("wasapi");
- }
- bool lastWasEmpty{false};
- Q_FOREACH(const QString &backend, drivers)
- {
- lastWasEmpty = backend.isEmpty();
- if(lastWasEmpty) continue;
- if(!backend.startsWith(QChar('-')))
- {
- for(size_t j{0};j < backendList.size();++j)
- {
- if(backend == std::data(backendList[j].backend_name))
- {
- ui->enabledBackendList->addItem(std::data(backendList[j].full_string));
- break;
- }
- }
- }
- else if(backend.size() > 1)
- {
- QStringRef backendref{backend.rightRef(backend.size()-1)};
- for(size_t j{0};j < backendList.size();++j)
- {
- if(backendref == std::data(backendList[j].backend_name))
- {
- ui->disabledBackendList->addItem(std::data(backendList[j].full_string));
- break;
- }
- }
- }
- }
- ui->backendCheckBox->setChecked(lastWasEmpty);
- }
- QString defaultreverb{settings.value(QStringLiteral("default-reverb")).toString().toLower()};
- ui->defaultReverbComboBox->setCurrentIndex(0);
- if(defaultreverb.isEmpty() == false)
- {
- for(int i = 0;i < ui->defaultReverbComboBox->count();i++)
- {
- if(defaultreverb.compare(ui->defaultReverbComboBox->itemText(i).toLower()) == 0)
- {
- ui->defaultReverbComboBox->setCurrentIndex(i);
- break;
- }
- }
- }
- QStringList excludefx{settings.value(QStringLiteral("excludefx")).toStringList()};
- if(excludefx.size() == 1)
- excludefx = excludefx[0].split(QChar(','));
- for(QString &name : excludefx)
- name = name.trimmed();
- ui->enableEaxReverbCheck->setChecked(!excludefx.contains(QStringLiteral("eaxreverb"), Qt::CaseInsensitive));
- ui->enableStdReverbCheck->setChecked(!excludefx.contains(QStringLiteral("reverb"), Qt::CaseInsensitive));
- ui->enableAutowahCheck->setChecked(!excludefx.contains(QStringLiteral("autowah"), Qt::CaseInsensitive));
- ui->enableChorusCheck->setChecked(!excludefx.contains(QStringLiteral("chorus"), Qt::CaseInsensitive));
- ui->enableCompressorCheck->setChecked(!excludefx.contains(QStringLiteral("compressor"), Qt::CaseInsensitive));
- ui->enableDistortionCheck->setChecked(!excludefx.contains(QStringLiteral("distortion"), Qt::CaseInsensitive));
- ui->enableEchoCheck->setChecked(!excludefx.contains(QStringLiteral("echo"), Qt::CaseInsensitive));
- ui->enableEqualizerCheck->setChecked(!excludefx.contains(QStringLiteral("equalizer"), Qt::CaseInsensitive));
- ui->enableFlangerCheck->setChecked(!excludefx.contains(QStringLiteral("flanger"), Qt::CaseInsensitive));
- ui->enableFrequencyShifterCheck->setChecked(!excludefx.contains(QStringLiteral("fshifter"), Qt::CaseInsensitive));
- ui->enableModulatorCheck->setChecked(!excludefx.contains(QStringLiteral("modulator"), Qt::CaseInsensitive));
- ui->enableDedicatedCheck->setChecked(!excludefx.contains(QStringLiteral("dedicated"), Qt::CaseInsensitive));
- ui->enablePitchShifterCheck->setChecked(!excludefx.contains(QStringLiteral("pshifter"), Qt::CaseInsensitive));
- ui->enableVocalMorpherCheck->setChecked(!excludefx.contains(QStringLiteral("vmorpher"), Qt::CaseInsensitive));
- if(ui->enableEaxCheck->isEnabled())
- ui->enableEaxCheck->setChecked(getCheckState(settings.value(QStringLiteral("eax/enable"))) != Qt::Unchecked);
- ui->pulseAutospawnCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("pulse/spawn-server"))));
- ui->pulseAllowMovesCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("pulse/allow-moves"))));
- ui->pulseFixRateCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("pulse/fix-rate"))));
- ui->pulseAdjLatencyCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("pulse/adjust-latency"))));
- ui->pwireAssumeAudioCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("pipewire/assume-audio"))));
- ui->pwireRtMixCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("pipewire/rt-mix"))));
- ui->wasapiResamplerCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("wasapi/allow-resampler"))));
- ui->jackAutospawnCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("jack/spawn-server"))));
- ui->jackConnectPortsCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("jack/connect-ports"))));
- ui->jackRtMixCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("jack/rt-mix"))));
- ui->jackBufferSizeLine->setText(settings.value(QStringLiteral("jack/buffer-size"), QString()).toString());
- updateJackBufferSizeSlider();
- ui->alsaDefaultDeviceLine->setText(settings.value(QStringLiteral("alsa/device"), QString()).toString());
- ui->alsaDefaultCaptureLine->setText(settings.value(QStringLiteral("alsa/capture"), QString()).toString());
- ui->alsaResamplerCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("alsa/allow-resampler"))));
- ui->alsaMmapCheckBox->setCheckState(getCheckState(settings.value(QStringLiteral("alsa/mmap"))));
- ui->ossDefaultDeviceLine->setText(settings.value(QStringLiteral("oss/device"), QString()).toString());
- ui->ossDefaultCaptureLine->setText(settings.value(QStringLiteral("oss/capture"), QString()).toString());
- ui->solarisDefaultDeviceLine->setText(settings.value(QStringLiteral("solaris/device"), QString()).toString());
- ui->waveOutputLine->setText(settings.value(QStringLiteral("wave/file"), QString()).toString());
- ui->waveBFormatCheckBox->setChecked(settings.value(QStringLiteral("wave/bformat"), false).toBool());
- ui->applyButton->setEnabled(false);
- ui->closeCancelButton->setText(tr("Close"));
- mNeedsSave = false;
- }
- void MainWindow::saveCurrentConfig()
- {
- saveConfig(getDefaultConfigName());
- ui->applyButton->setEnabled(false);
- ui->closeCancelButton->setText(tr("Close"));
- mNeedsSave = false;
- QMessageBox::information(this, tr("Information"),
- tr("Applications using OpenAL need to be restarted for changes to take effect."));
- }
- void MainWindow::saveConfigAsFile()
- {
- QString fname{QFileDialog::getOpenFileName(this, tr("Select Files"))};
- if(fname.isEmpty() == false)
- {
- saveConfig(fname);
- ui->applyButton->setEnabled(false);
- mNeedsSave = false;
- }
- }
- void MainWindow::saveConfig(const QString &fname) const
- {
- QSettings settings{fname, QSettings::IniFormat};
- /* HACK: Compound any stringlist values into a comma-separated string. */
- QStringList allkeys{settings.allKeys()};
- Q_FOREACH(const QString &key, allkeys)
- {
- QStringList vals{settings.value(key).toStringList()};
- if(vals.size() > 1)
- settings.setValue(key, vals.join(QChar(',')));
- }
- settings.setValue(QStringLiteral("sample-type"), getValueFromName(sampleTypeList, ui->sampleFormatCombo->currentText()));
- settings.setValue(QStringLiteral("channels"), getValueFromName(speakerModeList, ui->channelConfigCombo->currentText()));
- uint rate{ui->sampleRateCombo->currentText().toUInt()};
- if(rate <= 0)
- settings.setValue(QStringLiteral("frequency"), QString{});
- else
- settings.setValue(QStringLiteral("frequency"), rate);
- settings.setValue(QStringLiteral("period_size"), ui->periodSizeEdit->text());
- settings.setValue(QStringLiteral("periods"), ui->periodCountEdit->text());
- settings.setValue(QStringLiteral("sources"), ui->srcCountLineEdit->text());
- settings.setValue(QStringLiteral("slots"), ui->effectSlotLineEdit->text());
- settings.setValue(QStringLiteral("resampler"), std::data(resamplerList[ui->resamplerSlider->value()].value));
- settings.setValue(QStringLiteral("stereo-mode"), getValueFromName(stereoModeList, ui->stereoModeCombo->currentText()));
- settings.setValue(QStringLiteral("stereo-encoding"), getValueFromName(stereoEncList, ui->stereoEncodingComboBox->currentText()));
- settings.setValue(QStringLiteral("ambi-format"), getValueFromName(ambiFormatList, ui->ambiFormatComboBox->currentText()));
- settings.setValue(QStringLiteral("output-limiter"), getCheckValue(ui->outputLimiterCheckBox));
- settings.setValue(QStringLiteral("dither"), getCheckValue(ui->outputDitherCheckBox));
- settings.setValue(QStringLiteral("decoder/hq-mode"), getCheckValue(ui->decoderHQModeCheckBox));
- settings.setValue(QStringLiteral("decoder/distance-comp"), getCheckValue(ui->decoderDistCompCheckBox));
- settings.setValue(QStringLiteral("decoder/nfc"), getCheckValue(ui->decoderNFEffectsCheckBox));
- double speakerdist{ui->decoderSpeakerDistSpinBox->value()};
- settings.setValue(QStringLiteral("decoder/speaker-dist"),
- (speakerdist != 1.0) ? QString::number(speakerdist) : QString{}
- );
- settings.setValue(QStringLiteral("decoder/quad"), ui->decoderQuadLineEdit->text());
- settings.setValue(QStringLiteral("decoder/surround51"), ui->decoder51LineEdit->text());
- settings.setValue(QStringLiteral("decoder/surround61"), ui->decoder61LineEdit->text());
- settings.setValue(QStringLiteral("decoder/surround71"), ui->decoder71LineEdit->text());
- settings.setValue(QStringLiteral("decoder/surround3d71"), ui->decoder3D71LineEdit->text());
- QStringList strlist;
- if(!ui->enableSSECheckBox->isChecked())
- strlist.append(QStringLiteral("sse"));
- if(!ui->enableSSE2CheckBox->isChecked())
- strlist.append(QStringLiteral("sse2"));
- if(!ui->enableSSE3CheckBox->isChecked())
- strlist.append(QStringLiteral("sse3"));
- if(!ui->enableSSE41CheckBox->isChecked())
- strlist.append(QStringLiteral("sse4.1"));
- if(!ui->enableNeonCheckBox->isChecked())
- strlist.append(QStringLiteral("neon"));
- settings.setValue(QStringLiteral("disable-cpu-exts"), strlist.join(QChar(',')));
- settings.setValue(QStringLiteral("hrtf-mode"), std::data(hrtfModeList[ui->hrtfmodeSlider->value()].value));
- if(ui->preferredHrtfComboBox->currentIndex() == 0)
- settings.setValue(QStringLiteral("default-hrtf"), QString{});
- else
- {
- QString str{ui->preferredHrtfComboBox->currentText()};
- settings.setValue(QStringLiteral("default-hrtf"), str);
- }
- strlist.clear();
- strlist.reserve(ui->hrtfFileList->count());
- for(int i = 0;i < ui->hrtfFileList->count();i++)
- strlist.append(ui->hrtfFileList->item(i)->text());
- if(!strlist.empty() && ui->defaultHrtfPathsCheckBox->isChecked())
- strlist.append(QString{});
- settings.setValue(QStringLiteral("hrtf-paths"), strlist.join(QChar{','}));
- strlist.clear();
- for(int i = 0;i < ui->enabledBackendList->count();i++)
- {
- QString label{ui->enabledBackendList->item(i)->text()};
- for(size_t j{0};j < backendList.size();++j)
- {
- if(label == std::data(backendList[j].full_string))
- {
- strlist.append(std::data(backendList[j].backend_name));
- break;
- }
- }
- }
- for(int i = 0;i < ui->disabledBackendList->count();i++)
- {
- QString label{ui->disabledBackendList->item(i)->text()};
- for(size_t j{0};j < backendList.size();++j)
- {
- if(label == std::data(backendList[j].full_string))
- {
- strlist.append(QChar{'-'}+QString{std::data(backendList[j].backend_name)});
- break;
- }
- }
- }
- if(strlist.empty() && !ui->backendCheckBox->isChecked())
- strlist.append(QStringLiteral("-all"));
- else if(ui->backendCheckBox->isChecked())
- strlist.append(QString{});
- settings.setValue(QStringLiteral("drivers"), strlist.join(QChar(',')));
- // TODO: Remove check when we can properly match global values.
- if(ui->defaultReverbComboBox->currentIndex() == 0)
- settings.setValue(QStringLiteral("default-reverb"), QString{});
- else
- {
- QString str{ui->defaultReverbComboBox->currentText().toLower()};
- settings.setValue(QStringLiteral("default-reverb"), str);
- }
- strlist.clear();
- if(!ui->enableEaxReverbCheck->isChecked())
- strlist.append(QStringLiteral("eaxreverb"));
- if(!ui->enableStdReverbCheck->isChecked())
- strlist.append(QStringLiteral("reverb"));
- if(!ui->enableAutowahCheck->isChecked())
- strlist.append(QStringLiteral("autowah"));
- if(!ui->enableChorusCheck->isChecked())
- strlist.append(QStringLiteral("chorus"));
- if(!ui->enableDistortionCheck->isChecked())
- strlist.append(QStringLiteral("distortion"));
- if(!ui->enableCompressorCheck->isChecked())
- strlist.append(QStringLiteral("compressor"));
- if(!ui->enableEchoCheck->isChecked())
- strlist.append(QStringLiteral("echo"));
- if(!ui->enableEqualizerCheck->isChecked())
- strlist.append(QStringLiteral("equalizer"));
- if(!ui->enableFlangerCheck->isChecked())
- strlist.append(QStringLiteral("flanger"));
- if(!ui->enableFrequencyShifterCheck->isChecked())
- strlist.append(QStringLiteral("fshifter"));
- if(!ui->enableModulatorCheck->isChecked())
- strlist.append(QStringLiteral("modulator"));
- if(!ui->enableDedicatedCheck->isChecked())
- strlist.append(QStringLiteral("dedicated"));
- if(!ui->enablePitchShifterCheck->isChecked())
- strlist.append(QStringLiteral("pshifter"));
- if(!ui->enableVocalMorpherCheck->isChecked())
- strlist.append(QStringLiteral("vmorpher"));
- settings.setValue(QStringLiteral("excludefx"), strlist.join(QChar{','}));
- settings.setValue(QStringLiteral("eax/enable"),
- (!ui->enableEaxCheck->isEnabled() || ui->enableEaxCheck->isChecked())
- ? QString{/*"true"*/} : QStringLiteral("false"));
- settings.setValue(QStringLiteral("pipewire/assume-audio"), getCheckValue(ui->pwireAssumeAudioCheckBox));
- settings.setValue(QStringLiteral("pipewire/rt-mix"), getCheckValue(ui->pwireRtMixCheckBox));
- settings.setValue(QStringLiteral("wasapi/allow-resampler"), getCheckValue(ui->wasapiResamplerCheckBox));
- settings.setValue(QStringLiteral("pulse/spawn-server"), getCheckValue(ui->pulseAutospawnCheckBox));
- settings.setValue(QStringLiteral("pulse/allow-moves"), getCheckValue(ui->pulseAllowMovesCheckBox));
- settings.setValue(QStringLiteral("pulse/fix-rate"), getCheckValue(ui->pulseFixRateCheckBox));
- settings.setValue(QStringLiteral("pulse/adjust-latency"), getCheckValue(ui->pulseAdjLatencyCheckBox));
- settings.setValue(QStringLiteral("jack/spawn-server"), getCheckValue(ui->jackAutospawnCheckBox));
- settings.setValue(QStringLiteral("jack/connect-ports"), getCheckValue(ui->jackConnectPortsCheckBox));
- settings.setValue(QStringLiteral("jack/rt-mix"), getCheckValue(ui->jackRtMixCheckBox));
- settings.setValue(QStringLiteral("jack/buffer-size"), ui->jackBufferSizeLine->text());
- settings.setValue(QStringLiteral("alsa/device"), ui->alsaDefaultDeviceLine->text());
- settings.setValue(QStringLiteral("alsa/capture"), ui->alsaDefaultCaptureLine->text());
- settings.setValue(QStringLiteral("alsa/allow-resampler"), getCheckValue(ui->alsaResamplerCheckBox));
- settings.setValue(QStringLiteral("alsa/mmap"), getCheckValue(ui->alsaMmapCheckBox));
- settings.setValue(QStringLiteral("oss/device"), ui->ossDefaultDeviceLine->text());
- settings.setValue(QStringLiteral("oss/capture"), ui->ossDefaultCaptureLine->text());
- settings.setValue(QStringLiteral("solaris/device"), ui->solarisDefaultDeviceLine->text());
- settings.setValue(QStringLiteral("wave/file"), ui->waveOutputLine->text());
- settings.setValue(QStringLiteral("wave/bformat"),
- ui->waveBFormatCheckBox->isChecked() ? QStringLiteral("true") : QString{/*"false"*/}
- );
- /* Remove empty keys
- * FIXME: Should only remove keys whose value matches the globally-specified value.
- */
- allkeys = settings.allKeys();
- Q_FOREACH(const QString &key, allkeys)
- {
- QString str{settings.value(key).toString()};
- if(str.isEmpty())
- settings.remove(key);
- }
- }
- void MainWindow::enableApplyButton()
- {
- if(!mNeedsSave)
- ui->applyButton->setEnabled(true);
- mNeedsSave = true;
- ui->closeCancelButton->setText(tr("Cancel"));
- }
- void MainWindow::updateResamplerLabel(int num)
- {
- ui->resamplerLabel->setText(std::data(resamplerList[num].name));
- enableApplyButton();
- }
- void MainWindow::updatePeriodSizeEdit(int size)
- {
- ui->periodSizeEdit->clear();
- if(size >= 64)
- ui->periodSizeEdit->insert(QString::number(size));
- enableApplyButton();
- }
- void MainWindow::updatePeriodSizeSlider()
- {
- int pos = ui->periodSizeEdit->text().toInt();
- if(pos >= 64)
- {
- if(pos > 8192)
- pos = 8192;
- ui->periodSizeSlider->setSliderPosition(pos);
- }
- enableApplyButton();
- }
- void MainWindow::updatePeriodCountEdit(int count)
- {
- ui->periodCountEdit->clear();
- if(count >= 2)
- ui->periodCountEdit->insert(QString::number(count));
- enableApplyButton();
- }
- void MainWindow::updatePeriodCountSlider()
- {
- int pos = ui->periodCountEdit->text().toInt();
- if(pos < 2)
- pos = 0;
- else if(pos > 16)
- pos = 16;
- ui->periodCountSlider->setSliderPosition(pos);
- enableApplyButton();
- }
- void MainWindow::selectQuadDecoderFile()
- { selectDecoderFile(ui->decoderQuadLineEdit, "Select Quadraphonic Decoder");}
- void MainWindow::select51DecoderFile()
- { selectDecoderFile(ui->decoder51LineEdit, "Select 5.1 Surround Decoder");}
- void MainWindow::select61DecoderFile()
- { selectDecoderFile(ui->decoder61LineEdit, "Select 6.1 Surround Decoder");}
- void MainWindow::select71DecoderFile()
- { selectDecoderFile(ui->decoder71LineEdit, "Select 7.1 Surround Decoder");}
- void MainWindow::select3D71DecoderFile()
- { selectDecoderFile(ui->decoder3D71LineEdit, "Select 3D7.1 Surround Decoder");}
- void MainWindow::selectDecoderFile(QLineEdit *line, const char *caption)
- {
- QString dir{line->text()};
- if(dir.isEmpty() || QDir::isRelativePath(dir))
- {
- QStringList paths{getAllDataPaths("/openal/presets")};
- while(!paths.isEmpty())
- {
- if(QDir{paths.last()}.exists())
- {
- dir = paths.last();
- break;
- }
- paths.removeLast();
- }
- }
- QString fname{QFileDialog::getOpenFileName(this, tr(caption),
- dir, tr("AmbDec Files (*.ambdec);;All Files (*.*)"))};
- if(!fname.isEmpty())
- {
- line->setText(fname);
- enableApplyButton();
- }
- }
- void MainWindow::updateJackBufferSizeEdit(int size)
- {
- ui->jackBufferSizeLine->clear();
- if(size > 0)
- ui->jackBufferSizeLine->insert(QString::number(1<<size));
- enableApplyButton();
- }
- void MainWindow::updateJackBufferSizeSlider()
- {
- int value{ui->jackBufferSizeLine->text().toInt()};
- auto pos = static_cast<int>(floor(log2(value) + 0.5));
- ui->jackBufferSizeSlider->setSliderPosition(pos);
- enableApplyButton();
- }
- void MainWindow::updateHrtfModeLabel(int num)
- {
- ui->hrtfmodeLabel->setText(std::data(hrtfModeList[static_cast<uint>(num)].name));
- enableApplyButton();
- }
- void MainWindow::addHrtfFile()
- {
- QString path{QFileDialog::getExistingDirectory(this, tr("Select HRTF Path"))};
- if(path.isEmpty() == false && !getAllDataPaths(QStringLiteral("/openal/hrtf")).contains(path))
- {
- ui->hrtfFileList->addItem(path);
- enableApplyButton();
- }
- }
- void MainWindow::removeHrtfFile()
- {
- QList<gsl::owner<QListWidgetItem*>> selected{ui->hrtfFileList->selectedItems()};
- if(!selected.isEmpty())
- {
- std::for_each(selected.begin(), selected.end(), std::default_delete<QListWidgetItem>{});
- enableApplyButton();
- }
- }
- void MainWindow::updateHrtfRemoveButton()
- {
- ui->hrtfRemoveButton->setEnabled(!ui->hrtfFileList->selectedItems().empty());
- }
- void MainWindow::showEnabledBackendMenu(QPoint pt)
- {
- QHash<QAction*,QString> actionMap;
- pt = ui->enabledBackendList->mapToGlobal(pt);
- QMenu ctxmenu;
- QAction *removeAction{ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove")};
- if(ui->enabledBackendList->selectedItems().empty())
- removeAction->setEnabled(false);
- ctxmenu.addSeparator();
- for(size_t i{0};i < backendList.size();++i)
- {
- QString backend{std::data(backendList[i].full_string)};
- QAction *action{ctxmenu.addAction(QString("Add ")+backend)};
- actionMap[action] = backend;
- if(!ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).empty() ||
- !ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).empty())
- action->setEnabled(false);
- }
- QAction *gotAction{ctxmenu.exec(pt)};
- if(gotAction == removeAction)
- {
- QList<gsl::owner<QListWidgetItem*>> selected{ui->enabledBackendList->selectedItems()};
- std::for_each(selected.begin(), selected.end(), std::default_delete<QListWidgetItem>{});
- enableApplyButton();
- }
- else if(gotAction != nullptr)
- {
- auto iter = actionMap.constFind(gotAction);
- if(iter != actionMap.cend())
- ui->enabledBackendList->addItem(iter.value());
- enableApplyButton();
- }
- }
- void MainWindow::showDisabledBackendMenu(QPoint pt)
- {
- QHash<QAction*,QString> actionMap;
- pt = ui->disabledBackendList->mapToGlobal(pt);
- QMenu ctxmenu;
- QAction *removeAction{ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove")};
- if(ui->disabledBackendList->selectedItems().empty())
- removeAction->setEnabled(false);
- ctxmenu.addSeparator();
- for(size_t i{0};i < backendList.size();++i)
- {
- QString backend{std::data(backendList[i].full_string)};
- QAction *action{ctxmenu.addAction(QString("Add ")+backend)};
- actionMap[action] = backend;
- if(!ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).empty() ||
- !ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).empty())
- action->setEnabled(false);
- }
- QAction *gotAction{ctxmenu.exec(pt)};
- if(gotAction == removeAction)
- {
- QList<gsl::owner<QListWidgetItem*>> selected{ui->disabledBackendList->selectedItems()};
- std::for_each(selected.begin(), selected.end(), std::default_delete<QListWidgetItem>{});
- enableApplyButton();
- }
- else if(gotAction != nullptr)
- {
- auto iter = actionMap.constFind(gotAction);
- if(iter != actionMap.cend())
- ui->disabledBackendList->addItem(iter.value());
- enableApplyButton();
- }
- }
- void MainWindow::selectOSSPlayback()
- {
- QString current{ui->ossDefaultDeviceLine->text()};
- if(current.isEmpty()) current = ui->ossDefaultDeviceLine->placeholderText();
- QString fname{QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current)};
- if(!fname.isEmpty())
- {
- ui->ossDefaultDeviceLine->setText(fname);
- enableApplyButton();
- }
- }
- void MainWindow::selectOSSCapture()
- {
- QString current{ui->ossDefaultCaptureLine->text()};
- if(current.isEmpty()) current = ui->ossDefaultCaptureLine->placeholderText();
- QString fname{QFileDialog::getOpenFileName(this, tr("Select Capture Device"), current)};
- if(!fname.isEmpty())
- {
- ui->ossDefaultCaptureLine->setText(fname);
- enableApplyButton();
- }
- }
- void MainWindow::selectSolarisPlayback()
- {
- QString current{ui->solarisDefaultDeviceLine->text()};
- if(current.isEmpty()) current = ui->solarisDefaultDeviceLine->placeholderText();
- QString fname{QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current)};
- if(!fname.isEmpty())
- {
- ui->solarisDefaultDeviceLine->setText(fname);
- enableApplyButton();
- }
- }
- void MainWindow::selectWaveOutput()
- {
- QString fname{QFileDialog::getSaveFileName(this, tr("Select Wave File Output"),
- ui->waveOutputLine->text(), tr("Wave Files (*.wav *.amb);;All Files (*.*)"))};
- if(!fname.isEmpty())
- {
- ui->waveOutputLine->setText(fname);
- enableApplyButton();
- }
- }
|