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