diff main/PreferencesDialog.cpp @ 263:9d47adc3e32d

* Add audio device selection to preferences * Add (not yet functional) insert, delete, edit buttons to data edit window * Add proper set methods for time fields in data edit window (using general sparse model base class)
author Chris Cannam
date Fri, 13 Jun 2008 21:09:43 +0000
parents 92cad26f44a1
children 15ce557e1bf8
line wrap: on
line diff
--- a/main/PreferencesDialog.cpp	Thu Jun 12 10:47:11 2008 +0000
+++ b/main/PreferencesDialog.cpp	Fri Jun 13 21:09:43 2008 +0000
@@ -31,13 +31,16 @@
 #include <QFileDialog>
 #include <QMessageBox>
 #include <QSpinBox>
+#include <QSettings>
 
 #include "widgets/WindowTypeSelector.h"
 #include "widgets/IconLoader.h"
 #include "base/Preferences.h"
+#include "audioio/AudioTargetFactory.h"
 
 PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WFlags flags) :
     QDialog(parent, flags),
+    m_audioDevice(0),
     m_changesOnRestart(false)
 {
     setWindowTitle(tr("Sonic Visualiser: Application Preferences"));
@@ -111,6 +114,24 @@
     connect(frequency, SIGNAL(valueChanged(double)),
             this, SLOT(tuningFrequencyChanged(double)));
 
+    QComboBox *audioDevice = new QComboBox;
+    std::vector<QString> devices =
+        AudioTargetFactory::getInstance()->getCallbackTargetNames();
+    
+    QSettings settings;
+    settings.beginGroup("Preferences");
+    QString targetName = settings.value("audio-target", "").toString();
+    settings.endGroup();
+
+    for (int i = 0; i < 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)));
+
     QComboBox *resampleQuality = new QComboBox;
 
     int rsq = prefs->getPropertyRangeAndValue("Resample Quality", &min, &max,
@@ -188,6 +209,37 @@
     int row = 0;
 
     subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
+                                                ("Temporary Directory Root"))),
+                       row, 0);
+    subgrid->addWidget(m_tempDirRootEdit, row, 1, 1, 1);
+    subgrid->addWidget(tempDirButton, row, 2, 1, 1);
+    row++;
+
+    subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
+                                                ("Resample On Load"))),
+                       row, 0);
+    subgrid->addWidget(resampleOnLoad, 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("%1:").arg(prefs->getPropertyLabel
+                                                ("Resample Quality"))),
+                       row, 0);
+    subgrid->addWidget(resampleQuality, row++, 1, 1, 2);
+
+    subgrid->setRowStretch(row, 10);
+    
+    tab->addTab(frame, tr("&General"));
+
+    // Appearance tab
+
+    frame = new QFrame;
+    subgrid = new QGridLayout;
+    frame->setLayout(subgrid);
+    row = 0;
+
+    subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
                                                 ("Property Box Layout"))),
                        row, 0);
     subgrid->addWidget(propertyLayout, row++, 1, 1, 2);
@@ -209,26 +261,9 @@
                        row, 0);
     subgrid->addWidget(showSplash, row++, 1, 1, 1);
 
-    subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
-                                                ("Temporary Directory Root"))),
-                       row, 0);
-    subgrid->addWidget(m_tempDirRootEdit, row, 1, 1, 1);
-    subgrid->addWidget(tempDirButton, row, 2, 1, 1);
-    row++;
-
-    subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
-                                                ("Resample On Load"))),
-                       row, 0);
-    subgrid->addWidget(resampleOnLoad, row++, 1, 1, 1);
-
-    subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
-                                                ("Resample Quality"))),
-                       row, 0);
-    subgrid->addWidget(resampleQuality, row++, 1, 1, 2);
-
     subgrid->setRowStretch(row, 10);
     
-    tab->addTab(frame, tr("&General"));
+    tab->addTab(frame, tr("&Appearance"));
 
     // Analysis tab
 
@@ -256,7 +291,7 @@
     
     subgrid->setRowStretch(row, 10);
     
-    tab->addTab(frame, tr("&Analysis"));
+    tab->addTab(frame, tr("Anal&ysis"));
 
     QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal);
     grid->addWidget(bb, 1, 0);
@@ -307,6 +342,14 @@
 }
 
 void
+PreferencesDialog::audioDeviceChanged(int s)
+{
+    m_audioDevice = s;
+    m_applyButton->setEnabled(true);
+    m_changesOnRestart = true;
+}
+
+void
 PreferencesDialog::resampleQualityChanged(int q)
 {
     m_resampleQuality = q;
@@ -386,6 +429,14 @@
     prefs->setTemporaryDirectoryRoot(m_tempDirRoot);
     prefs->setBackgroundMode(Preferences::BackgroundMode(m_backgroundMode));
     prefs->setViewFontSize(m_viewFontSize);
+    
+    std::vector<QString> devices =
+        AudioTargetFactory::getInstance()->getCallbackTargetNames();
+
+    QSettings settings;
+    settings.beginGroup("Preferences");
+    settings.setValue("audio-target", devices[m_audioDevice]);
+    settings.endGroup();
 
     m_applyButton->setEnabled(false);