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