From 7e4a3dce01149e4cdbb0d93b7b2033a7c357fb6e Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 11 Jan 2023 11:51:03 -0700 Subject: [PATCH] lollipop pixel pushing --- gtk2_ardour/velocity_ghost_region.cc | 17 +++++++++++------ gtk2_ardour/velocity_ghost_region.h | 2 ++ libs/canvas/canvas/lollipop.h | 15 +++------------ libs/canvas/lollipop.cc | 21 +++++++++++++-------- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/gtk2_ardour/velocity_ghost_region.cc b/gtk2_ardour/velocity_ghost_region.cc index f44dc2df6f..1b0e04402f 100644 --- a/gtk2_ardour/velocity_ghost_region.cc +++ b/gtk2_ardour/velocity_ghost_region.cc @@ -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 (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 (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)); +} diff --git a/gtk2_ardour/velocity_ghost_region.h b/gtk2_ardour/velocity_ghost_region.h index 9d844f7acc..8cb14a069d 100644 --- a/gtk2_ardour/velocity_ghost_region.h +++ b/gtk2_ardour/velocity_ghost_region.h @@ -35,6 +35,8 @@ public: void update_hit (GhostEvent* hit); void remove_note (NoteBase*); + void set_colors (); + private: }; diff --git a/libs/canvas/canvas/lollipop.h b/libs/canvas/canvas/lollipop.h index f3eeac4cee..ccc3116c80 100644 --- a/libs/canvas/canvas/lollipop.h +++ b/libs/canvas/canvas/lollipop.h @@ -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]; diff --git a/libs/canvas/lollipop.cc b/libs/canvas/lollipop.cc index 30e6bece75..3f16f8ebed 100644 --- a/libs/canvas/lollipop.cc +++ b/libs/canvas/lollipop.cc @@ -73,7 +73,8 @@ Lollipop::render (Rect const & /*area*/, Cairo::RefPtr 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;