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@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@245
|
116 int *min, int *max, int *deflt) 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@245
|
121 if (deflt) *deflt = 1;
|
Chris@136
|
122 return m_smoothSpectrogram ? 1 : 0;
|
Chris@136
|
123 }
|
Chris@136
|
124
|
Chris@136
|
125 //!!! freq mapping
|
Chris@136
|
126
|
Chris@138
|
127 if (name == "Property Box Layout") {
|
Chris@138
|
128 if (min) *min = 0;
|
Chris@138
|
129 if (max) *max = 1;
|
Chris@245
|
130 if (deflt) *deflt = 0;
|
Chris@138
|
131 return m_propertyBoxLayout == Layered ? 1 : 0;
|
Chris@138
|
132 }
|
Chris@138
|
133
|
Chris@140
|
134 if (name == "Window Type") {
|
Chris@140
|
135 if (min) *min = int(RectangularWindow);
|
Chris@142
|
136 if (max) *max = int(BlackmanHarrisWindow);
|
Chris@245
|
137 if (deflt) *deflt = int(HanningWindow);
|
Chris@140
|
138 return int(m_windowType);
|
Chris@140
|
139 }
|
Chris@140
|
140
|
Chris@164
|
141 if (name == "Resample Quality") {
|
Chris@164
|
142 if (min) *min = 0;
|
Chris@164
|
143 if (max) *max = 2;
|
Chris@245
|
144 if (deflt) *deflt = 1;
|
Chris@164
|
145 return m_resampleQuality;
|
Chris@164
|
146 }
|
Chris@164
|
147
|
Chris@136
|
148 return 0;
|
Chris@136
|
149 }
|
Chris@136
|
150
|
Chris@136
|
151 QString
|
Chris@136
|
152 Preferences::getPropertyValueLabel(const PropertyName &name,
|
Chris@136
|
153 int value) const
|
Chris@136
|
154 {
|
Chris@138
|
155 if (name == "Property Box Layout") {
|
Chris@141
|
156 if (value == 0) return tr("Show boxes for all panes");
|
Chris@141
|
157 else return tr("Show box for current pane only");
|
Chris@138
|
158 }
|
Chris@140
|
159 if (name == "Window Type") {
|
Chris@140
|
160 switch (WindowType(value)) {
|
Chris@140
|
161 case RectangularWindow: return tr("Rectangular");
|
Chris@141
|
162 case BartlettWindow: return tr("Triangular");
|
Chris@140
|
163 case HammingWindow: return tr("Hamming");
|
Chris@140
|
164 case HanningWindow: return tr("Hanning");
|
Chris@140
|
165 case BlackmanWindow: return tr("Blackman");
|
Chris@140
|
166 case GaussianWindow: return tr("Gaussian");
|
Chris@140
|
167 case ParzenWindow: return tr("Parzen");
|
Chris@142
|
168 case NuttallWindow: return tr("Nuttall");
|
Chris@142
|
169 case BlackmanHarrisWindow: return tr("Blackman-Harris");
|
Chris@140
|
170 }
|
Chris@140
|
171 }
|
Chris@164
|
172 if (name == "Resample Quality") {
|
Chris@164
|
173 switch (value) {
|
Chris@164
|
174 case 0: return tr("Fastest");
|
Chris@165
|
175 case 1: return tr("Standard");
|
Chris@164
|
176 case 2: return tr("Highest quality");
|
Chris@164
|
177 }
|
Chris@164
|
178 }
|
Chris@136
|
179 return "";
|
Chris@136
|
180 }
|
Chris@136
|
181
|
Chris@136
|
182 QString
|
Chris@136
|
183 Preferences::getPropertyContainerName() const
|
Chris@136
|
184 {
|
Chris@136
|
185 return tr("Preferences");
|
Chris@136
|
186 }
|
Chris@136
|
187
|
Chris@136
|
188 QString
|
Chris@136
|
189 Preferences::getPropertyContainerIconName() const
|
Chris@136
|
190 {
|
Chris@136
|
191 return "preferences";
|
Chris@136
|
192 }
|
Chris@136
|
193
|
Chris@136
|
194 void
|
Chris@136
|
195 Preferences::setProperty(const PropertyName &name, int value)
|
Chris@136
|
196 {
|
Chris@136
|
197 if (name == "Smooth Spectrogram") {
|
Chris@136
|
198 setSmoothSpectrogram(value > 0.1);
|
Chris@136
|
199 } else if (name == "Tuning Frequency") {
|
Chris@136
|
200 //!!!
|
Chris@138
|
201 } else if (name == "Property Box Layout") {
|
Chris@138
|
202 setPropertyBoxLayout(value == 0 ? VerticallyStacked : Layered);
|
Chris@140
|
203 } else if (name == "Window Type") {
|
Chris@140
|
204 setWindowType(WindowType(value));
|
Chris@164
|
205 } else if (name == "Resample Quality") {
|
Chris@164
|
206 setResampleQuality(value);
|
Chris@136
|
207 }
|
Chris@136
|
208 }
|
Chris@136
|
209
|
Chris@136
|
210 void
|
Chris@136
|
211 Preferences::setSmoothSpectrogram(bool smooth)
|
Chris@136
|
212 {
|
Chris@138
|
213 if (m_smoothSpectrogram != smooth) {
|
Chris@138
|
214 m_smoothSpectrogram = smooth;
|
Chris@156
|
215 QSettings settings;
|
Chris@156
|
216 settings.beginGroup("Preferences");
|
Chris@156
|
217 settings.setValue("smooth-spectrogram", smooth);
|
Chris@156
|
218 settings.endGroup();
|
Chris@141
|
219 emit propertyChanged("Smooth Spectrogram");
|
Chris@138
|
220 }
|
Chris@136
|
221 }
|
Chris@136
|
222
|
Chris@136
|
223 void
|
Chris@136
|
224 Preferences::setTuningFrequency(float freq)
|
Chris@136
|
225 {
|
Chris@138
|
226 if (m_tuningFrequency != freq) {
|
Chris@138
|
227 m_tuningFrequency = freq;
|
Chris@156
|
228 QSettings settings;
|
Chris@156
|
229 settings.beginGroup("Preferences");
|
Chris@156
|
230 settings.setValue("tuning-frequency", freq);
|
Chris@156
|
231 settings.endGroup();
|
Chris@141
|
232 emit propertyChanged("Tuning Frequency");
|
Chris@138
|
233 }
|
Chris@136
|
234 }
|
Chris@136
|
235
|
Chris@138
|
236 void
|
Chris@138
|
237 Preferences::setPropertyBoxLayout(PropertyBoxLayout layout)
|
Chris@138
|
238 {
|
Chris@138
|
239 if (m_propertyBoxLayout != layout) {
|
Chris@138
|
240 m_propertyBoxLayout = layout;
|
Chris@156
|
241 QSettings settings;
|
Chris@156
|
242 settings.beginGroup("Preferences");
|
Chris@156
|
243 settings.setValue("property-box-layout", int(layout));
|
Chris@156
|
244 settings.endGroup();
|
Chris@141
|
245 emit propertyChanged("Property Box Layout");
|
Chris@138
|
246 }
|
Chris@138
|
247 }
|
Chris@138
|
248
|
Chris@140
|
249 void
|
Chris@140
|
250 Preferences::setWindowType(WindowType type)
|
Chris@140
|
251 {
|
Chris@140
|
252 if (m_windowType != type) {
|
Chris@140
|
253 m_windowType = type;
|
Chris@156
|
254 QSettings settings;
|
Chris@156
|
255 settings.beginGroup("Preferences");
|
Chris@156
|
256 settings.setValue("window-type", int(type));
|
Chris@156
|
257 settings.endGroup();
|
Chris@141
|
258 emit propertyChanged("Window Type");
|
Chris@140
|
259 }
|
Chris@140
|
260 }
|
Chris@140
|
261
|
Chris@164
|
262 void
|
Chris@164
|
263 Preferences::setResampleQuality(int q)
|
Chris@164
|
264 {
|
Chris@164
|
265 if (m_resampleQuality != q) {
|
Chris@164
|
266 m_resampleQuality = q;
|
Chris@164
|
267 QSettings settings;
|
Chris@164
|
268 settings.beginGroup("Preferences");
|
Chris@164
|
269 settings.setValue("resample-quality", q);
|
Chris@164
|
270 settings.endGroup();
|
Chris@164
|
271 emit propertyChanged("Resample Quality");
|
Chris@164
|
272 }
|
Chris@164
|
273 }
|