OSC: Changed gainVCA to gainfader as VCA is already used.
[ardour.git] / gtk2_ardour / hit.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 "evoral/Note.hpp"
21
22 #include "canvas/polygon.h"
23 #include "canvas/debug.h"
24
25 #include "hit.h"
26
27 using namespace ARDOUR;
28 using namespace ArdourCanvas;
29
30 Hit::Hit (MidiRegionView& region, Item* parent, double size, const boost::shared_ptr<NoteType> note, bool with_events)
31         : NoteBase (region, with_events, note)
32 {
33         _polygon = new ArdourCanvas::Polygon (parent);
34         CANVAS_DEBUG_NAME (_polygon, "note");
35         set_item (_polygon);
36         set_height (size);
37 }
38
39 Hit::~Hit ()
40 {
41         delete _polygon;
42 }
43
44 void
45 Hit::move_event (double dx, double dy)
46 {
47         Points points = _polygon->get();
48         Points moved;
49         for (Points::iterator p = points.begin(); p != points.end(); ++p) {
50                 moved.push_back ((*p).translate (ArdourCanvas::Duple (dx, dy)));
51         }
52         _polygon->set (moved);
53 }
54
55 void
56 Hit::set_outline_color (uint32_t color)
57 {
58         _polygon->set_outline_color (color);
59 }
60
61 void
62 Hit::set_fill_color (uint32_t color)
63 {
64         _polygon->set_fill_color (color);
65 }
66
67 void
68 Hit::show ()
69 {
70         _polygon->show ();
71 }
72
73 void
74 Hit::hide ()
75 {
76         _polygon->hide ();
77 }
78
79 Points
80 Hit::points(Distance height)
81 {
82         /* draw a diamond */
83
84         Points p;
85
86         const double half_height = height/2.0;
87         p.push_back (Duple (-half_height, 0)); // left, middle
88         p.push_back (Duple (0, -half_height)); // top
89         p.push_back (Duple (+half_height, 0)); // right, middle
90         p.push_back (Duple (0, +half_height)); // bottom
91
92         return p;
93 }
94
95 void
96 Hit::set_height (Distance height)
97 {
98         _polygon->set (points(height));
99 }
100
101 Duple
102 Hit::position ()
103 {
104         return _polygon->position ();
105 }
106
107 void
108 Hit::set_position (Duple position)
109 {
110         _polygon->set_position (position);
111 }
112
113 Coord
114 Hit::x0 () const
115 {
116         /* left vertex */
117         return _polygon->position().x + _polygon->get()[0].x;
118 }
119
120 Coord
121 Hit::x1 () const
122 {
123         /* right vertex */
124         return _polygon->position().x + _polygon->get()[2].x;
125 }
126
127 Coord
128 Hit::y0 () const
129 {
130         /* top vertex */
131         return _polygon->position().y + _polygon->get()[1].y;
132 }
133
134 Coord
135 Hit::y1 () const
136 {
137         /* bottom vertex */
138         return _polygon->position().y + _polygon->get()[3].y;
139 }
140
141 void
142 Hit::set_ignore_events (bool ignore)
143 {
144         _polygon->set_ignore_events (ignore);
145 }