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"
22 #include "gtkmm2ext/rgb_macros.h"
24 #include "canvas/note.h"
25 #include "canvas/debug.h"
28 using namespace ArdourCanvas;
30 bool Note::_show_velocity_bars = true;
33 Note::set_show_velocity_bars (bool yn)
35 _show_velocity_bars = yn;
38 Note::Note (Canvas* c)
45 Note::Note (Item* parent)
53 Note::set_velocity (double fract)
55 _velocity = max (0.0, min (1.0, fract));
60 Note::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
62 Rectangle::render (area, context);
64 if (_show_velocity_bars && _velocity > 0.0) {
66 Rect self (item_to_window (Rectangle::get().translate (_position), false));
68 if ((self.y1 - self.y0) < ((outline_width() * 2) + 1)) {
69 /* not tall enough to show a velocity bar */
73 /* 2 pixel margin above and below (taking outline width into account).
74 outline_width() margin on left.
75 set width based on velocity.
77 const double center = (self.y1 - self.y0) * 0.5;
78 self.y1 = self.y0 + center + 2;
79 self.y0 = self.y0 + center - 1;
80 const double width = (self.x1 - self.x0) - (2 * outline_width());
81 self.x0 = self.x0 + outline_width()+1;
82 self.x1 = self.x0 + ((width-2) * _velocity);
84 const Rect draw = self.intersection (area);
90 Gtkmm2ext::set_source_rgba (context, _velocity_color);
91 context->rectangle (draw.x0, draw.y0, draw.width(), draw.height());
97 Note::set_fill_color (Gtkmm2ext::Color c)
99 Fill::set_fill_color (c);
100 _velocity_color = UINT_INTERPOLATE (c, 0x000000ff, 0.5);