globally change all use of "frame" to refer to audio into "sample".
[ardour.git] / gtk2_ardour / automation_time_axis.h
1 /*
2     Copyright (C) 2000-2007 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_gtk_automation_time_axis_h__
21 #define __ardour_gtk_automation_time_axis_h__
22
23 #include <list>
24 #include <string>
25 #include <utility>
26
27 #include <boost/shared_ptr.hpp>
28
29 #include "ardour/types.h"
30 #include "ardour/automatable.h"
31 #include "ardour/automation_list.h"
32
33 #include "canvas/rectangle.h"
34
35 #include "widgets/ardour_button.h"
36 #include "widgets/ardour_dropdown.h"
37
38 #include "time_axis_view.h"
39 #include "automation_controller.h"
40
41 namespace ARDOUR {
42         class Session;
43         class Stripable;
44         class AutomationControl;
45 }
46
47 class PublicEditor;
48 class TimeSelection;
49 class RegionSelection;
50 class PointSelection;
51 class AutomationLine;
52 class Selection;
53 class Selectable;
54 class AutomationStreamView;
55 class AutomationController;
56 class ItemCounts;
57
58 class AutomationTimeAxisView : public TimeAxisView
59 {
60 public:
61         AutomationTimeAxisView (ARDOUR::Session*,
62                                 boost::shared_ptr<ARDOUR::Stripable>,
63                                 boost::shared_ptr<ARDOUR::Automatable>,
64                                 boost::shared_ptr<ARDOUR::AutomationControl>,
65                                 Evoral::Parameter,
66                                 PublicEditor&,
67                                 TimeAxisView& parent,
68                                 bool show_regions,
69                                 ArdourCanvas::Canvas& canvas,
70                                 const std::string & name, /* translatable */
71                                 const std::string & plug_name = "");
72
73         ~AutomationTimeAxisView();
74
75         virtual void set_height (uint32_t, TrackHeightMode m = OnlySelf);
76         void set_samples_per_pixel (double);
77         std::string name() const { return _name; }
78         Gdk::Color color () const;
79
80         boost::shared_ptr<ARDOUR::Stripable> stripable() const;
81         ARDOUR::PresentationInfo const & presentation_info () const;
82
83         void add_automation_event (GdkEvent *, samplepos_t, double, bool with_guard_points);
84
85         void clear_lines ();
86
87         /** @return Our AutomationLine, if this view has one, or 0 if it uses AutomationRegionViews */
88         boost::shared_ptr<AutomationLine> line() { return _line; }
89
90         /** @return All AutomationLines associated with this view */
91         std::list<boost::shared_ptr<AutomationLine> > lines () const;
92
93         void set_selected_points (PointSelection&);
94         void get_selectables (ARDOUR::samplepos_t start, ARDOUR::samplepos_t end, double top, double bot, std::list<Selectable *>&, bool within = false);
95         void get_inverted_selectables (Selection&, std::list<Selectable*>& results);
96
97         void show_timestretch (samplepos_t /*start*/, samplepos_t /*end*/, int /*layers*/, int /*layer*/) {}
98         void hide_timestretch () {}
99
100         /* editing operations */
101
102         void cut_copy_clear (Selection&, Editing::CutCopyOp);
103         bool paste (ARDOUR::samplepos_t, const Selection&, PasteContext&, const int32_t sub_num);
104
105         int  set_state (const XMLNode&, int version);
106
107         std::string state_id() const;
108         static bool parse_state_id (std::string const &, PBD::ID &, bool &, Evoral::Parameter &);
109
110         boost::shared_ptr<ARDOUR::AutomationControl> control() const   { return _control; }
111         boost::shared_ptr<AutomationController>      controller() const { return _controller; }
112         Evoral::Parameter parameter () const {
113                 return _parameter;
114         }
115
116         ArdourCanvas::Item* base_item () const {
117                 return _base_rect;
118         }
119
120         bool has_automation () const;
121
122         boost::shared_ptr<ARDOUR::Stripable> parent_stripable () {
123                 return _stripable;
124         }
125
126         bool show_regions () const {
127                 return _show_regions;
128         }
129
130         static void what_has_visible_automation (const boost::shared_ptr<ARDOUR::Automatable>& automatable, std::set<Evoral::Parameter>& visible);
131
132 protected:
133         /* Note that for MIDI controller "automation" (in regions), all of these
134          * may be set.  In this case, _automatable is likely _route so the
135          * controller will send immediate events out the route's MIDI port. */
136
137         /** parent strip */
138         boost::shared_ptr<ARDOUR::Stripable> _stripable;
139         /** control */
140         boost::shared_ptr<ARDOUR::AutomationControl> _control;
141         /** control owner; may be _stripable, something else (e.g. a pan control), or NULL */
142         boost::shared_ptr<ARDOUR::Automatable> _automatable;
143         /** controller owner */
144         boost::shared_ptr<AutomationController> _controller;
145         Evoral::Parameter _parameter;
146
147         ArdourCanvas::Rectangle* _base_rect;
148         boost::shared_ptr<AutomationLine> _line;
149
150         std::string _name;
151
152         /** AutomationStreamView if we are editing region-based automation (for MIDI), otherwise 0 */
153         AutomationStreamView* _view;
154
155         bool    ignore_toggle;
156         bool    first_call_to_set_height;
157
158         ArdourWidgets::ArdourButton   hide_button;
159         ArdourWidgets::ArdourDropdown auto_dropdown;
160         Gtk::Label*        plugname;
161         bool               plugname_packed;
162
163         Gtk::CheckMenuItem*     auto_off_item;
164         Gtk::CheckMenuItem*     auto_play_item;
165         Gtk::CheckMenuItem*     auto_touch_item;
166         Gtk::CheckMenuItem*     auto_write_item;
167         Gtk::CheckMenuItem*     auto_latch_item;
168
169         Gtk::CheckMenuItem* mode_discrete_item;
170         Gtk::CheckMenuItem* mode_line_item;
171         Gtk::CheckMenuItem* mode_log_item;
172         Gtk::CheckMenuItem* mode_exp_item;
173
174         bool _show_regions;
175
176         void add_line (boost::shared_ptr<AutomationLine>);
177
178         void clear_clicked ();
179         void hide_clicked ();
180
181         virtual bool can_edit_name() const {return false;}
182
183         void build_display_menu ();
184
185         void cut_copy_clear_one (AutomationLine&, Selection&, Editing::CutCopyOp);
186         bool paste_one (ARDOUR::samplepos_t, unsigned, float times, const Selection&, ItemCounts& counts, bool greedy=false);
187         void route_going_away ();
188
189         void set_automation_state (ARDOUR::AutoState);
190         bool ignore_state_request;
191         bool ignore_mode_request;
192
193         bool propagate_time_selection () const;
194
195         void automation_state_changed ();
196
197         void set_interpolation (ARDOUR::AutomationList::InterpolationStyle);
198         void interpolation_changed (ARDOUR::AutomationList::InterpolationStyle);
199
200         PBD::ScopedConnectionList _list_connections;
201         PBD::ScopedConnectionList _stripable_connections;
202
203         void entered ();
204         void exited ();
205
206         //void set_colors ();
207         void color_handler ();
208
209         static Pango::FontDescription name_font;
210         static bool have_name_font;
211
212         std::string automation_state_off_string () const;
213
214 private:
215         int set_state_2X (const XMLNode &, int);
216 };
217
218 #endif /* __ardour_gtk_automation_time_axis_h__ */