lollipop pixel pushing

This commit is contained in:
Paul Davis 2023-01-11 11:51:03 -07:00
parent 1a4ef77222
commit 7e4a3dce01
4 changed files with 29 additions and 26 deletions

View File

@ -45,6 +45,8 @@
using namespace Temporal;
static double const lollipop_radius = 8.0;
VelocityGhostRegion::VelocityGhostRegion (MidiRegionView& mrv, TimeAxisView& tv, TimeAxisView& source_tv, double initial_unit_pos)
: MidiGhostRegion (mrv, tv, source_tv, initial_unit_pos)
{
@ -59,7 +61,7 @@ VelocityGhostRegion::update_contents_height ()
{
for (auto const & ev : events) {
ArdourCanvas::Lollipop* l = dynamic_cast<ArdourCanvas::Lollipop*> (ev.second->item);
l->set_length (ev.second->event->note()->velocity() / 127.0 * base_rect->y1 ());
l->set (ArdourCanvas::Duple (l->x(), base_rect->y1()), ev.second->event->note()->velocity() / 127.0 * base_rect->y1 (), lollipop_radius);
}
}
@ -76,11 +78,10 @@ VelocityGhostRegion::add_note (NoteBase* n)
MidiStreamView* mv = midi_view();
if (mv) {
if (!n->item()->visible()) {
event->item->hide();
l->hide();
} else {
l->set (ArdourCanvas::Duple (n->x0(), base_rect->y1()), n->note()->velocity() / 127.0 * base_rect->y1(), 10);
l->set (ArdourCanvas::Duple (n->x0() - 1.0, base_rect->y1()), n->note()->velocity() / 127.0 * base_rect->y1(), lollipop_radius);
}
}
}
@ -89,7 +90,7 @@ void
VelocityGhostRegion::update_note (GhostEvent* n)
{
ArdourCanvas::Lollipop* l = dynamic_cast<ArdourCanvas::Lollipop*> (n->item);
l->set (ArdourCanvas::Duple (n->event->x0(), base_rect->y1()), n->event->note()->velocity() / 127.0 * base_rect->y1(), 10);
l->set (ArdourCanvas::Duple (n->event->x0() - 1.0, base_rect->y1()), n->event->note()->velocity() / 127.0 * base_rect->y1(), lollipop_radius);
}
void
@ -102,4 +103,8 @@ VelocityGhostRegion::remove_note (NoteBase*)
{
}
void
VelocityGhostRegion::set_colors ()
{
base_rect->set_fill_color (Gtkmm2ext::Color (0xff0000ff));
}

View File

@ -35,6 +35,8 @@ public:
void update_hit (GhostEvent* hit);
void remove_note (NoteBase*);
void set_colors ();
private:
};

View File

@ -50,18 +50,9 @@ public:
void set (Duple const &, Coord, Coord);
void set_x (Coord);
Coord x0 () const {
return _points[0].x;
}
Coord y0 () const {
return _points[0].y;
}
Coord x1 () const {
return _points[1].x;
}
Coord y1 () const {
return _points[1].y;
}
Coord x () const { return _points[0].x; }
Coord y0 () const { return _points[0].y; }
Coord y1 () const { return _points[1].y; }
private:
Duple _points[2];

View File

@ -73,7 +73,8 @@ Lollipop::render (Rect const & /*area*/, Cairo::RefPtr<Cairo::Context> context)
}
context->move_to (p0.x, p0.y);
context->line_to (p1.x, p1.y);
/* Do not enter the circle */
context->line_to (p1.x, p1.y + _radius);
context->stroke ();
/* the circle */
@ -125,6 +126,7 @@ Lollipop::set_length (Coord len)
{
if (_points[1].y != _points[0].y - len) {
begin_change ();
/* draw upwards */
_points[1].y = _points[0].y - len;
end_change ();
}
@ -135,14 +137,15 @@ Lollipop::set (Duple const & d, Coord l, Coord r)
{
begin_change ();
_radius = r;
_points[0].x = d.x;
_points[1].x = d.x;
_points[0].y = d.y;
/* Draw upwards */
_points[1].y = _points[0].y - l;
_radius = r;
end_change ();
}
@ -158,12 +161,14 @@ Lollipop::covers (Duple const & point) const
if (_points[0].x == _points[1].x) {
/* line is vertical, just check x coordinate */
return fabs (_points[0].x - p.x) <= threshold;
}
if (_points[0].y == _points[1].y) {
if (fabs (_points[0].x - p.x) <= threshold) {
return true;
}
} else if (_points[0].y == _points[1].y) {
/* line is horizontal, just check y coordinate */
return fabs (_points[0].y - p.y) <= threshold;
if (fabs (_points[0].y - p.y) <= threshold) {
return true;
}
}
Duple at;