diff --git a/gtk2_ardour/editor_canvas_events.cc b/gtk2_ardour/editor_canvas_events.cc index bf8135f6ee..033c048e36 100644 --- a/gtk2_ardour/editor_canvas_events.cc +++ b/gtk2_ardour/editor_canvas_events.cc @@ -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. diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 03dc0380af..d7f66c797a 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -7212,7 +7212,7 @@ LollipopDrag::LollipopDrag (EditingContext& ec, ArdourCanvas::Item* l) , _primary (dynamic_cast (l)) { DEBUG_TRACE (DEBUG::Drags, "New LollipopDrag\n"); - _region = reinterpret_cast (_item->get_data ("ghostregionview")); + _display = reinterpret_cast (_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 (_primary->get_data (X_("note"))); - MidiRegionView* mrv = dynamic_cast (&_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 (_primary->get_data (X_("note"))); - MidiRegionView* mrv = dynamic_cast (&_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 (_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 (ec, nullptr, r, time_domain) - , grv (static_cast (r.get_data ("ghostregionview"))) + , vd (static_cast (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::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); } diff --git a/gtk2_ardour/editor_drag.h b/gtk2_ardour/editor_drag.h index d39d226f7b..a905e45ba6 100644 --- a/gtk2_ardour/editor_drag.h +++ b/gtk2_ardour/editor_drag.h @@ -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 (item->get_data ("ghostregionview")); + VelocityDisplay* vd = static_cast (item->get_data ("ghostregionview")); + VelocityGhostRegion* grv = dynamic_cast (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); } diff --git a/gtk2_ardour/ghostregion.cc b/gtk2_ardour/ghostregion.cc index ee82213057..9e158b0b11 100644 --- a/gtk2_ardour/ghostregion.cc +++ b/gtk2_ardour/ghostregion.cc @@ -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); diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 8b71989f67..15b6b09fa5 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -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(ghost)) != 0) { + gr->clear_events (); + } + } +} + +void +MidiRegionView::ghosts_model_changed() +{ + for (auto & ghost : ghosts) { + + MidiGhostRegion* gr; + + if ((gr = dynamic_cast(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(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(ghost)) != 0) { + gr->add_note (nb); + } + } +} + +void +MidiRegionView::ghost_sync_selection (NoteBase* nb) +{ + for (auto & ghost : ghosts) { + + MidiGhostRegion* gr; + + if ((gr = dynamic_cast(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(ghost)) != 0) { - gr->note_selected (ev); - } - } -} - uint32_t MidiRegionView::get_fill_color() const { diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index c238d5c127..f9dce309d1 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -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*); diff --git a/gtk2_ardour/midi_view.cc b/gtk2_ardour/midi_view.cc index d37ee1bad1..a43c645227 100644 --- a/gtk2_ardour/midi_view.cc +++ b/gtk2_ardour/midi_view.cc @@ -1753,6 +1753,8 @@ MidiView::add_note(const std::shared_ptr note, bool visible) event = 0; } + std::cerr << "add note, event " << event << std::endl; + if (event) { ghost_add_note (event); diff --git a/gtk2_ardour/velocity_display.cc b/gtk2_ardour/velocity_display.cc index c20b7a14ea..319096b47e 100644 --- a/gtk2_ardour/velocity_display.cc +++ b/gtk2_ardour/velocity_display.cc @@ -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) { diff --git a/gtk2_ardour/velocity_display.h b/gtk2_ardour/velocity_display.h index 49c289cccd..52e18f234c 100644 --- a/gtk2_ardour/velocity_display.h +++ b/gtk2_ardour/velocity_display.h @@ -72,7 +72,8 @@ 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; diff --git a/gtk2_ardour/velocity_ghost_region.cc b/gtk2_ardour/velocity_ghost_region.cc index 8af4c2b8aa..c2be26999a 100644 --- a/gtk2_ardour/velocity_ghost_region.cc +++ b/gtk2_ardour/velocity_ghost_region.cc @@ -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); +} diff --git a/gtk2_ardour/velocity_ghost_region.h b/gtk2_ardour/velocity_ghost_region.h index e3fd9a3b31..adada59405 100644 --- a/gtk2_ardour/velocity_ghost_region.h +++ b/gtk2_ardour/velocity_ghost_region.h @@ -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*);