diff --git a/gtk2_ardour/ghostregion.cc b/gtk2_ardour/ghostregion.cc index d4c9ab6ff2..5ac5e4aaea 100644 --- a/gtk2_ardour/ghostregion.cc +++ b/gtk2_ardour/ghostregion.cc @@ -62,7 +62,7 @@ GhostRegion::GhostRegion (RegionView& rv, , base_rect (0) { group = new ArdourCanvas::Container (parent); - CANVAS_DEBUG_NAME (group, "ghost region"); + CANVAS_DEBUG_NAME (group, "ghost region group"); group->set_position (ArdourCanvas::Duple (initial_pos, 0)); if (is_automation_ghost()) { @@ -200,6 +200,8 @@ MidiGhostRegion::MidiGhostRegion(MidiRegionView& rv, if (base_rect) { base_rect->lower_to_bottom(); } + + CANVAS_DEBUG_NAME (_note_group, "midi ghost note group"); } MidiGhostRegion::~MidiGhostRegion() diff --git a/gtk2_ardour/velocity_ghost_region.cc b/gtk2_ardour/velocity_ghost_region.cc index 1b0e04402f..568b75f270 100644 --- a/gtk2_ardour/velocity_ghost_region.cc +++ b/gtk2_ardour/velocity_ghost_region.cc @@ -59,18 +59,26 @@ VelocityGhostRegion::~VelocityGhostRegion () void VelocityGhostRegion::update_contents_height () { - for (auto const & ev : events) { - ArdourCanvas::Lollipop* l = dynamic_cast (ev.second->item); - l->set (ArdourCanvas::Duple (l->x(), base_rect->y1()), ev.second->event->note()->velocity() / 127.0 * base_rect->y1 (), lollipop_radius); + for (auto const & i : events) { + set_size_and_position (*i.second); } } +bool +VelocityGhostRegion::lollevent (GdkEvent* ev, MidiGhostRegion::GhostEvent* gev) +{ + return trackview.editor().canvas_velocity_event (ev, gev->item); +} + void VelocityGhostRegion::add_note (NoteBase* n) { ArdourCanvas::Lollipop* l = new ArdourCanvas::Lollipop (_note_group); + GhostEvent* event = new GhostEvent (n, _note_group, l); events.insert (std::make_pair (n->note(), event)); + l->Event.connect (sigc::bind (sigc::mem_fun (*this, &VelocityGhostRegion::lollevent), event)); + l->raise_to_top (); event->item->set_fill_color (UIConfiguration::instance().color_mod(n->base_color(), "ghost track midi fill")); event->item->set_outline_color (_outline); @@ -81,21 +89,30 @@ VelocityGhostRegion::add_note (NoteBase* n) if (!n->item()->visible()) { l->hide(); } else { - l->set (ArdourCanvas::Duple (n->x0() - 1.0, base_rect->y1()), n->note()->velocity() / 127.0 * base_rect->y1(), lollipop_radius); + set_size_and_position (*event); } } } void -VelocityGhostRegion::update_note (GhostEvent* n) +VelocityGhostRegion::set_size_and_position (GhostEvent& ev) { - ArdourCanvas::Lollipop* l = dynamic_cast (n->item); - l->set (ArdourCanvas::Duple (n->event->x0() - 1.0, base_rect->y1()), n->event->note()->velocity() / 127.0 * base_rect->y1(), lollipop_radius); + ArdourCanvas::Lollipop* l = dynamic_cast (ev.item); + const double available_height = base_rect->y1() - (2.0 * lollipop_radius); + const double actual_height = (ev.event->note()->velocity() / 127.0) * available_height; + l->set (ArdourCanvas::Duple (ev.event->x0() - 1.0, base_rect->y1() - actual_height), actual_height, lollipop_radius); } void -VelocityGhostRegion::update_hit (GhostEvent* n) +VelocityGhostRegion::update_note (GhostEvent* ev) { + set_size_and_position (*ev); +} + +void +VelocityGhostRegion::update_hit (GhostEvent* ev) +{ + set_size_and_position (*ev); } void @@ -106,5 +123,5 @@ VelocityGhostRegion::remove_note (NoteBase*) void VelocityGhostRegion::set_colors () { - base_rect->set_fill_color (Gtkmm2ext::Color (0xff0000ff)); + base_rect->set_fill_color (Gtkmm2ext::Color (0xff000085)); } diff --git a/gtk2_ardour/velocity_ghost_region.h b/gtk2_ardour/velocity_ghost_region.h index 8cb14a069d..d1f8ef2a51 100644 --- a/gtk2_ardour/velocity_ghost_region.h +++ b/gtk2_ardour/velocity_ghost_region.h @@ -38,6 +38,8 @@ public: void set_colors (); private: + bool lollevent (GdkEvent*, MidiGhostRegion::GhostEvent*); + void set_size_and_position (MidiGhostRegion::GhostEvent&); }; #endif /* __gtk_ardour_velocity_region_view_h__ */ diff --git a/libs/canvas/canvas/lollipop.h b/libs/canvas/canvas/lollipop.h index ccc3116c80..a56638ae1d 100644 --- a/libs/canvas/canvas/lollipop.h +++ b/libs/canvas/canvas/lollipop.h @@ -44,19 +44,19 @@ public: Coord radius() const { return _radius; } void set_length (Coord); - Coord length() const { return _points[1].y - _points[0].y; } + Coord length() const { return _length; } /* Set origin, length, radius in one pass */ void set (Duple const &, Coord, Coord); void set_x (Coord); - Coord x () const { return _points[0].x; } - Coord y0 () const { return _points[0].y; } - Coord y1 () const { return _points[1].y; } + Coord x () const { return _position.x; } + Coord y0 () const { return _position.y; } + Coord y1 () const { return _position.y + _length; } private: - Duple _points[2]; Coord _radius; + Coord _length; }; } diff --git a/libs/canvas/lollipop.cc b/libs/canvas/lollipop.cc index 3f16f8ebed..32ac9034e9 100644 --- a/libs/canvas/lollipop.cc +++ b/libs/canvas/lollipop.cc @@ -31,27 +31,22 @@ using namespace ArdourCanvas; Lollipop::Lollipop (Canvas* c) : Item (c) + , _radius (8) + , _length (0) { } Lollipop::Lollipop (Item* parent) : Item (parent) + , _radius (8) + , _length (0) { } void Lollipop::compute_bounding_box () const { - Rect bbox; - - bbox.x0 = min (_points[0].x, _points[1].x); - bbox.y0 = min (_points[0].y, _points[1].y); - bbox.x1 = max (_points[0].x, _points[1].x) + _radius; - bbox.y1 = max (_points[0].y, _points[1].y) + _radius; - - bbox = bbox.expand (0.5 + (_outline_width / 2)); - - _bounding_box = bbox; + _bounding_box = Rect (-_radius, -_radius, _radius, _length + _radius).expand (0.5 + (_outline_width / 2)); set_bbox_clean (); } @@ -60,26 +55,25 @@ Lollipop::render (Rect const & /*area*/, Cairo::RefPtr context) { setup_outline_context (context); - Duple p0 = item_to_window (Duple (_points[0].x, _points[0].y)); - Duple p1 = item_to_window (Duple (_points[1].x, _points[1].y)); + Duple p = _parent->item_to_window (Duple (_position.x, _position.y)); if (_outline_width <= 1.0) { /* See Cairo FAQ on single pixel lines to understand why we add 0.5 */ const Duple half_a_pixel (0.5, 0.5); - p0 = p0.translate (half_a_pixel); - p1 = p1.translate (half_a_pixel); + p = p.translate (half_a_pixel); } - context->move_to (p0.x, p0.y); - /* Do not enter the circle */ - context->line_to (p1.x, p1.y + _radius); + /* the line */ + + context->move_to (p.x, p.y + _radius); + context->line_to (p.x, p.y + _length - _radius); context->stroke (); /* the circle */ - context->arc (p1.x, p1.y, _radius, 0.0 * (M_PI/180.0), 360.0 * (M_PI/180.0)); + context->arc (p.x, p.y, _radius, 0.0 * (M_PI/180.0), 360.0 * (M_PI/180.0)); if (fill()) { setup_fill_context (context); @@ -110,12 +104,9 @@ Lollipop::set_radius (Coord r) void Lollipop::set_x (Coord x) { - if (x != _points[0].x) { + if (x != _position.x) { begin_change (); - - _points[0].x = x; - _points[1].x = x; - + _position.x = x; set_bbox_dirty (); end_change (); } @@ -124,10 +115,10 @@ Lollipop::set_x (Coord x) void Lollipop::set_length (Coord len) { - if (_points[1].y != _points[0].y - len) { + if (_length != len) { begin_change (); - /* draw upwards */ - _points[1].y = _points[0].y - len; + _length = len; + set_bbox_dirty (); end_change (); } } @@ -138,63 +129,25 @@ Lollipop::set (Duple const & d, Coord l, Coord r) begin_change (); _radius = r; + _length = l; - _points[0].x = d.x; - _points[1].x = d.x; - - _points[0].y = d.y; - /* Draw upwards */ - _points[1].y = _points[0].y - l; + set_position (d); + set_bbox_dirty (); end_change (); } bool Lollipop::covers (Duple const & point) const { - const Duple p = window_to_item (point); + const Duple p = _parent->window_to_item (point); static const Distance threshold = 2.0; - /* this quick check works for vertical and horizontal lines, which are - * common. - */ + /* only the circle is considered as "covering" */ - if (_points[0].x == _points[1].x) { - /* line is vertical, just check x coordinate */ - 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 */ - if (fabs (_points[0].y - p.y) <= threshold) { - return true; - } - } - - Duple at; - double t; - Duple a (_points[0]); - Duple b (_points[1]); - const Rect visible (window_to_item (_canvas->visible_area())); - - /* - Clamp the line endpoints to the visible area of the canvas. If we do - not do this, we have a line segment extending to COORD_MAX and our - math goes wrong. - */ - - a.x = min (a.x, visible.x1); - a.y = min (a.y, visible.y1); - b.x = min (b.x, visible.x1); - b.y = min (b.y, visible.y1); - - double d = distance_to_segment_squared (p, a, b, t, at); - - if (t < 0.0 || t > 1.0) { - return false; - } - - if (d < threshold) { + if (((fabs (_position.x - p.x)) <= (_radius + threshold)) && + ((fabs (_position.y - p.y)) <= (_radius + threshold))) { + /* inside circle */ return true; }