mainwindow.cpp 57 KB

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