Separate Ardour UI widgets into dedicated library
[ardour.git] / gtk2_ardour / route_time_axis.h
1 /*
2     Copyright (C) 2006 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_route_time_axis_h__
21 #define __ardour_route_time_axis_h__
22
23 #include <list>
24 #include <set>
25
26 #include <gtkmm/table.h>
27 #include <gtkmm/button.h>
28 #include <gtkmm/box.h>
29 #include <gtkmm/menu.h>
30 #include <gtkmm/menuitem.h>
31 #include <gtkmm/radiomenuitem.h>
32 #include <gtkmm/checkmenuitem.h>
33 #include <gtkmm/adjustment.h>
34
35 #include <gtkmm2ext/selector.h>
36 #include <gtkmm2ext/slider_controller.h>
37
38 #include "widgets/ardour_button.h"
39
40 #include "ardour/playlist.h"
41 #include "ardour/types.h"
42
43 #include "ardour_dialog.h"
44 #include "route_ui.h"
45 #include "enums.h"
46 #include "stripable_time_axis.h"
47 #include "gain_meter.h"
48
49 namespace ARDOUR {
50         class Session;
51         class Region;
52         class RouteGroup;
53         class IOProcessor;
54         class Processor;
55         class Location;
56         class Playlist;
57 }
58
59 namespace ArdourCanvas {
60         class Rectangle;
61 }
62
63 class PublicEditor;
64 class RegionView;
65 class StreamView;
66 class Selection;
67 class RegionSelection;
68 class Selectable;
69 class AutomationTimeAxisView;
70 class AutomationLine;
71 class ProcessorAutomationLine;
72 class TimeSelection;
73 class RouteGroupMenu;
74 class ItemCounts;
75
76 class RouteTimeAxisView : public RouteUI, public StripableTimeAxisView
77 {
78 public:
79         RouteTimeAxisView (PublicEditor&, ARDOUR::Session*, ArdourCanvas::Canvas& canvas);
80         virtual ~RouteTimeAxisView ();
81
82         std::string name()  const;
83         Gdk::Color color () const;
84         bool marked_for_display () const;
85         bool set_marked_for_display (bool);
86
87         boost::shared_ptr<ARDOUR::Stripable> stripable() const { return RouteUI::stripable(); }
88
89         void set_route (boost::shared_ptr<ARDOUR::Route>);
90
91         void show_selection (TimeSelection&);
92         void set_button_names ();
93
94         void set_samples_per_pixel (double);
95         void set_height (uint32_t h, TrackHeightMode m = OnlySelf);
96         void show_timestretch (framepos_t start, framepos_t end, int layers, int layer);
97         void hide_timestretch ();
98         void selection_click (GdkEventButton*);
99         void set_selected_points (PointSelection&);
100         void set_selected_regionviews (RegionSelection&);
101         void get_selectables (ARDOUR::framepos_t start, ARDOUR::framepos_t end, double top, double bot, std::list<Selectable *>&, bool within = false);
102         void get_inverted_selectables (Selection&, std::list<Selectable*>&);
103         void set_layer_display (LayerDisplay d, bool apply_to_selection = false);
104         LayerDisplay layer_display () const;
105
106         boost::shared_ptr<ARDOUR::Region> find_next_region (framepos_t pos, ARDOUR::RegionPoint, int32_t dir);
107         framepos_t find_next_region_boundary (framepos_t pos, int32_t dir);
108
109         /* Editing operations */
110         void cut_copy_clear (Selection&, Editing::CutCopyOp);
111         bool paste (ARDOUR::framepos_t, const Selection&, PasteContext& ctx, const int32_t sub_num);
112         RegionView* combine_regions ();
113         void uncombine_regions ();
114         void uncombine_region (RegionView*);
115         void toggle_automation_track (const Evoral::Parameter& param);
116         void fade_range (TimeSelection&);
117
118         /* The editor calls these when mapping an operation across multiple tracks */
119         void use_new_playlist (bool prompt, std::vector<boost::shared_ptr<ARDOUR::Playlist> > const &, bool copy);
120         void clear_playlist ();
121
122         /* group playlist name resolving */
123         std::string resolve_new_group_playlist_name(std::string &, std::vector<boost::shared_ptr<ARDOUR::Playlist> > const &);
124
125         void build_playlist_menu ();
126
127         void add_underlay (StreamView*, bool update_xml = true);
128         void remove_underlay (StreamView*);
129         void build_underlay_menu(Gtk::Menu*);
130
131         int set_state (const XMLNode&, int version);
132
133         virtual Gtk::CheckMenuItem* automation_child_menu_item (Evoral::Parameter);
134
135         StreamView*         view() const { return _view; }
136         ARDOUR::RouteGroup* route_group() const;
137         boost::shared_ptr<ARDOUR::Playlist> playlist() const;
138
139         void fast_update ();
140         void hide_meter ();
141         void show_meter ();
142         void reset_meter ();
143         void clear_meter ();
144         void io_changed (ARDOUR::IOChange, void *);
145         void meter_changed ();
146         void effective_gain_display () { gm.effective_gain_display(); }
147
148         std::string state_id() const;
149
150 protected:
151         friend class StreamView;
152
153         struct ProcessorAutomationNode {
154                 Evoral::Parameter                         what;
155                 Gtk::CheckMenuItem*                       menu_item;
156                 boost::shared_ptr<AutomationTimeAxisView> view;
157                 RouteTimeAxisView&                        parent;
158
159                 ProcessorAutomationNode (Evoral::Parameter w, Gtk::CheckMenuItem* mitem, RouteTimeAxisView& p)
160                     : what (w), menu_item (mitem), parent (p) {}
161
162                 ~ProcessorAutomationNode ();
163         };
164
165         struct ProcessorAutomationInfo {
166                 boost::shared_ptr<ARDOUR::Processor> processor;
167                 bool                                 valid;
168                 Gtk::Menu*                           menu;
169                 std::vector<ProcessorAutomationNode*>     lines;
170
171                 ProcessorAutomationInfo (boost::shared_ptr<ARDOUR::Processor> i)
172                     : processor (i), valid (true), menu (0) {}
173
174                 ~ProcessorAutomationInfo ();
175         };
176
177
178         void update_diskstream_display ();
179
180         bool route_group_click  (GdkEventButton *);
181
182         void processors_changed (ARDOUR::RouteProcessorChange);
183
184         virtual void add_processor_to_subplugin_menu (boost::weak_ptr<ARDOUR::Processor>);
185         void remove_processor_automation_node (ProcessorAutomationNode* pan);
186
187         void processor_menu_item_toggled (RouteTimeAxisView::ProcessorAutomationInfo*,
188                                          RouteTimeAxisView::ProcessorAutomationNode*);
189
190         void processor_automation_track_hidden (ProcessorAutomationNode*,
191                                                boost::shared_ptr<ARDOUR::Processor>);
192
193
194         ProcessorAutomationNode*
195         find_processor_automation_node (boost::shared_ptr<ARDOUR::Processor> i, Evoral::Parameter);
196
197         boost::shared_ptr<AutomationLine>
198         find_processor_automation_curve (boost::shared_ptr<ARDOUR::Processor> i, Evoral::Parameter);
199
200         void add_processor_automation_curve (boost::shared_ptr<ARDOUR::Processor> r, Evoral::Parameter);
201         void add_existing_processor_automation_curves (boost::weak_ptr<ARDOUR::Processor>);
202
203
204         void reset_processor_automation_curves ();
205
206         void take_name_changed (void *src);
207         void route_property_changed (const PBD::PropertyChange&);
208         bool name_entry_changed (std::string const&);
209
210         virtual void toggle_channel_selector () {}
211
212         void blink_rec_display (bool onoff);
213
214         virtual void label_view ();
215
216         virtual void build_automation_action_menu (bool);
217         virtual void append_extra_display_menu_items () {}
218         void         build_display_menu ();
219
220         void set_align_choice (Gtk::RadioMenuItem*, ARDOUR::AlignChoice, bool apply_to_selection = false);
221
222         bool         playlist_click (GdkEventButton *);
223         void         show_playlist_selector ();
224         void         playlist_changed ();
225
226         void rename_current_playlist ();
227
228         bool         automation_click (GdkEventButton *);
229
230         virtual void show_all_automation (bool apply_to_selection = false);
231         virtual void show_existing_automation (bool apply_to_selection = false);
232         virtual void hide_all_automation (bool apply_to_selection = false);
233
234         void timestretch (framepos_t start, framepos_t end);
235         void speed_changed ();
236         void map_frozen ();
237         void color_handler ();
238         void region_view_added (RegionView*);
239         void create_gain_automation_child (const Evoral::Parameter &, bool);
240         void create_trim_automation_child (const Evoral::Parameter &, bool);
241         void create_mute_automation_child (const Evoral::Parameter &, bool);
242         void setup_processor_menu_and_curves ();
243         void route_color_changed ();
244         bool can_edit_name() const;
245
246         StreamView*           _view;
247
248         Gtk::HBox   other_button_hbox;
249         Gtk::Table  button_table;
250         ArdourWidgets::ArdourButton route_group_button;
251         ArdourWidgets::ArdourButton playlist_button;
252         ArdourWidgets::ArdourButton automation_button;
253         ArdourWidgets::ArdourButton number_label;
254
255         Gtk::Menu           subplugin_menu;
256         Gtk::Menu*          automation_action_menu;
257         Gtk::MenuItem*      plugins_submenu_item;
258         RouteGroupMenu*     route_group_menu;
259         Gtk::Menu*          playlist_action_menu;
260         Gtk::MenuItem*      playlist_item;
261         Gtk::Menu*          mode_menu;
262         Gtk::Menu*          color_mode_menu;
263
264         virtual Gtk::Menu* build_color_mode_menu() { return 0; }
265
266         void use_playlist (Gtk::RadioMenuItem *item, boost::weak_ptr<ARDOUR::Playlist> wpl);
267
268         ArdourCanvas::Rectangle* timestretch_rect;
269
270 #ifdef XXX_OLD_DESTRUCTIVE_API_XXX
271         void set_track_mode (ARDOUR::TrackMode, bool apply_to_selection = false);
272 #endif
273
274         /** Information about all automatable processor parameters that apply to
275          *  this route.  The Amp processor is not included in this list.
276          */
277         std::list<ProcessorAutomationInfo*> processor_automation;
278
279         typedef std::vector<boost::shared_ptr<AutomationLine> > ProcessorAutomationCurves;
280         ProcessorAutomationCurves processor_automation_curves;
281         /** parameter -> menu item map for the plugin automation menu */
282         ParameterMenuMap _subplugin_menu_map;
283
284         void post_construct ();
285
286         GainMeterBase gm;
287
288         XMLNode* underlay_xml_node;
289         bool set_underlay_state();
290
291         typedef std::list<StreamView*> UnderlayList;
292         UnderlayList _underlay_streams;
293         typedef std::list<RouteTimeAxisView*> UnderlayMirrorList;
294         UnderlayMirrorList _underlay_mirrors;
295
296         bool _ignore_set_layer_display;
297
298 protected:
299         void update_pan_track_visibility ();
300
301         /** Ensure that we have the appropriate automation lanes for panners.
302          *
303          *  @param show true to show any new views that we create, otherwise false.
304          */
305         void ensure_pan_views (bool show = true);
306
307         std::list<boost::shared_ptr<AutomationTimeAxisView> > pan_tracks;
308         Gtk::CheckMenuItem* pan_automation_item;
309
310 private:
311
312         void remove_child (boost::shared_ptr<TimeAxisView>);
313         void update_playlist_tip ();
314         void parameter_changed (std::string const & p);
315         void update_track_number_visibility();
316 };
317
318 #endif /* __ardour_route_time_axis_h__ */