Skip to content

Commit

Permalink
bring in change from bf7d4f8 but also try to fix API ambiguity and bu…
Browse files Browse the repository at this point in the history
…g in that commit and existing code

_grid_type is an EditingContext member; grid_type is a method parameter
  • Loading branch information
pauldavisthefirst committed Jan 5, 2025
1 parent a0413c5 commit d0890ab
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 26 deletions.
23 changes: 4 additions & 19 deletions gtk2_ardour/editing_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1417,11 +1417,11 @@ EditingContext::snap_to (timepos_t& start, Temporal::RoundMode direction, SnapPr
timepos_t
EditingContext::snap_to_bbt (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref) const
{
return _snap_to_bbt (presnap, direction, gpref, _grid_type);
return snap_to_bbt_via_grid (presnap, direction, gpref, _grid_type);
}

timepos_t
EditingContext::_snap_to_bbt (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref, GridType grid_type) const
EditingContext::snap_to_bbt_via_grid (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref, GridType grid_type) const
{
timepos_t ret(presnap);
TempoMap::SharedPtr tmap (TempoMap::use());
Expand All @@ -1434,22 +1434,7 @@ EditingContext::_snap_to_bbt (timepos_t const & presnap, Temporal::RoundMode dir
*/

if (grid_type == GridTypeBar) {
TempoMetric m (tmap->metric_at (presnap));
BBT_Argument bbt (m.bbt_at (presnap));
switch (direction) {
case RoundDownAlways:
bbt = BBT_Argument (bbt.reference(), bbt.round_down_to_bar ());
break;
case RoundUpAlways:
bbt = BBT_Argument (bbt.reference(), bbt.round_up_to_bar ());
break;
case RoundNearest:
bbt = BBT_Argument (bbt.reference(), m.round_to_bar (bbt));
break;
default:
break;
}
return timepos_t (tmap->quarters_at (bbt));
return timepos_t (tmap->quarters_at (presnap).round_to_subdivision (get_grid_beat_divisions(grid_type), direction));
}

if (gpref != SnapToGrid_Unscaled) { // use the visual grid lines which are limited by the zoom scale that the user selected
Expand Down Expand Up @@ -1531,7 +1516,7 @@ EditingContext::_snap_to_bbt (timepos_t const & presnap, Temporal::RoundMode dir
* zoom level
*/

ret = timepos_t (tmap->quarters_at (presnap).round_to_subdivision (get_grid_beat_divisions(_grid_type), direction));
ret = timepos_t (tmap->quarters_at (presnap).round_to_subdivision (get_grid_beat_divisions (grid_type), direction));
}

return ret;
Expand Down
8 changes: 4 additions & 4 deletions gtk2_ardour/editing_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,10 @@ class EditingContext : public ARDOUR::SessionHandlePtr, public AxisViewProvider
Editing::ZoomFocus _zoom_focus;
virtual Editing::ZoomFocus effective_zoom_focus() const { return _zoom_focus; }

Temporal::timepos_t _snap_to_bbt (Temporal::timepos_t const & start,
Temporal::RoundMode direction,
ARDOUR::SnapPref gpref,
Editing::GridType grid_type) const;
Temporal::timepos_t snap_to_bbt_via_grid (Temporal::timepos_t const & start,
Temporal::RoundMode direction,
ARDOUR::SnapPref gpref,
Editing::GridType grid_type) const;

virtual Temporal::timepos_t snap_to_grid (Temporal::timepos_t const & start,
Temporal::RoundMode direction,
Expand Down
6 changes: 3 additions & 3 deletions gtk2_ardour/editor_mouse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1728,10 +1728,10 @@ Editor::button_release_handler (ArdourCanvas::Item* item, GdkEvent* event, ItemT


GridType
Editor::determine_mapping_grid_snap(timepos_t t)
Editor::determine_mapping_grid_snap (timepos_t t)
{
timepos_t snapped = _snap_to_bbt (t, RoundNearest, SnapToGrid_Unscaled, GridTypeBeat);
timepos_t snapped_to_bar = _snap_to_bbt (t, RoundNearest, SnapToGrid_Unscaled, GridTypeBar);
timepos_t snapped = snap_to_bbt_via_grid (t, RoundNearest, SnapToGrid_Unscaled, GridTypeBeat);
timepos_t snapped_to_bar = snap_to_bbt_via_grid (t, RoundNearest, SnapToGrid_Unscaled, GridTypeBar);
const double unsnapped_pos = time_to_pixel_unrounded (t);
const double snapped_pos = time_to_pixel_unrounded (snapped);

Expand Down

0 comments on commit d0890ab

Please sign in to comment.