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@136
|
18 Preferences *
|
Chris@136
|
19 Preferences::m_instance = new Preferences();
|
Chris@136
|
20
|
Chris@136
|
21 Preferences::Preferences() :
|
Chris@137
|
22 m_smoothSpectrogram(true),
|
Chris@140
|
23 m_tuningFrequency(440),
|
Chris@140
|
24 m_propertyBoxLayout(VerticallyStacked),
|
Chris@140
|
25 m_windowType(HanningWindow)
|
Chris@136
|
26 {
|
Chris@136
|
27 }
|
Chris@136
|
28
|
Chris@136
|
29 Preferences::PropertyList
|
Chris@136
|
30 Preferences::getProperties() const
|
Chris@136
|
31 {
|
Chris@136
|
32 PropertyList props;
|
Chris@136
|
33 props.push_back("Smooth Spectrogram");
|
Chris@136
|
34 props.push_back("Tuning Frequency");
|
Chris@138
|
35 props.push_back("Property Box Layout");
|
Chris@140
|
36 props.push_back("Window Type");
|
Chris@136
|
37 return props;
|
Chris@136
|
38 }
|
Chris@136
|
39
|
Chris@136
|
40 QString
|
Chris@136
|
41 Preferences::getPropertyLabel(const PropertyName &name) const
|
Chris@136
|
42 {
|
Chris@136
|
43 if (name == "Smooth Spectrogram") {
|
Chris@136
|
44 return tr("Spectrogram Display Smoothing");
|
Chris@136
|
45 }
|
Chris@136
|
46 if (name == "Tuning Frequency") {
|
Chris@136
|
47 return tr("Tuning Frequency (concert A)");
|
Chris@136
|
48 }
|
Chris@138
|
49 if (name == "Property Box Layout") {
|
Chris@138
|
50 return tr("Arrangement of Layer Properties");
|
Chris@138
|
51 }
|
Chris@140
|
52 if (name == "Window Type") {
|
Chris@140
|
53 return tr("Spectral Analysis Window Shape");
|
Chris@140
|
54 }
|
Chris@136
|
55 return name;
|
Chris@136
|
56 }
|
Chris@136
|
57
|
Chris@136
|
58 Preferences::PropertyType
|
Chris@136
|
59 Preferences::getPropertyType(const PropertyName &name) const
|
Chris@136
|
60 {
|
Chris@136
|
61 if (name == "Smooth Spectrogram") {
|
Chris@136
|
62 return ToggleProperty;
|
Chris@136
|
63 }
|
Chris@136
|
64 if (name == "Tuning Frequency") {
|
Chris@136
|
65 return RangeProperty;
|
Chris@136
|
66 }
|
Chris@138
|
67 if (name == "Property Box Layout") {
|
Chris@138
|
68 return ValueProperty;
|
Chris@138
|
69 }
|
Chris@140
|
70 if (name == "Window Type") {
|
Chris@140
|
71 return ValueProperty;
|
Chris@140
|
72 }
|
Chris@136
|
73 return InvalidProperty;
|
Chris@136
|
74 }
|
Chris@136
|
75
|
Chris@136
|
76 int
|
Chris@136
|
77 Preferences::getPropertyRangeAndValue(const PropertyName &name,
|
Chris@136
|
78 int *min, int *max) const
|
Chris@136
|
79 {
|
Chris@136
|
80 if (name == "Smooth Spectrogram") {
|
Chris@136
|
81 if (min) *min = 0;
|
Chris@136
|
82 if (max) *max = 1;
|
Chris@136
|
83 return m_smoothSpectrogram ? 1 : 0;
|
Chris@136
|
84 }
|
Chris@136
|
85
|
Chris@136
|
86 //!!! freq mapping
|
Chris@136
|
87
|
Chris@138
|
88 if (name == "Property Box Layout") {
|
Chris@138
|
89 if (min) *min = 0;
|
Chris@138
|
90 if (max) *max = 1;
|
Chris@138
|
91 return m_propertyBoxLayout == Layered ? 1 : 0;
|
Chris@138
|
92 }
|
Chris@138
|
93
|
Chris@140
|
94 if (name == "Window Type") {
|
Chris@140
|
95 if (min) *min = int(RectangularWindow);
|
Chris@140
|
96 if (max) *max = int(ParzenWindow);
|
Chris@140
|
97 return int(m_windowType);
|
Chris@140
|
98 }
|
Chris@140
|
99
|
Chris@136
|
100 return 0;
|
Chris@136
|
101 }
|
Chris@136
|
102
|
Chris@136
|
103 QString
|
Chris@136
|
104 Preferences::getPropertyValueLabel(const PropertyName &name,
|
Chris@136
|
105 int value) const
|
Chris@136
|
106 {
|
Chris@138
|
107 if (name == "Property Box Layout") {
|
Chris@138
|
108 if (value == 0) return tr("Vertically Stacked");
|
Chris@138
|
109 else return tr("Layered");
|
Chris@138
|
110 }
|
Chris@140
|
111 if (name == "Window Type") {
|
Chris@140
|
112 switch (WindowType(value)) {
|
Chris@140
|
113 case RectangularWindow: return tr("Rectangular");
|
Chris@140
|
114 case BartlettWindow: return tr("Bartlett");
|
Chris@140
|
115 case HammingWindow: return tr("Hamming");
|
Chris@140
|
116 case HanningWindow: return tr("Hanning");
|
Chris@140
|
117 case BlackmanWindow: return tr("Blackman");
|
Chris@140
|
118 case GaussianWindow: return tr("Gaussian");
|
Chris@140
|
119 case ParzenWindow: return tr("Parzen");
|
Chris@140
|
120 }
|
Chris@140
|
121 }
|
Chris@136
|
122 return "";
|
Chris@136
|
123 }
|
Chris@136
|
124
|
Chris@136
|
125 QString
|
Chris@136
|
126 Preferences::getPropertyContainerName() const
|
Chris@136
|
127 {
|
Chris@136
|
128 return tr("Preferences");
|
Chris@136
|
129 }
|
Chris@136
|
130
|
Chris@136
|
131 QString
|
Chris@136
|
132 Preferences::getPropertyContainerIconName() const
|
Chris@136
|
133 {
|
Chris@136
|
134 return "preferences";
|
Chris@136
|
135 }
|
Chris@136
|
136
|
Chris@136
|
137 void
|
Chris@136
|
138 Preferences::setProperty(const PropertyName &name, int value)
|
Chris@136
|
139 {
|
Chris@136
|
140 if (name == "Smooth Spectrogram") {
|
Chris@136
|
141 setSmoothSpectrogram(value > 0.1);
|
Chris@136
|
142 } else if (name == "Tuning Frequency") {
|
Chris@136
|
143 //!!!
|
Chris@138
|
144 } else if (name == "Property Box Layout") {
|
Chris@138
|
145 setPropertyBoxLayout(value == 0 ? VerticallyStacked : Layered);
|
Chris@140
|
146 } else if (name == "Window Type") {
|
Chris@140
|
147 setWindowType(WindowType(value));
|
Chris@136
|
148 }
|
Chris@136
|
149 }
|
Chris@136
|
150
|
Chris@136
|
151 void
|
Chris@136
|
152 Preferences::setSmoothSpectrogram(bool smooth)
|
Chris@136
|
153 {
|
Chris@138
|
154 if (m_smoothSpectrogram != smooth) {
|
Chris@138
|
155 m_smoothSpectrogram = smooth;
|
Chris@136
|
156 //!!! emit
|
Chris@138
|
157 }
|
Chris@136
|
158 }
|
Chris@136
|
159
|
Chris@136
|
160 void
|
Chris@136
|
161 Preferences::setTuningFrequency(float freq)
|
Chris@136
|
162 {
|
Chris@138
|
163 if (m_tuningFrequency != freq) {
|
Chris@138
|
164 m_tuningFrequency = freq;
|
Chris@138
|
165 //!!! emit
|
Chris@138
|
166 }
|
Chris@136
|
167 }
|
Chris@136
|
168
|
Chris@138
|
169 void
|
Chris@138
|
170 Preferences::setPropertyBoxLayout(PropertyBoxLayout layout)
|
Chris@138
|
171 {
|
Chris@138
|
172 if (m_propertyBoxLayout != layout) {
|
Chris@138
|
173 m_propertyBoxLayout = layout;
|
Chris@138
|
174 //!!! emit
|
Chris@138
|
175 }
|
Chris@138
|
176 }
|
Chris@138
|
177
|
Chris@140
|
178 void
|
Chris@140
|
179 Preferences::setWindowType(WindowType type)
|
Chris@140
|
180 {
|
Chris@140
|
181 if (m_windowType != type) {
|
Chris@140
|
182 m_windowType = type;
|
Chris@140
|
183 //!!! emit
|
Chris@140
|
184 }
|
Chris@140
|
185 }
|
Chris@140
|
186
|