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