annotate base/Preferences.cpp @ 289:3020904de772

* Layer tree view updating when visibility / audibility changed (and layers updating when they are changed in view) -- still some problems when a model is loaded while the tree is visible * FFTW_MEASURE throughout -- it does turn out to make an appreciable difference sometimes
author Chris Cannam
date Thu, 16 Aug 2007 16:47:07 +0000
parents 3b8008d09541
children c022976d18e8
rev   line source
Chris@136 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@136 2
Chris@136 3 /*
Chris@136 4 Sonic Visualiser
Chris@136 5 An audio file viewer and annotation editor.
Chris@136 6 Centre for Digital Music, Queen Mary, University of London.
Chris@202 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@136 8
Chris@136 9 This program is free software; you can redistribute it and/or
Chris@136 10 modify it under the terms of the GNU General Public License as
Chris@136 11 published by the Free Software Foundation; either version 2 of the
Chris@136 12 License, or (at your option) any later version. See the file
Chris@136 13 COPYING included with this distribution for more information.
Chris@136 14 */
Chris@136 15
Chris@136 16 #include "Preferences.h"
Chris@136 17
Chris@145 18 #include "Exceptions.h"
Chris@145 19
Chris@145 20 #include "TempDirectory.h"
Chris@145 21
Chris@145 22 #include <QDir>
Chris@145 23 #include <QFileInfo>
Chris@156 24 #include <QMutex>
Chris@156 25 #include <QSettings>
Chris@145 26
Chris@136 27 Preferences *
Chris@156 28 Preferences::m_instance = 0;
Chris@156 29
Chris@156 30 Preferences *
Chris@156 31 Preferences::getInstance()
Chris@156 32 {
Chris@156 33 if (!m_instance) m_instance = new Preferences();
Chris@156 34 return m_instance;
Chris@156 35 }
Chris@136 36
Chris@136 37 Preferences::Preferences() :
Chris@246 38 m_spectrogramSmoothing(SpectrogramZeroPadded),
Chris@140 39 m_tuningFrequency(440),
Chris@140 40 m_propertyBoxLayout(VerticallyStacked),
Chris@164 41 m_windowType(HanningWindow),
Chris@277 42 m_resampleQuality(1),
Chris@277 43 m_omitRecentTemps(true)
Chris@136 44 {
Chris@156 45 QSettings settings;
Chris@156 46 settings.beginGroup("Preferences");
Chris@246 47 m_spectrogramSmoothing = SpectrogramSmoothing
Chris@246 48 (settings.value("spectrogram-smoothing", int(m_spectrogramSmoothing)).toInt());
Chris@156 49 m_tuningFrequency = settings.value("tuning-frequency", 440.f).toDouble();
Chris@145 50 m_propertyBoxLayout = PropertyBoxLayout
Chris@156 51 (settings.value("property-box-layout", int(VerticallyStacked)).toInt());
Chris@145 52 m_windowType = WindowType
Chris@156 53 (settings.value("window-type", int(HanningWindow)).toInt());
Chris@164 54 m_resampleQuality = settings.value("resample-quality", 1).toInt();
Chris@156 55 settings.endGroup();
Chris@145 56 }
Chris@145 57
Chris@145 58 Preferences::~Preferences()
Chris@145 59 {
Chris@136 60 }
Chris@136 61
Chris@136 62 Preferences::PropertyList
Chris@136 63 Preferences::getProperties() const
Chris@136 64 {
Chris@136 65 PropertyList props;
Chris@246 66 props.push_back("Spectrogram Smoothing");
Chris@136 67 props.push_back("Tuning Frequency");
Chris@138 68 props.push_back("Property Box Layout");
Chris@140 69 props.push_back("Window Type");
Chris@164 70 props.push_back("Resample Quality");
Chris@277 71 props.push_back("Omit Temporaries from Recent Files");
Chris@136 72 return props;
Chris@136 73 }
Chris@136 74
Chris@136 75 QString
Chris@136 76 Preferences::getPropertyLabel(const PropertyName &name) const
Chris@136 77 {
Chris@246 78 if (name == "Spectrogram Smoothing") {
Chris@246 79 return tr("Spectrogram y-axis smoothing:");
Chris@136 80 }
Chris@136 81 if (name == "Tuning Frequency") {
Chris@141 82 return tr("Frequency of concert A");
Chris@136 83 }
Chris@138 84 if (name == "Property Box Layout") {
Chris@141 85 return tr("Property box layout");
Chris@138 86 }
Chris@140 87 if (name == "Window Type") {
Chris@141 88 return tr("Spectral analysis window shape");
Chris@140 89 }
Chris@164 90 if (name == "Resample Quality") {
Chris@165 91 return tr("Playback resampler type");
Chris@164 92 }
Chris@277 93 if (name == "Omit Temporaries from Recent Files") {
Chris@277 94 return tr("Omit Temporaries from Recent Files");
Chris@277 95 }
Chris@136 96 return name;
Chris@136 97 }
Chris@136 98
Chris@136 99 Preferences::PropertyType
Chris@136 100 Preferences::getPropertyType(const PropertyName &name) const
Chris@136 101 {
Chris@246 102 if (name == "Spectrogram Smoothing") {
Chris@246 103 return ValueProperty;
Chris@136 104 }
Chris@136 105 if (name == "Tuning Frequency") {
Chris@136 106 return RangeProperty;
Chris@136 107 }
Chris@138 108 if (name == "Property Box Layout") {
Chris@138 109 return ValueProperty;
Chris@138 110 }
Chris@140 111 if (name == "Window Type") {
Chris@140 112 return ValueProperty;
Chris@140 113 }
Chris@164 114 if (name == "Resample Quality") {
Chris@164 115 return ValueProperty;
Chris@164 116 }
Chris@277 117 if (name == "Omit Temporaries from Recent Files") {
Chris@277 118 return ToggleProperty;
Chris@277 119 }
Chris@136 120 return InvalidProperty;
Chris@136 121 }
Chris@136 122
Chris@136 123 int
Chris@136 124 Preferences::getPropertyRangeAndValue(const PropertyName &name,
Chris@245 125 int *min, int *max, int *deflt) const
Chris@136 126 {
Chris@246 127 if (name == "Spectrogram Smoothing") {
Chris@136 128 if (min) *min = 0;
Chris@246 129 if (max) *max = 2;
Chris@246 130 if (deflt) *deflt = int(SpectrogramZeroPadded);
Chris@246 131 return int(m_spectrogramSmoothing);
Chris@136 132 }
Chris@136 133
Chris@136 134 //!!! freq mapping
Chris@136 135
Chris@138 136 if (name == "Property Box Layout") {
Chris@138 137 if (min) *min = 0;
Chris@138 138 if (max) *max = 1;
Chris@245 139 if (deflt) *deflt = 0;
Chris@138 140 return m_propertyBoxLayout == Layered ? 1 : 0;
Chris@138 141 }
Chris@138 142
Chris@140 143 if (name == "Window Type") {
Chris@140 144 if (min) *min = int(RectangularWindow);
Chris@142 145 if (max) *max = int(BlackmanHarrisWindow);
Chris@245 146 if (deflt) *deflt = int(HanningWindow);
Chris@140 147 return int(m_windowType);
Chris@140 148 }
Chris@140 149
Chris@164 150 if (name == "Resample Quality") {
Chris@164 151 if (min) *min = 0;
Chris@164 152 if (max) *max = 2;
Chris@245 153 if (deflt) *deflt = 1;
Chris@164 154 return m_resampleQuality;
Chris@164 155 }
Chris@164 156
Chris@277 157 if (name == "Omit Temporaries from Recent Files") {
Chris@277 158 if (deflt) *deflt = 1;
Chris@277 159 }
Chris@277 160
Chris@136 161 return 0;
Chris@136 162 }
Chris@136 163
Chris@136 164 QString
Chris@136 165 Preferences::getPropertyValueLabel(const PropertyName &name,
Chris@136 166 int value) const
Chris@136 167 {
Chris@138 168 if (name == "Property Box Layout") {
Chris@141 169 if (value == 0) return tr("Show boxes for all panes");
Chris@141 170 else return tr("Show box for current pane only");
Chris@138 171 }
Chris@140 172 if (name == "Window Type") {
Chris@140 173 switch (WindowType(value)) {
Chris@140 174 case RectangularWindow: return tr("Rectangular");
Chris@141 175 case BartlettWindow: return tr("Triangular");
Chris@140 176 case HammingWindow: return tr("Hamming");
Chris@140 177 case HanningWindow: return tr("Hanning");
Chris@140 178 case BlackmanWindow: return tr("Blackman");
Chris@140 179 case GaussianWindow: return tr("Gaussian");
Chris@140 180 case ParzenWindow: return tr("Parzen");
Chris@142 181 case NuttallWindow: return tr("Nuttall");
Chris@142 182 case BlackmanHarrisWindow: return tr("Blackman-Harris");
Chris@140 183 }
Chris@140 184 }
Chris@164 185 if (name == "Resample Quality") {
Chris@164 186 switch (value) {
Chris@164 187 case 0: return tr("Fastest");
Chris@165 188 case 1: return tr("Standard");
Chris@164 189 case 2: return tr("Highest quality");
Chris@164 190 }
Chris@164 191 }
Chris@246 192 if (name == "Spectrogram Smoothing") {
Chris@246 193 switch (value) {
Chris@246 194 case NoSpectrogramSmoothing: return tr("None - blocky but accurate");
Chris@246 195 case SpectrogramInterpolated: return tr("Interpolate - fast but fuzzy");
Chris@246 196 case SpectrogramZeroPadded: return tr("Zero pad FFT - slow but clear");
Chris@246 197 }
Chris@246 198 }
Chris@246 199
Chris@136 200 return "";
Chris@136 201 }
Chris@136 202
Chris@136 203 QString
Chris@136 204 Preferences::getPropertyContainerName() const
Chris@136 205 {
Chris@136 206 return tr("Preferences");
Chris@136 207 }
Chris@136 208
Chris@136 209 QString
Chris@136 210 Preferences::getPropertyContainerIconName() const
Chris@136 211 {
Chris@136 212 return "preferences";
Chris@136 213 }
Chris@136 214
Chris@136 215 void
Chris@136 216 Preferences::setProperty(const PropertyName &name, int value)
Chris@136 217 {
Chris@246 218 if (name == "Spectrogram Smoothing") {
Chris@246 219 setSpectrogramSmoothing(SpectrogramSmoothing(value));
Chris@136 220 } else if (name == "Tuning Frequency") {
Chris@136 221 //!!!
Chris@138 222 } else if (name == "Property Box Layout") {
Chris@138 223 setPropertyBoxLayout(value == 0 ? VerticallyStacked : Layered);
Chris@140 224 } else if (name == "Window Type") {
Chris@140 225 setWindowType(WindowType(value));
Chris@164 226 } else if (name == "Resample Quality") {
Chris@164 227 setResampleQuality(value);
Chris@277 228 } else if (name == "Omit Temporaries from Recent Files") {
Chris@277 229 setOmitTempsFromRecentFiles(value ? true : false);
Chris@136 230 }
Chris@136 231 }
Chris@136 232
Chris@136 233 void
Chris@246 234 Preferences::setSpectrogramSmoothing(SpectrogramSmoothing smoothing)
Chris@136 235 {
Chris@246 236 if (m_spectrogramSmoothing != smoothing) {
Chris@246 237
Chris@246 238 // "smoothing" is one of those words that looks increasingly
Chris@246 239 // ridiculous the more you see it. Smoothing smoothing smoothing.
Chris@246 240 m_spectrogramSmoothing = smoothing;
Chris@246 241
Chris@156 242 QSettings settings;
Chris@156 243 settings.beginGroup("Preferences");
Chris@246 244 settings.setValue("spectrogram-smoothing", int(smoothing));
Chris@156 245 settings.endGroup();
Chris@246 246 emit propertyChanged("Spectrogram Smoothing");
Chris@138 247 }
Chris@136 248 }
Chris@136 249
Chris@136 250 void
Chris@136 251 Preferences::setTuningFrequency(float freq)
Chris@136 252 {
Chris@138 253 if (m_tuningFrequency != freq) {
Chris@138 254 m_tuningFrequency = freq;
Chris@156 255 QSettings settings;
Chris@156 256 settings.beginGroup("Preferences");
Chris@156 257 settings.setValue("tuning-frequency", freq);
Chris@156 258 settings.endGroup();
Chris@141 259 emit propertyChanged("Tuning Frequency");
Chris@138 260 }
Chris@136 261 }
Chris@136 262
Chris@138 263 void
Chris@138 264 Preferences::setPropertyBoxLayout(PropertyBoxLayout layout)
Chris@138 265 {
Chris@138 266 if (m_propertyBoxLayout != layout) {
Chris@138 267 m_propertyBoxLayout = layout;
Chris@156 268 QSettings settings;
Chris@156 269 settings.beginGroup("Preferences");
Chris@156 270 settings.setValue("property-box-layout", int(layout));
Chris@156 271 settings.endGroup();
Chris@141 272 emit propertyChanged("Property Box Layout");
Chris@138 273 }
Chris@138 274 }
Chris@138 275
Chris@140 276 void
Chris@140 277 Preferences::setWindowType(WindowType type)
Chris@140 278 {
Chris@140 279 if (m_windowType != type) {
Chris@140 280 m_windowType = type;
Chris@156 281 QSettings settings;
Chris@156 282 settings.beginGroup("Preferences");
Chris@156 283 settings.setValue("window-type", int(type));
Chris@156 284 settings.endGroup();
Chris@141 285 emit propertyChanged("Window Type");
Chris@140 286 }
Chris@140 287 }
Chris@140 288
Chris@164 289 void
Chris@164 290 Preferences::setResampleQuality(int q)
Chris@164 291 {
Chris@164 292 if (m_resampleQuality != q) {
Chris@164 293 m_resampleQuality = q;
Chris@164 294 QSettings settings;
Chris@164 295 settings.beginGroup("Preferences");
Chris@164 296 settings.setValue("resample-quality", q);
Chris@164 297 settings.endGroup();
Chris@164 298 emit propertyChanged("Resample Quality");
Chris@164 299 }
Chris@164 300 }
Chris@277 301
Chris@277 302 void
Chris@277 303 Preferences::setOmitTempsFromRecentFiles(bool omit)
Chris@277 304 {
Chris@277 305 if (m_omitRecentTemps != omit) {
Chris@277 306 m_omitRecentTemps = omit;
Chris@277 307 QSettings settings;
Chris@277 308 settings.beginGroup("Preferences");
Chris@277 309 settings.setValue("omit-recent-temporaries", omit);
Chris@277 310 settings.endGroup();
Chris@277 311 emit propertyChanged("Omit Temporaries from Recent Files");
Chris@277 312 }
Chris@277 313 }