First cut of some Pro-tools inspired editing features; linked play/play range
[ardour.git] / gtk2_ardour / control_point.cc
1 /*
2     Copyright (C) 2002-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 #include "control_point.h"
21 #include "diamond.h"
22 #include "automation_line.h"
23 #include "ardour_ui.h"
24 #include "public_editor.h"
25
26 #include "i18n.h"
27
28 using namespace std;
29 using namespace ARDOUR;
30 using namespace PBD;
31 using namespace Gnome; // for Canvas
32
33 ControlPoint::ControlPoint (AutomationLine& al)
34         : _line (al)
35 {
36         _model = al.the_list()->end();
37         _view_index = 0;
38         _can_slide = true;
39         _x = 0;
40         _y = 0;
41         _shape = Full;
42         _size = 4.0;
43         _selected = false;
44
45         _item = new Canvas::SimpleRect (_line.canvas_group());
46         _item->property_draw() = true;
47         _item->property_fill() = false;
48         _item->property_fill_color_rgba() =  ARDOUR_UI::config()->canvasvar_ControlPointFill.get();
49         _item->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_ControlPointOutline.get();
50         _item->property_outline_pixels() = 1;
51         _item->set_data ("control_point", this);
52         _item->signal_event().connect (sigc::mem_fun (this, &ControlPoint::event_handler));
53
54         hide ();
55         set_visible (false);
56 }
57
58 ControlPoint::ControlPoint (const ControlPoint& other, bool /*dummy_arg_to_force_special_copy_constructor*/)
59         : _line (other._line)
60 {
61         if (&other == this) {
62                 return;
63         }
64
65         _model = other._model;
66         _view_index = other._view_index;
67         _can_slide = other._can_slide;
68         _x = other._x;
69         _y = other._y;
70         _shape = other._shape;
71         _size = other._size;
72         _selected = false;
73
74         _item = new Canvas::SimpleRect (_line.canvas_group());
75         _item->property_fill() = false;
76         _item->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_ControlPointOutline.get();
77         _item->property_outline_pixels() = 1;
78
79         /* NOTE: no event handling in copied ControlPoints */
80
81         hide ();
82         set_visible (false);
83 }
84
85 ControlPoint::~ControlPoint ()
86 {
87         delete _item;
88 }
89
90 bool
91 ControlPoint::event_handler (GdkEvent* event)
92 {
93         return PublicEditor::instance().canvas_control_point_event (event, _item, this);
94 }
95
96 void
97 ControlPoint::hide ()
98 {
99         _item->hide();
100 }
101
102 void
103 ControlPoint::show()
104 {
105         _item->show();
106 }
107
108 void
109 ControlPoint::set_visible (bool yn)
110 {
111         _item->property_draw() = (gboolean) yn;
112 }
113
114 void
115 ControlPoint::reset (double x, double y, AutomationList::iterator mi, uint32_t vi, ShapeType shape)
116 {
117         _model = mi;
118         _view_index = vi;
119         move_to (x, y, shape);
120 }
121
122 void
123 ControlPoint::show_color (bool entered, bool hide_too)
124 {
125         uint32_t color = 0;
126
127         if (entered) {
128                 if (_selected) {
129                         color = ARDOUR_UI::config()->canvasvar_EnteredControlPointSelected.get();
130                         set_visible(true);
131                 } else {
132                         color = ARDOUR_UI::config()->canvasvar_EnteredControlPointOutline.get();
133                         if (hide_too) {
134                                 set_visible(false);
135                         }
136                 }
137
138         } else {
139                 if (_selected) {
140                         color = ARDOUR_UI::config()->canvasvar_ControlPointSelected.get();
141                         set_visible(true);
142                 } else {
143                         color = ARDOUR_UI::config()->canvasvar_ControlPointOutline.get();
144                         if (hide_too) {
145                                 set_visible(false);
146                         }
147                 }
148         }
149
150         _item->property_outline_color_rgba() = color;
151         _item->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_ControlPointFill.get();
152 }
153
154 void
155 ControlPoint::set_size (double sz)
156 {
157         _size = sz;
158         move_to (_x, _y, _shape);
159 }
160
161 void
162 ControlPoint::move_to (double x, double y, ShapeType shape)
163 {
164         double x1 = 0;
165         double x2 = 0;
166         double half_size = rint(_size/2.0);
167
168         switch (shape) {
169         case Full:
170                 x1 = x - half_size;
171                 x2 = x + half_size;
172                 break;
173         case Start:
174                 x1 = x;
175                 x2 = x + half_size;
176                 break;
177         case End:
178                 x1 = x - half_size;
179                 x2 = x;
180                 break;
181         }
182
183         _item->property_x1() = x1;
184         _item->property_x2() = x2;
185         _item->property_y1() = y - half_size;
186         _item->property_y2() = y + half_size;
187
188         _x = x;
189         _y = y;
190         _shape = shape;
191 }
192