annotate base/Preferences.cpp @ 189:0703252c9fe8

* Add spectrum icon * Start range mapper class for use in mapping between e.g. dial positions and underlying values
author Chris Cannam
date Mon, 16 Oct 2006 13:13:57 +0000
parents 5ae5885d6ce3
children 91fdc752e540
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@136 7 This file copyright 2006 Chris Cannam.
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@137 38 m_smoothSpectrogram(true),
Chris@140 39 m_tuningFrequency(440),
Chris@140 40 m_propertyBoxLayout(VerticallyStacked),
Chris@164 41 m_windowType(HanningWindow),
Chris@164 42 m_resampleQuality(1)
Chris@136 43 {
Chris@156 44 QSettings settings;
Chris@156 45 settings.beginGroup("Preferences");
Chris@156 46 m_smoothSpectrogram = settings.value("smooth-spectrogram", true).toBool();
Chris@156 47 m_tuningFrequency = settings.value("tuning-frequency", 440.f).toDouble();
Chris@145 48 m_propertyBoxLayout = PropertyBoxLayout
Chris@156 49 (settings.value("property-box-layout", int(VerticallyStacked)).toInt());
Chris@145 50 m_windowType = WindowType
Chris@156 51 (settings.value("window-type", int(HanningWindow)).toInt());
Chris@164 52 m_resampleQuality = settings.value("resample-quality", 1).toInt();
Chris@156 53 settings.endGroup();
Chris@145 54 }
Chris@145 55
Chris@145 56 Preferences::~Preferences()
Chris@145 57 {
Chris@136 58 }
Chris@136 59
Chris@136 60 Preferences::PropertyList
Chris@136 61 Preferences::getProperties() const
Chris@136 62 {
Chris@136 63 PropertyList props;
Chris@136 64 props.push_back("Smooth Spectrogram");
Chris@136 65 props.push_back("Tuning Frequency");
Chris@138 66 props.push_back("Property Box Layout");
Chris@140 67 props.push_back("Window Type");
Chris@164 68 props.push_back("Resample Quality");
Chris@136 69 return props;
Chris@136 70 }
Chris@136 71
Chris@136 72 QString
Chris@136 73 Preferences::getPropertyLabel(const PropertyName &name) const
Chris@136 74 {
Chris@136 75 if (name == "Smooth Spectrogram") {
Chris@141 76 return tr("Smooth spectrogram display by zero padding FFT");
Chris@136 77 }
Chris@136 78 if (name == "Tuning Frequency") {
Chris@141 79 return tr("Frequency of concert A");
Chris@136 80 }
Chris@138 81 if (name == "Property Box Layout") {
Chris@141 82 return tr("Property box layout");
Chris@138 83 }
Chris@140 84 if (name == "Window Type") {
Chris@141 85 return tr("Spectral analysis window shape");
Chris@140 86 }
Chris@164 87 if (name == "Resample Quality") {
Chris@165 88 return tr("Playback resampler type");
Chris@164 89 }
Chris@136 90 return name;
Chris@136 91 }
Chris@136 92
Chris@136 93 Preferences::PropertyType
Chris@136 94 Preferences::getPropertyType(const PropertyName &name) const
Chris@136 95 {
Chris@136 96 if (name == "Smooth Spectrogram") {
Chris@136 97 return ToggleProperty;
Chris@136 98 }
Chris@136 99 if (name == "Tuning Frequency") {
Chris@136 100 return RangeProperty;
Chris@136 101 }
Chris@138 102 if (name == "Property Box Layout") {
Chris@138 103 return ValueProperty;
Chris@138 104 }
Chris@140 105 if (name == "Window Type") {
Chris@140 106 return ValueProperty;
Chris@140 107 }
Chris@164 108 if (name == "Resample Quality") {
Chris@164 109 return ValueProperty;
Chris@164 110 }
Chris@136 111 return InvalidProperty;
Chris@136 112 }
Chris@136 113
Chris@136 114 int
Chris@136 115 Preferences::getPropertyRangeAndValue(const PropertyName &name,
Chris@136 116 int *min, int *max) const
Chris@136 117 {
Chris@136 118 if (name == "Smooth Spectrogram") {
Chris@136 119 if (min) *min = 0;
Chris@136 120 if (max) *max = 1;
Chris@136 121 return m_smoothSpectrogram ? 1 : 0;
Chris@136 122 }
Chris@136 123
Chris@136 124 //!!! freq mapping
Chris@136 125
Chris@138 126 if (name == "Property Box Layout") {
Chris@138 127 if (min) *min = 0;
Chris@138 128 if (max) *max = 1;
Chris@138 129 return m_propertyBoxLayout == Layered ? 1 : 0;
Chris@138 130 }
Chris@138 131
Chris@140 132 if (name == "Window Type") {
Chris@140 133 if (min) *min = int(RectangularWindow);
Chris@142 134 if (max) *max = int(BlackmanHarrisWindow);
Chris@140 135 return int(m_windowType);
Chris@140 136 }
Chris@140 137
Chris@164 138 if (name == "Resample Quality") {
Chris@164 139 if (min) *min = 0;
Chris@164 140 if (max) *max = 2;
Chris@164 141 return m_resampleQuality;
Chris@164 142 }
Chris@164 143
Chris@136 144 return 0;
Chris@136 145 }
Chris@136 146
Chris@136 147 QString
Chris@136 148 Preferences::getPropertyValueLabel(const PropertyName &name,
Chris@136 149 int value) const
Chris@136 150 {
Chris@138 151 if (name == "Property Box Layout") {
Chris@141 152 if (value == 0) return tr("Show boxes for all panes");
Chris@141 153 else return tr("Show box for current pane only");
Chris@138 154 }
Chris@140 155 if (name == "Window Type") {
Chris@140 156 switch (WindowType(value)) {
Chris@140 157 case RectangularWindow: return tr("Rectangular");
Chris@141 158 case BartlettWindow: return tr("Triangular");
Chris@140 159 case HammingWindow: return tr("Hamming");
Chris@140 160 case HanningWindow: return tr("Hanning");
Chris@140 161 case BlackmanWindow: return tr("Blackman");
Chris@140 162 case GaussianWindow: return tr("Gaussian");
Chris@140 163 case ParzenWindow: return tr("Parzen");
Chris@142 164 case NuttallWindow: return tr("Nuttall");
Chris@142 165 case BlackmanHarrisWindow: return tr("Blackman-Harris");
Chris@140 166 }
Chris@140 167 }
Chris@164 168 if (name == "Resample Quality") {
Chris@164 169 switch (value) {
Chris@164 170 case 0: return tr("Fastest");
Chris@165 171 case 1: return tr("Standard");
Chris@164 172 case 2: return tr("Highest quality");
Chris@164 173 }
Chris@164 174 }
Chris@136 175 return "";
Chris@136 176 }
Chris@136 177
Chris@136 178 QString
Chris@136 179 Preferences::getPropertyContainerName() const
Chris@136 180 {
Chris@136 181 return tr("Preferences");
Chris@136 182 }
Chris@136 183
Chris@136 184 QString
Chris@136 185 Preferences::getPropertyContainerIconName() const
Chris@136 186 {
Chris@136 187 return "preferences";
Chris@136 188 }
Chris@136 189
Chris@136 190 void
Chris@136 191 Preferences::setProperty(const PropertyName &name, int value)
Chris@136 192 {
Chris@136 193 if (name == "Smooth Spectrogram") {
Chris@136 194 setSmoothSpectrogram(value > 0.1);
Chris@136 195 } else if (name == "Tuning Frequency") {
Chris@136 196 //!!!
Chris@138 197 } else if (name == "Property Box Layout") {
Chris@138 198 setPropertyBoxLayout(value == 0 ? VerticallyStacked : Layered);
Chris@140 199 } else if (name == "Window Type") {
Chris@140 200 setWindowType(WindowType(value));
Chris@164 201 } else if (name == "Resample Quality") {
Chris@164 202 setResampleQuality(value);
Chris@136 203 }
Chris@136 204 }
Chris@136 205
Chris@136 206 void
Chris@136 207 Preferences::setSmoothSpectrogram(bool smooth)
Chris@136 208 {
Chris@138 209 if (m_smoothSpectrogram != smooth) {
Chris@138 210 m_smoothSpectrogram = smooth;
Chris@156 211 QSettings settings;
Chris@156 212 settings.beginGroup("Preferences");
Chris@156 213 settings.setValue("smooth-spectrogram", smooth);
Chris@156 214 settings.endGroup();
Chris@141 215 emit propertyChanged("Smooth Spectrogram");
Chris@138 216 }
Chris@136 217 }
Chris@136 218
Chris@136 219 void
Chris@136 220 Preferences::setTuningFrequency(float freq)
Chris@136 221 {
Chris@138 222 if (m_tuningFrequency != freq) {
Chris@138 223 m_tuningFrequency = freq;
Chris@156 224 QSettings settings;
Chris@156 225 settings.beginGroup("Preferences");
Chris@156 226 settings.setValue("tuning-frequency", freq);
Chris@156 227 settings.endGroup();
Chris@141 228 emit propertyChanged("Tuning Frequency");
Chris@138 229 }
Chris@136 230 }
Chris@136 231
Chris@138 232 void
Chris@138 233 Preferences::setPropertyBoxLayout(PropertyBoxLayout layout)
Chris@138 234 {
Chris@138 235 if (m_propertyBoxLayout != layout) {
Chris@138 236 m_propertyBoxLayout = layout;
Chris@156 237 QSettings settings;
Chris@156 238 settings.beginGroup("Preferences");
Chris@156 239 settings.setValue("property-box-layout", int(layout));
Chris@156 240 settings.endGroup();
Chris@141 241 emit propertyChanged("Property Box Layout");
Chris@138 242 }
Chris@138 243 }
Chris@138 244
Chris@140 245 void
Chris@140 246 Preferences::setWindowType(WindowType type)
Chris@140 247 {
Chris@140 248 if (m_windowType != type) {
Chris@140 249 m_windowType = type;
Chris@156 250 QSettings settings;
Chris@156 251 settings.beginGroup("Preferences");
Chris@156 252 settings.setValue("window-type", int(type));
Chris@156 253 settings.endGroup();
Chris@141 254 emit propertyChanged("Window Type");
Chris@140 255 }
Chris@140 256 }
Chris@140 257
Chris@164 258 void
Chris@164 259 Preferences::setResampleQuality(int q)
Chris@164 260 {
Chris@164 261 if (m_resampleQuality != q) {
Chris@164 262 m_resampleQuality = q;
Chris@164 263 QSettings settings;
Chris@164 264 settings.beginGroup("Preferences");
Chris@164 265 settings.setValue("resample-quality", q);
Chris@164 266 settings.endGroup();
Chris@164 267 emit propertyChanged("Resample Quality");
Chris@164 268 }
Chris@164 269 }