save/restore plugin-sidebar expanded items
[ardour.git] / gtk2_ardour / mixer_ui.h
1 /*
2     Copyright (C) 2000 Paul Davis
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
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __ardour_mixer_ui_h__
21 #define __ardour_mixer_ui_h__
22
23 #include <list>
24
25 #include <gtkmm/box.h>
26 #include <gtkmm/scrolledwindow.h>
27 #include <gtkmm/eventbox.h>
28 #include <gtkmm/label.h>
29 #include <gtkmm/button.h>
30 #include <gtkmm/frame.h>
31 #include <gtkmm/paned.h>
32 #include <gtkmm/menu.h>
33 #include <gtkmm/treeview.h>
34 #include <gtkmm/liststore.h>
35
36 #include "pbd/stateful.h"
37 #include "pbd/signals.h"
38
39 #include "ardour/ardour.h"
40 #include "ardour/types.h"
41 #include "ardour/session_handle.h"
42 #include "ardour/plugin.h"
43 #include "ardour/plugin_manager.h"
44
45 #include "gtkmm2ext/visibility_tracker.h"
46 #include "gtkmm2ext/dndtreeview.h"
47 #include "gtkmm2ext/treeutils.h"
48
49 #include "enums.h"
50 #include "mixer_actor.h"
51
52 namespace ARDOUR {
53         class Route;
54         class RouteGroup;
55 };
56
57 class MixerStrip;
58 class PluginSelector;
59 class MixerGroupTabs;
60 class MonitorSection;
61
62 class PluginTreeStore : public Gtk::TreeStore
63 {
64 public:
65         static Glib::RefPtr<PluginTreeStore> create(const Gtk::TreeModelColumnRecord& columns) {
66                 return Glib::RefPtr<PluginTreeStore> (new PluginTreeStore (columns));
67         }
68
69 protected:
70         PluginTreeStore (const Gtk::TreeModelColumnRecord& columns) : Gtk::TreeStore (columns) {}
71         virtual bool row_draggable_vfunc (const Gtk::TreeModel::Path&) const { return true; }
72         virtual bool row_drop_possible_vfunc (const Gtk::TreeModel::Path&, const Gtk::SelectionData&) const;
73 };
74
75 class Mixer_UI : public Gtk::Window, public PBD::ScopedConnectionList, public ARDOUR::SessionHandlePtr, public MixerActor, public Gtkmm2ext::VisibilityTracker
76 {
77   public:
78         static Mixer_UI* instance();
79         ~Mixer_UI();
80
81         void set_session (ARDOUR::Session *);
82         void track_editor_selection ();
83
84         PluginSelector* plugin_selector();
85
86         void  set_strip_width (Width, bool save = false);
87         Width get_strip_width () const { return _strip_width; }
88
89         void unselect_strip_in_display (MixerStrip*);
90         void select_strip_in_display (MixerStrip*);
91
92         XMLNode& get_state (void);
93         int set_state (const XMLNode& );
94
95         void show_mixer_list (bool yn);
96         void show_monitor_section (bool);
97         
98         void show_window ();
99         bool hide_window (GdkEventAny *ev);
100         void show_strip (MixerStrip *);
101         void hide_strip (MixerStrip *);
102
103         void maximise_mixer_space();
104         void restore_mixer_space();
105
106         void ensure_float (Gtk::Window&);
107
108         MonitorSection* monitor_section() const { return _monitor_section; }
109
110         void deselect_all_strip_processors();
111         void delete_processors();
112
113         void select_none ();
114
115   protected:
116         void set_route_targets_for_operation ();
117
118   private:
119         Mixer_UI ();
120         static Mixer_UI* _instance;
121
122         bool                                    _visible;
123
124         Gtk::HBox                               global_hpacker;
125         Gtk::VBox                               global_vpacker;
126         Gtk::ScrolledWindow             scroller;
127         Gtk::EventBox                   scroller_base;
128         Gtk::HBox                               scroller_hpacker;
129         Gtk::VBox                               mixer_scroller_vpacker;
130         Gtk::VBox                               list_vpacker;
131         Gtk::Label                              group_display_button_label;
132         Gtk::Button                             group_display_button;
133         Gtk::ScrolledWindow             track_display_scroller;
134         Gtk::ScrolledWindow             group_display_scroller;
135         Gtk::ScrolledWindow             favorite_plugins_scroller;
136         Gtk::VBox                               group_display_vbox;
137         Gtk::Frame                              track_display_frame;
138         Gtk::Frame                              group_display_frame;
139         Gtk::Frame                              favorite_plugins_frame;
140         Gtk::VPaned                             rhs_pane1;
141         Gtk::VPaned                             rhs_pane2;
142         Gtk::HBox                               strip_packer;
143         Gtk::HBox                               out_packer;
144         Gtk::HPaned                             list_hpane;
145
146         MixerGroupTabs* _group_tabs;
147
148         // for restoring window geometry.
149         int m_root_x, m_root_y, m_width, m_height;
150
151         void set_window_pos_and_size ();
152         void get_window_pos_and_size ();
153
154         bool on_key_press_event (GdkEventKey*);
155         bool on_key_release_event (GdkEventKey*);
156         bool on_scroll_event (GdkEventScroll*);
157
158         void pane_allocation_handler (Gtk::Allocation&, Gtk::Paned*);
159
160         std::list<MixerStrip *> strips;
161
162         bool strip_scroller_button_release (GdkEventButton*);
163         void scroll_left ();
164         void scroll_right ();
165         void toggle_midi_input_active (bool flip_others);
166
167         void add_strips (ARDOUR::RouteList&);
168         void remove_strip (MixerStrip *);
169
170         MixerStrip* strip_by_route (boost::shared_ptr<ARDOUR::Route>);
171
172         void hide_all_strips (bool with_select);
173         void unselect_all_strips();
174         void select_all_strips ();
175         void unselect_all_audiotrack_strips ();
176         void select_all_audiotrack_strips ();
177         void unselect_all_audiobus_strips ();
178         void select_all_audiobus_strips ();
179
180         void strip_select_op (bool audiotrack, bool select);
181         void select_strip_op (MixerStrip*, bool select);
182
183         gint start_updating ();
184         gint stop_updating ();
185
186         void session_going_away ();
187
188         sigc::connection fast_screen_update_connection;
189         void fast_update_strips ();
190
191         void track_name_changed (MixerStrip *);
192
193         void redisplay_track_list ();
194         bool no_track_list_redisplay;
195         bool track_display_button_press (GdkEventButton*);
196         void strip_width_changed ();
197
198         void track_list_delete (const Gtk::TreeModel::Path&);
199         void track_list_reorder (const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter, int* new_order);
200
201         void plugin_row_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column);
202
203         void initial_track_display ();
204         void show_track_list_menu ();
205
206         void set_all_strips_visibility (bool yn);
207         void set_all_audio_midi_visibility (int, bool);
208         void track_visibility_changed (std::string const & path);
209         void update_track_visibility ();
210
211         void hide_all_routes ();
212         void show_all_routes ();
213         void show_all_audiobus ();
214         void hide_all_audiobus ();
215         void show_all_audiotracks();
216         void hide_all_audiotracks ();
217         void show_all_miditracks();
218         void hide_all_miditracks ();
219
220         bool in_group_row_change;
221
222         void group_selected (gint row, gint col, GdkEvent *ev);
223         void group_unselected (gint row, gint col, GdkEvent *ev);
224         void group_display_active_clicked();
225         void new_route_group ();
226         void remove_selected_route_group ();
227         void activate_all_route_groups ();
228         void disable_all_route_groups ();
229         void add_route_group (ARDOUR::RouteGroup *);
230         void route_groups_changed ();
231         void route_group_name_edit (const std::string&, const std::string&);
232         void route_group_row_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter);
233         void route_group_row_deleted (Gtk::TreeModel::Path const &);
234
235         Gtk::Menu *track_menu;
236         void track_column_click (gint);
237         void build_track_menu ();
238
239         MonitorSection* _monitor_section;
240         PluginSelector    *_plugin_selector;
241
242         void strip_property_changed (const PBD::PropertyChange&, MixerStrip *);
243         void route_group_property_changed (ARDOUR::RouteGroup *, const PBD::PropertyChange &);
244
245         /* various treeviews */
246
247         struct TrackDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
248             TrackDisplayModelColumns () {
249                     add (text);
250                     add (visible);
251                     add (route);
252                     add (strip);
253             }
254             Gtk::TreeModelColumn<bool>           visible;
255             Gtk::TreeModelColumn<std::string>  text;
256             Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Route> > route;
257             Gtk::TreeModelColumn<MixerStrip*>    strip;
258         };
259
260         struct GroupDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
261             GroupDisplayModelColumns() {
262                     add (visible);
263                     add (text);
264                     add (group);
265             }
266             Gtk::TreeModelColumn<bool>                                  visible;
267             Gtk::TreeModelColumn<std::string>                   text;
268             Gtk::TreeModelColumn<ARDOUR::RouteGroup*>   group;
269         };
270
271         struct PluginsDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
272             PluginsDisplayModelColumns() {
273                     add (name);
274                     add (plugin);
275             }
276             Gtk::TreeModelColumn<std::string> name;
277                         Gtk::TreeModelColumn<ARDOUR::PluginPresetPtr> plugin;
278         };
279
280         ARDOUR::PluginInfoList favorite_order;
281         std::map<std::string, bool> favorite_ui_state;
282
283         TrackDisplayModelColumns    track_columns;
284         GroupDisplayModelColumns    group_columns;
285         PluginsDisplayModelColumns  favorite_plugins_columns;
286
287         Gtk::TreeView track_display;
288         Gtk::TreeView group_display;
289         Gtkmm2ext::DnDTreeView<ARDOUR::PluginPresetPtr> favorite_plugins_display;
290
291         Glib::RefPtr<Gtk::ListStore> track_model;
292         Glib::RefPtr<Gtk::ListStore> group_model;
293         Glib::RefPtr<PluginTreeStore> favorite_plugins_model;
294
295         bool group_display_button_press (GdkEventButton*);
296         void group_display_selection_changed ();
297
298         bool strip_button_release_event (GdkEventButton*, MixerStrip*);
299
300         Width _strip_width;
301
302         void sync_order_keys_from_treeview ();
303         void sync_treeview_from_order_keys ();
304         void reset_remote_control_ids ();
305         void reset_order_keys ();
306
307         bool ignore_reorder;
308
309         void parameter_changed (std::string const &);
310         void set_route_group_activation (ARDOUR::RouteGroup *, bool);
311
312         void setup_track_display ();
313         void new_track_or_bus ();
314
315         static const int32_t default_width = 478;
316         static const int32_t default_height = 765;
317
318         /** true if we are rebuilding the route group list, or clearing
319             it during a session teardown.
320         */
321         bool _in_group_rebuild_or_clear;
322         bool _route_deletion_in_progress;
323
324         void update_title ();
325         MixerStrip* strip_by_x (int x);
326
327         friend class MixerGroupTabs;
328
329         void follow_editor_selection ();
330         bool _following_editor_selection;
331
332         void monitor_section_going_away ();
333
334         void monitor_section_attached ();
335         void monitor_section_detached ();
336
337         void store_current_favorite_order();
338         void refiller (ARDOUR::PluginInfoList& result, const ARDOUR::PluginInfoList& plugs);
339         void refill_favorite_plugins ();
340         void sync_treeview_from_favorite_order ();
341
342         /// true if we are in fullscreen mode
343         bool _maximised;
344
345         // true if mixer list is visible
346         bool _show_mixer_list;
347 };
348
349 #endif /* __ardour_mixer_ui_h__ */
350
351