Use shorter display names for the surround sound config options
[openal-soft.git] / utils / alsoft-config / mainwindow.cpp
blob13fdfe3f13a0fde80a8e9276af6c78e0981c983b
1 #include <QFileDialog>
2 #include <QMessageBox>
3 #include <QSettings>
4 #include <QtGlobal>
5 #include "mainwindow.h"
6 #include "ui_mainwindow.h"
8 namespace {
9 static const struct {
10 char backend_name[16];
11 char menu_string[32];
12 } backendMenuList[] = {
13 #ifdef Q_OS_WIN32
14 { "mmdevapi", "Add MMDevAPI" },
15 { "dsound", "Add DirectSound" },
16 { "winmm", "Add Windows Multimedia" },
17 #endif
18 #ifdef Q_OS_MAC
19 { "core", "Add CoreAudio" },
20 #endif
21 { "pulse", "Add PulseAudio" },
22 #ifdef Q_OS_UNIX
23 { "alsa", "Add ALSA" },
24 { "oss", "Add OSS" },
25 { "solaris", "Add Solaris" },
26 { "sndio", "Add SndIO" },
27 { "qsa", "Add QSA" },
28 #endif
29 { "port", "Add PortAudio" },
30 { "opensl", "Add OpenSL" },
31 { "null", "Add Null Output" },
32 { "wave", "Add Wave Writer" },
33 { "", "" }
36 static const struct {
37 const char name[32];
38 const char value[16];
39 } speakerModeList[] = {
40 { "Autodetect", "" },
41 { "Mono", "mono" },
42 { "Stereo", "stereo" },
43 { "Quadrophonic", "quad" },
44 { "5.1 Surround", "surround51" },
45 { "6.1 Surround", "surround61" },
46 { "7.1 Surround", "surround71" },
48 { "", "" }
49 }, sampleTypeList[] = {
50 { "Autodetect", "" },
51 { "8-bit int", "int8" },
52 { "8-bit uint", "uint8" },
53 { "16-bit int", "int16" },
54 { "16-bit uint", "uint16" },
55 { "32-bit int", "int32" },
56 { "32-bit uint", "uint32" },
57 { "32-bit float", "float32" },
59 { "", "" }
60 }, resamplerList[] = {
61 { "Default", "" },
62 { "Point (low quality, fast)", "point" },
63 { "Linear (basic quality, fast)", "linear" },
64 { "Cubic Spline (good quality)", "cubic" },
66 { "", "" }
69 static QString getDefaultConfigName()
71 #ifdef Q_OS_WIN32
72 static const char fname[] = "alsoft.ini";
73 QByteArray base = qgetenv("AppData");
74 #else
75 static const char fname[] = "alsoft.conf";
76 QByteArray base = qgetenv("XDG_CONFIG_HOME");
77 if(base.isEmpty())
79 base = qgetenv("HOME");
80 if(base.isEmpty() == false)
81 base += "/.config";
83 #endif
84 if(base.isEmpty() == false)
85 return base +'/'+ fname;
86 return fname;
89 static QString getBaseDataPath()
91 #ifdef Q_OS_WIN32
92 QByteArray base = qgetenv("AppData");
93 #else
94 QByteArray base = qgetenv("XDG_DATA_HOME");
95 if(base.isEmpty())
97 base = qgetenv("HOME");
98 if(!base.isEmpty())
99 base += "/.local/share";
101 #endif
102 return base;
105 static QStringList getAllDataPaths(QString append=QString())
107 QStringList list;
108 list.append(getBaseDataPath());
109 #ifdef Q_OS_WIN32
110 // TODO: Common AppData path
111 #else
112 QString paths = qgetenv("XDG_DATA_DIRS");
113 if(paths.isEmpty())
114 paths = "/usr/local/share/:/usr/share/";
115 list += paths.split(QChar(':'), QString::SkipEmptyParts);
116 #endif
117 QStringList::iterator iter = list.begin();
118 while(iter != list.end())
120 if(iter->isEmpty())
121 iter = list.erase(iter);
122 else
124 iter->append(append);
125 iter++;
128 return list;
132 MainWindow::MainWindow(QWidget *parent) :
133 QMainWindow(parent),
134 ui(new Ui::MainWindow),
135 mPeriodSizeValidator(NULL),
136 mPeriodCountValidator(NULL),
137 mSourceCountValidator(NULL),
138 mEffectSlotValidator(NULL),
139 mSourceSendValidator(NULL),
140 mSampleRateValidator(NULL),
141 mReverbBoostValidator(NULL)
143 ui->setupUi(this);
145 for(int i = 0;speakerModeList[i].name[0];i++)
146 ui->channelConfigCombo->addItem(speakerModeList[i].name);
147 ui->channelConfigCombo->adjustSize();
148 for(int i = 0;sampleTypeList[i].name[0];i++)
149 ui->sampleFormatCombo->addItem(sampleTypeList[i].name);
150 ui->sampleFormatCombo->adjustSize();
151 for(int i = 0;resamplerList[i].name[0];i++)
152 ui->resamplerComboBox->addItem(resamplerList[i].name);
153 ui->resamplerComboBox->adjustSize();
155 mPeriodSizeValidator = new QIntValidator(64, 8192, this);
156 ui->periodSizeEdit->setValidator(mPeriodSizeValidator);
157 mPeriodCountValidator = new QIntValidator(2, 16, this);
158 ui->periodCountEdit->setValidator(mPeriodCountValidator);
160 mSourceCountValidator = new QIntValidator(0, 256, this);
161 ui->srcCountLineEdit->setValidator(mSourceCountValidator);
162 mEffectSlotValidator = new QIntValidator(0, 16, this);
163 ui->effectSlotLineEdit->setValidator(mEffectSlotValidator);
164 mSourceSendValidator = new QIntValidator(0, 4, this);
165 ui->srcSendLineEdit->setValidator(mSourceSendValidator);
166 mSampleRateValidator = new QIntValidator(8000, 192000, this);
167 ui->sampleRateCombo->lineEdit()->setValidator(mSampleRateValidator);
169 mReverbBoostValidator = new QDoubleValidator(-12.0, +12.0, 1, this);
170 ui->reverbBoostEdit->setValidator(mReverbBoostValidator);
172 connect(ui->actionLoad, SIGNAL(triggered()), this, SLOT(loadConfigFromFile()));
173 connect(ui->actionSave_As, SIGNAL(triggered()), this, SLOT(saveConfigAsFile()));
175 connect(ui->applyButton, SIGNAL(clicked()), this, SLOT(saveCurrentConfig()));
177 connect(ui->periodSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(updatePeriodSizeEdit(int)));
178 connect(ui->periodSizeEdit, SIGNAL(editingFinished()), this, SLOT(updatePeriodSizeSlider()));
179 connect(ui->periodCountSlider, SIGNAL(valueChanged(int)), this, SLOT(updatePeriodCountEdit(int)));
180 connect(ui->periodCountEdit, SIGNAL(editingFinished()), this, SLOT(updatePeriodCountSlider()));
182 connect(ui->hrtfAddButton, SIGNAL(clicked()), this, SLOT(addHrtfFile()));
183 connect(ui->hrtfRemoveButton, SIGNAL(clicked()), this, SLOT(removeHrtfFile()));
184 connect(ui->hrtfFileList, SIGNAL(itemSelectionChanged()), this, SLOT(updateHrtfRemoveButton()));
186 ui->enabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
187 connect(ui->enabledBackendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showEnabledBackendMenu(QPoint)));
189 ui->disabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
190 connect(ui->disabledBackendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showDisabledBackendMenu(QPoint)));
192 connect(ui->reverbBoostSlider, SIGNAL(valueChanged(int)), this, SLOT(updateReverbBoostEdit(int)));
193 connect(ui->reverbBoostEdit, SIGNAL(textEdited(QString)), this, SLOT(updateReverbBoostSlider(QString)));
195 loadConfig(getDefaultConfigName());
198 MainWindow::~MainWindow()
200 delete ui;
201 delete mPeriodSizeValidator;
202 delete mPeriodCountValidator;
203 delete mSourceCountValidator;
204 delete mEffectSlotValidator;
205 delete mSourceSendValidator;
206 delete mSampleRateValidator;
207 delete mReverbBoostValidator;
210 void MainWindow::loadConfigFromFile()
212 QString fname = QFileDialog::getOpenFileName(this, tr("Select Files"));
213 if(fname.isEmpty() == false)
214 loadConfig(fname);
217 void MainWindow::loadConfig(const QString &fname)
219 QSettings settings(fname, QSettings::IniFormat);
221 QString sampletype = settings.value("sample-type").toString();
222 ui->sampleFormatCombo->setCurrentIndex(0);
223 if(sampletype.isEmpty() == false)
225 for(int i = 0;sampleTypeList[i].name[i];i++)
227 if(sampletype == sampleTypeList[i].value)
229 for(int j = 1;j < ui->sampleFormatCombo->count();j++)
231 QString item = ui->sampleFormatCombo->itemText(j);
232 if(item == sampleTypeList[i].name)
234 ui->sampleFormatCombo->setCurrentIndex(j);
235 break;
238 break;
243 QString channelconfig = settings.value("channels").toString();
244 ui->channelConfigCombo->setCurrentIndex(0);
245 if(channelconfig.isEmpty() == false)
247 for(int i = 0;speakerModeList[i].name[i];i++)
249 if(channelconfig == speakerModeList[i].value)
251 for(int j = 1;j < ui->channelConfigCombo->count();j++)
253 QString item = ui->channelConfigCombo->itemText(j);
254 if(item == speakerModeList[i].name)
256 ui->channelConfigCombo->setCurrentIndex(j);
257 break;
260 break;
265 QString srate = settings.value("frequency").toString();
266 if(srate.isEmpty())
267 ui->sampleRateCombo->setCurrentIndex(0);
268 else
270 ui->sampleRateCombo->lineEdit()->clear();
271 ui->sampleRateCombo->lineEdit()->insert(srate);
274 ui->srcCountLineEdit->clear();
275 ui->srcCountLineEdit->insert(settings.value("sources").toString());
276 ui->effectSlotLineEdit->clear();
277 ui->effectSlotLineEdit->insert(settings.value("slots").toString());
278 ui->srcSendLineEdit->clear();
279 ui->srcSendLineEdit->insert(settings.value("sends").toString());
281 QString resampler = settings.value("resampler").toString().trimmed();
282 ui->resamplerComboBox->setCurrentIndex(0);
283 if(resampler.isEmpty() == false)
285 for(int i = 0;resamplerList[i].name[i];i++)
287 if(resampler == resamplerList[i].value)
289 for(int j = 1;j < ui->resamplerComboBox->count();j++)
291 QString item = ui->resamplerComboBox->itemText(j);
292 if(item == resamplerList[i].name)
294 ui->resamplerComboBox->setCurrentIndex(j);
295 break;
298 break;
303 int periodsize = settings.value("period_size").toInt();
304 ui->periodSizeEdit->clear();
305 if(periodsize >= 64)
307 ui->periodSizeEdit->insert(QString::number(periodsize));
308 updatePeriodSizeSlider();
311 int periodcount = settings.value("periods").toInt();
312 ui->periodCountEdit->clear();
313 if(periodcount >= 2)
315 ui->periodCountEdit->insert(QString::number(periodcount));
316 updatePeriodCountSlider();
319 QStringList disabledCpuExts = settings.value("disable-cpu-exts").toStringList();
320 if(disabledCpuExts.size() == 1)
321 disabledCpuExts = disabledCpuExts[0].split(QChar(','));
322 std::transform(disabledCpuExts.begin(), disabledCpuExts.end(),
323 disabledCpuExts.begin(), std::mem_fun_ref(&QString::trimmed));
324 ui->enableSSECheckBox->setChecked(!disabledCpuExts.contains("sse", Qt::CaseInsensitive));
325 ui->enableSSE2CheckBox->setChecked(!disabledCpuExts.contains("sse2", Qt::CaseInsensitive));
326 ui->enableSSE41CheckBox->setChecked(!disabledCpuExts.contains("sse4.1", Qt::CaseInsensitive));
327 ui->enableNeonCheckBox->setChecked(!disabledCpuExts.contains("neon", Qt::CaseInsensitive));
329 if(settings.value("hrtf").toString() == QString())
330 ui->hrtfEnableButton->setChecked(true);
331 else
333 if(settings.value("hrtf", true).toBool())
334 ui->hrtfForceButton->setChecked(true);
335 else
336 ui->hrtfDisableButton->setChecked(true);
339 QStringList hrtf_tables = settings.value("hrtf_tables").toStringList();
340 if(hrtf_tables.size() == 1)
341 hrtf_tables = hrtf_tables[0].split(QChar(','));
342 std::transform(hrtf_tables.begin(), hrtf_tables.end(),
343 hrtf_tables.begin(), std::mem_fun_ref(&QString::trimmed));
344 ui->hrtfFileList->clear();
345 ui->hrtfFileList->addItems(hrtf_tables);
346 updateHrtfRemoveButton();
348 ui->enabledBackendList->clear();
349 ui->disabledBackendList->clear();
350 QStringList drivers = settings.value("drivers").toStringList();
351 if(drivers.size() == 0)
352 ui->backendCheckBox->setChecked(true);
353 else
355 if(drivers.size() == 1)
356 drivers = drivers[0].split(QChar(','));
357 std::transform(drivers.begin(), drivers.end(),
358 drivers.begin(), std::mem_fun_ref(&QString::trimmed));
360 bool lastWasEmpty = false;
361 foreach(const QString &backend, drivers)
363 lastWasEmpty = backend.isEmpty();
364 if(!backend.startsWith(QChar('-')) && !lastWasEmpty)
365 ui->enabledBackendList->addItem(backend);
366 else if(backend.size() > 1)
367 ui->disabledBackendList->addItem(backend.right(backend.size()-1));
369 ui->backendCheckBox->setChecked(lastWasEmpty);
372 QString defaultreverb = settings.value("default-reverb").toString().toLower();
373 ui->defaultReverbComboBox->setCurrentIndex(0);
374 if(defaultreverb.isEmpty() == false)
376 for(int i = 0;i < ui->defaultReverbComboBox->count();i++)
378 if(defaultreverb.compare(ui->defaultReverbComboBox->itemText(i).toLower()) == 0)
380 ui->defaultReverbComboBox->setCurrentIndex(i);
381 break;
386 ui->emulateEaxCheckBox->setChecked(settings.value("reverb/emulate-eax", false).toBool());
387 ui->reverbBoostEdit->clear();
388 ui->reverbBoostEdit->insert(settings.value("reverb/boost").toString());
390 QStringList excludefx = settings.value("excludefx").toStringList();
391 if(excludefx.size() == 1)
392 excludefx = excludefx[0].split(QChar(','));
393 std::transform(excludefx.begin(), excludefx.end(),
394 excludefx.begin(), std::mem_fun_ref(&QString::trimmed));
395 ui->enableEaxReverbCheck->setChecked(!excludefx.contains("eaxreverb", Qt::CaseInsensitive));
396 ui->enableStdReverbCheck->setChecked(!excludefx.contains("reverb", Qt::CaseInsensitive));
397 ui->enableChorusCheck->setChecked(!excludefx.contains("chorus", Qt::CaseInsensitive));
398 ui->enableCompressorCheck->setChecked(!excludefx.contains("compressor", Qt::CaseInsensitive));
399 ui->enableDistortionCheck->setChecked(!excludefx.contains("distortion", Qt::CaseInsensitive));
400 ui->enableEchoCheck->setChecked(!excludefx.contains("echo", Qt::CaseInsensitive));
401 ui->enableEqualizerCheck->setChecked(!excludefx.contains("equalizer", Qt::CaseInsensitive));
402 ui->enableFlangerCheck->setChecked(!excludefx.contains("flanger", Qt::CaseInsensitive));
403 ui->enableModulatorCheck->setChecked(!excludefx.contains("modulator", Qt::CaseInsensitive));
404 ui->enableDedicatedCheck->setChecked(!excludefx.contains("dedicated", Qt::CaseInsensitive));
407 void MainWindow::saveCurrentConfig()
409 saveConfig(getDefaultConfigName());
410 QMessageBox::information(this, tr("Information"),
411 tr("Applications using OpenAL need to be restarted for changes to take effect."));
414 void MainWindow::saveConfigAsFile()
416 QString fname = QFileDialog::getOpenFileName(this, tr("Select Files"));
417 if(fname.isEmpty() == false)
418 saveConfig(fname);
421 void MainWindow::saveConfig(const QString &fname) const
423 QSettings settings(fname, QSettings::IniFormat);
425 /* HACK: Compound any stringlist values into a comma-separated string. */
426 QStringList allkeys = settings.allKeys();
427 foreach(const QString &key, allkeys)
429 QStringList vals = settings.value(key).toStringList();
430 if(vals.size() > 1)
431 settings.setValue(key, vals.join(QChar(',')));
434 QString str = ui->sampleFormatCombo->currentText();
435 for(int i = 0;sampleTypeList[i].name[0];i++)
437 if(str == sampleTypeList[i].name)
439 settings.setValue("sample-type", sampleTypeList[i].value);
440 break;
444 str = ui->channelConfigCombo->currentText();
445 for(int i = 0;speakerModeList[i].name[0];i++)
447 if(str == speakerModeList[i].name)
449 settings.setValue("channels", speakerModeList[i].value);
450 break;
454 uint rate = ui->sampleRateCombo->currentText().toUInt();
455 if(!(rate > 0))
456 settings.setValue("frequency", QString());
457 else
458 settings.setValue("frequency", rate);
460 settings.setValue("period_size", ui->periodSizeEdit->text());
461 settings.setValue("periods", ui->periodCountEdit->text());
463 settings.setValue("sources", ui->srcCountLineEdit->text());
464 settings.setValue("slots", ui->effectSlotLineEdit->text());
466 str = ui->resamplerComboBox->currentText();
467 for(int i = 0;resamplerList[i].name[0];i++)
469 if(str == resamplerList[i].name)
471 settings.setValue("resampler", resamplerList[i].value);
472 break;
476 QStringList strlist;
477 if(!ui->enableSSECheckBox->isChecked())
478 strlist.append("sse");
479 if(!ui->enableSSE2CheckBox->isChecked())
480 strlist.append("sse2");
481 if(!ui->enableSSE41CheckBox->isChecked())
482 strlist.append("sse4.1");
483 if(!ui->enableNeonCheckBox->isChecked())
484 strlist.append("neon");
485 settings.setValue("disable-cpu-exts", strlist.join(QChar(',')));
487 if(ui->hrtfForceButton->isChecked())
488 settings.setValue("hrtf", "true");
489 else if(ui->hrtfDisableButton->isChecked())
490 settings.setValue("hrtf", "false");
491 else
492 settings.setValue("hrtf", QString());
494 strlist.clear();
495 QList<QListWidgetItem*> items = ui->hrtfFileList->findItems("*", Qt::MatchWildcard);
496 foreach(const QListWidgetItem *item, items)
497 strlist.append(item->text());
498 settings.setValue("hrtf_tables", strlist.join(QChar(',')));
500 strlist.clear();
501 items = ui->enabledBackendList->findItems("*", Qt::MatchWildcard);
502 foreach(const QListWidgetItem *item, items)
503 strlist.append(item->text());
504 items = ui->disabledBackendList->findItems("*", Qt::MatchWildcard);
505 foreach(const QListWidgetItem *item, items)
506 strlist.append(QChar('-')+item->text());
507 if(strlist.size() == 0 && !ui->backendCheckBox->isChecked())
508 strlist.append("-all");
509 else if(ui->backendCheckBox->isChecked())
510 strlist.append(QString());
511 settings.setValue("drivers", strlist.join(QChar(',')));
513 // TODO: Remove check when we can properly match global values.
514 if(ui->defaultReverbComboBox->currentIndex() == 0)
515 settings.setValue("default-reverb", QString());
516 else
518 str = ui->defaultReverbComboBox->currentText().toLower();
519 settings.setValue("default-reverb", str);
522 if(ui->emulateEaxCheckBox->isChecked())
523 settings.setValue("reverb/emulate-eax", "true");
524 else
525 settings.setValue("reverb/emulate-eax", QString()/*"false"*/);
527 // TODO: Remove check when we can properly match global values.
528 if(ui->reverbBoostSlider->sliderPosition() == 0)
529 settings.setValue("reverb/boost", QString());
530 else
531 settings.setValue("reverb/boost", ui->reverbBoostEdit->text());
533 strlist.clear();
534 if(!ui->enableEaxReverbCheck->isChecked())
535 strlist.append("eaxreverb");
536 if(!ui->enableStdReverbCheck->isChecked())
537 strlist.append("reverb");
538 if(!ui->enableChorusCheck->isChecked())
539 strlist.append("chorus");
540 if(!ui->enableDistortionCheck->isChecked())
541 strlist.append("distortion");
542 if(!ui->enableCompressorCheck->isChecked())
543 strlist.append("compressor");
544 if(!ui->enableEchoCheck->isChecked())
545 strlist.append("echo");
546 if(!ui->enableEqualizerCheck->isChecked())
547 strlist.append("equalizer");
548 if(!ui->enableFlangerCheck->isChecked())
549 strlist.append("flanger");
550 if(!ui->enableModulatorCheck->isChecked())
551 strlist.append("modulator");
552 if(!ui->enableDedicatedCheck->isChecked())
553 strlist.append("dedicated");
554 settings.setValue("excludefx", strlist.join(QChar(',')));
556 /* Remove empty keys
557 * FIXME: Should only remove keys whose value matches the globally-specified value.
559 allkeys = settings.allKeys();
560 foreach(const QString &key, allkeys)
562 str = settings.value(key).toString();
563 if(str == QString())
564 settings.remove(key);
569 void MainWindow::updatePeriodSizeEdit(int size)
571 ui->periodSizeEdit->clear();
572 if(size >= 64)
574 size = (size+32)&~0x3f;
575 ui->periodSizeEdit->insert(QString::number(size));
579 void MainWindow::updatePeriodSizeSlider()
581 int pos = ui->periodSizeEdit->text().toInt();
582 if(pos >= 64)
584 if(pos > 8192)
585 pos = 8192;
586 ui->periodSizeSlider->setSliderPosition(pos);
590 void MainWindow::updatePeriodCountEdit(int count)
592 ui->periodCountEdit->clear();
593 if(count >= 2)
594 ui->periodCountEdit->insert(QString::number(count));
597 void MainWindow::updatePeriodCountSlider()
599 int pos = ui->periodCountEdit->text().toInt();
600 if(pos < 2)
601 pos = 0;
602 else if(pos > 16)
603 pos = 16;
604 ui->periodCountSlider->setSliderPosition(pos);
608 void MainWindow::addHrtfFile()
610 const QStringList datapaths = getAllDataPaths("/openal/hrtf");
611 QStringList fnames = QFileDialog::getOpenFileNames(this, tr("Select Files"),
612 datapaths.empty() ? QString() : datapaths[0],
613 "HRTF Datasets(*.mhr);;All Files(*.*)");
614 if(fnames.isEmpty() == false)
616 for(QStringList::iterator iter = fnames.begin();iter != fnames.end();iter++)
618 QStringList::const_iterator path = datapaths.constBegin();
619 for(;path != datapaths.constEnd();path++)
621 QDir hrtfdir(*path);
622 if(!hrtfdir.isAbsolute())
623 continue;
625 const QString relname = hrtfdir.relativeFilePath(*iter);
626 if(!relname.startsWith(".."))
628 // If filename is within this path, use the relative pathname
629 ui->hrtfFileList->addItem(relname);
630 break;
633 if(path == datapaths.constEnd())
635 // Filename is not within any data path, use the absolute pathname
636 ui->hrtfFileList->addItem(*iter);
642 void MainWindow::removeHrtfFile()
644 QList<QListWidgetItem*> selected = ui->hrtfFileList->selectedItems();
645 foreach(QListWidgetItem *item, selected)
646 delete item;
649 void MainWindow::updateHrtfRemoveButton()
651 ui->hrtfRemoveButton->setEnabled(ui->hrtfFileList->selectedItems().size() != 0);
654 void MainWindow::showEnabledBackendMenu(QPoint pt)
656 QMap<QAction*,QString> actionMap;
658 pt = ui->enabledBackendList->mapToGlobal(pt);
660 QMenu ctxmenu;
661 QAction *removeAction = ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove");
662 if(ui->enabledBackendList->selectedItems().size() == 0)
663 removeAction->setEnabled(false);
664 ctxmenu.addSeparator();
665 for(size_t i = 0;backendMenuList[i].backend_name[0];i++)
667 QAction *action = ctxmenu.addAction(backendMenuList[i].menu_string);
668 actionMap[action] = backendMenuList[i].backend_name;
669 if(ui->enabledBackendList->findItems(backendMenuList[i].backend_name, Qt::MatchFixedString).size() != 0 ||
670 ui->disabledBackendList->findItems(backendMenuList[i].backend_name, Qt::MatchFixedString).size() != 0)
671 action->setEnabled(false);
674 QAction *gotAction = ctxmenu.exec(pt);
675 if(gotAction == removeAction)
677 QList<QListWidgetItem*> selected = ui->enabledBackendList->selectedItems();
678 foreach(QListWidgetItem *item, selected)
679 delete item;
681 else if(gotAction != NULL)
683 QMap<QAction*,QString>::const_iterator iter = actionMap.find(gotAction);
684 if(iter != actionMap.end())
685 ui->enabledBackendList->addItem(iter.value());
689 void MainWindow::showDisabledBackendMenu(QPoint pt)
691 QMap<QAction*,QString> actionMap;
693 pt = ui->disabledBackendList->mapToGlobal(pt);
695 QMenu ctxmenu;
696 QAction *removeAction = ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove");
697 if(ui->disabledBackendList->selectedItems().size() == 0)
698 removeAction->setEnabled(false);
699 ctxmenu.addSeparator();
700 for(size_t i = 0;backendMenuList[i].backend_name[0];i++)
702 QAction *action = ctxmenu.addAction(backendMenuList[i].menu_string);
703 actionMap[action] = backendMenuList[i].backend_name;
704 if(ui->disabledBackendList->findItems(backendMenuList[i].backend_name, Qt::MatchFixedString).size() != 0 ||
705 ui->enabledBackendList->findItems(backendMenuList[i].backend_name, Qt::MatchFixedString).size() != 0)
706 action->setEnabled(false);
709 QAction *gotAction = ctxmenu.exec(pt);
710 if(gotAction == removeAction)
712 QList<QListWidgetItem*> selected = ui->disabledBackendList->selectedItems();
713 foreach(QListWidgetItem *item, selected)
714 delete item;
716 else if(gotAction != NULL)
718 QMap<QAction*,QString>::const_iterator iter = actionMap.find(gotAction);
719 if(iter != actionMap.end())
720 ui->disabledBackendList->addItem(iter.value());
724 void MainWindow::updateReverbBoostEdit(int value)
726 ui->reverbBoostEdit->clear();
727 if(value != 0)
728 ui->reverbBoostEdit->insert(QString::number(value/10.0, 'f', 1));
731 void MainWindow::updateReverbBoostSlider(QString value)
733 int pos = int(value.toFloat()*10.0f);
734 ui->reverbBoostSlider->setSliderPosition(pos);