Mercurial > hg > easaier-soundaccess
comparison base/Preferences.cpp @ 0:fc9323a41f5a
start base : Sonic Visualiser sv1-1.0rc1
author | lbajardsilogic |
---|---|
date | Fri, 11 May 2007 09:08:14 +0000 |
parents | |
children | c5970f7af886 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:fc9323a41f5a |
---|---|
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 and QMUL. | |
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 "Preferences.h" | |
17 | |
18 #include "Exceptions.h" | |
19 | |
20 #include "TempDirectory.h" | |
21 | |
22 #include <QDir> | |
23 #include <QFileInfo> | |
24 #include <QMutex> | |
25 #include <QSettings> | |
26 | |
27 Preferences * | |
28 Preferences::m_instance = 0; | |
29 | |
30 Preferences * | |
31 Preferences::getInstance() | |
32 { | |
33 if (!m_instance) m_instance = new Preferences(); | |
34 return m_instance; | |
35 } | |
36 | |
37 Preferences::Preferences() : | |
38 m_spectrogramSmoothing(SpectrogramZeroPadded), | |
39 m_tuningFrequency(440), | |
40 m_propertyBoxLayout(VerticallyStacked), | |
41 m_windowType(HanningWindow), | |
42 m_resampleQuality(1) | |
43 { | |
44 QSettings settings; | |
45 settings.beginGroup("Preferences"); | |
46 m_spectrogramSmoothing = SpectrogramSmoothing | |
47 (settings.value("spectrogram-smoothing", int(m_spectrogramSmoothing)).toInt()); | |
48 m_tuningFrequency = settings.value("tuning-frequency", 440.f).toDouble(); | |
49 m_propertyBoxLayout = PropertyBoxLayout | |
50 (settings.value("property-box-layout", int(VerticallyStacked)).toInt()); | |
51 m_windowType = WindowType | |
52 (settings.value("window-type", int(HanningWindow)).toInt()); | |
53 m_resampleQuality = settings.value("resample-quality", 1).toInt(); | |
54 settings.endGroup(); | |
55 } | |
56 | |
57 Preferences::~Preferences() | |
58 { | |
59 } | |
60 | |
61 Preferences::PropertyList | |
62 Preferences::getProperties() const | |
63 { | |
64 PropertyList props; | |
65 props.push_back("Spectrogram Smoothing"); | |
66 props.push_back("Tuning Frequency"); | |
67 props.push_back("Property Box Layout"); | |
68 props.push_back("Window Type"); | |
69 props.push_back("Resample Quality"); | |
70 return props; | |
71 } | |
72 | |
73 QString | |
74 Preferences::getPropertyLabel(const PropertyName &name) const | |
75 { | |
76 if (name == "Spectrogram Smoothing") { | |
77 return tr("Spectrogram y-axis smoothing:"); | |
78 } | |
79 if (name == "Tuning Frequency") { | |
80 return tr("Frequency of concert A"); | |
81 } | |
82 if (name == "Property Box Layout") { | |
83 return tr("Property box layout"); | |
84 } | |
85 if (name == "Window Type") { | |
86 return tr("Spectral analysis window shape"); | |
87 } | |
88 if (name == "Resample Quality") { | |
89 return tr("Playback resampler type"); | |
90 } | |
91 return name; | |
92 } | |
93 | |
94 Preferences::PropertyType | |
95 Preferences::getPropertyType(const PropertyName &name) const | |
96 { | |
97 if (name == "Spectrogram Smoothing") { | |
98 return ValueProperty; | |
99 } | |
100 if (name == "Tuning Frequency") { | |
101 return RangeProperty; | |
102 } | |
103 if (name == "Property Box Layout") { | |
104 return ValueProperty; | |
105 } | |
106 if (name == "Window Type") { | |
107 return ValueProperty; | |
108 } | |
109 if (name == "Resample Quality") { | |
110 return ValueProperty; | |
111 } | |
112 return InvalidProperty; | |
113 } | |
114 | |
115 int | |
116 Preferences::getPropertyRangeAndValue(const PropertyName &name, | |
117 int *min, int *max, int *deflt) const | |
118 { | |
119 if (name == "Spectrogram Smoothing") { | |
120 if (min) *min = 0; | |
121 if (max) *max = 2; | |
122 if (deflt) *deflt = int(SpectrogramZeroPadded); | |
123 return int(m_spectrogramSmoothing); | |
124 } | |
125 | |
126 //!!! freq mapping | |
127 | |
128 if (name == "Property Box Layout") { | |
129 if (min) *min = 0; | |
130 if (max) *max = 1; | |
131 if (deflt) *deflt = 0; | |
132 return m_propertyBoxLayout == Layered ? 1 : 0; | |
133 } | |
134 | |
135 if (name == "Window Type") { | |
136 if (min) *min = int(RectangularWindow); | |
137 if (max) *max = int(BlackmanHarrisWindow); | |
138 if (deflt) *deflt = int(HanningWindow); | |
139 return int(m_windowType); | |
140 } | |
141 | |
142 if (name == "Resample Quality") { | |
143 if (min) *min = 0; | |
144 if (max) *max = 2; | |
145 if (deflt) *deflt = 1; | |
146 return m_resampleQuality; | |
147 } | |
148 | |
149 return 0; | |
150 } | |
151 | |
152 QString | |
153 Preferences::getPropertyValueLabel(const PropertyName &name, | |
154 int value) const | |
155 { | |
156 if (name == "Property Box Layout") { | |
157 if (value == 0) return tr("Show boxes for all panes"); | |
158 else return tr("Show box for current pane only"); | |
159 } | |
160 if (name == "Window Type") { | |
161 switch (WindowType(value)) { | |
162 case RectangularWindow: return tr("Rectangular"); | |
163 case BartlettWindow: return tr("Triangular"); | |
164 case HammingWindow: return tr("Hamming"); | |
165 case HanningWindow: return tr("Hanning"); | |
166 case BlackmanWindow: return tr("Blackman"); | |
167 case GaussianWindow: return tr("Gaussian"); | |
168 case ParzenWindow: return tr("Parzen"); | |
169 case NuttallWindow: return tr("Nuttall"); | |
170 case BlackmanHarrisWindow: return tr("Blackman-Harris"); | |
171 } | |
172 } | |
173 if (name == "Resample Quality") { | |
174 switch (value) { | |
175 case 0: return tr("Fastest"); | |
176 case 1: return tr("Standard"); | |
177 case 2: return tr("Highest quality"); | |
178 } | |
179 } | |
180 if (name == "Spectrogram Smoothing") { | |
181 switch (value) { | |
182 case NoSpectrogramSmoothing: return tr("None - blocky but accurate"); | |
183 case SpectrogramInterpolated: return tr("Interpolate - fast but fuzzy"); | |
184 case SpectrogramZeroPadded: return tr("Zero pad FFT - slow but clear"); | |
185 } | |
186 } | |
187 | |
188 return ""; | |
189 } | |
190 | |
191 QString | |
192 Preferences::getPropertyContainerName() const | |
193 { | |
194 return tr("Preferences"); | |
195 } | |
196 | |
197 QString | |
198 Preferences::getPropertyContainerIconName() const | |
199 { | |
200 return "preferences"; | |
201 } | |
202 | |
203 void | |
204 Preferences::setProperty(const PropertyName &name, int value) | |
205 { | |
206 if (name == "Spectrogram Smoothing") { | |
207 setSpectrogramSmoothing(SpectrogramSmoothing(value)); | |
208 } else if (name == "Tuning Frequency") { | |
209 //!!! | |
210 } else if (name == "Property Box Layout") { | |
211 setPropertyBoxLayout(value == 0 ? VerticallyStacked : Layered); | |
212 } else if (name == "Window Type") { | |
213 setWindowType(WindowType(value)); | |
214 } else if (name == "Resample Quality") { | |
215 setResampleQuality(value); | |
216 } | |
217 } | |
218 | |
219 void | |
220 Preferences::setSpectrogramSmoothing(SpectrogramSmoothing smoothing) | |
221 { | |
222 if (m_spectrogramSmoothing != smoothing) { | |
223 | |
224 // "smoothing" is one of those words that looks increasingly | |
225 // ridiculous the more you see it. Smoothing smoothing smoothing. | |
226 m_spectrogramSmoothing = smoothing; | |
227 | |
228 QSettings settings; | |
229 settings.beginGroup("Preferences"); | |
230 settings.setValue("spectrogram-smoothing", int(smoothing)); | |
231 settings.endGroup(); | |
232 emit propertyChanged("Spectrogram Smoothing"); | |
233 } | |
234 } | |
235 | |
236 void | |
237 Preferences::setTuningFrequency(float freq) | |
238 { | |
239 if (m_tuningFrequency != freq) { | |
240 m_tuningFrequency = freq; | |
241 QSettings settings; | |
242 settings.beginGroup("Preferences"); | |
243 settings.setValue("tuning-frequency", freq); | |
244 settings.endGroup(); | |
245 emit propertyChanged("Tuning Frequency"); | |
246 } | |
247 } | |
248 | |
249 void | |
250 Preferences::setPropertyBoxLayout(PropertyBoxLayout layout) | |
251 { | |
252 if (m_propertyBoxLayout != layout) { | |
253 m_propertyBoxLayout = layout; | |
254 QSettings settings; | |
255 settings.beginGroup("Preferences"); | |
256 settings.setValue("property-box-layout", int(layout)); | |
257 settings.endGroup(); | |
258 emit propertyChanged("Property Box Layout"); | |
259 } | |
260 } | |
261 | |
262 void | |
263 Preferences::setWindowType(WindowType type) | |
264 { | |
265 if (m_windowType != type) { | |
266 m_windowType = type; | |
267 QSettings settings; | |
268 settings.beginGroup("Preferences"); | |
269 settings.setValue("window-type", int(type)); | |
270 settings.endGroup(); | |
271 emit propertyChanged("Window Type"); | |
272 } | |
273 } | |
274 | |
275 void | |
276 Preferences::setResampleQuality(int q) | |
277 { | |
278 if (m_resampleQuality != q) { | |
279 m_resampleQuality = q; | |
280 QSettings settings; | |
281 settings.beginGroup("Preferences"); | |
282 settings.setValue("resample-quality", q); | |
283 settings.endGroup(); | |
284 emit propertyChanged("Resample Quality"); | |
285 } | |
286 } |