From 2d9a2ad6686ec4091d5047ef5a03cfe4f6b90129 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 20 Jun 2023 14:42:43 -0600 Subject: [PATCH] lollis: also adjust velocity bars during the drag --- gtk2_ardour/hit.cc | 7 ++++ gtk2_ardour/hit.h | 2 ++ gtk2_ardour/midi_region_view.cc | 11 ++++-- gtk2_ardour/midi_region_view.h | 2 ++ gtk2_ardour/note.cc | 50 ++++++++++++++++------------ gtk2_ardour/note.h | 4 ++- gtk2_ardour/note_base.h | 5 ++- gtk2_ardour/velocity_ghost_region.cc | 10 ++++-- 8 files changed, 62 insertions(+), 29 deletions(-) diff --git a/gtk2_ardour/hit.cc b/gtk2_ardour/hit.cc index 434efe24db..32a027f89d 100644 --- a/gtk2_ardour/hit.cc +++ b/gtk2_ardour/hit.cc @@ -145,3 +145,10 @@ Hit::set_ignore_events (bool ignore) { _polygon->set_ignore_events (ignore); } + +double +Hit::visual_velocity() const +{ + /* We don't display velocity in any explicit way */ + return 0.0; +} diff --git a/gtk2_ardour/hit.h b/gtk2_ardour/hit.h index 6dbbda5954..ec24794a06 100644 --- a/gtk2_ardour/hit.h +++ b/gtk2_ardour/hit.h @@ -66,6 +66,8 @@ public: static ArdourCanvas::Points points(ArdourCanvas::Distance height); + double visual_velocity() const; + private: ArdourCanvas::Polygon* _polygon; }; diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 6932c976a4..d437c014d9 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -1859,7 +1859,6 @@ MidiRegionView::update_sustained (Note* ev, bool update_ghost_regions) const uint32_t base_col = ev->base_color(); ev->set_fill_color(base_col); ev->set_outline_color(ev->calculate_outline(base_col, ev->selected())); - } void @@ -3378,8 +3377,6 @@ MidiRegionView::set_velocity (NoteBase* note, int velocity) int delta = velocity - note->note()->velocity(); - std::cerr << "vel delta = " << delta << std::endl; - start_note_diff_command (_("set velocities")); for (Selection::iterator i = _selection.begin(); i != _selection.end();) { @@ -4660,3 +4657,11 @@ MidiRegionView::quantize_selected_notes () trackview.editor().apply_midi_note_edit_op (quant, rs); } + +void +MidiRegionView::sync_velocity_drag (double factor) +{ + for (auto & s : _selection) { + s->set_velocity (s->visual_velocity() * factor); + } +} diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index 7ec8193dd3..be224d65ad 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -505,6 +505,8 @@ public: std::shared_ptr find_canvas_sys_ex (ARDOUR::MidiModel::SysExPtr s); friend class VelocityGhostRegion; + void sync_velocity_drag (double factor); + void update_note (NoteBase*, bool update_ghost_regions = true); void update_sustained (Note *, bool update_ghost_regions = true); void update_hit (Hit *, bool update_ghost_regions = true); diff --git a/gtk2_ardour/note.cc b/gtk2_ardour/note.cc index e93cd9304a..0d179b9cf0 100644 --- a/gtk2_ardour/note.cc +++ b/gtk2_ardour/note.cc @@ -32,122 +32,128 @@ using ArdourCanvas::Duple; Note::Note ( MidiRegionView& region, ArdourCanvas::Item* parent, const std::shared_ptr note, bool with_events) : NoteBase (region, with_events, note) - , _note (new ArdourCanvas::Note (parent)) + , _visual_note (new ArdourCanvas::Note (parent)) { - CANVAS_DEBUG_NAME (_note, "note"); - set_item (_note); + CANVAS_DEBUG_NAME (_visual_note, "note"); + set_item (_visual_note); } Note::~Note () { - delete _note; + delete _visual_note; } void Note::move_event (double dx, double dy) { - _note->set (_note->get().translate (Duple (dx, dy))); + _visual_note->set (_visual_note->get().translate (Duple (dx, dy))); } Coord Note::x0 () const { - return _note->x0 (); + return _visual_note->x0 (); } Coord Note::x1 () const { - return _note->x1 (); + return _visual_note->x1 (); } Coord Note::y0 () const { - return _note->y0 (); + return _visual_note->y0 (); } Coord Note::y1 () const { - return _note->y1 (); + return _visual_note->y1 (); } void Note::set_outline_color (uint32_t color) { - _note->set_outline_color (color); + _visual_note->set_outline_color (color); } void Note::set_fill_color (uint32_t color) { - _note->set_fill_color (color); + _visual_note->set_fill_color (color); } void Note::show () { - _note->show (); + _visual_note->show (); } void Note::hide () { - _note->hide (); + _visual_note->hide (); } void Note::set (ArdourCanvas::Rect rect) { - _note->set (rect); + _visual_note->set (rect); } void Note::set_x0 (Coord x0) { - _note->set_x0 (x0); + _visual_note->set_x0 (x0); } void Note::set_y0 (Coord y0) { - _note->set_y0 (y0); + _visual_note->set_y0 (y0); } void Note::set_x1 (Coord x1) { - _note->set_x1 (x1); + _visual_note->set_x1 (x1); } void Note::set_y1 (Coord y1) { - _note->set_y1 (y1); + _visual_note->set_y1 (y1); } void Note::set_outline_what (ArdourCanvas::Rectangle::What what) { - _note->set_outline_what (what); + _visual_note->set_outline_what (what); } void Note::set_outline_all () { - _note->set_outline_all (); + _visual_note->set_outline_all (); } void Note::set_ignore_events (bool ignore) { - _note->set_ignore_events (ignore); + _visual_note->set_ignore_events (ignore); } void Note::set_velocity (double fract) { - _note->set_velocity (fract); + /* This just changes the way velocity is drawn */ + _visual_note->set_velocity (fract); } +double +Note::visual_velocity () const +{ + return _visual_note->velocity(); +} diff --git a/gtk2_ardour/note.h b/gtk2_ardour/note.h index dd699e2825..5fa15d75e0 100644 --- a/gtk2_ardour/note.h +++ b/gtk2_ardour/note.h @@ -62,11 +62,13 @@ public: void set_ignore_events (bool); + /* Just changes the visual display of velocity during a drag */ void set_velocity (double); + double visual_velocity () const; void move_event (double dx, double dy); private: - ArdourCanvas::Note* _note; + ArdourCanvas::Note* _visual_note; }; #endif /* __gtk_ardour_note_h__ */ diff --git a/gtk2_ardour/note_base.h b/gtk2_ardour/note_base.h index c1083443af..49aed80da1 100644 --- a/gtk2_ardour/note_base.h +++ b/gtk2_ardour/note_base.h @@ -105,6 +105,9 @@ class NoteBase : public sigc::trackable virtual ArdourCanvas::Coord x1 () const = 0; virtual ArdourCanvas::Coord y1 () const = 0; + virtual void set_velocity (double) {} + virtual double visual_velocity() const = 0; + float mouse_x_fraction() const { return _mouse_x_fraction; } float mouse_y_fraction() const { return _mouse_y_fraction; } @@ -137,7 +140,7 @@ protected: ArdourCanvas::Item* _item; ArdourCanvas::Text* _text; State _state; - const std::shared_ptr _note; + const std::shared_ptr _note; bool _with_events; bool _own_note; Flags _flags; diff --git a/gtk2_ardour/velocity_ghost_region.cc b/gtk2_ardour/velocity_ghost_region.cc index 9a007005e4..f0fe25fa38 100644 --- a/gtk2_ardour/velocity_ghost_region.cc +++ b/gtk2_ardour/velocity_ghost_region.cc @@ -150,6 +150,14 @@ VelocityGhostRegion::drag_lolli (ArdourCanvas::Lollipop* l, GdkEventMotion* ev) MidiRegionView* mrv = dynamic_cast (&parent_rv); assert (mrv); + + /* This will redraw the velocity bars for the selected notes, without + * changing the note velocities. + */ + + const double factor = newlen / l->length(); + mrv->sync_velocity_drag (factor); + MidiRegionView::Selection const & sel (mrv->selection()); for (auto & s : sel) { @@ -176,7 +184,5 @@ VelocityGhostRegion::y_position_to_velocity (double y) const velocity = floor (127. * (((r.height() - 2.0 * lollipop_radius)- y) / r.height())); } - std::cerr << " y = " << y << " vel = " << velocity << std::endl; - return velocity; }