RangeMapper.h

Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006 QMUL.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #ifndef _RANGE_MAPPER_H_
00017 #define _RANGE_MAPPER_H_
00018 
00019 #include <QString>
00020 
00021 
00022 class RangeMapper 
00023 {
00024 public:
00025     virtual ~RangeMapper() { }
00026     virtual int getPositionForValue(float value) const = 0;
00027     virtual float getValueForPosition(int position) const = 0;
00028     virtual QString getUnit() const { return ""; }
00029 };
00030 
00031 
00032 class LinearRangeMapper : public RangeMapper
00033 {
00034 public:
00035     LinearRangeMapper(int minpos, int maxpos,
00036                       float minval, float maxval,
00037                       QString unit = "");
00038     
00039     virtual int getPositionForValue(float value) const;
00040     virtual float getValueForPosition(int position) const;
00041 
00042     virtual QString getUnit() const { return m_unit; }
00043 
00044 protected:
00045     int m_minpos;
00046     int m_maxpos;
00047     float m_minval;
00048     float m_maxval;
00049     QString m_unit;
00050 };
00051 
00052 
00053 class LogRangeMapper : public RangeMapper
00054 {
00055 public:
00056     LogRangeMapper(int minpos, int maxpos,
00057                    float minval, float maxval,
00058                    QString m_unit = "");
00059 
00060     static void convertRatioMinLog(float ratio, float minlog,
00061                                    int minpos, int maxpos,
00062                                    float &minval, float &maxval);
00063 
00064     static void convertMinMax(int minpos, int maxpos,
00065                               float minval, float maxval,
00066                               float &ratio, float &minlog);
00067 
00068     virtual int getPositionForValue(float value) const;
00069     virtual float getValueForPosition(int position) const;
00070 
00071     virtual QString getUnit() const { return m_unit; }
00072 
00073 protected:
00074     int m_minpos;
00075     int m_maxpos;
00076     float m_ratio;
00077     float m_minlog;
00078     float m_maxlog;
00079     QString m_unit;
00080 };
00081 
00082 
00083 #endif

Generated on Wed Feb 20 15:45:27 2008 for SonicVisualiser by  doxygen 1.5.1