ardour
hit.cc
Go to the documentation of this file.
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");
36  set_height (size);
37 }
38 
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
57 {
58  _polygon->set_outline_color (color);
59 }
60 
61 void
63 {
64  _polygon->set_fill_color (color);
65 }
66 
67 void
69 {
70  _polygon->show ();
71 }
72 
73 void
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
103 {
104  return _polygon->position ();
105 }
106 
107 void
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
143 {
144  _polygon->set_ignore_events (ignore);
145 }
ArdourCanvas::Duple position()
Definition: hit.cc:102
void set_fill_color(uint32_t)
Definition: hit.cc:62
ArdourCanvas::Coord x1() const
Definition: hit.cc:121
ArdourCanvas::Coord y1() const
Definition: hit.cc:135
void hide()
Definition: hit.cc:74
Hit(MidiRegionView &region, ArdourCanvas::Item *parent, double size, const boost::shared_ptr< NoteType > note=boost::shared_ptr< NoteType >(), bool with_events=true)
Definition: hit.cc:30
ArdourCanvas::Coord y0() const
Definition: hit.cc:128
void set_position(ArdourCanvas::Duple)
Definition: hit.cc:108
void show()
Definition: hit.cc:68
Definition: amp.h:29
void move_event(double, double)
Definition: hit.cc:45
~Hit()
Definition: hit.cc:39
static ArdourCanvas::Points points(ArdourCanvas::Distance height)
Definition: hit.cc:80
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > position
Definition: region.cc:65
ArdourCanvas::Polygon * _polygon
Definition: hit.h:70
void set_outline_color(uint32_t)
Definition: hit.cc:56
void set_ignore_events(bool)
Definition: hit.cc:142
ArdourCanvas::Coord x0() const
Definition: hit.cc:114
void set_height(ArdourCanvas::Coord)
Definition: hit.cc:96
void set_item(ArdourCanvas::Item *)
Definition: note_base.cc:71
LIBARDOUR_API PBD::PropertyDescriptor< bool > color
Definition: route_group.cc:50