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.hpp"
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.
192 virtual bool paste (ARDOUR::samplepos_t pos,
193 const Selection& selection,
195 const int32_t sub_num)
201 virtual void set_selected_regionviews (RegionSelection&) {}
202 virtual void set_selected_points (PointSelection&);
204 virtual void fade_range (TimeSelection&) {}
206 virtual boost::shared_ptr<ARDOUR::Region> find_next_region (samplepos_t /*pos*/, ARDOUR::RegionPoint, int32_t /*dir*/) {
207 return boost::shared_ptr<ARDOUR::Region> ();
210 void order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top);
212 virtual void get_selectables (ARDOUR::samplepos_t, ARDOUR::samplepos_t, double, double, std::list<Selectable*>&, bool within = false);
213 virtual void get_inverted_selectables (Selection&, std::list<Selectable *>& results);
215 void add_ghost (RegionView*);
216 void remove_ghost (RegionView*);
217 void erase_ghost (GhostRegion*);
219 /** called at load time when first GUI idle occurs. put
220 expensive data loading/redisplay code in here. */
221 virtual void first_idle () {}
223 TimeAxisView* get_parent () { return parent; }
224 void set_parent (TimeAxisView& p);
226 virtual LayerDisplay layer_display () const { return Overlaid; }
227 virtual StreamView* view () const { return 0; }
229 typedef std::vector<boost::shared_ptr<TimeAxisView> > Children;
230 Children get_child_list () const;
232 static uint32_t preset_height (Height);
235 static Glib::RefPtr<Gtk::SizeGroup> controls_meters_size_group;
236 static Glib::RefPtr<Gtk::SizeGroup> midi_scroomer_size_group;
237 static unsigned int name_width_px;
238 /* The Standard LHS Controls */
239 Gtk::Table controls_table;
240 Glib::RefPtr<Gtk::SizeGroup> controls_button_size_group;
241 Gtk::EventBox controls_ebox;
242 Gtk::VBox controls_vbox;
243 Gtk::VBox time_axis_vbox;
244 Gtk::HBox time_axis_hbox;
245 Gtk::Frame time_axis_frame;
247 Gtk::Fixed scroomer_placeholder;
249 uint32_t height; /* in canvas units */
250 std::string controls_base_unselected_name;
251 std::string controls_base_selected_name;
252 Gtk::Menu* display_menu; /* The standard LHS Track control popup-menus */
253 TimeAxisView* parent;
254 ArdourCanvas::Container* selection_group;
255 ArdourCanvas::Container* _ghost_group;
256 std::list<GhostRegion*> ghosts;
257 std::list<SelectionRect*> free_selection_rects;
258 std::list<SelectionRect*> used_selection_rects;
261 Gtk::Menu* _size_menu;
262 ArdourCanvas::Line* _canvas_separator;
263 ArdourCanvas::Container* _canvas_display;
265 PublicEditor& _editor;
267 virtual bool can_edit_name() const;
269 void begin_name_edit ();
270 void end_name_edit (std::string, int);
271 virtual std::string name () const { return name_label.get_text (); }
273 /* derived classes can override these */
275 virtual bool name_entry_changed (std::string const&);
277 /** Handle mouse relaese on our LHS control name ebox.
279 *@ param ev the event
281 virtual bool controls_ebox_button_release (GdkEventButton*);
282 virtual bool controls_ebox_scroll (GdkEventScroll*);
283 virtual bool controls_ebox_button_press (GdkEventButton*);
284 virtual bool controls_ebox_motion (GdkEventMotion*);
285 virtual bool controls_ebox_leave (GdkEventCrossing*);
287 /** Display the standard LHS control menu at when.
289 * @param when the popup activation time
291 virtual void popup_display_menu (guint32 when);
293 /** Build the standard LHS control menu.
294 * Subclasses should extend this method to add their own menu options.
296 virtual void build_display_menu ();
298 /** Do whatever needs to be done to dynamically reset the LHS control menu.
300 virtual bool handle_display_menu_map_event (GdkEventAny * /*ev*/) { return false; }
303 bool is_child (TimeAxisView*);
304 virtual bool propagate_time_selection () const { return false; }
306 virtual void remove_child (boost::shared_ptr<TimeAxisView>);
307 void add_child (boost::shared_ptr<TimeAxisView>);
309 /* selection display */
311 virtual void selection_click (GdkEventButton*);
313 void color_handler ();
314 void parameter_changed (std::string const &);
316 void conditionally_add_to_selection ();
318 void build_size_menu ();
321 Gtk::VBox* control_parent;
323 uint32_t _effective_height;
324 double _resize_drag_start;
326 GdkCursor* _preresize_cursor;
327 bool _have_preresize_cursor;
328 bool _ebox_release_can_act;
330 static uint32_t button_height;
331 static uint32_t extra_height;
332 static int const _max_order;
334 SelectionRect* get_selection_rect(uint32_t id);
336 void compute_heights ();
337 bool maybe_set_cursor (int y);
339 }; /* class TimeAxisView */
341 #endif /* __ardour_gtk_time_axis_h__ */