comparison main/PreferencesDialog.cpp @ 1397:558347e7e1ab bqresample

Audio device selection
author Chris Cannam
date Wed, 07 Dec 2016 11:53:19 +0000
parents 032bf0b11de9
children a89ca5ccb958
comparison
equal deleted inserted replaced
1396:bdf06d34730f 1397:558347e7e1ab
40 #include "widgets/IconLoader.h" 40 #include "widgets/IconLoader.h"
41 #include "base/Preferences.h" 41 #include "base/Preferences.h"
42 #include "base/ResourceFinder.h" 42 #include "base/ResourceFinder.h"
43 #include "layer/ColourMapper.h" 43 #include "layer/ColourMapper.h"
44 44
45 //#include "audioio/AudioTargetFactory.h" 45 #include "bqaudioio/AudioFactory.h"
46 46
47 #include "version.h" 47 #include "version.h"
48
49 using namespace std;
48 50
49 PreferencesDialog::PreferencesDialog(QWidget *parent) : 51 PreferencesDialog::PreferencesDialog(QWidget *parent) :
50 QDialog(parent), 52 QDialog(parent),
51 m_audioDevice(0), 53 m_audioImplementation(0),
54 m_audioPlaybackDevice(0),
55 m_audioRecordDevice(0),
52 m_changesOnRestart(false) 56 m_changesOnRestart(false)
53 { 57 {
54 setWindowTitle(tr("Sonic Visualiser: Application Preferences")); 58 setWindowTitle(tr("Sonic Visualiser: Application Preferences"));
55 59
56 Preferences *prefs = Preferences::getInstance(); 60 Preferences *prefs = Preferences::getInstance();
182 octaveSystem->setCurrentIndex(oct); 186 octaveSystem->setCurrentIndex(oct);
183 187
184 connect(octaveSystem, SIGNAL(currentIndexChanged(int)), 188 connect(octaveSystem, SIGNAL(currentIndexChanged(int)),
185 this, SLOT(octaveSystemChanged(int))); 189 this, SLOT(octaveSystemChanged(int)));
186 190
187 /*!!! restore
188 QComboBox *audioDevice = new QComboBox;
189 std::vector<QString> devices =
190 AudioTargetFactory::getInstance()->getCallbackTargetNames();
191
192 settings.beginGroup("Preferences"); 191 settings.beginGroup("Preferences");
193 QString targetName = settings.value("audio-target", "").toString(); 192
193 QComboBox *audioImplementation = new QComboBox;
194 connect(audioImplementation, SIGNAL(currentIndexChanged(int)),
195 this, SLOT(audioImplementationChanged(int)));
196
197 m_audioPlaybackDeviceCombo = new QComboBox;
198 connect(m_audioPlaybackDeviceCombo, SIGNAL(currentIndexChanged(int)),
199 this, SLOT(audioPlaybackDeviceChanged(int)));
200
201 m_audioRecordDeviceCombo = new QComboBox;
202 connect(m_audioRecordDeviceCombo, SIGNAL(currentIndexChanged(int)),
203 this, SLOT(audioRecordDeviceChanged(int)));
204
205 vector<string> names = breakfastquay::AudioFactory::getImplementationNames();
206 QString implementationName = settings.value("audio-target", "").toString();
207 if (implementationName == "auto") implementationName = "";
208 audioImplementation->addItem(tr("(auto)"));
209 m_audioImplementation = 0;
210 for (int i = 0; in_range_for(names, i); ++i) {
211 audioImplementation->addItem
212 (breakfastquay::AudioFactory::getImplementationDescription(names[i]).
213 c_str());
214 if (implementationName.toStdString() == names[i]) {
215 audioImplementation->setCurrentIndex(i+1);
216 m_audioImplementation = i+1;
217 }
218 }
194 settings.endGroup(); 219 settings.endGroup();
195 220
196 for (int i = 0; i < (int)devices.size(); ++i) { 221 rebuildDeviceCombos();
197 audioDevice->addItem(AudioTargetFactory::getInstance() 222 m_changesOnRestart = false; // the rebuild will have changed this
198 ->getCallbackTargetDescription(devices[i]));
199 if (targetName == devices[i]) audioDevice->setCurrentIndex(i);
200 }
201
202 connect(audioDevice, SIGNAL(currentIndexChanged(int)),
203 this, SLOT(audioDeviceChanged(int)));
204 */
205 223
206 QCheckBox *resampleOnLoad = new QCheckBox; 224 QCheckBox *resampleOnLoad = new QCheckBox;
207 m_resampleOnLoad = prefs->getResampleOnLoad(); 225 m_resampleOnLoad = prefs->getResampleOnLoad();
208 resampleOnLoad->setCheckState(m_resampleOnLoad ? Qt::Checked : 226 resampleOnLoad->setCheckState(m_resampleOnLoad ? Qt::Checked :
209 Qt::Unchecked); 227 Qt::Unchecked);
367 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel 385 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
368 ("Use Gapless Mode"))), 386 ("Use Gapless Mode"))),
369 row, 0); 387 row, 0);
370 subgrid->addWidget(gaplessMode, row++, 1, 1, 1); 388 subgrid->addWidget(gaplessMode, row++, 1, 1, 1);
371 389
372 //!!! subgrid->addWidget(new QLabel(tr("Playback audio device:")), row, 0); 390 subgrid->addWidget(new QLabel(tr("Audio service:")), row, 0);
373 //!!! subgrid->addWidget(audioDevice, row++, 1, 1, 2); 391 subgrid->addWidget(audioImplementation, row++, 1, 1, 2);
392
393 subgrid->addWidget(new QLabel(tr("Audio playback device:")), row, 0);
394 subgrid->addWidget(m_audioPlaybackDeviceCombo, row++, 1, 1, 2);
395
396 subgrid->addWidget(new QLabel(tr("Audio record device:")), row, 0);
397 subgrid->addWidget(m_audioRecordDeviceCombo, row++, 1, 1, 2);
374 398
375 subgrid->setRowStretch(row, 10); 399 subgrid->setRowStretch(row, 10);
376 400
377 m_tabOrdering[GeneralTab] = m_tabs->count(); 401 m_tabOrdering[GeneralTab] = m_tabs->count();
378 m_tabs->addTab(frame, tr("&General")); 402 m_tabs->addTab(frame, tr("&General"));
508 } 532 }
509 m_templates.push_back(""); 533 m_templates.push_back("");
510 534
511 QStringList templates = ResourceFinder().getResourceFiles("templates", "svt"); 535 QStringList templates = ResourceFinder().getResourceFiles("templates", "svt");
512 536
513 std::set<QString> byName; 537 set<QString> byName;
514 foreach (QString t, templates) { 538 foreach (QString t, templates) {
515 byName.insert(QFileInfo(t).baseName()); 539 byName.insert(QFileInfo(t).baseName());
516 } 540 }
517 541
518 foreach (QString t, byName) { 542 foreach (QString t, byName) {
548 { 572 {
549 SVDEBUG << "PreferencesDialog::~PreferencesDialog()" << endl; 573 SVDEBUG << "PreferencesDialog::~PreferencesDialog()" << endl;
550 } 574 }
551 575
552 void 576 void
577 PreferencesDialog::rebuildDeviceCombos()
578 {
579 QSettings settings;
580 settings.beginGroup("Preferences");
581
582 vector<string> names = breakfastquay::AudioFactory::getImplementationNames();
583 string implementationName;
584 if (in_range_for(names, m_audioImplementation-1)) {
585 implementationName = names[m_audioImplementation-1];
586 }
587
588 m_audioPlaybackDeviceCombo->clear();
589 m_audioRecordDeviceCombo->clear();
590
591 QString suffix;
592 if (implementationName != "") {
593 suffix = "-" + QString(implementationName.c_str());
594 }
595
596 names = breakfastquay::AudioFactory::getPlaybackDeviceNames(implementationName);
597 QString playbackDeviceName = settings.value
598 ("audio-playback-device" + suffix, "").toString();
599 m_audioPlaybackDeviceCombo->addItem(tr("(auto)"));
600 m_audioPlaybackDeviceCombo->setCurrentIndex(0);
601 m_audioPlaybackDevice = 0;
602 for (int i = 0; in_range_for(names, i); ++i) {
603 m_audioPlaybackDeviceCombo->addItem(names[i].c_str());
604 if (playbackDeviceName.toStdString() == names[i]) {
605 m_audioPlaybackDeviceCombo->setCurrentIndex(i+1);
606 m_audioPlaybackDevice = i+1;
607 }
608 }
609
610 names = breakfastquay::AudioFactory::getRecordDeviceNames(implementationName);
611 QString recordDeviceName = settings.value
612 ("audio-record-device" + suffix, "").toString();
613 m_audioRecordDeviceCombo->addItem(tr("(auto)"));
614 m_audioRecordDeviceCombo->setCurrentIndex(0);
615 m_audioRecordDevice = 0;
616 for (int i = 0; in_range_for(names, i); ++i) {
617 m_audioRecordDeviceCombo->addItem(names[i].c_str());
618 if (recordDeviceName.toStdString() == names[i]) {
619 m_audioRecordDeviceCombo->setCurrentIndex(i+1);
620 m_audioRecordDevice = i+1;
621 }
622 }
623
624 settings.endGroup();
625 }
626
627 void
553 PreferencesDialog::switchToTab(Tab t) 628 PreferencesDialog::switchToTab(Tab t)
554 { 629 {
555 if (m_tabOrdering.contains(t)) { 630 if (m_tabOrdering.contains(t)) {
556 m_tabs->setCurrentIndex(m_tabOrdering[t]); 631 m_tabs->setCurrentIndex(m_tabOrdering[t]);
557 } 632 }
612 m_tuningFrequency = freq; 687 m_tuningFrequency = freq;
613 m_applyButton->setEnabled(true); 688 m_applyButton->setEnabled(true);
614 } 689 }
615 690
616 void 691 void
617 PreferencesDialog::audioDeviceChanged(int s) 692 PreferencesDialog::audioImplementationChanged(int s)
618 { 693 {
619 m_audioDevice = s; 694 if (m_audioImplementation != s) {
620 m_applyButton->setEnabled(true); 695 m_audioImplementation = s;
621 m_changesOnRestart = true; 696 rebuildDeviceCombos();
697 m_applyButton->setEnabled(true);
698 m_changesOnRestart = true;
699 }
700 }
701
702 void
703 PreferencesDialog::audioPlaybackDeviceChanged(int s)
704 {
705 if (m_audioPlaybackDevice != s) {
706 m_audioPlaybackDevice = s;
707 m_applyButton->setEnabled(true);
708 m_changesOnRestart = true;
709 }
710 }
711
712 void
713 PreferencesDialog::audioRecordDeviceChanged(int s)
714 {
715 if (m_audioRecordDevice != s) {
716 m_audioRecordDevice = s;
717 m_applyButton->setEnabled(true);
718 m_changesOnRestart = true;
719 }
622 } 720 }
623 721
624 void 722 void
625 PreferencesDialog::resampleOnLoadChanged(int state) 723 PreferencesDialog::resampleOnLoadChanged(int state)
626 { 724 {
767 prefs->setShowHMS(m_showHMS); 865 prefs->setShowHMS(m_showHMS);
768 prefs->setViewFontSize(m_viewFontSize); 866 prefs->setViewFontSize(m_viewFontSize);
769 867
770 prefs->setProperty("Octave Numbering System", m_octaveSystem); 868 prefs->setProperty("Octave Numbering System", m_octaveSystem);
771 869
772 //!!! std::vector<QString> devices =
773 //!!! AudioTargetFactory::getInstance()->getCallbackTargetNames();
774
775 QSettings settings; 870 QSettings settings;
776 settings.beginGroup("Preferences"); 871 settings.beginGroup("Preferences");
777 QString permishTag = QString("network-permission-%1").arg(SV_VERSION); 872 QString permishTag = QString("network-permission-%1").arg(SV_VERSION);
778 settings.setValue(permishTag, m_networkPermission); 873 settings.setValue(permishTag, m_networkPermission);
779 //!!! settings.setValue("audio-target", devices[m_audioDevice]); 874
875 vector<string> names = breakfastquay::AudioFactory::getImplementationNames();
876 string implementationName;
877 if (m_audioImplementation > 0) {
878 implementationName = names[m_audioImplementation-1];
879 }
880 settings.setValue("audio-target", implementationName.c_str());
881
882 QString suffix;
883 if (implementationName != "") {
884 suffix = "-" + QString(implementationName.c_str());
885 }
886
887 names = breakfastquay::AudioFactory::getPlaybackDeviceNames(implementationName);
888 string deviceName;
889 if (m_audioPlaybackDevice > 0) {
890 deviceName = names[m_audioPlaybackDevice-1];
891 }
892 settings.setValue("audio-playback-device" + suffix, deviceName.c_str());
893
894 names = breakfastquay::AudioFactory::getRecordDeviceNames(implementationName);
895 deviceName = "";
896 if (m_audioRecordDevice > 0) {
897 deviceName = names[m_audioRecordDevice-1];
898 }
899 settings.setValue("audio-record-device" + suffix, deviceName.c_str());
900
780 settings.setValue("locale", m_currentLocale); 901 settings.setValue("locale", m_currentLocale);
781 #ifdef Q_OS_MAC 902 #ifdef Q_OS_MAC
782 settings.setValue("scaledHiDpi", m_retina); 903 settings.setValue("scaledHiDpi", m_retina);
783 #endif 904 #endif
784 settings.setValue("spectrogram-colour", m_spectrogramGColour); 905 settings.setValue("spectrogram-colour", m_spectrogramGColour);