From 21a66c01ea508c23c2e383ea8c5a4ba54421affd Mon Sep 17 00:00:00 2001 From: Ben Loftis Date: Sat, 20 Feb 2021 10:25:10 -0600 Subject: [PATCH] snap-revisited: replace hardcoded ruler-density with a configgable value --- gtk2_ardour/editor_rulers.cc | 7 +++++-- gtk2_ardour/rc_option_editor.cc | 10 ++++++++++ gtk2_ardour/ui_config_vars.h | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/gtk2_ardour/editor_rulers.cc b/gtk2_ardour/editor_rulers.cc index 88044f1e04..5d7b4f6cce 100644 --- a/gtk2_ardour/editor_rulers.cc +++ b/gtk2_ardour/editor_rulers.cc @@ -1073,8 +1073,11 @@ Editor::compute_bbt_ruler_scale (samplepos_t lower, samplepos_t upper) bbt_bars = _session->tempo_map().bbt_at_beat (ceil_upper_beat).bars - _session->tempo_map().bbt_at_beat (floor_lower_beat).bars; - beats = (ceil_upper_beat - floor_lower_beat);// - bbt_bars; possible thinko; this fixes the problem (for me) where measure lines alternately appear&disappear while playing at certain zoom scales - double beat_density = ((beats + 1) * ((double) (upper - lower) / (double) (1 + beat_after_upper_pos - beat_before_lower_pos))) / 5.0; + double ruler_line_granularity = UIConfiguration::instance().get_ruler_granularity (); //in pixels + ruler_line_granularity = _visible_canvas_width / (ruler_line_granularity*5); //fudge factor '5' probably related to (4+1 beats)/measure, I think + + beats = (ceil_upper_beat - floor_lower_beat); + double beat_density = ((beats + 1) * ((double) (upper - lower) / (double) (1 + beat_after_upper_pos - beat_before_lower_pos))) / (float)ruler_line_granularity; /* Only show the bar helper if there aren't many bars on the screen */ if ((bbt_bars < 2) || (beats < 5)) { diff --git a/gtk2_ardour/rc_option_editor.cc b/gtk2_ardour/rc_option_editor.cc index 0bb5714d5d..5f15091e3c 100644 --- a/gtk2_ardour/rc_option_editor.cc +++ b/gtk2_ardour/rc_option_editor.cc @@ -2687,6 +2687,16 @@ RCOptionEditor::RCOptionEditor () 1, 10 )); + add_option (_("Editor/Snap"), + new SpinOption ( + "ruler-granularity", + _("Approximate Grid/Ruler granularity (pixels)"), + sigc::mem_fun (UIConfiguration::instance(), &UIConfiguration::get_ruler_granularity), + sigc::mem_fun (UIConfiguration::instance(), &UIConfiguration::set_ruler_granularity), + 1, 100, + 1, 10 + )); + add_option (_("Editor/Snap"), new BoolOption ( "show-snapped-cursor", diff --git a/gtk2_ardour/ui_config_vars.h b/gtk2_ardour/ui_config_vars.h index 2298bb6f99..84aeebb9d0 100644 --- a/gtk2_ardour/ui_config_vars.h +++ b/gtk2_ardour/ui_config_vars.h @@ -116,6 +116,7 @@ UI_CONFIG_VARIABLE (bool, use_note_bars_for_velocity, "use-note-bars-for-velocit UI_CONFIG_VARIABLE (bool, use_note_color_for_velocity, "use-note-color-for-velocity", true) UI_CONFIG_VARIABLE (bool, show_snapped_cursor, "show-snapped-cursor", true) UI_CONFIG_VARIABLE (uint32_t, snap_threshold, "snap-threshold", 25) +UI_CONFIG_VARIABLE (uint32_t, ruler_granularity, "ruler-granularity", 25) UI_CONFIG_VARIABLE (bool, snap_to_marks, "snap-to-marks", true) UI_CONFIG_VARIABLE (bool, snap_to_region_sync, "snap-to-region-sync", true) UI_CONFIG_VARIABLE (bool, snap_to_region_start, "snap-to-region-start", true)