add context-menu for processor-sidebar
[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         bool plugin_row_button_press (GdkEventButton*);
203         void popup_note_context_menu (GdkEventButton*);
204
205         enum ProcessorPosition {
206                 AddTop,
207                 AddPreFader,
208                 AddPostFader,
209                 AddBottom
210         };
211
212         void add_selected_processor (ProcessorPosition);
213         void add_favorite_processor (ARDOUR::PluginPresetPtr, ProcessorPosition);
214
215         void initial_track_display ();
216         void show_track_list_menu ();
217
218         void set_all_strips_visibility (bool yn);
219         void set_all_audio_midi_visibility (int, bool);
220         void track_visibility_changed (std::string const & path);
221         void update_track_visibility ();
222
223         void hide_all_routes ();
224         void show_all_routes ();
225         void show_all_audiobus ();
226         void hide_all_audiobus ();
227         void show_all_audiotracks();
228         void hide_all_audiotracks ();
229         void show_all_miditracks();
230         void hide_all_miditracks ();
231
232         bool in_group_row_change;
233
234         void group_selected (gint row, gint col, GdkEvent *ev);
235         void group_unselected (gint row, gint col, GdkEvent *ev);
236         void group_display_active_clicked();
237         void new_route_group ();
238         void remove_selected_route_group ();
239         void activate_all_route_groups ();
240         void disable_all_route_groups ();
241         void add_route_group (ARDOUR::RouteGroup *);
242         void route_groups_changed ();
243         void route_group_name_edit (const std::string&, const std::string&);
244         void route_group_row_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter);
245         void route_group_row_deleted (Gtk::TreeModel::Path const &);
246
247         Gtk::Menu *track_menu;
248         void track_column_click (gint);
249         void build_track_menu ();
250
251         MonitorSection* _monitor_section;
252         PluginSelector    *_plugin_selector;
253
254         void strip_property_changed (const PBD::PropertyChange&, MixerStrip *);
255         void route_group_property_changed (ARDOUR::RouteGroup *, const PBD::PropertyChange &);
256
257         /* various treeviews */
258
259         struct TrackDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
260             TrackDisplayModelColumns () {
261                     add (text);
262                     add (visible);
263                     add (route);
264                     add (strip);
265             }
266             Gtk::TreeModelColumn<bool>           visible;
267             Gtk::TreeModelColumn<std::string>  text;
268             Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Route> > route;
269             Gtk::TreeModelColumn<MixerStrip*>    strip;
270         };
271
272         struct GroupDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
273             GroupDisplayModelColumns() {
274                     add (visible);
275                     add (text);
276                     add (group);
277             }
278             Gtk::TreeModelColumn<bool>                                  visible;
279             Gtk::TreeModelColumn<std::string>                   text;
280             Gtk::TreeModelColumn<ARDOUR::RouteGroup*>   group;
281         };
282
283         struct PluginsDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
284             PluginsDisplayModelColumns() {
285                     add (name);
286                     add (plugin);
287             }
288             Gtk::TreeModelColumn<std::string> name;
289                         Gtk::TreeModelColumn<ARDOUR::PluginPresetPtr> plugin;
290         };
291
292         ARDOUR::PluginInfoList favorite_order;
293         std::map<std::string, bool> favorite_ui_state;
294
295         TrackDisplayModelColumns    track_columns;
296         GroupDisplayModelColumns    group_columns;
297         PluginsDisplayModelColumns  favorite_plugins_columns;
298
299         Gtk::TreeView track_display;
300         Gtk::TreeView group_display;
301         Gtkmm2ext::DnDTreeView<ARDOUR::PluginPresetPtr> favorite_plugins_display;
302
303         Glib::RefPtr<Gtk::ListStore> track_model;
304         Glib::RefPtr<Gtk::ListStore> group_model;
305         Glib::RefPtr<PluginTreeStore> favorite_plugins_model;
306
307         bool group_display_button_press (GdkEventButton*);
308         void group_display_selection_changed ();
309
310         bool strip_button_release_event (GdkEventButton*, MixerStrip*);
311
312         Width _strip_width;
313
314         void sync_order_keys_from_treeview ();
315         void sync_treeview_from_order_keys ();
316         void reset_remote_control_ids ();
317         void reset_order_keys ();
318
319         bool ignore_reorder;
320
321         void parameter_changed (std::string const &);
322         void set_route_group_activation (ARDOUR::RouteGroup *, bool);
323
324         void setup_track_display ();
325         void new_track_or_bus ();
326
327         static const int32_t default_width = 478;
328         static const int32_t default_height = 765;
329
330         /** true if we are rebuilding the route group list, or clearing
331             it during a session teardown.
332         */
333         bool _in_group_rebuild_or_clear;
334         bool _route_deletion_in_progress;
335
336         void update_title ();
337         MixerStrip* strip_by_x (int x);
338
339         friend class MixerGroupTabs;
340
341         void follow_editor_selection ();
342         bool _following_editor_selection;
343
344         void monitor_section_going_away ();
345
346         void monitor_section_attached ();
347         void monitor_section_detached ();
348
349         void store_current_favorite_order();
350         void refiller (ARDOUR::PluginInfoList& result, const ARDOUR::PluginInfoList& plugs);
351         void refill_favorite_plugins ();
352         void sync_treeview_from_favorite_order ();
353
354         /// true if we are in fullscreen mode
355         bool _maximised;
356
357         // true if mixer list is visible
358         bool _show_mixer_list;
359 };
360
361 #endif /* __ardour_mixer_ui_h__ */
362
363