annotate main/PreferencesDialog.cpp @ 1324:b5bce5d34927 piper

Avoid assigning model resolution of 0 to models coming from plugins that report weirdly high output rates (symptom: data did not show up in edit layer data dialog, as the row/frame conversion failed)
author Chris Cannam
date Sat, 05 Nov 2016 10:40:22 +0000
parents 0c6cdcf53641
children a264b51728cf
rev   line source
Chris@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 Sonic Visualiser
Chris@0 5 An audio file viewer and annotation editor.
Chris@0 6 Centre for Digital Music, Queen Mary, University of London.
Chris@0 7 This file copyright 2006 Chris Cannam.
Chris@0 8
Chris@0 9 This program is free software; you can redistribute it and/or
Chris@0 10 modify it under the terms of the GNU General Public License as
Chris@0 11 published by the Free Software Foundation; either version 2 of the
Chris@0 12 License, or (at your option) any later version. See the file
Chris@0 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #include "PreferencesDialog.h"
Chris@0 17
Chris@0 18 #include <QGridLayout>
Chris@0 19 #include <QComboBox>
Chris@0 20 #include <QCheckBox>
Chris@0 21 #include <QGroupBox>
Chris@0 22 #include <QDoubleSpinBox>
Chris@0 23 #include <QLabel>
Chris@0 24 #include <QPushButton>
Chris@0 25 #include <QHBoxLayout>
Chris@0 26 #include <QString>
Chris@163 27 #include <QDialogButtonBox>
Chris@163 28 #include <QMessageBox>
Chris@180 29 #include <QTabWidget>
Chris@180 30 #include <QLineEdit>
Chris@180 31 #include <QFileDialog>
Chris@180 32 #include <QMessageBox>
Chris@225 33 #include <QSpinBox>
Chris@436 34 #include <QListWidget>
Chris@263 35 #include <QSettings>
Chris@0 36
Chris@436 37 #include <set>
Chris@436 38
Chris@9 39 #include "widgets/WindowTypeSelector.h"
Chris@180 40 #include "widgets/IconLoader.h"
Chris@0 41 #include "base/Preferences.h"
Chris@436 42 #include "base/ResourceFinder.h"
Chris@1096 43 #include "layer/ColourMapper.h"
Chris@0 44
Chris@1035 45 //#include "audioio/AudioTargetFactory.h"
Chris@1035 46
Chris@686 47 #include "version.h"
Chris@686 48
Chris@528 49 PreferencesDialog::PreferencesDialog(QWidget *parent) :
Chris@528 50 QDialog(parent),
Chris@263 51 m_audioDevice(0),
Chris@180 52 m_changesOnRestart(false)
Chris@0 53 {
Chris@163 54 setWindowTitle(tr("Sonic Visualiser: Application Preferences"));
Chris@0 55
Chris@0 56 Preferences *prefs = Preferences::getInstance();
Chris@0 57
Chris@0 58 QGridLayout *grid = new QGridLayout;
Chris@0 59 setLayout(grid);
Chris@180 60
Chris@436 61 m_tabs = new QTabWidget;
Chris@436 62 grid->addWidget(m_tabs, 0, 0);
Chris@0 63
Chris@436 64 m_tabs->setTabPosition(QTabWidget::North);
Chris@0 65
Chris@0 66 // Create this first, as slots that get called from the ctor will
Chris@0 67 // refer to it
Chris@0 68 m_applyButton = new QPushButton(tr("Apply"));
Chris@0 69
Chris@180 70 // Create all the preference widgets first, then create the
Chris@180 71 // individual tab widgets and place the preferences in their
Chris@180 72 // appropriate places in one go afterwards
Chris@180 73
Chris@114 74 int min, max, deflt, i;
Chris@0 75
Chris@9 76 m_windowType = WindowType(prefs->getPropertyRangeAndValue
Chris@114 77 ("Window Type", &min, &max, &deflt));
Chris@9 78 m_windowTypeSelector = new WindowTypeSelector(m_windowType);
Chris@0 79
Chris@9 80 connect(m_windowTypeSelector, SIGNAL(windowTypeChanged(WindowType)),
Chris@9 81 this, SLOT(windowTypeChanged(WindowType)));
Chris@0 82
Chris@1275 83 QCheckBox *vampProcessSeparation = new QCheckBox;
Chris@1275 84 m_runPluginsInProcess = prefs->getRunPluginsInProcess();
Chris@1275 85 vampProcessSeparation->setCheckState(m_runPluginsInProcess ? Qt::Unchecked :
Chris@1275 86 Qt::Checked);
Chris@1275 87 connect(vampProcessSeparation, SIGNAL(stateChanged(int)),
Chris@1275 88 this, SLOT(vampProcessSeparationChanged(int)));
Chris@1275 89
Chris@115 90 QComboBox *smoothing = new QComboBox;
Chris@115 91
Chris@299 92 int sm = prefs->getPropertyRangeAndValue("Spectrogram Y Smoothing", &min, &max,
Chris@115 93 &deflt);
Chris@115 94 m_spectrogramSmoothing = sm;
Chris@0 95
Chris@115 96 for (i = min; i <= max; ++i) {
Chris@299 97 smoothing->addItem(prefs->getPropertyValueLabel("Spectrogram Y Smoothing", i));
Chris@115 98 }
Chris@115 99
Chris@115 100 smoothing->setCurrentIndex(sm);
Chris@115 101
Chris@115 102 connect(smoothing, SIGNAL(currentIndexChanged(int)),
Chris@115 103 this, SLOT(spectrogramSmoothingChanged(int)));
Chris@0 104
Chris@299 105 QComboBox *xsmoothing = new QComboBox;
Chris@299 106
Chris@299 107 int xsm = prefs->getPropertyRangeAndValue("Spectrogram X Smoothing", &min, &max,
Chris@299 108 &deflt);
Chris@299 109 m_spectrogramXSmoothing = xsm;
Chris@299 110
Chris@299 111 for (i = min; i <= max; ++i) {
Chris@299 112 xsmoothing->addItem(prefs->getPropertyValueLabel("Spectrogram X Smoothing", i));
Chris@299 113 }
Chris@299 114
Chris@299 115 xsmoothing->setCurrentIndex(xsm);
Chris@299 116
Chris@299 117 connect(xsmoothing, SIGNAL(currentIndexChanged(int)),
Chris@299 118 this, SLOT(spectrogramXSmoothingChanged(int)));
Chris@299 119
Chris@0 120 QComboBox *propertyLayout = new QComboBox;
Chris@114 121 int pl = prefs->getPropertyRangeAndValue("Property Box Layout", &min, &max,
Chris@115 122 &deflt);
Chris@0 123 m_propertyLayout = pl;
Chris@0 124
Chris@0 125 for (i = min; i <= max; ++i) {
Chris@0 126 propertyLayout->addItem(prefs->getPropertyValueLabel("Property Box Layout", i));
Chris@0 127 }
Chris@0 128
Chris@0 129 propertyLayout->setCurrentIndex(pl);
Chris@0 130
Chris@0 131 connect(propertyLayout, SIGNAL(currentIndexChanged(int)),
Chris@0 132 this, SLOT(propertyLayoutChanged(int)));
Chris@0 133
Chris@1096 134 QSettings settings;
Chris@1096 135 settings.beginGroup("Preferences");
Chris@1096 136 m_spectrogramGColour = (settings.value("spectrogram-colour",
Chris@1096 137 int(ColourMapper::Green)).toInt());
Chris@1096 138 m_spectrogramMColour = (settings.value("spectrogram-melodic-colour",
Chris@1096 139 int(ColourMapper::Sunset)).toInt());
Chris@1097 140 m_colour3DColour = (settings.value("colour-3d-plot-colour",
Chris@1097 141 int(ColourMapper::Green)).toInt());
Chris@1096 142 settings.endGroup();
Chris@1096 143 QComboBox *spectrogramGColour = new QComboBox;
Chris@1096 144 QComboBox *spectrogramMColour = new QComboBox;
Chris@1097 145 QComboBox *colour3DColour = new QComboBox;
Chris@1096 146 for (i = 0; i < ColourMapper::getColourMapCount(); ++i) {
Chris@1096 147 spectrogramGColour->addItem(ColourMapper::getColourMapName(i));
Chris@1096 148 spectrogramMColour->addItem(ColourMapper::getColourMapName(i));
Chris@1097 149 colour3DColour->addItem(ColourMapper::getColourMapName(i));
Chris@1096 150 if (i == m_spectrogramGColour) spectrogramGColour->setCurrentIndex(i);
Chris@1096 151 if (i == m_spectrogramMColour) spectrogramMColour->setCurrentIndex(i);
Chris@1097 152 if (i == m_colour3DColour) colour3DColour->setCurrentIndex(i);
Chris@1096 153 }
Chris@1096 154 connect(spectrogramGColour, SIGNAL(currentIndexChanged(int)),
Chris@1096 155 this, SLOT(spectrogramGColourChanged(int)));
Chris@1096 156 connect(spectrogramMColour, SIGNAL(currentIndexChanged(int)),
Chris@1096 157 this, SLOT(spectrogramMColourChanged(int)));
Chris@1097 158 connect(colour3DColour, SIGNAL(currentIndexChanged(int)),
Chris@1097 159 this, SLOT(colour3DColourChanged(int)));
Chris@702 160
Chris@0 161 m_tuningFrequency = prefs->getTuningFrequency();
Chris@0 162
Chris@0 163 QDoubleSpinBox *frequency = new QDoubleSpinBox;
Chris@0 164 frequency->setMinimum(100.0);
Chris@0 165 frequency->setMaximum(5000.0);
Chris@0 166 frequency->setSuffix(" Hz");
Chris@0 167 frequency->setSingleStep(1);
Chris@0 168 frequency->setValue(m_tuningFrequency);
Chris@0 169 frequency->setDecimals(2);
Chris@0 170
Chris@0 171 connect(frequency, SIGNAL(valueChanged(double)),
Chris@0 172 this, SLOT(tuningFrequencyChanged(double)));
Chris@0 173
Chris@702 174 QComboBox *octaveSystem = new QComboBox;
Chris@702 175 int oct = prefs->getPropertyRangeAndValue
Chris@702 176 ("Octave Numbering System", &min, &max, &deflt);
Chris@702 177 m_octaveSystem = oct;
Chris@702 178 for (i = min; i <= max; ++i) {
Chris@702 179 octaveSystem->addItem(prefs->getPropertyValueLabel
Chris@702 180 ("Octave Numbering System", i));
Chris@702 181 }
Chris@702 182 octaveSystem->setCurrentIndex(oct);
Chris@702 183
Chris@702 184 connect(octaveSystem, SIGNAL(currentIndexChanged(int)),
Chris@702 185 this, SLOT(octaveSystemChanged(int)));
Chris@702 186
Chris@1035 187 /*!!! restore
Chris@263 188 QComboBox *audioDevice = new QComboBox;
Chris@263 189 std::vector<QString> devices =
Chris@263 190 AudioTargetFactory::getInstance()->getCallbackTargetNames();
Chris@263 191
Chris@263 192 settings.beginGroup("Preferences");
Chris@263 193 QString targetName = settings.value("audio-target", "").toString();
Chris@263 194 settings.endGroup();
Chris@263 195
Chris@658 196 for (int i = 0; i < (int)devices.size(); ++i) {
Chris@263 197 audioDevice->addItem(AudioTargetFactory::getInstance()
Chris@263 198 ->getCallbackTargetDescription(devices[i]));
Chris@263 199 if (targetName == devices[i]) audioDevice->setCurrentIndex(i);
Chris@263 200 }
Chris@263 201
Chris@263 202 connect(audioDevice, SIGNAL(currentIndexChanged(int)),
Chris@263 203 this, SLOT(audioDeviceChanged(int)));
Chris@1035 204 */
Chris@32 205 QComboBox *resampleQuality = new QComboBox;
Chris@32 206
Chris@114 207 int rsq = prefs->getPropertyRangeAndValue("Resample Quality", &min, &max,
Chris@114 208 &deflt);
Chris@32 209 m_resampleQuality = rsq;
Chris@32 210
Chris@32 211 for (i = min; i <= max; ++i) {
Chris@32 212 resampleQuality->addItem(prefs->getPropertyValueLabel("Resample Quality", i));
Chris@32 213 }
Chris@32 214
Chris@32 215 resampleQuality->setCurrentIndex(rsq);
Chris@32 216
Chris@32 217 connect(resampleQuality, SIGNAL(currentIndexChanged(int)),
Chris@32 218 this, SLOT(resampleQualityChanged(int)));
Chris@32 219
Chris@180 220 QCheckBox *resampleOnLoad = new QCheckBox;
Chris@180 221 m_resampleOnLoad = prefs->getResampleOnLoad();
Chris@180 222 resampleOnLoad->setCheckState(m_resampleOnLoad ? Qt::Checked :
Chris@180 223 Qt::Unchecked);
Chris@180 224 connect(resampleOnLoad, SIGNAL(stateChanged(int)),
Chris@180 225 this, SLOT(resampleOnLoadChanged(int)));
Chris@180 226
Chris@180 227 m_tempDirRootEdit = new QLineEdit;
Chris@180 228 QString dir = prefs->getTemporaryDirectoryRoot();
Chris@180 229 m_tempDirRoot = dir;
Chris@180 230 dir.replace("$HOME", tr("<home directory>"));
Chris@180 231 m_tempDirRootEdit->setText(dir);
Chris@180 232 m_tempDirRootEdit->setReadOnly(true);
Chris@180 233 QPushButton *tempDirButton = new QPushButton;
Chris@180 234 tempDirButton->setIcon(IconLoader().load("fileopen"));
Chris@180 235 connect(tempDirButton, SIGNAL(clicked()),
Chris@180 236 this, SLOT(tempDirButtonClicked()));
Chris@180 237 tempDirButton->setFixedSize(QSize(24, 24));
Chris@180 238
Chris@237 239 QCheckBox *showSplash = new QCheckBox;
Chris@237 240 m_showSplash = prefs->getShowSplash();
Chris@237 241 showSplash->setCheckState(m_showSplash ? Qt::Checked : Qt::Unchecked);
Chris@237 242 connect(showSplash, SIGNAL(stateChanged(int)),
Chris@237 243 this, SLOT(showSplashChanged(int)));
Chris@237 244
Chris@1092 245 #ifdef NOT_DEFINED // This no longer works correctly on any platform AFAICS
Chris@180 246 QComboBox *bgMode = new QComboBox;
Chris@180 247 int bg = prefs->getPropertyRangeAndValue("Background Mode", &min, &max,
Chris@180 248 &deflt);
Chris@180 249 m_backgroundMode = bg;
Chris@180 250 for (i = min; i <= max; ++i) {
Chris@180 251 bgMode->addItem(prefs->getPropertyValueLabel("Background Mode", i));
Chris@180 252 }
Chris@180 253 bgMode->setCurrentIndex(bg);
Chris@180 254
Chris@180 255 connect(bgMode, SIGNAL(currentIndexChanged(int)),
Chris@180 256 this, SLOT(backgroundModeChanged(int)));
Chris@237 257 #endif
Chris@180 258
Chris@658 259 settings.beginGroup("Preferences");
Chris@686 260
Chris@950 261 #ifdef Q_OS_MAC
Chris@950 262 m_retina = settings.value("scaledHiDpi", true).toBool();
Chris@950 263 QCheckBox *retina = new QCheckBox;
Chris@950 264 retina->setCheckState(m_retina ? Qt::Checked : Qt::Unchecked);
Chris@950 265 connect(retina, SIGNAL(stateChanged(int)), this, SLOT(retinaChanged(int)));
Chris@950 266 #else
Chris@950 267 m_retina = false;
Chris@950 268 #endif
Chris@950 269
Chris@658 270 QString userLocale = settings.value("locale", "").toString();
Chris@658 271 m_currentLocale = userLocale;
Chris@686 272
Chris@686 273 QString permishTag = QString("network-permission-%1").arg(SV_VERSION);
Chris@686 274 m_networkPermission = settings.value(permishTag, false).toBool();
Chris@686 275
Chris@658 276 settings.endGroup();
Chris@658 277
Chris@658 278 QComboBox *locale = new QComboBox;
Chris@658 279 QStringList localeFiles = QDir(":i18n").entryList(QStringList() << "*.qm");
Chris@658 280 locale->addItem(tr("Follow system locale"));
Chris@658 281 m_locales.push_back("");
Chris@658 282 if (userLocale == "") {
Chris@658 283 locale->setCurrentIndex(0);
Chris@658 284 }
Chris@658 285 foreach (QString f, localeFiles) {
Chris@658 286 QString f0 = f;
Chris@658 287 f.replace("sonic-visualiser_", "").replace(".qm", "");
Chris@658 288 if (f == f0) { // our expectations about filename format were not met
Chris@665 289 cerr << "INFO: Unexpected filename " << f << " in i18n resource directory" << endl;
Chris@658 290 } else {
Chris@658 291 m_locales.push_back(f);
Chris@658 292 QString displayText;
Chris@658 293 // Add new translations here
Chris@658 294 if (f == "ru") displayText = tr("Russian");
Chris@658 295 else if (f == "en_GB") displayText = tr("British English");
Chris@658 296 else if (f == "en_US") displayText = tr("American English");
Chris@658 297 else if (f == "cs_CZ") displayText = tr("Czech");
Chris@658 298 else displayText = f;
Chris@658 299 locale->addItem(QString("%1 [%2]").arg(displayText).arg(f));
Chris@658 300 if (userLocale == f) {
Chris@658 301 locale->setCurrentIndex(locale->count() - 1);
Chris@658 302 }
Chris@658 303 }
Chris@658 304 }
Chris@658 305 connect(locale, SIGNAL(currentIndexChanged(int)),
Chris@658 306 this, SLOT(localeChanged(int)));
Chris@658 307
Chris@686 308 QCheckBox *networkPermish = new QCheckBox;
Chris@686 309 networkPermish->setCheckState(m_networkPermission ? Qt::Checked : Qt::Unchecked);
Chris@686 310 connect(networkPermish, SIGNAL(stateChanged(int)),
Chris@686 311 this, SLOT(networkPermissionChanged(int)));
Chris@686 312
Chris@225 313 QSpinBox *fontSize = new QSpinBox;
Chris@225 314 int fs = prefs->getPropertyRangeAndValue("View Font Size", &min, &max,
Chris@225 315 &deflt);
Chris@234 316 m_viewFontSize = fs;
Chris@225 317 fontSize->setMinimum(min);
Chris@225 318 fontSize->setMaximum(max);
Chris@225 319 fontSize->setSuffix(" pt");
Chris@225 320 fontSize->setSingleStep(1);
Chris@225 321 fontSize->setValue(fs);
Chris@225 322
Chris@225 323 connect(fontSize, SIGNAL(valueChanged(int)),
Chris@225 324 this, SLOT(viewFontSizeChanged(int)));
Chris@225 325
Chris@337 326 QComboBox *ttMode = new QComboBox;
Chris@337 327 int tt = prefs->getPropertyRangeAndValue("Time To Text Mode", &min, &max,
Chris@337 328 &deflt);
Chris@337 329 m_timeToTextMode = tt;
Chris@337 330 for (i = min; i <= max; ++i) {
Chris@337 331 ttMode->addItem(prefs->getPropertyValueLabel("Time To Text Mode", i));
Chris@337 332 }
Chris@337 333 ttMode->setCurrentIndex(tt);
Chris@337 334
Chris@337 335 connect(ttMode, SIGNAL(currentIndexChanged(int)),
Chris@337 336 this, SLOT(timeToTextModeChanged(int)));
Chris@337 337
Chris@906 338 QCheckBox *hms = new QCheckBox;
Chris@906 339 int showHMS = prefs->getPropertyRangeAndValue
Chris@906 340 ("Show Hours And Minutes", &min, &max, &deflt);
Chris@906 341 m_showHMS = (showHMS != 0);
Chris@906 342 hms->setCheckState(m_showHMS ? Qt::Checked : Qt::Unchecked);
Chris@906 343 connect(hms, SIGNAL(stateChanged(int)),
Chris@906 344 this, SLOT(showHMSChanged(int)));
Chris@906 345
Chris@180 346 // General tab
Chris@180 347
Chris@180 348 QFrame *frame = new QFrame;
Chris@180 349
Chris@180 350 QGridLayout *subgrid = new QGridLayout;
Chris@180 351 frame->setLayout(subgrid);
Chris@180 352
Chris@0 353 int row = 0;
Chris@0 354
Chris@658 355 subgrid->addWidget(new QLabel(tr("%1:").arg(tr("User interface language"))),
Chris@658 356 row, 0);
Chris@658 357 subgrid->addWidget(locale, row++, 1, 1, 1);
Chris@658 358
Chris@686 359 subgrid->addWidget(new QLabel(tr("%1:").arg(tr("Allow network usage"))),
Chris@686 360 row, 0);
Chris@686 361 subgrid->addWidget(networkPermish, row++, 1, 1, 1);
Chris@686 362
Chris@0 363 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 364 ("Temporary Directory Root"))),
Chris@263 365 row, 0);
Chris@263 366 subgrid->addWidget(m_tempDirRootEdit, row, 1, 1, 1);
Chris@263 367 subgrid->addWidget(tempDirButton, row, 2, 1, 1);
Chris@263 368 row++;
Chris@263 369
Chris@263 370 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 371 ("Resample On Load"))),
Chris@263 372 row, 0);
Chris@263 373 subgrid->addWidget(resampleOnLoad, row++, 1, 1, 1);
Chris@263 374
Chris@1035 375 //!!! subgrid->addWidget(new QLabel(tr("Playback audio device:")), row, 0);
Chris@1035 376 //!!! subgrid->addWidget(audioDevice, row++, 1, 1, 2);
Chris@263 377
Chris@263 378 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@263 379 ("Resample Quality"))),
Chris@263 380 row, 0);
Chris@263 381 subgrid->addWidget(resampleQuality, row++, 1, 1, 2);
Chris@263 382
Chris@263 383 subgrid->setRowStretch(row, 10);
Chris@263 384
Chris@436 385 m_tabOrdering[GeneralTab] = m_tabs->count();
Chris@436 386 m_tabs->addTab(frame, tr("&General"));
Chris@263 387
Chris@263 388 // Appearance tab
Chris@263 389
Chris@263 390 frame = new QFrame;
Chris@263 391 subgrid = new QGridLayout;
Chris@263 392 frame->setLayout(subgrid);
Chris@263 393 row = 0;
Chris@263 394
Chris@263 395 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@906 396 ("Show Splash Screen"))),
Chris@906 397 row, 0);
Chris@906 398 subgrid->addWidget(showSplash, row++, 1, 1, 1);
Chris@906 399
Chris@950 400 #ifdef Q_OS_MAC
Chris@950 401 if (devicePixelRatio() > 1) {
Chris@950 402 subgrid->addWidget(new QLabel(tr("Draw layers at Retina resolution:")), row, 0);
Chris@950 403 subgrid->addWidget(retina, row++, 1, 1, 1);
Chris@950 404 }
Chris@950 405 #endif
Chris@950 406
Chris@906 407 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 408 ("Property Box Layout"))),
Chris@0 409 row, 0);
Chris@0 410 subgrid->addWidget(propertyLayout, row++, 1, 1, 2);
Chris@0 411
Chris@1098 412 subgrid->addWidget(new QLabel(tr("Default spectrogram colour:")),
Chris@1096 413 row, 0);
Chris@1096 414 subgrid->addWidget(spectrogramGColour, row++, 1, 1, 2);
Chris@1096 415
Chris@1098 416 subgrid->addWidget(new QLabel(tr("Default melodic spectrogram colour:")),
Chris@1096 417 row, 0);
Chris@1096 418 subgrid->addWidget(spectrogramMColour, row++, 1, 1, 2);
Chris@1096 419
Chris@1098 420 subgrid->addWidget(new QLabel(tr("Default colour 3D plot colour:")),
Chris@1097 421 row, 0);
Chris@1097 422 subgrid->addWidget(colour3DColour, row++, 1, 1, 2);
Chris@1097 423
Chris@1092 424 #ifdef NOT_DEFINED // see earlier
Chris@0 425 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@180 426 ("Background Mode"))),
Chris@0 427 row, 0);
Chris@180 428 subgrid->addWidget(bgMode, row++, 1, 1, 2);
Chris@242 429 #endif
Chris@180 430
Chris@180 431 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@225 432 ("View Font Size"))),
Chris@225 433 row, 0);
Chris@225 434 subgrid->addWidget(fontSize, row++, 1, 1, 2);
Chris@225 435
Chris@225 436 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@337 437 ("Time To Text Mode"))),
Chris@337 438 row, 0);
Chris@337 439 subgrid->addWidget(ttMode, row++, 1, 1, 2);
Chris@337 440
Chris@337 441 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@906 442 ("Show Hours And Minutes"))),
Chris@237 443 row, 0);
Chris@906 444 subgrid->addWidget(hms, row++, 1, 1, 1);
Chris@237 445
Chris@180 446 subgrid->setRowStretch(row, 10);
Chris@180 447
Chris@436 448 m_tabOrdering[AppearanceTab] = m_tabs->count();
Chris@436 449 m_tabs->addTab(frame, tr("&Appearance"));
Chris@180 450
Chris@180 451 // Analysis tab
Chris@180 452
Chris@180 453 frame = new QFrame;
Chris@180 454 subgrid = new QGridLayout;
Chris@180 455 frame->setLayout(subgrid);
Chris@180 456 row = 0;
Chris@180 457
Chris@180 458 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@180 459 ("Tuning Frequency"))),
Chris@180 460 row, 0);
Chris@180 461 subgrid->addWidget(frequency, row++, 1, 1, 2);
Chris@180 462
Chris@702 463 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@702 464 ("Octave Numbering System"))),
Chris@702 465 row, 0);
Chris@702 466 subgrid->addWidget(octaveSystem, row++, 1, 1, 2);
Chris@702 467
Chris@0 468 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
Chris@299 469 ("Spectrogram Y Smoothing")),
Chris@115 470 row, 0);
Chris@115 471 subgrid->addWidget(smoothing, row++, 1, 1, 2);
Chris@0 472
Chris@299 473 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
Chris@299 474 ("Spectrogram X Smoothing")),
Chris@299 475 row, 0);
Chris@299 476 subgrid->addWidget(xsmoothing, row++, 1, 1, 2);
Chris@299 477
Chris@0 478 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 479 ("Window Type"))),
Chris@0 480 row, 0);
Chris@9 481 subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2);
Chris@1275 482
Chris@9 483 subgrid->setRowStretch(row, 10);
Chris@9 484 row++;
Chris@1275 485
Chris@1275 486 subgrid->addWidget(new QLabel(tr("Run Vamp plugins in separate process:")),
Chris@1275 487 row, 0);
Chris@1275 488 subgrid->addWidget(vampProcessSeparation, row++, 1, 1, 1);
Chris@0 489
Chris@180 490 subgrid->setRowStretch(row, 10);
Chris@180 491
Chris@436 492 m_tabOrdering[AnalysisTab] = m_tabs->count();
Chris@436 493 m_tabs->addTab(frame, tr("Anal&ysis"));
Chris@436 494
Chris@436 495 // Template tab
Chris@436 496
Chris@436 497 frame = new QFrame;
Chris@436 498 subgrid = new QGridLayout;
Chris@436 499 frame->setLayout(subgrid);
Chris@436 500 row = 0;
Chris@436 501
Chris@436 502 subgrid->addWidget(new QLabel(tr("Default session template for audio files:")), row++, 0);
Chris@436 503
Chris@436 504 QListWidget *lw = new QListWidget();
Chris@436 505 subgrid->addWidget(lw, row, 0);
Chris@436 506 subgrid->setRowStretch(row, 10);
Chris@436 507 row++;
Chris@436 508
Chris@436 509 settings.beginGroup("MainWindow");
Chris@436 510 m_currentTemplate = settings.value("sessiontemplate", "").toString();
Chris@436 511 settings.endGroup();
Chris@436 512
Chris@455 513 lw->addItem(tr("Standard Waveform"));
Chris@436 514 if (m_currentTemplate == "" || m_currentTemplate == "default") {
Chris@436 515 lw->setCurrentRow(lw->count()-1);
Chris@436 516 }
Chris@436 517 m_templates.push_back("");
Chris@436 518
Chris@436 519 QStringList templates = ResourceFinder().getResourceFiles("templates", "svt");
Chris@436 520
Chris@436 521 std::set<QString> byName;
Chris@436 522 foreach (QString t, templates) {
Chris@436 523 byName.insert(QFileInfo(t).baseName());
Chris@436 524 }
Chris@436 525
Chris@436 526 foreach (QString t, byName) {
Chris@436 527 if (t.toLower() == "default") continue;
Chris@436 528 m_templates.push_back(t);
Chris@436 529 lw->addItem(t);
Chris@436 530 if (m_currentTemplate == t) {
Chris@436 531 lw->setCurrentRow(lw->count()-1);
Chris@436 532 }
Chris@436 533 }
Chris@436 534
Chris@436 535 connect(lw, SIGNAL(currentRowChanged(int)), this, SLOT(defaultTemplateChanged(int)));
Chris@436 536
Chris@436 537 m_tabOrdering[TemplateTab] = m_tabs->count();
Chris@436 538 m_tabs->addTab(frame, tr("Session &Template"));
Chris@180 539
Chris@163 540 QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal);
Chris@163 541 grid->addWidget(bb, 1, 0);
Chris@0 542
Chris@0 543 QPushButton *ok = new QPushButton(tr("OK"));
Chris@0 544 QPushButton *cancel = new QPushButton(tr("Cancel"));
Chris@163 545 bb->addButton(ok, QDialogButtonBox::AcceptRole);
Chris@163 546 bb->addButton(m_applyButton, QDialogButtonBox::ApplyRole);
Chris@163 547 bb->addButton(cancel, QDialogButtonBox::RejectRole);
Chris@0 548 connect(ok, SIGNAL(clicked()), this, SLOT(okClicked()));
Chris@0 549 connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked()));
Chris@0 550 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
Chris@0 551
Chris@0 552 m_applyButton->setEnabled(false);
Chris@0 553 }
Chris@0 554
Chris@0 555 PreferencesDialog::~PreferencesDialog()
Chris@0 556 {
Chris@438 557 SVDEBUG << "PreferencesDialog::~PreferencesDialog()" << endl;
Chris@0 558 }
Chris@0 559
Chris@0 560 void
Chris@436 561 PreferencesDialog::switchToTab(Tab t)
Chris@436 562 {
Chris@436 563 if (m_tabOrdering.contains(t)) {
Chris@436 564 m_tabs->setCurrentIndex(m_tabOrdering[t]);
Chris@436 565 }
Chris@436 566 }
Chris@436 567
Chris@436 568 void
Chris@9 569 PreferencesDialog::windowTypeChanged(WindowType type)
Chris@0 570 {
Chris@0 571 m_windowType = type;
Chris@0 572 m_applyButton->setEnabled(true);
Chris@0 573 }
Chris@0 574
Chris@0 575 void
Chris@115 576 PreferencesDialog::spectrogramSmoothingChanged(int smoothing)
Chris@0 577 {
Chris@115 578 m_spectrogramSmoothing = smoothing;
Chris@0 579 m_applyButton->setEnabled(true);
Chris@0 580 }
Chris@0 581
Chris@0 582 void
Chris@299 583 PreferencesDialog::spectrogramXSmoothingChanged(int smoothing)
Chris@299 584 {
Chris@299 585 m_spectrogramXSmoothing = smoothing;
Chris@299 586 m_applyButton->setEnabled(true);
Chris@299 587 }
Chris@299 588
Chris@299 589 void
Chris@1096 590 PreferencesDialog::spectrogramGColourChanged(int colour)
Chris@1096 591 {
Chris@1096 592 m_spectrogramGColour = colour;
Chris@1096 593 m_applyButton->setEnabled(true);
Chris@1096 594 }
Chris@1096 595
Chris@1096 596 void
Chris@1096 597 PreferencesDialog::spectrogramMColourChanged(int colour)
Chris@1096 598 {
Chris@1096 599 m_spectrogramMColour = colour;
Chris@1096 600 m_applyButton->setEnabled(true);
Chris@1096 601 }
Chris@1096 602
Chris@1096 603 void
Chris@1097 604 PreferencesDialog::colour3DColourChanged(int colour)
Chris@1097 605 {
Chris@1097 606 m_colour3DColour = colour;
Chris@1097 607 m_applyButton->setEnabled(true);
Chris@1097 608 }
Chris@1097 609
Chris@1097 610 void
Chris@0 611 PreferencesDialog::propertyLayoutChanged(int layout)
Chris@0 612 {
Chris@0 613 m_propertyLayout = layout;
Chris@0 614 m_applyButton->setEnabled(true);
Chris@0 615 }
Chris@0 616
Chris@0 617 void
Chris@0 618 PreferencesDialog::tuningFrequencyChanged(double freq)
Chris@0 619 {
Chris@0 620 m_tuningFrequency = freq;
Chris@0 621 m_applyButton->setEnabled(true);
Chris@0 622 }
Chris@0 623
Chris@0 624 void
Chris@263 625 PreferencesDialog::audioDeviceChanged(int s)
Chris@263 626 {
Chris@263 627 m_audioDevice = s;
Chris@263 628 m_applyButton->setEnabled(true);
Chris@263 629 m_changesOnRestart = true;
Chris@263 630 }
Chris@263 631
Chris@263 632 void
Chris@32 633 PreferencesDialog::resampleQualityChanged(int q)
Chris@32 634 {
Chris@32 635 m_resampleQuality = q;
Chris@32 636 m_applyButton->setEnabled(true);
Chris@32 637 }
Chris@32 638
Chris@32 639 void
Chris@180 640 PreferencesDialog::resampleOnLoadChanged(int state)
Chris@180 641 {
Chris@180 642 m_resampleOnLoad = (state == Qt::Checked);
Chris@180 643 m_applyButton->setEnabled(true);
Chris@180 644 m_changesOnRestart = true;
Chris@180 645 }
Chris@180 646
Chris@180 647 void
Chris@1275 648 PreferencesDialog::vampProcessSeparationChanged(int state)
Chris@1275 649 {
Chris@1275 650 m_runPluginsInProcess = (state == Qt::Unchecked);
Chris@1275 651 m_applyButton->setEnabled(true);
Chris@1275 652 m_changesOnRestart = true;
Chris@1275 653 }
Chris@1275 654
Chris@1275 655 void
Chris@686 656 PreferencesDialog::networkPermissionChanged(int state)
Chris@686 657 {
Chris@686 658 m_networkPermission = (state == Qt::Checked);
Chris@686 659 m_applyButton->setEnabled(true);
Chris@686 660 m_changesOnRestart = true;
Chris@686 661 }
Chris@686 662
Chris@686 663 void
Chris@950 664 PreferencesDialog::retinaChanged(int state)
Chris@950 665 {
Chris@950 666 m_retina = (state == Qt::Checked);
Chris@950 667 m_applyButton->setEnabled(true);
Chris@950 668 // Does not require a restart
Chris@950 669 }
Chris@950 670
Chris@950 671 void
Chris@237 672 PreferencesDialog::showSplashChanged(int state)
Chris@237 673 {
Chris@237 674 m_showSplash = (state == Qt::Checked);
Chris@237 675 m_applyButton->setEnabled(true);
Chris@237 676 m_changesOnRestart = true;
Chris@237 677 }
Chris@237 678
Chris@237 679 void
Chris@436 680 PreferencesDialog::defaultTemplateChanged(int i)
Chris@436 681 {
Chris@436 682 m_currentTemplate = m_templates[i];
Chris@436 683 m_applyButton->setEnabled(true);
Chris@436 684 }
Chris@436 685
Chris@436 686 void
Chris@658 687 PreferencesDialog::localeChanged(int i)
Chris@658 688 {
Chris@658 689 m_currentLocale = m_locales[i];
Chris@658 690 m_applyButton->setEnabled(true);
Chris@658 691 m_changesOnRestart = true;
Chris@658 692 }
Chris@658 693
Chris@658 694 void
Chris@180 695 PreferencesDialog::tempDirRootChanged(QString r)
Chris@180 696 {
Chris@180 697 m_tempDirRoot = r;
Chris@180 698 m_applyButton->setEnabled(true);
Chris@180 699 }
Chris@180 700
Chris@180 701 void
Chris@180 702 PreferencesDialog::tempDirButtonClicked()
Chris@180 703 {
Chris@180 704 QString dir = QFileDialog::getExistingDirectory
Chris@180 705 (this, tr("Select a directory to create cache subdirectory in"),
Chris@180 706 m_tempDirRoot);
Chris@180 707 if (dir == "") return;
Chris@180 708 m_tempDirRootEdit->setText(dir);
Chris@180 709 tempDirRootChanged(dir);
Chris@180 710 m_changesOnRestart = true;
Chris@180 711 }
Chris@180 712
Chris@180 713 void
Chris@180 714 PreferencesDialog::backgroundModeChanged(int mode)
Chris@180 715 {
Chris@180 716 m_backgroundMode = mode;
Chris@180 717 m_applyButton->setEnabled(true);
Chris@180 718 m_changesOnRestart = true;
Chris@180 719 }
Chris@180 720
Chris@180 721 void
Chris@337 722 PreferencesDialog::timeToTextModeChanged(int mode)
Chris@337 723 {
Chris@337 724 m_timeToTextMode = mode;
Chris@337 725 m_applyButton->setEnabled(true);
Chris@337 726 }
Chris@337 727
Chris@337 728 void
Chris@906 729 PreferencesDialog::showHMSChanged(int state)
Chris@906 730 {
Chris@906 731 m_showHMS = (state == Qt::Checked);
Chris@906 732 m_applyButton->setEnabled(true);
Chris@906 733 }
Chris@906 734
Chris@906 735 void
Chris@702 736 PreferencesDialog::octaveSystemChanged(int system)
Chris@702 737 {
Chris@702 738 m_octaveSystem = system;
Chris@702 739 m_applyButton->setEnabled(true);
Chris@702 740 }
Chris@702 741
Chris@702 742 void
Chris@225 743 PreferencesDialog::viewFontSizeChanged(int sz)
Chris@225 744 {
Chris@225 745 m_viewFontSize = sz;
Chris@225 746 m_applyButton->setEnabled(true);
Chris@225 747 }
Chris@225 748
Chris@225 749 void
Chris@0 750 PreferencesDialog::okClicked()
Chris@0 751 {
Chris@0 752 applyClicked();
Chris@0 753 accept();
Chris@0 754 }
Chris@0 755
Chris@0 756 void
Chris@0 757 PreferencesDialog::applyClicked()
Chris@0 758 {
Chris@0 759 Preferences *prefs = Preferences::getInstance();
Chris@0 760 prefs->setWindowType(WindowType(m_windowType));
Chris@115 761 prefs->setSpectrogramSmoothing(Preferences::SpectrogramSmoothing
Chris@115 762 (m_spectrogramSmoothing));
Chris@299 763 prefs->setSpectrogramXSmoothing(Preferences::SpectrogramXSmoothing
Chris@299 764 (m_spectrogramXSmoothing));
Chris@0 765 prefs->setPropertyBoxLayout(Preferences::PropertyBoxLayout
Chris@0 766 (m_propertyLayout));
Chris@0 767 prefs->setTuningFrequency(m_tuningFrequency);
Chris@32 768 prefs->setResampleQuality(m_resampleQuality);
Chris@180 769 prefs->setResampleOnLoad(m_resampleOnLoad);
Chris@1276 770 prefs->setRunPluginsInProcess(m_runPluginsInProcess);
Chris@237 771 prefs->setShowSplash(m_showSplash);
Chris@180 772 prefs->setTemporaryDirectoryRoot(m_tempDirRoot);
Chris@180 773 prefs->setBackgroundMode(Preferences::BackgroundMode(m_backgroundMode));
Chris@337 774 prefs->setTimeToTextMode(Preferences::TimeToTextMode(m_timeToTextMode));
Chris@906 775 prefs->setShowHMS(m_showHMS);
Chris@225 776 prefs->setViewFontSize(m_viewFontSize);
Chris@263 777
Chris@702 778 prefs->setProperty("Octave Numbering System", m_octaveSystem);
Chris@702 779
Chris@1035 780 //!!! std::vector<QString> devices =
Chris@1035 781 //!!! AudioTargetFactory::getInstance()->getCallbackTargetNames();
Chris@263 782
Chris@263 783 QSettings settings;
Chris@263 784 settings.beginGroup("Preferences");
Chris@686 785 QString permishTag = QString("network-permission-%1").arg(SV_VERSION);
Chris@686 786 settings.setValue(permishTag, m_networkPermission);
Chris@1035 787 //!!! settings.setValue("audio-target", devices[m_audioDevice]);
Chris@686 788 settings.setValue("locale", m_currentLocale);
Chris@950 789 #ifdef Q_OS_MAC
Chris@950 790 settings.setValue("scaledHiDpi", m_retina);
Chris@950 791 #endif
Chris@1096 792 settings.setValue("spectrogram-colour", m_spectrogramGColour);
Chris@1096 793 settings.setValue("spectrogram-melodic-colour", m_spectrogramMColour);
Chris@1097 794 settings.setValue("colour-3d-plot-colour", m_colour3DColour);
Chris@263 795 settings.endGroup();
Chris@180 796
Chris@436 797 settings.beginGroup("MainWindow");
Chris@436 798 settings.setValue("sessiontemplate", m_currentTemplate);
Chris@436 799 settings.endGroup();
Chris@436 800
Chris@0 801 m_applyButton->setEnabled(false);
Chris@180 802
Chris@180 803 if (m_changesOnRestart) {
Chris@180 804 QMessageBox::information(this, tr("Preferences"),
Chris@255 805 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>"));
Chris@180 806 m_changesOnRestart = false;
Chris@180 807 }
Chris@0 808 }
Chris@0 809
Chris@0 810 void
Chris@0 811 PreferencesDialog::cancelClicked()
Chris@0 812 {
Chris@0 813 reject();
Chris@0 814 }
Chris@0 815
Chris@163 816 void
Chris@163 817 PreferencesDialog::applicationClosing(bool quickly)
Chris@163 818 {
Chris@163 819 if (quickly) {
Chris@163 820 reject();
Chris@163 821 return;
Chris@163 822 }
Chris@163 823
Chris@163 824 if (m_applyButton->isEnabled()) {
Chris@163 825 int rv = QMessageBox::warning
Chris@163 826 (this, tr("Preferences Changed"),
Chris@163 827 tr("Some preferences have been changed but not applied.\n"
Chris@163 828 "Apply them before closing?"),
Chris@163 829 QMessageBox::Apply | QMessageBox::Discard,
Chris@163 830 QMessageBox::Discard);
Chris@163 831 if (rv == QMessageBox::Apply) {
Chris@163 832 applyClicked();
Chris@163 833 accept();
Chris@163 834 } else {
Chris@163 835 reject();
Chris@163 836 }
Chris@163 837 } else {
Chris@163 838 accept();
Chris@163 839 }
Chris@163 840 }
Chris@163 841