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>
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.
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.
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.
27 #ifndef __ardour_gtk_time_axis_h__
28 #define __ardour_gtk_time_axis_h__
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>
43 #include "pbd/stateful.h"
44 #include "pbd/signals.h"
46 #include "evoral/Parameter.h"
48 #include "ardour/types.h"
49 #include "ardour/presentation_info.h"
50 #include "ardour/region.h"
52 #include "canvas/line.h"
54 #include "widgets/focus_entry.h"
56 #include "axis_view.h"
73 namespace ArdourCanvas {
80 class RegionSelection;
83 class TimeAxisViewItem;
93 /** Abstract base class for time-axis views (horizontal editor 'strips')
95 * This class provides the basic LHS controls and display methods. This should be
96 * extended to create functional time-axis based views.
98 class TimeAxisView : public virtual AxisView
101 enum NamePackingBits {
102 NameLabelPacked = 0x1,
103 NameEntryPacked = 0x2
107 TimeAxisView(ARDOUR::Session* sess, PublicEditor& ed, TimeAxisView* parent, ArdourCanvas::Canvas& canvas);
108 virtual ~TimeAxisView ();
110 static PBD::Signal1<void,TimeAxisView*> CatchDeletion;
112 static void setup_sizes ();
114 /** @return index of this TimeAxisView within its parent */
115 int order () const { return _order; }
117 /** @return maximum allowable value of order */
118 static int max_order () { return _max_order; }
120 ArdourCanvas::Container* canvas_display () { return _canvas_display; }
121 ArdourCanvas::Container* ghost_group () { return _ghost_group; }
123 /** @return effective height (taking children into account) in canvas units, or
124 0 if this TimeAxisView has not yet been shown */
125 uint32_t effective_height () const { return _effective_height; }
127 /** @return y position, or -1 if hidden */
128 double y_position () const { return _y_position; }
130 /** @return our Editor */
131 PublicEditor& editor () const { return _editor; }
133 uint32_t current_height() const { return height; }
135 void idle_resize (int32_t);
137 virtual guint32 show_at (double y, int& nth, Gtk::VBox *parent);
138 virtual void hide ();
140 bool touched (double top, double bot);
142 /** @return true if hidden, otherwise false */
143 bool hidden () const { return _hidden; }
145 void set_selected (bool);
147 virtual bool selectable() const { return true; }
150 * potential handler for entered events
153 virtual void entered () {}
154 virtual void exited () {}
156 enum TrackHeightMode {
162 virtual void set_height (uint32_t h, TrackHeightMode m = OnlySelf);
163 void set_height_enum (Height, bool apply_to_selection = false);
166 virtual void reset_visual_state ();
168 std::pair<TimeAxisView*, double> covers_y_position (double) const;
169 bool covered_by_y_range (double y0, double y1) const;
171 virtual void step_height (bool);
173 virtual ARDOUR::RouteGroup* route_group() const { return 0; }
174 virtual boost::shared_ptr<ARDOUR::Playlist> playlist() const { return boost::shared_ptr<ARDOUR::Playlist> (); }
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 ();
183 /* editing operations */
185 virtual void cut_copy_clear (Selection&, Editing::CutCopyOp) {}
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
193 virtual bool paste (ARDOUR::samplepos_t pos,
194 const Selection& selection,
196 const int32_t sub_num)
202 virtual void set_selected_regionviews (RegionSelection&) {}
203 virtual void set_selected_points (PointSelection&);
205 virtual void fade_range (TimeSelection&) {}
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> ();
211 void order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top);
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);
216 void add_ghost (RegionView*);
217 void remove_ghost (RegionView*);
218 void erase_ghost (GhostRegion*);
220 /** called at load time when first GUI idle occurs. put
221 expensive data loading/redisplay code in here. */
222 virtual void first_idle () {}
224 TimeAxisView* get_parent () { return parent; }
225 void set_parent (TimeAxisView& p);
227 virtual LayerDisplay layer_display () const { return Overlaid; }
228 virtual StreamView* view () const { return 0; }
230 typedef std::vector<boost::shared_ptr<TimeAxisView> > Children;
231 Children get_child_list () const;
233 static uint32_t preset_height (Height);
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;
248 Gtk::Fixed scroomer_placeholder;
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;
262 Gtk::Menu* _size_menu;
263 ArdourCanvas::Line* _canvas_separator;
264 ArdourCanvas::Container* _canvas_display;
266 PublicEditor& _editor;
268 virtual bool can_edit_name() const;
270 void begin_name_edit ();
271 void end_name_edit (std::string, int);
272 virtual std::string name () const { return name_label.get_text (); }
274 /* derived classes can override these */
276 virtual bool name_entry_changed (std::string const&);
278 /** Handle mouse relaese on our LHS control name ebox.
280 *@ param ev the event
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*);
288 /** Display the standard LHS control menu at when.
290 * @param when the popup activation time
292 virtual void popup_display_menu (guint32 when);
294 /** Build the standard LHS control menu.
295 * Subclasses should extend this method to add their own menu options.
297 virtual void build_display_menu ();
299 /** Do whatever needs to be done to dynamically reset the LHS control menu.
301 virtual bool handle_display_menu_map_event (GdkEventAny * /*ev*/) { return false; }
304 bool is_child (TimeAxisView*);
305 virtual bool propagate_time_selection () const { return false; }
307 virtual void remove_child (boost::shared_ptr<TimeAxisView>);
308 void add_child (boost::shared_ptr<TimeAxisView>);
310 /* selection display */
312 virtual void selection_click (GdkEventButton*);
314 void color_handler ();
315 void parameter_changed (std::string const &);
317 void conditionally_add_to_selection ();
319 void build_size_menu ();
322 Gtk::VBox* control_parent;
324 uint32_t _effective_height;
325 double _resize_drag_start;
327 GdkCursor* _preresize_cursor;
328 bool _have_preresize_cursor;
329 bool _ebox_release_can_act;
331 static uint32_t button_height;
332 static uint32_t extra_height;
333 static int const _max_order;
335 SelectionRect* get_selection_rect(uint32_t id);
337 void compute_heights ();
338 bool maybe_set_cursor (int y);
340 }; /* class TimeAxisView */
342 #endif /* __ardour_gtk_time_axis_h__ */