Chris@136: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@136: Chris@136: /* Chris@136: Sonic Visualiser Chris@136: An audio file viewer and annotation editor. Chris@136: Centre for Digital Music, Queen Mary, University of London. Chris@136: This file copyright 2006 Chris Cannam. Chris@136: Chris@136: This program is free software; you can redistribute it and/or Chris@136: modify it under the terms of the GNU General Public License as Chris@136: published by the Free Software Foundation; either version 2 of the Chris@136: License, or (at your option) any later version. See the file Chris@136: COPYING included with this distribution for more information. Chris@136: */ Chris@136: Chris@136: #include "Preferences.h" Chris@136: Chris@136: Preferences * Chris@136: Preferences::m_instance = new Preferences(); Chris@136: Chris@136: Preferences::Preferences() : Chris@137: m_smoothSpectrogram(true), Chris@140: m_tuningFrequency(440), Chris@140: m_propertyBoxLayout(VerticallyStacked), Chris@140: m_windowType(HanningWindow) Chris@136: { Chris@136: } Chris@136: Chris@136: Preferences::PropertyList Chris@136: Preferences::getProperties() const Chris@136: { Chris@136: PropertyList props; Chris@136: props.push_back("Smooth Spectrogram"); Chris@136: props.push_back("Tuning Frequency"); Chris@138: props.push_back("Property Box Layout"); Chris@140: props.push_back("Window Type"); Chris@136: return props; Chris@136: } Chris@136: Chris@136: QString Chris@136: Preferences::getPropertyLabel(const PropertyName &name) const Chris@136: { Chris@136: if (name == "Smooth Spectrogram") { Chris@141: return tr("Smooth spectrogram display by zero padding FFT"); Chris@136: } Chris@136: if (name == "Tuning Frequency") { Chris@141: return tr("Frequency of concert A"); Chris@136: } Chris@138: if (name == "Property Box Layout") { Chris@141: return tr("Property box layout"); Chris@138: } Chris@140: if (name == "Window Type") { Chris@141: return tr("Spectral analysis window shape"); Chris@140: } Chris@136: return name; Chris@136: } Chris@136: Chris@136: Preferences::PropertyType Chris@136: Preferences::getPropertyType(const PropertyName &name) const Chris@136: { Chris@136: if (name == "Smooth Spectrogram") { Chris@136: return ToggleProperty; Chris@136: } Chris@136: if (name == "Tuning Frequency") { Chris@136: return RangeProperty; Chris@136: } Chris@138: if (name == "Property Box Layout") { Chris@138: return ValueProperty; Chris@138: } Chris@140: if (name == "Window Type") { Chris@140: return ValueProperty; Chris@140: } Chris@136: return InvalidProperty; Chris@136: } Chris@136: Chris@136: int Chris@136: Preferences::getPropertyRangeAndValue(const PropertyName &name, Chris@136: int *min, int *max) const Chris@136: { Chris@136: if (name == "Smooth Spectrogram") { Chris@136: if (min) *min = 0; Chris@136: if (max) *max = 1; Chris@136: return m_smoothSpectrogram ? 1 : 0; Chris@136: } Chris@136: Chris@136: //!!! freq mapping Chris@136: Chris@138: if (name == "Property Box Layout") { Chris@138: if (min) *min = 0; Chris@138: if (max) *max = 1; Chris@138: return m_propertyBoxLayout == Layered ? 1 : 0; Chris@138: } Chris@138: Chris@140: if (name == "Window Type") { Chris@140: if (min) *min = int(RectangularWindow); Chris@140: if (max) *max = int(ParzenWindow); Chris@140: return int(m_windowType); Chris@140: } Chris@140: Chris@136: return 0; Chris@136: } Chris@136: Chris@136: QString Chris@136: Preferences::getPropertyValueLabel(const PropertyName &name, Chris@136: int value) const Chris@136: { Chris@138: if (name == "Property Box Layout") { Chris@141: if (value == 0) return tr("Show boxes for all panes"); Chris@141: else return tr("Show box for current pane only"); Chris@138: } Chris@140: if (name == "Window Type") { Chris@140: switch (WindowType(value)) { Chris@140: case RectangularWindow: return tr("Rectangular"); Chris@141: case BartlettWindow: return tr("Triangular"); Chris@140: case HammingWindow: return tr("Hamming"); Chris@140: case HanningWindow: return tr("Hanning"); Chris@140: case BlackmanWindow: return tr("Blackman"); Chris@140: case GaussianWindow: return tr("Gaussian"); Chris@140: case ParzenWindow: return tr("Parzen"); Chris@140: } Chris@140: } Chris@136: return ""; Chris@136: } Chris@136: Chris@136: QString Chris@136: Preferences::getPropertyContainerName() const Chris@136: { Chris@136: return tr("Preferences"); Chris@136: } Chris@136: Chris@136: QString Chris@136: Preferences::getPropertyContainerIconName() const Chris@136: { Chris@136: return "preferences"; Chris@136: } Chris@136: Chris@136: void Chris@136: Preferences::setProperty(const PropertyName &name, int value) Chris@136: { Chris@136: if (name == "Smooth Spectrogram") { Chris@136: setSmoothSpectrogram(value > 0.1); Chris@136: } else if (name == "Tuning Frequency") { Chris@136: //!!! Chris@138: } else if (name == "Property Box Layout") { Chris@138: setPropertyBoxLayout(value == 0 ? VerticallyStacked : Layered); Chris@140: } else if (name == "Window Type") { Chris@140: setWindowType(WindowType(value)); Chris@136: } Chris@136: } Chris@136: Chris@136: void Chris@136: Preferences::setSmoothSpectrogram(bool smooth) Chris@136: { Chris@138: if (m_smoothSpectrogram != smooth) { Chris@138: m_smoothSpectrogram = smooth; Chris@141: emit propertyChanged("Smooth Spectrogram"); Chris@138: } Chris@136: } Chris@136: Chris@136: void Chris@136: Preferences::setTuningFrequency(float freq) Chris@136: { Chris@138: if (m_tuningFrequency != freq) { Chris@138: m_tuningFrequency = freq; Chris@141: emit propertyChanged("Tuning Frequency"); Chris@138: } Chris@136: } Chris@136: Chris@138: void Chris@138: Preferences::setPropertyBoxLayout(PropertyBoxLayout layout) Chris@138: { Chris@138: if (m_propertyBoxLayout != layout) { Chris@138: m_propertyBoxLayout = layout; Chris@141: emit propertyChanged("Property Box Layout"); Chris@138: } Chris@138: } Chris@138: Chris@140: void Chris@140: Preferences::setWindowType(WindowType type) Chris@140: { Chris@140: if (m_windowType != type) { Chris@140: m_windowType = type; Chris@141: emit propertyChanged("Window Type"); Chris@140: } Chris@140: } Chris@140: