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