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@189
|
21
|
Chris@189
|
22 class RangeMapper
|
Chris@189
|
23 {
|
Chris@189
|
24 public:
|
Chris@189
|
25 virtual ~RangeMapper() { }
|
Chris@189
|
26 virtual int getPositionForValue(float value) const = 0;
|
Chris@189
|
27 virtual float getValueForPosition(int position) const = 0;
|
Chris@189
|
28 virtual QString getUnit() const { return ""; }
|
Chris@189
|
29 };
|
Chris@189
|
30
|
Chris@189
|
31
|
Chris@189
|
32 class LinearRangeMapper : public RangeMapper
|
Chris@189
|
33 {
|
Chris@189
|
34 public:
|
Chris@189
|
35 LinearRangeMapper(int minpos, int maxpos,
|
Chris@189
|
36 float minval, float maxval,
|
Chris@464
|
37 QString unit = "", bool inverted = false);
|
Chris@189
|
38
|
Chris@189
|
39 virtual int getPositionForValue(float value) const;
|
Chris@189
|
40 virtual float getValueForPosition(int position) const;
|
Chris@189
|
41
|
Chris@189
|
42 virtual QString getUnit() const { return m_unit; }
|
Chris@189
|
43
|
Chris@189
|
44 protected:
|
Chris@189
|
45 int m_minpos;
|
Chris@189
|
46 int m_maxpos;
|
Chris@189
|
47 float m_minval;
|
Chris@189
|
48 float m_maxval;
|
Chris@189
|
49 QString m_unit;
|
Chris@464
|
50 bool m_inverted;
|
Chris@189
|
51 };
|
Chris@189
|
52
|
Chris@189
|
53
|
Chris@189
|
54 class LogRangeMapper : public RangeMapper
|
Chris@189
|
55 {
|
Chris@189
|
56 public:
|
Chris@189
|
57 LogRangeMapper(int minpos, int maxpos,
|
Chris@356
|
58 float minval, float maxval,
|
Chris@464
|
59 QString m_unit = "", bool inverted = false);
|
Chris@189
|
60
|
Chris@356
|
61 static void convertRatioMinLog(float ratio, float minlog,
|
Chris@356
|
62 int minpos, int maxpos,
|
Chris@356
|
63 float &minval, float &maxval);
|
Chris@356
|
64
|
Chris@356
|
65 static void convertMinMax(int minpos, int maxpos,
|
Chris@356
|
66 float minval, float maxval,
|
Chris@356
|
67 float &ratio, float &minlog);
|
Chris@356
|
68
|
Chris@189
|
69 virtual int getPositionForValue(float value) const;
|
Chris@189
|
70 virtual float getValueForPosition(int position) const;
|
Chris@189
|
71
|
Chris@189
|
72 virtual QString getUnit() const { return m_unit; }
|
Chris@189
|
73
|
Chris@189
|
74 protected:
|
Chris@189
|
75 int m_minpos;
|
Chris@189
|
76 int m_maxpos;
|
Chris@189
|
77 float m_ratio;
|
Chris@189
|
78 float m_minlog;
|
Chris@189
|
79 float m_maxlog;
|
Chris@189
|
80 QString m_unit;
|
Chris@464
|
81 bool m_inverted;
|
Chris@189
|
82 };
|
Chris@189
|
83
|
Chris@189
|
84
|
Chris@189
|
85 #endif
|