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@136
|
23 m_tuningFrequency(440)
|
Chris@136
|
24 {
|
Chris@136
|
25 }
|
Chris@136
|
26
|
Chris@136
|
27 Preferences::PropertyList
|
Chris@136
|
28 Preferences::getProperties() const
|
Chris@136
|
29 {
|
Chris@136
|
30 PropertyList props;
|
Chris@136
|
31 props.push_back("Smooth Spectrogram");
|
Chris@136
|
32 props.push_back("Tuning Frequency");
|
Chris@138
|
33 props.push_back("Property Box Layout");
|
Chris@136
|
34 return props;
|
Chris@136
|
35 }
|
Chris@136
|
36
|
Chris@136
|
37 QString
|
Chris@136
|
38 Preferences::getPropertyLabel(const PropertyName &name) const
|
Chris@136
|
39 {
|
Chris@136
|
40 if (name == "Smooth Spectrogram") {
|
Chris@136
|
41 return tr("Spectrogram Display Smoothing");
|
Chris@136
|
42 }
|
Chris@136
|
43 if (name == "Tuning Frequency") {
|
Chris@136
|
44 return tr("Tuning Frequency (concert A)");
|
Chris@136
|
45 }
|
Chris@138
|
46 if (name == "Property Box Layout") {
|
Chris@138
|
47 return tr("Arrangement of Layer Properties");
|
Chris@138
|
48 }
|
Chris@136
|
49 return name;
|
Chris@136
|
50 }
|
Chris@136
|
51
|
Chris@136
|
52 Preferences::PropertyType
|
Chris@136
|
53 Preferences::getPropertyType(const PropertyName &name) const
|
Chris@136
|
54 {
|
Chris@136
|
55 if (name == "Smooth Spectrogram") {
|
Chris@136
|
56 return ToggleProperty;
|
Chris@136
|
57 }
|
Chris@136
|
58 if (name == "Tuning Frequency") {
|
Chris@136
|
59 return RangeProperty;
|
Chris@136
|
60 }
|
Chris@138
|
61 if (name == "Property Box Layout") {
|
Chris@138
|
62 return ValueProperty;
|
Chris@138
|
63 }
|
Chris@136
|
64 return InvalidProperty;
|
Chris@136
|
65 }
|
Chris@136
|
66
|
Chris@136
|
67 int
|
Chris@136
|
68 Preferences::getPropertyRangeAndValue(const PropertyName &name,
|
Chris@136
|
69 int *min, int *max) const
|
Chris@136
|
70 {
|
Chris@136
|
71 if (name == "Smooth Spectrogram") {
|
Chris@136
|
72 if (min) *min = 0;
|
Chris@136
|
73 if (max) *max = 1;
|
Chris@136
|
74 return m_smoothSpectrogram ? 1 : 0;
|
Chris@136
|
75 }
|
Chris@136
|
76
|
Chris@136
|
77 //!!! freq mapping
|
Chris@136
|
78
|
Chris@138
|
79 if (name == "Property Box Layout") {
|
Chris@138
|
80 if (min) *min = 0;
|
Chris@138
|
81 if (max) *max = 1;
|
Chris@138
|
82 return m_propertyBoxLayout == Layered ? 1 : 0;
|
Chris@138
|
83 }
|
Chris@138
|
84
|
Chris@136
|
85 return 0;
|
Chris@136
|
86 }
|
Chris@136
|
87
|
Chris@136
|
88 QString
|
Chris@136
|
89 Preferences::getPropertyValueLabel(const PropertyName &name,
|
Chris@136
|
90 int value) const
|
Chris@136
|
91 {
|
Chris@138
|
92 if (name == "Property Box Layout") {
|
Chris@138
|
93 if (value == 0) return tr("Vertically Stacked");
|
Chris@138
|
94 else return tr("Layered");
|
Chris@138
|
95 }
|
Chris@136
|
96 return "";
|
Chris@136
|
97 }
|
Chris@136
|
98
|
Chris@136
|
99 QString
|
Chris@136
|
100 Preferences::getPropertyContainerName() const
|
Chris@136
|
101 {
|
Chris@136
|
102 return tr("Preferences");
|
Chris@136
|
103 }
|
Chris@136
|
104
|
Chris@136
|
105 QString
|
Chris@136
|
106 Preferences::getPropertyContainerIconName() const
|
Chris@136
|
107 {
|
Chris@136
|
108 return "preferences";
|
Chris@136
|
109 }
|
Chris@136
|
110
|
Chris@136
|
111 void
|
Chris@136
|
112 Preferences::setProperty(const PropertyName &name, int value)
|
Chris@136
|
113 {
|
Chris@136
|
114 if (name == "Smooth Spectrogram") {
|
Chris@136
|
115 setSmoothSpectrogram(value > 0.1);
|
Chris@136
|
116 } else if (name == "Tuning Frequency") {
|
Chris@136
|
117 //!!!
|
Chris@138
|
118 } else if (name == "Property Box Layout") {
|
Chris@138
|
119 setPropertyBoxLayout(value == 0 ? VerticallyStacked : Layered);
|
Chris@136
|
120 }
|
Chris@136
|
121 }
|
Chris@136
|
122
|
Chris@136
|
123 void
|
Chris@136
|
124 Preferences::setSmoothSpectrogram(bool smooth)
|
Chris@136
|
125 {
|
Chris@138
|
126 if (m_smoothSpectrogram != smooth) {
|
Chris@138
|
127 m_smoothSpectrogram = smooth;
|
Chris@136
|
128 //!!! emit
|
Chris@138
|
129 }
|
Chris@136
|
130 }
|
Chris@136
|
131
|
Chris@136
|
132 void
|
Chris@136
|
133 Preferences::setTuningFrequency(float freq)
|
Chris@136
|
134 {
|
Chris@138
|
135 if (m_tuningFrequency != freq) {
|
Chris@138
|
136 m_tuningFrequency = freq;
|
Chris@138
|
137 //!!! emit
|
Chris@138
|
138 }
|
Chris@136
|
139 }
|
Chris@136
|
140
|
Chris@138
|
141 void
|
Chris@138
|
142 Preferences::setPropertyBoxLayout(PropertyBoxLayout layout)
|
Chris@138
|
143 {
|
Chris@138
|
144 if (m_propertyBoxLayout != layout) {
|
Chris@138
|
145 m_propertyBoxLayout = layout;
|
Chris@138
|
146 //!!! emit
|
Chris@138
|
147 }
|
Chris@138
|
148 }
|
Chris@138
|
149
|