initial implementation of a more specialized canvas item for (sustained) notes
This commit is contained in:
parent
5102d8fae1
commit
ed24e01658
44
libs/canvas/canvas/note.h
Normal file
44
libs/canvas/canvas/note.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
Copyright (C) 2018 Paul Davis
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#ifndef __CANVAS_NOTE_H__
|
||||
#define __CANVAS_NOTE_H__
|
||||
|
||||
#include "canvas/visibility.h"
|
||||
#include "canvas/rectangle.h"
|
||||
|
||||
namespace ArdourCanvas
|
||||
{
|
||||
|
||||
class LIBCANVAS_API Note : public Rectangle
|
||||
{
|
||||
public:
|
||||
Note (Canvas*);
|
||||
Note (Item*);
|
||||
|
||||
void render (Rect const &, Cairo::RefPtr<Cairo::Context>) const;
|
||||
void set_velocity (double fract);
|
||||
|
||||
private:
|
||||
static bool _show_velocity_bars;
|
||||
double _velocity;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* __CANVAS_NOTE_H__ */
|
85
libs/canvas/note.cc
Normal file
85
libs/canvas/note.cc
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
Copyright (C) 2018 Paul Davis
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <cairomm/context.h>
|
||||
|
||||
#include "gtkmm2ext/colors.h"
|
||||
|
||||
#include "canvas/note.h"
|
||||
#include "canvas/debug.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace ArdourCanvas;
|
||||
|
||||
bool Note::_show_velocity_bars = true;
|
||||
|
||||
Note::Note (Canvas* c)
|
||||
: Rectangle (c)
|
||||
, _velocity (0.5)
|
||||
{
|
||||
}
|
||||
|
||||
Note::Note (Item* parent)
|
||||
: Rectangle (parent)
|
||||
, _velocity (0.5)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Note::set_velocity (double fract)
|
||||
{
|
||||
_velocity = max (0.0, min (1.0, fract));
|
||||
redraw ();
|
||||
}
|
||||
|
||||
void
|
||||
Note::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
|
||||
{
|
||||
Rectangle::render (area, context);
|
||||
|
||||
if (_show_velocity_bars && _velocity > 0.0) {
|
||||
|
||||
Rect self (item_to_window (Rectangle::get().translate (_position), false));
|
||||
|
||||
if ((self.y1 - self.y0) < 5) {
|
||||
/* not tall enough to show a velocity bar */
|
||||
return;
|
||||
}
|
||||
|
||||
/* 2 pixel margin above and below
|
||||
outline_width() margin on left
|
||||
set width based on velocity
|
||||
*/
|
||||
|
||||
self.y0 = self.y0 + 2;
|
||||
self.y1 = self.y1 - 2;
|
||||
const double width = (self.x1 - self.x0) - (2 * outline_width());
|
||||
self.x0 = self.x0 + outline_width();
|
||||
self.x1 = self.x0 + (width * _velocity);
|
||||
|
||||
const Rect draw = self.intersection (area);
|
||||
|
||||
if (!draw) {
|
||||
return;
|
||||
}
|
||||
|
||||
Gtkmm2ext::set_source_rgba (context, Gtkmm2ext::contrasting_text_color (fill_color()));
|
||||
context->rectangle (draw.x0, draw.y0, draw.width(), draw.height());
|
||||
context->fill ();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user