diff options
author | nick_m <mainsbridge@gmail.com> | 2016-06-12 00:42:43 +1000 |
---|---|---|
committer | nick_m <mainsbridge@gmail.com> | 2016-06-12 00:42:43 +1000 |
commit | e973e39f06c81fc301c8b059c5240cc17c6671ad (patch) | |
tree | a156b00f014fcd540a054650b87cc1493f78a925 /libs/ardour/tempo.cc | |
parent | ec8a4de01596c162c1529f3021dfc432bf66dfe8 (diff) |
Set tempo sections to the exact pulse when snapped to a musical grid.
Diffstat (limited to 'libs/ardour/tempo.cc')
-rw-r--r-- | libs/ardour/tempo.cc | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc index d0cf857ad9..15323751b4 100644 --- a/libs/ardour/tempo.cc +++ b/libs/ardour/tempo.cc @@ -2528,15 +2528,31 @@ TempoMap::predict_tempo_position (TempoSection* section, const BBT_Time& bbt) } void -TempoMap::gui_move_tempo (TempoSection* ts, const framepos_t& frame) +TempoMap::gui_move_tempo (TempoSection* ts, const framepos_t& frame, const int& sub_num) { Metrics future_map; if (ts->position_lock_style() == MusicTime) { { + /* if we're snapping to a musical grid, set the pulse exactly instead of via the supplied frame. */ Glib::Threads::RWLock::WriterLock lm (lock); TempoSection* tempo_copy = copy_metrics_and_point (_metrics, future_map, ts); - const double pulse = pulse_at_frame_locked (future_map, frame); + double beat = beat_at_frame_locked (future_map, frame); + + if (sub_num > 0) { + beat = floor (beat) + (floor (((beat - floor (beat)) * (double) sub_num) + 0.5) / sub_num); + } else if (sub_num == -2) { + /* snap to beat */ + beat = floor (beat + 0.5); + } + + double pulse = pulse_at_beat_locked (future_map, beat); + + if (sub_num == -3) { + /* snap to bar */ + pulse = floor (pulse + 0.5); + } + if (solve_map_pulse (future_map, tempo_copy, pulse)) { solve_map_pulse (_metrics, ts, pulse); recompute_meters (_metrics); |