From 3edbeefdb73b650d466b76583c8dac664d4d6ee0 Mon Sep 17 00:00:00 2001
From: Chris Robinson <chris.kcat@gmail.com>
Date: Thu, 4 Jul 2019 22:59:12 -0700
Subject: Add a setting for hrtf-mode to alsoft-config

---
 utils/alsoft-config/mainwindow.cpp | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

(limited to 'utils/alsoft-config/mainwindow.cpp')

diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp
index 4e2b2464..687f9134 100644
--- a/utils/alsoft-config/mainwindow.cpp
+++ b/utils/alsoft-config/mainwindow.cpp
@@ -123,6 +123,14 @@ static const struct NameValuePair {
     { "ACN, N3D", "acn+n3d" },
     { "Furse-Malham", "fuma" },
 
+    { "", "" }
+}, hrtfModeList[] = {
+    { "1st Order Ambisonic", "ambi1" },
+    { "2nd Order Ambisonic", "ambi2" },
+    { "3rd Order Ambisonic", "ambi3" },
+    { "Default (Full)", "" },
+    { "Full", "full" },
+
     { "", "" }
 };
 
@@ -267,6 +275,9 @@ MainWindow::MainWindow(QWidget *parent) :
     }
     ui->resamplerSlider->setRange(0, count-1);
 
+    for(count = 0;hrtfModeList[count].name[0];count++) {
+    }
+    ui->hrtfqualitySlider->setRange(0, count-1);
     ui->hrtfStateComboBox->adjustSize();
 
 #if !defined(HAVE_NEON) && !defined(HAVE_SSE)
@@ -367,6 +378,8 @@ MainWindow::MainWindow(QWidget *parent) :
 
     connect(ui->preferredHrtfComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
     connect(ui->hrtfStateComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
+    connect(ui->hrtfqualitySlider, SIGNAL(valueChanged(int)), this, SLOT(updateHrtfModeLabel(int)));
+
     connect(ui->hrtfAddButton, SIGNAL(clicked()), this, SLOT(addHrtfFile()));
     connect(ui->hrtfRemoveButton, SIGNAL(clicked()), this, SLOT(removeHrtfFile()));
     connect(ui->hrtfFileList, SIGNAL(itemSelectionChanged()), this, SLOT(updateHrtfRemoveButton()));
@@ -725,6 +738,21 @@ void MainWindow::loadConfig(const QString &fname)
     ui->enableSSE41CheckBox->setChecked(!disabledCpuExts.contains("sse4.1", Qt::CaseInsensitive));
     ui->enableNeonCheckBox->setChecked(!disabledCpuExts.contains("neon", Qt::CaseInsensitive));
 
+    QString hrtfmode = settings.value("hrtf-mode").toString().trimmed();
+    ui->hrtfqualitySlider->setValue(3);
+    ui->hrtfqualityLabel->setText(hrtfModeList[3].name);
+    /* The "basic" mode name is no longer supported. Use "ambi2" instead. */
+    if(hrtfmode == "basic") hrtfmode = "ambi2";
+    for(int i = 0;hrtfModeList[i].name[0];i++)
+    {
+        if(hrtfmode == hrtfModeList[i].value)
+        {
+            ui->hrtfqualitySlider->setValue(i);
+            ui->hrtfqualityLabel->setText(hrtfModeList[i].name);
+            break;
+        }
+    }
+
     QStringList hrtf_paths = settings.value("hrtf-paths").toStringList();
     if(hrtf_paths.size() == 1)
         hrtf_paths = hrtf_paths[0].split(QChar(','));
@@ -973,6 +1001,8 @@ void MainWindow::saveConfig(const QString &fname) const
         strlist.append("neon");
     settings.setValue("disable-cpu-exts", strlist.join(QChar(',')));
 
+    settings.setValue("hrtf-mode", hrtfModeList[ui->hrtfqualitySlider->value()].value);
+
     if(ui->hrtfStateComboBox->currentIndex() == 1)
         settings.setValue("hrtf", "true");
     else if(ui->hrtfStateComboBox->currentIndex() == 2)
@@ -1208,6 +1238,13 @@ void MainWindow::updateJackBufferSizeSlider()
 }
 
 
+void MainWindow::updateHrtfModeLabel(int num)
+{
+    ui->hrtfqualityLabel->setText(hrtfModeList[num].name);
+    enableApplyButton();
+}
+
+
 void MainWindow::addHrtfFile()
 {
     QString path = QFileDialog::getExistingDirectory(this, tr("Select HRTF Path"));
-- 
cgit v1.2.3