mainwindow.cpp 49 KB

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