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