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

1359 lines
49 KiB

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