Ardour  9.0-pre0-582-g084a23a80d
fastmeter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef _WIDGETS_FAST_METER_H_
21 #define _WIDGETS_FAST_METER_H_
22 
23 #include <map>
24 #include <tuple>
25 #include <cairomm/pattern.h>
26 #include "gtkmm2ext/cairo_widget.h"
27 
28 #include "widgets/visibility.h"
29 
30 namespace ArdourWidgets {
31 
33 public:
34  enum Orientation {
36  Vertical
37  };
38 
39  FastMeter (long hold_cnt, unsigned long width, Orientation, int len=0,
40  int clr0=0x008800ff, int clr1=0x008800ff,
41  int clr2=0x00ff00ff, int clr3=0x00ff00ff,
42  int clr4=0xffaa00ff, int clr5=0xffaa00ff,
43  int clr6=0xffff00ff, int clr7=0xffff00ff,
44  int clr8=0xff0000ff, int clr9=0xff0000ff,
45  int bgc0=0x333333ff, int bgc1=0x444444ff,
46  int bgh0=0x991122ff, int bgh1=0x551111ff,
47  float stp0 = 55.0, // log_meter(-18);
48  float stp1 = 77.5, // log_meter(-9);
49  float stp2 = 92.5, // log_meter(-3); // 95.0, // log_meter(-2);
50  float stp3 = 100.0,
51  int styleflags = 3
52  );
53  virtual ~FastMeter ();
54  static void flush_pattern_cache();
55 
56  void set (float level, float peak = -1);
57  void clear ();
58 
59  float get_level() { return current_level; }
60  float get_user_level() { return current_user_level; }
61  float get_peak() { return current_peak; }
62 
63  long hold_count() { return hold_cnt; }
64  void set_hold_count (long);
65  void set_highlight (bool);
66  bool get_highlight () { return highlight; }
67  void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
68 
69 protected:
72 
73 private:
74  Cairo::RefPtr<Cairo::Pattern> fgpattern;
75  Cairo::RefPtr<Cairo::Pattern> bgpattern;
76  gint pixheight;
77  gint pixwidth;
78 
79  float _stp[4];
80  int _clr[10];
81  int _bgc[2];
82  int _bgh[2];
84 
90  unsigned long hold_cnt;
91  unsigned long hold_state;
94  float current_peak;
96  bool highlight;
97 
98  uint32_t outline_color;
99 
100  void vertical_expose (cairo_t*, cairo_rectangle_t*);
103  void queue_vertical_redraw (const Glib::RefPtr<Gdk::Window>&, float);
104 
105  void horizontal_expose (cairo_t*, cairo_rectangle_t*);
108  void queue_horizontal_redraw (const Glib::RefPtr<Gdk::Window>&, float);
109 
110  static bool no_rgba_overlay;
111 
112  static Cairo::RefPtr<Cairo::Pattern> generate_meter_pattern (
113  int, int, int *, float *, int, bool);
114  static Cairo::RefPtr<Cairo::Pattern> request_vertical_meter (
115  int, int, int *, float *, int);
116  static Cairo::RefPtr<Cairo::Pattern> request_horizontal_meter (
117  int, int, int *, float *, int);
118 
119  static Cairo::RefPtr<Cairo::Pattern> generate_meter_background (
120  int, int, int *, bool, bool);
121  static Cairo::RefPtr<Cairo::Pattern> request_vertical_background (
122  int, int, int *, bool);
123  static Cairo::RefPtr<Cairo::Pattern> request_horizontal_background (
124  int, int, int *, bool);
125 
128  int w, int h,
129  float stp0, float stp1, float stp2, float stp3,
130  int c0, int c1, int c2, int c3,
131  int c4, int c5, int c6, int c7,
132  int c8, int c9, int st
133  )
134  : dim(w, h)
135  , stp(stp0, stp1, stp2, stp3)
136  , cols(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9)
137  , style(st)
138  {}
139  inline bool operator<(const Pattern10MapKey& rhs) const {
140  return (dim < rhs.dim)
141  || (dim == rhs.dim && stp < rhs.stp)
142  || (dim == rhs.dim && stp == rhs.stp && cols < rhs.cols)
143  || (dim == rhs.dim && stp == rhs.stp && cols == rhs.cols && style < rhs.style);
144  }
145  std::tuple<int, int> dim;
146  std::tuple<float, float, float, float> stp;
147  std::tuple<int, int, int, int, int, int, int, int, int, int> cols;
148  int style;
149  };
150  typedef std::map<Pattern10MapKey, Cairo::RefPtr<Cairo::Pattern> > Pattern10Map;
151 
153  PatternBgMapKey (int w, int h, int c0, int c1, bool shade)
154  : dim(w, h)
155  , cols(c0, c1)
156  , sh(shade)
157  {}
158  inline bool operator<(const PatternBgMapKey& rhs) const {
159  return (dim < rhs.dim) || (dim == rhs.dim && cols < rhs.cols) || (dim == rhs.dim && cols == rhs.cols && (sh && !rhs.sh));
160  }
161  std::tuple<int, int> dim;
162  std::tuple<int, int> cols;
163  bool sh;
164  };
165  typedef std::map<PatternBgMapKey, Cairo::RefPtr<Cairo::Pattern> > PatternBgMap;
166 
171  static int min_pattern_metric_size; // min dimension for axis that displays the meter level
172  static int max_pattern_metric_size; // max dimension for axis that displays the meter level
173 };
174 
175 
176 } /* namespace */
177 
178 #endif
void vertical_size_allocate(Gtk::Allocation &)
static Pattern10Map hm_pattern_cache
Definition: fastmeter.h:169
static Cairo::RefPtr< Cairo::Pattern > request_horizontal_meter(int, int, int *, float *, int)
std::map< Pattern10MapKey, Cairo::RefPtr< Cairo::Pattern > > Pattern10Map
Definition: fastmeter.h:150
Cairo::RefPtr< Cairo::Pattern > bgpattern
Definition: fastmeter.h:75
GdkRectangle pixrect
Definition: fastmeter.h:86
void render(Cairo::RefPtr< Cairo::Context > const &, cairo_rectangle_t *)
FastMeter(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 on_size_request(GtkRequisition *)
This is a default handler for the signal signal_size_request().
static Cairo::RefPtr< Cairo::Pattern > request_vertical_background(int, int, int *, bool)
static Cairo::RefPtr< Cairo::Pattern > generate_meter_background(int, int, int *, bool, bool)
void set(float level, float peak=-1)
Cairo::RefPtr< Cairo::Pattern > fgpattern
Definition: fastmeter.h:74
static void flush_pattern_cache()
void horizontal_size_request(GtkRequisition *)
static PatternBgMap vb_pattern_cache
Definition: fastmeter.h:168
static Pattern10Map vm_pattern_cache
Definition: fastmeter.h:167
static Cairo::RefPtr< Cairo::Pattern > request_vertical_meter(int, int, int *, float *, int)
void vertical_expose(cairo_t *, cairo_rectangle_t *)
static Cairo::RefPtr< Cairo::Pattern > generate_meter_pattern(int, int, int *, float *, int, bool)
static bool no_rgba_overlay
Definition: fastmeter.h:110
static Cairo::RefPtr< Cairo::Pattern > request_horizontal_background(int, int, int *, bool)
GdkRectangle last_peak_rect
Definition: fastmeter.h:87
unsigned long hold_state
Definition: fastmeter.h:91
void horizontal_expose(cairo_t *, cairo_rectangle_t *)
static int min_pattern_metric_size
Definition: fastmeter.h:171
void queue_vertical_redraw(const Glib::RefPtr< Gdk::Window > &, float)
void vertical_size_request(GtkRequisition *)
void horizontal_size_allocate(Gtk::Allocation &)
static int max_pattern_metric_size
Definition: fastmeter.h:172
void on_size_allocate(Gtk::Allocation &)
This is a default handler for the signal signal_size_allocate().
unsigned long hold_cnt
Definition: fastmeter.h:90
static PatternBgMap hb_pattern_cache
Definition: fastmeter.h:170
std::map< PatternBgMapKey, Cairo::RefPtr< Cairo::Pattern > > PatternBgMap
Definition: fastmeter.h:165
Orientation orientation
Definition: fastmeter.h:85
void queue_horizontal_redraw(const Glib::RefPtr< Gdk::Window > &, float)
@ Vertical
Definition: editing.h:249
std::tuple< int, int, int, int, int, int, int, int, int, int > cols
Definition: fastmeter.h:147
bool operator<(const Pattern10MapKey &rhs) const
Definition: fastmeter.h:139
std::tuple< float, float, float, float > stp
Definition: fastmeter.h:146
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)
Definition: fastmeter.h:127
bool operator<(const PatternBgMapKey &rhs) const
Definition: fastmeter.h:158
PatternBgMapKey(int w, int h, int c0, int c1, bool shade)
Definition: fastmeter.h:153
link region and track false waveform clip level
#define LIBWIDGETS_API
gint width
Definition: xcursors.h:1