1 /*
2  * Copyright (C) 2006-2008 Sampo Savolainen <v2@iki.fi>
3  * Copyright (C) 2006-2014 David Robillard <d@drobilla.net>
4  * Copyright (C) 2006-2017 Paul Davis <paul@linuxaudiosystems.com>
5  * Copyright (C) 2007 Doug McLain <doug@nostar.net>
6  * Copyright (C) 2008-2012 Carl Hetherington <carl@carlh.net>
7  * Copyright (C) 2014-2015 Ben Loftis <ben@harrisonconsoles.com>
8  * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24 
25 #ifndef __ardour_route_time_axis_h__
26 #define __ardour_route_time_axis_h__
27 
28 #include <list>
29 #include <set>
30 
31 #include <gtkmm/table.h>
32 #include <gtkmm/button.h>
33 #include <gtkmm/box.h>
34 #include <gtkmm/menu.h>
35 #include <gtkmm/menuitem.h>
36 #include <gtkmm/radiomenuitem.h>
37 #include <gtkmm/checkmenuitem.h>
38 #include <gtkmm/adjustment.h>
39 
40 #include "widgets/ardour_button.h"
41 
42 #include "ardour/playlist.h"
43 #include "ardour/types.h"
44 
45 #include "ardour_dialog.h"
46 #include "route_ui.h"
47 #include "enums.h"
48 #include "stripable_time_axis.h"
49 #include "gain_meter.h"
50 
51 namespace ARDOUR {
52 	class Session;
53 	class Region;
54 	class RouteGroup;
55 	class IOProcessor;
56 	class Processor;
57 	class Location;
58 	class Playlist;
59 }
60 
61 namespace ArdourCanvas {
62 	class Rectangle;
63 }
64 
65 class PublicEditor;
66 class RegionView;
67 class StreamView;
68 class Selection;
69 class RegionSelection;
70 class Selectable;
71 class AutomationTimeAxisView;
72 class AutomationLine;
73 class ProcessorAutomationLine;
74 class TimeSelection;
75 class RouteGroupMenu;
76 class ItemCounts;
77 
78 class RouteTimeAxisView : public RouteUI, public StripableTimeAxisView
79 {
80 public:
81 	RouteTimeAxisView (PublicEditor&, ARDOUR::Session*, ArdourCanvas::Canvas& canvas);
82 	virtual ~RouteTimeAxisView ();
83 
84 	std::string name()  const;
85 	Gdk::Color color () const;
86 	bool marked_for_display () const;
87 	bool set_marked_for_display (bool);
88 
stripable()89 	boost::shared_ptr<ARDOUR::Stripable> stripable() const { return RouteUI::stripable(); }
90 
91 	void set_route (boost::shared_ptr<ARDOUR::Route>);
92 
93 	void show_selection (TimeSelection&);
94 	void set_button_names ();
95 
96 	void set_samples_per_pixel (double);
97 	void set_height (uint32_t h, TrackHeightMode m = OnlySelf);
98 	void show_timestretch (samplepos_t start, samplepos_t end, int layers, int layer);
99 	void hide_timestretch ();
100 	void selection_click (GdkEventButton*);
101 	void set_selected_points (PointSelection&);
102 	void set_selected_regionviews (RegionSelection&);
103 	void get_selectables (ARDOUR::samplepos_t start, ARDOUR::samplepos_t end, double top, double bot, std::list<Selectable *>&, bool within = false);
104 	void get_inverted_selectables (Selection&, std::list<Selectable*>&);
105 	void set_layer_display (LayerDisplay d);
106 	void toggle_layer_display ();
107 	LayerDisplay layer_display () const;
108 
109 	boost::shared_ptr<ARDOUR::Region> find_next_region (samplepos_t pos, ARDOUR::RegionPoint, int32_t dir);
110 	samplepos_t find_next_region_boundary (samplepos_t pos, int32_t dir);
111 
112 	/* Editing operations */
113 	void cut_copy_clear (Selection&, Editing::CutCopyOp);
114 	bool paste (ARDOUR::samplepos_t, const Selection&, PasteContext& ctx, const int32_t sub_num);
115 	RegionView* combine_regions ();
116 	void uncombine_regions ();
117 	void uncombine_region (RegionView*);
118 	void toggle_automation_track (const Evoral::Parameter& param);
119 	void fade_range (TimeSelection&);
120 
121 	void add_underlay (StreamView*, bool update_xml = true);
122 	void remove_underlay (StreamView*);
123 	void build_underlay_menu(Gtk::Menu*);
124 
125 	int set_state (const XMLNode&, int version);
126 
127 	virtual Gtk::CheckMenuItem* automation_child_menu_item (Evoral::Parameter);
128 	virtual boost::shared_ptr<AutomationTimeAxisView> automation_child(Evoral::Parameter param, PBD::ID ctrl_id = PBD::ID(0));
129 
view()130 	StreamView*         view() const { return _view; }
131 	ARDOUR::RouteGroup* route_group() const;
132 	boost::shared_ptr<ARDOUR::Playlist> playlist() const;
133 
134 	void fast_update ();
135 	void hide_meter ();
136 	void show_meter ();
137 	void reset_meter ();
138 	void clear_meter ();
139 	void io_changed (ARDOUR::IOChange, void *);
140 	void chan_count_changed ();
141 	void meter_changed ();
effective_gain_display()142 	void effective_gain_display () { gm.effective_gain_display(); }
143 
144 	static sigc::signal<void, bool> signal_ctrl_touched;
145 
146 	std::string state_id() const;
147 
148 	void show_all_automation (bool apply_to_selection = false);
149 	void show_existing_automation (bool apply_to_selection = false);
150 	void hide_all_automation (bool apply_to_selection = false);
151 
152 protected:
153 	friend class StreamView;
154 
155 	struct ProcessorAutomationNode {
156 		Evoral::Parameter                         what;
157 		Gtk::CheckMenuItem*                       menu_item;
158 		boost::shared_ptr<AutomationTimeAxisView> view;
159 		RouteTimeAxisView&                        parent;
160 
ProcessorAutomationNodeProcessorAutomationNode161 		ProcessorAutomationNode (Evoral::Parameter w, Gtk::CheckMenuItem* mitem, RouteTimeAxisView& p)
162 		    : what (w), menu_item (mitem), parent (p) {}
163 
164 		~ProcessorAutomationNode ();
165 	};
166 
167 	struct ProcessorAutomationInfo {
168 		boost::shared_ptr<ARDOUR::Processor> processor;
169 		bool                                  valid;
170 		Gtk::Menu*                            menu;
171 		std::vector<ProcessorAutomationNode*> lines;
172 
ProcessorAutomationInfoProcessorAutomationInfo173 		ProcessorAutomationInfo (boost::shared_ptr<ARDOUR::Processor> i)
174 		    : processor (i), valid (true), menu (0) {}
175 
176 		~ProcessorAutomationInfo ();
177 	};
178 
179 
180 	void update_diskstream_display ();
181 
182 	bool route_group_click  (GdkEventButton *);
183 
184 	virtual void processors_changed (ARDOUR::RouteProcessorChange);
185 
186 	virtual void add_processor_to_subplugin_menu (boost::weak_ptr<ARDOUR::Processor>);
187 	void remove_processor_automation_node (ProcessorAutomationNode* pan);
188 
189 	void processor_menu_item_toggled (RouteTimeAxisView::ProcessorAutomationInfo*,
190 	                                 RouteTimeAxisView::ProcessorAutomationNode*);
191 
192 	void processor_automation_track_hidden (ProcessorAutomationNode*,
193 	                                       boost::shared_ptr<ARDOUR::Processor>);
194 
195 
196 	ProcessorAutomationNode*
197 	find_processor_automation_node (boost::shared_ptr<ARDOUR::Processor> i, Evoral::Parameter);
198 
199 	/* O(log(N)) lookup of menu-item by AC */
200 	Gtk::CheckMenuItem*
201 	find_menu_item_by_ctrl (boost::shared_ptr<ARDOUR::AutomationControl>);
202 
203 	/* O(1) IFF route_owned_only == true, O(N) otherwise */
204 	boost::shared_ptr<AutomationTimeAxisView>
205 	find_atav_by_ctrl (boost::shared_ptr<ARDOUR::AutomationControl>, bool route_owned_only = true);
206 
207 	boost::shared_ptr<AutomationLine>
208 	find_processor_automation_curve (boost::shared_ptr<ARDOUR::Processor> i, Evoral::Parameter);
209 
210 	void add_processor_automation_curve (boost::shared_ptr<ARDOUR::Processor> r, Evoral::Parameter);
211 	void add_existing_processor_automation_curves (boost::weak_ptr<ARDOUR::Processor>);
212 
213 	boost::shared_ptr<AutomationLine> automation_child_by_alist_id (PBD::ID);
214 
215 	void reset_processor_automation_curves ();
216 
217 	void take_name_changed (void *src);
218 	void route_property_changed (const PBD::PropertyChange&);
219 	void route_active_changed ();
220 	bool name_entry_changed (std::string const&);
221 
toggle_channel_selector()222 	virtual void toggle_channel_selector () {}
223 
224 	void blink_rec_display (bool onoff);
225 
226 	virtual void label_view ();
227 
228 	virtual void build_automation_action_menu (bool);
append_extra_display_menu_items()229 	virtual void append_extra_display_menu_items () {}
230 	void         build_display_menu ();
231 
232 	void set_align_choice (Gtk::RadioMenuItem*, ARDOUR::AlignChoice, bool apply_to_selection = false);
233 
234 	bool         playlist_click (GdkEventButton *);
235 	void         playlist_changed ();
236 
237 	bool         automation_click (GdkEventButton *);
238 
239 	void timestretch (samplepos_t start, samplepos_t end);
240 	void speed_changed ();
241 	void map_frozen ();
242 	void color_handler ();
243 	void region_view_added (RegionView*);
244 	void create_gain_automation_child (const Evoral::Parameter &, bool);
245 	void create_trim_automation_child (const Evoral::Parameter &, bool);
246 	void create_mute_automation_child (const Evoral::Parameter &, bool);
247 	void setup_processor_menu_and_curves ();
248 	void route_color_changed ();
249 	bool can_edit_name() const;
250 
251 	StreamView*           _view;
252 
253 	Gtk::HBox   other_button_hbox;
254 	Gtk::Table  button_table;
255 	ArdourWidgets::ArdourButton route_group_button;
256 	ArdourWidgets::ArdourButton playlist_button;
257 	ArdourWidgets::ArdourButton automation_button;
258 	ArdourWidgets::ArdourButton number_label;
259 
260 	Gtk::Menu           subplugin_menu;
261 	Gtk::Menu*          automation_action_menu;
262 	Gtk::MenuItem*      plugins_submenu_item;
263 	RouteGroupMenu*     route_group_menu;
264 	Gtk::MenuItem*      overlaid_menu_item;
265 	Gtk::MenuItem*      stacked_menu_item;
266 
267 	ArdourCanvas::Rectangle* timestretch_rect;
268 
269 	/** Information about all automatable processor parameters that apply to
270 	 *  this route.  The Amp processor is not included in this list.
271 	 */
272 	std::list<ProcessorAutomationInfo*> processor_automation;
273 
274 	std::map<boost::shared_ptr<PBD::Controllable>, Gtk::CheckMenuItem*> ctrl_item_map;
275 
276 	typedef std::vector<boost::shared_ptr<AutomationLine> > ProcessorAutomationCurves;
277 	ProcessorAutomationCurves processor_automation_curves;
278 	/** parameter -> menu item map for the plugin automation menu */
279 	ParameterMenuMap _subplugin_menu_map;
280 
281 	void post_construct ();
282 
283 	GainMeterBase gm;
284 
285 	XMLNode* underlay_xml_node;
286 	bool set_underlay_state();
287 
288 	typedef std::list<StreamView*> UnderlayList;
289 	UnderlayList _underlay_streams;
290 	typedef std::list<RouteTimeAxisView*> UnderlayMirrorList;
291 	UnderlayMirrorList _underlay_mirrors;
292 
293 	bool _ignore_set_layer_display;
294 	void layer_display_menu_change (Gtk::MenuItem* item);
295 
296 protected:
297 	void update_pan_track_visibility ();
298 
299 	/** Ensure that we have the appropriate automation lanes for panners.
300 	 *
301 	 *  @param show true to show any new views that we create, otherwise false.
302 	 */
303 	void ensure_pan_views (bool show = true);
304 
305 	std::list<boost::shared_ptr<AutomationTimeAxisView> > pan_tracks;
306 	Gtk::CheckMenuItem* pan_automation_item;
307 
308 private:
309 
310 	void remove_child (boost::shared_ptr<TimeAxisView>);
311 	void update_playlist_tip ();
312 	void parameter_changed (std::string const & p);
313 	void update_track_number_visibility();
314 	void show_touched_automation (boost::weak_ptr<PBD::Controllable>);
315 	void maybe_hide_automation (bool, boost::weak_ptr<PBD::Controllable>);
316 
317 	void drop_instrument_ref ();
318 	void reread_midnam ();
319 	PBD::ScopedConnectionList midnam_connection;
320 
321 	PBD::ScopedConnection ctrl_touched_connection;
322 	sigc::connection      ctrl_autohide_connection;
323 };
324 
325 #endif /* __ardour_route_time_axis_h__ */
326