From 354567e5a72c3d24fb13d8b47a51b1c3859918ea Mon Sep 17 00:00:00 2001 From: nick_m Date: Tue, 29 Mar 2016 04:13:37 +1100 Subject: [PATCH] Tempo ramps - switch MusicLocked tempos to beat-based dragging. fix various bugs wrt future-snapped tempo drags --- gtk2_ardour/editor.cc | 2 ++ gtk2_ardour/editor_drag.cc | 36 ++++++++++++++++++++++-------------- libs/ardour/tempo.cc | 8 +++----- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 155024f720..6e59cfc912 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -2157,6 +2157,8 @@ Editor::snap_musical() const case SnapToBeatDiv4: case SnapToBeatDiv3: case SnapToBeatDiv2: + case SnapToBeat: + case SnapToBar: return true; default: break; diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 3305bfd040..b6083281ab 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -3317,18 +3317,29 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move) } framepos_t pf; + double beat = 0.0; + if (!_editor->snap_musical()) { pf = adjusted_current_frame (event); } else { - pf = adjusted_current_frame (event); + pf = adjusted_current_frame (event, false); Timecode::BBT_Time when; _editor->session()->tempo_map().bbt_time (pf, when); - if (_editor->snap_type() == SnapToBar) { - _editor->session()->tempo_map().round_bbt (when, -1); + if (_real_section->position_lock_style() == MusicTime) { + if (_editor->snap_type() == SnapToBar) { + _editor->session()->tempo_map().round_bbt (when, -1); + } else { + _editor->session()->tempo_map().round_bbt (when, _editor->get_grid_beat_divisions (0)); + } + beat = _editor->session()->tempo_map().bbt_to_beats (when); } else { - _editor->session()->tempo_map().round_bbt (when, _editor->get_grid_beat_divisions (0)); + if (_editor->snap_type() == SnapToBar) { + _editor->session()->tempo_map().round_bbt (when, -1); + } else { + _editor->session()->tempo_map().round_bbt (when, _editor->get_grid_beat_divisions (0)); + } + pf = _editor->session()->tempo_map().predict_tempo_frame (_real_section, Tempo (_real_section->beats_per_minute(), _real_section->note_type()), when); } - pf = _editor->session()->tempo_map().predict_tempo_frame (_real_section, Tempo (_real_section->beats_per_minute(), _real_section->note_type()), when); } Tempo const tp = _marker->tempo(); @@ -3340,17 +3351,14 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move) show_verbose_cursor_text (strs.str()); } else if (_movable) { - _marker->set_position (pf); - /* just here for a check/laugh - if (_real_section->position_lock_style() == MusicTime) { - const double baf = _editor->session()->tempo_map().beat_at_frame (pf); - _editor->session()->tempo_map().gui_move_tempo_beat (_real_section, tp, baf); - } else { - */ - _editor->session()->tempo_map().gui_move_tempo_frame (_real_section, tp, pf); - //} + if (_real_section->position_lock_style() == MusicTime) { + _editor->session()->tempo_map().gui_move_tempo_beat (_real_section, tp, beat); + } else { + _editor->session()->tempo_map().gui_move_tempo_frame (_real_section, tp, pf); + } show_verbose_cursor_time (pf); } + _marker->set_position (pf); } void diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc index 72a1f2fea6..fec74ccfe0 100644 --- a/libs/ardour/tempo.cc +++ b/libs/ardour/tempo.cc @@ -1146,7 +1146,7 @@ TempoMap::gui_move_tempo_beat (TempoSection* ts, const Tempo& bpm, const double Glib::Threads::RWLock::WriterLock lm (lock); TempoSection* new_section = copy_metrics_and_point (future_map, ts); if (solve_map (future_map, new_section, bpm, pulse_at_beat_locked (future_map, beat))) { - solve_map (_metrics, ts, bpm, beat); + solve_map (_metrics, ts, bpm, pulse_at_beat_locked (_metrics, beat)); } } @@ -2492,16 +2492,14 @@ TempoMap::round_bbt (BBT_Time& when, const int32_t& sub_num) return; } else if (sub_num == 0) { const double bpb = meter_section_at (bbt_to_beats_locked (_metrics, when)).divisions_per_bar(); - if (when.ticks > BBT_Time::ticks_per_beat / 2) { + if ((double) when.ticks > BBT_Time::ticks_per_beat / 2.0) { ++when.beats; while ((double) when.beats > bpb) { ++when.bars; when.beats -= (uint32_t) floor (bpb); } - when.ticks = 0; - } else { - when.ticks = 0; } + when.ticks = 0; return; } const uint32_t ticks_one_subdivisions_worth = BBT_Time::ticks_per_beat / sub_num;