From 9412130c01b42b924c3bcfd355346093dd5e3d75 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 7 Dec 2020 11:40:00 -0700 Subject: [PATCH] use cleaned up Temporal ::quarters*_at* API (GUI edition) --- gtk2_ardour/audio_clock.cc | 4 +- gtk2_ardour/editor.cc | 12 ++--- gtk2_ardour/editor_drag.cc | 12 ++--- gtk2_ardour/editor_rulers.cc | 76 ++++++++++++++++++++++++++++-- gtk2_ardour/editor_tempodisplay.cc | 4 +- gtk2_ardour/midi_region_view.cc | 8 ++-- 6 files changed, 93 insertions(+), 23 deletions(-) diff --git a/gtk2_ardour/audio_clock.cc b/gtk2_ardour/audio_clock.cc index 9932a0cc59..6154ad19f5 100644 --- a/gtk2_ardour/audio_clock.cc +++ b/gtk2_ardour/audio_clock.cc @@ -1244,10 +1244,10 @@ AudioClock::set_bbt (timepos_t const & w, timecnt_t const & o, bool /*force*/) Temporal::BBT_Time sub_bbt; if (negative) { - BBT = tmap->bbt_at (tmap->quarter_note_at (timepos_t (offset))); + BBT = tmap->bbt_at (tmap->quarters_at (timepos_t (offset))); sub_bbt = tmap->bbt_at (timepos_t (offset - when)); } else { - BBT = tmap->bbt_at (tmap->quarter_note_at (when + offset)); + BBT = tmap->bbt_at (tmap->quarters_at (when + offset)); sub_bbt = tmap->bbt_at (timepos_t (offset)); } diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index eac184bd45..ffb87f2906 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -2841,19 +2841,19 @@ Editor::snap_to_bbt (timepos_t const & presnap, Temporal::RoundMode direction, S case bbt_show_16: case bbt_show_4: case bbt_show_1: - ret = timepos_t (tmap->quarter_note_at (tmap->round_to_bar (tmap->bbt_at (presnap)))); + ret = timepos_t (tmap->quarters_at (tmap->round_to_bar (tmap->bbt_at (presnap)))); break; case bbt_show_quarters: - ret = timepos_t (tmap->quarter_note_at (presnap).round_to_beat ()); + ret = timepos_t (tmap->quarters_at (presnap).round_to_beat ()); break; case bbt_show_eighths: - ret = timepos_t (tmap->quarter_note_at (presnap).round_to_subdivision (1 * divisor, direction)); + ret = timepos_t (tmap->quarters_at (presnap).round_to_subdivision (1 * divisor, direction)); break; case bbt_show_sixteenths: - ret = timepos_t (tmap->quarter_note_at (presnap).round_to_subdivision (2 * divisor, direction)); + ret = timepos_t (tmap->quarters_at (presnap).round_to_subdivision (2 * divisor, direction)); break; case bbt_show_thirtyseconds: - ret = timepos_t (tmap->quarter_note_at (presnap).round_to_subdivision (4 * divisor, direction)); + ret = timepos_t (tmap->quarters_at (presnap).round_to_subdivision (4 * divisor, direction)); break; case bbt_show_sixtyfourths: ret = _session->tempo_map().round_to_quarter_note_subdivision (presnap.sample, 8 * divisor, direction); @@ -2863,7 +2863,7 @@ Editor::snap_to_bbt (timepos_t const & presnap, Temporal::RoundMode direction, S break; } } else { - ret = timepos_t (tmap->quarter_note_at (presnap).round_to_subdivision (get_grid_beat_divisions(), direction)); + ret = timepos_t (tmap->quarters_at (presnap).round_to_subdivision (get_grid_beat_divisions(), direction)); } return ret; diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 793536df56..6d646ea239 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -3449,7 +3449,7 @@ MeterMarkerDrag::motion (GdkEvent* event, bool first_move) if (map->time_domain() == AudioTime) { pos = timepos_t (map->sample_at (bbt, _editor->session()->sample_rate())); } else { - pos = timepos_t (map->quarter_note_at (bbt)); + pos = timepos_t (map->quarters_at (bbt)); } _marker->reset_meter (map->set_meter (meter, pos)); @@ -3619,7 +3619,7 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move) if (map->time_domain() == AudioTime) { pos = timepos_t (map->sample_at (bbt, _editor->session()->sample_rate())); } else { - pos = timepos_t (map->quarter_note_at (bbt)); + pos = timepos_t (map->quarters_at (bbt)); } _marker->reset_tempo (map->set_tempo (tempo, pos)); @@ -3792,7 +3792,7 @@ BBTRulerDrag::setup_pointer_offset () beat = floor (beat_at_sample) + (floor (((beat_at_sample - floor (beat_at_sample)) * 4)) / 4); } - _grab_qn = map.quarter_note_at (beat); + _grab_qn = map.quarters_at (beat); _pointer_offset = raw_grab_sample() - map.sample_at_quarter_note (_grab_qn); @@ -3823,7 +3823,7 @@ BBTRulerDrag::motion (GdkEvent* event, bool first_move) if (ArdourKeyboard::indicates_constraint (event->button.state)) { /* adjust previous tempo to match pointer sample */ - _editor->session()->tempo_map().gui_stretch_tempo (_tempo, map.sample_at_quarter_note (_grab_qn), pf, _grab_qn, map.quarter_note_at_sample (pf)); + _editor->session()->tempo_map().gui_stretch_tempo (_tempo, map.sample_at_quarter_note (_grab_qn), pf, _grab_qn, map.quarters_at_sample (pf)); } ostringstream sstr; @@ -3951,7 +3951,7 @@ TempoTwistDrag::setup_pointer_offset () beat = floor (beat_at_sample) + (floor (((beat_at_sample - floor (beat_at_sample)) * 4)) / 4); } - _grab_qn = map.quarter_note_at_beat (beat); + _grab_qn = map.quarters_at_beat (beat); _pointer_offset = raw_grab_sample() - map.sample_at_quarter_note (_grab_qn); @@ -6922,7 +6922,7 @@ NoteCreateDrag::grid_aligned_beats (timepos_t const & pos, GdkEvent const * even beats = pos.beats (); break; case -1: /* round to bar */ - beats = map->quarter_note_at (map->metric_at (pos).meter().round_to_bar (map->bbt_at (pos))); + beats = map->quarters_at (map->metric_at (pos).meter().round_to_bar (map->bbt_at (pos))); break; default: /* round to some beat subdivision */ beats = (pos).beats().round_to_subdivision (divisions, Temporal::RoundNearest); diff --git a/gtk2_ardour/editor_rulers.cc b/gtk2_ardour/editor_rulers.cc index 99ec3c1335..e83b0a8177 100644 --- a/gtk2_ardour/editor_rulers.cc +++ b/gtk2_ardour/editor_rulers.cc @@ -981,14 +981,14 @@ Editor::compute_bbt_ruler_scale (samplepos_t lower, samplepos_t upper) std::vector::const_iterator i; Temporal::BBT_Time lower_beat, upper_beat; // the beats at each end of the ruler Temporal::TempoMap::SharedPtr tmap (Temporal::TempoMap::use()); - Beats floor_lower_beat = std::max (Beats(), tmap->quarter_note_at (lower)).round_down_to_beat (); + Beats floor_lower_beat = std::max (Beats(), tmap->quarters_at_sample (lower)).round_down_to_beat (); if (floor_lower_beat < 0.0) { floor_lower_beat = 0.0; } const samplepos_t beat_before_lower_pos = tmap->sample_at (floor_lower_beat, _session->sample_rate()); - const samplepos_t beat_after_upper_pos = tmap->sample_at ((std::max (Beats(), tmap->quarter_note_at (upper)).round_down_to_beat()) + Beats (1, 0), _session->sample_rate()); + const samplepos_t beat_after_upper_pos = tmap->sample_at ((std::max (Beats(), tmap->quarters_at_sample (upper)).round_down_to_beat()) + Beats (1, 0), _session->sample_rate()); _session->bbt_time (timepos_t (beat_before_lower_pos), lower_beat); _session->bbt_time (timepos_t (beat_after_upper_pos), upper_beat); @@ -1000,7 +1000,77 @@ Editor::compute_bbt_ruler_scale (samplepos_t lower, samplepos_t upper) bbt_ruler_scale = bbt_show_many; - const double ceil_upper_beat = floor (std::max (0.0, _session->tempo_map().beat_at_sample (upper))) + 1.0; + switch (_grid_type) { + case GridTypeBeatDiv2: + bbt_beat_subdivision = 2; + break; + case GridTypeBeatDiv3: + bbt_beat_subdivision = 3; + break; + case GridTypeBeatDiv4: + bbt_beat_subdivision = 4; + break; + case GridTypeBeatDiv5: + bbt_beat_subdivision = 5; + bbt_accent_modulo = 2; // XXX YIKES + break; + case GridTypeBeatDiv6: + bbt_beat_subdivision = 3; + bbt_accent_modulo = 2; // XXX YIKES + break; + case GridTypeBeatDiv7: + bbt_beat_subdivision = 7; + bbt_accent_modulo = 2; // XXX YIKES + break; + case GridTypeBeatDiv8: + bbt_beat_subdivision = 4; + bbt_accent_modulo = 2; + break; + case GridTypeBeatDiv10: + bbt_beat_subdivision = 5; + bbt_accent_modulo = 2; // XXX YIKES + break; + case GridTypeBeatDiv12: + bbt_beat_subdivision = 3; + bbt_accent_modulo = 3; + break; + case GridTypeBeatDiv14: + bbt_beat_subdivision = 7; + bbt_accent_modulo = 3; // XXX YIKES! + break; + case GridTypeBeatDiv16: + bbt_beat_subdivision = 4; + bbt_accent_modulo = 4; + break; + case GridTypeBeatDiv20: + bbt_beat_subdivision = 5; + bbt_accent_modulo = 5; + break; + case GridTypeBeatDiv24: + bbt_beat_subdivision = 6; + bbt_accent_modulo = 6; + break; + case GridTypeBeatDiv28: + bbt_beat_subdivision = 7; + bbt_accent_modulo = 7; + break; + case GridTypeBeatDiv32: + bbt_beat_subdivision = 4; + bbt_accent_modulo = 8; + break; + case GridTypeBar: + case GridTypeBeat: + bbt_beat_subdivision = 4; + break; + case GridTypeNone: + case GridTypeTimecode: + case GridTypeMinSec: + case GridTypeCDFrame: + bbt_beat_subdivision = 4; + break; + } + + const Beats ceil_upper_beat = std::max (Beats(), tmap->quarters_at_sample (upper)).round_up_to_beat() + Beats (1, 0); if (ceil_upper_beat == floor_lower_beat) { return; diff --git a/gtk2_ardour/editor_tempodisplay.cc b/gtk2_ardour/editor_tempodisplay.cc index 66ff945f94..f5e6aaedaa 100644 --- a/gtk2_ardour/editor_tempodisplay.cc +++ b/gtk2_ardour/editor_tempodisplay.cc @@ -334,7 +334,7 @@ Editor::compute_current_bbt_points (Temporal::TempoMapPoints& grid, samplepos_t /* prevent negative values of leftmost from creeping into tempomap */ - const Beats lower_beat = max (Beats (), TempoMap::use()->quarter_note_at (leftmost)).round_down_to_beat() - Beats (1, 0); + const Beats lower_beat = max (Beats (), TempoMap::use()->quarters_at_sample (leftmost)).round_down_to_beat() - Beats (1, 0); const samplecnt_t sr (_session->sample_rate()); TempoMap::SharedPtr tmap (TempoMap::use()); @@ -419,7 +419,7 @@ Editor::mouse_add_new_tempo_event (timepos_t pos) begin_reversible_command (_("add tempo mark")); - const Beats qn = map->quarter_note_at (pos); + const Beats qn = map->quarters_at (pos); if (qn > Beats()) { XMLNode &before = map->get_state(); diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 47a514f54b..d15a25b509 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -2932,7 +2932,7 @@ MidiRegionView::update_resizing (NoteBase* primary, bool at_front, double delta_ } Temporal::TempoMap::SharedPtr tmap (Temporal::TempoMap::use()); - const timepos_t abs_beats (tmap->quarter_note_at (snapped_x)); + const timepos_t abs_beats (tmap->quarters_at (snapped_x)); const Temporal::Beats beats = _region->absolute_time_to_source_beats (abs_beats); Temporal::Beats len = Temporal::Beats(); @@ -3027,7 +3027,7 @@ MidiRegionView::commit_resizing (NoteBase* primary, bool at_front, double delta_ } /* and then to beats */ - const timepos_t abs_beats (Temporal::TempoMap::use()->quarter_note_at (current_time)); + const timepos_t abs_beats (Temporal::TempoMap::use()->quarters_at (current_time)); const Temporal::Beats x_beats = _region->absolute_time_to_source_beats (abs_beats); if (at_front && x_beats < canvas_note->note()->end_time()) { @@ -4268,11 +4268,11 @@ MidiRegionView::snap_sample_to_grid_underneath (samplepos_t p, bool shift_snap) #warning NUTEMPO new tempo map API required #if 0 Temporal::TempoMap& map (trackview.session()->tempo_map()); - Temporal::Beats eqaf = map.quarter_note_at (p + _region->position_sample()); + Temporal::Beats eqaf = map.quarters_at (p + _region->position_sample()); if (shift_snap) { - const Temporal::Beats qaf = map.quarter_note_at (p + _region->position_sample()); + const Temporal::Beats qaf = map.quarters_at (p + _region->position_sample()); /* Hack so that we always snap to the note that we are over, instead of snapping to the next one if we're more than halfway through the one we're over. */