mainwindow.cpp 50 KB

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