annotate base/Preferences.cpp @ 142:0ba66b160a02

* Add frequency plot to window shape preference -- just because... * Fix some window shapes
author Chris Cannam
date Mon, 24 Jul 2006 14:36:35 +0000
parents 4f26f623a8bc
children 82f529a08cf3
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@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@141 44 return tr("Smooth spectrogram display by zero padding FFT");
Chris@136 45 }
Chris@136 46 if (name == "Tuning Frequency") {
Chris@141 47 return tr("Frequency of concert A");
Chris@136 48 }
Chris@138 49 if (name == "Property Box Layout") {
Chris@141 50 return tr("Property box layout");
Chris@138 51 }
Chris@140 52 if (name == "Window Type") {
Chris@141 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@142 96 if (max) *max = int(BlackmanHarrisWindow);
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@141 108 if (value == 0) return tr("Show boxes for all panes");
Chris@141 109 else return tr("Show box for current pane only");
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@141 114 case BartlettWindow: return tr("Triangular");
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@142 120 case NuttallWindow: return tr("Nuttall");
Chris@142 121 case BlackmanHarrisWindow: return tr("Blackman-Harris");
Chris@140 122 }
Chris@140 123 }
Chris@136 124 return "";
Chris@136 125 }
Chris@136 126
Chris@136 127 QString
Chris@136 128 Preferences::getPropertyContainerName() const
Chris@136 129 {
Chris@136 130 return tr("Preferences");
Chris@136 131 }
Chris@136 132
Chris@136 133 QString
Chris@136 134 Preferences::getPropertyContainerIconName() const
Chris@136 135 {
Chris@136 136 return "preferences";
Chris@136 137 }
Chris@136 138
Chris@136 139 void
Chris@136 140 Preferences::setProperty(const PropertyName &name, int value)
Chris@136 141 {
Chris@136 142 if (name == "Smooth Spectrogram") {
Chris@136 143 setSmoothSpectrogram(value > 0.1);
Chris@136 144 } else if (name == "Tuning Frequency") {
Chris@136 145 //!!!
Chris@138 146 } else if (name == "Property Box Layout") {
Chris@138 147 setPropertyBoxLayout(value == 0 ? VerticallyStacked : Layered);
Chris@140 148 } else if (name == "Window Type") {
Chris@140 149 setWindowType(WindowType(value));
Chris@136 150 }
Chris@136 151 }
Chris@136 152
Chris@136 153 void
Chris@136 154 Preferences::setSmoothSpectrogram(bool smooth)
Chris@136 155 {
Chris@138 156 if (m_smoothSpectrogram != smooth) {
Chris@138 157 m_smoothSpectrogram = smooth;
Chris@141 158 emit propertyChanged("Smooth Spectrogram");
Chris@138 159 }
Chris@136 160 }
Chris@136 161
Chris@136 162 void
Chris@136 163 Preferences::setTuningFrequency(float freq)
Chris@136 164 {
Chris@138 165 if (m_tuningFrequency != freq) {
Chris@138 166 m_tuningFrequency = freq;
Chris@141 167 emit propertyChanged("Tuning Frequency");
Chris@138 168 }
Chris@136 169 }
Chris@136 170
Chris@138 171 void
Chris@138 172 Preferences::setPropertyBoxLayout(PropertyBoxLayout layout)
Chris@138 173 {
Chris@138 174 if (m_propertyBoxLayout != layout) {
Chris@138 175 m_propertyBoxLayout = layout;
Chris@141 176 emit propertyChanged("Property Box Layout");
Chris@138 177 }
Chris@138 178 }
Chris@138 179
Chris@140 180 void
Chris@140 181 Preferences::setWindowType(WindowType type)
Chris@140 182 {
Chris@140 183 if (m_windowType != type) {
Chris@140 184 m_windowType = type;
Chris@141 185 emit propertyChanged("Window Type");
Chris@140 186 }
Chris@140 187 }
Chris@140 188