Ardour  9.0-pre0-582-g084a23a80d
canvas/canvas/meter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Paul Davis <paul@linuxaudiosystems.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef __push2_meter_h__
20 #define __push2_meter_h__
21 
22 #include <map>
23 #include <tuple>
24 
25 #include <cairomm/pattern.h>
26 #include <cairomm/region.h>
27 
28 #include "canvas/item.h"
29 
30 namespace ArdourCanvas {
31 
32 class Canvas;
33 
34 class Meter : public Item {
35  public:
36  enum Orientation {
38  Vertical
39  };
40 
42  long hold_cnt, unsigned long width, Orientation, int len=0,
43  int clr0=0x008800ff, int clr1=0x008800ff,
44  int clr2=0x00ff00ff, int clr3=0x00ff00ff,
45  int clr4=0xffaa00ff, int clr5=0xffaa00ff,
46  int clr6=0xffff00ff, int clr7=0xffff00ff,
47  int clr8=0xff0000ff, int clr9=0xff0000ff,
48  int bgc0=0x333333ff, int bgc1=0x444444ff,
49  int bgh0=0x991122ff, int bgh1=0x551111ff,
50  float stp0 = 55.0, // log_meter(-18);
51  float stp1 = 77.5, // log_meter(-9);
52  float stp2 = 92.5, // log_meter(-3); // 95.0, // log_meter(-2);
53  float stp3 = 100.0,
54  int styleflags = 3
55  );
56 
58  long hold_cnt, unsigned long width, Orientation, int len=0,
59  int clr0=0x008800ff, int clr1=0x008800ff,
60  int clr2=0x00ff00ff, int clr3=0x00ff00ff,
61  int clr4=0xffaa00ff, int clr5=0xffaa00ff,
62  int clr6=0xffff00ff, int clr7=0xffff00ff,
63  int clr8=0xff0000ff, int clr9=0xff0000ff,
64  int bgc0=0x333333ff, int bgc1=0x444444ff,
65  int bgh0=0x991122ff, int bgh1=0x551111ff,
66  float stp0 = 55.0, // log_meter(-18);
67  float stp1 = 77.5, // log_meter(-9);
68  float stp2 = 92.5, // log_meter(-3); // 95.0, // log_meter(-2);
69  float stp3 = 100.0,
70  int styleflags = 3
71  );
72  virtual ~Meter ();
73  static void flush_pattern_cache();
74 
75  void set (float level, float peak = -1);
76  void clear ();
77 
78  float get_level() { return current_level; }
79  float get_user_level() { return current_user_level; }
80  float get_peak() { return current_peak; }
81 
82  long hold_count() { return hold_cnt; }
83  void set_hold_count (long);
84  void set_highlight (bool);
85  bool get_highlight () { return highlight; }
86 
87  void render (ArdourCanvas::Rect const &, Cairo::RefPtr<Cairo::Context>) const;
88  void compute_bounding_box() const;
89 
90  private:
91 
92  Cairo::RefPtr<Cairo::Pattern> fgpattern;
93  Cairo::RefPtr<Cairo::Pattern> bgpattern;
94  gint pixheight;
95  gint pixwidth;
96 
97  float _stp[4];
98  int _clr[10];
99  int _bgc[2];
100  int _bgh[2];
102 
104  mutable Cairo::RectangleInt pixrect;
105  mutable Cairo::RectangleInt last_peak_rect;
106  unsigned long hold_cnt;
107  unsigned long hold_state;
112  bool highlight;
113 
114  void init (int clr0, int clr1, int clr2, int clr3,
115  int clr4, int clr5, int clr6, int clr7,
116  int clr8, int clr9,
117  int bgc0, int bgc1,
118  int bgh0, int bgh1,
119  float stp0, float stp1,
120  float stp2, float stp3,
121  int dimen, int len);
122 
123  void vertical_expose (ArdourCanvas::Rect const & area, Cairo::RefPtr<Cairo::Context> context) const;
124  void queue_vertical_redraw (float old_level);
125 
126  void horizontal_expose (ArdourCanvas::Rect const & area, Cairo::RefPtr<Cairo::Context> context) const;
127  void queue_horizontal_redraw (float old_level);
128 
129  static bool no_rgba_overlay;
130 
131  static Cairo::RefPtr<Cairo::Pattern> generate_meter_pattern (int, int, int *, float *, int, bool);
132  static Cairo::RefPtr<Cairo::Pattern> vertical_meter_pattern (int, int, int *, float *, int);
133  static Cairo::RefPtr<Cairo::Pattern> horizontal_meter_pattern (int, int, int *, float *, int);
134 
135  static Cairo::RefPtr<Cairo::Pattern> generate_meter_background (int, int, int *, bool, bool);
136  static Cairo::RefPtr<Cairo::Pattern> vertical_background (int, int, int *, bool);
137  static Cairo::RefPtr<Cairo::Pattern> horizontal_background (int, int, int *, bool);
138 
141  int w, int h,
142  float stp0, float stp1, float stp2, float stp3,
143  int c0, int c1, int c2, int c3,
144  int c4, int c5, int c6, int c7,
145  int c8, int c9, int st
146  )
147  : dim(w, h)
148  , stp(stp0, stp1, stp2, stp3)
149  , cols(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9)
150  , style(st)
151  {}
152  inline bool operator<(const Pattern10MapKey& rhs) const {
153  return (dim < rhs.dim)
154  || (dim == rhs.dim && stp < rhs.stp)
155  || (dim == rhs.dim && stp == rhs.stp && cols < rhs.cols)
156  || (dim == rhs.dim && stp == rhs.stp && cols == rhs.cols && style < rhs.style);
157  }
158  std::tuple<int, int> dim;
159  std::tuple<float, float, float, float> stp;
160  std::tuple<int, int, int, int, int, int, int, int, int, int> cols;
161  int style;
162  };
163  typedef std::map<Pattern10MapKey, Cairo::RefPtr<Cairo::Pattern> > Pattern10Map;
164 
166  PatternBgMapKey (int w, int h, int c0, int c1, bool shade)
167  : dim(w, h)
168  , cols(c0, c1)
169  , sh(shade)
170  {}
171  inline bool operator<(const PatternBgMapKey& rhs) const {
172  return (dim < rhs.dim) || (dim == rhs.dim && cols < rhs.cols) || (dim == rhs.dim && cols == rhs.cols && (sh && !rhs.sh));
173  }
174  std::tuple<int, int> dim;
175  std::tuple<int, int> cols;
176  bool sh;
177  };
178  typedef std::map<PatternBgMapKey, Cairo::RefPtr<Cairo::Pattern> > PatternBgMap;
179 
184  static int min_pattern_metric_size; // min dimension for axis that displays the meter level
185  static int max_pattern_metric_size; // max dimension for axis that displays the meter level
186 };
187 
188 } /* namespace */
189 
190 #endif /* __push2_meter_h__ */
Canvas * canvas() const
Coord width() const
void init(int clr0, int clr1, int clr2, int clr3, int clr4, int clr5, int clr6, int clr7, int clr8, int clr9, int bgc0, int bgc1, int bgh0, int bgh1, float stp0, float stp1, float stp2, float stp3, int dimen, int len)
Cairo::RectangleInt last_peak_rect
static Cairo::RefPtr< Cairo::Pattern > vertical_meter_pattern(int, int, int *, float *, int)
static Pattern10Map vm_pattern_cache
static Cairo::RefPtr< Cairo::Pattern > vertical_background(int, int, int *, bool)
Cairo::RefPtr< Cairo::Pattern > bgpattern
void compute_bounding_box() const
static Pattern10Map hm_pattern_cache
static int min_pattern_metric_size
static PatternBgMap vb_pattern_cache
Cairo::RectangleInt pixrect
Meter(ArdourCanvas::Canvas *canvas, long hold_cnt, unsigned long width, Orientation, int len=0, int clr0=0x008800ff, int clr1=0x008800ff, int clr2=0x00ff00ff, int clr3=0x00ff00ff, int clr4=0xffaa00ff, int clr5=0xffaa00ff, int clr6=0xffff00ff, int clr7=0xffff00ff, int clr8=0xff0000ff, int clr9=0xff0000ff, int bgc0=0x333333ff, int bgc1=0x444444ff, int bgh0=0x991122ff, int bgh1=0x551111ff, float stp0=55.0, float stp1=77.5, float stp2=92.5, float stp3=100.0, int styleflags=3)
void set(float level, float peak=-1)
void queue_horizontal_redraw(float old_level)
std::map< Pattern10MapKey, Cairo::RefPtr< Cairo::Pattern > > Pattern10Map
void queue_vertical_redraw(float old_level)
static Cairo::RefPtr< Cairo::Pattern > generate_meter_background(int, int, int *, bool, bool)
void set_highlight(bool)
static Cairo::RefPtr< Cairo::Pattern > generate_meter_pattern(int, int, int *, float *, int, bool)
std::map< PatternBgMapKey, Cairo::RefPtr< Cairo::Pattern > > PatternBgMap
static void flush_pattern_cache()
Meter(Item *parent, long hold_cnt, unsigned long width, Orientation, int len=0, int clr0=0x008800ff, int clr1=0x008800ff, int clr2=0x00ff00ff, int clr3=0x00ff00ff, int clr4=0xffaa00ff, int clr5=0xffaa00ff, int clr6=0xffff00ff, int clr7=0xffff00ff, int clr8=0xff0000ff, int clr9=0xff0000ff, int bgc0=0x333333ff, int bgc1=0x444444ff, int bgh0=0x991122ff, int bgh1=0x551111ff, float stp0=55.0, float stp1=77.5, float stp2=92.5, float stp3=100.0, int styleflags=3)
void set_hold_count(long)
void vertical_expose(ArdourCanvas::Rect const &area, Cairo::RefPtr< Cairo::Context > context) const
static Cairo::RefPtr< Cairo::Pattern > horizontal_background(int, int, int *, bool)
Cairo::RefPtr< Cairo::Pattern > fgpattern
static int max_pattern_metric_size
static PatternBgMap hb_pattern_cache
void horizontal_expose(ArdourCanvas::Rect const &area, Cairo::RefPtr< Cairo::Context > context) const
void render(ArdourCanvas::Rect const &, Cairo::RefPtr< Cairo::Context >) const
static Cairo::RefPtr< Cairo::Pattern > horizontal_meter_pattern(int, int, int *, float *, int)
bool operator<(const Pattern10MapKey &rhs) const
Pattern10MapKey(int w, int h, float stp0, float stp1, float stp2, float stp3, int c0, int c1, int c2, int c3, int c4, int c5, int c6, int c7, int c8, int c9, int st)
std::tuple< int, int, int, int, int, int, int, int, int, int > cols
std::tuple< float, float, float, float > stp
PatternBgMapKey(int w, int h, int c0, int c1, bool shade)
bool operator<(const PatternBgMapKey &rhs) const
link region and track false waveform clip level