fix mistaken "do not roll" conclusion in TransportFSM::compute_should_roll()
[ardour.git] / gtk2_ardour / meterbridge.h
1 /*
2  * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
3  * Copyright (C) 2016 Paul Davis <paul@linuxaudiosystems.com>
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 #ifndef __ardour_meterbridge_h__
20 #define __ardour_meterbridge_h__
21
22 #include <glibmm/thread.h>
23
24 #include <gtkmm/box.h>
25 #include <gtkmm/scrolledwindow.h>
26 #include <gtkmm/label.h>
27 #include <gtkmm/window.h>
28
29 #include "ardour/ardour.h"
30 #include "ardour/types.h"
31 #include "ardour/session_handle.h"
32
33 #include "pbd/stateful.h"
34 #include "pbd/signals.h"
35
36 #include "gtkmm2ext/visibility_tracker.h"
37
38 #include "meter_strip.h"
39
40 class Meterbridge :
41         public Gtk::Window,
42         public PBD::ScopedConnectionList,
43         public ARDOUR::SessionHandlePtr,
44         public Gtkmm2ext::VisibilityTracker
45 {
46 public:
47         static Meterbridge* instance();
48         ~Meterbridge();
49
50         void set_session (ARDOUR::Session *);
51
52         XMLNode& get_state (void);
53         int set_state (const XMLNode& );
54
55         void show_window ();
56         bool hide_window (GdkEventAny *ev);
57
58 private:
59         Meterbridge ();
60         static Meterbridge* _instance;
61
62         bool _visible;
63         bool _show_busses;
64         bool _show_master;
65         bool _show_midi;
66
67         Gtk::ScrolledWindow scroller;
68         Gtk::HBox meterarea;
69         Gtk::HBox global_hpacker;
70         Gtk::VBox global_vpacker;
71
72         gint start_updating ();
73         gint stop_updating ();
74
75         sigc::connection fast_screen_update_connection;
76         void fast_update_strips ();
77
78         void add_strips (ARDOUR::RouteList&);
79         void remove_strip (MeterStrip *);
80
81         void session_going_away ();
82         void sync_order_keys ();
83         void resync_order (PBD::PropertyChange what_changed = ARDOUR::Properties::order);
84         mutable Glib::Threads::Mutex _resync_mutex;
85
86         struct MeterBridgeStrip {
87                 MeterStrip *s;
88                 bool visible;
89
90                 MeterBridgeStrip(MeterStrip *ss) {
91                         s = ss;
92                         visible = true;
93                 }
94         };
95
96         struct MeterOrderRouteSorter
97         {
98                 bool operator() (struct MeterBridgeStrip ma, struct MeterBridgeStrip mb) {
99                         boost::shared_ptr<ARDOUR::Route> a = ma.s->route();
100                         boost::shared_ptr<ARDOUR::Route> b = mb.s->route();
101                         if (a->is_master() || a->is_monitor()) {
102                                 /* "a" is a special route (master, monitor, etc), and comes
103                                  * last in the mixer ordering
104                                  */
105                                 return false;
106                         } else if (b->is_master() || b->is_monitor()) {
107                                 /* everything comes before b */
108                                 return true;
109                         }
110                         return ARDOUR::Stripable::Sorter (true) (a, b);
111                 }
112         };
113
114         std::list<MeterBridgeStrip> strips;
115
116         MeterStrip metrics_left;
117         MeterStrip metrics_right;
118         std::vector<MeterStrip *> _metrics;
119
120         Gtk::VBox metrics_vpacker_left;
121         Gtk::VBox metrics_vpacker_right;
122         Gtk::HBox metrics_spacer_left;
123         Gtk::HBox metrics_spacer_right;
124
125         static const int32_t default_width = 600;
126         static const int32_t default_height = 400;
127         static const int max_height = 1200; // == 1024 + 148 + 16 + 12 see meter_strip.cc
128         int cur_max_width;
129
130         void update_title ();
131
132         // for restoring window geometry.
133         int m_root_x, m_root_y, m_width, m_height;
134
135         void set_window_pos_and_size ();
136         void get_window_pos_and_size ();
137
138         bool on_key_press_event (GdkEventKey*);
139         bool on_key_release_event (GdkEventKey*);
140         bool on_scroll_event (GdkEventScroll*);
141
142         void scroll_left ();
143         void scroll_right ();
144
145         void on_size_allocate (Gtk::Allocation&);
146         void on_size_request (Gtk::Requisition*);
147
148         void parameter_changed (std::string const & p);
149         void on_theme_changed ();
150
151         void on_scroll ();
152         sigc::connection scroll_connection;
153
154         int _mm_left, _mm_right;
155         ARDOUR::MeterType _mt_left, _mt_right;
156 };
157
158 #endif