Attempt #46 to understand MIDI data locking.
[ardour2.git] / gtk2_ardour / time_axis_view.h
blob92835fb59e2ed611350e5b552da73e41f834e5d0
1 /*
2 Copyright (C) 2003 Paul Davis
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.
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.
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.
20 #ifndef __ardour_gtk_time_axis_h__
21 #define __ardour_gtk_time_axis_h__
23 #include <vector>
24 #include <list>
26 #include <gtkmm/box.h>
27 #include <gtkmm/frame.h>
28 #include <gtkmm/drawingarea.h>
29 #include <gtkmm/eventbox.h>
30 #include <gtkmm/table.h>
31 #include <gtkmm/entry.h>
32 #include <gtkmm/label.h>
34 #include <gtkmm2ext/focus_entry.h>
36 #include "pbd/stateful.h"
37 #include "pbd/signals.h"
39 #include "ardour/types.h"
40 #include "ardour/region.h"
41 #include "evoral/Parameter.hpp"
43 #include "prompter.h"
44 #include "axis_view.h"
45 #include "enums.h"
46 #include "editing.h"
47 #include "canvas.h"
49 namespace ARDOUR {
50 class Session;
51 class Region;
52 class Session;
53 class RouteGroup;
54 class Playlist;
57 namespace Gtk {
58 class Menu;
61 class PublicEditor;
62 class RegionSelection;
63 class TimeSelection;
64 class PointSelection;
65 class TimeAxisViewItem;
66 class Selection;
67 class Selectable;
68 class RegionView;
69 class GhostRegion;
70 class StreamView;
72 /** Abstract base class for time-axis views (horizontal editor 'strips')
74 * This class provides the basic LHS controls and display methods. This should be
75 * extended to create functional time-axis based views.
77 class TimeAxisView : public virtual AxisView, public PBD::Stateful
79 private:
80 enum NamePackingBits {
81 NameLabelPacked = 0x1,
82 NameEntryPacked = 0x2
85 public:
87 TimeAxisView(ARDOUR::Session* sess, PublicEditor& ed, TimeAxisView* parent, ArdourCanvas::Canvas& canvas);
88 virtual ~TimeAxisView ();
90 XMLNode& get_state ();
91 int set_state (const XMLNode&, int version);
93 static PBD::Signal1<void,TimeAxisView*> CatchDeletion;
95 /** @return index of this TimeAxisView within its parent */
96 int order () const { return _order; }
98 /** @return maximum allowable value of order */
99 static int max_order () { return _max_order; }
101 virtual void enter_internal_edit_mode () {}
102 virtual void leave_internal_edit_mode () {}
104 ArdourCanvas::Group* canvas_display () { return _canvas_display; }
105 ArdourCanvas::Group* canvas_background () { return _canvas_background; }
106 ArdourCanvas::Group* ghost_group () { return _ghost_group; }
108 /** @return effective height (taking children into account) in canvas units, or
109 0 if this TimeAxisView has not yet been shown */
110 uint32_t effective_height () const { return _effective_height; }
112 /** @return y position, or -1 if hidden */
113 double y_position () const { return _y_position; }
115 /** @return our Editor */
116 PublicEditor& editor () const { return _editor; }
118 uint32_t current_height() const { return height; }
120 bool resizer_button_press (GdkEventButton*);
121 bool resizer_button_release (GdkEventButton*);
122 bool resizer_motion (GdkEventMotion*);
123 bool resizer_expose (GdkEventExpose*);
125 void idle_resize (uint32_t);
127 void hide_name_label ();
128 void hide_name_entry ();
129 void show_name_label ();
130 void show_name_entry ();
132 virtual bool set_visibility (bool);
133 virtual guint32 show_at (double y, int& nth, Gtk::VBox *parent);
135 void clip_to_viewport ();
137 bool touched (double top, double bot);
139 /** Hide this TrackView */
140 virtual void hide ();
142 /** @return true if hidden, otherwise false */
143 bool hidden () const { return _hidden; }
145 virtual void set_selected (bool);
148 * potential handler for entered events
151 virtual void entered () {}
152 virtual void exited () {}
154 virtual void set_height (uint32_t h);
155 void set_height_enum (Height, bool apply_to_selection = false);
156 void reset_height();
158 std::pair<TimeAxisView*, ARDOUR::layer_t> covers_y_position (double);
160 virtual void step_height (bool);
162 virtual ARDOUR::RouteGroup* route_group() const { return 0; }
163 virtual boost::shared_ptr<ARDOUR::Playlist> playlist() const { return boost::shared_ptr<ARDOUR::Playlist> (); }
165 virtual void set_samples_per_unit (double);
166 virtual void show_selection (TimeSelection&);
167 virtual void hide_selection ();
168 virtual void reshow_selection (TimeSelection&);
169 virtual void show_timestretch (framepos_t start, framepos_t end);
170 virtual void hide_timestretch ();
172 virtual void hide_dependent_views (TimeAxisViewItem&) {}
173 virtual void reveal_dependent_views (TimeAxisViewItem&) {}
175 /* editing operations */
177 virtual void cut_copy_clear (Selection&, Editing::CutCopyOp) {}
178 virtual bool paste (ARDOUR::framepos_t, float /*times*/, Selection&, size_t /*nth*/) { return false; }
180 virtual void set_selected_regionviews (RegionSelection&) {}
181 virtual void set_selected_points (PointSelection&) {}
183 virtual boost::shared_ptr<ARDOUR::Region> find_next_region (framepos_t /*pos*/, ARDOUR::RegionPoint, int32_t /*dir*/) {
184 return boost::shared_ptr<ARDOUR::Region> ();
187 void order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top);
189 virtual void get_selectables (ARDOUR::framepos_t, ARDOUR::framepos_t, double, double, std::list<Selectable*>&);
190 virtual void get_inverted_selectables (Selection&, std::list<Selectable *>& results);
192 void add_ghost (RegionView*);
193 void remove_ghost (RegionView*);
194 void erase_ghost (GhostRegion*);
196 /** called at load time when first GUI idle occurs. put
197 expensive data loading/redisplay code in here. */
198 virtual void first_idle () {}
200 TimeAxisView* get_parent () { return parent; }
201 void set_parent (TimeAxisView& p);
202 bool has_state () const;
204 /* call this on the parent */
206 virtual XMLNode* get_automation_child_xml_node (Evoral::Parameter) { return 0; }
208 virtual LayerDisplay layer_display () const { return Overlaid; }
209 virtual StreamView* view () const { return 0; }
211 typedef std::vector<boost::shared_ptr<TimeAxisView> > Children;
212 Children get_child_list ();
214 SelectionRect* get_selection_rect(uint32_t id);
216 static uint32_t preset_height (Height);
218 protected:
219 /* The Standard LHS Controls */
220 Gtk::HBox controls_hbox;
221 Gtk::Table controls_table;
222 Gtk::Table _controls_padding_table;
223 Gtk::EventBox controls_ebox;
224 Gtk::VBox controls_vbox;
225 Gtk::VBox time_axis_vbox;
226 Gtk::DrawingArea resizer;
227 Gtk::HBox resizer_box;
228 Gtk::HBox name_hbox;
229 Gtk::Frame name_frame;
230 Gtkmm2ext::FocusEntry name_entry;
232 uint32_t height; /* in canvas units */
234 std::string controls_base_unselected_name;
235 std::string controls_base_selected_name;
237 bool name_entry_button_press (GdkEventButton *ev);
238 bool name_entry_button_release (GdkEventButton *ev);
239 bool name_entry_key_release (GdkEventKey *ev);
240 void name_entry_activated ();
241 sigc::connection name_entry_key_timeout;
242 bool name_entry_key_timed_out ();
243 guint32 last_name_entry_key_press_event;
245 /* derived classes can override these */
247 virtual void name_entry_changed ();
248 virtual bool name_entry_focus_in (GdkEventFocus *ev);
249 virtual bool name_entry_focus_out (GdkEventFocus *ev);
251 /** Handle mouse relaese on our LHS control name ebox.
253 *@ param ev the event
255 virtual bool controls_ebox_button_release (GdkEventButton *ev);
256 virtual bool controls_ebox_scroll (GdkEventScroll *ev);
258 /** Display the standard LHS control menu at when.
260 * @param when the popup activation time
262 virtual void popup_display_menu (guint32 when);
264 /** Build the standard LHS control menu.
265 * Subclasses should extend this method to add their own menu options.
267 virtual void build_display_menu ();
269 /** Do whatever needs to be done to dynamically reset the LHS control menu.
271 virtual bool handle_display_menu_map_event (GdkEventAny * /*ev*/) { return false; }
273 /* The standard LHS Track control popup-menus */
275 Gtk::Menu *display_menu;
277 Gtk::Label name_label;
279 TimeAxisView* parent;
281 /** Find the parent with state */
282 TimeAxisView* get_parent_with_state();
284 Children children;
285 bool is_child (TimeAxisView*);
287 void remove_child (boost::shared_ptr<TimeAxisView>);
288 void add_child (boost::shared_ptr<TimeAxisView>);
290 /* selection display */
292 ArdourCanvas::Group *selection_group;
294 std::list<GhostRegion*> ghosts;
296 std::list<SelectionRect*> free_selection_rects;
297 std::list<SelectionRect*> used_selection_rects;
299 virtual void selection_click (GdkEventButton*);
301 bool _hidden;
302 bool _has_state;
303 bool in_destructor;
304 NamePackingBits name_packing;
306 void set_heights (uint32_t h);
307 void color_handler ();
309 void conditionally_add_to_selection ();
311 void build_size_menu ();
312 Gtk::Menu* _size_menu;
314 ArdourCanvas::Group* _canvas_display;
315 double _y_position;
316 PublicEditor& _editor;
318 private:
320 ArdourCanvas::Group* _canvas_background;
321 Gtk::VBox* control_parent;
322 int _order;
323 uint32_t _effective_height;
324 double _resize_drag_start;
325 ArdourCanvas::Group* _ghost_group;
327 void compute_heights ();
328 static uint32_t extra_height;
329 static uint32_t smaller_height;
331 static int const _max_order;
333 }; /* class TimeAxisView */
335 #endif /* __ardour_gtk_time_axis_h__ */