PreferencesDialog.cpp
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #include "PreferencesDialog.h"
17 
18 #include <QGridLayout>
19 #include <QComboBox>
20 #include <QCheckBox>
21 #include <QGroupBox>
22 #include <QDoubleSpinBox>
23 #include <QLabel>
24 #include <QPushButton>
25 #include <QHBoxLayout>
26 #include <QString>
27 #include <QDialogButtonBox>
28 #include <QMessageBox>
29 #include <QTabWidget>
30 #include <QLineEdit>
31 #include <QFileDialog>
32 #include <QSpinBox>
33 #include <QListWidget>
34 #include <QSettings>
35 
36 #include <set>
37 
38 #include "widgets/WindowTypeSelector.h"
39 #include "widgets/IconLoader.h"
40 #include "widgets/ColourMapComboBox.h"
41 #include "widgets/ColourComboBox.h"
42 #include "widgets/PluginPathConfigurator.h"
43 #include "widgets/WidgetScale.h"
44 #include "base/Preferences.h"
45 #include "base/ResourceFinder.h"
46 #include "layer/ColourMapper.h"
47 #include "layer/ColourDatabase.h"
48 
49 #include "bqaudioio/AudioFactory.h"
50 
51 #include "../version.h"
52 
53 using namespace std;
54 
56  QDialog(parent),
57  m_audioImplementation(0),
58  m_audioPlaybackDevice(0),
59  m_audioRecordDevice(0),
60  m_audioDeviceChanged(false),
61  m_coloursChanged(false),
62  m_changesOnRestart(false)
63 {
64  setWindowTitle(tr("Sonic Visualiser: Application Preferences"));
65 
66  Preferences *prefs = Preferences::getInstance();
67 
68  QGridLayout *grid = new QGridLayout;
69  setLayout(grid);
70 
71  m_tabs = new QTabWidget;
72  grid->addWidget(m_tabs, 0, 0);
73 
74  m_tabs->setTabPosition(QTabWidget::North);
75 
76  // Create this first, as slots that get called from the ctor will
77  // refer to it
78  m_applyButton = new QPushButton(tr("Apply"));
79 
80  // Create all the preference widgets first, then create the
81  // individual tab widgets and place the preferences in their
82  // appropriate places in one go afterwards
83 
84  int min, max, deflt, i;
85 
86  m_windowType = WindowType(prefs->getPropertyRangeAndValue
87  ("Window Type", &min, &max, &deflt));
88  m_windowTypeSelector = new WindowTypeSelector(m_windowType);
89 
90  connect(m_windowTypeSelector, SIGNAL(windowTypeChanged(WindowType)),
91  this, SLOT(windowTypeChanged(WindowType)));
92 
93  QCheckBox *vampProcessSeparation = new QCheckBox;
94  m_runPluginsInProcess = prefs->getRunPluginsInProcess();
95  vampProcessSeparation->setCheckState(m_runPluginsInProcess ? Qt::Unchecked :
96  Qt::Checked);
97  connect(vampProcessSeparation, SIGNAL(stateChanged(int)),
98  this, SLOT(vampProcessSeparationChanged(int)));
99 
100  QComboBox *smoothing = new QComboBox;
101 
102  int sm = prefs->getPropertyRangeAndValue("Spectrogram Y Smoothing", &min, &max,
103  &deflt);
105 
106  for (i = min; i <= max; ++i) {
107  smoothing->addItem(prefs->getPropertyValueLabel("Spectrogram Y Smoothing", i));
108  }
109 
110  smoothing->setCurrentIndex(sm);
111 
112  connect(smoothing, SIGNAL(currentIndexChanged(int)),
113  this, SLOT(spectrogramSmoothingChanged(int)));
114 
115  QComboBox *xsmoothing = new QComboBox;
116 
117  int xsm = prefs->getPropertyRangeAndValue("Spectrogram X Smoothing", &min, &max,
118  &deflt);
120 
121  for (i = min; i <= max; ++i) {
122  xsmoothing->addItem(prefs->getPropertyValueLabel("Spectrogram X Smoothing", i));
123  }
124 
125  xsmoothing->setCurrentIndex(xsm);
126 
127  connect(xsmoothing, SIGNAL(currentIndexChanged(int)),
128  this, SLOT(spectrogramXSmoothingChanged(int)));
129 
130  QComboBox *propertyLayout = new QComboBox;
131  int pl = prefs->getPropertyRangeAndValue("Property Box Layout", &min, &max,
132  &deflt);
133  m_propertyLayout = pl;
134 
135  for (i = min; i <= max; ++i) {
136  propertyLayout->addItem(prefs->getPropertyValueLabel("Property Box Layout", i));
137  }
138 
139  propertyLayout->setCurrentIndex(pl);
140 
141  connect(propertyLayout, SIGNAL(currentIndexChanged(int)),
142  this, SLOT(propertyLayoutChanged(int)));
143 
144  QSettings settings;
145  settings.beginGroup("Preferences");
146  m_spectrogramGColour = (settings.value("spectrogram-colour",
147  int(ColourMapper::Green)).toInt());
148  m_spectrogramMColour = (settings.value("spectrogram-melodic-colour",
149  int(ColourMapper::Sunset)).toInt());
150  m_colour3DColour = (settings.value("colour-3d-plot-colour",
151  int(ColourMapper::Green)).toInt());
152  m_overviewColourIsSet = false;
153  m_overviewColour = ColourDatabase::getInstance()->getColour(tr("Green"));
154  if (settings.contains("overview-colour")) {
155  QString qcolorName =
156  settings.value("overview-colour", m_overviewColour.name())
157  .toString();
158  m_overviewColour.setNamedColor(qcolorName);
159  m_overviewColourIsSet = true;
160  SVCERR << "loaded colour " << m_overviewColour.name() << " from settings" << endl;
161  }
162  settings.endGroup();
163 
164  ColourMapComboBox *spectrogramGColour = new ColourMapComboBox(true);
165  spectrogramGColour->setCurrentIndex(m_spectrogramGColour);
166 
167  ColourMapComboBox *spectrogramMColour = new ColourMapComboBox(true);
168  spectrogramMColour->setCurrentIndex(m_spectrogramMColour);
169 
170  ColourMapComboBox *colour3DColour = new ColourMapComboBox(true);
171  colour3DColour->setCurrentIndex(m_colour3DColour);
172 
173  // can't have "add new colour", as it gets saved in the session not in prefs
174  m_overviewColourCombo = new ColourComboBox(false);
175  m_overviewColourCombo->includeUnsetEntry(tr("Follow desktop theme"));
176  if (m_overviewColourIsSet) {
177  int overviewColourIndex =
178  ColourDatabase::getInstance()->getColourIndex(m_overviewColour);
179  if (overviewColourIndex >= 0) {
180  m_overviewColourCombo->setCurrentIndex(overviewColourIndex + 1);
181  }
182  } else {
183  m_overviewColourCombo->setCurrentIndex(0);
184  }
185 
186  connect(spectrogramGColour, SIGNAL(colourMapChanged(int)),
187  this, SLOT(spectrogramGColourChanged(int)));
188  connect(spectrogramMColour, SIGNAL(colourMapChanged(int)),
189  this, SLOT(spectrogramMColourChanged(int)));
190  connect(colour3DColour, SIGNAL(colourMapChanged(int)),
191  this, SLOT(colour3DColourChanged(int)));
192  connect(m_overviewColourCombo, SIGNAL(colourChanged(int)),
193  this, SLOT(overviewColourChanged(int)));
194 
195  m_tuningFrequency = prefs->getTuningFrequency();
196 
197  QDoubleSpinBox *frequency = new QDoubleSpinBox;
198  frequency->setMinimum(100.0);
199  frequency->setMaximum(5000.0);
200  frequency->setSuffix(" Hz");
201  frequency->setSingleStep(1);
202  frequency->setValue(m_tuningFrequency);
203  frequency->setDecimals(2);
204 
205  connect(frequency, SIGNAL(valueChanged(double)),
206  this, SLOT(tuningFrequencyChanged(double)));
207 
208  QComboBox *octaveSystem = new QComboBox;
209  int oct = prefs->getPropertyRangeAndValue
210  ("Octave Numbering System", &min, &max, &deflt);
211  m_octaveSystem = oct;
212  for (i = min; i <= max; ++i) {
213  octaveSystem->addItem(prefs->getPropertyValueLabel
214  ("Octave Numbering System", i));
215  }
216  octaveSystem->setCurrentIndex(oct);
217 
218  connect(octaveSystem, SIGNAL(currentIndexChanged(int)),
219  this, SLOT(octaveSystemChanged(int)));
220 
221  settings.beginGroup("Preferences");
222 
223  QComboBox *audioImplementation = new QComboBox;
224  connect(audioImplementation, SIGNAL(currentIndexChanged(int)),
225  this, SLOT(audioImplementationChanged(int)));
226 
227  m_audioPlaybackDeviceCombo = new QComboBox;
228  connect(m_audioPlaybackDeviceCombo, SIGNAL(currentIndexChanged(int)),
229  this, SLOT(audioPlaybackDeviceChanged(int)));
230 
231  m_audioRecordDeviceCombo = new QComboBox;
232  connect(m_audioRecordDeviceCombo, SIGNAL(currentIndexChanged(int)),
233  this, SLOT(audioRecordDeviceChanged(int)));
234 
235  vector<string> implementationNames =
236  breakfastquay::AudioFactory::getImplementationNames();
237 
238  QString implementationName = settings.value("audio-target", "").toString();
239  if (implementationName == "auto") implementationName = "";
240  if (implementationName == "" && implementationNames.size() == 1) {
241  // We won't be showing the implementations menu in this case
242  implementationName = implementationNames[0].c_str();
243  }
244 
245  audioImplementation->addItem(tr("(auto)"));
247 
248  for (int i = 0; in_range_for(implementationNames, i); ++i) {
249  audioImplementation->addItem
250  (breakfastquay::AudioFactory::getImplementationDescription
251  (implementationNames[i]).c_str());
252  if (implementationName.toStdString() == implementationNames[i]) {
253  audioImplementation->setCurrentIndex(i+1);
254  m_audioImplementation = i+1;
255  }
256  }
257 
258  settings.endGroup();
259 
261  m_audioDeviceChanged = false; // the rebuild will have changed this
262 
263  QCheckBox *resampleOnLoad = new QCheckBox;
264  m_resampleOnLoad = prefs->getResampleOnLoad();
265  resampleOnLoad->setCheckState(m_resampleOnLoad ? Qt::Checked :
266  Qt::Unchecked);
267  connect(resampleOnLoad, SIGNAL(stateChanged(int)),
268  this, SLOT(resampleOnLoadChanged(int)));
269 
270  QCheckBox *gaplessMode = new QCheckBox;
271  m_gapless = prefs->getUseGaplessMode();
272  gaplessMode->setCheckState(m_gapless ? Qt::Checked : Qt::Unchecked);
273  connect(gaplessMode, SIGNAL(stateChanged(int)),
274  this, SLOT(gaplessModeChanged(int)));
275 
276  m_tempDirRootEdit = new QLineEdit;
277  QString dir = prefs->getTemporaryDirectoryRoot();
278  m_tempDirRoot = dir;
279  dir.replace("$HOME", tr("<home directory>"));
280  m_tempDirRootEdit->setText(dir);
281  m_tempDirRootEdit->setReadOnly(true);
282  QPushButton *tempDirButton = new QPushButton;
283  tempDirButton->setIcon(IconLoader().load("fileopen"));
284  connect(tempDirButton, SIGNAL(clicked()),
285  this, SLOT(tempDirButtonClicked()));
286  tempDirButton->setFixedSize(WidgetScale::scaleQSize(QSize(24, 24)));
287 
288  QCheckBox *showSplash = new QCheckBox;
289  m_showSplash = prefs->getShowSplash();
290  showSplash->setCheckState(m_showSplash ? Qt::Checked : Qt::Unchecked);
291  connect(showSplash, SIGNAL(stateChanged(int)),
292  this, SLOT(showSplashChanged(int)));
293 
294 #ifndef Q_OS_MAC
295  QComboBox *bgMode = new QComboBox;
296  int bg = prefs->getPropertyRangeAndValue("Background Mode", &min, &max,
297  &deflt);
298  m_backgroundMode = bg;
299  for (i = min; i <= max; ++i) {
300  bgMode->addItem(prefs->getPropertyValueLabel("Background Mode", i));
301  }
302  bgMode->setCurrentIndex(bg);
303 
304  connect(bgMode, SIGNAL(currentIndexChanged(int)),
305  this, SLOT(backgroundModeChanged(int)));
306 #endif
307 
308  settings.beginGroup("Preferences");
309 
310 #ifdef Q_OS_MAC
311  m_retina = settings.value("scaledHiDpi", true).toBool();
312  QCheckBox *retina = new QCheckBox;
313  retina->setCheckState(m_retina ? Qt::Checked : Qt::Unchecked);
314  connect(retina, SIGNAL(stateChanged(int)), this, SLOT(retinaChanged(int)));
315 #else
316  m_retina = false;
317 #endif
318 
319  QString userLocale = settings.value("locale", "").toString();
320  m_currentLocale = userLocale;
321 
322  QString permishTag = QString("network-permission-%1").arg(SV_VERSION);
323  m_networkPermission = settings.value(permishTag, false).toBool();
324 
325  settings.endGroup();
326 
327  QComboBox *locale = new QComboBox;
328  QStringList localeFiles = QDir(":i18n").entryList(QStringList() << "*.qm");
329  locale->addItem(tr("Follow system locale"));
330  m_locales.push_back("");
331  if (userLocale == "") {
332  locale->setCurrentIndex(0);
333  }
334  foreach (QString f, localeFiles) {
335  QString f0 = f;
336  f.replace("sonic-visualiser_", "").replace(".qm", "");
337  if (f == f0) { // our expectations about filename format were not met
338  SVCERR << "INFO: Unexpected filename " << f << " in i18n resource directory" << endl;
339  } else {
340  m_locales.push_back(f);
341  QString displayText;
342  // Add new translations here
343  if (f == "ru") displayText = tr("Russian");
344  else if (f == "en_GB") displayText = tr("British English");
345  else if (f == "en_US") displayText = tr("American English");
346  else if (f == "cs_CZ") displayText = tr("Czech");
347  else displayText = f;
348  locale->addItem(QString("%1 [%2]").arg(displayText).arg(f));
349  if (userLocale == f) {
350  locale->setCurrentIndex(locale->count() - 1);
351  }
352  }
353  }
354  connect(locale, SIGNAL(currentIndexChanged(int)),
355  this, SLOT(localeChanged(int)));
356 
357  QCheckBox *networkPermish = new QCheckBox;
358  networkPermish->setCheckState(m_networkPermission ? Qt::Checked : Qt::Unchecked);
359  connect(networkPermish, SIGNAL(stateChanged(int)),
360  this, SLOT(networkPermissionChanged(int)));
361 
362  QSpinBox *fontSize = new QSpinBox;
363  int fs = prefs->getPropertyRangeAndValue("View Font Size", &min, &max,
364  &deflt);
365  m_viewFontSize = fs;
366  fontSize->setMinimum(min);
367  fontSize->setMaximum(max);
368  fontSize->setSuffix(" pt");
369  fontSize->setSingleStep(1);
370  fontSize->setValue(fs);
371 
372  connect(fontSize, SIGNAL(valueChanged(int)),
373  this, SLOT(viewFontSizeChanged(int)));
374 
375  QComboBox *ttMode = new QComboBox;
376  int tt = prefs->getPropertyRangeAndValue("Time To Text Mode", &min, &max,
377  &deflt);
378  m_timeToTextMode = tt;
379  for (i = min; i <= max; ++i) {
380  ttMode->addItem(prefs->getPropertyValueLabel("Time To Text Mode", i));
381  }
382  ttMode->setCurrentIndex(tt);
383 
384  connect(ttMode, SIGNAL(currentIndexChanged(int)),
385  this, SLOT(timeToTextModeChanged(int)));
386 
387  QCheckBox *hms = new QCheckBox;
388  int showHMS = prefs->getPropertyRangeAndValue
389  ("Show Hours And Minutes", &min, &max, &deflt);
390  m_showHMS = (showHMS != 0);
391  hms->setCheckState(m_showHMS ? Qt::Checked : Qt::Unchecked);
392  connect(hms, SIGNAL(stateChanged(int)),
393  this, SLOT(showHMSChanged(int)));
394 
395  QFrame *frame = nullptr;
396  QGridLayout *subgrid = nullptr;
397  int row = 0;
398 
399  // Appearance tab
400 
401  frame = new QFrame;
402  subgrid = new QGridLayout;
403  frame->setLayout(subgrid);
404  row = 0;
405 
406 #ifdef Q_OS_MAC
407  if (devicePixelRatio() > 1) {
408  subgrid->addWidget(new QLabel(tr("Draw layers at Retina resolution:")), row, 0);
409  subgrid->addWidget(retina, row++, 1, 1, 1);
410  }
411 #endif
412 
413 #ifndef Q_OS_MAC
414  subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
415  ("Background Mode"))),
416  row, 0);
417  subgrid->addWidget(bgMode, row++, 1, 1, 2);
418 #endif
419 
420  subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
421  ("Property Box Layout"))),
422  row, 0);
423  subgrid->addWidget(propertyLayout, row++, 1, 1, 2);
424 
425  subgrid->addWidget(new QLabel(tr("Default spectrogram colour:")),
426  row, 0);
427  subgrid->addWidget(spectrogramGColour, row++, 1, 1, 2);
428 
429  subgrid->addWidget(new QLabel(tr("Default melodic spectrogram colour:")),
430  row, 0);
431  subgrid->addWidget(spectrogramMColour, row++, 1, 1, 2);
432 
433  subgrid->addWidget(new QLabel(tr("Default colour 3D plot colour:")),
434  row, 0);
435  subgrid->addWidget(colour3DColour, row++, 1, 1, 2);
436 
437  subgrid->addWidget(new QLabel(tr("Overview waveform colour:")),
438  row, 0);
439  subgrid->addWidget(m_overviewColourCombo, row++, 1, 1, 2);
440 
441  subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
442  ("View Font Size"))),
443  row, 0);
444  subgrid->addWidget(fontSize, row++, 1, 1, 2);
445 
446  subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
447  ("Time To Text Mode"))),
448  row, 0);
449  subgrid->addWidget(ttMode, row++, 1, 1, 2);
450 
451  subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
452  ("Show Hours And Minutes"))),
453  row, 0);
454  subgrid->addWidget(hms, row++, 1, 1, 1);
455 
456  subgrid->setRowStretch(row, 10);
457 
458  m_tabOrdering[AppearanceTab] = m_tabs->count();
459  m_tabs->addTab(frame, tr("&Appearance"));
460 
461  // Analysis tab
462 
463  frame = new QFrame;
464  subgrid = new QGridLayout;
465  frame->setLayout(subgrid);
466  row = 0;
467 
468  subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
469  ("Tuning Frequency"))),
470  row, 0);
471  subgrid->addWidget(frequency, row++, 1, 1, 2);
472 
473  subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
474  ("Octave Numbering System"))),
475  row, 0);
476  subgrid->addWidget(octaveSystem, row++, 1, 1, 2);
477 
478  subgrid->addWidget(new QLabel(prefs->getPropertyLabel
479  ("Spectrogram Y Smoothing")),
480  row, 0);
481  subgrid->addWidget(smoothing, row++, 1, 1, 2);
482 
483  subgrid->addWidget(new QLabel(prefs->getPropertyLabel
484  ("Spectrogram X Smoothing")),
485  row, 0);
486  subgrid->addWidget(xsmoothing, row++, 1, 1, 2);
487 
488  subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
489  ("Window Type"))),
490  row, 0);
491  subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2);
492 
493  subgrid->setRowStretch(row, 10);
494  row++;
495 
496  subgrid->addWidget(new QLabel(tr("Run Vamp plugins in separate process:")),
497  row, 0);
498  subgrid->addWidget(vampProcessSeparation, row++, 1, 1, 1);
499 
500  subgrid->setRowStretch(row, 10);
501 
502  m_tabOrdering[AnalysisTab] = m_tabs->count();
503  m_tabs->addTab(frame, tr("Anal&ysis"));
504 
505  // Template tab
506 
507  frame = new QFrame;
508  subgrid = new QGridLayout;
509  frame->setLayout(subgrid);
510  row = 0;
511 
512  subgrid->addWidget(new QLabel(tr("Default session template when loading audio files:")), row++, 0);
513 
514  QListWidget *lw = new QListWidget();
515  subgrid->addWidget(lw, row, 0);
516  subgrid->setRowStretch(row, 10);
517  row++;
518 
519  subgrid->addWidget(new QLabel(tr("(Use \"%1\" in the File menu to add to these.)")
520  .arg(tr("Export Session as Template..."))),
521  row++, 0);
522 
523  settings.beginGroup("MainWindow");
524  m_currentTemplate = settings.value("sessiontemplate", "").toString();
525  settings.endGroup();
526 
527  lw->addItem(tr("Standard Waveform"));
528  if (m_currentTemplate == "" || m_currentTemplate == "default") {
529  lw->setCurrentRow(lw->count()-1);
530  }
531  m_templates.push_back("");
532 
533  QStringList templates = ResourceFinder().getResourceFiles("templates", "svt");
534 
535  set<QString> byName;
536  foreach (QString t, templates) {
537  byName.insert(QFileInfo(t).baseName());
538  }
539 
540  foreach (QString t, byName) {
541  if (t.toLower() == "default") continue;
542  m_templates.push_back(t);
543  lw->addItem(t);
544  if (m_currentTemplate == t) {
545  lw->setCurrentRow(lw->count()-1);
546  }
547  }
548 
549  connect(lw, SIGNAL(currentRowChanged(int)), this, SLOT(defaultTemplateChanged(int)));
550 
551  m_tabOrdering[TemplateTab] = m_tabs->count();
552  m_tabs->addTab(frame, tr("Session &Template"));
553 
554  // Audio IO tab
555 
556  frame = new QFrame;
557  subgrid = new QGridLayout;
558  frame->setLayout(subgrid);
559  row = 0;
560 
561  if (implementationNames.size() > 1) {
562  subgrid->addWidget(new QLabel(tr("Audio service:")), row, 0);
563  subgrid->addWidget(audioImplementation, row++, 1, 1, 2);
564  }
565 
566  subgrid->addWidget(new QLabel(tr("Audio playback device:")), row, 0);
567  subgrid->addWidget(m_audioPlaybackDeviceCombo, row++, 1, 1, 2);
568 
569  subgrid->addWidget(new QLabel(tr("Audio record device:")), row, 0);
570  subgrid->addWidget(m_audioRecordDeviceCombo, row++, 1, 1, 2);
571 
572  subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
573  ("Use Gapless Mode"))),
574  row, 0);
575  subgrid->addWidget(gaplessMode, row++, 1, 1, 1);
576 
577  subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
578  ("Resample On Load"))),
579  row, 0);
580  subgrid->addWidget(resampleOnLoad, row++, 1, 1, 1);
581 
582  subgrid->setRowStretch(row, 10);
583 
584  m_tabOrdering[AudioIOTab] = m_tabs->count();
585  m_tabs->addTab(frame, tr("A&udio I/O"));
586 
587  // Plugins tab
588 
589  m_pluginPathConfigurator = new PluginPathConfigurator(this);
590  m_pluginPathConfigurator->setPaths(PluginPathSetter::getPaths());
591  connect(m_pluginPathConfigurator, SIGNAL(pathsChanged()),
592  this, SLOT(pluginPathsChanged()));
593 
594  m_tabOrdering[PluginTab] = m_tabs->count();
595  m_tabs->addTab(m_pluginPathConfigurator, tr("&Plugins"));
596 
597  // General tab
598 
599  frame = new QFrame;
600  subgrid = new QGridLayout;
601  frame->setLayout(subgrid);
602  row = 0;
603 
604  subgrid->addWidget(new QLabel(tr("%1:").arg(tr("User interface language"))),
605  row, 0);
606  subgrid->addWidget(locale, row++, 1, 1, 1);
607 
608  subgrid->addWidget(new QLabel(tr("%1:").arg(tr("Allow network usage"))),
609  row, 0);
610  subgrid->addWidget(networkPermish, row++, 1, 1, 1);
611 
612  subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
613  ("Show Splash Screen"))),
614  row, 0);
615  subgrid->addWidget(showSplash, row++, 1, 1, 1);
616 
617  subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
618  ("Temporary Directory Root"))),
619  row, 0);
620  subgrid->addWidget(m_tempDirRootEdit, row, 1, 1, 1);
621  subgrid->addWidget(tempDirButton, row, 2, 1, 1);
622  row++;
623 
624  subgrid->setRowStretch(row, 10);
625 
626  m_tabOrdering[GeneralTab] = m_tabs->count();
627  m_tabs->addTab(frame, tr("&Other"));
628 
629  QDialogButtonBox *bb = new QDialogButtonBox(Qt::Horizontal);
630  grid->addWidget(bb, 1, 0);
631 
632  QPushButton *ok = new QPushButton(tr("OK"));
633  QPushButton *cancel = new QPushButton(tr("Cancel"));
634  bb->addButton(ok, QDialogButtonBox::AcceptRole);
635  bb->addButton(m_applyButton, QDialogButtonBox::ApplyRole);
636  bb->addButton(cancel, QDialogButtonBox::RejectRole);
637  connect(ok, SIGNAL(clicked()), this, SLOT(okClicked()));
638  connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked()));
639  connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
640 
641  m_applyButton->setEnabled(false);
642 }
643 
645 {
646  SVDEBUG << "PreferencesDialog::~PreferencesDialog()" << endl;
647 }
648 
649 void
651 {
652  QSettings settings;
653  settings.beginGroup("Preferences");
654 
655  vector<string> names = breakfastquay::AudioFactory::getImplementationNames();
656  string implementationName;
657 
658  if (in_range_for(names, m_audioImplementation-1)) {
659  implementationName = names[m_audioImplementation-1];
660  }
661 
662  QString suffix;
663  if (implementationName != "") {
664  suffix = "-" + QString(implementationName.c_str());
665  }
666 
667  names = breakfastquay::AudioFactory::getPlaybackDeviceNames(implementationName);
668  QString playbackDeviceName = settings.value
669  ("audio-playback-device" + suffix, "").toString();
671  m_audioPlaybackDeviceCombo->addItem(tr("(auto)"));
672  m_audioPlaybackDeviceCombo->setCurrentIndex(0);
674  for (int i = 0; in_range_for(names, i); ++i) {
675  m_audioPlaybackDeviceCombo->addItem(names[i].c_str());
676  if (playbackDeviceName.toStdString() == names[i]) {
677  m_audioPlaybackDeviceCombo->setCurrentIndex(i+1);
678  m_audioPlaybackDevice = i+1;
679  }
680  }
681 
682  names = breakfastquay::AudioFactory::getRecordDeviceNames(implementationName);
683  QString recordDeviceName = settings.value
684  ("audio-record-device" + suffix, "").toString();
685  m_audioRecordDeviceCombo->clear();
686  m_audioRecordDeviceCombo->addItem(tr("(auto)"));
687  m_audioRecordDeviceCombo->setCurrentIndex(0);
689  for (int i = 0; in_range_for(names, i); ++i) {
690  m_audioRecordDeviceCombo->addItem(names[i].c_str());
691  if (recordDeviceName.toStdString() == names[i]) {
692  m_audioRecordDeviceCombo->setCurrentIndex(i+1);
693  m_audioRecordDevice = i+1;
694  }
695  }
696 
697  settings.endGroup();
698 }
699 
700 void
702 {
703  if (m_tabOrdering.contains(t)) {
704  m_tabs->setCurrentIndex(m_tabOrdering[t]);
705  }
706 }
707 
708 void
710 {
711  m_windowType = type;
712  m_applyButton->setEnabled(true);
713 }
714 
715 void
717 {
718  m_spectrogramSmoothing = smoothing;
719  m_applyButton->setEnabled(true);
720 }
721 
722 void
724 {
725  m_spectrogramXSmoothing = smoothing;
726  m_applyButton->setEnabled(true);
727 }
728 
729 void
731 {
732  m_spectrogramGColour = colour;
733  m_coloursChanged = true;
734  m_applyButton->setEnabled(true);
735 }
736 
737 void
739 {
740  m_spectrogramMColour = colour;
741  m_coloursChanged = true;
742  m_applyButton->setEnabled(true);
743 }
744 
745 void
747 {
748  m_colour3DColour = colour;
749  m_coloursChanged = true;
750  m_applyButton->setEnabled(true);
751 }
752 
753 void
755 {
756  m_overviewColourIsSet = (colour >= 0);
757  if (m_overviewColourIsSet) {
758  m_overviewColour = ColourDatabase::getInstance()->getColour(colour);
759  }
760  m_coloursChanged = true;
761  m_applyButton->setEnabled(true);
762 }
763 
764 void
766 {
767  m_propertyLayout = layout;
768  m_applyButton->setEnabled(true);
769 }
770 
771 void
773 {
774  m_tuningFrequency = freq;
775  m_applyButton->setEnabled(true);
776 }
777 
778 void
780 {
781  if (m_audioImplementation != s) {
784  m_applyButton->setEnabled(true);
785  m_audioDeviceChanged = true;
786  }
787 }
788 
789 void
791 {
792  if (m_audioPlaybackDevice != s) {
794  m_applyButton->setEnabled(true);
795  m_audioDeviceChanged = true;
796  }
797 }
798 
799 void
801 {
802  if (m_audioRecordDevice != s) {
804  m_applyButton->setEnabled(true);
805  m_audioDeviceChanged = true;
806  }
807 }
808 
809 void
811 {
812  m_resampleOnLoad = (state == Qt::Checked);
813  m_applyButton->setEnabled(true);
814  m_changesOnRestart = true;
815 }
816 
817 void
819 {
820  m_gapless = (state == Qt::Checked);
821  m_applyButton->setEnabled(true);
822 }
823 
824 void
826 {
827  m_runPluginsInProcess = (state == Qt::Unchecked);
828  m_applyButton->setEnabled(true);
829  m_changesOnRestart = true;
830 }
831 
832 void
834 {
835  m_networkPermission = (state == Qt::Checked);
836  m_applyButton->setEnabled(true);
837  m_changesOnRestart = true;
838 }
839 
840 void
842 {
843  m_retina = (state == Qt::Checked);
844  m_applyButton->setEnabled(true);
845  // Does not require a restart
846 }
847 
848 void
850 {
851  m_showSplash = (state == Qt::Checked);
852  m_applyButton->setEnabled(true);
853  m_changesOnRestart = true;
854 }
855 
856 void
858 {
860  m_applyButton->setEnabled(true);
861 }
862 
863 void
865 {
867  m_applyButton->setEnabled(true);
868  m_changesOnRestart = true;
869 }
870 
871 void
873 {
874  m_tempDirRoot = r;
875  m_applyButton->setEnabled(true);
876 }
877 
878 void
880 {
881  QString dir = QFileDialog::getExistingDirectory
882  (this, tr("Select a directory to create cache subdirectory in"),
883  m_tempDirRoot);
884  if (dir == "") return;
885  m_tempDirRootEdit->setText(dir);
886  tempDirRootChanged(dir);
887  m_changesOnRestart = true;
888 }
889 
890 void
892 {
893  m_backgroundMode = mode;
894  m_applyButton->setEnabled(true);
895  m_changesOnRestart = true;
896 
897  // When switching to one of the explicit background choices
898  // (dark/light), also default the overview colour preference to
899  // something sensible
900 
901  int overviewColour = m_overviewColourCombo->getCurrentColourIndex();
902 
903  if (overviewColour >= 0) {
904  int plainColours = 6; // we happen to know there are 6 light and 6 dark
905 
906  if (mode == Preferences::DarkBackground &&
907  overviewColour < plainColours) {
908  overviewColour += plainColours;
909  }
910  if (mode == Preferences::LightBackground &&
911  overviewColour >= plainColours) {
912  overviewColour -= plainColours;
913  }
914 
915  m_overviewColourCombo->setCurrentIndex(overviewColour + 1);
916  overviewColourChanged(overviewColour);
917  }
918 }
919 
920 void
922 {
923  m_timeToTextMode = mode;
924  m_applyButton->setEnabled(true);
925 }
926 
927 void
929 {
930  m_showHMS = (state == Qt::Checked);
931  m_applyButton->setEnabled(true);
932 }
933 
934 void
936 {
937  m_octaveSystem = system;
938  m_applyButton->setEnabled(true);
939 }
940 
941 void
943 {
944  m_viewFontSize = sz;
945  m_applyButton->setEnabled(true);
946 }
947 
948 void
950 {
951  m_applyButton->setEnabled(true);
952  m_changesOnRestart = true;
953 }
954 
955 void
957 {
958  applyClicked();
959  accept();
960 }
961 
962 void
964 {
965  Preferences *prefs = Preferences::getInstance();
966  prefs->setWindowType(WindowType(m_windowType));
967  prefs->setSpectrogramSmoothing(Preferences::SpectrogramSmoothing
969  prefs->setSpectrogramXSmoothing(Preferences::SpectrogramXSmoothing
971  prefs->setPropertyBoxLayout(Preferences::PropertyBoxLayout
972  (m_propertyLayout));
973  prefs->setTuningFrequency(m_tuningFrequency);
974  prefs->setResampleOnLoad(m_resampleOnLoad);
975  prefs->setUseGaplessMode(m_gapless);
976  prefs->setRunPluginsInProcess(m_runPluginsInProcess);
977  prefs->setShowSplash(m_showSplash);
978  prefs->setTemporaryDirectoryRoot(m_tempDirRoot);
979  prefs->setBackgroundMode(Preferences::BackgroundMode(m_backgroundMode));
980  prefs->setTimeToTextMode(Preferences::TimeToTextMode(m_timeToTextMode));
981  prefs->setShowHMS(m_showHMS);
982  prefs->setViewFontSize(m_viewFontSize);
983 
984  prefs->setProperty("Octave Numbering System", m_octaveSystem);
985 
986  QSettings settings;
987  settings.beginGroup("Preferences");
988  QString permishTag = QString("network-permission-%1").arg(SV_VERSION);
989  settings.setValue(permishTag, m_networkPermission);
990 
991  vector<string> names = breakfastquay::AudioFactory::getImplementationNames();
992  string implementationName;
993  if (m_audioImplementation > int(names.size())) {
995  }
996  if (m_audioImplementation > 0) {
997  implementationName = names[m_audioImplementation-1];
998  }
999  settings.setValue("audio-target", implementationName.c_str());
1000 
1001  QString suffix;
1002  if (implementationName != "") {
1003  suffix = "-" + QString(implementationName.c_str());
1004  }
1005 
1006  names = breakfastquay::AudioFactory::getPlaybackDeviceNames(implementationName);
1007  string deviceName;
1008  if (m_audioPlaybackDevice > int(names.size())) {
1010  }
1011  if (m_audioPlaybackDevice > 0) {
1012  deviceName = names[m_audioPlaybackDevice-1];
1013  }
1014  settings.setValue("audio-playback-device" + suffix, deviceName.c_str());
1015 
1016  names = breakfastquay::AudioFactory::getRecordDeviceNames(implementationName);
1017  deviceName = "";
1018  if (m_audioRecordDevice > int(names.size())) {
1019  m_audioRecordDevice = 0;
1020  }
1021  if (m_audioRecordDevice > 0) {
1022  deviceName = names[m_audioRecordDevice-1];
1023  }
1024  settings.setValue("audio-record-device" + suffix, deviceName.c_str());
1025 
1026  settings.setValue("locale", m_currentLocale);
1027 #ifdef Q_OS_MAC
1028  settings.setValue("scaledHiDpi", m_retina);
1029 #endif
1030  settings.setValue("spectrogram-colour", m_spectrogramGColour);
1031  settings.setValue("spectrogram-melodic-colour", m_spectrogramMColour);
1032  settings.setValue("colour-3d-plot-colour", m_colour3DColour);
1033  if (m_overviewColourIsSet) {
1034  settings.setValue("overview-colour", m_overviewColour.name());
1035  } else {
1036  settings.remove("overview-colour");
1037  }
1038  settings.endGroup();
1039 
1040  settings.beginGroup("MainWindow");
1041  settings.setValue("sessiontemplate", m_currentTemplate);
1042  settings.endGroup();
1043 
1044  m_applyButton->setEnabled(false);
1045 
1046  if (m_changesOnRestart) {
1047  QMessageBox::information(this, tr("Preferences"),
1048  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>"));
1049  m_changesOnRestart = false;
1050  }
1051 
1052  if (m_audioDeviceChanged) {
1053  emit audioDeviceChanged();
1054  m_audioDeviceChanged = false;
1055  }
1056 
1057  if (m_coloursChanged) {
1058  emit coloursChanged();
1059  m_coloursChanged = false;
1060  }
1061 
1062  PluginPathSetter::savePathSettings(m_pluginPathConfigurator->getPaths());
1063 }
1064 
1065 void
1067 {
1068  reject();
1069 }
1070 
1071 void
1073 {
1074  if (quickly) {
1075  reject();
1076  return;
1077  }
1078 
1079  if (m_applyButton->isEnabled()) {
1080  int rv = QMessageBox::warning
1081  (this, tr("Preferences Changed"),
1082  tr("Some preferences have been changed but not applied.\n"
1083  "Apply them before closing?"),
1084  QMessageBox::Apply | QMessageBox::Discard,
1085  QMessageBox::Discard);
1086  if (rv == QMessageBox::Apply) {
1087  applyClicked();
1088  accept();
1089  } else {
1090  reject();
1091  }
1092  } else {
1093  accept();
1094  }
1095 }
1096 
void colour3DColourChanged(int state)
void timeToTextModeChanged(int mode)
void overviewColourChanged(int state)
QPushButton * m_applyButton
void octaveSystemChanged(int system)
QComboBox * m_audioRecordDeviceCombo
QComboBox * m_audioPlaybackDeviceCombo
void audioPlaybackDeviceChanged(int device)
void networkPermissionChanged(int state)
void showSplashChanged(int state)
void propertyLayoutChanged(int layout)
ColourComboBox * m_overviewColourCombo
void audioImplementationChanged(int impl)
void defaultTemplateChanged(int)
void windowTypeChanged(WindowType type)
QLineEdit * m_tempDirRootEdit
void spectrogramXSmoothingChanged(int state)
void viewFontSizeChanged(int sz)
void spectrogramMColourChanged(int state)
void spectrogramSmoothingChanged(int state)
void backgroundModeChanged(int mode)
void audioRecordDeviceChanged(int device)
void gaplessModeChanged(int state)
void resampleOnLoadChanged(int state)
QMap< Tab, int > m_tabOrdering
void switchToTab(Tab tab)
WindowTypeSelector * m_windowTypeSelector
PreferencesDialog(QWidget *parent=0)
void showHMSChanged(int state)
void tuningFrequencyChanged(double freq)
void vampProcessSeparationChanged(int state)
void retinaChanged(int state)
void applicationClosing(bool quickly)
PluginPathConfigurator * m_pluginPathConfigurator
void audioDeviceChanged()
void tempDirRootChanged(QString root)
void spectrogramGColourChanged(int state)