lots of detailed fixes to get lollipops in tracks working again, post re-factor

This commit is contained in:
Paul Davis 2024-09-16 18:19:40 -06:00
parent 7901b4119f
commit 54fdf90cc2
12 changed files with 133 additions and 49 deletions

View file

@ -331,8 +331,6 @@ Editor::canvas_stream_view_event (GdkEvent *event, ArdourCanvas::Item* item, Rou
bool
Editor::canvas_automation_track_event (GdkEvent *event, ArdourCanvas::Item* item, AutomationTimeAxisView *atv)
{
std::cerr << "AT event\n";
if (atv->parameter().type() == MidiVelocityAutomation) {
/* no event handling for velocity tracks until we can make the
automation control affect note velocity.

View file

@ -7212,7 +7212,7 @@ LollipopDrag::LollipopDrag (EditingContext& ec, ArdourCanvas::Item* l)
, _primary (dynamic_cast<ArdourCanvas::Lollipop*> (l))
{
DEBUG_TRACE (DEBUG::Drags, "New LollipopDrag\n");
_region = reinterpret_cast<VelocityGhostRegion*> (_item->get_data ("ghostregionview"));
_display = reinterpret_cast<VelocityDisplay*> (_item->get_data ("ghostregionview"));
}
LollipopDrag::~LollipopDrag ()
@ -7225,21 +7225,20 @@ LollipopDrag::start_grab (GdkEvent *ev, Gdk::Cursor* c)
Drag::start_grab (ev, c);
NoteBase* note = static_cast<NoteBase*> (_primary->get_data (X_("note")));
MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (&_region->parent_rv);
assert (mrv);
MidiView& view (_display->midi_view());
bool add = Keyboard::modifier_state_equals (ev->button.state, Keyboard::PrimaryModifier);
bool extend = Keyboard::modifier_state_equals (ev->button.state, Keyboard::TertiaryModifier);
if (mrv->selection().find (note) == mrv->selection().end()) {
mrv->note_selected (note, add, extend);
if (view.selection().find (note) == view.selection().end()) {
view.note_selected (note, add, extend);
}
}
void
LollipopDrag::motion (GdkEvent *ev, bool first_move)
{
_region->drag_lolli (_primary, &ev->motion);
_display->drag_lolli (_primary, &ev->motion);
}
void
@ -7249,12 +7248,10 @@ LollipopDrag::finished (GdkEvent *ev, bool did_move)
return;
}
int velocity = _region->y_position_to_velocity (_primary->y0());
int velocity = _display->y_position_to_velocity (_primary->y0());
NoteBase* note = static_cast<NoteBase*> (_primary->get_data (X_("note")));
MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (&_region->parent_rv);
assert (mrv);
mrv->set_velocity (note, velocity);
_display->midi_view().set_velocity (note, velocity);
}
void
@ -7267,7 +7264,8 @@ void
LollipopDrag::setup_pointer_offset ()
{
NoteBase* note = static_cast<NoteBase*> (_primary->get_data (X_("note")));
_pointer_offset = _region->parent_rv.region()->source_beats_to_absolute_time (note->note()->time ()).distance (raw_grab_time ());
#warning paul this needs to use some other math in the non-time axis view case
_pointer_offset = _display->midi_view().midi_region()->source_beats_to_absolute_time (note->note()->time ()).distance (raw_grab_time ());
}
/********/
@ -7516,11 +7514,11 @@ AutomationDrawDrag::finished (GdkEvent* event, bool motion_occured)
VelocityLineDrag::VelocityLineDrag (EditingContext& ec, ArdourCanvas::Rectangle& r, Temporal::TimeDomain time_domain)
: FreehandLineDrag<Evoral::ControlList::OrderedPoints,Evoral::ControlList::OrderedPoint> (ec, nullptr, r, time_domain)
, grv (static_cast<VelocityGhostRegion*> (r.get_data ("ghostregionview")))
, vd (static_cast<VelocityDisplay*> (r.get_data ("ghostregionview")))
, drag_did_change (false)
{
DEBUG_TRACE (DEBUG::Drags, "New VelocityLineDrag\n");
assert (grv);
assert (vd);
}
VelocityLineDrag::~VelocityLineDrag ()
@ -7531,19 +7529,19 @@ void
VelocityLineDrag::start_grab (GdkEvent* ev, Gdk::Cursor* c)
{
FreehandLineDrag<Evoral::ControlList::OrderedPoints,Evoral::ControlList::OrderedPoint>::start_grab (ev, c);
grv->start_line_drag ();
vd->start_line_drag ();
}
void
VelocityLineDrag::point_added (Duple const & d, ArdourCanvas::Rectangle const & r, double last_x)
{
drag_did_change |= grv->line_draw_motion (d, r, last_x);
drag_did_change |= vd->line_draw_motion (d, r, last_x);
}
void
VelocityLineDrag::line_extended (Duple const & from, Duple const & to, ArdourCanvas::Rectangle const & r, double last_x)
{
drag_did_change |= grv->line_extended (from, to, r, last_x);
drag_did_change |= vd->line_extended (from, to, r, last_x);
}
void
@ -7560,11 +7558,11 @@ VelocityLineDrag::finished (GdkEvent* event, bool motion_occured)
* drawn_points
*/
grv->end_line_drag (drag_did_change);
vd->end_line_drag (drag_did_change);
}
void
VelocityLineDrag::aborted (bool)
{
grv->end_line_drag (false);
vd->end_line_drag (false);
}

View file

@ -86,7 +86,7 @@ class ControlPoint;
class AudioRegionView;
class AutomationLine;
class AutomationTimeAxisView;
class VelocityGhostRegion;
class VelocityDisplay;
/** Class to manage current drags */
class DragManager
@ -1589,7 +1589,7 @@ class LollipopDrag : public Drag
void setup_pointer_offset ();
private:
VelocityGhostRegion* _region;
VelocityDisplay* _display;
ArdourCanvas::Lollipop* _primary;
};
@ -1646,7 +1646,7 @@ class VelocityLineDrag : public FreehandLineDrag<Evoral::ControlList::OrderedPoi
void line_extended (ArdourCanvas::Duple const & from, ArdourCanvas::Duple const & to, ArdourCanvas::Rectangle const & r, double last_x);
private:
VelocityGhostRegion* grv;
VelocityDisplay* vd;
bool drag_did_change;
};

View file

@ -763,7 +763,9 @@ Editor::button_press_handler_1 (ArdourCanvas::Item* item, GdkEvent* event, ItemT
case VelocityBaseItem:
{
VelocityGhostRegion* grv = static_cast<VelocityGhostRegion*> (item->get_data ("ghostregionview"));
VelocityDisplay* vd = static_cast<VelocityDisplay*> (item->get_data ("ghostregionview"));
VelocityGhostRegion* grv = dynamic_cast<VelocityGhostRegion*> (vd);
std::cerr << "VBI with item " << item << " vd " << vd << " data for grv pointed at " << grv << std::endl;
if (grv) {
_drags->set (new VelocityLineDrag (*this, grv->base_item(), Temporal::BeatTime), event);
}

View file

@ -59,14 +59,13 @@ GhostRegion::GhostRegion (RegionView& rv,
: parent_rv (rv)
, trackview (tv)
, source_trackview (source_tv)
, base_rect (0)
, group (new ArdourCanvas::Container (parent))
, base_rect (new ArdourCanvas::Rectangle (group))
{
group = new ArdourCanvas::Container (parent);
CANVAS_DEBUG_NAME (group, "ghost region group");
group->set_position (ArdourCanvas::Duple (initial_pos, 0));
if (is_automation_ghost()) {
base_rect = new ArdourCanvas::Rectangle (group);
CANVAS_DEBUG_NAME (base_rect, "ghost region rect");
base_rect->set_x0 (0);
base_rect->set_y0 (1.0);

View file

@ -272,6 +272,7 @@ MidiRegionView::add_ghost (TimeAxisView& tv)
ghost->set_height ();
ghost->set_duration (_region->length().samples() / samples_per_pixel);
std::cerr << "Adding " << _events.size() << " notes to ghost\n";
for (auto const & i : _events) {
ghost->add_note (i.second);
}
@ -563,6 +564,75 @@ MidiRegionView::ghosts_view_changed ()
}
}
void
MidiRegionView::clear_ghost_events()
{
for (auto & ghost : ghosts) {
MidiGhostRegion* gr;
if ((gr = dynamic_cast<MidiGhostRegion*>(ghost)) != 0) {
gr->clear_events ();
}
}
}
void
MidiRegionView::ghosts_model_changed()
{
for (auto & ghost : ghosts) {
MidiGhostRegion* gr;
if ((gr = dynamic_cast<MidiGhostRegion*>(ghost)) != 0) {
if (!gr->trackview.hidden()) {
gr->model_changed ();
}
}
}
}
void
MidiRegionView::ghost_remove_note (NoteBase* nb)
{
for (auto & ghost : ghosts) {
MidiGhostRegion* gr;
if ((gr = dynamic_cast<MidiGhostRegion*>(ghost)) != 0) {
gr->remove_note (nb);
}
}
}
void
MidiRegionView::ghost_add_note (NoteBase* nb)
{
for (auto & ghost : ghosts) {
MidiGhostRegion* gr;
std::cerr << "GAN on " << ghost << std::endl;
if ((gr = dynamic_cast<MidiGhostRegion*>(ghost)) != 0) {
gr->add_note (nb);
}
}
}
void
MidiRegionView::ghost_sync_selection (NoteBase* nb)
{
for (auto & ghost : ghosts) {
MidiGhostRegion* gr;
if ((gr = dynamic_cast<MidiGhostRegion*>(ghost)) != 0) {
gr->note_selected (nb);
}
}
}
MidiRegionView::~MidiRegionView ()
{
in_destructor = true;
@ -608,19 +678,6 @@ MidiRegionView::set_selected (bool selected)
RegionView::set_selected (selected);
}
void
MidiRegionView::ghost_sync_selection (NoteBase* ev)
{
for (auto & ghost : ghosts) {
MidiGhostRegion* gr;
if ((gr = dynamic_cast<MidiGhostRegion*>(ghost)) != 0) {
gr->note_selected (ev);
}
}
}
uint32_t
MidiRegionView::get_fill_color() const
{

View file

@ -152,11 +152,11 @@ public:
friend class EditNoteDialog;
void clear_ghost_events() {}
void ghosts_model_changed() {}
void clear_ghost_events();
void ghosts_model_changed();
void ghosts_view_changed();
void ghost_remove_note (NoteBase*) {}
void ghost_add_note (NoteBase*) {}
void ghost_remove_note (NoteBase*);
void ghost_add_note (NoteBase*);
void ghost_sync_selection (NoteBase*);
bool motion (GdkEventMotion*);

View file

@ -1753,6 +1753,8 @@ MidiView::add_note(const std::shared_ptr<NoteType> note, bool visible)
event = 0;
}
std::cerr << "add note, event " << event << std::endl;
if (event) {
ghost_add_note (event);

View file

@ -68,6 +68,7 @@ VelocityDisplay::VelocityDisplay (EditingContext& ec, MidiViewBackground& backgr
, selected (false)
, _optimization_iterator (events.end())
{
std::cerr << "new VD @ " << this << " view " << &view << std::endl;
base.set_data (X_("ghostregionview"), this);
base.Event.connect (sigc::mem_fun (*this, &VelocityDisplay::base_event));
base.set_fill_color (UIConfiguration::instance().color_mod ("ghost track base", "ghost track midi fill"));
@ -158,6 +159,7 @@ VelocityDisplay::clear ()
void
VelocityDisplay::add_note (NoteBase* nb)
{
std::cerr << "Add new lolli\n";
ArdourCanvas::Lollipop* l = new ArdourCanvas::Lollipop (lolli_container);
l->set_bounding_parent (&base);
@ -196,8 +198,6 @@ VelocityDisplay::set_size_and_position (GhostEvent& gev)
l->set (ArdourCanvas::Duple (gev.event->x0() + (gev.event->x1() - gev.event->x0()) / 2, base.height() - actual_height), actual_height, lollipop_radius * scale);
} else {
l->set (ArdourCanvas::Duple (gev.event->x0(), base.height() - actual_height), actual_height, lollipop_radius * scale);
std::cerr << "place loli @ " << ArdourCanvas::Duple (gev.event->x0(), base.height() - actual_height) << " h: " << actual_height << " r: " << lollipop_radius * scale << " of " << available_height
<< " ah " << actual_height << " from " << base.whoami() << " = " << base.get() << " bh " << base.height() << std::endl;
}
}
@ -320,7 +320,6 @@ VelocityDisplay::y_position_to_velocity (double y) const
void
VelocityDisplay::note_selected (NoteBase* ev)
{
std::cerr << "Look for event in " << events.size() << std::endl;
GhostEvent* gev = GhostEvent::find (ev->note(), events, _optimization_iterator);
if (!gev) {

View file

@ -72,6 +72,7 @@ class VelocityDisplay
void end_line_drag (bool did_change);
ArdourCanvas::Rectangle& base_item() { return base; }
MidiView& midi_view() const { return view; }
protected:
virtual bool lollevent (GdkEvent*, GhostEvent*) = 0;

View file

@ -52,6 +52,7 @@ using namespace Temporal;
VelocityGhostRegion::VelocityGhostRegion (MidiRegionView& mrv, TimeAxisView& tv, TimeAxisView& source_tv, double initial_unit_pos)
: MidiGhostRegion (mrv, tv, source_tv, initial_unit_pos)
, VelocityDisplay (trackview.editor(), *mrv.midi_stream_view(), mrv, *base_rect, *_note_group, MidiGhostRegion::events, MidiGhostRegion::_outline)
{
}
@ -59,6 +60,12 @@ VelocityGhostRegion::~VelocityGhostRegion ()
{
}
void
VelocityGhostRegion::add_note (NoteBase* nb)
{
VelocityDisplay::add_note (nb);
}
void
VelocityGhostRegion::set_colors ()
{
@ -87,3 +94,20 @@ VelocityGhostRegion::lollevent (GdkEvent* ev, GhostEvent* gev)
return trackview.editor().canvas_velocity_event (ev, gev->item);
}
ArdourCanvas::Rectangle&
VelocityGhostRegion::base_item()
{
return VelocityDisplay::base_item();
}
void
VelocityGhostRegion::update_note (GhostEvent* ev)
{
VelocityDisplay::update_note (ev);
}
void
VelocityGhostRegion::note_selected (NoteBase* nb)
{
VelocityDisplay::note_selected (nb);
}

View file

@ -39,7 +39,11 @@ class VelocityGhostRegion : public MidiGhostRegion, public VelocityDisplay
~VelocityGhostRegion ();
void remove_note (NoteBase*);
ArdourCanvas::Rectangle& base_item() { return *base_rect; }
void add_note (NoteBase*);
void note_selected (NoteBase*);
void update_note (GhostEvent*);
ArdourCanvas::Rectangle& base_item();
void set_colors ();
private:
bool base_event (GdkEvent*);