2 Copyright (C) 2018 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include <cairomm/context.h>
21 #include "gtkmm2ext/colors.h"
23 #include "canvas/note.h"
24 #include "canvas/debug.h"
27 using namespace ArdourCanvas;
29 bool Note::_show_velocity_bars = true;
31 Note::Note (Canvas* c)
37 Note::Note (Item* parent)
44 Note::set_velocity (double fract)
46 _velocity = max (0.0, min (1.0, fract));
51 Note::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
53 Rectangle::render (area, context);
55 if (_show_velocity_bars && _velocity > 0.0) {
57 Rect self (item_to_window (Rectangle::get().translate (_position), false));
59 if ((self.y1 - self.y0) < 5) {
60 /* not tall enough to show a velocity bar */
64 /* 2 pixel margin above and below
65 outline_width() margin on left
66 set width based on velocity
69 self.y0 = self.y0 + 2;
70 self.y1 = self.y1 - 2;
71 const double width = (self.x1 - self.x0) - (2 * outline_width());
72 self.x0 = self.x0 + outline_width();
73 self.x1 = self.x0 + (width * _velocity);
75 const Rect draw = self.intersection (area);
81 Gtkmm2ext::set_source_rgba (context, Gtkmm2ext::contrasting_text_color (fill_color()));
82 context->rectangle (draw.x0, draw.y0, draw.width(), draw.height());