merge from 2.0-ongoing @ 3581
[ardour.git] / gtk2_ardour / route_time_axis.h
1 /*
2     Copyright (C) 2006 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 */
19
20 #ifndef __ardour_route_time_axis_h__
21 #define __ardour_route_time_axis_h__
22
23 #include <gtkmm/table.h>
24 #include <gtkmm/button.h>
25 #include <gtkmm/box.h>
26 #include <gtkmm/menu.h>
27 #include <gtkmm/menuitem.h>
28 #include <gtkmm/radiomenuitem.h>
29 #include <gtkmm/checkmenuitem.h>
30 #include <gtkmm/adjustment.h>
31
32 #include <gtkmm2ext/selector.h>
33 #include <gtkmm2ext/slider_controller.h>
34 #include <list>
35
36 #include <ardour/types.h>
37
38 #include "ardour_dialog.h"
39 #include "route_ui.h"
40 #include "enums.h"
41 #include "time_axis_view.h"
42 #include "canvas.h"
43 #include "gain_meter.h"
44
45
46 namespace ARDOUR {
47         class Session;
48         class Region;
49         class Diskstream;
50         class RouteGroup;
51         class IOProcessor;
52         class Processor;
53         class Location;
54         class Playlist;
55 }
56
57 class PublicEditor;
58 class RegionView;
59 class StreamView;
60 class Selection;
61 class RegionSelection;
62 class Selectable;
63 class AutomationTimeAxisView;
64 class AutomationLine;
65 class ProcessorAutomationLine;
66 class TimeSelection;
67
68 class RouteTimeAxisView : public RouteUI, public TimeAxisView
69 {
70 public:
71         RouteTimeAxisView (PublicEditor&, ARDOUR::Session&, boost::shared_ptr<ARDOUR::Route>, ArdourCanvas::Canvas& canvas);
72         virtual ~RouteTimeAxisView ();
73
74         void show_selection (TimeSelection&);
75
76         void set_samples_per_unit (double);
77         void set_height (uint32_t h);
78         void show_timestretch (nframes_t start, nframes_t end);
79         void hide_timestretch ();
80         void selection_click (GdkEventButton*);
81         void set_selected_points (PointSelection&);
82         void set_selected_regionviews (RegionSelection&);
83         void get_selectables (nframes_t start, nframes_t end, double top, double bot, list<Selectable *>&);
84         void get_inverted_selectables (Selection&, list<Selectable*>&);
85         bool show_automation(ARDOUR::Parameter param);
86         void set_layer_display (LayerDisplay d);
87                 
88         boost::shared_ptr<ARDOUR::Region> find_next_region (nframes_t pos, ARDOUR::RegionPoint, int32_t dir);
89         nframes64_t find_next_region_boundary (nframes64_t pos, int32_t dir);
90
91         /* Editing operations */
92         bool cut_copy_clear (Selection&, Editing::CutCopyOp);
93         bool paste (nframes_t, float times, Selection&, size_t nth);
94
95         TimeAxisView::Children get_child_list();
96
97         /* The editor calls these when mapping an operation across multiple tracks */
98         void use_new_playlist (bool prompt);
99         void use_copy_playlist (bool prompt);
100         void clear_playlist ();
101         
102         void build_playlist_menu (Gtk::Menu *);
103
104         void add_underlay (StreamView*, bool update_xml = true);
105         void remove_underlay (StreamView*);
106         void build_underlay_menu(Gtk::Menu*);
107         
108         /* This is a bit nasty to expose :/ */
109         struct RouteAutomationNode {
110                 ARDOUR::Parameter                         param;
111             Gtk::CheckMenuItem*                       menu_item;
112                 boost::shared_ptr<AutomationTimeAxisView> track;
113             
114                 RouteAutomationNode (ARDOUR::Parameter par, Gtk::CheckMenuItem* mi, boost::shared_ptr<AutomationTimeAxisView> tr)
115                     : param (par), menu_item (mi), track (tr) {}
116         };
117
118         virtual void create_automation_child (ARDOUR::Parameter param, bool show) = 0;
119         
120         /* make sure we get the right version of this */
121
122         XMLNode* get_automation_child_xml_node (ARDOUR::Parameter param) { return RouteUI::get_automation_child_xml_node (param); }
123         
124         typedef map<ARDOUR::Parameter, RouteAutomationNode*> AutomationTracks;
125         AutomationTracks automation_tracks() { return _automation_tracks; }
126
127         boost::shared_ptr<AutomationTimeAxisView> automation_child(ARDOUR::Parameter param);
128         
129         string              name() const;
130         StreamView*         view() const { return _view; }
131         ARDOUR::RouteGroup* edit_group() const;
132         boost::shared_ptr<ARDOUR::Playlist> playlist() const;
133
134         void fast_update ();
135         void hide_meter ();
136         void show_meter ();
137         void reset_meter ();
138         void clear_meter ();
139         void io_changed (ARDOUR::IOChange, void *);
140         void meter_changed (void *);
141         void effective_gain_display () { gm.effective_gain_display(); }
142
143         static void setup_slider_pix ();
144
145 protected:
146         friend class StreamView;
147
148         struct ProcessorAutomationNode {
149                 ARDOUR::Parameter                         what;
150             Gtk::CheckMenuItem*                       menu_item;
151                 boost::shared_ptr<AutomationTimeAxisView> view;
152             RouteTimeAxisView&                        parent;
153
154             ProcessorAutomationNode (ARDOUR::Parameter w, Gtk::CheckMenuItem* mitem, RouteTimeAxisView& p)
155                     : what (w), menu_item (mitem), parent (p) {}
156
157             ~ProcessorAutomationNode ();
158         };
159
160         struct ProcessorAutomationInfo {
161             boost::shared_ptr<ARDOUR::Processor> processor;
162             bool                                 valid;
163             Gtk::Menu*                           menu;
164             vector<ProcessorAutomationNode*>     lines;
165
166             ProcessorAutomationInfo (boost::shared_ptr<ARDOUR::Processor> i) 
167                     : processor (i), valid (true), menu (0) {}
168
169             ~ProcessorAutomationInfo ();
170         };
171         
172
173         void diskstream_changed ();
174         void update_diskstream_display ();
175         
176         gint edit_click  (GdkEventButton *);
177
178         void processors_changed ();
179         
180         void add_processor_to_subplugin_menu (boost::shared_ptr<ARDOUR::Processor>);
181         void remove_processor_automation_node (ProcessorAutomationNode* pan);
182
183         void processor_menu_item_toggled (RouteTimeAxisView::ProcessorAutomationInfo*,
184                                          RouteTimeAxisView::ProcessorAutomationNode*);
185         
186         void processor_automation_track_hidden (ProcessorAutomationNode*,
187                                                boost::shared_ptr<ARDOUR::Processor>);
188         
189         void automation_track_hidden (ARDOUR::Parameter param);
190
191         RouteAutomationNode* automation_track(ARDOUR::Parameter param);
192         RouteAutomationNode* automation_track(ARDOUR::AutomationType type);
193
194         ProcessorAutomationNode*
195         find_processor_automation_node (boost::shared_ptr<ARDOUR::Processor> i, ARDOUR::Parameter);
196         
197         boost::shared_ptr<AutomationLine>
198         find_processor_automation_curve (boost::shared_ptr<ARDOUR::Processor> i, ARDOUR::Parameter);
199
200         void add_processor_automation_curve (boost::shared_ptr<ARDOUR::Processor> r, ARDOUR::Parameter);
201         void add_existing_processor_automation_curves (boost::shared_ptr<ARDOUR::Processor>);
202
203         void add_automation_child(ARDOUR::Parameter param, boost::shared_ptr<AutomationTimeAxisView> track, bool show=true);
204         
205         void reset_processor_automation_curves ();
206
207         void take_name_changed (void *src);
208         void route_name_changed ();
209         void name_entry_changed ();
210
211         void update_rec_display ();
212
213         virtual void label_view ();
214         
215         void add_edit_group_menu_item (ARDOUR::RouteGroup *, Gtk::RadioMenuItem::Group*);
216         void set_edit_group_from_menu (ARDOUR::RouteGroup *);
217
218         void reset_samples_per_unit ();
219
220         void select_track_color();
221         
222         virtual void build_automation_action_menu ();
223         virtual void append_extra_display_menu_items () {}
224         void         build_display_menu ();
225         
226         void align_style_changed ();
227         void set_align_style (ARDOUR::AlignStyle);
228         
229         virtual void set_playlist (boost::shared_ptr<ARDOUR::Playlist>);
230         void         playlist_click ();
231         void         show_playlist_selector ();
232         void         playlist_changed ();
233         void         playlist_modified ();
234
235         void rename_current_playlist ();
236         
237         void         automation_click ();
238         void         toggle_automation_track (ARDOUR::Parameter param);
239         virtual void show_all_automation ();
240         virtual void show_existing_automation ();
241         virtual void hide_all_automation ();
242
243         void timestretch (nframes_t start, nframes_t end);
244
245         void visual_click ();
246         void hide_click ();
247
248         void speed_changed ();
249         
250         void map_frozen ();
251
252         void color_handler ();
253
254         void region_view_added (RegionView*);
255
256         StreamView*           _view;
257         ArdourCanvas::Canvas& parent_canvas;
258         bool                  no_redraw;
259   
260         Gtk::HBox   other_button_hbox;
261         Gtk::Table  button_table;
262         Gtk::Button processor_button;
263         Gtk::Button edit_group_button;
264         Gtk::Button playlist_button;
265         Gtk::Button size_button;
266         Gtk::Button automation_button;
267         Gtk::Button hide_button;
268         Gtk::Button visual_button;
269         
270         Gtk::Menu           subplugin_menu;
271         Gtk::Menu*          automation_action_menu;
272         Gtk::Menu           edit_group_menu;
273         Gtk::RadioMenuItem* align_existing_item;
274         Gtk::RadioMenuItem* align_capture_item;
275         Gtk::RadioMenuItem* normal_track_mode_item;
276         Gtk::RadioMenuItem* destructive_track_mode_item;
277         Gtk::Menu*          playlist_menu;
278         Gtk::Menu*          playlist_action_menu;
279         Gtk::MenuItem*      playlist_item;
280         Gtk::Menu*          mode_menu;
281
282         virtual Gtk::Menu* build_mode_menu() { return NULL; }
283
284         void use_playlist (boost::weak_ptr<ARDOUR::Playlist>);
285
286         ArdourCanvas::SimpleRect* timestretch_rect;
287
288         void set_track_mode (ARDOUR::TrackMode);
289         void _set_track_mode (ARDOUR::Track* track, ARDOUR::TrackMode mode, Gtk::RadioMenuItem* reset_item);
290         void track_mode_changed ();
291
292         list<ProcessorAutomationInfo*> processor_automation;
293
294         typedef vector<boost::shared_ptr<AutomationLine> > ProcessorAutomationCurves;
295         ProcessorAutomationCurves processor_automation_curves;
296         
297         // Set from XML so context menu automation buttons can be correctly initialized
298         set<ARDOUR::Parameter> _show_automation;
299
300         AutomationTracks _automation_tracks;
301
302         sigc::connection modified_connection;
303
304         void post_construct ();
305         
306         GainMeterBase gm;
307
308         static Glib::RefPtr<Gdk::Pixbuf> slider;
309
310         XMLNode* underlay_xml_node;
311         bool set_underlay_state();
312
313         typedef list<StreamView*> UnderlayList;
314         UnderlayList _underlay_streams;
315         typedef list<RouteTimeAxisView*> UnderlayMirrorList;
316         UnderlayMirrorList _underlay_mirrors;
317 };
318
319 #endif /* __ardour_route_time_axis_h__ */
320