lollis: also adjust velocity bars during the drag

This commit is contained in:
Paul Davis 2023-06-20 14:42:43 -06:00
parent 96c9f2ee19
commit 2d9a2ad668
8 changed files with 62 additions and 29 deletions

View File

@ -145,3 +145,10 @@ Hit::set_ignore_events (bool ignore)
{ {
_polygon->set_ignore_events (ignore); _polygon->set_ignore_events (ignore);
} }
double
Hit::visual_velocity() const
{
/* We don't display velocity in any explicit way */
return 0.0;
}

View File

@ -66,6 +66,8 @@ public:
static ArdourCanvas::Points points(ArdourCanvas::Distance height); static ArdourCanvas::Points points(ArdourCanvas::Distance height);
double visual_velocity() const;
private: private:
ArdourCanvas::Polygon* _polygon; ArdourCanvas::Polygon* _polygon;
}; };

View File

@ -1859,7 +1859,6 @@ MidiRegionView::update_sustained (Note* ev, bool update_ghost_regions)
const uint32_t base_col = ev->base_color(); const uint32_t base_col = ev->base_color();
ev->set_fill_color(base_col); ev->set_fill_color(base_col);
ev->set_outline_color(ev->calculate_outline(base_col, ev->selected())); ev->set_outline_color(ev->calculate_outline(base_col, ev->selected()));
} }
void void
@ -3378,8 +3377,6 @@ MidiRegionView::set_velocity (NoteBase* note, int velocity)
int delta = velocity - note->note()->velocity(); int delta = velocity - note->note()->velocity();
std::cerr << "vel delta = " << delta << std::endl;
start_note_diff_command (_("set velocities")); start_note_diff_command (_("set velocities"));
for (Selection::iterator i = _selection.begin(); i != _selection.end();) { 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); 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);
}
}

View File

@ -505,6 +505,8 @@ public:
std::shared_ptr<SysEx> find_canvas_sys_ex (ARDOUR::MidiModel::SysExPtr s); std::shared_ptr<SysEx> find_canvas_sys_ex (ARDOUR::MidiModel::SysExPtr s);
friend class VelocityGhostRegion; friend class VelocityGhostRegion;
void sync_velocity_drag (double factor);
void update_note (NoteBase*, bool update_ghost_regions = true); void update_note (NoteBase*, bool update_ghost_regions = true);
void update_sustained (Note *, bool update_ghost_regions = true); void update_sustained (Note *, bool update_ghost_regions = true);
void update_hit (Hit *, bool update_ghost_regions = true); void update_hit (Hit *, bool update_ghost_regions = true);

View File

@ -32,122 +32,128 @@ using ArdourCanvas::Duple;
Note::Note ( Note::Note (
MidiRegionView& region, ArdourCanvas::Item* parent, const std::shared_ptr<NoteType> note, bool with_events) MidiRegionView& region, ArdourCanvas::Item* parent, const std::shared_ptr<NoteType> note, bool with_events)
: NoteBase (region, with_events, note) : NoteBase (region, with_events, note)
, _note (new ArdourCanvas::Note (parent)) , _visual_note (new ArdourCanvas::Note (parent))
{ {
CANVAS_DEBUG_NAME (_note, "note"); CANVAS_DEBUG_NAME (_visual_note, "note");
set_item (_note); set_item (_visual_note);
} }
Note::~Note () Note::~Note ()
{ {
delete _note; delete _visual_note;
} }
void void
Note::move_event (double dx, double dy) 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 Coord
Note::x0 () const Note::x0 () const
{ {
return _note->x0 (); return _visual_note->x0 ();
} }
Coord Coord
Note::x1 () const Note::x1 () const
{ {
return _note->x1 (); return _visual_note->x1 ();
} }
Coord Coord
Note::y0 () const Note::y0 () const
{ {
return _note->y0 (); return _visual_note->y0 ();
} }
Coord Coord
Note::y1 () const Note::y1 () const
{ {
return _note->y1 (); return _visual_note->y1 ();
} }
void void
Note::set_outline_color (uint32_t color) Note::set_outline_color (uint32_t color)
{ {
_note->set_outline_color (color); _visual_note->set_outline_color (color);
} }
void void
Note::set_fill_color (uint32_t color) Note::set_fill_color (uint32_t color)
{ {
_note->set_fill_color (color); _visual_note->set_fill_color (color);
} }
void void
Note::show () Note::show ()
{ {
_note->show (); _visual_note->show ();
} }
void void
Note::hide () Note::hide ()
{ {
_note->hide (); _visual_note->hide ();
} }
void void
Note::set (ArdourCanvas::Rect rect) Note::set (ArdourCanvas::Rect rect)
{ {
_note->set (rect); _visual_note->set (rect);
} }
void void
Note::set_x0 (Coord x0) Note::set_x0 (Coord x0)
{ {
_note->set_x0 (x0); _visual_note->set_x0 (x0);
} }
void void
Note::set_y0 (Coord y0) Note::set_y0 (Coord y0)
{ {
_note->set_y0 (y0); _visual_note->set_y0 (y0);
} }
void void
Note::set_x1 (Coord x1) Note::set_x1 (Coord x1)
{ {
_note->set_x1 (x1); _visual_note->set_x1 (x1);
} }
void void
Note::set_y1 (Coord y1) Note::set_y1 (Coord y1)
{ {
_note->set_y1 (y1); _visual_note->set_y1 (y1);
} }
void void
Note::set_outline_what (ArdourCanvas::Rectangle::What what) Note::set_outline_what (ArdourCanvas::Rectangle::What what)
{ {
_note->set_outline_what (what); _visual_note->set_outline_what (what);
} }
void void
Note::set_outline_all () Note::set_outline_all ()
{ {
_note->set_outline_all (); _visual_note->set_outline_all ();
} }
void void
Note::set_ignore_events (bool ignore) Note::set_ignore_events (bool ignore)
{ {
_note->set_ignore_events (ignore); _visual_note->set_ignore_events (ignore);
} }
void void
Note::set_velocity (double fract) 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();
}

View File

@ -62,11 +62,13 @@ public:
void set_ignore_events (bool); void set_ignore_events (bool);
/* Just changes the visual display of velocity during a drag */
void set_velocity (double); void set_velocity (double);
double visual_velocity () const;
void move_event (double dx, double dy); void move_event (double dx, double dy);
private: private:
ArdourCanvas::Note* _note; ArdourCanvas::Note* _visual_note;
}; };
#endif /* __gtk_ardour_note_h__ */ #endif /* __gtk_ardour_note_h__ */

View File

@ -105,6 +105,9 @@ class NoteBase : public sigc::trackable
virtual ArdourCanvas::Coord x1 () const = 0; virtual ArdourCanvas::Coord x1 () const = 0;
virtual ArdourCanvas::Coord y1 () 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_x_fraction() const { return _mouse_x_fraction; }
float mouse_y_fraction() const { return _mouse_y_fraction; } float mouse_y_fraction() const { return _mouse_y_fraction; }
@ -137,7 +140,7 @@ protected:
ArdourCanvas::Item* _item; ArdourCanvas::Item* _item;
ArdourCanvas::Text* _text; ArdourCanvas::Text* _text;
State _state; State _state;
const std::shared_ptr<NoteType> _note; const std::shared_ptr<NoteType> _note;
bool _with_events; bool _with_events;
bool _own_note; bool _own_note;
Flags _flags; Flags _flags;

View File

@ -150,6 +150,14 @@ VelocityGhostRegion::drag_lolli (ArdourCanvas::Lollipop* l, GdkEventMotion* ev)
MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (&parent_rv); MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (&parent_rv);
assert (mrv); 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()); MidiRegionView::Selection const & sel (mrv->selection());
for (auto & s : sel) { 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())); velocity = floor (127. * (((r.height() - 2.0 * lollipop_radius)- y) / r.height()));
} }
std::cerr << " y = " << y << " vel = " << velocity << std::endl;
return velocity; return velocity;
} }