comparison main/PreferencesDialog.cpp @ 1429:3e2dee09c10c levelpanwidget

Merge from branch 3.0-integration
author Chris Cannam
date Wed, 14 Dec 2016 14:28:41 +0000
parents 4618d3a03069
children a9c30afdbbfe
comparison
equal deleted inserted replaced
1394:db151fd29091 1429:3e2dee09c10c
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),
56 m_audioDeviceChanged(false),
52 m_changesOnRestart(false) 57 m_changesOnRestart(false)
53 { 58 {
54 setWindowTitle(tr("Sonic Visualiser: Application Preferences")); 59 setWindowTitle(tr("Sonic Visualiser: Application Preferences"));
55 60
56 Preferences *prefs = Preferences::getInstance(); 61 Preferences *prefs = Preferences::getInstance();
182 octaveSystem->setCurrentIndex(oct); 187 octaveSystem->setCurrentIndex(oct);
183 188
184 connect(octaveSystem, SIGNAL(currentIndexChanged(int)), 189 connect(octaveSystem, SIGNAL(currentIndexChanged(int)),
185 this, SLOT(octaveSystemChanged(int))); 190 this, SLOT(octaveSystemChanged(int)));
186 191
187 /*!!! restore
188 QComboBox *audioDevice = new QComboBox;
189 std::vector<QString> devices =
190 AudioTargetFactory::getInstance()->getCallbackTargetNames();
191
192 settings.beginGroup("Preferences"); 192 settings.beginGroup("Preferences");
193 QString targetName = settings.value("audio-target", "").toString(); 193
194 QComboBox *audioImplementation = new QComboBox;
195 connect(audioImplementation, SIGNAL(currentIndexChanged(int)),
196 this, SLOT(audioImplementationChanged(int)));
197
198 m_audioPlaybackDeviceCombo = new QComboBox;
199 connect(m_audioPlaybackDeviceCombo, SIGNAL(currentIndexChanged(int)),
200 this, SLOT(audioPlaybackDeviceChanged(int)));
201
202 m_audioRecordDeviceCombo = new QComboBox;
203 connect(m_audioRecordDeviceCombo, SIGNAL(currentIndexChanged(int)),
204 this, SLOT(audioRecordDeviceChanged(int)));
205
206 vector<string> names = breakfastquay::AudioFactory::getImplementationNames();
207 QString implementationName = settings.value("audio-target", "").toString();
208 if (implementationName == "auto") implementationName = "";
209 audioImplementation->addItem(tr("(auto)"));
210 m_audioImplementation = 0;
211 for (int i = 0; in_range_for(names, i); ++i) {
212 audioImplementation->addItem
213 (breakfastquay::AudioFactory::getImplementationDescription(names[i]).
214 c_str());
215 if (implementationName.toStdString() == names[i]) {
216 audioImplementation->setCurrentIndex(i+1);
217 m_audioImplementation = i+1;
218 }
219 }
194 settings.endGroup(); 220 settings.endGroup();
195 221
196 for (int i = 0; i < (int)devices.size(); ++i) { 222 rebuildDeviceCombos();
197 audioDevice->addItem(AudioTargetFactory::getInstance() 223 m_audioDeviceChanged = 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 224
206 QCheckBox *resampleOnLoad = new QCheckBox; 225 QCheckBox *resampleOnLoad = new QCheckBox;
207 m_resampleOnLoad = prefs->getResampleOnLoad(); 226 m_resampleOnLoad = prefs->getResampleOnLoad();
208 resampleOnLoad->setCheckState(m_resampleOnLoad ? Qt::Checked : 227 resampleOnLoad->setCheckState(m_resampleOnLoad ? Qt::Checked :
209 Qt::Unchecked); 228 Qt::Unchecked);
367 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel 386 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
368 ("Use Gapless Mode"))), 387 ("Use Gapless Mode"))),
369 row, 0); 388 row, 0);
370 subgrid->addWidget(gaplessMode, row++, 1, 1, 1); 389 subgrid->addWidget(gaplessMode, row++, 1, 1, 1);
371 390
372 //!!! subgrid->addWidget(new QLabel(tr("Playback audio device:")), row, 0); 391 subgrid->addWidget(new QLabel(tr("Audio service:")), row, 0);
373 //!!! subgrid->addWidget(audioDevice, row++, 1, 1, 2); 392 subgrid->addWidget(audioImplementation, row++, 1, 1, 2);
393
394 subgrid->addWidget(new QLabel(tr("Audio playback device:")), row, 0);
395 subgrid->addWidget(m_audioPlaybackDeviceCombo, row++, 1, 1, 2);
396
397 subgrid->addWidget(new QLabel(tr("Audio record device:")), row, 0);
398 subgrid->addWidget(m_audioRecordDeviceCombo, row++, 1, 1, 2);
374 399
375 subgrid->setRowStretch(row, 10); 400 subgrid->setRowStretch(row, 10);
376 401
377 m_tabOrdering[GeneralTab] = m_tabs->count(); 402 m_tabOrdering[GeneralTab] = m_tabs->count();
378 m_tabs->addTab(frame, tr("&General")); 403 m_tabs->addTab(frame, tr("&General"));
496 QListWidget *lw = new QListWidget(); 521 QListWidget *lw = new QListWidget();
497 subgrid->addWidget(lw, row, 0); 522 subgrid->addWidget(lw, row, 0);
498 subgrid->setRowStretch(row, 10); 523 subgrid->setRowStretch(row, 10);
499 row++; 524 row++;
500 525
526 subgrid->addWidget(new QLabel(tr("(Use \"%1\" in the File menu to add to these.)")
527 .arg(tr("Export Session as Template..."))),
528 row++, 0);
529
501 settings.beginGroup("MainWindow"); 530 settings.beginGroup("MainWindow");
502 m_currentTemplate = settings.value("sessiontemplate", "").toString(); 531 m_currentTemplate = settings.value("sessiontemplate", "").toString();
503 settings.endGroup(); 532 settings.endGroup();
504 533
505 lw->addItem(tr("Standard Waveform")); 534 lw->addItem(tr("Standard Waveform"));
508 } 537 }
509 m_templates.push_back(""); 538 m_templates.push_back("");
510 539
511 QStringList templates = ResourceFinder().getResourceFiles("templates", "svt"); 540 QStringList templates = ResourceFinder().getResourceFiles("templates", "svt");
512 541
513 std::set<QString> byName; 542 set<QString> byName;
514 foreach (QString t, templates) { 543 foreach (QString t, templates) {
515 byName.insert(QFileInfo(t).baseName()); 544 byName.insert(QFileInfo(t).baseName());
516 } 545 }
517 546
518 foreach (QString t, byName) { 547 foreach (QString t, byName) {
548 { 577 {
549 SVDEBUG << "PreferencesDialog::~PreferencesDialog()" << endl; 578 SVDEBUG << "PreferencesDialog::~PreferencesDialog()" << endl;
550 } 579 }
551 580
552 void 581 void
582 PreferencesDialog::rebuildDeviceCombos()
583 {
584 QSettings settings;
585 settings.beginGroup("Preferences");
586
587 vector<string> names = breakfastquay::AudioFactory::getImplementationNames();
588 string implementationName;
589 if (in_range_for(names, m_audioImplementation-1)) {
590 implementationName = names[m_audioImplementation-1];
591 }
592
593 QString suffix;
594 if (implementationName != "") {
595 suffix = "-" + QString(implementationName.c_str());
596 }
597
598 names = breakfastquay::AudioFactory::getPlaybackDeviceNames(implementationName);
599 QString playbackDeviceName = settings.value
600 ("audio-playback-device" + suffix, "").toString();
601 m_audioPlaybackDeviceCombo->clear();
602 m_audioPlaybackDeviceCombo->addItem(tr("(auto)"));
603 m_audioPlaybackDeviceCombo->setCurrentIndex(0);
604 m_audioPlaybackDevice = 0;
605 for (int i = 0; in_range_for(names, i); ++i) {
606 m_audioPlaybackDeviceCombo->addItem(names[i].c_str());
607 if (playbackDeviceName.toStdString() == names[i]) {
608 m_audioPlaybackDeviceCombo->setCurrentIndex(i+1);
609 m_audioPlaybackDevice = i+1;
610 }
611 }
612
613 names = breakfastquay::AudioFactory::getRecordDeviceNames(implementationName);
614 QString recordDeviceName = settings.value
615 ("audio-record-device" + suffix, "").toString();
616 m_audioRecordDeviceCombo->clear();
617 m_audioRecordDeviceCombo->addItem(tr("(auto)"));
618 m_audioRecordDeviceCombo->setCurrentIndex(0);
619 m_audioRecordDevice = 0;
620 for (int i = 0; in_range_for(names, i); ++i) {
621 m_audioRecordDeviceCombo->addItem(names[i].c_str());
622 if (recordDeviceName.toStdString() == names[i]) {
623 m_audioRecordDeviceCombo->setCurrentIndex(i+1);
624 m_audioRecordDevice = i+1;
625 }
626 }
627
628 settings.endGroup();
629 }
630
631 void
553 PreferencesDialog::switchToTab(Tab t) 632 PreferencesDialog::switchToTab(Tab t)
554 { 633 {
555 if (m_tabOrdering.contains(t)) { 634 if (m_tabOrdering.contains(t)) {
556 m_tabs->setCurrentIndex(m_tabOrdering[t]); 635 m_tabs->setCurrentIndex(m_tabOrdering[t]);
557 } 636 }
612 m_tuningFrequency = freq; 691 m_tuningFrequency = freq;
613 m_applyButton->setEnabled(true); 692 m_applyButton->setEnabled(true);
614 } 693 }
615 694
616 void 695 void
617 PreferencesDialog::audioDeviceChanged(int s) 696 PreferencesDialog::audioImplementationChanged(int s)
618 { 697 {
619 m_audioDevice = s; 698 if (m_audioImplementation != s) {
620 m_applyButton->setEnabled(true); 699 m_audioImplementation = s;
621 m_changesOnRestart = true; 700 rebuildDeviceCombos();
701 m_applyButton->setEnabled(true);
702 m_audioDeviceChanged = true;
703 }
704 }
705
706 void
707 PreferencesDialog::audioPlaybackDeviceChanged(int s)
708 {
709 if (m_audioPlaybackDevice != s) {
710 m_audioPlaybackDevice = s;
711 m_applyButton->setEnabled(true);
712 m_audioDeviceChanged = true;
713 }
714 }
715
716 void
717 PreferencesDialog::audioRecordDeviceChanged(int s)
718 {
719 if (m_audioRecordDevice != s) {
720 m_audioRecordDevice = s;
721 m_applyButton->setEnabled(true);
722 m_audioDeviceChanged = true;
723 }
622 } 724 }
623 725
624 void 726 void
625 PreferencesDialog::resampleOnLoadChanged(int state) 727 PreferencesDialog::resampleOnLoadChanged(int state)
626 { 728 {
767 prefs->setShowHMS(m_showHMS); 869 prefs->setShowHMS(m_showHMS);
768 prefs->setViewFontSize(m_viewFontSize); 870 prefs->setViewFontSize(m_viewFontSize);
769 871
770 prefs->setProperty("Octave Numbering System", m_octaveSystem); 872 prefs->setProperty("Octave Numbering System", m_octaveSystem);
771 873
772 //!!! std::vector<QString> devices =
773 //!!! AudioTargetFactory::getInstance()->getCallbackTargetNames();
774
775 QSettings settings; 874 QSettings settings;
776 settings.beginGroup("Preferences"); 875 settings.beginGroup("Preferences");
777 QString permishTag = QString("network-permission-%1").arg(SV_VERSION); 876 QString permishTag = QString("network-permission-%1").arg(SV_VERSION);
778 settings.setValue(permishTag, m_networkPermission); 877 settings.setValue(permishTag, m_networkPermission);
779 //!!! settings.setValue("audio-target", devices[m_audioDevice]); 878
879 vector<string> names = breakfastquay::AudioFactory::getImplementationNames();
880 string implementationName;
881 if (m_audioImplementation > int(names.size())) {
882 m_audioImplementation = 0;
883 }
884 if (m_audioImplementation > 0) {
885 implementationName = names[m_audioImplementation-1];
886 }
887 settings.setValue("audio-target", implementationName.c_str());
888
889 QString suffix;
890 if (implementationName != "") {
891 suffix = "-" + QString(implementationName.c_str());
892 }
893
894 names = breakfastquay::AudioFactory::getPlaybackDeviceNames(implementationName);
895 string deviceName;
896 if (m_audioPlaybackDevice > int(names.size())) {
897 m_audioPlaybackDevice = 0;
898 }
899 if (m_audioPlaybackDevice > 0) {
900 deviceName = names[m_audioPlaybackDevice-1];
901 }
902 settings.setValue("audio-playback-device" + suffix, deviceName.c_str());
903
904 names = breakfastquay::AudioFactory::getRecordDeviceNames(implementationName);
905 deviceName = "";
906 if (m_audioRecordDevice > int(names.size())) {
907 m_audioRecordDevice = 0;
908 }
909 if (m_audioRecordDevice > 0) {
910 deviceName = names[m_audioRecordDevice-1];
911 }
912 settings.setValue("audio-record-device" + suffix, deviceName.c_str());
913
780 settings.setValue("locale", m_currentLocale); 914 settings.setValue("locale", m_currentLocale);
781 #ifdef Q_OS_MAC 915 #ifdef Q_OS_MAC
782 settings.setValue("scaledHiDpi", m_retina); 916 settings.setValue("scaledHiDpi", m_retina);
783 #endif 917 #endif
784 settings.setValue("spectrogram-colour", m_spectrogramGColour); 918 settings.setValue("spectrogram-colour", m_spectrogramGColour);
794 928
795 if (m_changesOnRestart) { 929 if (m_changesOnRestart) {
796 QMessageBox::information(this, tr("Preferences"), 930 QMessageBox::information(this, tr("Preferences"),
797 tr("<b>Restart required</b><p>One or more of the application preferences you have changed may not take full effect until Sonic Visualiser is restarted.</p><p>Please exit and restart the application now if you want these changes to take effect immediately.</p>")); 931 tr("<b>Restart required</b><p>One or more of the application preferences you have changed may not take full effect until Sonic Visualiser is restarted.</p><p>Please exit and restart the application now if you want these changes to take effect immediately.</p>"));
798 m_changesOnRestart = false; 932 m_changesOnRestart = false;
933 }
934
935 if (m_audioDeviceChanged) {
936 emit audioDeviceChanged();
937 m_audioDeviceChanged = false;
799 } 938 }
800 } 939 }
801 940
802 void 941 void
803 PreferencesDialog::cancelClicked() 942 PreferencesDialog::cancelClicked()