merge with master and fix 4 conflicts by hand
[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 "midi_region_view.h"
26 #include "public_editor.h"
27 #include "utils.h"
28 #include "hit.h"
29
30 using namespace ARDOUR;
31 using namespace ArdourCanvas;
32
33 Hit::Hit (MidiRegionView& region, Group* group, double size, const boost::shared_ptr<NoteType> note, bool with_events) 
34         : NoteBase (region, with_events, note)
35 {
36         _polygon = new ArdourCanvas::Polygon (group);
37         CANVAS_DEBUG_NAME (_polygon, "note");
38         set_item (_polygon);
39         set_height (size);
40 }
41
42 Hit::~Hit ()
43 {
44         delete _polygon;
45 }
46
47 void
48 Hit::move_event (double dx, double dy)
49 {
50         Points points = _polygon->get();
51         Points moved;
52         for (Points::iterator p = points.begin(); p != points.end(); ++p) {
53                 moved.push_back ((*p).translate (ArdourCanvas::Duple (dx, dy)));
54         }
55         _polygon->set (moved);
56 }
57
58 void
59 Hit::set_outline_color (uint32_t color)
60 {
61         _polygon->set_outline_color (color);
62 }
63
64 void
65 Hit::set_fill_color (uint32_t color)
66 {
67         _polygon->set_fill_color (color);
68 }
69
70 void
71 Hit::show ()
72 {
73         _polygon->show ();
74 }
75
76 void
77 Hit::hide ()
78 {
79         _polygon->hide ();
80 }
81
82 void
83 Hit::set_height (Distance height)
84 {
85         /* draw a diamond */
86
87         Points p;
88
89         const double half_height = height/2.0;
90         p.push_back (Duple (-half_height, 0)); // left, middle
91         p.push_back (Duple (0, -half_height)); // top
92         p.push_back (Duple (+half_height, 0)); // right, middle
93         p.push_back (Duple (0, +half_height)); // bottom
94
95         _polygon->set (p);
96 }
97
98 void
99 Hit::set_position (Duple position)
100 {
101         _polygon->set_position (position);
102 }
103
104 Coord
105 Hit::x0 () const
106 {
107         /* left vertex */
108         return _polygon->get()[0].x;
109 }
110
111 Coord
112 Hit::x1 () const
113 {
114         /* right vertex */
115         return _polygon->get()[2].x;
116 }
117
118 Coord
119 Hit::y0 () const
120 {
121         /* top vertex */
122         return _polygon->get()[1].y;
123 }
124
125 Coord
126 Hit::y1 () const
127 {
128         /* bottom vertex */
129         return _polygon->get()[3].y;
130 }