changeset 136:e4acb520ad2a

* fledgling preferences stuff
author Chris Cannam
date Mon, 10 Jul 2006 13:54:49 +0000 (2006-07-10)
parents fb8422cf4326
children 0aafdda005ce
files base/Preferences.cpp base/Preferences.h base/PropertyContainer.h
diffstat 3 files changed, 174 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/base/Preferences.cpp	Mon Jul 10 13:54:49 2006 +0000
@@ -0,0 +1,118 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006 Chris Cannam.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#include "Preferences.h"
+
+Preferences *
+Preferences::m_instance = new Preferences();
+
+Preferences::Preferences() :
+    m_smoothSpectrogram(false),
+    m_tuningFrequency(440)
+{
+}
+
+Preferences::PropertyList
+Preferences::getProperties() const
+{
+    PropertyList props;
+    props.push_back("Smooth Spectrogram");
+    props.push_back("Tuning Frequency");
+    return props;
+}
+
+QString
+Preferences::getPropertyLabel(const PropertyName &name) const
+{
+    if (name == "Smooth Spectrogram") {
+        return tr("Spectrogram Display Smoothing");
+    }
+    if (name == "Tuning Frequency") {
+        return tr("Tuning Frequency (concert A)");
+    }
+    return name;
+}
+
+Preferences::PropertyType
+Preferences::getPropertyType(const PropertyName &name) const
+{
+    if (name == "Smooth Spectrogram") {
+        return ToggleProperty;
+    }
+    if (name == "Tuning Frequency") {
+        return RangeProperty;
+    }
+    return InvalidProperty;
+}
+
+int
+Preferences::getPropertyRangeAndValue(const PropertyName &name,
+                                      int *min, int *max) const
+{
+    if (name == "Smooth Spectrogram") {
+        if (min) *min = 0;
+        if (max) *max = 1;
+        return m_smoothSpectrogram ? 1 : 0;
+    }
+
+    //!!! freq mapping
+
+    return 0;
+}
+
+QString
+Preferences::getPropertyValueLabel(const PropertyName &name,
+                                   int value) const
+{
+    //!!!
+    return "";
+}
+
+QString
+Preferences::getPropertyContainerName() const
+{
+    return tr("Preferences");
+}
+
+QString
+Preferences::getPropertyContainerIconName() const
+{
+    return "preferences";
+}
+
+void
+Preferences::setProperty(const PropertyName &name, int value) 
+{
+    if (name == "Smooth Spectrogram") {
+        setSmoothSpectrogram(value > 0.1);
+    } else if (name == "Tuning Frequency") {
+        //!!!
+    }
+}
+
+void
+Preferences::setSmoothSpectrogram(bool smooth)
+{
+    m_smoothSpectrogram = smooth;
+//!!!    emit 
+}
+
+void
+Preferences::setTuningFrequency(float freq)
+{
+    m_tuningFrequency = freq;
+    //!!! emit
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/base/Preferences.h	Mon Jul 10 13:54:49 2006 +0000
@@ -0,0 +1,55 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006 Chris Cannam.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#ifndef _PREFERENCES_H_
+#define _PREFERENCES_H_
+
+#include "PropertyContainer.h"
+
+class Preferences : public PropertyContainer
+{
+    Q_OBJECT
+
+public:
+    static Preferences *getInstance() { return m_instance; }
+
+    virtual PropertyList getProperties() const;
+    virtual QString getPropertyLabel(const PropertyName &) const;
+    virtual PropertyType getPropertyType(const PropertyName &) const;
+    virtual int getPropertyRangeAndValue(const PropertyName &, int *, int *) const;
+    virtual QString getPropertyValueLabel(const PropertyName &, int value) const;
+    virtual QString getPropertyContainerName() const;
+    virtual QString getPropertyContainerIconName() const;
+
+    bool getSmoothSpectrogram() const { return m_smoothSpectrogram; }
+    float getTuningFrequency() const { return m_tuningFrequency; }
+
+public slots:
+    virtual void setProperty(const PropertyName &, int);
+
+    void setSmoothSpectrogram(bool smooth);
+    void setTuningFrequency(float freq);
+
+private:
+    Preferences(); 
+    virtual ~Preferences() { }
+
+    static Preferences *m_instance;
+
+    bool m_smoothSpectrogram;
+    float m_tuningFrequency;
+};
+
+#endif
--- a/base/PropertyContainer.h	Fri Jul 07 16:02:22 2006 +0000
+++ b/base/PropertyContainer.h	Mon Jul 10 13:54:49 2006 +0000
@@ -102,6 +102,7 @@
 
     /**
      * Set a property using a command, supporting undo and redo.
+     * The default implementation should work for most subclasses.
      */
     virtual void setPropertyWithCommand(const PropertyName &, int value);