🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1457 lines
53 KiB

  1. #include "config.h"
  2. #include "mainwindow.h"
  3. #include <iostream>
  4. #include <cmath>
  5. #include <QFileDialog>
  6. #include <QMessageBox>
  7. #include <QCloseEvent>
  8. #include <QSettings>
  9. #include <QtGlobal>
  10. #include "ui_mainwindow.h"
  11. #include "verstr.h"
  12. #ifdef _WIN32
  13. #include <windows.h>
  14. #include <shlobj.h>
  15. #endif
  16. namespace {
  17. static const struct {
  18. char backend_name[16];
  19. char full_string[32];
  20. } backendList[] = {
  21. #ifdef HAVE_JACK
  22. { "jack", "JACK" },
  23. #endif
  24. #ifdef HAVE_PIPEWIRE
  25. { "pipewire", "PipeWire" },
  26. #endif
  27. #ifdef HAVE_PULSEAUDIO
  28. { "pulse", "PulseAudio" },
  29. #endif
  30. #ifdef HAVE_ALSA
  31. { "alsa", "ALSA" },
  32. #endif
  33. #ifdef HAVE_COREAUDIO
  34. { "core", "CoreAudio" },
  35. #endif
  36. #ifdef HAVE_OSS
  37. { "oss", "OSS" },
  38. #endif
  39. #ifdef HAVE_SOLARIS
  40. { "solaris", "Solaris" },
  41. #endif
  42. #ifdef HAVE_SNDIO
  43. { "sndio", "SoundIO" },
  44. #endif
  45. #ifdef HAVE_QSA
  46. { "qsa", "QSA" },
  47. #endif
  48. #ifdef HAVE_WASAPI
  49. { "wasapi", "WASAPI" },
  50. #endif
  51. #ifdef HAVE_DSOUND
  52. { "dsound", "DirectSound" },
  53. #endif
  54. #ifdef HAVE_WINMM
  55. { "winmm", "Windows Multimedia" },
  56. #endif
  57. #ifdef HAVE_PORTAUDIO
  58. { "port", "PortAudio" },
  59. #endif
  60. #ifdef HAVE_OPENSL
  61. { "opensl", "OpenSL" },
  62. #endif
  63. { "null", "Null Output" },
  64. #ifdef HAVE_WAVE
  65. { "wave", "Wave Writer" },
  66. #endif
  67. { "", "" }
  68. };
  69. static const struct NameValuePair {
  70. const char name[64];
  71. const char value[16];
  72. } speakerModeList[] = {
  73. { "Autodetect", "" },
  74. { "Mono", "mono" },
  75. { "Stereo", "stereo" },
  76. { "Quadraphonic", "quad" },
  77. { "5.1 Surround", "surround51" },
  78. { "6.1 Surround", "surround61" },
  79. { "7.1 Surround", "surround71" },
  80. { "3D7.1 Surround", "surround3d71" },
  81. { "Ambisonic, 1st Order", "ambi1" },
  82. { "Ambisonic, 2nd Order", "ambi2" },
  83. { "Ambisonic, 3rd Order", "ambi3" },
  84. { "", "" }
  85. }, sampleTypeList[] = {
  86. { "Autodetect", "" },
  87. { "8-bit int", "int8" },
  88. { "8-bit uint", "uint8" },
  89. { "16-bit int", "int16" },
  90. { "16-bit uint", "uint16" },
  91. { "32-bit int", "int32" },
  92. { "32-bit uint", "uint32" },
  93. { "32-bit float", "float32" },
  94. { "", "" }
  95. }, resamplerList[] = {
  96. { "Point", "point" },
  97. { "Linear", "linear" },
  98. { "Default (Linear)", "" },
  99. { "Cubic Spline", "cubic" },
  100. { "11th order Sinc (fast)", "fast_bsinc12" },
  101. { "11th order Sinc", "bsinc12" },
  102. { "23rd order Sinc (fast)", "fast_bsinc24" },
  103. { "23rd order Sinc", "bsinc24" },
  104. { "", "" }
  105. }, stereoModeList[] = {
  106. { "Autodetect", "" },
  107. { "Speakers", "speakers" },
  108. { "Headphones", "headphones" },
  109. { "", "" }
  110. }, stereoEncList[] = {
  111. { "Default", "" },
  112. { "Pan Pot", "panpot" },
  113. { "UHJ", "uhj" },
  114. { "Binaural", "hrtf" },
  115. { "", "" }
  116. }, ambiFormatList[] = {
  117. { "Default", "" },
  118. { "AmbiX (ACN, SN3D)", "ambix" },
  119. { "Furse-Malham", "fuma" },
  120. { "ACN, N3D", "acn+n3d" },
  121. { "ACN, FuMa", "acn+fuma" },
  122. { "", "" }
  123. }, hrtfModeList[] = {
  124. { "1st Order Ambisonic", "ambi1" },
  125. { "2nd Order Ambisonic", "ambi2" },
  126. { "3rd Order Ambisonic", "ambi3" },
  127. { "Default (Full)", "" },
  128. { "Full", "full" },
  129. { "", "" }
  130. };
  131. static QString getDefaultConfigName()
  132. {
  133. #ifdef Q_OS_WIN32
  134. static const char fname[] = "alsoft.ini";
  135. auto get_appdata_path = []() noexcept -> QString
  136. {
  137. WCHAR buffer[MAX_PATH];
  138. if(SHGetSpecialFolderPathW(nullptr, buffer, CSIDL_APPDATA, FALSE) != FALSE)
  139. return QString::fromWCharArray(buffer);
  140. return QString();
  141. };
  142. QString base = get_appdata_path();
  143. #else
  144. static const char fname[] = "alsoft.conf";
  145. QByteArray base = qgetenv("XDG_CONFIG_HOME");
  146. if(base.isEmpty())
  147. {
  148. base = qgetenv("HOME");
  149. if(base.isEmpty() == false)
  150. base += "/.config";
  151. }
  152. #endif
  153. if(base.isEmpty() == false)
  154. return base +'/'+ fname;
  155. return fname;
  156. }
  157. static QString getBaseDataPath()
  158. {
  159. #ifdef Q_OS_WIN32
  160. auto get_appdata_path = []() noexcept -> QString
  161. {
  162. WCHAR buffer[MAX_PATH];
  163. if(SHGetSpecialFolderPathW(nullptr, buffer, CSIDL_APPDATA, FALSE) != FALSE)
  164. return QString::fromWCharArray(buffer);
  165. return QString();
  166. };
  167. QString base = get_appdata_path();
  168. #else
  169. QByteArray base = qgetenv("XDG_DATA_HOME");
  170. if(base.isEmpty())
  171. {
  172. base = qgetenv("HOME");
  173. if(!base.isEmpty())
  174. base += "/.local/share";
  175. }
  176. #endif
  177. return base;
  178. }
  179. static QStringList getAllDataPaths(const QString &append)
  180. {
  181. QStringList list;
  182. list.append(getBaseDataPath());
  183. #ifdef Q_OS_WIN32
  184. // TODO: Common AppData path
  185. #else
  186. QString paths = qgetenv("XDG_DATA_DIRS");
  187. if(paths.isEmpty())
  188. paths = "/usr/local/share/:/usr/share/";
  189. #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
  190. list += paths.split(QChar(':'), Qt::SkipEmptyParts);
  191. #else
  192. list += paths.split(QChar(':'), QString::SkipEmptyParts);
  193. #endif
  194. #endif
  195. QStringList::iterator iter = list.begin();
  196. while(iter != list.end())
  197. {
  198. if(iter->isEmpty())
  199. iter = list.erase(iter);
  200. else
  201. {
  202. iter->append(append);
  203. iter++;
  204. }
  205. }
  206. return list;
  207. }
  208. template<size_t N>
  209. static QString getValueFromName(const NameValuePair (&list)[N], const QString &str)
  210. {
  211. for(size_t i = 0;i < N-1;i++)
  212. {
  213. if(str == list[i].name)
  214. return list[i].value;
  215. }
  216. return QString{};
  217. }
  218. template<size_t N>
  219. static QString getNameFromValue(const NameValuePair (&list)[N], const QString &str)
  220. {
  221. for(size_t i = 0;i < N-1;i++)
  222. {
  223. if(str == list[i].value)
  224. return list[i].name;
  225. }
  226. return QString{};
  227. }
  228. Qt::CheckState getCheckState(const QVariant &var)
  229. {
  230. if(var.isNull())
  231. return Qt::PartiallyChecked;
  232. if(var.toBool())
  233. return Qt::Checked;
  234. return Qt::Unchecked;
  235. }
  236. QString getCheckValue(const QCheckBox *checkbox)
  237. {
  238. const Qt::CheckState state{checkbox->checkState()};
  239. if(state == Qt::Checked)
  240. return QString{"true"};
  241. if(state == Qt::Unchecked)
  242. return QString{"false"};
  243. return QString{};
  244. }
  245. }
  246. MainWindow::MainWindow(QWidget *parent) :
  247. QMainWindow(parent),
  248. ui(new Ui::MainWindow),
  249. mPeriodSizeValidator(nullptr),
  250. mPeriodCountValidator(nullptr),
  251. mSourceCountValidator(nullptr),
  252. mEffectSlotValidator(nullptr),
  253. mSourceSendValidator(nullptr),
  254. mSampleRateValidator(nullptr),
  255. mJackBufferValidator(nullptr),
  256. mNeedsSave(false)
  257. {
  258. ui->setupUi(this);
  259. for(int i = 0;speakerModeList[i].name[0];i++)
  260. ui->channelConfigCombo->addItem(speakerModeList[i].name);
  261. ui->channelConfigCombo->adjustSize();
  262. for(int i = 0;sampleTypeList[i].name[0];i++)
  263. ui->sampleFormatCombo->addItem(sampleTypeList[i].name);
  264. ui->sampleFormatCombo->adjustSize();
  265. for(int i = 0;stereoModeList[i].name[0];i++)
  266. ui->stereoModeCombo->addItem(stereoModeList[i].name);
  267. ui->stereoModeCombo->adjustSize();
  268. for(int i = 0;stereoEncList[i].name[0];i++)
  269. ui->stereoEncodingComboBox->addItem(stereoEncList[i].name);
  270. ui->stereoEncodingComboBox->adjustSize();
  271. for(int i = 0;ambiFormatList[i].name[0];i++)
  272. ui->ambiFormatComboBox->addItem(ambiFormatList[i].name);
  273. ui->ambiFormatComboBox->adjustSize();
  274. int count;
  275. for(count = 0;resamplerList[count].name[0];count++) {
  276. }
  277. ui->resamplerSlider->setRange(0, count-1);
  278. for(count = 0;hrtfModeList[count].name[0];count++) {
  279. }
  280. ui->hrtfmodeSlider->setRange(0, count-1);
  281. ui->hrtfStateComboBox->adjustSize();
  282. #if !defined(HAVE_NEON) && !defined(HAVE_SSE)
  283. ui->cpuExtDisabledLabel->move(ui->cpuExtDisabledLabel->x(), ui->cpuExtDisabledLabel->y() - 60);
  284. #else
  285. ui->cpuExtDisabledLabel->setVisible(false);
  286. #endif
  287. #ifndef HAVE_NEON
  288. #ifndef HAVE_SSE4_1
  289. #ifndef HAVE_SSE3
  290. #ifndef HAVE_SSE2
  291. #ifndef HAVE_SSE
  292. ui->enableSSECheckBox->setVisible(false);
  293. #endif /* !SSE */
  294. ui->enableSSE2CheckBox->setVisible(false);
  295. #endif /* !SSE2 */
  296. ui->enableSSE3CheckBox->setVisible(false);
  297. #endif /* !SSE3 */
  298. ui->enableSSE41CheckBox->setVisible(false);
  299. #endif /* !SSE4.1 */
  300. ui->enableNeonCheckBox->setVisible(false);
  301. #else /* !Neon */
  302. #ifndef HAVE_SSE4_1
  303. #ifndef HAVE_SSE3
  304. #ifndef HAVE_SSE2
  305. #ifndef HAVE_SSE
  306. ui->enableNeonCheckBox->move(ui->enableNeonCheckBox->x(), ui->enableNeonCheckBox->y() - 30);
  307. ui->enableSSECheckBox->setVisible(false);
  308. #endif /* !SSE */
  309. ui->enableSSE2CheckBox->setVisible(false);
  310. #endif /* !SSE2 */
  311. ui->enableSSE3CheckBox->setVisible(false);
  312. #endif /* !SSE3 */
  313. ui->enableSSE41CheckBox->setVisible(false);
  314. #endif /* !SSE4.1 */
  315. #endif
  316. #ifndef ALSOFT_EAX
  317. ui->enableEaxCheck->setChecked(Qt::Unchecked);
  318. ui->enableEaxCheck->setEnabled(false);
  319. ui->enableEaxCheck->setVisible(false);
  320. #endif
  321. mPeriodSizeValidator = new QIntValidator{64, 8192, this};
  322. ui->periodSizeEdit->setValidator(mPeriodSizeValidator);
  323. mPeriodCountValidator = new QIntValidator{2, 16, this};
  324. ui->periodCountEdit->setValidator(mPeriodCountValidator);
  325. mSourceCountValidator = new QIntValidator{0, 4096, this};
  326. ui->srcCountLineEdit->setValidator(mSourceCountValidator);
  327. mEffectSlotValidator = new QIntValidator{0, 64, this};
  328. ui->effectSlotLineEdit->setValidator(mEffectSlotValidator);
  329. mSourceSendValidator = new QIntValidator{0, 16, this};
  330. ui->srcSendLineEdit->setValidator(mSourceSendValidator);
  331. mSampleRateValidator = new QIntValidator{8000, 192000, this};
  332. ui->sampleRateCombo->lineEdit()->setValidator(mSampleRateValidator);
  333. mJackBufferValidator = new QIntValidator{0, 8192, this};
  334. ui->jackBufferSizeLine->setValidator(mJackBufferValidator);
  335. connect(ui->actionLoad, &QAction::triggered, this, &MainWindow::loadConfigFromFile);
  336. connect(ui->actionSave_As, &QAction::triggered, this, &MainWindow::saveConfigAsFile);
  337. connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::showAboutPage);
  338. connect(ui->closeCancelButton, &QPushButton::clicked, this, &MainWindow::cancelCloseAction);
  339. connect(ui->applyButton, &QPushButton::clicked, this, &MainWindow::saveCurrentConfig);
  340. auto qcb_cicint = static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged);
  341. connect(ui->channelConfigCombo, qcb_cicint, this, &MainWindow::enableApplyButton);
  342. connect(ui->sampleFormatCombo, qcb_cicint, this, &MainWindow::enableApplyButton);
  343. connect(ui->stereoModeCombo, qcb_cicint, this, &MainWindow::enableApplyButton);
  344. connect(ui->sampleRateCombo, qcb_cicint, this, &MainWindow::enableApplyButton);
  345. connect(ui->sampleRateCombo, &QComboBox::editTextChanged, this, &MainWindow::enableApplyButton);
  346. connect(ui->resamplerSlider, &QSlider::valueChanged, this, &MainWindow::updateResamplerLabel);
  347. connect(ui->periodSizeSlider, &QSlider::valueChanged, this, &MainWindow::updatePeriodSizeEdit);
  348. connect(ui->periodSizeEdit, &QLineEdit::editingFinished, this, &MainWindow::updatePeriodSizeSlider);
  349. connect(ui->periodCountSlider, &QSlider::valueChanged, this, &MainWindow::updatePeriodCountEdit);
  350. connect(ui->periodCountEdit, &QLineEdit::editingFinished, this, &MainWindow::updatePeriodCountSlider);
  351. connect(ui->stereoEncodingComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
  352. connect(ui->ambiFormatComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
  353. connect(ui->outputLimiterCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  354. connect(ui->outputDitherCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  355. connect(ui->decoderHQModeCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  356. connect(ui->decoderDistCompCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  357. connect(ui->decoderNFEffectsCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  358. auto qdsb_vcd = static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged);
  359. connect(ui->decoderNFRefDelaySpinBox, qdsb_vcd, this, &MainWindow::enableApplyButton);
  360. connect(ui->decoderQuadLineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
  361. connect(ui->decoderQuadButton, &QPushButton::clicked, this, &MainWindow::selectQuadDecoderFile);
  362. connect(ui->decoder51LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
  363. connect(ui->decoder51Button, &QPushButton::clicked, this, &MainWindow::select51DecoderFile);
  364. connect(ui->decoder61LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
  365. connect(ui->decoder61Button, &QPushButton::clicked, this, &MainWindow::select61DecoderFile);
  366. connect(ui->decoder71LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
  367. connect(ui->decoder71Button, &QPushButton::clicked, this, &MainWindow::select71DecoderFile);
  368. connect(ui->decoder3D71LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
  369. connect(ui->decoder3D71Button, &QPushButton::clicked, this, &MainWindow::select3D71DecoderFile);
  370. connect(ui->preferredHrtfComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
  371. connect(ui->hrtfStateComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
  372. connect(ui->hrtfmodeSlider, &QSlider::valueChanged, this, &MainWindow::updateHrtfModeLabel);
  373. connect(ui->hrtfAddButton, &QPushButton::clicked, this, &MainWindow::addHrtfFile);
  374. connect(ui->hrtfRemoveButton, &QPushButton::clicked, this, &MainWindow::removeHrtfFile);
  375. connect(ui->hrtfFileList, &QListWidget::itemSelectionChanged, this, &MainWindow::updateHrtfRemoveButton);
  376. connect(ui->defaultHrtfPathsCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  377. connect(ui->srcCountLineEdit, &QLineEdit::editingFinished, this, &MainWindow::enableApplyButton);
  378. connect(ui->srcSendLineEdit, &QLineEdit::editingFinished, this, &MainWindow::enableApplyButton);
  379. connect(ui->effectSlotLineEdit, &QLineEdit::editingFinished, this, &MainWindow::enableApplyButton);
  380. connect(ui->enableSSECheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  381. connect(ui->enableSSE2CheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  382. connect(ui->enableSSE3CheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  383. connect(ui->enableSSE41CheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  384. connect(ui->enableNeonCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  385. ui->enabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
  386. connect(ui->enabledBackendList, &QListWidget::customContextMenuRequested, this, &MainWindow::showEnabledBackendMenu);
  387. ui->disabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
  388. connect(ui->disabledBackendList, &QListWidget::customContextMenuRequested, this, &MainWindow::showDisabledBackendMenu);
  389. connect(ui->backendCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  390. connect(ui->defaultReverbComboBox, qcb_cicint, this, &MainWindow::enableApplyButton);
  391. connect(ui->enableEaxReverbCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  392. connect(ui->enableStdReverbCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  393. connect(ui->enableAutowahCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  394. connect(ui->enableChorusCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  395. connect(ui->enableCompressorCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  396. connect(ui->enableDistortionCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  397. connect(ui->enableEchoCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  398. connect(ui->enableEqualizerCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  399. connect(ui->enableFlangerCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  400. connect(ui->enableFrequencyShifterCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  401. connect(ui->enableModulatorCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  402. connect(ui->enableDedicatedCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  403. connect(ui->enablePitchShifterCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  404. connect(ui->enableVocalMorpherCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  405. connect(ui->enableEaxCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  406. connect(ui->pulseAutospawnCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  407. connect(ui->pulseAllowMovesCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  408. connect(ui->pulseFixRateCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  409. connect(ui->pulseAdjLatencyCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  410. connect(ui->pwireAssumeAudioCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  411. connect(ui->jackAutospawnCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  412. connect(ui->jackConnectPortsCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  413. connect(ui->jackRtMixCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  414. connect(ui->jackBufferSizeSlider, &QSlider::valueChanged, this, &MainWindow::updateJackBufferSizeEdit);
  415. connect(ui->jackBufferSizeLine, &QLineEdit::editingFinished, this, &MainWindow::updateJackBufferSizeSlider);
  416. connect(ui->alsaDefaultDeviceLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
  417. connect(ui->alsaDefaultCaptureLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
  418. connect(ui->alsaResamplerCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  419. connect(ui->alsaMmapCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  420. connect(ui->ossDefaultDeviceLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
  421. connect(ui->ossPlaybackPushButton, &QPushButton::clicked, this, &MainWindow::selectOSSPlayback);
  422. connect(ui->ossDefaultCaptureLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
  423. connect(ui->ossCapturePushButton, &QPushButton::clicked, this, &MainWindow::selectOSSCapture);
  424. connect(ui->solarisDefaultDeviceLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
  425. connect(ui->solarisPlaybackPushButton, &QPushButton::clicked, this, &MainWindow::selectSolarisPlayback);
  426. connect(ui->waveOutputLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton);
  427. connect(ui->waveOutputButton, &QPushButton::clicked, this, &MainWindow::selectWaveOutput);
  428. connect(ui->waveBFormatCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton);
  429. ui->backendListWidget->setCurrentRow(0);
  430. ui->tabWidget->setCurrentIndex(0);
  431. for(int i = 1;i < ui->backendListWidget->count();i++)
  432. ui->backendListWidget->setRowHidden(i, true);
  433. for(int i = 0;backendList[i].backend_name[0];i++)
  434. {
  435. QList<QListWidgetItem*> items = ui->backendListWidget->findItems(
  436. backendList[i].full_string, Qt::MatchFixedString);
  437. foreach(QListWidgetItem *item, items)
  438. item->setHidden(false);
  439. }
  440. loadConfig(getDefaultConfigName());
  441. }
  442. MainWindow::~MainWindow()
  443. {
  444. delete ui;
  445. delete mPeriodSizeValidator;
  446. delete mPeriodCountValidator;
  447. delete mSourceCountValidator;
  448. delete mEffectSlotValidator;
  449. delete mSourceSendValidator;
  450. delete mSampleRateValidator;
  451. delete mJackBufferValidator;
  452. }
  453. void MainWindow::closeEvent(QCloseEvent *event)
  454. {
  455. if(!mNeedsSave)
  456. event->accept();
  457. else
  458. {
  459. QMessageBox::StandardButton btn = QMessageBox::warning(this,
  460. tr("Apply changes?"), tr("Save changes before quitting?"),
  461. QMessageBox::Save | QMessageBox::No | QMessageBox::Cancel);
  462. if(btn == QMessageBox::Save)
  463. saveCurrentConfig();
  464. if(btn == QMessageBox::Cancel)
  465. event->ignore();
  466. else
  467. event->accept();
  468. }
  469. }
  470. void MainWindow::cancelCloseAction()
  471. {
  472. mNeedsSave = false;
  473. close();
  474. }
  475. void MainWindow::showAboutPage()
  476. {
  477. QMessageBox::information(this, tr("About"),
  478. tr("OpenAL Soft Configuration Utility.\nBuilt for OpenAL Soft library version ") +
  479. GetVersionString());
  480. }
  481. QStringList MainWindow::collectHrtfs()
  482. {
  483. QStringList ret;
  484. QStringList processed;
  485. for(int i = 0;i < ui->hrtfFileList->count();i++)
  486. {
  487. QDir dir(ui->hrtfFileList->item(i)->text());
  488. QStringList fnames = dir.entryList(QDir::Files | QDir::Readable, QDir::Name);
  489. foreach(const QString &fname, fnames)
  490. {
  491. if(!fname.endsWith(".mhr", Qt::CaseInsensitive))
  492. continue;
  493. QString fullname{dir.absoluteFilePath(fname)};
  494. if(processed.contains(fullname))
  495. continue;
  496. processed.push_back(fullname);
  497. QString name{fname.left(fname.length()-4)};
  498. if(!ret.contains(name))
  499. ret.push_back(name);
  500. else
  501. {
  502. size_t i{2};
  503. do {
  504. QString s = name+" #"+QString::number(i);
  505. if(!ret.contains(s))
  506. {
  507. ret.push_back(s);
  508. break;
  509. }
  510. ++i;
  511. } while(1);
  512. }
  513. }
  514. }
  515. if(ui->defaultHrtfPathsCheckBox->isChecked())
  516. {
  517. QStringList paths = getAllDataPaths("/openal/hrtf");
  518. foreach(const QString &name, paths)
  519. {
  520. QDir dir{name};
  521. QStringList fnames{dir.entryList(QDir::Files | QDir::Readable, QDir::Name)};
  522. foreach(const QString &fname, fnames)
  523. {
  524. if(!fname.endsWith(".mhr", Qt::CaseInsensitive))
  525. continue;
  526. QString fullname{dir.absoluteFilePath(fname)};
  527. if(processed.contains(fullname))
  528. continue;
  529. processed.push_back(fullname);
  530. QString name{fname.left(fname.length()-4)};
  531. if(!ret.contains(name))
  532. ret.push_back(name);
  533. else
  534. {
  535. size_t i{2};
  536. do {
  537. QString s{name+" #"+QString::number(i)};
  538. if(!ret.contains(s))
  539. {
  540. ret.push_back(s);
  541. break;
  542. }
  543. ++i;
  544. } while(1);
  545. }
  546. }
  547. }
  548. #ifdef ALSOFT_EMBED_HRTF_DATA
  549. ret.push_back("Built-In HRTF");
  550. #endif
  551. }
  552. return ret;
  553. }
  554. void MainWindow::loadConfigFromFile()
  555. {
  556. QString fname = QFileDialog::getOpenFileName(this, tr("Select Files"));
  557. if(fname.isEmpty() == false)
  558. loadConfig(fname);
  559. }
  560. void MainWindow::loadConfig(const QString &fname)
  561. {
  562. QSettings settings{fname, QSettings::IniFormat};
  563. QString sampletype = settings.value("sample-type").toString();
  564. ui->sampleFormatCombo->setCurrentIndex(0);
  565. if(sampletype.isEmpty() == false)
  566. {
  567. QString str{getNameFromValue(sampleTypeList, sampletype)};
  568. if(!str.isEmpty())
  569. {
  570. const int j{ui->sampleFormatCombo->findText(str)};
  571. if(j > 0) ui->sampleFormatCombo->setCurrentIndex(j);
  572. }
  573. }
  574. QString channelconfig{settings.value("channels").toString()};
  575. ui->channelConfigCombo->setCurrentIndex(0);
  576. if(channelconfig.isEmpty() == false)
  577. {
  578. if(channelconfig == "surround51rear")
  579. channelconfig = "surround51";
  580. QString str{getNameFromValue(speakerModeList, channelconfig)};
  581. if(!str.isEmpty())
  582. {
  583. const int j{ui->channelConfigCombo->findText(str)};
  584. if(j > 0) ui->channelConfigCombo->setCurrentIndex(j);
  585. }
  586. }
  587. QString srate{settings.value("frequency").toString()};
  588. if(srate.isEmpty())
  589. ui->sampleRateCombo->setCurrentIndex(0);
  590. else
  591. {
  592. ui->sampleRateCombo->lineEdit()->clear();
  593. ui->sampleRateCombo->lineEdit()->insert(srate);
  594. }
  595. ui->srcCountLineEdit->clear();
  596. ui->srcCountLineEdit->insert(settings.value("sources").toString());
  597. ui->effectSlotLineEdit->clear();
  598. ui->effectSlotLineEdit->insert(settings.value("slots").toString());
  599. ui->srcSendLineEdit->clear();
  600. ui->srcSendLineEdit->insert(settings.value("sends").toString());
  601. QString resampler = settings.value("resampler").toString().trimmed();
  602. ui->resamplerSlider->setValue(2);
  603. ui->resamplerLabel->setText(resamplerList[2].name);
  604. /* The "sinc4" and "sinc8" resamplers are no longer supported. Use "cubic"
  605. * as a fallback.
  606. */
  607. if(resampler == "sinc4" || resampler == "sinc8")
  608. resampler = "cubic";
  609. /* The "bsinc" resampler name is an alias for "bsinc12". */
  610. else if(resampler == "bsinc")
  611. resampler = "bsinc12";
  612. for(int i = 0;resamplerList[i].name[0];i++)
  613. {
  614. if(resampler == resamplerList[i].value)
  615. {
  616. ui->resamplerSlider->setValue(i);
  617. ui->resamplerLabel->setText(resamplerList[i].name);
  618. break;
  619. }
  620. }
  621. QString stereomode = settings.value("stereo-mode").toString().trimmed();
  622. ui->stereoModeCombo->setCurrentIndex(0);
  623. if(stereomode.isEmpty() == false)
  624. {
  625. QString str{getNameFromValue(stereoModeList, stereomode)};
  626. if(!str.isEmpty())
  627. {
  628. const int j{ui->stereoModeCombo->findText(str)};
  629. if(j > 0) ui->stereoModeCombo->setCurrentIndex(j);
  630. }
  631. }
  632. int periodsize{settings.value("period_size").toInt()};
  633. ui->periodSizeEdit->clear();
  634. if(periodsize >= 64)
  635. {
  636. ui->periodSizeEdit->insert(QString::number(periodsize));
  637. updatePeriodSizeSlider();
  638. }
  639. int periodcount{settings.value("periods").toInt()};
  640. ui->periodCountEdit->clear();
  641. if(periodcount >= 2)
  642. {
  643. ui->periodCountEdit->insert(QString::number(periodcount));
  644. updatePeriodCountSlider();
  645. }
  646. ui->outputLimiterCheckBox->setCheckState(getCheckState(settings.value("output-limiter")));
  647. ui->outputDitherCheckBox->setCheckState(getCheckState(settings.value("dither")));
  648. QString stereopan{settings.value("stereo-encoding").toString()};
  649. ui->stereoEncodingComboBox->setCurrentIndex(0);
  650. if(stereopan.isEmpty() == false)
  651. {
  652. QString str{getNameFromValue(stereoEncList, stereopan)};
  653. if(!str.isEmpty())
  654. {
  655. const int j{ui->stereoEncodingComboBox->findText(str)};
  656. if(j > 0) ui->stereoEncodingComboBox->setCurrentIndex(j);
  657. }
  658. }
  659. QString ambiformat{settings.value("ambi-format").toString()};
  660. ui->ambiFormatComboBox->setCurrentIndex(0);
  661. if(ambiformat.isEmpty() == false)
  662. {
  663. QString str{getNameFromValue(ambiFormatList, ambiformat)};
  664. if(!str.isEmpty())
  665. {
  666. const int j{ui->ambiFormatComboBox->findText(str)};
  667. if(j > 0) ui->ambiFormatComboBox->setCurrentIndex(j);
  668. }
  669. }
  670. ui->decoderHQModeCheckBox->setChecked(getCheckState(settings.value("decoder/hq-mode")));
  671. ui->decoderDistCompCheckBox->setCheckState(getCheckState(settings.value("decoder/distance-comp")));
  672. ui->decoderNFEffectsCheckBox->setCheckState(getCheckState(settings.value("decoder/nfc")));
  673. double refdelay{settings.value("decoder/nfc-ref-delay", 0.0).toDouble()};
  674. ui->decoderNFRefDelaySpinBox->setValue(refdelay);
  675. ui->decoderQuadLineEdit->setText(settings.value("decoder/quad").toString());
  676. ui->decoder51LineEdit->setText(settings.value("decoder/surround51").toString());
  677. ui->decoder61LineEdit->setText(settings.value("decoder/surround61").toString());
  678. ui->decoder71LineEdit->setText(settings.value("decoder/surround71").toString());
  679. QStringList disabledCpuExts{settings.value("disable-cpu-exts").toStringList()};
  680. if(disabledCpuExts.size() == 1)
  681. disabledCpuExts = disabledCpuExts[0].split(QChar(','));
  682. for(QString &name : disabledCpuExts)
  683. name = name.trimmed();
  684. ui->enableSSECheckBox->setChecked(!disabledCpuExts.contains("sse", Qt::CaseInsensitive));
  685. ui->enableSSE2CheckBox->setChecked(!disabledCpuExts.contains("sse2", Qt::CaseInsensitive));
  686. ui->enableSSE3CheckBox->setChecked(!disabledCpuExts.contains("sse3", Qt::CaseInsensitive));
  687. ui->enableSSE41CheckBox->setChecked(!disabledCpuExts.contains("sse4.1", Qt::CaseInsensitive));
  688. ui->enableNeonCheckBox->setChecked(!disabledCpuExts.contains("neon", Qt::CaseInsensitive));
  689. QString hrtfmode{settings.value("hrtf-mode").toString().trimmed()};
  690. ui->hrtfmodeSlider->setValue(2);
  691. ui->hrtfmodeLabel->setText(hrtfModeList[3].name);
  692. /* The "basic" mode name is no longer supported. Use "ambi2" instead. */
  693. if(hrtfmode == "basic")
  694. hrtfmode = "ambi2";
  695. for(int i = 0;hrtfModeList[i].name[0];i++)
  696. {
  697. if(hrtfmode == hrtfModeList[i].value)
  698. {
  699. ui->hrtfmodeSlider->setValue(i);
  700. ui->hrtfmodeLabel->setText(hrtfModeList[i].name);
  701. break;
  702. }
  703. }
  704. QStringList hrtf_paths{settings.value("hrtf-paths").toStringList()};
  705. if(hrtf_paths.size() == 1)
  706. hrtf_paths = hrtf_paths[0].split(QChar(','));
  707. for(QString &name : hrtf_paths)
  708. name = name.trimmed();
  709. if(!hrtf_paths.empty() && !hrtf_paths.back().isEmpty())
  710. ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Unchecked);
  711. else
  712. {
  713. hrtf_paths.removeAll(QString());
  714. ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Checked);
  715. }
  716. hrtf_paths.removeDuplicates();
  717. ui->hrtfFileList->clear();
  718. ui->hrtfFileList->addItems(hrtf_paths);
  719. updateHrtfRemoveButton();
  720. QString hrtfstate{settings.value("hrtf").toString().toLower()};
  721. if(hrtfstate == "true")
  722. ui->hrtfStateComboBox->setCurrentIndex(1);
  723. else if(hrtfstate == "false")
  724. ui->hrtfStateComboBox->setCurrentIndex(2);
  725. else
  726. ui->hrtfStateComboBox->setCurrentIndex(0);
  727. ui->preferredHrtfComboBox->clear();
  728. ui->preferredHrtfComboBox->addItem("- Any -");
  729. if(ui->defaultHrtfPathsCheckBox->isChecked())
  730. {
  731. QStringList hrtfs{collectHrtfs()};
  732. foreach(const QString &name, hrtfs)
  733. ui->preferredHrtfComboBox->addItem(name);
  734. }
  735. QString defaulthrtf{settings.value("default-hrtf").toString()};
  736. ui->preferredHrtfComboBox->setCurrentIndex(0);
  737. if(defaulthrtf.isEmpty() == false)
  738. {
  739. int i{ui->preferredHrtfComboBox->findText(defaulthrtf)};
  740. if(i > 0)
  741. ui->preferredHrtfComboBox->setCurrentIndex(i);
  742. else
  743. {
  744. i = ui->preferredHrtfComboBox->count();
  745. ui->preferredHrtfComboBox->addItem(defaulthrtf);
  746. ui->preferredHrtfComboBox->setCurrentIndex(i);
  747. }
  748. }
  749. ui->preferredHrtfComboBox->adjustSize();
  750. ui->enabledBackendList->clear();
  751. ui->disabledBackendList->clear();
  752. QStringList drivers{settings.value("drivers").toStringList()};
  753. if(drivers.size() == 0)
  754. ui->backendCheckBox->setChecked(true);
  755. else
  756. {
  757. if(drivers.size() == 1)
  758. drivers = drivers[0].split(QChar(','));
  759. for(QString &name : drivers)
  760. {
  761. name = name.trimmed();
  762. /* Convert "mmdevapi" references to "wasapi" for backwards
  763. * compatibility.
  764. */
  765. if(name == "-mmdevapi")
  766. name = "-wasapi";
  767. else if(name == "mmdevapi")
  768. name = "wasapi";
  769. }
  770. bool lastWasEmpty = false;
  771. foreach(const QString &backend, drivers)
  772. {
  773. lastWasEmpty = backend.isEmpty();
  774. if(lastWasEmpty) continue;
  775. if(!backend.startsWith(QChar('-')))
  776. for(int j = 0;backendList[j].backend_name[0];j++)
  777. {
  778. if(backend == backendList[j].backend_name)
  779. {
  780. ui->enabledBackendList->addItem(backendList[j].full_string);
  781. break;
  782. }
  783. }
  784. else if(backend.size() > 1)
  785. {
  786. QStringRef backendref{backend.rightRef(backend.size()-1)};
  787. for(int j = 0;backendList[j].backend_name[0];j++)
  788. {
  789. if(backendref == backendList[j].backend_name)
  790. {
  791. ui->disabledBackendList->addItem(backendList[j].full_string);
  792. break;
  793. }
  794. }
  795. }
  796. }
  797. ui->backendCheckBox->setChecked(lastWasEmpty);
  798. }
  799. QString defaultreverb{settings.value("default-reverb").toString().toLower()};
  800. ui->defaultReverbComboBox->setCurrentIndex(0);
  801. if(defaultreverb.isEmpty() == false)
  802. {
  803. for(int i = 0;i < ui->defaultReverbComboBox->count();i++)
  804. {
  805. if(defaultreverb.compare(ui->defaultReverbComboBox->itemText(i).toLower()) == 0)
  806. {
  807. ui->defaultReverbComboBox->setCurrentIndex(i);
  808. break;
  809. }
  810. }
  811. }
  812. QStringList excludefx{settings.value("excludefx").toStringList()};
  813. if(excludefx.size() == 1)
  814. excludefx = excludefx[0].split(QChar(','));
  815. for(QString &name : excludefx)
  816. name = name.trimmed();
  817. ui->enableEaxReverbCheck->setChecked(!excludefx.contains("eaxreverb", Qt::CaseInsensitive));
  818. ui->enableStdReverbCheck->setChecked(!excludefx.contains("reverb", Qt::CaseInsensitive));
  819. ui->enableAutowahCheck->setChecked(!excludefx.contains("autowah", Qt::CaseInsensitive));
  820. ui->enableChorusCheck->setChecked(!excludefx.contains("chorus", Qt::CaseInsensitive));
  821. ui->enableCompressorCheck->setChecked(!excludefx.contains("compressor", Qt::CaseInsensitive));
  822. ui->enableDistortionCheck->setChecked(!excludefx.contains("distortion", Qt::CaseInsensitive));
  823. ui->enableEchoCheck->setChecked(!excludefx.contains("echo", Qt::CaseInsensitive));
  824. ui->enableEqualizerCheck->setChecked(!excludefx.contains("equalizer", Qt::CaseInsensitive));
  825. ui->enableFlangerCheck->setChecked(!excludefx.contains("flanger", Qt::CaseInsensitive));
  826. ui->enableFrequencyShifterCheck->setChecked(!excludefx.contains("fshifter", Qt::CaseInsensitive));
  827. ui->enableModulatorCheck->setChecked(!excludefx.contains("modulator", Qt::CaseInsensitive));
  828. ui->enableDedicatedCheck->setChecked(!excludefx.contains("dedicated", Qt::CaseInsensitive));
  829. ui->enablePitchShifterCheck->setChecked(!excludefx.contains("pshifter", Qt::CaseInsensitive));
  830. ui->enableVocalMorpherCheck->setChecked(!excludefx.contains("vmorpher", Qt::CaseInsensitive));
  831. if(ui->enableEaxCheck->isEnabled())
  832. ui->enableEaxCheck->setChecked(getCheckState(settings.value("eax/enable")) != Qt::Unchecked);
  833. ui->pulseAutospawnCheckBox->setCheckState(getCheckState(settings.value("pulse/spawn-server")));
  834. ui->pulseAllowMovesCheckBox->setCheckState(getCheckState(settings.value("pulse/allow-moves")));
  835. ui->pulseFixRateCheckBox->setCheckState(getCheckState(settings.value("pulse/fix-rate")));
  836. ui->pulseAdjLatencyCheckBox->setCheckState(getCheckState(settings.value("pulse/adjust-latency")));
  837. ui->pwireAssumeAudioCheckBox->setCheckState(settings.value("pipewire/assume-audio").toBool()
  838. ? Qt::Checked : Qt::Unchecked);
  839. ui->jackAutospawnCheckBox->setCheckState(getCheckState(settings.value("jack/spawn-server")));
  840. ui->jackConnectPortsCheckBox->setCheckState(getCheckState(settings.value("jack/connect-ports")));
  841. ui->jackRtMixCheckBox->setCheckState(getCheckState(settings.value("jack/rt-mix")));
  842. ui->jackBufferSizeLine->setText(settings.value("jack/buffer-size", QString()).toString());
  843. updateJackBufferSizeSlider();
  844. ui->alsaDefaultDeviceLine->setText(settings.value("alsa/device", QString()).toString());
  845. ui->alsaDefaultCaptureLine->setText(settings.value("alsa/capture", QString()).toString());
  846. ui->alsaResamplerCheckBox->setCheckState(getCheckState(settings.value("alsa/allow-resampler")));
  847. ui->alsaMmapCheckBox->setCheckState(getCheckState(settings.value("alsa/mmap")));
  848. ui->ossDefaultDeviceLine->setText(settings.value("oss/device", QString()).toString());
  849. ui->ossDefaultCaptureLine->setText(settings.value("oss/capture", QString()).toString());
  850. ui->solarisDefaultDeviceLine->setText(settings.value("solaris/device", QString()).toString());
  851. ui->waveOutputLine->setText(settings.value("wave/file", QString()).toString());
  852. ui->waveBFormatCheckBox->setChecked(settings.value("wave/bformat", false).toBool());
  853. ui->applyButton->setEnabled(false);
  854. ui->closeCancelButton->setText(tr("Close"));
  855. mNeedsSave = false;
  856. }
  857. void MainWindow::saveCurrentConfig()
  858. {
  859. saveConfig(getDefaultConfigName());
  860. ui->applyButton->setEnabled(false);
  861. ui->closeCancelButton->setText(tr("Close"));
  862. mNeedsSave = false;
  863. QMessageBox::information(this, tr("Information"),
  864. tr("Applications using OpenAL need to be restarted for changes to take effect."));
  865. }
  866. void MainWindow::saveConfigAsFile()
  867. {
  868. QString fname{QFileDialog::getOpenFileName(this, tr("Select Files"))};
  869. if(fname.isEmpty() == false)
  870. {
  871. saveConfig(fname);
  872. ui->applyButton->setEnabled(false);
  873. mNeedsSave = false;
  874. }
  875. }
  876. void MainWindow::saveConfig(const QString &fname) const
  877. {
  878. QSettings settings{fname, QSettings::IniFormat};
  879. /* HACK: Compound any stringlist values into a comma-separated string. */
  880. QStringList allkeys{settings.allKeys()};
  881. foreach(const QString &key, allkeys)
  882. {
  883. QStringList vals{settings.value(key).toStringList()};
  884. if(vals.size() > 1)
  885. settings.setValue(key, vals.join(QChar(',')));
  886. }
  887. settings.setValue("sample-type", getValueFromName(sampleTypeList, ui->sampleFormatCombo->currentText()));
  888. settings.setValue("channels", getValueFromName(speakerModeList, ui->channelConfigCombo->currentText()));
  889. uint rate{ui->sampleRateCombo->currentText().toUInt()};
  890. if(rate <= 0)
  891. settings.setValue("frequency", QString{});
  892. else
  893. settings.setValue("frequency", rate);
  894. settings.setValue("period_size", ui->periodSizeEdit->text());
  895. settings.setValue("periods", ui->periodCountEdit->text());
  896. settings.setValue("sources", ui->srcCountLineEdit->text());
  897. settings.setValue("slots", ui->effectSlotLineEdit->text());
  898. settings.setValue("resampler", resamplerList[ui->resamplerSlider->value()].value);
  899. settings.setValue("stereo-mode", getValueFromName(stereoModeList, ui->stereoModeCombo->currentText()));
  900. settings.setValue("stereo-encoding", getValueFromName(stereoEncList, ui->stereoEncodingComboBox->currentText()));
  901. settings.setValue("ambi-format", getValueFromName(ambiFormatList, ui->ambiFormatComboBox->currentText()));
  902. settings.setValue("output-limiter", getCheckValue(ui->outputLimiterCheckBox));
  903. settings.setValue("dither", getCheckValue(ui->outputDitherCheckBox));
  904. settings.setValue("decoder/hq-mode", getCheckValue(ui->decoderHQModeCheckBox));
  905. settings.setValue("decoder/distance-comp", getCheckValue(ui->decoderDistCompCheckBox));
  906. settings.setValue("decoder/nfc", getCheckValue(ui->decoderNFEffectsCheckBox));
  907. double refdelay = ui->decoderNFRefDelaySpinBox->value();
  908. settings.setValue("decoder/nfc-ref-delay",
  909. (refdelay > 0.0) ? QString::number(refdelay) : QString{}
  910. );
  911. settings.setValue("decoder/quad", ui->decoderQuadLineEdit->text());
  912. settings.setValue("decoder/surround51", ui->decoder51LineEdit->text());
  913. settings.setValue("decoder/surround61", ui->decoder61LineEdit->text());
  914. settings.setValue("decoder/surround71", ui->decoder71LineEdit->text());
  915. QStringList strlist;
  916. if(!ui->enableSSECheckBox->isChecked())
  917. strlist.append("sse");
  918. if(!ui->enableSSE2CheckBox->isChecked())
  919. strlist.append("sse2");
  920. if(!ui->enableSSE3CheckBox->isChecked())
  921. strlist.append("sse3");
  922. if(!ui->enableSSE41CheckBox->isChecked())
  923. strlist.append("sse4.1");
  924. if(!ui->enableNeonCheckBox->isChecked())
  925. strlist.append("neon");
  926. settings.setValue("disable-cpu-exts", strlist.join(QChar(',')));
  927. settings.setValue("hrtf-mode", hrtfModeList[ui->hrtfmodeSlider->value()].value);
  928. if(ui->hrtfStateComboBox->currentIndex() == 1)
  929. settings.setValue("hrtf", "true");
  930. else if(ui->hrtfStateComboBox->currentIndex() == 2)
  931. settings.setValue("hrtf", "false");
  932. else
  933. settings.setValue("hrtf", QString{});
  934. if(ui->preferredHrtfComboBox->currentIndex() == 0)
  935. settings.setValue("default-hrtf", QString{});
  936. else
  937. {
  938. QString str{ui->preferredHrtfComboBox->currentText()};
  939. settings.setValue("default-hrtf", str);
  940. }
  941. strlist.clear();
  942. strlist.reserve(ui->hrtfFileList->count());
  943. for(int i = 0;i < ui->hrtfFileList->count();i++)
  944. strlist.append(ui->hrtfFileList->item(i)->text());
  945. if(!strlist.empty() && ui->defaultHrtfPathsCheckBox->isChecked())
  946. strlist.append(QString{});
  947. settings.setValue("hrtf-paths", strlist.join(QChar{','}));
  948. strlist.clear();
  949. for(int i = 0;i < ui->enabledBackendList->count();i++)
  950. {
  951. QString label{ui->enabledBackendList->item(i)->text()};
  952. for(int j = 0;backendList[j].backend_name[0];j++)
  953. {
  954. if(label == backendList[j].full_string)
  955. {
  956. strlist.append(backendList[j].backend_name);
  957. break;
  958. }
  959. }
  960. }
  961. for(int i = 0;i < ui->disabledBackendList->count();i++)
  962. {
  963. QString label{ui->disabledBackendList->item(i)->text()};
  964. for(int j = 0;backendList[j].backend_name[0];j++)
  965. {
  966. if(label == backendList[j].full_string)
  967. {
  968. strlist.append(QChar{'-'}+QString{backendList[j].backend_name});
  969. break;
  970. }
  971. }
  972. }
  973. if(strlist.size() == 0 && !ui->backendCheckBox->isChecked())
  974. strlist.append("-all");
  975. else if(ui->backendCheckBox->isChecked())
  976. strlist.append(QString{});
  977. settings.setValue("drivers", strlist.join(QChar(',')));
  978. // TODO: Remove check when we can properly match global values.
  979. if(ui->defaultReverbComboBox->currentIndex() == 0)
  980. settings.setValue("default-reverb", QString{});
  981. else
  982. {
  983. QString str{ui->defaultReverbComboBox->currentText().toLower()};
  984. settings.setValue("default-reverb", str);
  985. }
  986. strlist.clear();
  987. if(!ui->enableEaxReverbCheck->isChecked())
  988. strlist.append("eaxreverb");
  989. if(!ui->enableStdReverbCheck->isChecked())
  990. strlist.append("reverb");
  991. if(!ui->enableAutowahCheck->isChecked())
  992. strlist.append("autowah");
  993. if(!ui->enableChorusCheck->isChecked())
  994. strlist.append("chorus");
  995. if(!ui->enableDistortionCheck->isChecked())
  996. strlist.append("distortion");
  997. if(!ui->enableCompressorCheck->isChecked())
  998. strlist.append("compressor");
  999. if(!ui->enableEchoCheck->isChecked())
  1000. strlist.append("echo");
  1001. if(!ui->enableEqualizerCheck->isChecked())
  1002. strlist.append("equalizer");
  1003. if(!ui->enableFlangerCheck->isChecked())
  1004. strlist.append("flanger");
  1005. if(!ui->enableFrequencyShifterCheck->isChecked())
  1006. strlist.append("fshifter");
  1007. if(!ui->enableModulatorCheck->isChecked())
  1008. strlist.append("modulator");
  1009. if(!ui->enableDedicatedCheck->isChecked())
  1010. strlist.append("dedicated");
  1011. if(!ui->enablePitchShifterCheck->isChecked())
  1012. strlist.append("pshifter");
  1013. if(!ui->enableVocalMorpherCheck->isChecked())
  1014. strlist.append("vmorpher");
  1015. settings.setValue("excludefx", strlist.join(QChar{','}));
  1016. settings.setValue("eax/enable",
  1017. (!ui->enableEaxCheck->isEnabled() || ui->enableEaxCheck->isChecked())
  1018. ? QString{/*"true"*/} : QString{"false"});
  1019. settings.setValue("pulse/spawn-server", getCheckValue(ui->pulseAutospawnCheckBox));
  1020. settings.setValue("pulse/allow-moves", getCheckValue(ui->pulseAllowMovesCheckBox));
  1021. settings.setValue("pulse/fix-rate", getCheckValue(ui->pulseFixRateCheckBox));
  1022. settings.setValue("pulse/adjust-latency", getCheckValue(ui->pulseAdjLatencyCheckBox));
  1023. settings.setValue("pipewire/assume-audio", ui->pwireAssumeAudioCheckBox->isChecked()
  1024. ? QString{"true"} : QString{/*"false"*/});
  1025. settings.setValue("jack/spawn-server", getCheckValue(ui->jackAutospawnCheckBox));
  1026. settings.setValue("jack/connect-ports", getCheckValue(ui->jackConnectPortsCheckBox));
  1027. settings.setValue("jack/rt-mix", getCheckValue(ui->jackRtMixCheckBox));
  1028. settings.setValue("jack/buffer-size", ui->jackBufferSizeLine->text());
  1029. settings.setValue("alsa/device", ui->alsaDefaultDeviceLine->text());
  1030. settings.setValue("alsa/capture", ui->alsaDefaultCaptureLine->text());
  1031. settings.setValue("alsa/allow-resampler", getCheckValue(ui->alsaResamplerCheckBox));
  1032. settings.setValue("alsa/mmap", getCheckValue(ui->alsaMmapCheckBox));
  1033. settings.setValue("oss/device", ui->ossDefaultDeviceLine->text());
  1034. settings.setValue("oss/capture", ui->ossDefaultCaptureLine->text());
  1035. settings.setValue("solaris/device", ui->solarisDefaultDeviceLine->text());
  1036. settings.setValue("wave/file", ui->waveOutputLine->text());
  1037. settings.setValue("wave/bformat",
  1038. ui->waveBFormatCheckBox->isChecked() ? QString{"true"} : QString{/*"false"*/}
  1039. );
  1040. /* Remove empty keys
  1041. * FIXME: Should only remove keys whose value matches the globally-specified value.
  1042. */
  1043. allkeys = settings.allKeys();
  1044. foreach(const QString &key, allkeys)
  1045. {
  1046. QString str{settings.value(key).toString()};
  1047. if(str == QString{})
  1048. settings.remove(key);
  1049. }
  1050. }
  1051. void MainWindow::enableApplyButton()
  1052. {
  1053. if(!mNeedsSave)
  1054. ui->applyButton->setEnabled(true);
  1055. mNeedsSave = true;
  1056. ui->closeCancelButton->setText(tr("Cancel"));
  1057. }
  1058. void MainWindow::updateResamplerLabel(int num)
  1059. {
  1060. ui->resamplerLabel->setText(resamplerList[num].name);
  1061. enableApplyButton();
  1062. }
  1063. void MainWindow::updatePeriodSizeEdit(int size)
  1064. {
  1065. ui->periodSizeEdit->clear();
  1066. if(size >= 64)
  1067. ui->periodSizeEdit->insert(QString::number(size));
  1068. enableApplyButton();
  1069. }
  1070. void MainWindow::updatePeriodSizeSlider()
  1071. {
  1072. int pos = ui->periodSizeEdit->text().toInt();
  1073. if(pos >= 64)
  1074. {
  1075. if(pos > 8192)
  1076. pos = 8192;
  1077. ui->periodSizeSlider->setSliderPosition(pos);
  1078. }
  1079. enableApplyButton();
  1080. }
  1081. void MainWindow::updatePeriodCountEdit(int count)
  1082. {
  1083. ui->periodCountEdit->clear();
  1084. if(count >= 2)
  1085. ui->periodCountEdit->insert(QString::number(count));
  1086. enableApplyButton();
  1087. }
  1088. void MainWindow::updatePeriodCountSlider()
  1089. {
  1090. int pos = ui->periodCountEdit->text().toInt();
  1091. if(pos < 2)
  1092. pos = 0;
  1093. else if(pos > 16)
  1094. pos = 16;
  1095. ui->periodCountSlider->setSliderPosition(pos);
  1096. enableApplyButton();
  1097. }
  1098. void MainWindow::selectQuadDecoderFile()
  1099. { selectDecoderFile(ui->decoderQuadLineEdit, "Select Quadraphonic Decoder");}
  1100. void MainWindow::select51DecoderFile()
  1101. { selectDecoderFile(ui->decoder51LineEdit, "Select 5.1 Surround Decoder");}
  1102. void MainWindow::select61DecoderFile()
  1103. { selectDecoderFile(ui->decoder61LineEdit, "Select 6.1 Surround Decoder");}
  1104. void MainWindow::select71DecoderFile()
  1105. { selectDecoderFile(ui->decoder71LineEdit, "Select 7.1 Surround Decoder");}
  1106. void MainWindow::select3D71DecoderFile()
  1107. { selectDecoderFile(ui->decoder3D71LineEdit, "Select 3D7.1 Surround Decoder");}
  1108. void MainWindow::selectDecoderFile(QLineEdit *line, const char *caption)
  1109. {
  1110. QString dir{line->text()};
  1111. if(dir.isEmpty() || QDir::isRelativePath(dir))
  1112. {
  1113. QStringList paths{getAllDataPaths("/openal/presets")};
  1114. while(!paths.isEmpty())
  1115. {
  1116. if(QDir{paths.last()}.exists())
  1117. {
  1118. dir = paths.last();
  1119. break;
  1120. }
  1121. paths.removeLast();
  1122. }
  1123. }
  1124. QString fname{QFileDialog::getOpenFileName(this, tr(caption),
  1125. dir, tr("AmbDec Files (*.ambdec);;All Files (*.*)"))};
  1126. if(!fname.isEmpty())
  1127. {
  1128. line->setText(fname);
  1129. enableApplyButton();
  1130. }
  1131. }
  1132. void MainWindow::updateJackBufferSizeEdit(int size)
  1133. {
  1134. ui->jackBufferSizeLine->clear();
  1135. if(size > 0)
  1136. ui->jackBufferSizeLine->insert(QString::number(1<<size));
  1137. enableApplyButton();
  1138. }
  1139. void MainWindow::updateJackBufferSizeSlider()
  1140. {
  1141. int value{ui->jackBufferSizeLine->text().toInt()};
  1142. auto pos = static_cast<int>(floor(log2(value) + 0.5));
  1143. ui->jackBufferSizeSlider->setSliderPosition(pos);
  1144. enableApplyButton();
  1145. }
  1146. void MainWindow::updateHrtfModeLabel(int num)
  1147. {
  1148. ui->hrtfmodeLabel->setText(hrtfModeList[num].name);
  1149. enableApplyButton();
  1150. }
  1151. void MainWindow::addHrtfFile()
  1152. {
  1153. QString path{QFileDialog::getExistingDirectory(this, tr("Select HRTF Path"))};
  1154. if(path.isEmpty() == false && !getAllDataPaths("/openal/hrtf").contains(path))
  1155. {
  1156. ui->hrtfFileList->addItem(path);
  1157. enableApplyButton();
  1158. }
  1159. }
  1160. void MainWindow::removeHrtfFile()
  1161. {
  1162. QList<QListWidgetItem*> selected{ui->hrtfFileList->selectedItems()};
  1163. if(!selected.isEmpty())
  1164. {
  1165. foreach(QListWidgetItem *item, selected)
  1166. delete item;
  1167. enableApplyButton();
  1168. }
  1169. }
  1170. void MainWindow::updateHrtfRemoveButton()
  1171. {
  1172. ui->hrtfRemoveButton->setEnabled(ui->hrtfFileList->selectedItems().size() != 0);
  1173. }
  1174. void MainWindow::showEnabledBackendMenu(QPoint pt)
  1175. {
  1176. QHash<QAction*,QString> actionMap;
  1177. pt = ui->enabledBackendList->mapToGlobal(pt);
  1178. QMenu ctxmenu;
  1179. QAction *removeAction{ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove")};
  1180. if(ui->enabledBackendList->selectedItems().size() == 0)
  1181. removeAction->setEnabled(false);
  1182. ctxmenu.addSeparator();
  1183. for(size_t i = 0;backendList[i].backend_name[0];i++)
  1184. {
  1185. QString backend{backendList[i].full_string};
  1186. QAction *action{ctxmenu.addAction(QString("Add ")+backend)};
  1187. actionMap[action] = backend;
  1188. if(ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0 ||
  1189. ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0)
  1190. action->setEnabled(false);
  1191. }
  1192. QAction *gotAction{ctxmenu.exec(pt)};
  1193. if(gotAction == removeAction)
  1194. {
  1195. QList<QListWidgetItem*> selected{ui->enabledBackendList->selectedItems()};
  1196. foreach(QListWidgetItem *item, selected)
  1197. delete item;
  1198. enableApplyButton();
  1199. }
  1200. else if(gotAction != nullptr)
  1201. {
  1202. auto iter = actionMap.constFind(gotAction);
  1203. if(iter != actionMap.cend())
  1204. ui->enabledBackendList->addItem(iter.value());
  1205. enableApplyButton();
  1206. }
  1207. }
  1208. void MainWindow::showDisabledBackendMenu(QPoint pt)
  1209. {
  1210. QHash<QAction*,QString> actionMap;
  1211. pt = ui->disabledBackendList->mapToGlobal(pt);
  1212. QMenu ctxmenu;
  1213. QAction *removeAction{ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove")};
  1214. if(ui->disabledBackendList->selectedItems().size() == 0)
  1215. removeAction->setEnabled(false);
  1216. ctxmenu.addSeparator();
  1217. for(size_t i = 0;backendList[i].backend_name[0];i++)
  1218. {
  1219. QString backend{backendList[i].full_string};
  1220. QAction *action{ctxmenu.addAction(QString("Add ")+backend)};
  1221. actionMap[action] = backend;
  1222. if(ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0 ||
  1223. ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0)
  1224. action->setEnabled(false);
  1225. }
  1226. QAction *gotAction{ctxmenu.exec(pt)};
  1227. if(gotAction == removeAction)
  1228. {
  1229. QList<QListWidgetItem*> selected{ui->disabledBackendList->selectedItems()};
  1230. foreach(QListWidgetItem *item, selected)
  1231. delete item;
  1232. enableApplyButton();
  1233. }
  1234. else if(gotAction != nullptr)
  1235. {
  1236. auto iter = actionMap.constFind(gotAction);
  1237. if(iter != actionMap.cend())
  1238. ui->disabledBackendList->addItem(iter.value());
  1239. enableApplyButton();
  1240. }
  1241. }
  1242. void MainWindow::selectOSSPlayback()
  1243. {
  1244. QString current{ui->ossDefaultDeviceLine->text()};
  1245. if(current.isEmpty()) current = ui->ossDefaultDeviceLine->placeholderText();
  1246. QString fname{QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current)};
  1247. if(!fname.isEmpty())
  1248. {
  1249. ui->ossDefaultDeviceLine->setText(fname);
  1250. enableApplyButton();
  1251. }
  1252. }
  1253. void MainWindow::selectOSSCapture()
  1254. {
  1255. QString current{ui->ossDefaultCaptureLine->text()};
  1256. if(current.isEmpty()) current = ui->ossDefaultCaptureLine->placeholderText();
  1257. QString fname{QFileDialog::getOpenFileName(this, tr("Select Capture Device"), current)};
  1258. if(!fname.isEmpty())
  1259. {
  1260. ui->ossDefaultCaptureLine->setText(fname);
  1261. enableApplyButton();
  1262. }
  1263. }
  1264. void MainWindow::selectSolarisPlayback()
  1265. {
  1266. QString current{ui->solarisDefaultDeviceLine->text()};
  1267. if(current.isEmpty()) current = ui->solarisDefaultDeviceLine->placeholderText();
  1268. QString fname{QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current)};
  1269. if(!fname.isEmpty())
  1270. {
  1271. ui->solarisDefaultDeviceLine->setText(fname);
  1272. enableApplyButton();
  1273. }
  1274. }
  1275. void MainWindow::selectWaveOutput()
  1276. {
  1277. QString fname{QFileDialog::getSaveFileName(this, tr("Select Wave File Output"),
  1278. ui->waveOutputLine->text(), tr("Wave Files (*.wav *.amb);;All Files (*.*)"))};
  1279. if(!fname.isEmpty())
  1280. {
  1281. ui->waveOutputLine->setText(fname);
  1282. enableApplyButton();
  1283. }
  1284. }