Ignore the listening angle for the wet path sound cones
[openal-soft.git] / utils / alsoft-config / mainwindow.cpp
blobbbe179e11a3302d94be83d7ff0753b48858e7102
2 #include "config.h"
4 #include <iostream>
5 #include <cmath>
7 #include <QFileDialog>
8 #include <QMessageBox>
9 #include <QCloseEvent>
10 #include <QSettings>
11 #include <QtGlobal>
12 #include "mainwindow.h"
13 #include "ui_mainwindow.h"
15 namespace {
17 static const struct {
18 char backend_name[16];
19 char full_string[32];
20 } backendList[] = {
21 #ifdef HAVE_JACK
22 { "jack", "JACK" },
23 #endif
24 #ifdef HAVE_PULSEAUDIO
25 { "pulse", "PulseAudio" },
26 #endif
27 #ifdef HAVE_ALSA
28 { "alsa", "ALSA" },
29 #endif
30 #ifdef HAVE_COREAUDIO
31 { "core", "CoreAudio" },
32 #endif
33 #ifdef HAVE_OSS
34 { "oss", "OSS" },
35 #endif
36 #ifdef HAVE_SOLARIS
37 { "solaris", "Solaris" },
38 #endif
39 #ifdef HAVE_SNDIO
40 { "sndio", "SoundIO" },
41 #endif
42 #ifdef HAVE_QSA
43 { "qsa", "QSA" },
44 #endif
45 #ifdef HAVE_MMDEVAPI
46 { "mmdevapi", "MMDevAPI" },
47 #endif
48 #ifdef HAVE_DSOUND
49 { "dsound", "DirectSound" },
50 #endif
51 #ifdef HAVE_WINMM
52 { "winmm", "Windows Multimedia" },
53 #endif
54 #ifdef HAVE_PORTAUDIO
55 { "port", "PortAudio" },
56 #endif
57 #ifdef HAVE_OPENSL
58 { "opensl", "OpenSL" },
59 #endif
61 { "null", "Null Output" },
62 #ifdef HAVE_WAVE
63 { "wave", "Wave Writer" },
64 #endif
65 { "", "" }
68 static const struct NameValuePair {
69 const char name[64];
70 const char value[16];
71 } speakerModeList[] = {
72 { "Autodetect", "" },
73 { "Mono", "mono" },
74 { "Stereo", "stereo" },
75 { "Quadrophonic", "quad" },
76 { "5.1 Surround (Side)", "surround51" },
77 { "5.1 Surround (Rear)", "surround51rear" },
78 { "6.1 Surround", "surround61" },
79 { "7.1 Surround", "surround71" },
81 { "", "" }
82 }, sampleTypeList[] = {
83 { "Autodetect", "" },
84 { "8-bit int", "int8" },
85 { "8-bit uint", "uint8" },
86 { "16-bit int", "int16" },
87 { "16-bit uint", "uint16" },
88 { "32-bit int", "int32" },
89 { "32-bit uint", "uint32" },
90 { "32-bit float", "float32" },
92 { "", "" }
93 }, resamplerList[] = {
94 { "Point", "point" },
95 { "Linear", "linear" },
96 { "Default (Linear)", "" },
97 { "4-Point Sinc", "sinc4" },
98 { "8-Point Sinc", "sinc8" },
99 { "Band-limited Sinc", "bsinc" },
101 { "", "" }
102 }, stereoModeList[] = {
103 { "Autodetect", "" },
104 { "Speakers", "speakers" },
105 { "Headphones", "headphones" },
107 { "", "" }
108 }, stereoPanList[] = {
109 { "Default", "" },
110 { "UHJ", "uhj" },
111 { "Pair-Wise", "paired" },
113 { "", "" }
116 static QString getDefaultConfigName()
118 #ifdef Q_OS_WIN32
119 static const char fname[] = "alsoft.ini";
120 QByteArray base = qgetenv("AppData");
121 #else
122 static const char fname[] = "alsoft.conf";
123 QByteArray base = qgetenv("XDG_CONFIG_HOME");
124 if(base.isEmpty())
126 base = qgetenv("HOME");
127 if(base.isEmpty() == false)
128 base += "/.config";
130 #endif
131 if(base.isEmpty() == false)
132 return base +'/'+ fname;
133 return fname;
136 static QString getBaseDataPath()
138 #ifdef Q_OS_WIN32
139 QByteArray base = qgetenv("AppData");
140 #else
141 QByteArray base = qgetenv("XDG_DATA_HOME");
142 if(base.isEmpty())
144 base = qgetenv("HOME");
145 if(!base.isEmpty())
146 base += "/.local/share";
148 #endif
149 return base;
152 static QStringList getAllDataPaths(QString append=QString())
154 QStringList list;
155 list.append(getBaseDataPath());
156 #ifdef Q_OS_WIN32
157 // TODO: Common AppData path
158 #else
159 QString paths = qgetenv("XDG_DATA_DIRS");
160 if(paths.isEmpty())
161 paths = "/usr/local/share/:/usr/share/";
162 list += paths.split(QChar(':'), QString::SkipEmptyParts);
163 #endif
164 QStringList::iterator iter = list.begin();
165 while(iter != list.end())
167 if(iter->isEmpty())
168 iter = list.erase(iter);
169 else
171 iter->append(append);
172 iter++;
175 return list;
178 template<size_t N>
179 static QString getValueFromName(const NameValuePair (&list)[N], const QString &str)
181 for(size_t i = 0;i < N-1;i++)
183 if(str == list[i].name)
184 return list[i].value;
186 return QString();
189 template<size_t N>
190 static QString getNameFromValue(const NameValuePair (&list)[N], const QString &str)
192 for(size_t i = 0;i < N-1;i++)
194 if(str == list[i].value)
195 return list[i].name;
197 return QString();
202 MainWindow::MainWindow(QWidget *parent) :
203 QMainWindow(parent),
204 ui(new Ui::MainWindow),
205 mPeriodSizeValidator(NULL),
206 mPeriodCountValidator(NULL),
207 mSourceCountValidator(NULL),
208 mEffectSlotValidator(NULL),
209 mSourceSendValidator(NULL),
210 mSampleRateValidator(NULL),
211 mJackBufferValidator(NULL),
212 mNeedsSave(false)
214 ui->setupUi(this);
216 for(int i = 0;speakerModeList[i].name[0];i++)
217 ui->channelConfigCombo->addItem(speakerModeList[i].name);
218 ui->channelConfigCombo->adjustSize();
219 for(int i = 0;sampleTypeList[i].name[0];i++)
220 ui->sampleFormatCombo->addItem(sampleTypeList[i].name);
221 ui->sampleFormatCombo->adjustSize();
222 for(int i = 0;stereoModeList[i].name[0];i++)
223 ui->stereoModeCombo->addItem(stereoModeList[i].name);
224 ui->stereoModeCombo->adjustSize();
225 for(int i = 0;stereoPanList[i].name[0];i++)
226 ui->stereoPanningComboBox->addItem(stereoPanList[i].name);
227 ui->stereoPanningComboBox->adjustSize();
229 int count;
230 for(count = 0;resamplerList[count].name[0];count++) {
232 ui->resamplerSlider->setRange(0, count-1);
234 ui->hrtfStateComboBox->adjustSize();
236 #if !defined(HAVE_NEON) && !defined(HAVE_SSE)
237 ui->cpuExtDisabledLabel->move(ui->cpuExtDisabledLabel->x(), ui->cpuExtDisabledLabel->y() - 60);
238 #else
239 ui->cpuExtDisabledLabel->setVisible(false);
240 #endif
242 #ifndef HAVE_NEON
244 #ifndef HAVE_SSE4_1
245 #ifndef HAVE_SSE3
246 #ifndef HAVE_SSE2
247 #ifndef HAVE_SSE
248 ui->enableSSECheckBox->setVisible(false);
249 #endif /* !SSE */
250 ui->enableSSE2CheckBox->setVisible(false);
251 #endif /* !SSE2 */
252 ui->enableSSE3CheckBox->setVisible(false);
253 #endif /* !SSE3 */
254 ui->enableSSE41CheckBox->setVisible(false);
255 #endif /* !SSE4.1 */
256 ui->enableNeonCheckBox->setVisible(false);
258 #else /* !Neon */
260 #ifndef HAVE_SSE4_1
261 #ifndef HAVE_SSE3
262 #ifndef HAVE_SSE2
263 #ifndef HAVE_SSE
264 ui->enableNeonCheckBox->move(ui->enableNeonCheckBox->x(), ui->enableNeonCheckBox->y() - 30);
265 ui->enableSSECheckBox->setVisible(false);
266 #endif /* !SSE */
267 ui->enableSSE2CheckBox->setVisible(false);
268 #endif /* !SSE2 */
269 ui->enableSSE3CheckBox->setVisible(false);
270 #endif /* !SSE3 */
271 ui->enableSSE41CheckBox->setVisible(false);
272 #endif /* !SSE4.1 */
274 #endif
276 mPeriodSizeValidator = new QIntValidator(64, 8192, this);
277 ui->periodSizeEdit->setValidator(mPeriodSizeValidator);
278 mPeriodCountValidator = new QIntValidator(2, 16, this);
279 ui->periodCountEdit->setValidator(mPeriodCountValidator);
281 mSourceCountValidator = new QIntValidator(0, 4096, this);
282 ui->srcCountLineEdit->setValidator(mSourceCountValidator);
283 mEffectSlotValidator = new QIntValidator(0, 16, this);
284 ui->effectSlotLineEdit->setValidator(mEffectSlotValidator);
285 mSourceSendValidator = new QIntValidator(0, 4, this);
286 ui->srcSendLineEdit->setValidator(mSourceSendValidator);
287 mSampleRateValidator = new QIntValidator(8000, 192000, this);
288 ui->sampleRateCombo->lineEdit()->setValidator(mSampleRateValidator);
290 mJackBufferValidator = new QIntValidator(0, 8192, this);
291 ui->jackBufferSizeLine->setValidator(mJackBufferValidator);
293 connect(ui->actionLoad, SIGNAL(triggered()), this, SLOT(loadConfigFromFile()));
294 connect(ui->actionSave_As, SIGNAL(triggered()), this, SLOT(saveConfigAsFile()));
296 connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAboutPage()));
298 connect(ui->closeCancelButton, SIGNAL(clicked()), this, SLOT(cancelCloseAction()));
299 connect(ui->applyButton, SIGNAL(clicked()), this, SLOT(saveCurrentConfig()));
301 connect(ui->channelConfigCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
302 connect(ui->sampleFormatCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
303 connect(ui->stereoModeCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
304 connect(ui->sampleRateCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
305 connect(ui->sampleRateCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(enableApplyButton()));
307 connect(ui->resamplerSlider, SIGNAL(valueChanged(int)), this, SLOT(updateResamplerLabel(int)));
309 connect(ui->periodSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(updatePeriodSizeEdit(int)));
310 connect(ui->periodSizeEdit, SIGNAL(editingFinished()), this, SLOT(updatePeriodSizeSlider()));
311 connect(ui->periodCountSlider, SIGNAL(valueChanged(int)), this, SLOT(updatePeriodCountEdit(int)));
312 connect(ui->periodCountEdit, SIGNAL(editingFinished()), this, SLOT(updatePeriodCountSlider()));
314 connect(ui->stereoPanningComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(enableApplyButton()));
316 connect(ui->decoderHQModeCheckBox, SIGNAL(stateChanged(int)), this, SLOT(toggleHqState(int)));
317 connect(ui->decoderDistCompCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
318 connect(ui->decoderQuadLineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
319 connect(ui->decoderQuadButton, SIGNAL(clicked()), this, SLOT(selectQuadDecoderFile()));
320 connect(ui->decoder51LineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
321 connect(ui->decoder51Button, SIGNAL(clicked()), this, SLOT(select51DecoderFile()));
322 connect(ui->decoder51RearLineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
323 connect(ui->decoder51RearButton, SIGNAL(clicked()), this, SLOT(select51RearDecoderFile()));
324 connect(ui->decoder61LineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
325 connect(ui->decoder61Button, SIGNAL(clicked()), this, SLOT(select61DecoderFile()));
326 connect(ui->decoder71LineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
327 connect(ui->decoder71Button, SIGNAL(clicked()), this, SLOT(select71DecoderFile()));
329 connect(ui->preferredHrtfComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
330 connect(ui->hrtfStateComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
331 connect(ui->hrtfAddButton, SIGNAL(clicked()), this, SLOT(addHrtfFile()));
332 connect(ui->hrtfRemoveButton, SIGNAL(clicked()), this, SLOT(removeHrtfFile()));
333 connect(ui->hrtfFileList, SIGNAL(itemSelectionChanged()), this, SLOT(updateHrtfRemoveButton()));
334 connect(ui->defaultHrtfPathsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
336 connect(ui->srcCountLineEdit, SIGNAL(editingFinished()), this, SLOT(enableApplyButton()));
337 connect(ui->srcSendLineEdit, SIGNAL(editingFinished()), this, SLOT(enableApplyButton()));
338 connect(ui->effectSlotLineEdit, SIGNAL(editingFinished()), this, SLOT(enableApplyButton()));
340 connect(ui->enableSSECheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
341 connect(ui->enableSSE2CheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
342 connect(ui->enableSSE3CheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
343 connect(ui->enableSSE41CheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
344 connect(ui->enableNeonCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
346 ui->enabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
347 connect(ui->enabledBackendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showEnabledBackendMenu(QPoint)));
349 ui->disabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
350 connect(ui->disabledBackendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showDisabledBackendMenu(QPoint)));
351 connect(ui->backendCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
353 connect(ui->defaultReverbComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
354 connect(ui->emulateEaxCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
355 connect(ui->enableEaxReverbCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
356 connect(ui->enableStdReverbCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
357 connect(ui->enableChorusCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
358 connect(ui->enableCompressorCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
359 connect(ui->enableDistortionCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
360 connect(ui->enableEchoCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
361 connect(ui->enableEqualizerCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
362 connect(ui->enableFlangerCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
363 connect(ui->enableModulatorCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
364 connect(ui->enableDedicatedCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
366 connect(ui->pulseAutospawnCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
367 connect(ui->pulseAllowMovesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
368 connect(ui->pulseFixRateCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
370 connect(ui->jackAutospawnCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
371 connect(ui->jackBufferSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(updateJackBufferSizeEdit(int)));
372 connect(ui->jackBufferSizeLine, SIGNAL(editingFinished()), this, SLOT(updateJackBufferSizeSlider()));
374 connect(ui->alsaDefaultDeviceLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
375 connect(ui->alsaDefaultCaptureLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
376 connect(ui->alsaResamplerCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
377 connect(ui->alsaMmapCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
379 connect(ui->ossDefaultDeviceLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
380 connect(ui->ossPlaybackPushButton, SIGNAL(clicked(bool)), this, SLOT(selectOSSPlayback()));
381 connect(ui->ossDefaultCaptureLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
382 connect(ui->ossCapturePushButton, SIGNAL(clicked(bool)), this, SLOT(selectOSSCapture()));
384 connect(ui->solarisDefaultDeviceLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
385 connect(ui->solarisPlaybackPushButton, SIGNAL(clicked(bool)), this, SLOT(selectSolarisPlayback()));
387 connect(ui->waveOutputLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
388 connect(ui->waveOutputButton, SIGNAL(clicked(bool)), this, SLOT(selectWaveOutput()));
389 connect(ui->waveBFormatCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
391 ui->backendListWidget->setCurrentRow(0);
392 ui->tabWidget->setCurrentIndex(0);
394 for(int i = 1;i < ui->backendListWidget->count();i++)
395 ui->backendListWidget->setRowHidden(i, true);
396 for(int i = 0;backendList[i].backend_name[0];i++)
398 QList<QListWidgetItem*> items = ui->backendListWidget->findItems(
399 backendList[i].full_string, Qt::MatchFixedString
401 foreach(const QListWidgetItem *item, items)
402 ui->backendListWidget->setItemHidden(item, false);
405 loadConfig(getDefaultConfigName());
408 MainWindow::~MainWindow()
410 delete ui;
411 delete mPeriodSizeValidator;
412 delete mPeriodCountValidator;
413 delete mSourceCountValidator;
414 delete mEffectSlotValidator;
415 delete mSourceSendValidator;
416 delete mSampleRateValidator;
417 delete mJackBufferValidator;
420 void MainWindow::closeEvent(QCloseEvent *event)
422 if(!mNeedsSave)
423 event->accept();
424 else
426 QMessageBox::StandardButton btn = QMessageBox::warning(this,
427 tr("Apply changes?"), tr("Save changes before quitting?"),
428 QMessageBox::Save | QMessageBox::No | QMessageBox::Cancel
430 if(btn == QMessageBox::Save)
431 saveCurrentConfig();
432 if(btn == QMessageBox::Cancel)
433 event->ignore();
434 else
435 event->accept();
439 void MainWindow::cancelCloseAction()
441 mNeedsSave = false;
442 close();
446 void MainWindow::showAboutPage()
448 QMessageBox::information(this, tr("About"),
449 tr("OpenAL Soft Configuration Utility.\nBuilt for OpenAL Soft library version ")+(ALSOFT_VERSION ".")
454 QStringList MainWindow::collectHrtfs()
456 QStringList ret;
458 for(int i = 0;i < ui->hrtfFileList->count();i++)
460 QDir dir(ui->hrtfFileList->item(i)->text());
461 QStringList fnames = dir.entryList(QDir::Files | QDir::Readable, QDir::Name);
462 foreach(const QString &fname, fnames)
464 if(!fname.endsWith(".mhr", Qt::CaseInsensitive))
465 continue;
467 QString name = fname.left(fname.length()-4);
468 if(!ret.contains(name))
469 ret.push_back(name);
470 else
472 size_t i = 1;
473 do {
474 QString s = name+" #"+QString::number(i);
475 if(!ret.contains(s))
477 ret.push_back(s);
478 break;
480 ++i;
481 } while(1);
486 if(ui->defaultHrtfPathsCheckBox->isChecked())
488 QStringList paths = getAllDataPaths("/openal/hrtf");
489 foreach(const QString &name, paths)
491 QDir dir(name);
492 QStringList fnames = dir.entryList(QDir::Files | QDir::Readable, QDir::Name);
493 foreach(const QString &fname, fnames)
495 if(!fname.endsWith(".mhr", Qt::CaseInsensitive))
496 continue;
498 QString name = fname.left(fname.length()-4);
499 if(!ret.contains(name))
500 ret.push_back(name);
501 else
503 size_t i = 1;
504 do {
505 QString s = name+" #"+QString::number(i);
506 if(!ret.contains(s))
508 ret.push_back(s);
509 break;
511 ++i;
512 } while(1);
517 return ret;
521 void MainWindow::loadConfigFromFile()
523 QString fname = QFileDialog::getOpenFileName(this, tr("Select Files"));
524 if(fname.isEmpty() == false)
525 loadConfig(fname);
528 void MainWindow::loadConfig(const QString &fname)
530 QSettings settings(fname, QSettings::IniFormat);
532 QString sampletype = settings.value("sample-type").toString();
533 ui->sampleFormatCombo->setCurrentIndex(0);
534 if(sampletype.isEmpty() == false)
536 QString str = getNameFromValue(sampleTypeList, sampletype);
537 if(!str.isEmpty())
539 int j = ui->sampleFormatCombo->findText(str);
540 if(j > 0) ui->sampleFormatCombo->setCurrentIndex(j);
544 QString channelconfig = settings.value("channels").toString();
545 ui->channelConfigCombo->setCurrentIndex(0);
546 if(channelconfig.isEmpty() == false)
548 QString str = getNameFromValue(speakerModeList, channelconfig);
549 if(!str.isEmpty())
551 int j = ui->channelConfigCombo->findText(str);
552 if(j > 0) ui->channelConfigCombo->setCurrentIndex(j);
556 QString srate = settings.value("frequency").toString();
557 if(srate.isEmpty())
558 ui->sampleRateCombo->setCurrentIndex(0);
559 else
561 ui->sampleRateCombo->lineEdit()->clear();
562 ui->sampleRateCombo->lineEdit()->insert(srate);
565 ui->srcCountLineEdit->clear();
566 ui->srcCountLineEdit->insert(settings.value("sources").toString());
567 ui->effectSlotLineEdit->clear();
568 ui->effectSlotLineEdit->insert(settings.value("slots").toString());
569 ui->srcSendLineEdit->clear();
570 ui->srcSendLineEdit->insert(settings.value("sends").toString());
572 QString resampler = settings.value("resampler").toString().trimmed();
573 ui->resamplerSlider->setValue(0);
574 /* The "cubic" resampler is no longer supported. It's been replaced by
575 * "sinc4". */
576 if(resampler == "cubic")
577 resampler = "sinc4";
578 for(int i = 0;resamplerList[i].name[0];i++)
580 if(resampler == resamplerList[i].value)
582 ui->resamplerSlider->setValue(i);
583 break;
587 QString stereomode = settings.value("stereo-mode").toString().trimmed();
588 ui->stereoModeCombo->setCurrentIndex(0);
589 if(stereomode.isEmpty() == false)
591 QString str = getNameFromValue(stereoModeList, stereomode);
592 if(!str.isEmpty())
594 int j = ui->stereoModeCombo->findText(str);
595 if(j > 0) ui->stereoModeCombo->setCurrentIndex(j);
599 int periodsize = settings.value("period_size").toInt();
600 ui->periodSizeEdit->clear();
601 if(periodsize >= 64)
603 ui->periodSizeEdit->insert(QString::number(periodsize));
604 updatePeriodSizeSlider();
607 int periodcount = settings.value("periods").toInt();
608 ui->periodCountEdit->clear();
609 if(periodcount >= 2)
611 ui->periodCountEdit->insert(QString::number(periodcount));
612 updatePeriodCountSlider();
615 QString stereopan = settings.value("stereo-panning").toString();
616 ui->stereoPanningComboBox->setCurrentIndex(0);
617 if(stereopan.isEmpty() == false)
619 QString str = getNameFromValue(stereoPanList, stereopan);
620 if(!str.isEmpty())
622 int j = ui->stereoPanningComboBox->findText(str);
623 if(j > 0) ui->stereoPanningComboBox->setCurrentIndex(j);
627 bool hqmode = settings.value("decoder/hq-mode", false).toBool();
628 ui->decoderHQModeCheckBox->setChecked(hqmode);
629 bool distcomp = settings.value("decoder/distance-comp", true).toBool();
630 ui->decoderDistCompCheckBox->setChecked(distcomp);
631 ui->decoderDistCompCheckBox->setEnabled(hqmode);
633 ui->decoderQuadLineEdit->setText(settings.value("decoder/quad").toString());
634 ui->decoder51LineEdit->setText(settings.value("decoder/surround51").toString());
635 ui->decoder51RearLineEdit->setText(settings.value("decoder/surround51rear").toString());
636 ui->decoder61LineEdit->setText(settings.value("decoder/surround61").toString());
637 ui->decoder71LineEdit->setText(settings.value("decoder/surround71").toString());
639 QStringList disabledCpuExts = settings.value("disable-cpu-exts").toStringList();
640 if(disabledCpuExts.size() == 1)
641 disabledCpuExts = disabledCpuExts[0].split(QChar(','));
642 std::transform(disabledCpuExts.begin(), disabledCpuExts.end(),
643 disabledCpuExts.begin(), std::mem_fun_ref(&QString::trimmed));
644 ui->enableSSECheckBox->setChecked(!disabledCpuExts.contains("sse", Qt::CaseInsensitive));
645 ui->enableSSE2CheckBox->setChecked(!disabledCpuExts.contains("sse2", Qt::CaseInsensitive));
646 ui->enableSSE3CheckBox->setChecked(!disabledCpuExts.contains("sse3", Qt::CaseInsensitive));
647 ui->enableSSE41CheckBox->setChecked(!disabledCpuExts.contains("sse4.1", Qt::CaseInsensitive));
648 ui->enableNeonCheckBox->setChecked(!disabledCpuExts.contains("neon", Qt::CaseInsensitive));
650 QStringList hrtf_paths = settings.value("hrtf-paths").toStringList();
651 if(hrtf_paths.size() == 1)
652 hrtf_paths = hrtf_paths[0].split(QChar(','));
653 std::transform(hrtf_paths.begin(), hrtf_paths.end(),
654 hrtf_paths.begin(), std::mem_fun_ref(&QString::trimmed));
655 if(!hrtf_paths.empty() && !hrtf_paths.back().isEmpty())
656 ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Unchecked);
657 else
659 hrtf_paths.removeAll(QString());
660 ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Checked);
662 hrtf_paths.removeDuplicates();
663 ui->hrtfFileList->clear();
664 ui->hrtfFileList->addItems(hrtf_paths);
665 updateHrtfRemoveButton();
667 QString hrtfstate = settings.value("hrtf").toString().toLower();
668 if(hrtfstate == "true")
669 ui->hrtfStateComboBox->setCurrentIndex(1);
670 else if(hrtfstate == "false")
671 ui->hrtfStateComboBox->setCurrentIndex(2);
672 else
673 ui->hrtfStateComboBox->setCurrentIndex(0);
675 ui->preferredHrtfComboBox->clear();
676 ui->preferredHrtfComboBox->addItem("- Any -");
677 if(ui->defaultHrtfPathsCheckBox->isChecked())
679 QStringList hrtfs = collectHrtfs();
680 foreach(const QString &name, hrtfs)
681 ui->preferredHrtfComboBox->addItem(name);
684 QString defaulthrtf = settings.value("default-hrtf").toString();
685 ui->preferredHrtfComboBox->setCurrentIndex(0);
686 if(defaulthrtf.isEmpty() == false)
688 int i = ui->preferredHrtfComboBox->findText(defaulthrtf);
689 if(i > 0)
690 ui->preferredHrtfComboBox->setCurrentIndex(i);
691 else
693 i = ui->preferredHrtfComboBox->count();
694 ui->preferredHrtfComboBox->addItem(defaulthrtf);
695 ui->preferredHrtfComboBox->setCurrentIndex(i);
698 ui->preferredHrtfComboBox->adjustSize();
700 ui->enabledBackendList->clear();
701 ui->disabledBackendList->clear();
702 QStringList drivers = settings.value("drivers").toStringList();
703 if(drivers.size() == 0)
704 ui->backendCheckBox->setChecked(true);
705 else
707 if(drivers.size() == 1)
708 drivers = drivers[0].split(QChar(','));
709 std::transform(drivers.begin(), drivers.end(),
710 drivers.begin(), std::mem_fun_ref(&QString::trimmed));
712 bool lastWasEmpty = false;
713 foreach(const QString &backend, drivers)
715 lastWasEmpty = backend.isEmpty();
716 if(lastWasEmpty) continue;
718 if(!backend.startsWith(QChar('-')))
719 for(int j = 0;backendList[j].backend_name[0];j++)
721 if(backend == backendList[j].backend_name)
723 ui->enabledBackendList->addItem(backendList[j].full_string);
724 break;
727 else if(backend.size() > 1)
729 QStringRef backendref = backend.rightRef(backend.size()-1);
730 for(int j = 0;backendList[j].backend_name[0];j++)
732 if(backendref == backendList[j].backend_name)
734 ui->disabledBackendList->addItem(backendList[j].full_string);
735 break;
740 ui->backendCheckBox->setChecked(lastWasEmpty);
743 QString defaultreverb = settings.value("default-reverb").toString().toLower();
744 ui->defaultReverbComboBox->setCurrentIndex(0);
745 if(defaultreverb.isEmpty() == false)
747 for(int i = 0;i < ui->defaultReverbComboBox->count();i++)
749 if(defaultreverb.compare(ui->defaultReverbComboBox->itemText(i).toLower()) == 0)
751 ui->defaultReverbComboBox->setCurrentIndex(i);
752 break;
757 ui->emulateEaxCheckBox->setChecked(settings.value("reverb/emulate-eax", false).toBool());
759 QStringList excludefx = settings.value("excludefx").toStringList();
760 if(excludefx.size() == 1)
761 excludefx = excludefx[0].split(QChar(','));
762 std::transform(excludefx.begin(), excludefx.end(),
763 excludefx.begin(), std::mem_fun_ref(&QString::trimmed));
764 ui->enableEaxReverbCheck->setChecked(!excludefx.contains("eaxreverb", Qt::CaseInsensitive));
765 ui->enableStdReverbCheck->setChecked(!excludefx.contains("reverb", Qt::CaseInsensitive));
766 ui->enableChorusCheck->setChecked(!excludefx.contains("chorus", Qt::CaseInsensitive));
767 ui->enableCompressorCheck->setChecked(!excludefx.contains("compressor", Qt::CaseInsensitive));
768 ui->enableDistortionCheck->setChecked(!excludefx.contains("distortion", Qt::CaseInsensitive));
769 ui->enableEchoCheck->setChecked(!excludefx.contains("echo", Qt::CaseInsensitive));
770 ui->enableEqualizerCheck->setChecked(!excludefx.contains("equalizer", Qt::CaseInsensitive));
771 ui->enableFlangerCheck->setChecked(!excludefx.contains("flanger", Qt::CaseInsensitive));
772 ui->enableModulatorCheck->setChecked(!excludefx.contains("modulator", Qt::CaseInsensitive));
773 ui->enableDedicatedCheck->setChecked(!excludefx.contains("dedicated", Qt::CaseInsensitive));
775 ui->pulseAutospawnCheckBox->setChecked(settings.value("pulse/spawn-server", true).toBool());
776 ui->pulseAllowMovesCheckBox->setChecked(settings.value("pulse/allow-moves", false).toBool());
777 ui->pulseFixRateCheckBox->setChecked(settings.value("pulse/fix-rate", false).toBool());
779 ui->jackAutospawnCheckBox->setChecked(settings.value("jack/spawn-server", false).toBool());
780 ui->jackBufferSizeLine->setText(settings.value("jack/buffer-size", QString()).toString());
781 updateJackBufferSizeSlider();
783 ui->alsaDefaultDeviceLine->setText(settings.value("alsa/device", QString()).toString());
784 ui->alsaDefaultCaptureLine->setText(settings.value("alsa/capture", QString()).toString());
785 ui->alsaResamplerCheckBox->setChecked(settings.value("alsa/allow-resampler", false).toBool());
786 ui->alsaMmapCheckBox->setChecked(settings.value("alsa/mmap", true).toBool());
788 ui->ossDefaultDeviceLine->setText(settings.value("oss/device", QString()).toString());
789 ui->ossDefaultCaptureLine->setText(settings.value("oss/capture", QString()).toString());
791 ui->solarisDefaultDeviceLine->setText(settings.value("solaris/device", QString()).toString());
793 ui->waveOutputLine->setText(settings.value("wave/file", QString()).toString());
794 ui->waveBFormatCheckBox->setChecked(settings.value("wave/bformat", false).toBool());
796 ui->applyButton->setEnabled(false);
797 ui->closeCancelButton->setText(tr("Close"));
798 mNeedsSave = false;
801 void MainWindow::saveCurrentConfig()
803 saveConfig(getDefaultConfigName());
804 ui->applyButton->setEnabled(false);
805 ui->closeCancelButton->setText(tr("Close"));
806 mNeedsSave = false;
807 QMessageBox::information(this, tr("Information"),
808 tr("Applications using OpenAL need to be restarted for changes to take effect."));
811 void MainWindow::saveConfigAsFile()
813 QString fname = QFileDialog::getOpenFileName(this, tr("Select Files"));
814 if(fname.isEmpty() == false)
816 saveConfig(fname);
817 ui->applyButton->setEnabled(false);
818 mNeedsSave = false;
822 void MainWindow::saveConfig(const QString &fname) const
824 QSettings settings(fname, QSettings::IniFormat);
826 /* HACK: Compound any stringlist values into a comma-separated string. */
827 QStringList allkeys = settings.allKeys();
828 foreach(const QString &key, allkeys)
830 QStringList vals = settings.value(key).toStringList();
831 if(vals.size() > 1)
832 settings.setValue(key, vals.join(QChar(',')));
835 settings.setValue("sample-type", getValueFromName(sampleTypeList, ui->sampleFormatCombo->currentText()));
836 settings.setValue("channels", getValueFromName(speakerModeList, ui->channelConfigCombo->currentText()));
838 uint rate = ui->sampleRateCombo->currentText().toUInt();
839 if(!(rate > 0))
840 settings.setValue("frequency", QString());
841 else
842 settings.setValue("frequency", rate);
844 settings.setValue("period_size", ui->periodSizeEdit->text());
845 settings.setValue("periods", ui->periodCountEdit->text());
847 settings.setValue("sources", ui->srcCountLineEdit->text());
848 settings.setValue("slots", ui->effectSlotLineEdit->text());
850 settings.setValue("resampler", resamplerList[ui->resamplerSlider->value()].value);
852 settings.setValue("stereo-mode", getValueFromName(stereoModeList, ui->stereoModeCombo->currentText()));
853 settings.setValue("stereo-panning", getValueFromName(stereoPanList, ui->stereoPanningComboBox->currentText()));
855 settings.setValue("decoder/hq-mode",
856 ui->decoderHQModeCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
858 settings.setValue("decoder/distance-comp",
859 ui->decoderDistCompCheckBox->isChecked() ? QString(/*"true"*/) : QString("false")
862 settings.setValue("decoder/quad", ui->decoderQuadLineEdit->text());
863 settings.setValue("decoder/surround51", ui->decoder51LineEdit->text());
864 settings.setValue("decoder/surround51rear", ui->decoder51RearLineEdit->text());
865 settings.setValue("decoder/surround61", ui->decoder61LineEdit->text());
866 settings.setValue("decoder/surround71", ui->decoder71LineEdit->text());
868 QStringList strlist;
869 if(!ui->enableSSECheckBox->isChecked())
870 strlist.append("sse");
871 if(!ui->enableSSE2CheckBox->isChecked())
872 strlist.append("sse2");
873 if(!ui->enableSSE3CheckBox->isChecked())
874 strlist.append("sse3");
875 if(!ui->enableSSE41CheckBox->isChecked())
876 strlist.append("sse4.1");
877 if(!ui->enableNeonCheckBox->isChecked())
878 strlist.append("neon");
879 settings.setValue("disable-cpu-exts", strlist.join(QChar(',')));
881 if(ui->hrtfStateComboBox->currentIndex() == 1)
882 settings.setValue("hrtf", "true");
883 else if(ui->hrtfStateComboBox->currentIndex() == 2)
884 settings.setValue("hrtf", "false");
885 else
886 settings.setValue("hrtf", QString());
888 if(ui->preferredHrtfComboBox->currentIndex() == 0)
889 settings.setValue("default-hrtf", QString());
890 else
892 QString str = ui->preferredHrtfComboBox->currentText();
893 settings.setValue("default-hrtf", str);
896 strlist.clear();
897 for(int i = 0;i < ui->hrtfFileList->count();i++)
898 strlist.append(ui->hrtfFileList->item(i)->text());
899 if(!strlist.empty() && ui->defaultHrtfPathsCheckBox->isChecked())
900 strlist.append(QString());
901 settings.setValue("hrtf-paths", strlist.join(QChar(',')));
903 strlist.clear();
904 for(int i = 0;i < ui->enabledBackendList->count();i++)
906 QString label = ui->enabledBackendList->item(i)->text();
907 for(int j = 0;backendList[j].backend_name[0];j++)
909 if(label == backendList[j].full_string)
911 strlist.append(backendList[j].backend_name);
912 break;
916 for(int i = 0;i < ui->disabledBackendList->count();i++)
918 QString label = ui->disabledBackendList->item(i)->text();
919 for(int j = 0;backendList[j].backend_name[0];j++)
921 if(label == backendList[j].full_string)
923 strlist.append(QChar('-')+QString(backendList[j].backend_name));
924 break;
928 if(strlist.size() == 0 && !ui->backendCheckBox->isChecked())
929 strlist.append("-all");
930 else if(ui->backendCheckBox->isChecked())
931 strlist.append(QString());
932 settings.setValue("drivers", strlist.join(QChar(',')));
934 // TODO: Remove check when we can properly match global values.
935 if(ui->defaultReverbComboBox->currentIndex() == 0)
936 settings.setValue("default-reverb", QString());
937 else
939 QString str = ui->defaultReverbComboBox->currentText().toLower();
940 settings.setValue("default-reverb", str);
943 if(ui->emulateEaxCheckBox->isChecked())
944 settings.setValue("reverb/emulate-eax", "true");
945 else
946 settings.remove("reverb/emulate-eax"/*, "false"*/);
948 strlist.clear();
949 if(!ui->enableEaxReverbCheck->isChecked())
950 strlist.append("eaxreverb");
951 if(!ui->enableStdReverbCheck->isChecked())
952 strlist.append("reverb");
953 if(!ui->enableChorusCheck->isChecked())
954 strlist.append("chorus");
955 if(!ui->enableDistortionCheck->isChecked())
956 strlist.append("distortion");
957 if(!ui->enableCompressorCheck->isChecked())
958 strlist.append("compressor");
959 if(!ui->enableEchoCheck->isChecked())
960 strlist.append("echo");
961 if(!ui->enableEqualizerCheck->isChecked())
962 strlist.append("equalizer");
963 if(!ui->enableFlangerCheck->isChecked())
964 strlist.append("flanger");
965 if(!ui->enableModulatorCheck->isChecked())
966 strlist.append("modulator");
967 if(!ui->enableDedicatedCheck->isChecked())
968 strlist.append("dedicated");
969 settings.setValue("excludefx", strlist.join(QChar(',')));
971 settings.setValue("pulse/spawn-server",
972 ui->pulseAutospawnCheckBox->isChecked() ? QString(/*"true"*/) : QString("false")
974 settings.setValue("pulse/allow-moves",
975 ui->pulseAllowMovesCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
977 settings.setValue("pulse/fix-rate",
978 ui->pulseFixRateCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
981 settings.setValue("jack/spawn-server",
982 ui->jackAutospawnCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
984 settings.setValue("jack/buffer-size", ui->jackBufferSizeLine->text());
986 settings.setValue("alsa/device", ui->alsaDefaultDeviceLine->text());
987 settings.setValue("alsa/capture", ui->alsaDefaultCaptureLine->text());
988 settings.setValue("alsa/allow-resampler",
989 ui->alsaResamplerCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
991 settings.setValue("alsa/mmap",
992 ui->alsaMmapCheckBox->isChecked() ? QString(/*"true"*/) : QString("false")
995 settings.setValue("oss/device", ui->ossDefaultDeviceLine->text());
996 settings.setValue("oss/capture", ui->ossDefaultCaptureLine->text());
998 settings.setValue("solaris/device", ui->solarisDefaultDeviceLine->text());
1000 settings.setValue("wave/file", ui->waveOutputLine->text());
1001 settings.setValue("wave/bformat",
1002 ui->waveBFormatCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
1005 /* Remove empty keys
1006 * FIXME: Should only remove keys whose value matches the globally-specified value.
1008 allkeys = settings.allKeys();
1009 foreach(const QString &key, allkeys)
1011 QString str = settings.value(key).toString();
1012 if(str == QString())
1013 settings.remove(key);
1018 void MainWindow::enableApplyButton()
1020 if(!mNeedsSave)
1021 ui->applyButton->setEnabled(true);
1022 mNeedsSave = true;
1023 ui->closeCancelButton->setText(tr("Cancel"));
1027 void MainWindow::updateResamplerLabel(int num)
1029 ui->resamplerLabel->setText(resamplerList[num].name);
1030 enableApplyButton();
1034 void MainWindow::updatePeriodSizeEdit(int size)
1036 ui->periodSizeEdit->clear();
1037 if(size >= 64)
1039 size = (size+32)&~0x3f;
1040 ui->periodSizeEdit->insert(QString::number(size));
1042 enableApplyButton();
1045 void MainWindow::updatePeriodSizeSlider()
1047 int pos = ui->periodSizeEdit->text().toInt();
1048 if(pos >= 64)
1050 if(pos > 8192)
1051 pos = 8192;
1052 ui->periodSizeSlider->setSliderPosition(pos);
1054 enableApplyButton();
1057 void MainWindow::updatePeriodCountEdit(int count)
1059 ui->periodCountEdit->clear();
1060 if(count >= 2)
1061 ui->periodCountEdit->insert(QString::number(count));
1062 enableApplyButton();
1065 void MainWindow::updatePeriodCountSlider()
1067 int pos = ui->periodCountEdit->text().toInt();
1068 if(pos < 2)
1069 pos = 0;
1070 else if(pos > 16)
1071 pos = 16;
1072 ui->periodCountSlider->setSliderPosition(pos);
1073 enableApplyButton();
1077 void MainWindow::toggleHqState(int state)
1079 ui->decoderDistCompCheckBox->setEnabled(state);
1080 enableApplyButton();
1083 void MainWindow::selectQuadDecoderFile()
1084 { selectDecoderFile(ui->decoderQuadLineEdit, "Select Quadrophonic Decoder");}
1085 void MainWindow::select51DecoderFile()
1086 { selectDecoderFile(ui->decoder51LineEdit, "Select 5.1 Surround (Side) Decoder");}
1087 void MainWindow::select51RearDecoderFile()
1088 { selectDecoderFile(ui->decoder51RearLineEdit, "Select 5.1 Surround (Rear) Decoder");}
1089 void MainWindow::select61DecoderFile()
1090 { selectDecoderFile(ui->decoder61LineEdit, "Select 6.1 Surround Decoder");}
1091 void MainWindow::select71DecoderFile()
1092 { selectDecoderFile(ui->decoder71LineEdit, "Select 7.1 Surround Decoder");}
1093 void MainWindow::selectDecoderFile(QLineEdit *line, const char *caption)
1095 QString dir = line->text();
1096 if(dir.isEmpty() || QDir::isRelativePath(dir))
1098 QStringList paths = getAllDataPaths("/openal/presets");
1099 while(!paths.isEmpty())
1101 if(QDir(paths.last()).exists())
1103 dir = paths.last();
1104 break;
1106 paths.removeLast();
1109 QString fname = QFileDialog::getOpenFileName(this, tr(caption),
1110 dir, tr("AmbDec Files (*.ambdec);;All Files (*.*)")
1112 if(!fname.isEmpty())
1114 line->setText(fname);
1115 enableApplyButton();
1120 void MainWindow::updateJackBufferSizeEdit(int size)
1122 ui->jackBufferSizeLine->clear();
1123 if(size > 0)
1124 ui->jackBufferSizeLine->insert(QString::number(1<<size));
1125 enableApplyButton();
1128 void MainWindow::updateJackBufferSizeSlider()
1130 int value = ui->jackBufferSizeLine->text().toInt();
1131 int pos = (int)floor(log2(value) + 0.5);
1132 ui->jackBufferSizeSlider->setSliderPosition(pos);
1133 enableApplyButton();
1137 void MainWindow::addHrtfFile()
1139 QString path = QFileDialog::getExistingDirectory(this, tr("Select HRTF Path"));
1140 if(path.isEmpty() == false && !getAllDataPaths("/openal/hrtf").contains(path))
1142 ui->hrtfFileList->addItem(path);
1143 enableApplyButton();
1147 void MainWindow::removeHrtfFile()
1149 QList<QListWidgetItem*> selected = ui->hrtfFileList->selectedItems();
1150 if(!selected.isEmpty())
1152 foreach(QListWidgetItem *item, selected)
1153 delete item;
1154 enableApplyButton();
1158 void MainWindow::updateHrtfRemoveButton()
1160 ui->hrtfRemoveButton->setEnabled(ui->hrtfFileList->selectedItems().size() != 0);
1163 void MainWindow::showEnabledBackendMenu(QPoint pt)
1165 QMap<QAction*,QString> actionMap;
1167 pt = ui->enabledBackendList->mapToGlobal(pt);
1169 QMenu ctxmenu;
1170 QAction *removeAction = ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove");
1171 if(ui->enabledBackendList->selectedItems().size() == 0)
1172 removeAction->setEnabled(false);
1173 ctxmenu.addSeparator();
1174 for(size_t i = 0;backendList[i].backend_name[0];i++)
1176 QString backend = backendList[i].full_string;
1177 QAction *action = ctxmenu.addAction(QString("Add ")+backend);
1178 actionMap[action] = backend;
1179 if(ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0 ||
1180 ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0)
1181 action->setEnabled(false);
1184 QAction *gotAction = ctxmenu.exec(pt);
1185 if(gotAction == removeAction)
1187 QList<QListWidgetItem*> selected = ui->enabledBackendList->selectedItems();
1188 foreach(QListWidgetItem *item, selected)
1189 delete item;
1190 enableApplyButton();
1192 else if(gotAction != NULL)
1194 QMap<QAction*,QString>::const_iterator iter = actionMap.find(gotAction);
1195 if(iter != actionMap.end())
1196 ui->enabledBackendList->addItem(iter.value());
1197 enableApplyButton();
1201 void MainWindow::showDisabledBackendMenu(QPoint pt)
1203 QMap<QAction*,QString> actionMap;
1205 pt = ui->disabledBackendList->mapToGlobal(pt);
1207 QMenu ctxmenu;
1208 QAction *removeAction = ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove");
1209 if(ui->disabledBackendList->selectedItems().size() == 0)
1210 removeAction->setEnabled(false);
1211 ctxmenu.addSeparator();
1212 for(size_t i = 0;backendList[i].backend_name[0];i++)
1214 QString backend = backendList[i].full_string;
1215 QAction *action = ctxmenu.addAction(QString("Add ")+backend);
1216 actionMap[action] = backend;
1217 if(ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0 ||
1218 ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0)
1219 action->setEnabled(false);
1222 QAction *gotAction = ctxmenu.exec(pt);
1223 if(gotAction == removeAction)
1225 QList<QListWidgetItem*> selected = ui->disabledBackendList->selectedItems();
1226 foreach(QListWidgetItem *item, selected)
1227 delete item;
1228 enableApplyButton();
1230 else if(gotAction != NULL)
1232 QMap<QAction*,QString>::const_iterator iter = actionMap.find(gotAction);
1233 if(iter != actionMap.end())
1234 ui->disabledBackendList->addItem(iter.value());
1235 enableApplyButton();
1239 void MainWindow::selectOSSPlayback()
1241 QString current = ui->ossDefaultDeviceLine->text();
1242 if(current.isEmpty()) current = ui->ossDefaultDeviceLine->placeholderText();
1243 QString fname = QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current);
1244 if(!fname.isEmpty())
1246 ui->ossDefaultDeviceLine->setText(fname);
1247 enableApplyButton();
1251 void MainWindow::selectOSSCapture()
1253 QString current = ui->ossDefaultCaptureLine->text();
1254 if(current.isEmpty()) current = ui->ossDefaultCaptureLine->placeholderText();
1255 QString fname = QFileDialog::getOpenFileName(this, tr("Select Capture Device"), current);
1256 if(!fname.isEmpty())
1258 ui->ossDefaultCaptureLine->setText(fname);
1259 enableApplyButton();
1263 void MainWindow::selectSolarisPlayback()
1265 QString current = ui->solarisDefaultDeviceLine->text();
1266 if(current.isEmpty()) current = ui->solarisDefaultDeviceLine->placeholderText();
1267 QString fname = QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current);
1268 if(!fname.isEmpty())
1270 ui->solarisDefaultDeviceLine->setText(fname);
1271 enableApplyButton();
1275 void MainWindow::selectWaveOutput()
1277 QString fname = QFileDialog::getSaveFileName(this, tr("Select Wave File Output"),
1278 ui->waveOutputLine->text(), tr("Wave Files (*.wav *.amb);;All Files (*.*)")
1280 if(!fname.isEmpty())
1282 ui->waveOutputLine->setText(fname);
1283 enableApplyButton();