make all use of bind/mem_fun be explicitly sigc::
[ardour.git] / gtk2_ardour / automation_region_view.cc
1 /*
2     Copyright (C) 2007 Paul Davis
3     Author: Dave Robillard
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include "pbd/memento_command.h"
21 #include "ardour/automation_control.h"
22 #include "ardour/event_type_map.h"
23 #include "ardour/session.h"
24 #include "ardour/source.h"
25 #include "automation_region_view.h"
26 #include "public_editor.h"
27
28 #include "i18n.h"
29
30 AutomationRegionView::AutomationRegionView(ArdourCanvas::Group*                      parent,
31                                            AutomationTimeAxisView&                   time_axis,
32                                            boost::shared_ptr<ARDOUR::Region>         region,
33                                            const Evoral::Parameter&                  param,
34                                            boost::shared_ptr<ARDOUR::AutomationList> list,
35                                            double                                    spu,
36                                            Gdk::Color const &                        basic_color)
37         : RegionView(parent, time_axis, region, spu, basic_color)
38         , _parameter(param)
39 {
40         if (list) {
41                 assert(list->parameter() == param);
42                 create_line(list);
43         }
44
45         group->signal_event().connect (sigc::mem_fun (this, &AutomationRegionView::canvas_event), false);
46         group->raise_to_top();
47 }
48
49 void
50 AutomationRegionView::init (Gdk::Color const & basic_color, bool /*wfd*/)
51 {
52         _enable_display = false;
53
54         RegionView::init(basic_color, false);
55
56         compute_colors (basic_color);
57
58         reset_width_dependent_items ((double) _region->length() / samples_per_unit);
59
60         set_height (trackview.current_height());
61
62         _region->StateChanged.connect (sigc::mem_fun(*this, &AutomationRegionView::region_changed));
63
64         set_colors ();
65
66         _enable_display = true;
67 }
68
69 void
70 AutomationRegionView::create_line (boost::shared_ptr<ARDOUR::AutomationList> list)
71 {
72         _line = boost::shared_ptr<AutomationLine>(new AutomationLine(
73                                 ARDOUR::EventTypeMap::instance().to_symbol(list->parameter()),
74                                 trackview, *get_canvas_group(), list, &_time_converter));
75         _line->set_colors();
76         _line->set_interpolation(list->interpolation());
77         _line->set_height ((uint32_t)rint(trackview.current_height() - NAME_HIGHLIGHT_SIZE));
78         _line->show();
79         _line->show_all_control_points();
80 }
81
82 bool
83 AutomationRegionView::canvas_event(GdkEvent* ev)
84 {
85         if (ev->type == GDK_BUTTON_RELEASE) {
86                 const nframes_t when = trackview.editor().pixel_to_frame((nframes_t)ev->button.x)
87                         - _region->position();
88                 add_automation_event(ev, when, ev->button.y);
89         }
90
91         return false;
92 }
93
94 void
95 AutomationRegionView::add_automation_event (GdkEvent* /*event*/, nframes_t when, double y)
96 {
97         if (!_line) {
98                 boost::shared_ptr<Evoral::Control> c = _region->control(_parameter, true);
99                 boost::shared_ptr<ARDOUR::AutomationControl> ac
100                                 = boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(c);
101                 assert(ac);
102                 create_line(ac->alist());
103         }
104         assert(_line);
105
106         double x = when;
107         AutomationTimeAxisView* const view = automation_view();
108
109         view->canvas_display()->w2i (x, y);
110
111         /* compute vertical fractional position */
112
113         const double h = trackview.current_height() - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 2;
114         y = 1.0 - (y / h);
115
116         /* map using line */
117
118         _line->view_to_model_coord (x, y);
119
120         view->session().begin_reversible_command (_("add automation event"));
121         XMLNode& before = _line->the_list()->get_state();
122
123         _line->the_list()->add (x, y);
124
125         XMLNode& after = _line->the_list()->get_state();
126         view->session().commit_reversible_command (new MementoCommand<ARDOUR::AutomationList>(
127                         *_line->the_list(), &before, &after));
128
129         view->session().set_dirty ();
130 }
131
132 void
133 AutomationRegionView::set_height (double h)
134 {
135         RegionView::set_height(h);
136
137         if (_line)
138                 _line->set_height ((uint32_t)rint(h - NAME_HIGHLIGHT_SIZE));
139 }
140
141 bool
142 AutomationRegionView::set_position (nframes64_t pos, void* src, double* ignored)
143 {
144         return RegionView::set_position(pos, src, ignored);
145 }
146
147
148 void
149 AutomationRegionView::reset_width_dependent_items (double pixel_width)
150 {
151         RegionView::reset_width_dependent_items(pixel_width);
152
153         if (_line)
154                 _line->reset();
155 }
156
157
158 void
159 AutomationRegionView::region_resized (ARDOUR::Change what_changed)
160 {
161         RegionView::region_resized(what_changed);
162
163         if (_line)
164                 _line->reset();
165 }
166
167
168 void
169 AutomationRegionView::entered()
170 {
171         if (_line)
172                 _line->track_entered();
173 }
174
175
176 void
177 AutomationRegionView::exited()
178 {
179         if (_line)
180                 _line->track_exited();
181 }
182