changeset 1397:558347e7e1ab bqresample

Audio device selection
author Chris Cannam
date Wed, 07 Dec 2016 11:53:19 +0000
parents bdf06d34730f
children 6f5a40419b00 21d6d75c2b51
files .hgsubstate main/PreferencesDialog.cpp main/PreferencesDialog.h
diffstat 3 files changed, 163 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/.hgsubstate	Tue Dec 06 16:07:22 2016 +0000
+++ b/.hgsubstate	Wed Dec 07 11:53:19 2016 +0000
@@ -1,13 +1,13 @@
-1f45516447f528170e7ecd704ab89c9d45405134 bqaudioio
+31c748f64308429553bbce7f18f1b6da3419ba1d bqaudioio
 f8f6b66b9875e6a9f153c1692b9f6cb241d51bf0 bqfft
 6b0cbfca8fb7cf64f89b0a0026b63bc212b156af bqresample
-08b6a1fcb5f063e7399b6fd941199b80ac98963a bqvec
+7ea6b5e4d20a016600bfc8c65fa87bdb05782322 bqvec
 1eefc20919cd080b684b2bbbc0af7270b8facb54 checker
 3768bdde6fdf866aa63fff5bde8d9fa64a8979ef dataquay
 c37b5598a4beb570417716e30aa649c78312169f icons/scalable
 3257ddb6fff110cc88f3ffeaeefa0f29d5eb3b6f piper-cpp
 5f67a29f0fc7f1b908f7cde4866173a7af337862 sv-dependency-builds
-4de547a5905ce355e046277713ca0f74c59839fc svapp
+ec189ad4d38ff73bdc60943cfffb49eb87df9cd8 svapp
 f830a10bfbd6ada2cb10398df47c8cec776904e5 svcore
 db90fee630bc756c3c64a6f904b551acb13e000f svgui
 0eebd22a081a824067bf3d5de65326696feab653 vamp-plugin-sdk
--- a/main/PreferencesDialog.cpp	Tue Dec 06 16:07:22 2016 +0000
+++ b/main/PreferencesDialog.cpp	Wed Dec 07 11:53:19 2016 +0000
@@ -42,13 +42,17 @@
 #include "base/ResourceFinder.h"
 #include "layer/ColourMapper.h"
 
-//#include "audioio/AudioTargetFactory.h"
+#include "bqaudioio/AudioFactory.h"
 
 #include "version.h"
 
+using namespace std;
+
 PreferencesDialog::PreferencesDialog(QWidget *parent) :
     QDialog(parent),
-    m_audioDevice(0),
+    m_audioImplementation(0),
+    m_audioPlaybackDevice(0),
+    m_audioRecordDevice(0),
     m_changesOnRestart(false)
 {
     setWindowTitle(tr("Sonic Visualiser: Application Preferences"));
@@ -184,24 +188,38 @@
     connect(octaveSystem, SIGNAL(currentIndexChanged(int)),
             this, SLOT(octaveSystemChanged(int)));
 
-    /*!!! restore
-    QComboBox *audioDevice = new QComboBox;
-    std::vector<QString> devices =
-        AudioTargetFactory::getInstance()->getCallbackTargetNames();
-    
     settings.beginGroup("Preferences");
-    QString targetName = settings.value("audio-target", "").toString();
+
+    QComboBox *audioImplementation = new QComboBox;
+    connect(audioImplementation, SIGNAL(currentIndexChanged(int)),
+            this, SLOT(audioImplementationChanged(int)));
+
+    m_audioPlaybackDeviceCombo = new QComboBox;
+    connect(m_audioPlaybackDeviceCombo, SIGNAL(currentIndexChanged(int)),
+            this, SLOT(audioPlaybackDeviceChanged(int)));
+
+    m_audioRecordDeviceCombo = new QComboBox;
+    connect(m_audioRecordDeviceCombo, SIGNAL(currentIndexChanged(int)),
+            this, SLOT(audioRecordDeviceChanged(int)));
+
+    vector<string> names = breakfastquay::AudioFactory::getImplementationNames();
+    QString implementationName = settings.value("audio-target", "").toString();
+    if (implementationName == "auto") implementationName = "";
+    audioImplementation->addItem(tr("(auto)"));
+    m_audioImplementation = 0;
+    for (int i = 0; in_range_for(names, i); ++i) {
+        audioImplementation->addItem
+            (breakfastquay::AudioFactory::getImplementationDescription(names[i]).
+             c_str());
+        if (implementationName.toStdString() == names[i]) {
+            audioImplementation->setCurrentIndex(i+1);
+            m_audioImplementation = i+1;
+        }
+    }
     settings.endGroup();
 
-    for (int i = 0; i < (int)devices.size(); ++i) {
-        audioDevice->addItem(AudioTargetFactory::getInstance()
-                             ->getCallbackTargetDescription(devices[i]));
-        if (targetName == devices[i]) audioDevice->setCurrentIndex(i);
-    }
-
-    connect(audioDevice, SIGNAL(currentIndexChanged(int)),
-            this, SLOT(audioDeviceChanged(int)));
-    */
+    rebuildDeviceCombos();
+    m_changesOnRestart = false; // the rebuild will have changed this
 
     QCheckBox *resampleOnLoad = new QCheckBox;
     m_resampleOnLoad = prefs->getResampleOnLoad();
@@ -369,8 +387,14 @@
                        row, 0);
     subgrid->addWidget(gaplessMode, row++, 1, 1, 1);
 
-//!!!    subgrid->addWidget(new QLabel(tr("Playback audio device:")), row, 0);
-//!!!    subgrid->addWidget(audioDevice, row++, 1, 1, 2);
+    subgrid->addWidget(new QLabel(tr("Audio service:")), row, 0);
+    subgrid->addWidget(audioImplementation, row++, 1, 1, 2);
+
+    subgrid->addWidget(new QLabel(tr("Audio playback device:")), row, 0);
+    subgrid->addWidget(m_audioPlaybackDeviceCombo, row++, 1, 1, 2);
+
+    subgrid->addWidget(new QLabel(tr("Audio record device:")), row, 0);
+    subgrid->addWidget(m_audioRecordDeviceCombo, row++, 1, 1, 2);
 
     subgrid->setRowStretch(row, 10);
     
@@ -510,7 +534,7 @@
 
     QStringList templates = ResourceFinder().getResourceFiles("templates", "svt");
 
-    std::set<QString> byName;
+    set<QString> byName;
     foreach (QString t, templates) {
         byName.insert(QFileInfo(t).baseName());
     }
@@ -550,6 +574,57 @@
 }
 
 void
+PreferencesDialog::rebuildDeviceCombos()
+{
+    QSettings settings;
+    settings.beginGroup("Preferences");
+
+    vector<string> names = breakfastquay::AudioFactory::getImplementationNames();
+    string implementationName;
+    if (in_range_for(names, m_audioImplementation-1)) {
+        implementationName = names[m_audioImplementation-1];
+    }
+
+    m_audioPlaybackDeviceCombo->clear();
+    m_audioRecordDeviceCombo->clear();
+
+    QString suffix;
+    if (implementationName != "") {
+        suffix = "-" + QString(implementationName.c_str());
+    }
+    
+    names = breakfastquay::AudioFactory::getPlaybackDeviceNames(implementationName);
+    QString playbackDeviceName = settings.value
+        ("audio-playback-device" + suffix, "").toString();
+    m_audioPlaybackDeviceCombo->addItem(tr("(auto)"));
+    m_audioPlaybackDeviceCombo->setCurrentIndex(0);
+    m_audioPlaybackDevice = 0;
+    for (int i = 0; in_range_for(names, i); ++i) {
+        m_audioPlaybackDeviceCombo->addItem(names[i].c_str());
+        if (playbackDeviceName.toStdString() == names[i]) {
+            m_audioPlaybackDeviceCombo->setCurrentIndex(i+1);
+            m_audioPlaybackDevice = i+1;
+        }
+    }
+    
+    names = breakfastquay::AudioFactory::getRecordDeviceNames(implementationName);
+    QString recordDeviceName = settings.value
+        ("audio-record-device" + suffix, "").toString();
+    m_audioRecordDeviceCombo->addItem(tr("(auto)"));
+    m_audioRecordDeviceCombo->setCurrentIndex(0);
+    m_audioRecordDevice = 0;
+    for (int i = 0; in_range_for(names, i); ++i) {
+        m_audioRecordDeviceCombo->addItem(names[i].c_str());
+        if (recordDeviceName.toStdString() == names[i]) {
+            m_audioRecordDeviceCombo->setCurrentIndex(i+1);
+            m_audioRecordDevice = i+1;
+        }
+    }
+
+    settings.endGroup();
+}
+
+void
 PreferencesDialog::switchToTab(Tab t)
 {
     if (m_tabOrdering.contains(t)) {
@@ -614,11 +689,34 @@
 }
 
 void
-PreferencesDialog::audioDeviceChanged(int s)
+PreferencesDialog::audioImplementationChanged(int s)
 {
-    m_audioDevice = s;
-    m_applyButton->setEnabled(true);
-    m_changesOnRestart = true;
+    if (m_audioImplementation != s) {
+        m_audioImplementation = s;
+        rebuildDeviceCombos();
+        m_applyButton->setEnabled(true);
+        m_changesOnRestart = true;
+    }
+}
+
+void
+PreferencesDialog::audioPlaybackDeviceChanged(int s)
+{
+    if (m_audioPlaybackDevice != s) {
+        m_audioPlaybackDevice = s;
+        m_applyButton->setEnabled(true);
+        m_changesOnRestart = true;
+    }
+}
+
+void
+PreferencesDialog::audioRecordDeviceChanged(int s)
+{
+    if (m_audioRecordDevice != s) {
+        m_audioRecordDevice = s;
+        m_applyButton->setEnabled(true);
+        m_changesOnRestart = true;
+    }
 }
 
 void
@@ -769,14 +867,37 @@
     
     prefs->setProperty("Octave Numbering System", m_octaveSystem);
 
-//!!!    std::vector<QString> devices =
-//!!!        AudioTargetFactory::getInstance()->getCallbackTargetNames();
-
     QSettings settings;
     settings.beginGroup("Preferences");
     QString permishTag = QString("network-permission-%1").arg(SV_VERSION);
     settings.setValue(permishTag, m_networkPermission);
-//!!!    settings.setValue("audio-target", devices[m_audioDevice]);
+
+    vector<string> names = breakfastquay::AudioFactory::getImplementationNames();
+    string implementationName;
+    if (m_audioImplementation > 0) {
+        implementationName = names[m_audioImplementation-1];
+    }
+    settings.setValue("audio-target", implementationName.c_str());
+
+    QString suffix;
+    if (implementationName != "") {
+        suffix = "-" + QString(implementationName.c_str());
+    }
+    
+    names = breakfastquay::AudioFactory::getPlaybackDeviceNames(implementationName);
+    string deviceName;
+    if (m_audioPlaybackDevice > 0) {
+        deviceName = names[m_audioPlaybackDevice-1];
+    }
+    settings.setValue("audio-playback-device" + suffix, deviceName.c_str());
+
+    names = breakfastquay::AudioFactory::getRecordDeviceNames(implementationName);
+    deviceName = "";
+    if (m_audioRecordDevice > 0) {
+        deviceName = names[m_audioRecordDevice-1];
+    }
+    settings.setValue("audio-record-device" + suffix, deviceName.c_str());
+    
     settings.setValue("locale", m_currentLocale);
 #ifdef Q_OS_MAC
     settings.setValue("scaledHiDpi", m_retina);
--- a/main/PreferencesDialog.h	Tue Dec 06 16:07:22 2016 +0000
+++ b/main/PreferencesDialog.h	Wed Dec 07 11:53:19 2016 +0000
@@ -25,6 +25,7 @@
 class QPushButton;
 class QLineEdit;
 class QTabWidget;
+class QComboBox;
 
 class PreferencesDialog : public QDialog
 {
@@ -54,7 +55,9 @@
     void colour3DColourChanged(int state);
     void propertyLayoutChanged(int layout);
     void tuningFrequencyChanged(double freq);
-    void audioDeviceChanged(int device);
+    void audioImplementationChanged(int impl);
+    void audioPlaybackDeviceChanged(int device);
+    void audioRecordDeviceChanged(int device);
     void resampleOnLoadChanged(int state);
     void gaplessModeChanged(int state);
     void vampProcessSeparationChanged(int state);
@@ -85,6 +88,10 @@
 
     QLineEdit *m_tempDirRootEdit;
 
+    QComboBox *m_audioPlaybackDeviceCombo;
+    QComboBox *m_audioRecordDeviceCombo;
+    void rebuildDeviceCombos();
+    
     QString m_currentTemplate;
     QStringList m_templates;
 
@@ -99,7 +106,9 @@
     int m_colour3DColour;
     int m_propertyLayout;
     double m_tuningFrequency;
-    int m_audioDevice;
+    int m_audioImplementation;
+    int m_audioPlaybackDevice;
+    int m_audioRecordDevice;
     bool m_resampleOnLoad;
     bool m_gapless;
     bool m_runPluginsInProcess;