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