mainwindow.cpp 49 KB

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