Fix MIDI disk-writer flush
[ardour.git] / gtk2_ardour / level_meter.h
1 /*
2  * Copyright (C) 2008-2014 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
5  * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifndef __ardour_gtk_track_meter_h__
23 #define __ardour_gtk_track_meter_h__
24
25 #include <vector>
26
27 #include <gtkmm/box.h>
28 #include <gtkmm/adjustment.h>
29 #include <gtkmm/frame.h>
30 #include <gtkmm/eventbox.h>
31 #include <gtkmm/button.h>
32 #include <gtkmm/table.h>
33 #include <gtkmm/drawingarea.h>
34
35 #include "ardour/types.h"
36 #include "ardour/chan_count.h"
37 #include "ardour/session_handle.h"
38
39 #include "widgets/fastmeter.h"
40 #include "widgets/focus_entry.h"
41 #include "widgets/slider_controller.h"
42
43 #include "enums.h"
44
45 namespace ARDOUR {
46         class Session;
47         class PeakMeter;
48 }
49 namespace Gtk {
50         class Menu;
51 }
52
53 class LevelMeterBase : public ARDOUR::SessionHandlePtr, virtual public sigc::trackable
54 {
55 public:
56         LevelMeterBase (ARDOUR::Session*, PBD::EventLoop::InvalidationRecord* ir,
57                         ArdourWidgets::FastMeter::Orientation o = ArdourWidgets::FastMeter::Vertical);
58         virtual ~LevelMeterBase ();
59
60         virtual void set_meter (ARDOUR::PeakMeter* meter);
61
62         void update_gain_sensitive ();
63
64         float update_meters ();
65         void update_meters_falloff ();
66         void clear_meters (bool reset_highlight = true);
67         void hide_meters ();
68         void setup_meters (int len=0, int width=3, int thin=2);
69         void set_max_audio_meter_count (uint32_t cnt = 0);
70
71         /** Emitted in the GUI thread when a button is pressed over the meter */
72         PBD::Signal1<bool, GdkEventButton *> ButtonPress;
73         PBD::Signal1<bool, GdkEventButton *> ButtonRelease;
74
75 protected:
76         virtual void mtr_pack(Gtk::Widget &w) = 0;
77         virtual void mtr_remove(Gtk::Widget &w) = 0;
78
79 private:
80         PBD::EventLoop::InvalidationRecord* parent_invalidator;
81         ARDOUR::PeakMeter* _meter;
82         ArdourWidgets::FastMeter::Orientation _meter_orientation;
83
84         Width _width;
85
86         struct MeterInfo {
87                 ArdourWidgets::FastMeter* meter;
88                 gint16                    width;
89                 int                       length;
90                 bool                      packed;
91                 float                     max_peak;
92
93                 MeterInfo() {
94                         meter = 0;
95                         width = 0;
96                         length = 0;
97                         packed = false;
98                         max_peak = -INFINITY;
99                 }
100         };
101
102         guint16                regular_meter_width;
103         int                    meter_length;
104         guint16                thin_meter_width;
105         std::vector<MeterInfo> meters;
106         float                  max_peak;
107         ARDOUR::MeterType      visible_meter_type;
108         uint32_t               midi_count;
109         uint32_t               meter_count;
110         uint32_t               max_visible_meters;
111
112         PBD::ScopedConnection _configuration_connection;
113         PBD::ScopedConnection _meter_type_connection;
114         PBD::ScopedConnection _parameter_connection;
115
116         void hide_all_meters ();
117         bool meter_button_press (GdkEventButton *);
118         bool meter_button_release (GdkEventButton *);
119
120         void parameter_changed (std::string);
121         void configuration_changed (ARDOUR::ChanCount in, ARDOUR::ChanCount out);
122         void meter_type_changed (ARDOUR::MeterType);
123
124         bool color_changed;
125         void color_handler ();
126 };
127
128 class LevelMeterHBox : public LevelMeterBase, public Gtk::HBox
129 {
130 public:
131         LevelMeterHBox (ARDOUR::Session*);
132         ~LevelMeterHBox();
133
134 protected:
135         void mtr_pack(Gtk::Widget &w);
136         void mtr_remove(Gtk::Widget &w);
137 };
138
139 class LevelMeterVBox : public LevelMeterBase, public Gtk::VBox
140 {
141 public:
142         LevelMeterVBox (ARDOUR::Session*);
143         ~LevelMeterVBox();
144
145 protected:
146         void mtr_pack(Gtk::Widget &w);
147         void mtr_remove(Gtk::Widget &w);
148 };
149
150 #endif /* __ardour_gtk_track_meter_h__ */
151