annotate base/RangeMapper.h @ 703:b1b40fa0cf9c sonic-annotator-0.6

Added tag sv_v1.9 for changeset 97fbb6b3e749
author Chris Cannam
date Wed, 28 Sep 2011 16:44:38 +0100
parents b4a8d8221eaf
children eb6b6a88faed
rev   line source
Chris@189 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@189 2
Chris@189 3 /*
Chris@189 4 Sonic Visualiser
Chris@189 5 An audio file viewer and annotation editor.
Chris@189 6 Centre for Digital Music, Queen Mary, University of London.
Chris@202 7 This file copyright 2006 QMUL.
Chris@189 8
Chris@189 9 This program is free software; you can redistribute it and/or
Chris@189 10 modify it under the terms of the GNU General Public License as
Chris@189 11 published by the Free Software Foundation; either version 2 of the
Chris@189 12 License, or (at your option) any later version. See the file
Chris@189 13 COPYING included with this distribution for more information.
Chris@189 14 */
Chris@189 15
Chris@189 16 #ifndef _RANGE_MAPPER_H_
Chris@189 17 #define _RANGE_MAPPER_H_
Chris@189 18
Chris@189 19 #include <QString>
Chris@189 20
Chris@686 21 #include "Debug.h"
Chris@686 22
Chris@189 23
Chris@189 24 class RangeMapper
Chris@189 25 {
Chris@189 26 public:
Chris@189 27 virtual ~RangeMapper() { }
Chris@189 28 virtual int getPositionForValue(float value) const = 0;
Chris@189 29 virtual float getValueForPosition(int position) const = 0;
Chris@189 30 virtual QString getUnit() const { return ""; }
Chris@189 31 };
Chris@189 32
Chris@189 33
Chris@189 34 class LinearRangeMapper : public RangeMapper
Chris@189 35 {
Chris@189 36 public:
Chris@189 37 LinearRangeMapper(int minpos, int maxpos,
Chris@189 38 float minval, float maxval,
Chris@464 39 QString unit = "", bool inverted = false);
Chris@189 40
Chris@189 41 virtual int getPositionForValue(float value) const;
Chris@189 42 virtual float getValueForPosition(int position) const;
Chris@189 43
Chris@189 44 virtual QString getUnit() const { return m_unit; }
Chris@189 45
Chris@189 46 protected:
Chris@189 47 int m_minpos;
Chris@189 48 int m_maxpos;
Chris@189 49 float m_minval;
Chris@189 50 float m_maxval;
Chris@189 51 QString m_unit;
Chris@464 52 bool m_inverted;
Chris@189 53 };
Chris@189 54
Chris@189 55
Chris@189 56 class LogRangeMapper : public RangeMapper
Chris@189 57 {
Chris@189 58 public:
Chris@189 59 LogRangeMapper(int minpos, int maxpos,
Chris@356 60 float minval, float maxval,
Chris@464 61 QString m_unit = "", bool inverted = false);
Chris@189 62
Chris@356 63 static void convertRatioMinLog(float ratio, float minlog,
Chris@356 64 int minpos, int maxpos,
Chris@356 65 float &minval, float &maxval);
Chris@356 66
Chris@356 67 static void convertMinMax(int minpos, int maxpos,
Chris@356 68 float minval, float maxval,
Chris@356 69 float &ratio, float &minlog);
Chris@356 70
Chris@189 71 virtual int getPositionForValue(float value) const;
Chris@189 72 virtual float getValueForPosition(int position) const;
Chris@189 73
Chris@189 74 virtual QString getUnit() const { return m_unit; }
Chris@189 75
Chris@189 76 protected:
Chris@189 77 int m_minpos;
Chris@189 78 int m_maxpos;
Chris@189 79 float m_ratio;
Chris@189 80 float m_minlog;
Chris@189 81 float m_maxlog;
Chris@189 82 QString m_unit;
Chris@464 83 bool m_inverted;
Chris@189 84 };
Chris@189 85
Chris@189 86
Chris@189 87 #endif