Use a spinbox for the nfc-ref-delay value
[openal-soft.git] / utils / alsoft-config / mainwindow.cpp
blobc2e36fb4c262d6e0f9a53e540bb72f905467a7e9
2 #include "config.h"
4 #include "version.h"
6 #include <iostream>
7 #include <cmath>
9 #include <QFileDialog>
10 #include <QMessageBox>
11 #include <QCloseEvent>
12 #include <QSettings>
13 #include <QtGlobal>
14 #include "mainwindow.h"
15 #include "ui_mainwindow.h"
17 namespace {
19 static const struct {
20 char backend_name[16];
21 char full_string[32];
22 } backendList[] = {
23 #ifdef HAVE_JACK
24 { "jack", "JACK" },
25 #endif
26 #ifdef HAVE_PULSEAUDIO
27 { "pulse", "PulseAudio" },
28 #endif
29 #ifdef HAVE_ALSA
30 { "alsa", "ALSA" },
31 #endif
32 #ifdef HAVE_COREAUDIO
33 { "core", "CoreAudio" },
34 #endif
35 #ifdef HAVE_OSS
36 { "oss", "OSS" },
37 #endif
38 #ifdef HAVE_SOLARIS
39 { "solaris", "Solaris" },
40 #endif
41 #ifdef HAVE_SNDIO
42 { "sndio", "SoundIO" },
43 #endif
44 #ifdef HAVE_QSA
45 { "qsa", "QSA" },
46 #endif
47 #ifdef HAVE_MMDEVAPI
48 { "mmdevapi", "MMDevAPI" },
49 #endif
50 #ifdef HAVE_DSOUND
51 { "dsound", "DirectSound" },
52 #endif
53 #ifdef HAVE_WINMM
54 { "winmm", "Windows Multimedia" },
55 #endif
56 #ifdef HAVE_PORTAUDIO
57 { "port", "PortAudio" },
58 #endif
59 #ifdef HAVE_OPENSL
60 { "opensl", "OpenSL" },
61 #endif
63 { "null", "Null Output" },
64 #ifdef HAVE_WAVE
65 { "wave", "Wave Writer" },
66 #endif
67 { "", "" }
70 static const struct NameValuePair {
71 const char name[64];
72 const char value[16];
73 } speakerModeList[] = {
74 { "Autodetect", "" },
75 { "Mono", "mono" },
76 { "Stereo", "stereo" },
77 { "Quadrophonic", "quad" },
78 { "5.1 Surround (Side)", "surround51" },
79 { "5.1 Surround (Rear)", "surround51rear" },
80 { "6.1 Surround", "surround61" },
81 { "7.1 Surround", "surround71" },
83 { "Ambisonic, 1st Order", "ambi1" },
84 { "Ambisonic, 2nd Order", "ambi2" },
85 { "Ambisonic, 3rd Order", "ambi3" },
87 { "", "" }
88 }, sampleTypeList[] = {
89 { "Autodetect", "" },
90 { "8-bit int", "int8" },
91 { "8-bit uint", "uint8" },
92 { "16-bit int", "int16" },
93 { "16-bit uint", "uint16" },
94 { "32-bit int", "int32" },
95 { "32-bit uint", "uint32" },
96 { "32-bit float", "float32" },
98 { "", "" }
99 }, resamplerList[] = {
100 { "Point", "point" },
101 { "Linear", "linear" },
102 { "Default (Linear)", "" },
103 { "4-Point Sinc", "sinc4" },
104 { "Band-limited Sinc", "bsinc" },
106 { "", "" }
107 }, stereoModeList[] = {
108 { "Autodetect", "" },
109 { "Speakers", "speakers" },
110 { "Headphones", "headphones" },
112 { "", "" }
113 }, stereoEncList[] = {
114 { "Default", "" },
115 { "Pan Pot", "panpot" },
116 { "UHJ", "uhj" },
118 { "", "" }
119 }, ambiFormatList[] = {
120 { "Default", "" },
121 { "ACN + SN3D", "acn+sn3d" },
122 { "ACN + N3D", "acn+n3d" },
123 { "Furse-Malham", "fuma" },
125 { "", "" }
128 static QString getDefaultConfigName()
130 #ifdef Q_OS_WIN32
131 static const char fname[] = "alsoft.ini";
132 QByteArray base = qgetenv("AppData");
133 #else
134 static const char fname[] = "alsoft.conf";
135 QByteArray base = qgetenv("XDG_CONFIG_HOME");
136 if(base.isEmpty())
138 base = qgetenv("HOME");
139 if(base.isEmpty() == false)
140 base += "/.config";
142 #endif
143 if(base.isEmpty() == false)
144 return base +'/'+ fname;
145 return fname;
148 static QString getBaseDataPath()
150 #ifdef Q_OS_WIN32
151 QByteArray base = qgetenv("AppData");
152 #else
153 QByteArray base = qgetenv("XDG_DATA_HOME");
154 if(base.isEmpty())
156 base = qgetenv("HOME");
157 if(!base.isEmpty())
158 base += "/.local/share";
160 #endif
161 return base;
164 static QStringList getAllDataPaths(QString append=QString())
166 QStringList list;
167 list.append(getBaseDataPath());
168 #ifdef Q_OS_WIN32
169 // TODO: Common AppData path
170 #else
171 QString paths = qgetenv("XDG_DATA_DIRS");
172 if(paths.isEmpty())
173 paths = "/usr/local/share/:/usr/share/";
174 list += paths.split(QChar(':'), QString::SkipEmptyParts);
175 #endif
176 QStringList::iterator iter = list.begin();
177 while(iter != list.end())
179 if(iter->isEmpty())
180 iter = list.erase(iter);
181 else
183 iter->append(append);
184 iter++;
187 return list;
190 template<size_t N>
191 static QString getValueFromName(const NameValuePair (&list)[N], const QString &str)
193 for(size_t i = 0;i < N-1;i++)
195 if(str == list[i].name)
196 return list[i].value;
198 return QString();
201 template<size_t N>
202 static QString getNameFromValue(const NameValuePair (&list)[N], const QString &str)
204 for(size_t i = 0;i < N-1;i++)
206 if(str == list[i].value)
207 return list[i].name;
209 return QString();
214 MainWindow::MainWindow(QWidget *parent) :
215 QMainWindow(parent),
216 ui(new Ui::MainWindow),
217 mPeriodSizeValidator(NULL),
218 mPeriodCountValidator(NULL),
219 mSourceCountValidator(NULL),
220 mEffectSlotValidator(NULL),
221 mSourceSendValidator(NULL),
222 mSampleRateValidator(NULL),
223 mJackBufferValidator(NULL),
224 mNeedsSave(false)
226 ui->setupUi(this);
228 for(int i = 0;speakerModeList[i].name[0];i++)
229 ui->channelConfigCombo->addItem(speakerModeList[i].name);
230 ui->channelConfigCombo->adjustSize();
231 for(int i = 0;sampleTypeList[i].name[0];i++)
232 ui->sampleFormatCombo->addItem(sampleTypeList[i].name);
233 ui->sampleFormatCombo->adjustSize();
234 for(int i = 0;stereoModeList[i].name[0];i++)
235 ui->stereoModeCombo->addItem(stereoModeList[i].name);
236 ui->stereoModeCombo->adjustSize();
237 for(int i = 0;stereoEncList[i].name[0];i++)
238 ui->stereoEncodingComboBox->addItem(stereoEncList[i].name);
239 ui->stereoEncodingComboBox->adjustSize();
240 for(int i = 0;ambiFormatList[i].name[0];i++)
241 ui->ambiFormatComboBox->addItem(ambiFormatList[i].name);
242 ui->ambiFormatComboBox->adjustSize();
244 int count;
245 for(count = 0;resamplerList[count].name[0];count++) {
247 ui->resamplerSlider->setRange(0, count-1);
249 ui->hrtfStateComboBox->adjustSize();
251 #if !defined(HAVE_NEON) && !defined(HAVE_SSE)
252 ui->cpuExtDisabledLabel->move(ui->cpuExtDisabledLabel->x(), ui->cpuExtDisabledLabel->y() - 60);
253 #else
254 ui->cpuExtDisabledLabel->setVisible(false);
255 #endif
257 #ifndef HAVE_NEON
259 #ifndef HAVE_SSE4_1
260 #ifndef HAVE_SSE3
261 #ifndef HAVE_SSE2
262 #ifndef HAVE_SSE
263 ui->enableSSECheckBox->setVisible(false);
264 #endif /* !SSE */
265 ui->enableSSE2CheckBox->setVisible(false);
266 #endif /* !SSE2 */
267 ui->enableSSE3CheckBox->setVisible(false);
268 #endif /* !SSE3 */
269 ui->enableSSE41CheckBox->setVisible(false);
270 #endif /* !SSE4.1 */
271 ui->enableNeonCheckBox->setVisible(false);
273 #else /* !Neon */
275 #ifndef HAVE_SSE4_1
276 #ifndef HAVE_SSE3
277 #ifndef HAVE_SSE2
278 #ifndef HAVE_SSE
279 ui->enableNeonCheckBox->move(ui->enableNeonCheckBox->x(), ui->enableNeonCheckBox->y() - 30);
280 ui->enableSSECheckBox->setVisible(false);
281 #endif /* !SSE */
282 ui->enableSSE2CheckBox->setVisible(false);
283 #endif /* !SSE2 */
284 ui->enableSSE3CheckBox->setVisible(false);
285 #endif /* !SSE3 */
286 ui->enableSSE41CheckBox->setVisible(false);
287 #endif /* !SSE4.1 */
289 #endif
291 mPeriodSizeValidator = new QIntValidator(64, 8192, this);
292 ui->periodSizeEdit->setValidator(mPeriodSizeValidator);
293 mPeriodCountValidator = new QIntValidator(2, 16, this);
294 ui->periodCountEdit->setValidator(mPeriodCountValidator);
296 mSourceCountValidator = new QIntValidator(0, 4096, this);
297 ui->srcCountLineEdit->setValidator(mSourceCountValidator);
298 mEffectSlotValidator = new QIntValidator(0, 64, this);
299 ui->effectSlotLineEdit->setValidator(mEffectSlotValidator);
300 mSourceSendValidator = new QIntValidator(0, 16, this);
301 ui->srcSendLineEdit->setValidator(mSourceSendValidator);
302 mSampleRateValidator = new QIntValidator(8000, 192000, this);
303 ui->sampleRateCombo->lineEdit()->setValidator(mSampleRateValidator);
305 mJackBufferValidator = new QIntValidator(0, 8192, this);
306 ui->jackBufferSizeLine->setValidator(mJackBufferValidator);
308 connect(ui->actionLoad, SIGNAL(triggered()), this, SLOT(loadConfigFromFile()));
309 connect(ui->actionSave_As, SIGNAL(triggered()), this, SLOT(saveConfigAsFile()));
311 connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAboutPage()));
313 connect(ui->closeCancelButton, SIGNAL(clicked()), this, SLOT(cancelCloseAction()));
314 connect(ui->applyButton, SIGNAL(clicked()), this, SLOT(saveCurrentConfig()));
316 connect(ui->channelConfigCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
317 connect(ui->sampleFormatCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
318 connect(ui->stereoModeCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
319 connect(ui->sampleRateCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
320 connect(ui->sampleRateCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(enableApplyButton()));
322 connect(ui->resamplerSlider, SIGNAL(valueChanged(int)), this, SLOT(updateResamplerLabel(int)));
324 connect(ui->periodSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(updatePeriodSizeEdit(int)));
325 connect(ui->periodSizeEdit, SIGNAL(editingFinished()), this, SLOT(updatePeriodSizeSlider()));
326 connect(ui->periodCountSlider, SIGNAL(valueChanged(int)), this, SLOT(updatePeriodCountEdit(int)));
327 connect(ui->periodCountEdit, SIGNAL(editingFinished()), this, SLOT(updatePeriodCountSlider()));
329 connect(ui->stereoEncodingComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(enableApplyButton()));
330 connect(ui->ambiFormatComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(enableApplyButton()));
332 connect(ui->decoderHQModeCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
333 connect(ui->decoderDistCompCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
334 connect(ui->decoderNFEffectsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
335 connect(ui->decoderNFRefDelaySpinBox, SIGNAL(valueChanged(double)), this, SLOT(enableApplyButton()));
336 connect(ui->decoderQuadLineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
337 connect(ui->decoderQuadButton, SIGNAL(clicked()), this, SLOT(selectQuadDecoderFile()));
338 connect(ui->decoder51LineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
339 connect(ui->decoder51Button, SIGNAL(clicked()), this, SLOT(select51DecoderFile()));
340 connect(ui->decoder61LineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
341 connect(ui->decoder61Button, SIGNAL(clicked()), this, SLOT(select61DecoderFile()));
342 connect(ui->decoder71LineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
343 connect(ui->decoder71Button, SIGNAL(clicked()), this, SLOT(select71DecoderFile()));
345 connect(ui->preferredHrtfComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
346 connect(ui->hrtfStateComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
347 connect(ui->hrtfAddButton, SIGNAL(clicked()), this, SLOT(addHrtfFile()));
348 connect(ui->hrtfRemoveButton, SIGNAL(clicked()), this, SLOT(removeHrtfFile()));
349 connect(ui->hrtfFileList, SIGNAL(itemSelectionChanged()), this, SLOT(updateHrtfRemoveButton()));
350 connect(ui->defaultHrtfPathsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
352 connect(ui->srcCountLineEdit, SIGNAL(editingFinished()), this, SLOT(enableApplyButton()));
353 connect(ui->srcSendLineEdit, SIGNAL(editingFinished()), this, SLOT(enableApplyButton()));
354 connect(ui->effectSlotLineEdit, SIGNAL(editingFinished()), this, SLOT(enableApplyButton()));
356 connect(ui->enableSSECheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
357 connect(ui->enableSSE2CheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
358 connect(ui->enableSSE3CheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
359 connect(ui->enableSSE41CheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
360 connect(ui->enableNeonCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
362 ui->enabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
363 connect(ui->enabledBackendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showEnabledBackendMenu(QPoint)));
365 ui->disabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
366 connect(ui->disabledBackendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showDisabledBackendMenu(QPoint)));
367 connect(ui->backendCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
369 connect(ui->defaultReverbComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
370 connect(ui->emulateEaxCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
371 connect(ui->enableEaxReverbCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
372 connect(ui->enableStdReverbCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
373 connect(ui->enableChorusCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
374 connect(ui->enableCompressorCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
375 connect(ui->enableDistortionCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
376 connect(ui->enableEchoCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
377 connect(ui->enableEqualizerCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
378 connect(ui->enableFlangerCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
379 connect(ui->enableModulatorCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
380 connect(ui->enableDedicatedCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
382 connect(ui->pulseAutospawnCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
383 connect(ui->pulseAllowMovesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
384 connect(ui->pulseFixRateCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
386 connect(ui->jackAutospawnCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
387 connect(ui->jackBufferSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(updateJackBufferSizeEdit(int)));
388 connect(ui->jackBufferSizeLine, SIGNAL(editingFinished()), this, SLOT(updateJackBufferSizeSlider()));
390 connect(ui->alsaDefaultDeviceLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
391 connect(ui->alsaDefaultCaptureLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
392 connect(ui->alsaResamplerCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
393 connect(ui->alsaMmapCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
395 connect(ui->ossDefaultDeviceLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
396 connect(ui->ossPlaybackPushButton, SIGNAL(clicked(bool)), this, SLOT(selectOSSPlayback()));
397 connect(ui->ossDefaultCaptureLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
398 connect(ui->ossCapturePushButton, SIGNAL(clicked(bool)), this, SLOT(selectOSSCapture()));
400 connect(ui->solarisDefaultDeviceLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
401 connect(ui->solarisPlaybackPushButton, SIGNAL(clicked(bool)), this, SLOT(selectSolarisPlayback()));
403 connect(ui->waveOutputLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
404 connect(ui->waveOutputButton, SIGNAL(clicked(bool)), this, SLOT(selectWaveOutput()));
405 connect(ui->waveBFormatCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
407 ui->backendListWidget->setCurrentRow(0);
408 ui->tabWidget->setCurrentIndex(0);
410 for(int i = 1;i < ui->backendListWidget->count();i++)
411 ui->backendListWidget->setRowHidden(i, true);
412 for(int i = 0;backendList[i].backend_name[0];i++)
414 QList<QListWidgetItem*> items = ui->backendListWidget->findItems(
415 backendList[i].full_string, Qt::MatchFixedString
417 foreach(const QListWidgetItem *item, items)
418 ui->backendListWidget->setItemHidden(item, false);
421 loadConfig(getDefaultConfigName());
424 MainWindow::~MainWindow()
426 delete ui;
427 delete mPeriodSizeValidator;
428 delete mPeriodCountValidator;
429 delete mSourceCountValidator;
430 delete mEffectSlotValidator;
431 delete mSourceSendValidator;
432 delete mSampleRateValidator;
433 delete mJackBufferValidator;
436 void MainWindow::closeEvent(QCloseEvent *event)
438 if(!mNeedsSave)
439 event->accept();
440 else
442 QMessageBox::StandardButton btn = QMessageBox::warning(this,
443 tr("Apply changes?"), tr("Save changes before quitting?"),
444 QMessageBox::Save | QMessageBox::No | QMessageBox::Cancel
446 if(btn == QMessageBox::Save)
447 saveCurrentConfig();
448 if(btn == QMessageBox::Cancel)
449 event->ignore();
450 else
451 event->accept();
455 void MainWindow::cancelCloseAction()
457 mNeedsSave = false;
458 close();
462 void MainWindow::showAboutPage()
464 QMessageBox::information(this, tr("About"),
465 tr("OpenAL Soft Configuration Utility.\nBuilt for OpenAL Soft library version ")+
466 (ALSOFT_VERSION "-" ALSOFT_GIT_COMMIT_HASH " (" ALSOFT_GIT_BRANCH " branch).")
471 QStringList MainWindow::collectHrtfs()
473 QStringList ret;
474 QStringList processed;
476 for(int i = 0;i < ui->hrtfFileList->count();i++)
478 QDir dir(ui->hrtfFileList->item(i)->text());
479 QStringList fnames = dir.entryList(QDir::Files | QDir::Readable, QDir::Name);
480 foreach(const QString &fname, fnames)
482 if(!fname.endsWith(".mhr", Qt::CaseInsensitive))
483 continue;
484 QString fullname = dir.absoluteFilePath(fname);
485 if(processed.contains(fullname))
486 continue;
487 processed.push_back(fullname);
489 QString name = fname.left(fname.length()-4);
490 if(!ret.contains(name))
491 ret.push_back(name);
492 else
494 size_t i = 2;
495 do {
496 QString s = name+" #"+QString::number(i);
497 if(!ret.contains(s))
499 ret.push_back(s);
500 break;
502 ++i;
503 } while(1);
508 if(ui->defaultHrtfPathsCheckBox->isChecked())
510 QStringList paths = getAllDataPaths("/openal/hrtf");
511 foreach(const QString &name, paths)
513 QDir dir(name);
514 QStringList fnames = dir.entryList(QDir::Files | QDir::Readable, QDir::Name);
515 foreach(const QString &fname, fnames)
517 if(!fname.endsWith(".mhr", Qt::CaseInsensitive))
518 continue;
519 QString fullname = dir.absoluteFilePath(fname);
520 if(processed.contains(fullname))
521 continue;
522 processed.push_back(fullname);
524 QString name = fname.left(fname.length()-4);
525 if(!ret.contains(name))
526 ret.push_back(name);
527 else
529 size_t i = 2;
530 do {
531 QString s = name+" #"+QString::number(i);
532 if(!ret.contains(s))
534 ret.push_back(s);
535 break;
537 ++i;
538 } while(1);
543 return ret;
547 void MainWindow::loadConfigFromFile()
549 QString fname = QFileDialog::getOpenFileName(this, tr("Select Files"));
550 if(fname.isEmpty() == false)
551 loadConfig(fname);
554 void MainWindow::loadConfig(const QString &fname)
556 QSettings settings(fname, QSettings::IniFormat);
558 QString sampletype = settings.value("sample-type").toString();
559 ui->sampleFormatCombo->setCurrentIndex(0);
560 if(sampletype.isEmpty() == false)
562 QString str = getNameFromValue(sampleTypeList, sampletype);
563 if(!str.isEmpty())
565 int j = ui->sampleFormatCombo->findText(str);
566 if(j > 0) ui->sampleFormatCombo->setCurrentIndex(j);
570 QString channelconfig = settings.value("channels").toString();
571 ui->channelConfigCombo->setCurrentIndex(0);
572 if(channelconfig.isEmpty() == false)
574 QString str = getNameFromValue(speakerModeList, channelconfig);
575 if(!str.isEmpty())
577 int j = ui->channelConfigCombo->findText(str);
578 if(j > 0) ui->channelConfigCombo->setCurrentIndex(j);
582 QString srate = settings.value("frequency").toString();
583 if(srate.isEmpty())
584 ui->sampleRateCombo->setCurrentIndex(0);
585 else
587 ui->sampleRateCombo->lineEdit()->clear();
588 ui->sampleRateCombo->lineEdit()->insert(srate);
591 ui->srcCountLineEdit->clear();
592 ui->srcCountLineEdit->insert(settings.value("sources").toString());
593 ui->effectSlotLineEdit->clear();
594 ui->effectSlotLineEdit->insert(settings.value("slots").toString());
595 ui->srcSendLineEdit->clear();
596 ui->srcSendLineEdit->insert(settings.value("sends").toString());
598 QString resampler = settings.value("resampler").toString().trimmed();
599 ui->resamplerSlider->setValue(0);
600 /* The "cubic" and "sinc8" resamplers are no longer supported. Use "sinc4"
601 * as a fallback.
603 if(resampler == "cubic" || resampler == "sinc8")
604 resampler = "sinc4";
605 for(int i = 0;resamplerList[i].name[0];i++)
607 if(resampler == resamplerList[i].value)
609 ui->resamplerSlider->setValue(i);
610 break;
614 QString stereomode = settings.value("stereo-mode").toString().trimmed();
615 ui->stereoModeCombo->setCurrentIndex(0);
616 if(stereomode.isEmpty() == false)
618 QString str = getNameFromValue(stereoModeList, stereomode);
619 if(!str.isEmpty())
621 int j = ui->stereoModeCombo->findText(str);
622 if(j > 0) ui->stereoModeCombo->setCurrentIndex(j);
626 int periodsize = settings.value("period_size").toInt();
627 ui->periodSizeEdit->clear();
628 if(periodsize >= 64)
630 ui->periodSizeEdit->insert(QString::number(periodsize));
631 updatePeriodSizeSlider();
634 int periodcount = settings.value("periods").toInt();
635 ui->periodCountEdit->clear();
636 if(periodcount >= 2)
638 ui->periodCountEdit->insert(QString::number(periodcount));
639 updatePeriodCountSlider();
642 QString stereopan = settings.value("stereo-encoding").toString();
643 ui->stereoEncodingComboBox->setCurrentIndex(0);
644 if(stereopan.isEmpty() == false)
646 QString str = getNameFromValue(stereoEncList, stereopan);
647 if(!str.isEmpty())
649 int j = ui->stereoEncodingComboBox->findText(str);
650 if(j > 0) ui->stereoEncodingComboBox->setCurrentIndex(j);
654 QString ambiformat = settings.value("ambi-format").toString();
655 ui->ambiFormatComboBox->setCurrentIndex(0);
656 if(ambiformat.isEmpty() == false)
658 QString str = getNameFromValue(ambiFormatList, ambiformat);
659 if(!str.isEmpty())
661 int j = ui->ambiFormatComboBox->findText(str);
662 if(j > 0) ui->ambiFormatComboBox->setCurrentIndex(j);
666 bool hqmode = settings.value("decoder/hq-mode", false).toBool();
667 ui->decoderHQModeCheckBox->setChecked(hqmode);
668 bool distcomp = settings.value("decoder/distance-comp", true).toBool();
669 ui->decoderDistCompCheckBox->setChecked(distcomp);
670 bool nfeffects = settings.value("decoder/nfc", true).toBool();
671 ui->decoderNFEffectsCheckBox->setChecked(nfeffects);
672 double refdelay = settings.value("decoder/nfc-ref-delay", 0.0).toDouble();
673 ui->decoderNFRefDelaySpinBox->setValue(refdelay);
675 ui->decoderQuadLineEdit->setText(settings.value("decoder/quad").toString());
676 ui->decoder51LineEdit->setText(settings.value("decoder/surround51").toString());
677 ui->decoder61LineEdit->setText(settings.value("decoder/surround61").toString());
678 ui->decoder71LineEdit->setText(settings.value("decoder/surround71").toString());
680 QStringList disabledCpuExts = settings.value("disable-cpu-exts").toStringList();
681 if(disabledCpuExts.size() == 1)
682 disabledCpuExts = disabledCpuExts[0].split(QChar(','));
683 for(QStringList::iterator iter = disabledCpuExts.begin();iter != disabledCpuExts.end();iter++)
684 *iter = iter->trimmed();
685 ui->enableSSECheckBox->setChecked(!disabledCpuExts.contains("sse", Qt::CaseInsensitive));
686 ui->enableSSE2CheckBox->setChecked(!disabledCpuExts.contains("sse2", Qt::CaseInsensitive));
687 ui->enableSSE3CheckBox->setChecked(!disabledCpuExts.contains("sse3", Qt::CaseInsensitive));
688 ui->enableSSE41CheckBox->setChecked(!disabledCpuExts.contains("sse4.1", Qt::CaseInsensitive));
689 ui->enableNeonCheckBox->setChecked(!disabledCpuExts.contains("neon", Qt::CaseInsensitive));
691 QStringList hrtf_paths = settings.value("hrtf-paths").toStringList();
692 if(hrtf_paths.size() == 1)
693 hrtf_paths = hrtf_paths[0].split(QChar(','));
694 for(QStringList::iterator iter = hrtf_paths.begin();iter != hrtf_paths.end();iter++)
695 *iter = iter->trimmed();
696 if(!hrtf_paths.empty() && !hrtf_paths.back().isEmpty())
697 ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Unchecked);
698 else
700 hrtf_paths.removeAll(QString());
701 ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Checked);
703 hrtf_paths.removeDuplicates();
704 ui->hrtfFileList->clear();
705 ui->hrtfFileList->addItems(hrtf_paths);
706 updateHrtfRemoveButton();
708 QString hrtfstate = settings.value("hrtf").toString().toLower();
709 if(hrtfstate == "true")
710 ui->hrtfStateComboBox->setCurrentIndex(1);
711 else if(hrtfstate == "false")
712 ui->hrtfStateComboBox->setCurrentIndex(2);
713 else
714 ui->hrtfStateComboBox->setCurrentIndex(0);
716 ui->preferredHrtfComboBox->clear();
717 ui->preferredHrtfComboBox->addItem("- Any -");
718 if(ui->defaultHrtfPathsCheckBox->isChecked())
720 QStringList hrtfs = collectHrtfs();
721 foreach(const QString &name, hrtfs)
722 ui->preferredHrtfComboBox->addItem(name);
725 QString defaulthrtf = settings.value("default-hrtf").toString();
726 ui->preferredHrtfComboBox->setCurrentIndex(0);
727 if(defaulthrtf.isEmpty() == false)
729 int i = ui->preferredHrtfComboBox->findText(defaulthrtf);
730 if(i > 0)
731 ui->preferredHrtfComboBox->setCurrentIndex(i);
732 else
734 i = ui->preferredHrtfComboBox->count();
735 ui->preferredHrtfComboBox->addItem(defaulthrtf);
736 ui->preferredHrtfComboBox->setCurrentIndex(i);
739 ui->preferredHrtfComboBox->adjustSize();
741 ui->enabledBackendList->clear();
742 ui->disabledBackendList->clear();
743 QStringList drivers = settings.value("drivers").toStringList();
744 if(drivers.size() == 0)
745 ui->backendCheckBox->setChecked(true);
746 else
748 if(drivers.size() == 1)
749 drivers = drivers[0].split(QChar(','));
750 for(QStringList::iterator iter = drivers.begin();iter != drivers.end();iter++)
751 *iter = iter->trimmed();
753 bool lastWasEmpty = false;
754 foreach(const QString &backend, drivers)
756 lastWasEmpty = backend.isEmpty();
757 if(lastWasEmpty) continue;
759 if(!backend.startsWith(QChar('-')))
760 for(int j = 0;backendList[j].backend_name[0];j++)
762 if(backend == backendList[j].backend_name)
764 ui->enabledBackendList->addItem(backendList[j].full_string);
765 break;
768 else if(backend.size() > 1)
770 QStringRef backendref = backend.rightRef(backend.size()-1);
771 for(int j = 0;backendList[j].backend_name[0];j++)
773 if(backendref == backendList[j].backend_name)
775 ui->disabledBackendList->addItem(backendList[j].full_string);
776 break;
781 ui->backendCheckBox->setChecked(lastWasEmpty);
784 QString defaultreverb = settings.value("default-reverb").toString().toLower();
785 ui->defaultReverbComboBox->setCurrentIndex(0);
786 if(defaultreverb.isEmpty() == false)
788 for(int i = 0;i < ui->defaultReverbComboBox->count();i++)
790 if(defaultreverb.compare(ui->defaultReverbComboBox->itemText(i).toLower()) == 0)
792 ui->defaultReverbComboBox->setCurrentIndex(i);
793 break;
798 ui->emulateEaxCheckBox->setChecked(settings.value("reverb/emulate-eax", false).toBool());
800 QStringList excludefx = settings.value("excludefx").toStringList();
801 if(excludefx.size() == 1)
802 excludefx = excludefx[0].split(QChar(','));
803 for(QStringList::iterator iter = excludefx.begin();iter != excludefx.end();iter++)
804 *iter = iter->trimmed();
805 ui->enableEaxReverbCheck->setChecked(!excludefx.contains("eaxreverb", Qt::CaseInsensitive));
806 ui->enableStdReverbCheck->setChecked(!excludefx.contains("reverb", Qt::CaseInsensitive));
807 ui->enableChorusCheck->setChecked(!excludefx.contains("chorus", Qt::CaseInsensitive));
808 ui->enableCompressorCheck->setChecked(!excludefx.contains("compressor", Qt::CaseInsensitive));
809 ui->enableDistortionCheck->setChecked(!excludefx.contains("distortion", Qt::CaseInsensitive));
810 ui->enableEchoCheck->setChecked(!excludefx.contains("echo", Qt::CaseInsensitive));
811 ui->enableEqualizerCheck->setChecked(!excludefx.contains("equalizer", Qt::CaseInsensitive));
812 ui->enableFlangerCheck->setChecked(!excludefx.contains("flanger", Qt::CaseInsensitive));
813 ui->enableModulatorCheck->setChecked(!excludefx.contains("modulator", Qt::CaseInsensitive));
814 ui->enableDedicatedCheck->setChecked(!excludefx.contains("dedicated", Qt::CaseInsensitive));
816 ui->pulseAutospawnCheckBox->setChecked(settings.value("pulse/spawn-server", true).toBool());
817 ui->pulseAllowMovesCheckBox->setChecked(settings.value("pulse/allow-moves", false).toBool());
818 ui->pulseFixRateCheckBox->setChecked(settings.value("pulse/fix-rate", false).toBool());
820 ui->jackAutospawnCheckBox->setChecked(settings.value("jack/spawn-server", false).toBool());
821 ui->jackBufferSizeLine->setText(settings.value("jack/buffer-size", QString()).toString());
822 updateJackBufferSizeSlider();
824 ui->alsaDefaultDeviceLine->setText(settings.value("alsa/device", QString()).toString());
825 ui->alsaDefaultCaptureLine->setText(settings.value("alsa/capture", QString()).toString());
826 ui->alsaResamplerCheckBox->setChecked(settings.value("alsa/allow-resampler", false).toBool());
827 ui->alsaMmapCheckBox->setChecked(settings.value("alsa/mmap", true).toBool());
829 ui->ossDefaultDeviceLine->setText(settings.value("oss/device", QString()).toString());
830 ui->ossDefaultCaptureLine->setText(settings.value("oss/capture", QString()).toString());
832 ui->solarisDefaultDeviceLine->setText(settings.value("solaris/device", QString()).toString());
834 ui->waveOutputLine->setText(settings.value("wave/file", QString()).toString());
835 ui->waveBFormatCheckBox->setChecked(settings.value("wave/bformat", false).toBool());
837 ui->applyButton->setEnabled(false);
838 ui->closeCancelButton->setText(tr("Close"));
839 mNeedsSave = false;
842 void MainWindow::saveCurrentConfig()
844 saveConfig(getDefaultConfigName());
845 ui->applyButton->setEnabled(false);
846 ui->closeCancelButton->setText(tr("Close"));
847 mNeedsSave = false;
848 QMessageBox::information(this, tr("Information"),
849 tr("Applications using OpenAL need to be restarted for changes to take effect."));
852 void MainWindow::saveConfigAsFile()
854 QString fname = QFileDialog::getOpenFileName(this, tr("Select Files"));
855 if(fname.isEmpty() == false)
857 saveConfig(fname);
858 ui->applyButton->setEnabled(false);
859 mNeedsSave = false;
863 void MainWindow::saveConfig(const QString &fname) const
865 QSettings settings(fname, QSettings::IniFormat);
867 /* HACK: Compound any stringlist values into a comma-separated string. */
868 QStringList allkeys = settings.allKeys();
869 foreach(const QString &key, allkeys)
871 QStringList vals = settings.value(key).toStringList();
872 if(vals.size() > 1)
873 settings.setValue(key, vals.join(QChar(',')));
876 settings.setValue("sample-type", getValueFromName(sampleTypeList, ui->sampleFormatCombo->currentText()));
877 settings.setValue("channels", getValueFromName(speakerModeList, ui->channelConfigCombo->currentText()));
879 uint rate = ui->sampleRateCombo->currentText().toUInt();
880 if(!(rate > 0))
881 settings.setValue("frequency", QString());
882 else
883 settings.setValue("frequency", rate);
885 settings.setValue("period_size", ui->periodSizeEdit->text());
886 settings.setValue("periods", ui->periodCountEdit->text());
888 settings.setValue("sources", ui->srcCountLineEdit->text());
889 settings.setValue("slots", ui->effectSlotLineEdit->text());
891 settings.setValue("resampler", resamplerList[ui->resamplerSlider->value()].value);
893 settings.setValue("stereo-mode", getValueFromName(stereoModeList, ui->stereoModeCombo->currentText()));
894 settings.setValue("stereo-encoding", getValueFromName(stereoEncList, ui->stereoEncodingComboBox->currentText()));
895 settings.setValue("ambi-format", getValueFromName(ambiFormatList, ui->ambiFormatComboBox->currentText()));
897 settings.setValue("decoder/hq-mode",
898 ui->decoderHQModeCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
900 settings.setValue("decoder/distance-comp",
901 ui->decoderDistCompCheckBox->isChecked() ? QString(/*"true"*/) : QString("false")
903 settings.setValue("decoder/nfc",
904 ui->decoderNFEffectsCheckBox->isChecked() ? QString(/*"true"*/) : QString("false")
906 double refdelay = ui->decoderNFRefDelaySpinBox->value();
907 settings.setValue("decoder/nfc-ref-delay",
908 (refdelay > 0.0) ? QString::number(refdelay) : QString()
911 settings.setValue("decoder/quad", ui->decoderQuadLineEdit->text());
912 settings.setValue("decoder/surround51", ui->decoder51LineEdit->text());
913 settings.setValue("decoder/surround61", ui->decoder61LineEdit->text());
914 settings.setValue("decoder/surround71", ui->decoder71LineEdit->text());
916 QStringList strlist;
917 if(!ui->enableSSECheckBox->isChecked())
918 strlist.append("sse");
919 if(!ui->enableSSE2CheckBox->isChecked())
920 strlist.append("sse2");
921 if(!ui->enableSSE3CheckBox->isChecked())
922 strlist.append("sse3");
923 if(!ui->enableSSE41CheckBox->isChecked())
924 strlist.append("sse4.1");
925 if(!ui->enableNeonCheckBox->isChecked())
926 strlist.append("neon");
927 settings.setValue("disable-cpu-exts", strlist.join(QChar(',')));
929 if(ui->hrtfStateComboBox->currentIndex() == 1)
930 settings.setValue("hrtf", "true");
931 else if(ui->hrtfStateComboBox->currentIndex() == 2)
932 settings.setValue("hrtf", "false");
933 else
934 settings.setValue("hrtf", QString());
936 if(ui->preferredHrtfComboBox->currentIndex() == 0)
937 settings.setValue("default-hrtf", QString());
938 else
940 QString str = ui->preferredHrtfComboBox->currentText();
941 settings.setValue("default-hrtf", str);
944 strlist.clear();
945 for(int i = 0;i < ui->hrtfFileList->count();i++)
946 strlist.append(ui->hrtfFileList->item(i)->text());
947 if(!strlist.empty() && ui->defaultHrtfPathsCheckBox->isChecked())
948 strlist.append(QString());
949 settings.setValue("hrtf-paths", strlist.join(QChar(',')));
951 strlist.clear();
952 for(int i = 0;i < ui->enabledBackendList->count();i++)
954 QString label = ui->enabledBackendList->item(i)->text();
955 for(int j = 0;backendList[j].backend_name[0];j++)
957 if(label == backendList[j].full_string)
959 strlist.append(backendList[j].backend_name);
960 break;
964 for(int i = 0;i < ui->disabledBackendList->count();i++)
966 QString label = ui->disabledBackendList->item(i)->text();
967 for(int j = 0;backendList[j].backend_name[0];j++)
969 if(label == backendList[j].full_string)
971 strlist.append(QChar('-')+QString(backendList[j].backend_name));
972 break;
976 if(strlist.size() == 0 && !ui->backendCheckBox->isChecked())
977 strlist.append("-all");
978 else if(ui->backendCheckBox->isChecked())
979 strlist.append(QString());
980 settings.setValue("drivers", strlist.join(QChar(',')));
982 // TODO: Remove check when we can properly match global values.
983 if(ui->defaultReverbComboBox->currentIndex() == 0)
984 settings.setValue("default-reverb", QString());
985 else
987 QString str = ui->defaultReverbComboBox->currentText().toLower();
988 settings.setValue("default-reverb", str);
991 if(ui->emulateEaxCheckBox->isChecked())
992 settings.setValue("reverb/emulate-eax", "true");
993 else
994 settings.remove("reverb/emulate-eax"/*, "false"*/);
996 strlist.clear();
997 if(!ui->enableEaxReverbCheck->isChecked())
998 strlist.append("eaxreverb");
999 if(!ui->enableStdReverbCheck->isChecked())
1000 strlist.append("reverb");
1001 if(!ui->enableChorusCheck->isChecked())
1002 strlist.append("chorus");
1003 if(!ui->enableDistortionCheck->isChecked())
1004 strlist.append("distortion");
1005 if(!ui->enableCompressorCheck->isChecked())
1006 strlist.append("compressor");
1007 if(!ui->enableEchoCheck->isChecked())
1008 strlist.append("echo");
1009 if(!ui->enableEqualizerCheck->isChecked())
1010 strlist.append("equalizer");
1011 if(!ui->enableFlangerCheck->isChecked())
1012 strlist.append("flanger");
1013 if(!ui->enableModulatorCheck->isChecked())
1014 strlist.append("modulator");
1015 if(!ui->enableDedicatedCheck->isChecked())
1016 strlist.append("dedicated");
1017 settings.setValue("excludefx", strlist.join(QChar(',')));
1019 settings.setValue("pulse/spawn-server",
1020 ui->pulseAutospawnCheckBox->isChecked() ? QString(/*"true"*/) : QString("false")
1022 settings.setValue("pulse/allow-moves",
1023 ui->pulseAllowMovesCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
1025 settings.setValue("pulse/fix-rate",
1026 ui->pulseFixRateCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
1029 settings.setValue("jack/spawn-server",
1030 ui->jackAutospawnCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
1032 settings.setValue("jack/buffer-size", ui->jackBufferSizeLine->text());
1034 settings.setValue("alsa/device", ui->alsaDefaultDeviceLine->text());
1035 settings.setValue("alsa/capture", ui->alsaDefaultCaptureLine->text());
1036 settings.setValue("alsa/allow-resampler",
1037 ui->alsaResamplerCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
1039 settings.setValue("alsa/mmap",
1040 ui->alsaMmapCheckBox->isChecked() ? QString(/*"true"*/) : QString("false")
1043 settings.setValue("oss/device", ui->ossDefaultDeviceLine->text());
1044 settings.setValue("oss/capture", ui->ossDefaultCaptureLine->text());
1046 settings.setValue("solaris/device", ui->solarisDefaultDeviceLine->text());
1048 settings.setValue("wave/file", ui->waveOutputLine->text());
1049 settings.setValue("wave/bformat",
1050 ui->waveBFormatCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
1053 /* Remove empty keys
1054 * FIXME: Should only remove keys whose value matches the globally-specified value.
1056 allkeys = settings.allKeys();
1057 foreach(const QString &key, allkeys)
1059 QString str = settings.value(key).toString();
1060 if(str == QString())
1061 settings.remove(key);
1066 void MainWindow::enableApplyButton()
1068 if(!mNeedsSave)
1069 ui->applyButton->setEnabled(true);
1070 mNeedsSave = true;
1071 ui->closeCancelButton->setText(tr("Cancel"));
1075 void MainWindow::updateResamplerLabel(int num)
1077 ui->resamplerLabel->setText(resamplerList[num].name);
1078 enableApplyButton();
1082 void MainWindow::updatePeriodSizeEdit(int size)
1084 ui->periodSizeEdit->clear();
1085 if(size >= 64)
1087 size = (size+32)&~0x3f;
1088 ui->periodSizeEdit->insert(QString::number(size));
1090 enableApplyButton();
1093 void MainWindow::updatePeriodSizeSlider()
1095 int pos = ui->periodSizeEdit->text().toInt();
1096 if(pos >= 64)
1098 if(pos > 8192)
1099 pos = 8192;
1100 ui->periodSizeSlider->setSliderPosition(pos);
1102 enableApplyButton();
1105 void MainWindow::updatePeriodCountEdit(int count)
1107 ui->periodCountEdit->clear();
1108 if(count >= 2)
1109 ui->periodCountEdit->insert(QString::number(count));
1110 enableApplyButton();
1113 void MainWindow::updatePeriodCountSlider()
1115 int pos = ui->periodCountEdit->text().toInt();
1116 if(pos < 2)
1117 pos = 0;
1118 else if(pos > 16)
1119 pos = 16;
1120 ui->periodCountSlider->setSliderPosition(pos);
1121 enableApplyButton();
1125 void MainWindow::selectQuadDecoderFile()
1126 { selectDecoderFile(ui->decoderQuadLineEdit, "Select Quadrophonic Decoder");}
1127 void MainWindow::select51DecoderFile()
1128 { selectDecoderFile(ui->decoder51LineEdit, "Select 5.1 Surround Decoder");}
1129 void MainWindow::select61DecoderFile()
1130 { selectDecoderFile(ui->decoder61LineEdit, "Select 6.1 Surround Decoder");}
1131 void MainWindow::select71DecoderFile()
1132 { selectDecoderFile(ui->decoder71LineEdit, "Select 7.1 Surround Decoder");}
1133 void MainWindow::selectDecoderFile(QLineEdit *line, const char *caption)
1135 QString dir = line->text();
1136 if(dir.isEmpty() || QDir::isRelativePath(dir))
1138 QStringList paths = getAllDataPaths("/openal/presets");
1139 while(!paths.isEmpty())
1141 if(QDir(paths.last()).exists())
1143 dir = paths.last();
1144 break;
1146 paths.removeLast();
1149 QString fname = QFileDialog::getOpenFileName(this, tr(caption),
1150 dir, tr("AmbDec Files (*.ambdec);;All Files (*.*)")
1152 if(!fname.isEmpty())
1154 line->setText(fname);
1155 enableApplyButton();
1160 void MainWindow::updateJackBufferSizeEdit(int size)
1162 ui->jackBufferSizeLine->clear();
1163 if(size > 0)
1164 ui->jackBufferSizeLine->insert(QString::number(1<<size));
1165 enableApplyButton();
1168 void MainWindow::updateJackBufferSizeSlider()
1170 int value = ui->jackBufferSizeLine->text().toInt();
1171 int pos = (int)floor(log2(value) + 0.5);
1172 ui->jackBufferSizeSlider->setSliderPosition(pos);
1173 enableApplyButton();
1177 void MainWindow::addHrtfFile()
1179 QString path = QFileDialog::getExistingDirectory(this, tr("Select HRTF Path"));
1180 if(path.isEmpty() == false && !getAllDataPaths("/openal/hrtf").contains(path))
1182 ui->hrtfFileList->addItem(path);
1183 enableApplyButton();
1187 void MainWindow::removeHrtfFile()
1189 QList<QListWidgetItem*> selected = ui->hrtfFileList->selectedItems();
1190 if(!selected.isEmpty())
1192 foreach(QListWidgetItem *item, selected)
1193 delete item;
1194 enableApplyButton();
1198 void MainWindow::updateHrtfRemoveButton()
1200 ui->hrtfRemoveButton->setEnabled(ui->hrtfFileList->selectedItems().size() != 0);
1203 void MainWindow::showEnabledBackendMenu(QPoint pt)
1205 QMap<QAction*,QString> actionMap;
1207 pt = ui->enabledBackendList->mapToGlobal(pt);
1209 QMenu ctxmenu;
1210 QAction *removeAction = ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove");
1211 if(ui->enabledBackendList->selectedItems().size() == 0)
1212 removeAction->setEnabled(false);
1213 ctxmenu.addSeparator();
1214 for(size_t i = 0;backendList[i].backend_name[0];i++)
1216 QString backend = backendList[i].full_string;
1217 QAction *action = ctxmenu.addAction(QString("Add ")+backend);
1218 actionMap[action] = backend;
1219 if(ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0 ||
1220 ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0)
1221 action->setEnabled(false);
1224 QAction *gotAction = ctxmenu.exec(pt);
1225 if(gotAction == removeAction)
1227 QList<QListWidgetItem*> selected = ui->enabledBackendList->selectedItems();
1228 foreach(QListWidgetItem *item, selected)
1229 delete item;
1230 enableApplyButton();
1232 else if(gotAction != NULL)
1234 QMap<QAction*,QString>::const_iterator iter = actionMap.find(gotAction);
1235 if(iter != actionMap.end())
1236 ui->enabledBackendList->addItem(iter.value());
1237 enableApplyButton();
1241 void MainWindow::showDisabledBackendMenu(QPoint pt)
1243 QMap<QAction*,QString> actionMap;
1245 pt = ui->disabledBackendList->mapToGlobal(pt);
1247 QMenu ctxmenu;
1248 QAction *removeAction = ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove");
1249 if(ui->disabledBackendList->selectedItems().size() == 0)
1250 removeAction->setEnabled(false);
1251 ctxmenu.addSeparator();
1252 for(size_t i = 0;backendList[i].backend_name[0];i++)
1254 QString backend = backendList[i].full_string;
1255 QAction *action = ctxmenu.addAction(QString("Add ")+backend);
1256 actionMap[action] = backend;
1257 if(ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0 ||
1258 ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0)
1259 action->setEnabled(false);
1262 QAction *gotAction = ctxmenu.exec(pt);
1263 if(gotAction == removeAction)
1265 QList<QListWidgetItem*> selected = ui->disabledBackendList->selectedItems();
1266 foreach(QListWidgetItem *item, selected)
1267 delete item;
1268 enableApplyButton();
1270 else if(gotAction != NULL)
1272 QMap<QAction*,QString>::const_iterator iter = actionMap.find(gotAction);
1273 if(iter != actionMap.end())
1274 ui->disabledBackendList->addItem(iter.value());
1275 enableApplyButton();
1279 void MainWindow::selectOSSPlayback()
1281 QString current = ui->ossDefaultDeviceLine->text();
1282 if(current.isEmpty()) current = ui->ossDefaultDeviceLine->placeholderText();
1283 QString fname = QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current);
1284 if(!fname.isEmpty())
1286 ui->ossDefaultDeviceLine->setText(fname);
1287 enableApplyButton();
1291 void MainWindow::selectOSSCapture()
1293 QString current = ui->ossDefaultCaptureLine->text();
1294 if(current.isEmpty()) current = ui->ossDefaultCaptureLine->placeholderText();
1295 QString fname = QFileDialog::getOpenFileName(this, tr("Select Capture Device"), current);
1296 if(!fname.isEmpty())
1298 ui->ossDefaultCaptureLine->setText(fname);
1299 enableApplyButton();
1303 void MainWindow::selectSolarisPlayback()
1305 QString current = ui->solarisDefaultDeviceLine->text();
1306 if(current.isEmpty()) current = ui->solarisDefaultDeviceLine->placeholderText();
1307 QString fname = QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current);
1308 if(!fname.isEmpty())
1310 ui->solarisDefaultDeviceLine->setText(fname);
1311 enableApplyButton();
1315 void MainWindow::selectWaveOutput()
1317 QString fname = QFileDialog::getSaveFileName(this, tr("Select Wave File Output"),
1318 ui->waveOutputLine->text(), tr("Wave Files (*.wav *.amb);;All Files (*.*)")
1320 if(!fname.isEmpty())
1322 ui->waveOutputLine->setText(fname);
1323 enableApplyButton();