mainwindow.cpp 51 KB

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