Properly remove empty config values
[openal-soft.git] / utils / alsoft-config / mainwindow.cpp
blob1fd6f81e52c50671605c5a0b4b0f9c0598f81f8e
2 #include "config.h"
4 #include <QFileDialog>
5 #include <QMessageBox>
6 #include <QCloseEvent>
7 #include <QSettings>
8 #include <QtGlobal>
9 #include "mainwindow.h"
10 #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
57 { "null", "Null Output" },
58 #ifdef HAVE_WAVE
59 { "wave", "Wave Writer" },
60 #endif
61 { "", "" }
64 static const struct {
65 const char name[64];
66 const char value[16];
67 } speakerModeList[] = {
68 { "Autodetect", "" },
69 { "Mono", "mono" },
70 { "Stereo", "stereo" },
71 { "Quadrophonic", "quad" },
72 { "5.1 Surround (Side)", "surround51" },
73 { "5.1 Surround (Rear)", "surround51rear" },
74 { "6.1 Surround", "surround61" },
75 { "7.1 Surround", "surround71" },
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" },
88 { "", "" }
89 }, resamplerList[] = {
90 { "Point", "point" },
91 { "Linear", "linear" },
92 { "Default (Linear)", "" },
93 { "4-Point Sinc", "sinc4" },
94 { "8-Point Sinc", "sinc8" },
95 { "Band-limited Sinc", "bsinc" },
97 { "", "" }
98 }, stereoModeList[] = {
99 { "Autodetect", "" },
100 { "Speakers", "speakers" },
101 { "Headphones", "headphones" },
103 { "", "" }
106 static QString getDefaultConfigName()
108 #ifdef Q_OS_WIN32
109 static const char fname[] = "alsoft.ini";
110 QByteArray base = qgetenv("AppData");
111 #else
112 static const char fname[] = "alsoft.conf";
113 QByteArray base = qgetenv("XDG_CONFIG_HOME");
114 if(base.isEmpty())
116 base = qgetenv("HOME");
117 if(base.isEmpty() == false)
118 base += "/.config";
120 #endif
121 if(base.isEmpty() == false)
122 return base +'/'+ fname;
123 return fname;
126 static QString getBaseDataPath()
128 #ifdef Q_OS_WIN32
129 QByteArray base = qgetenv("AppData");
130 #else
131 QByteArray base = qgetenv("XDG_DATA_HOME");
132 if(base.isEmpty())
134 base = qgetenv("HOME");
135 if(!base.isEmpty())
136 base += "/.local/share";
138 #endif
139 return base;
142 static QStringList getAllDataPaths(QString append=QString())
144 QStringList list;
145 list.append(getBaseDataPath());
146 #ifdef Q_OS_WIN32
147 // TODO: Common AppData path
148 #else
149 QString paths = qgetenv("XDG_DATA_DIRS");
150 if(paths.isEmpty())
151 paths = "/usr/local/share/:/usr/share/";
152 list += paths.split(QChar(':'), QString::SkipEmptyParts);
153 #endif
154 QStringList::iterator iter = list.begin();
155 while(iter != list.end())
157 if(iter->isEmpty())
158 iter = list.erase(iter);
159 else
161 iter->append(append);
162 iter++;
165 return list;
169 MainWindow::MainWindow(QWidget *parent) :
170 QMainWindow(parent),
171 ui(new Ui::MainWindow),
172 mPeriodSizeValidator(NULL),
173 mPeriodCountValidator(NULL),
174 mSourceCountValidator(NULL),
175 mEffectSlotValidator(NULL),
176 mSourceSendValidator(NULL),
177 mSampleRateValidator(NULL),
178 mNeedsSave(false)
180 ui->setupUi(this);
182 for(int i = 0;speakerModeList[i].name[0];i++)
183 ui->channelConfigCombo->addItem(speakerModeList[i].name);
184 ui->channelConfigCombo->adjustSize();
185 for(int i = 0;sampleTypeList[i].name[0];i++)
186 ui->sampleFormatCombo->addItem(sampleTypeList[i].name);
187 ui->sampleFormatCombo->adjustSize();
188 for(int i = 0;stereoModeList[i].name[0];i++)
189 ui->stereoModeCombo->addItem(stereoModeList[i].name);
190 ui->stereoModeCombo->adjustSize();
192 int count;
193 for(count = 0;resamplerList[count].name[0];count++) {
195 ui->resamplerSlider->setRange(0, count-1);
197 ui->hrtfStateComboBox->adjustSize();
199 #if !defined(HAVE_NEON) && !defined(HAVE_SSE)
200 ui->cpuExtDisabledLabel->move(ui->cpuExtDisabledLabel->x(), ui->cpuExtDisabledLabel->y() - 60);
201 #else
202 ui->cpuExtDisabledLabel->setVisible(false);
203 #endif
205 #ifndef HAVE_NEON
207 #ifndef HAVE_SSE4_1
208 #ifndef HAVE_SSE3
209 #ifndef HAVE_SSE2
210 #ifndef HAVE_SSE
211 ui->enableSSECheckBox->setVisible(false);
212 #endif /* !SSE */
213 ui->enableSSE2CheckBox->setVisible(false);
214 #endif /* !SSE2 */
215 ui->enableSSE3CheckBox->setVisible(false);
216 #endif /* !SSE3 */
217 ui->enableSSE41CheckBox->setVisible(false);
218 #endif /* !SSE4.1 */
219 ui->enableNeonCheckBox->setVisible(false);
221 #else /* !Neon */
223 #ifndef HAVE_SSE4_1
224 #ifndef HAVE_SSE3
225 #ifndef HAVE_SSE2
226 #ifndef HAVE_SSE
227 ui->enableNeonCheckBox->move(ui->enableNeonCheckBox->x(), ui->enableNeonCheckBox->y() - 30);
228 ui->enableSSECheckBox->setVisible(false);
229 #endif /* !SSE */
230 ui->enableSSE2CheckBox->setVisible(false);
231 #endif /* !SSE2 */
232 ui->enableSSE3CheckBox->setVisible(false);
233 #endif /* !SSE3 */
234 ui->enableSSE41CheckBox->setVisible(false);
235 #endif /* !SSE4.1 */
237 #endif
239 mPeriodSizeValidator = new QIntValidator(64, 8192, this);
240 ui->periodSizeEdit->setValidator(mPeriodSizeValidator);
241 mPeriodCountValidator = new QIntValidator(2, 16, this);
242 ui->periodCountEdit->setValidator(mPeriodCountValidator);
244 mSourceCountValidator = new QIntValidator(0, 256, this);
245 ui->srcCountLineEdit->setValidator(mSourceCountValidator);
246 mEffectSlotValidator = new QIntValidator(0, 16, this);
247 ui->effectSlotLineEdit->setValidator(mEffectSlotValidator);
248 mSourceSendValidator = new QIntValidator(0, 4, this);
249 ui->srcSendLineEdit->setValidator(mSourceSendValidator);
250 mSampleRateValidator = new QIntValidator(8000, 192000, this);
251 ui->sampleRateCombo->lineEdit()->setValidator(mSampleRateValidator);
253 connect(ui->actionLoad, SIGNAL(triggered()), this, SLOT(loadConfigFromFile()));
254 connect(ui->actionSave_As, SIGNAL(triggered()), this, SLOT(saveConfigAsFile()));
256 connect(ui->closeCancelButton, SIGNAL(clicked()), this, SLOT(cancelCloseAction()));
257 connect(ui->applyButton, SIGNAL(clicked()), this, SLOT(saveCurrentConfig()));
259 connect(ui->channelConfigCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
260 connect(ui->sampleFormatCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
261 connect(ui->stereoModeCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
262 connect(ui->sampleRateCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
263 connect(ui->sampleRateCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(enableApplyButton()));
265 connect(ui->resamplerSlider, SIGNAL(valueChanged(int)), this, SLOT(updateResamplerLabel(int)));
267 connect(ui->periodSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(updatePeriodSizeEdit(int)));
268 connect(ui->periodSizeEdit, SIGNAL(editingFinished()), this, SLOT(updatePeriodSizeSlider()));
269 connect(ui->periodCountSlider, SIGNAL(valueChanged(int)), this, SLOT(updatePeriodCountEdit(int)));
270 connect(ui->periodCountEdit, SIGNAL(editingFinished()), this, SLOT(updatePeriodCountSlider()));
272 connect(ui->stereoPanningComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(enableApplyButton()));
274 connect(ui->preferredHrtfComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
275 connect(ui->hrtfStateComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
276 connect(ui->hrtfAddButton, SIGNAL(clicked()), this, SLOT(addHrtfFile()));
277 connect(ui->hrtfRemoveButton, SIGNAL(clicked()), this, SLOT(removeHrtfFile()));
278 connect(ui->hrtfFileList, SIGNAL(itemSelectionChanged()), this, SLOT(updateHrtfRemoveButton()));
279 connect(ui->defaultHrtfPathsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
281 connect(ui->srcCountLineEdit, SIGNAL(editingFinished()), this, SLOT(enableApplyButton()));
282 connect(ui->srcSendLineEdit, SIGNAL(editingFinished()), this, SLOT(enableApplyButton()));
283 connect(ui->effectSlotLineEdit, SIGNAL(editingFinished()), this, SLOT(enableApplyButton()));
285 connect(ui->enableSSECheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
286 connect(ui->enableSSE2CheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
287 connect(ui->enableSSE3CheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
288 connect(ui->enableSSE41CheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
289 connect(ui->enableNeonCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
291 ui->enabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
292 connect(ui->enabledBackendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showEnabledBackendMenu(QPoint)));
294 ui->disabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
295 connect(ui->disabledBackendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showDisabledBackendMenu(QPoint)));
296 connect(ui->backendCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
298 connect(ui->defaultReverbComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
299 connect(ui->emulateEaxCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
300 connect(ui->enableEaxReverbCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
301 connect(ui->enableStdReverbCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
302 connect(ui->enableChorusCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
303 connect(ui->enableCompressorCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
304 connect(ui->enableDistortionCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
305 connect(ui->enableEchoCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
306 connect(ui->enableEqualizerCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
307 connect(ui->enableFlangerCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
308 connect(ui->enableModulatorCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
309 connect(ui->enableDedicatedCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
311 connect(ui->pulseAutospawnCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
312 connect(ui->pulseAllowMovesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
313 connect(ui->pulseFixRateCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
315 connect(ui->alsaDefaultDeviceLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
316 connect(ui->alsaDefaultCaptureLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
317 connect(ui->alsaResamplerCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
318 connect(ui->alsaMmapCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
320 ui->backendListWidget->setCurrentRow(0);
321 ui->tabWidget->setCurrentIndex(0);
323 for(int i = 1;i < ui->backendListWidget->count();i++)
324 ui->backendListWidget->setRowHidden(i, true);
325 for(int i = 0;backendList[i].backend_name[0];i++)
327 QList<QListWidgetItem*> items = ui->backendListWidget->findItems(
328 backendList[i].full_string, Qt::MatchFixedString
330 foreach(const QListWidgetItem *item, items)
331 ui->backendListWidget->setItemHidden(item, false);
334 loadConfig(getDefaultConfigName());
337 MainWindow::~MainWindow()
339 delete ui;
340 delete mPeriodSizeValidator;
341 delete mPeriodCountValidator;
342 delete mSourceCountValidator;
343 delete mEffectSlotValidator;
344 delete mSourceSendValidator;
345 delete mSampleRateValidator;
348 void MainWindow::closeEvent(QCloseEvent *event)
350 if(!mNeedsSave)
351 event->accept();
352 else
354 QMessageBox::StandardButton btn = QMessageBox::warning(this,
355 tr("Apply changes?"), tr("Save changes before quitting?"),
356 QMessageBox::Save | QMessageBox::No | QMessageBox::Cancel
358 if(btn == QMessageBox::Save)
359 saveCurrentConfig();
360 if(btn == QMessageBox::Cancel)
361 event->ignore();
362 else
363 event->accept();
367 void MainWindow::cancelCloseAction()
369 mNeedsSave = false;
370 close();
374 QStringList MainWindow::collectHrtfs()
376 QStringList ret;
378 for(int i = 0;i < ui->hrtfFileList->count();i++)
380 QDir dir(ui->hrtfFileList->item(i)->text());
381 QStringList fnames = dir.entryList(QDir::Files | QDir::Readable, QDir::Name);
382 foreach(const QString &fname, fnames)
384 if(!fname.endsWith(".mhr", Qt::CaseInsensitive))
385 continue;
387 QString name = fname.left(fname.length()-4);
388 if(!ret.contains(name))
389 ret.push_back(name);
390 else
392 size_t i = 1;
393 do {
394 QString s = name+" #"+QString::number(i);
395 if(!ret.contains(s))
397 ret.push_back(s);
398 break;
400 ++i;
401 } while(1);
406 if(ui->defaultHrtfPathsCheckBox->isChecked())
408 QStringList paths = getAllDataPaths("/openal/hrtf");
409 foreach(const QString &name, paths)
411 QDir dir(name);
412 QStringList fnames = dir.entryList(QDir::Files | QDir::Readable, QDir::Name);
413 foreach(const QString &fname, fnames)
415 if(!fname.endsWith(".mhr", Qt::CaseInsensitive))
416 continue;
418 QString name = fname.left(fname.length()-4);
419 if(!ret.contains(name))
420 ret.push_back(name);
421 else
423 size_t i = 1;
424 do {
425 QString s = name+" #"+QString::number(i);
426 if(!ret.contains(s))
428 ret.push_back(s);
429 break;
431 ++i;
432 } while(1);
437 return ret;
441 void MainWindow::loadConfigFromFile()
443 QString fname = QFileDialog::getOpenFileName(this, tr("Select Files"));
444 if(fname.isEmpty() == false)
445 loadConfig(fname);
448 void MainWindow::loadConfig(const QString &fname)
450 QSettings settings(fname, QSettings::IniFormat);
452 QString sampletype = settings.value("sample-type").toString();
453 ui->sampleFormatCombo->setCurrentIndex(0);
454 if(sampletype.isEmpty() == false)
456 for(int i = 0;sampleTypeList[i].name[i];i++)
458 if(sampletype == sampleTypeList[i].value)
460 int j = ui->sampleFormatCombo->findText(sampleTypeList[i].name);
461 if(j > 0) ui->sampleFormatCombo->setCurrentIndex(j);
462 break;
467 QString channelconfig = settings.value("channels").toString();
468 ui->channelConfigCombo->setCurrentIndex(0);
469 if(channelconfig.isEmpty() == false)
471 for(int i = 0;speakerModeList[i].name[i];i++)
473 if(channelconfig == speakerModeList[i].value)
475 int j = ui->channelConfigCombo->findText(speakerModeList[i].name);
476 if(j > 0) ui->channelConfigCombo->setCurrentIndex(j);
477 break;
482 QString srate = settings.value("frequency").toString();
483 if(srate.isEmpty())
484 ui->sampleRateCombo->setCurrentIndex(0);
485 else
487 ui->sampleRateCombo->lineEdit()->clear();
488 ui->sampleRateCombo->lineEdit()->insert(srate);
491 ui->srcCountLineEdit->clear();
492 ui->srcCountLineEdit->insert(settings.value("sources").toString());
493 ui->effectSlotLineEdit->clear();
494 ui->effectSlotLineEdit->insert(settings.value("slots").toString());
495 ui->srcSendLineEdit->clear();
496 ui->srcSendLineEdit->insert(settings.value("sends").toString());
498 QString resampler = settings.value("resampler").toString().trimmed();
499 ui->resamplerSlider->setValue(0);
500 /* The "cubic" resampler is no longer supported. It's been replaced by
501 * "sinc4". */
502 if(resampler == "cubic")
503 resampler = "sinc4";
504 for(int i = 0;resamplerList[i].name[i];i++)
506 if(resampler == resamplerList[i].value)
508 ui->resamplerSlider->setValue(i);
509 break;
513 QString stereomode = settings.value("stereo-mode").toString().trimmed();
514 ui->stereoModeCombo->setCurrentIndex(0);
515 if(stereomode.isEmpty() == false)
517 for(int i = 0;stereoModeList[i].name[i];i++)
519 if(stereomode == stereoModeList[i].value)
521 int j = ui->stereoModeCombo->findText(stereoModeList[i].name);
522 if(j > 0) ui->stereoModeCombo->setCurrentIndex(j);
523 break;
528 int periodsize = settings.value("period_size").toInt();
529 ui->periodSizeEdit->clear();
530 if(periodsize >= 64)
532 ui->periodSizeEdit->insert(QString::number(periodsize));
533 updatePeriodSizeSlider();
536 int periodcount = settings.value("periods").toInt();
537 ui->periodCountEdit->clear();
538 if(periodcount >= 2)
540 ui->periodCountEdit->insert(QString::number(periodcount));
541 updatePeriodCountSlider();
544 QString stereopan = settings.value("stereo-panning").toString();
545 if(stereopan == "uhj")
546 ui->stereoPanningComboBox->setCurrentIndex(1);
547 else if(stereopan == "paired")
548 ui->stereoPanningComboBox->setCurrentIndex(2);
549 else
550 ui->stereoPanningComboBox->setCurrentIndex(0);
552 QStringList disabledCpuExts = settings.value("disable-cpu-exts").toStringList();
553 if(disabledCpuExts.size() == 1)
554 disabledCpuExts = disabledCpuExts[0].split(QChar(','));
555 std::transform(disabledCpuExts.begin(), disabledCpuExts.end(),
556 disabledCpuExts.begin(), std::mem_fun_ref(&QString::trimmed));
557 ui->enableSSECheckBox->setChecked(!disabledCpuExts.contains("sse", Qt::CaseInsensitive));
558 ui->enableSSE2CheckBox->setChecked(!disabledCpuExts.contains("sse2", Qt::CaseInsensitive));
559 ui->enableSSE3CheckBox->setChecked(!disabledCpuExts.contains("sse3", Qt::CaseInsensitive));
560 ui->enableSSE41CheckBox->setChecked(!disabledCpuExts.contains("sse4.1", Qt::CaseInsensitive));
561 ui->enableNeonCheckBox->setChecked(!disabledCpuExts.contains("neon", Qt::CaseInsensitive));
563 QStringList hrtf_paths = settings.value("hrtf-paths").toStringList();
564 if(hrtf_paths.size() == 1)
565 hrtf_paths = hrtf_paths[0].split(QChar(','));
566 std::transform(hrtf_paths.begin(), hrtf_paths.end(),
567 hrtf_paths.begin(), std::mem_fun_ref(&QString::trimmed));
568 if(!hrtf_paths.empty() && !hrtf_paths.back().isEmpty())
569 ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Unchecked);
570 else
572 hrtf_paths.removeAll(QString());
573 ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Checked);
575 hrtf_paths.removeDuplicates();
576 ui->hrtfFileList->clear();
577 ui->hrtfFileList->addItems(hrtf_paths);
578 updateHrtfRemoveButton();
580 QString hrtfstate = settings.value("hrtf").toString().toLower();
581 if(hrtfstate == "true")
582 ui->hrtfStateComboBox->setCurrentIndex(1);
583 else if(hrtfstate == "false")
584 ui->hrtfStateComboBox->setCurrentIndex(2);
585 else
586 ui->hrtfStateComboBox->setCurrentIndex(0);
588 ui->preferredHrtfComboBox->clear();
589 ui->preferredHrtfComboBox->addItem("- Any -");
590 if(ui->defaultHrtfPathsCheckBox->isChecked())
592 QStringList hrtfs = collectHrtfs();
593 foreach(const QString &name, hrtfs)
594 ui->preferredHrtfComboBox->addItem(name);
597 QString defaulthrtf = settings.value("default-hrtf").toString();
598 ui->preferredHrtfComboBox->setCurrentIndex(0);
599 if(defaulthrtf.isEmpty() == false)
601 int i = ui->preferredHrtfComboBox->findText(defaulthrtf);
602 if(i > 0)
603 ui->preferredHrtfComboBox->setCurrentIndex(i);
604 else
606 i = ui->preferredHrtfComboBox->count();
607 ui->preferredHrtfComboBox->addItem(defaulthrtf);
608 ui->preferredHrtfComboBox->setCurrentIndex(i);
611 ui->preferredHrtfComboBox->adjustSize();
613 ui->enabledBackendList->clear();
614 ui->disabledBackendList->clear();
615 QStringList drivers = settings.value("drivers").toStringList();
616 if(drivers.size() == 0)
617 ui->backendCheckBox->setChecked(true);
618 else
620 if(drivers.size() == 1)
621 drivers = drivers[0].split(QChar(','));
622 std::transform(drivers.begin(), drivers.end(),
623 drivers.begin(), std::mem_fun_ref(&QString::trimmed));
625 bool lastWasEmpty = false;
626 foreach(const QString &backend, drivers)
628 lastWasEmpty = backend.isEmpty();
629 if(lastWasEmpty) continue;
631 if(!backend.startsWith(QChar('-')))
632 for(int j = 0;backendList[j].backend_name[0];j++)
634 if(backend == backendList[j].backend_name)
636 ui->enabledBackendList->addItem(backendList[j].full_string);
637 break;
640 else if(backend.size() > 1)
642 QStringRef backendref = backend.rightRef(backend.size()-1);
643 for(int j = 0;backendList[j].backend_name[0];j++)
645 if(backendref == backendList[j].backend_name)
647 ui->disabledBackendList->addItem(backendList[j].full_string);
648 break;
653 ui->backendCheckBox->setChecked(lastWasEmpty);
656 QString defaultreverb = settings.value("default-reverb").toString().toLower();
657 ui->defaultReverbComboBox->setCurrentIndex(0);
658 if(defaultreverb.isEmpty() == false)
660 for(int i = 0;i < ui->defaultReverbComboBox->count();i++)
662 if(defaultreverb.compare(ui->defaultReverbComboBox->itemText(i).toLower()) == 0)
664 ui->defaultReverbComboBox->setCurrentIndex(i);
665 break;
670 ui->emulateEaxCheckBox->setChecked(settings.value("reverb/emulate-eax", false).toBool());
672 QStringList excludefx = settings.value("excludefx").toStringList();
673 if(excludefx.size() == 1)
674 excludefx = excludefx[0].split(QChar(','));
675 std::transform(excludefx.begin(), excludefx.end(),
676 excludefx.begin(), std::mem_fun_ref(&QString::trimmed));
677 ui->enableEaxReverbCheck->setChecked(!excludefx.contains("eaxreverb", Qt::CaseInsensitive));
678 ui->enableStdReverbCheck->setChecked(!excludefx.contains("reverb", Qt::CaseInsensitive));
679 ui->enableChorusCheck->setChecked(!excludefx.contains("chorus", Qt::CaseInsensitive));
680 ui->enableCompressorCheck->setChecked(!excludefx.contains("compressor", Qt::CaseInsensitive));
681 ui->enableDistortionCheck->setChecked(!excludefx.contains("distortion", Qt::CaseInsensitive));
682 ui->enableEchoCheck->setChecked(!excludefx.contains("echo", Qt::CaseInsensitive));
683 ui->enableEqualizerCheck->setChecked(!excludefx.contains("equalizer", Qt::CaseInsensitive));
684 ui->enableFlangerCheck->setChecked(!excludefx.contains("flanger", Qt::CaseInsensitive));
685 ui->enableModulatorCheck->setChecked(!excludefx.contains("modulator", Qt::CaseInsensitive));
686 ui->enableDedicatedCheck->setChecked(!excludefx.contains("dedicated", Qt::CaseInsensitive));
688 ui->pulseAutospawnCheckBox->setChecked(settings.value("pulse/spawn-server", true).toBool());
689 ui->pulseAllowMovesCheckBox->setChecked(settings.value("pulse/allow-moves", false).toBool());
690 ui->pulseFixRateCheckBox->setChecked(settings.value("pulse/fix-rate", false).toBool());
692 ui->alsaDefaultDeviceLine->setText(settings.value("alsa/device", QString()).toString());
693 ui->alsaDefaultCaptureLine->setText(settings.value("alsa/capture", QString()).toString());
694 ui->alsaResamplerCheckBox->setChecked(settings.value("alsa/allow-resampler", false).toBool());
695 ui->alsaMmapCheckBox->setChecked(settings.value("alsa/mmap", true).toBool());
697 ui->applyButton->setEnabled(false);
698 ui->closeCancelButton->setText(tr("Close"));
699 mNeedsSave = false;
702 void MainWindow::saveCurrentConfig()
704 saveConfig(getDefaultConfigName());
705 ui->applyButton->setEnabled(false);
706 ui->closeCancelButton->setText(tr("Close"));
707 mNeedsSave = false;
708 QMessageBox::information(this, tr("Information"),
709 tr("Applications using OpenAL need to be restarted for changes to take effect."));
712 void MainWindow::saveConfigAsFile()
714 QString fname = QFileDialog::getOpenFileName(this, tr("Select Files"));
715 if(fname.isEmpty() == false)
717 saveConfig(fname);
718 ui->applyButton->setEnabled(false);
719 mNeedsSave = false;
723 void MainWindow::saveConfig(const QString &fname) const
725 QSettings settings(fname, QSettings::IniFormat);
727 /* HACK: Compound any stringlist values into a comma-separated string. */
728 QStringList allkeys = settings.allKeys();
729 foreach(const QString &key, allkeys)
731 QStringList vals = settings.value(key).toStringList();
732 if(vals.size() > 1)
733 settings.setValue(key, vals.join(QChar(',')));
736 QString str = ui->sampleFormatCombo->currentText();
737 for(int i = 0;sampleTypeList[i].name[0];i++)
739 if(str == sampleTypeList[i].name)
741 settings.setValue("sample-type", sampleTypeList[i].value);
742 break;
746 str = ui->channelConfigCombo->currentText();
747 for(int i = 0;speakerModeList[i].name[0];i++)
749 if(str == speakerModeList[i].name)
751 settings.setValue("channels", speakerModeList[i].value);
752 break;
756 uint rate = ui->sampleRateCombo->currentText().toUInt();
757 if(!(rate > 0))
758 settings.setValue("frequency", QString());
759 else
760 settings.setValue("frequency", rate);
762 settings.setValue("period_size", ui->periodSizeEdit->text());
763 settings.setValue("periods", ui->periodCountEdit->text());
765 settings.setValue("sources", ui->srcCountLineEdit->text());
766 settings.setValue("slots", ui->effectSlotLineEdit->text());
768 settings.setValue("resampler", resamplerList[ui->resamplerSlider->value()].value);
770 str = ui->stereoModeCombo->currentText();
771 for(int i = 0;stereoModeList[i].name[0];i++)
773 if(str == stereoModeList[i].name)
775 settings.setValue("stereo-mode", stereoModeList[i].value);
776 break;
780 if(ui->stereoPanningComboBox->currentIndex() == 1)
781 settings.setValue("stereo-panning", "uhj");
782 else if(ui->stereoPanningComboBox->currentIndex() == 2)
783 settings.setValue("stereo-panning", "paired");
784 else
785 settings.remove("stereo-panning");
787 QStringList strlist;
788 if(!ui->enableSSECheckBox->isChecked())
789 strlist.append("sse");
790 if(!ui->enableSSE2CheckBox->isChecked())
791 strlist.append("sse2");
792 if(!ui->enableSSE3CheckBox->isChecked())
793 strlist.append("sse3");
794 if(!ui->enableSSE41CheckBox->isChecked())
795 strlist.append("sse4.1");
796 if(!ui->enableNeonCheckBox->isChecked())
797 strlist.append("neon");
798 settings.setValue("disable-cpu-exts", strlist.join(QChar(',')));
800 if(ui->hrtfStateComboBox->currentIndex() == 1)
801 settings.setValue("hrtf", "true");
802 else if(ui->hrtfStateComboBox->currentIndex() == 2)
803 settings.setValue("hrtf", "false");
804 else
805 settings.setValue("hrtf", QString());
807 if(ui->preferredHrtfComboBox->currentIndex() == 0)
808 settings.setValue("default-hrtf", QString());
809 else
811 str = ui->preferredHrtfComboBox->currentText();
812 settings.setValue("default-hrtf", str);
815 strlist.clear();
816 for(int i = 0;i < ui->hrtfFileList->count();i++)
817 strlist.append(ui->hrtfFileList->item(i)->text());
818 if(!strlist.empty() && ui->defaultHrtfPathsCheckBox->isChecked())
819 strlist.append(QString());
820 settings.setValue("hrtf-paths", strlist.join(QChar(',')));
822 strlist.clear();
823 for(int i = 0;i < ui->enabledBackendList->count();i++)
825 QString label = ui->enabledBackendList->item(i)->text();
826 for(int j = 0;backendList[j].backend_name[0];j++)
828 if(label == backendList[j].full_string)
830 strlist.append(backendList[j].backend_name);
831 break;
835 for(int i = 0;i < ui->disabledBackendList->count();i++)
837 QString label = ui->disabledBackendList->item(i)->text();
838 for(int j = 0;backendList[j].backend_name[0];j++)
840 if(label == backendList[j].full_string)
842 strlist.append(QChar('-')+QString(backendList[j].backend_name));
843 break;
847 if(strlist.size() == 0 && !ui->backendCheckBox->isChecked())
848 strlist.append("-all");
849 else if(ui->backendCheckBox->isChecked())
850 strlist.append(QString());
851 settings.setValue("drivers", strlist.join(QChar(',')));
853 // TODO: Remove check when we can properly match global values.
854 if(ui->defaultReverbComboBox->currentIndex() == 0)
855 settings.setValue("default-reverb", QString());
856 else
858 str = ui->defaultReverbComboBox->currentText().toLower();
859 settings.setValue("default-reverb", str);
862 if(ui->emulateEaxCheckBox->isChecked())
863 settings.setValue("reverb/emulate-eax", "true");
864 else
865 settings.remove("reverb/emulate-eax"/*, "false"*/);
867 strlist.clear();
868 if(!ui->enableEaxReverbCheck->isChecked())
869 strlist.append("eaxreverb");
870 if(!ui->enableStdReverbCheck->isChecked())
871 strlist.append("reverb");
872 if(!ui->enableChorusCheck->isChecked())
873 strlist.append("chorus");
874 if(!ui->enableDistortionCheck->isChecked())
875 strlist.append("distortion");
876 if(!ui->enableCompressorCheck->isChecked())
877 strlist.append("compressor");
878 if(!ui->enableEchoCheck->isChecked())
879 strlist.append("echo");
880 if(!ui->enableEqualizerCheck->isChecked())
881 strlist.append("equalizer");
882 if(!ui->enableFlangerCheck->isChecked())
883 strlist.append("flanger");
884 if(!ui->enableModulatorCheck->isChecked())
885 strlist.append("modulator");
886 if(!ui->enableDedicatedCheck->isChecked())
887 strlist.append("dedicated");
888 settings.setValue("excludefx", strlist.join(QChar(',')));
890 settings.setValue("pulse/spawn-server",
891 ui->pulseAutospawnCheckBox->isChecked() ? QString(/*"true"*/) : QString("false")
893 settings.setValue("pulse/allow-moves",
894 ui->pulseAllowMovesCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
896 settings.setValue("pulse/fix-rate",
897 ui->pulseFixRateCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
900 settings.setValue("alsa/device", ui->alsaDefaultDeviceLine->text());
901 settings.setValue("alsa/capture", ui->alsaDefaultCaptureLine->text());
902 settings.setValue("alsa/allow-resampler",
903 ui->alsaResamplerCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
905 settings.setValue("alsa/mmap",
906 ui->alsaMmapCheckBox->isChecked() ? QString(/*"true"*/) : QString("false")
909 /* Remove empty keys
910 * FIXME: Should only remove keys whose value matches the globally-specified value.
912 allkeys = settings.allKeys();
913 foreach(const QString &key, allkeys)
915 str = settings.value(key).toString();
916 if(str == QString())
917 settings.remove(key);
922 void MainWindow::enableApplyButton()
924 if(!mNeedsSave)
925 ui->applyButton->setEnabled(true);
926 mNeedsSave = true;
927 ui->closeCancelButton->setText(tr("Cancel"));
931 void MainWindow::updateResamplerLabel(int num)
933 ui->resamplerLabel->setText(resamplerList[num].name);
934 enableApplyButton();
938 void MainWindow::updatePeriodSizeEdit(int size)
940 ui->periodSizeEdit->clear();
941 if(size >= 64)
943 size = (size+32)&~0x3f;
944 ui->periodSizeEdit->insert(QString::number(size));
946 enableApplyButton();
949 void MainWindow::updatePeriodSizeSlider()
951 int pos = ui->periodSizeEdit->text().toInt();
952 if(pos >= 64)
954 if(pos > 8192)
955 pos = 8192;
956 ui->periodSizeSlider->setSliderPosition(pos);
958 enableApplyButton();
961 void MainWindow::updatePeriodCountEdit(int count)
963 ui->periodCountEdit->clear();
964 if(count >= 2)
965 ui->periodCountEdit->insert(QString::number(count));
966 enableApplyButton();
969 void MainWindow::updatePeriodCountSlider()
971 int pos = ui->periodCountEdit->text().toInt();
972 if(pos < 2)
973 pos = 0;
974 else if(pos > 16)
975 pos = 16;
976 ui->periodCountSlider->setSliderPosition(pos);
977 enableApplyButton();
981 void MainWindow::addHrtfFile()
983 QString path = QFileDialog::getExistingDirectory(this, tr("Select HRTF Path"));
984 if(path.isEmpty() == false && !getAllDataPaths("/openal/hrtf").contains(path))
986 ui->hrtfFileList->addItem(path);
987 enableApplyButton();
991 void MainWindow::removeHrtfFile()
993 QList<QListWidgetItem*> selected = ui->hrtfFileList->selectedItems();
994 if(!selected.isEmpty())
996 foreach(QListWidgetItem *item, selected)
997 delete item;
998 enableApplyButton();
1002 void MainWindow::updateHrtfRemoveButton()
1004 ui->hrtfRemoveButton->setEnabled(ui->hrtfFileList->selectedItems().size() != 0);
1007 void MainWindow::showEnabledBackendMenu(QPoint pt)
1009 QMap<QAction*,QString> actionMap;
1011 pt = ui->enabledBackendList->mapToGlobal(pt);
1013 QMenu ctxmenu;
1014 QAction *removeAction = ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove");
1015 if(ui->enabledBackendList->selectedItems().size() == 0)
1016 removeAction->setEnabled(false);
1017 ctxmenu.addSeparator();
1018 for(size_t i = 0;backendList[i].backend_name[0];i++)
1020 QString backend = backendList[i].full_string;
1021 QAction *action = ctxmenu.addAction(QString("Add ")+backend);
1022 actionMap[action] = backend;
1023 if(ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0 ||
1024 ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0)
1025 action->setEnabled(false);
1028 QAction *gotAction = ctxmenu.exec(pt);
1029 if(gotAction == removeAction)
1031 QList<QListWidgetItem*> selected = ui->enabledBackendList->selectedItems();
1032 foreach(QListWidgetItem *item, selected)
1033 delete item;
1034 enableApplyButton();
1036 else if(gotAction != NULL)
1038 QMap<QAction*,QString>::const_iterator iter = actionMap.find(gotAction);
1039 if(iter != actionMap.end())
1040 ui->enabledBackendList->addItem(iter.value());
1041 enableApplyButton();
1045 void MainWindow::showDisabledBackendMenu(QPoint pt)
1047 QMap<QAction*,QString> actionMap;
1049 pt = ui->disabledBackendList->mapToGlobal(pt);
1051 QMenu ctxmenu;
1052 QAction *removeAction = ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove");
1053 if(ui->disabledBackendList->selectedItems().size() == 0)
1054 removeAction->setEnabled(false);
1055 ctxmenu.addSeparator();
1056 for(size_t i = 0;backendList[i].backend_name[0];i++)
1058 QString backend = backendList[i].full_string;
1059 QAction *action = ctxmenu.addAction(QString("Add ")+backend);
1060 actionMap[action] = backend;
1061 if(ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0 ||
1062 ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0)
1063 action->setEnabled(false);
1066 QAction *gotAction = ctxmenu.exec(pt);
1067 if(gotAction == removeAction)
1069 QList<QListWidgetItem*> selected = ui->disabledBackendList->selectedItems();
1070 foreach(QListWidgetItem *item, selected)
1071 delete item;
1072 enableApplyButton();
1074 else if(gotAction != NULL)
1076 QMap<QAction*,QString>::const_iterator iter = actionMap.find(gotAction);
1077 if(iter != actionMap.end())
1078 ui->disabledBackendList->addItem(iter.value());
1079 enableApplyButton();