Fix DSP load sorting with inactive plugins
[ardour.git] / gtk2_ardour / control_point.cc
1 /*
2  * Copyright (C) 2007-2014 David Robillard <d@drobilla.net>
3  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2009-2016 Paul Davis <paul@linuxaudiosystems.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20
21 #include "control_point.h"
22 #include "automation_line.h"
23 #include "public_editor.h"
24 #include "ui_config.h"
25
26 #include "canvas/rectangle.h"
27
28 #include "pbd/i18n.h"
29
30 using namespace std;
31 using namespace ARDOUR;
32 using namespace PBD;
33
34 PBD::Signal1<void, ControlPoint *> ControlPoint::CatchDeletion;
35
36 ControlPoint::ControlPoint (AutomationLine& al)
37         : _line (al)
38 {
39         _model = al.the_list()->end();
40         _view_index = 0;
41         _can_slide = true;
42         _x = 0;
43         _y = 0;
44         _shape = Full;
45         _size = 4.0;
46
47         _item = new ArdourCanvas::Rectangle (&_line.canvas_group());
48         _item->set_fill (true);
49         _item->set_fill_color (UIConfiguration::instance().color ("control point fill"));
50         _item->set_outline_color (UIConfiguration::instance().color ("control point outline"));
51         _item->set_data ("control_point", this);
52         _item->Event.connect (sigc::mem_fun (this, &ControlPoint::event_handler));
53
54         hide ();
55 }
56
57 ControlPoint::ControlPoint (const ControlPoint& other, bool /*dummy_arg_to_force_special_copy_constructor*/)
58         : _line (other._line)
59 {
60         if (&other == this) {
61                 return;
62         }
63
64         _model = other._model;
65         _view_index = other._view_index;
66         _can_slide = other._can_slide;
67         _x = other._x;
68         _y = other._y;
69         _shape = other._shape;
70         _size = other._size;
71
72         _item = new ArdourCanvas::Rectangle (&_line.canvas_group());
73         _item->set_fill (true);
74         _item->set_outline_color (UIConfiguration::instance().color ("control point outline"));
75
76         /* NOTE: no event handling in copied ControlPoints */
77
78         hide ();
79 }
80
81 ControlPoint::~ControlPoint ()
82 {
83         CatchDeletion (this); /* EMIT SIGNAL */
84
85         delete _item;
86 }
87
88 bool
89 ControlPoint::event_handler (GdkEvent* event)
90 {
91         return PublicEditor::instance().canvas_control_point_event (event, _item, this);
92 }
93
94 void
95 ControlPoint::hide ()
96 {
97         _item->hide();
98 }
99
100 void
101 ControlPoint::show()
102 {
103         _item->show();
104 }
105
106 bool
107 ControlPoint::visible () const
108 {
109         return _item->visible ();
110 }
111
112 void
113 ControlPoint::reset (double x, double y, AutomationList::iterator mi, uint32_t vi, ShapeType shape)
114 {
115         _model = mi;
116         _view_index = vi;
117         move_to (x, y, shape);
118 }
119
120 void
121 ControlPoint::set_color ()
122 {
123         if (_selected) {
124                 _item->set_outline_color(UIConfiguration::instance().color ("control point selected outline"));;
125                 _item->set_fill_color(UIConfiguration::instance().color ("control point selected fill"));
126         } else {
127                 _item->set_outline_color(UIConfiguration::instance().color ("control point outline"));
128                 _item->set_fill_color(UIConfiguration::instance().color ("control point fill"));
129         }
130 }
131
132 void
133 ControlPoint::set_size (double sz)
134 {
135         _size = sz;
136         move_to (_x, _y, _shape);
137 }
138
139 void
140 ControlPoint::move_to (double x, double y, ShapeType shape)
141 {
142         double x1 = 0;
143         double x2 = 0;
144         double half_size = rint(_size/2.0);
145
146         switch (shape) {
147         case Full:
148                 x1 = x - half_size;
149                 x2 = x + half_size;
150                 break;
151         case Start:
152                 x1 = x;
153                 x2 = x + half_size;
154                 break;
155         case End:
156                 x1 = x - half_size;
157                 x2 = x;
158                 break;
159         }
160
161         _item->set (ArdourCanvas::Rect (x1, y - half_size, x2, y + half_size));
162
163         _x = x;
164         _y = y;
165         _shape = shape;
166 }
167
168 ArdourCanvas::Item&
169 ControlPoint::item() const
170 {
171         return *_item;
172 }