1 /*
2  * Copyright (C) 2005-2008 Nick Mainsbridge <mainsbridge@gmail.com>
3  * Copyright (C) 2005-2019 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2005 Karsten Wiese <fzuuzf@googlemail.com>
5  * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
6  * Copyright (C) 2006-2014 David Robillard <d@drobilla.net>
7  * Copyright (C) 2007 Doug McLain <doug@nostar.net>
8  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
9  * Copyright (C) 2014-2015 Ben Loftis <ben@harrisonconsoles.com>
10  * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26 
27 #ifndef __ardour_gtk_time_axis_h__
28 #define __ardour_gtk_time_axis_h__
29 
30 #include <vector>
31 #include <list>
32 
33 #include <gtkmm/box.h>
34 #include <gtkmm/fixed.h>
35 #include <gtkmm/frame.h>
36 #include <gtkmm/drawingarea.h>
37 #include <gtkmm/eventbox.h>
38 #include <gtkmm/table.h>
39 #include <gtkmm/entry.h>
40 #include <gtkmm/label.h>
41 #include <gtkmm/sizegroup.h>
42 
43 #include "pbd/stateful.h"
44 #include "pbd/signals.h"
45 
46 #include "evoral/Parameter.h"
47 
48 #include "ardour/types.h"
49 #include "ardour/presentation_info.h"
50 #include "ardour/region.h"
51 
52 #include "canvas/line.h"
53 
54 #include "widgets/focus_entry.h"
55 
56 #include "axis_view.h"
57 #include "enums.h"
58 #include "editing.h"
59 
60 namespace ARDOUR {
61 	class Session;
62 	class Region;
63 	class Session;
64 	class RouteGroup;
65 	class Playlist;
66 	class Stripable;
67 }
68 
69 namespace Gtk {
70 	class Menu;
71 }
72 
73 namespace ArdourCanvas {
74 	class Canvas;
75 	class Container;
76 	class Item;
77 }
78 
79 class PublicEditor;
80 class RegionSelection;
81 class TimeSelection;
82 class PointSelection;
83 class TimeAxisViewItem;
84 class Selection;
85 class Selectable;
86 class RegionView;
87 class GhostRegion;
88 class StreamView;
89 class ArdourDialog;
90 class ItemCounts;
91 class PasteContext;
92 
93 /** Abstract base class for time-axis views (horizontal editor 'strips')
94  *
95  * This class provides the basic LHS controls and display methods. This should be
96  * extended to create functional time-axis based views.
97  */
98 class TimeAxisView : public virtual AxisView
99 {
100 private:
101 	enum NamePackingBits {
102 		NameLabelPacked = 0x1,
103 		NameEntryPacked = 0x2
104 	};
105 
106 public:
107 	TimeAxisView(ARDOUR::Session* sess, PublicEditor& ed, TimeAxisView* parent, ArdourCanvas::Canvas& canvas);
108 	virtual ~TimeAxisView ();
109 
110 	static PBD::Signal1<void,TimeAxisView*> CatchDeletion;
111 
112 	static void setup_sizes ();
113 
114 	/** @return index of this TimeAxisView within its parent */
order()115 	int order () const { return _order; }
116 
117 	/** @return maximum allowable value of order */
max_order()118 	static int max_order () { return _max_order; }
119 
canvas_display()120 	ArdourCanvas::Container* canvas_display () { return _canvas_display; }
ghost_group()121 	ArdourCanvas::Container* ghost_group () { return _ghost_group; }
122 
123 	/** @return effective height (taking children into account) in canvas units, or
124 		0 if this TimeAxisView has not yet been shown */
effective_height()125 	uint32_t effective_height () const { return _effective_height; }
126 
127 	/** @return y position, or -1 if hidden */
y_position()128 	double y_position () const { return _y_position; }
129 
130 	/** @return our Editor */
editor()131 	PublicEditor& editor () const { return _editor; }
132 
current_height()133 	uint32_t current_height() const { return height; }
134 
135 	void idle_resize (int32_t);
136 
137 	virtual guint32 show_at (double y, int& nth, Gtk::VBox *parent);
138 	virtual void hide ();
139 
140 	bool touched (double top, double bot);
141 
142 	/** @return true if hidden, otherwise false */
hidden()143 	bool hidden () const { return _hidden; }
144 
145 	void set_selected (bool);
146 
selectable()147 	virtual bool selectable() const { return true; }
148 
149 	/**
150 	 * potential handler for entered events
151 	 */
152 
entered()153 	virtual void entered () {}
exited()154 	virtual void exited () {}
155 
156 	enum TrackHeightMode {
157 		OnlySelf,
158 		TotalHeight,
159 		HeightPerLane
160 	};
161 
162 	virtual void set_height (uint32_t h, TrackHeightMode m = OnlySelf);
163 	void set_height_enum (Height, bool apply_to_selection = false);
164 	void reset_height();
165 
166 	virtual void reset_visual_state ();
167 
168 	std::pair<TimeAxisView*, double> covers_y_position (double) const;
169 	bool covered_by_y_range (double y0, double y1) const;
170 
171 	virtual void step_height (bool);
172 
route_group()173 	virtual ARDOUR::RouteGroup* route_group() const { return 0; }
playlist()174 	virtual boost::shared_ptr<ARDOUR::Playlist> playlist() const { return boost::shared_ptr<ARDOUR::Playlist> (); }
175 
176 	virtual void set_samples_per_pixel (double);
177 	virtual void show_selection (TimeSelection&);
178 	virtual void hide_selection ();
179 	virtual void reshow_selection (TimeSelection&);
180 	virtual void show_timestretch (samplepos_t start, samplepos_t end, int layers, int layer);
181 	virtual void hide_timestretch ();
182 
183 	/* editing operations */
184 
cut_copy_clear(Selection &,Editing::CutCopyOp)185 	virtual void cut_copy_clear (Selection&, Editing::CutCopyOp) {}
186 
187 	/** Paste a selection.
188 	 *  @param pos Position to paste to (session samples).
189 	 *  @param selection Selection to paste.
190 	 *  @param ctx Paste context.
191 	 *  @param sub_num music-time sub-division: \c -1: snap to bar, \c 1: exact beat, \c >1: \c (1 \c / \p sub_num \c ) beat-divisions
192 	 */
paste(ARDOUR::samplepos_t pos,const Selection & selection,PasteContext & ctx,const int32_t sub_num)193 	virtual bool paste (ARDOUR::samplepos_t pos,
194 	                    const Selection&    selection,
195 	                    PasteContext&       ctx,
196 	                    const int32_t sub_num)
197 	{
198 		return false;
199 	}
200 
201 
set_selected_regionviews(RegionSelection &)202 	virtual void set_selected_regionviews (RegionSelection&) {}
203 	virtual void set_selected_points (PointSelection&);
204 
fade_range(TimeSelection &)205 	virtual void fade_range (TimeSelection&) {}
206 
find_next_region(samplepos_t,ARDOUR::RegionPoint,int32_t)207 	virtual boost::shared_ptr<ARDOUR::Region> find_next_region (samplepos_t /*pos*/, ARDOUR::RegionPoint, int32_t /*dir*/) {
208 		return boost::shared_ptr<ARDOUR::Region> ();
209 	}
210 
211 	void order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top);
212 
213 	virtual void get_selectables (ARDOUR::samplepos_t, ARDOUR::samplepos_t, double, double, std::list<Selectable*>&, bool within = false);
214 	virtual void get_inverted_selectables (Selection&, std::list<Selectable *>& results);
215 
216 	void add_ghost (RegionView*);
217 	void remove_ghost (RegionView*);
218 	void erase_ghost (GhostRegion*);
219 
220 	/** called at load time when first GUI idle occurs. put
221 	    expensive data loading/redisplay code in here. */
first_idle()222 	virtual void first_idle () {}
223 
get_parent()224 	TimeAxisView* get_parent () { return parent; }
225 	void set_parent (TimeAxisView& p);
226 
layer_display()227 	virtual LayerDisplay layer_display () const { return Overlaid; }
view()228 	virtual StreamView* view () const { return 0; }
229 
230 	typedef std::vector<boost::shared_ptr<TimeAxisView> > Children;
231 	Children get_child_list () const;
232 
233 	static uint32_t preset_height (Height);
234 
235 protected:
236 	static Glib::RefPtr<Gtk::SizeGroup> controls_meters_size_group;
237 	static Glib::RefPtr<Gtk::SizeGroup> midi_scroomer_size_group;
238 	static unsigned int name_width_px;
239 	/* The Standard LHS Controls */
240 	Gtk::Table             controls_table;
241 	Glib::RefPtr<Gtk::SizeGroup> controls_button_size_group;
242 	Gtk::EventBox          controls_ebox;
243 	Gtk::VBox              controls_vbox;
244 	Gtk::VBox              time_axis_vbox;
245 	Gtk::HBox              time_axis_hbox;
246 	Gtk::Frame             time_axis_frame;
247 	Gtk::HBox              top_hbox;
248 	Gtk::Fixed             scroomer_placeholder;
249 	bool                  _name_editing;
250 	uint32_t               height;  /* in canvas units */
251 	std::string            controls_base_unselected_name;
252 	std::string            controls_base_selected_name;
253 	Gtk::Menu*             display_menu; /* The standard LHS Track control popup-menus */
254 	TimeAxisView*          parent;
255 	ArdourCanvas::Container*   selection_group;
256 	ArdourCanvas::Container*  _ghost_group;
257 	std::list<GhostRegion*> ghosts;
258 	std::list<SelectionRect*> free_selection_rects;
259 	std::list<SelectionRect*> used_selection_rects;
260 	bool                  _hidden;
261 	bool                   in_destructor;
262 	Gtk::Menu*            _size_menu;
263 	ArdourCanvas::Line*       _canvas_separator;
264 	ArdourCanvas::Container*  _canvas_display;
265 	double                _y_position;
266 	PublicEditor&         _editor;
267 
268 	virtual bool can_edit_name() const;
269 
270 	void begin_name_edit ();
271 	void end_name_edit (std::string, int);
name()272 	virtual std::string name () const { return name_label.get_text (); }
273 
274 	/* derived classes can override these */
275 
276 	virtual bool name_entry_changed (std::string const&);
277 
278 	/** Handle mouse relaese on our LHS control name ebox.
279 	 *
280 	 *@ param ev the event
281 	 */
282 	virtual bool controls_ebox_button_release (GdkEventButton*);
283 	virtual bool controls_ebox_scroll (GdkEventScroll*);
284 	virtual bool controls_ebox_button_press (GdkEventButton*);
285 	virtual bool controls_ebox_motion (GdkEventMotion*);
286 	virtual bool controls_ebox_leave (GdkEventCrossing*);
287 
288 	/** Display the standard LHS control menu at when.
289 	 *
290 	 * @param when the popup activation time
291 	 */
292 	virtual void popup_display_menu (guint32 when);
293 
294 	/** Build the standard LHS control menu.
295 	 * Subclasses should extend this method to add their own menu options.
296 	 */
297 	virtual void build_display_menu ();
298 
299 	/** Do whatever needs to be done to dynamically reset the LHS control menu.
300 	 */
handle_display_menu_map_event(GdkEventAny *)301 	virtual bool handle_display_menu_map_event (GdkEventAny * /*ev*/) { return false; }
302 
303 	Children children;
304 	bool is_child (TimeAxisView*);
propagate_time_selection()305 	virtual bool propagate_time_selection () const { return false; }
306 
307 	virtual void remove_child (boost::shared_ptr<TimeAxisView>);
308 	void add_child (boost::shared_ptr<TimeAxisView>);
309 
310 	/* selection display */
311 
312 	virtual void selection_click (GdkEventButton*);
313 
314 	void color_handler ();
315 	void parameter_changed (std::string const &);
316 
317 	void conditionally_add_to_selection ();
318 
319 	void build_size_menu ();
320 
321 private:
322 	Gtk::VBox*            control_parent;
323 	int                  _order;
324 	uint32_t             _effective_height;
325 	double               _resize_drag_start;
326 	bool                 _did_resize;
327 	GdkCursor*           _preresize_cursor;
328 	bool                 _have_preresize_cursor;
329 	bool                 _ebox_release_can_act;
330 
331 	static uint32_t button_height;
332 	static uint32_t extra_height;
333 	static int const _max_order;
334 
335 	SelectionRect* get_selection_rect(uint32_t id);
336 
337 	void compute_heights ();
338 	bool maybe_set_cursor (int y);
339 
340 }; /* class TimeAxisView */
341 
342 #endif /* __ardour_gtk_time_axis_h__ */
343