diff --git a/gtk2_ardour/ghostregion.cc b/gtk2_ardour/ghostregion.cc index e0cbefaf9c..d4c9ab6ff2 100644 --- a/gtk2_ardour/ghostregion.cc +++ b/gtk2_ardour/ghostregion.cc @@ -208,10 +208,16 @@ MidiGhostRegion::~MidiGhostRegion() delete _note_group; } +MidiGhostRegion::GhostEvent::GhostEvent (NoteBase* e, ArdourCanvas::Container* g, ArdourCanvas::Item* i) + : event (e) + , item (i) + , is_hit (false) +{ +} + MidiGhostRegion::GhostEvent::GhostEvent (NoteBase* e, ArdourCanvas::Container* g) : event (e) { - if (dynamic_cast(e)) { item = new ArdourCanvas::Rectangle( g, ArdourCanvas::Rect(e->x0(), e->y0(), e->x1(), e->y1())); diff --git a/gtk2_ardour/ghostregion.h b/gtk2_ardour/ghostregion.h index 4046e37ab1..f5898ddbdc 100644 --- a/gtk2_ardour/ghostregion.h +++ b/gtk2_ardour/ghostregion.h @@ -99,7 +99,8 @@ public: class GhostEvent : public sigc::trackable { public: - GhostEvent(::NoteBase *, ArdourCanvas::Container *); + GhostEvent (::NoteBase *, ArdourCanvas::Container *); + GhostEvent (::NoteBase *, ArdourCanvas::Container *, ArdourCanvas::Item* i); virtual ~GhostEvent (); NoteBase* event; @@ -119,7 +120,7 @@ public: void set_samples_per_pixel (double spu); void set_colors(); - void update_contents_height(); + virtual void update_contents_height(); virtual void add_note(NoteBase*); virtual void update_note (GhostEvent* note); @@ -130,7 +131,7 @@ public: void view_changed(); void clear_events(); -private: + protected: ArdourCanvas::Container* _note_group; Gtkmm2ext::Color _outline; ArdourCanvas::Rectangle* _tmp_rect; diff --git a/gtk2_ardour/lollipop.cc b/gtk2_ardour/lollipop.cc new file mode 100644 index 0000000000..76c1b1a91b --- /dev/null +++ b/gtk2_ardour/lollipop.cc @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2023 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "evoral/Note.h" + +#include "canvas/lollipop.h" +#include "canvas/debug.h" + +#include "lollipop.h" +#include "public_editor.h" + +using namespace ARDOUR; +using ArdourCanvas::Coord; +using ArdourCanvas::Duple; + +Lollipop::Lollipop ( + MidiRegionView& region, ArdourCanvas::Item* parent, const boost::shared_ptr note, bool with_events) + : NoteBase (region, with_events, note) + , _lollipop (new ArdourCanvas::Lollipop (parent)) +{ + CANVAS_DEBUG_NAME (_lollipop, "note"); + set_item (_lollipop); +} + +Lollipop::~Lollipop () +{ + delete _lollipop; +} + +void +Lollipop::move_event (double dx, double dy) +{ + _lollipop->set (Duple (_lollipop->x0(), _lollipop->y0()).translate (Duple (dx, dy)), _lollipop->length(), _lollipop->radius()); +} + +void +Lollipop::set_outline_color (uint32_t color) +{ + _lollipop->set_outline_color (color); +} + +void +Lollipop::set_fill_color (uint32_t color) +{ + _lollipop->set_fill_color (color); +} + +void +Lollipop::show () +{ + _lollipop->show (); +} + +void +Lollipop::hide () +{ + _lollipop->hide (); +} + +void +Lollipop::set (ArdourCanvas::Duple const & d, ArdourCanvas::Coord len, ArdourCanvas::Coord radius) +{ + _lollipop->set (d, len, radius); +} + +void +Lollipop::set_x (Coord x) +{ + _lollipop->set_x (x); +} + +void +Lollipop::set_len (Coord l) +{ + _lollipop->set_length (l); +} + +void +Lollipop::set_outline_what (ArdourCanvas::Rectangle::What what) +{ + // _lollipop->set_outline_what (what); +} + +void +Lollipop::set_outline_all () +{ + // _lollipop->set_outline_all (); +} + +void +Lollipop::set_ignore_events (bool ignore) +{ + _lollipop->set_ignore_events (ignore); +} diff --git a/gtk2_ardour/lollipop.h b/gtk2_ardour/lollipop.h new file mode 100644 index 0000000000..cace4ddf57 --- /dev/null +++ b/gtk2_ardour/lollipop.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2023 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __gtk_ardour_lollipop_h__ +#define __gtk_ardour_lollipop_h__ + +#include + +#include "canvas/rectangle.h" + +#include "note_base.h" +#include "midi_util.h" + +namespace ArdourCanvas { + class Container; + class Lollipop; +} + +class Lollipop : public NoteBase +{ +public: + typedef Evoral::Note NoteType; + + Lollipop (MidiRegionView& region, + ArdourCanvas::Item* parent, + const boost::shared_ptr note = boost::shared_ptr(), + bool with_events = true); + + ~Lollipop (); + + void set (ArdourCanvas::Duple const &, ArdourCanvas::Coord, ArdourCanvas::Coord); + void set_x (ArdourCanvas::Coord); + void set_len (ArdourCanvas::Coord); + + void set_outline_what (ArdourCanvas::Rectangle::What); + void set_outline_all (); + + void set_outline_color (uint32_t); + void set_fill_color (uint32_t); + + void show (); + void hide (); + + void set_ignore_events (bool); + + void move_event (double dx, double dy); + +private: + ArdourCanvas::Lollipop* _lollipop; +}; + +#endif /* __gtk_ardour_lollipop_h__ */ diff --git a/gtk2_ardour/velocity_ghost_region.cc b/gtk2_ardour/velocity_ghost_region.cc index 4f53bfd4a6..e50ef9f88f 100644 --- a/gtk2_ardour/velocity_ghost_region.cc +++ b/gtk2_ardour/velocity_ghost_region.cc @@ -29,12 +29,15 @@ #include "gtkmm2ext/keyboard.h" +#include "canvas/lollipop.h" + #include "velocity_ghost_region.h" #include "editing.h" #include "editor.h" #include "editor_drag.h" #include "gui_thread.h" #include "midi_automation_line.h" +#include "note_base.h" #include "public_editor.h" #include "ui_config.h" @@ -52,8 +55,34 @@ VelocityGhostRegion::~VelocityGhostRegion () } void -VelocityGhostRegion::add_note(NoteBase*) +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 ()); + } +} + +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)); + + event->item->set_fill_color (UIConfiguration::instance().color_mod(n->base_color(), "ghost track midi fill")); + event->item->set_outline_color (_outline); + + MidiStreamView* mv = midi_view(); + + if (mv) { + + if (!n->item()->visible()) { + event->item->hide(); + } else { + l->set (ArdourCanvas::Duple (n->x0(), n->y0()), n->note()->velocity() / 127.0 * base_rect->y1(), 10); + } + } } void diff --git a/gtk2_ardour/velocity_ghost_region.h b/gtk2_ardour/velocity_ghost_region.h index 442a9cc827..9d844f7acc 100644 --- a/gtk2_ardour/velocity_ghost_region.h +++ b/gtk2_ardour/velocity_ghost_region.h @@ -29,6 +29,7 @@ public: VelocityGhostRegion (MidiRegionView&, TimeAxisView& tv, TimeAxisView& source_tv, double initial_unit_pos); ~VelocityGhostRegion (); + void update_contents_height(); void add_note(NoteBase*); void update_note (GhostEvent* note); void update_hit (GhostEvent* hit); diff --git a/gtk2_ardour/wscript b/gtk2_ardour/wscript index 1055c37eaf..7a5615704a 100644 --- a/gtk2_ardour/wscript +++ b/gtk2_ardour/wscript @@ -152,6 +152,7 @@ gtk2_ardour_sources = [ 'level_meter.cc', 'library_download_dialog.cc', 'location_ui.cc', + 'lollipop.cc', 'loudness_dialog.cc', 'loudness_settings.cc', 'lua_script_manager.cc', diff --git a/libs/canvas/canvas/lollipop.h b/libs/canvas/canvas/lollipop.h index 0ae68eeedb..f3eeac4cee 100644 --- a/libs/canvas/canvas/lollipop.h +++ b/libs/canvas/canvas/lollipop.h @@ -44,10 +44,11 @@ public: Coord radius() const { return _radius; } void set_length (Coord); - void set_x (Coord); + Coord length() const { return _points[1].y - _points[0].y; } /* Set origin, length, radius in one pass */ - void set (Duple, Coord, Coord); + void set (Duple const &, Coord, Coord); + void set_x (Coord); Coord x0 () const { return _points[0].x; diff --git a/libs/canvas/lollipop.cc b/libs/canvas/lollipop.cc index ea7e260584..30e6bece75 100644 --- a/libs/canvas/lollipop.cc +++ b/libs/canvas/lollipop.cc @@ -120,6 +120,32 @@ Lollipop::set_x (Coord x) } } +void +Lollipop::set_length (Coord len) +{ + if (_points[1].y != _points[0].y - len) { + begin_change (); + _points[1].y = _points[0].y - len; + end_change (); + } +} + +void +Lollipop::set (Duple const & d, Coord l, Coord r) +{ + begin_change (); + + _points[0].x = d.x; + _points[1].x = d.x; + + _points[0].y = d.y; + _points[1].y = _points[0].y - l; + + _radius = r; + + end_change (); +} + bool Lollipop::covers (Duple const & point) const {