754a7bbab7aab724ee661137fdf18bc060eaa1b7
[ardour.git] / gtk2_ardour / time_axis_view.h
1 /*
2     Copyright (C) 2003 Paul Davis 
3
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.
8
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.
13
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.
17
18     $Id$
19 */
20
21 #ifndef __ardour_gtk_time_axis_h__
22 #define __ardour_gtk_time_axis_h__
23
24 #include <vector>
25 #include <list>
26
27 #include <gtkmm.h>
28 #include <gtk-canvas.h>
29
30 #include <ardour/types.h>
31 #include <ardour/region.h>
32
33 #include "prompter.h"
34 #include "axis_view.h"
35 #include "enums.h"
36 #include "editing.h"
37
38 namespace ARDOUR {
39         class Session;
40         class Region;
41         class Session;
42         class RouteGroup;
43         class Playlist;
44 }
45
46 class PublicEditor;
47 class AudioRegionSelection;
48 class TimeSelection;
49 class PointSelection;
50 class TimeAxisViewItem;
51 class Selection;
52 class Selectable;
53
54 /**
55  * TimeAxisView defines the abstract base class for time-axis views.
56  *
57  * This class provides the basic LHS controls and display methods. This should be
58  * extended to create functional time-axis based views.
59  *
60  */
61 class TimeAxisView : public virtual AxisView
62 {
63   public:
64         enum TrackHeight { 
65                 /* canvas units. they need to be odd
66                    valued so that there is a precise
67                    middle.
68                 */
69                 Largest = 301,
70                 Large = 201,
71                 Larger = 101,
72                 Normal = 51,
73                 Smaller = 31,
74                 Small = 21
75         };
76
77         TimeAxisView(ARDOUR::Session& sess, PublicEditor& ed, TimeAxisView* parent, Gtk::Widget *canvas);
78         virtual ~TimeAxisView ();
79
80         /* public data: XXX create accessor/mutators for these ?? */
81
82         PublicEditor& editor;
83
84         guint32 height;  /* in canvas units */
85         guint32 effective_height;  /* in canvas units */
86         double  y_position;
87         int     order;
88
89         
90         GtkCanvasItem   *canvas_display;
91         Gtk::VBox       *control_parent;
92
93         /* The Standard LHS Controls */
94         Gtk::Frame    controls_frame;
95         Gtk::HBox     controls_hbox;
96         Gtk::EventBox controls_lhs_pad;
97         Gtk::Table    controls_table;
98         Gtk::EventBox controls_ebox;
99         Gtk::VBox     controls_vbox;
100         Gtk::HBox     name_hbox;
101         Gtk::Frame    name_frame;
102         Gtk::Entry    name_entry;
103
104         /**
105          * Display this TrackView as the nth component of the parent box, at y.
106          *
107          * @param y 
108          * @param nth
109          * @param parent the parent component
110          * @return the height of this TrackView
111          */
112         virtual guint32 show_at (double y, int& nth, Gtk::VBox *parent);
113
114         bool touched (double top, double bot);
115
116         /**
117          * Hides this TrackView
118          */
119         virtual void hide ();
120         bool hidden() const { return _hidden; }
121
122         virtual void set_selected (bool);
123
124         /**
125          * potential handler for entered events
126          */
127
128         virtual void entered () {}
129         virtual void exited () {}
130
131         /**
132          * Sets the height of this TrackView to one of ths TrackHeghts
133          *
134          * @param h the TrackHeight value to set
135          */
136         virtual void set_height (TrackHeight h);
137         void reset_height();
138         /**
139          * Steps through the defined TrackHeights for this TrackView.
140          * Sets bigger to true to step up in size, set to fals eot step smaller.
141          *
142          * @param bigger true if stepping should increase in size, false otherwise
143          */
144         virtual void step_height (bool bigger);
145
146         virtual ARDOUR::RouteGroup* edit_group() const { return 0; }
147         virtual ARDOUR::Playlist* playlist() const { return 0; }
148
149         virtual void set_samples_per_unit (double);
150         virtual void show_selection (TimeSelection&);
151         virtual void hide_selection ();
152         virtual void reshow_selection (TimeSelection&);
153         virtual void show_timestretch (jack_nframes_t start, jack_nframes_t end);
154         virtual void hide_timestretch ();
155
156         virtual void hide_dependent_views (TimeAxisViewItem&) {}
157         virtual void reveal_dependent_views (TimeAxisViewItem&) {}
158
159         /* editing operations */
160         
161         virtual bool cut_copy_clear (Selection&, Editing::CutCopyOp) { return false; }
162         virtual bool paste (jack_nframes_t, float times, Selection&, size_t nth) { return false; }
163         
164         virtual void set_selected_regionviews (AudioRegionSelection&) {}
165         virtual void set_selected_points (PointSelection&) {}
166
167         virtual ARDOUR::Region* find_next_region (jack_nframes_t pos, ARDOUR::RegionPoint, int32_t dir) {
168                 return 0;
169         }
170
171         void order_selection_trims (GtkCanvasItem *item, bool put_start_on_top);
172
173         virtual void get_selectables (jack_nframes_t start, jack_nframes_t end, double top, double bot, list<Selectable*>& results);
174         virtual void get_inverted_selectables (Selection&, list<Selectable *>& results);
175
176         /* state/serialization management */
177
178         void set_parent (TimeAxisView& p);
179         bool has_state () const;
180
181         virtual void set_state (const XMLNode&);
182         virtual XMLNode* get_state_node () { return 0; }
183
184         /* call this on the parent */
185
186         virtual XMLNode* get_child_xml_node (std::string childname) { return 0; }
187
188   protected:
189
190         string controls_base_unselected_name;
191         string controls_base_selected_name;
192
193         /**
194          * Handle mouse press on our LHS control name entry.
195          *
196          * @param ev the event
197          */
198         virtual gint name_entry_button_press (GdkEventButton *ev);
199
200         /**
201          * Handle mouse relaese on our LHS control name entry.
202          * 
203          *@ param ev the event
204          */
205         virtual gint name_entry_button_release (GdkEventButton *ev);
206
207         /**
208          * Handle mouse relaese on our LHS control name ebox.
209          * 
210          *@ param ev the event
211          */
212         virtual gint controls_ebox_button_release (GdkEventButton *ev);
213
214         /**
215          * Displays the standard LHS control menu at when.
216          *
217          * @param when the popup activation time
218          */
219         virtual void popup_display_menu (guint32 when);
220
221         /**
222          * Build the standard LHS control menu.
223          * Subclasses should extend this method to add their own menu options.
224          *
225          */
226         virtual void build_display_menu ();
227
228         /**
229          * Do anything that needs to be done to dynamically reset
230          * the LHS control menu.
231          */
232         virtual gint handle_display_menu_map_event (GdkEventAny *ev) { return FALSE; }
233
234         /**
235          * Build the standard LHS control size menu for the default TrackHeight options.
236          *
237          */
238         virtual void build_size_menu();
239
240         /**
241          * Displays the standard LHS controls size menu for the TrackHeight.
242          *
243          * @parem when the popup activation time
244          */
245         void popup_size_menu(guint32 when);
246
247         /**
248          * Handle the size option of out main menu.
249          * 
250          * @param ev the event
251          */
252         gint size_click(GdkEventButton *ev);
253
254         /* The standard LHS Track control popup-menus */
255
256         Gtk::Menu *display_menu;
257         Gtk::Menu *size_menu;
258
259         Gtk::Label    name_label;
260
261         TimeAxisView* parent;
262
263         /* find the parent with state */
264
265         TimeAxisView* get_parent_with_state();
266
267         std::vector<TimeAxisView*> children;
268         bool is_child (TimeAxisView*);
269
270         void remove_child (TimeAxisView*);
271         void add_child (TimeAxisView*);
272
273         /* selection display */
274
275         GtkCanvasItem      *selection_group;
276
277         list<SelectionRect*> free_selection_rects;
278         list<SelectionRect*> used_selection_rects;
279
280         SelectionRect* get_selection_rect(uint32_t id);
281
282         virtual void selection_click (GdkEventButton*);
283
284         bool _hidden;
285         bool _has_state;
286
287 }; /* class TimeAxisView */
288
289 #endif /* __ardour_gtk_time_axis_h__ */
290