Ardour  8.7-15-gadf511264b
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 <boost/tuple/tuple.hpp>
24 #include <boost/tuple/tuple_comparison.hpp>
25 
26 #include <cairomm/pattern.h>
27 #include <cairomm/region.h>
28 
29 #include "canvas/item.h"
30 
31 namespace ArdourCanvas {
32 
33 class Canvas;
34 
35 class Meter : public Item {
36  public:
37  enum Orientation {
39  Vertical
40  };
41 
43  long hold_cnt, unsigned long width, Orientation, int len=0,
44  int clr0=0x008800ff, int clr1=0x008800ff,
45  int clr2=0x00ff00ff, int clr3=0x00ff00ff,
46  int clr4=0xffaa00ff, int clr5=0xffaa00ff,
47  int clr6=0xffff00ff, int clr7=0xffff00ff,
48  int clr8=0xff0000ff, int clr9=0xff0000ff,
49  int bgc0=0x333333ff, int bgc1=0x444444ff,
50  int bgh0=0x991122ff, int bgh1=0x551111ff,
51  float stp0 = 55.0, // log_meter(-18);
52  float stp1 = 77.5, // log_meter(-9);
53  float stp2 = 92.5, // log_meter(-3); // 95.0, // log_meter(-2);
54  float stp3 = 100.0,
55  int styleflags = 3
56  );
57 
59  long hold_cnt, unsigned long width, Orientation, int len=0,
60  int clr0=0x008800ff, int clr1=0x008800ff,
61  int clr2=0x00ff00ff, int clr3=0x00ff00ff,
62  int clr4=0xffaa00ff, int clr5=0xffaa00ff,
63  int clr6=0xffff00ff, int clr7=0xffff00ff,
64  int clr8=0xff0000ff, int clr9=0xff0000ff,
65  int bgc0=0x333333ff, int bgc1=0x444444ff,
66  int bgh0=0x991122ff, int bgh1=0x551111ff,
67  float stp0 = 55.0, // log_meter(-18);
68  float stp1 = 77.5, // log_meter(-9);
69  float stp2 = 92.5, // log_meter(-3); // 95.0, // log_meter(-2);
70  float stp3 = 100.0,
71  int styleflags = 3
72  );
73  virtual ~Meter ();
74  static void flush_pattern_cache();
75 
76  void set (float level, float peak = -1);
77  void clear ();
78 
79  float get_level() { return current_level; }
80  float get_user_level() { return current_user_level; }
81  float get_peak() { return current_peak; }
82 
83  long hold_count() { return hold_cnt; }
84  void set_hold_count (long);
85  void set_highlight (bool);
86  bool get_highlight () { return highlight; }
87 
88  void render (ArdourCanvas::Rect const &, Cairo::RefPtr<Cairo::Context>) const;
89  void compute_bounding_box() const;
90 
91  private:
92 
93  Cairo::RefPtr<Cairo::Pattern> fgpattern;
94  Cairo::RefPtr<Cairo::Pattern> bgpattern;
95  gint pixheight;
96  gint pixwidth;
97 
98  float _stp[4];
99  int _clr[10];
100  int _bgc[2];
101  int _bgh[2];
103 
105  mutable Cairo::RectangleInt pixrect;
106  mutable Cairo::RectangleInt last_peak_rect;
107  unsigned long hold_cnt;
108  unsigned long hold_state;
113  bool highlight;
114 
115  void init (int clr0, int clr1, int clr2, int clr3,
116  int clr4, int clr5, int clr6, int clr7,
117  int clr8, int clr9,
118  int bgc0, int bgc1,
119  int bgh0, int bgh1,
120  float stp0, float stp1,
121  float stp2, float stp3,
122  int dimen, int len);
123 
124  void vertical_expose (ArdourCanvas::Rect const & area, Cairo::RefPtr<Cairo::Context> context) const;
125  void queue_vertical_redraw (float old_level);
126 
127  void horizontal_expose (ArdourCanvas::Rect const & area, Cairo::RefPtr<Cairo::Context> context) const;
128  void queue_horizontal_redraw (float old_level);
129 
130  static bool no_rgba_overlay;
131 
132  static Cairo::RefPtr<Cairo::Pattern> generate_meter_pattern (int, int, int *, float *, int, bool);
133  static Cairo::RefPtr<Cairo::Pattern> vertical_meter_pattern (int, int, int *, float *, int);
134  static Cairo::RefPtr<Cairo::Pattern> horizontal_meter_pattern (int, int, int *, float *, int);
135 
136  static Cairo::RefPtr<Cairo::Pattern> generate_meter_background (int, int, int *, bool, bool);
137  static Cairo::RefPtr<Cairo::Pattern> vertical_background (int, int, int *, bool);
138  static Cairo::RefPtr<Cairo::Pattern> horizontal_background (int, int, int *, bool);
139 
142  int w, int h,
143  float stp0, float stp1, float stp2, float stp3,
144  int c0, int c1, int c2, int c3,
145  int c4, int c5, int c6, int c7,
146  int c8, int c9, int st
147  )
148  : dim(w, h)
149  , stp(stp0, stp1, stp2, stp3)
150  , cols(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9)
151  , style(st)
152  {}
153  inline bool operator<(const Pattern10MapKey& rhs) const {
154  return (dim < rhs.dim)
155  || (dim == rhs.dim && stp < rhs.stp)
156  || (dim == rhs.dim && stp == rhs.stp && cols < rhs.cols)
157  || (dim == rhs.dim && stp == rhs.stp && cols == rhs.cols && style < rhs.style);
158  }
159  boost::tuple<int, int> dim;
160  boost::tuple<float, float, float, float> stp;
161  boost::tuple<int, int, int, int, int, int, int, int, int, int> cols;
162  int style;
163  };
164  typedef std::map<Pattern10MapKey, Cairo::RefPtr<Cairo::Pattern> > Pattern10Map;
165 
167  PatternBgMapKey (int w, int h, int c0, int c1, bool shade)
168  : dim(w, h)
169  , cols(c0, c1)
170  , sh(shade)
171  {}
172  inline bool operator<(const PatternBgMapKey& rhs) const {
173  return (dim < rhs.dim) || (dim == rhs.dim && cols < rhs.cols) || (dim == rhs.dim && cols == rhs.cols && (sh && !rhs.sh));
174  }
175  boost::tuple<int, int> dim;
176  boost::tuple<int, int> cols;
177  bool sh;
178  };
179  typedef std::map<PatternBgMapKey, Cairo::RefPtr<Cairo::Pattern> > PatternBgMap;
180 
185  static int min_pattern_metric_size; // min dimension for axis that displays the meter level
186  static int max_pattern_metric_size; // max dimension for axis that displays the meter level
187 };
188 
189 } /* namespace */
190 
191 #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)
boost::tuple< int, int, int, int, int, int, int, int, int, int > cols
boost::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