From 43922a1fe13bddd71b37e9d654f7d2da88b39166 Mon Sep 17 00:00:00 2001 From: nick_m Date: Tue, 24 May 2016 05:49:58 +1000 Subject: Tempo ramps - clean up tempo dragging. --- gtk2_ardour/editor_drag.cc | 95 ++++++++++++---------------------------------- libs/ardour/ardour/tempo.h | 2 +- libs/ardour/tempo.cc | 11 +++--- 3 files changed, 31 insertions(+), 77 deletions(-) diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 13bc2f73d1..e7fa7023e1 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -3293,54 +3293,18 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move) TempoMap& map (_editor->session()->tempo_map()); /* get current state */ before_state = &map.get_state(); + if (!_copy) { _editor->begin_reversible_command (_("move tempo mark")); - } else { - _editor->begin_reversible_command (_("copy tempo mark")); - framepos_t frame; - bool use_snap = false; - if (!_editor->snap_musical()) { - frame = adjusted_current_frame (event); - } else { - frame = adjusted_current_frame (event, false); - if (ArdourKeyboard::indicates_snap (event->button.state)) { - if (_editor->snap_mode() == Editing::SnapOff) { - use_snap = true; - } else { - use_snap = false; - } - } else { - if (_editor->snap_mode() == Editing::SnapOff) { - use_snap = false; - } else { - use_snap = true; - } - } - } - - Timecode::BBT_Time bbt; - map.bbt_time (frame, bbt); + } else { + const framepos_t frame = adjusted_current_frame (event) + 1; - /* add new tempo section to map, ensuring we don't refer to existing tempos for snap */ + _editor->begin_reversible_command (_("copy tempo mark")); if (_real_section->position_lock_style() == MusicTime) { - if (use_snap && _editor->snap_type() == SnapToBar) { - map.round_bbt (bbt, -1, (frame > _real_section->frame()) ? RoundUpMaybe : RoundDownMaybe); - } else if (use_snap) { - map.round_bbt (bbt, _editor->get_grid_beat_divisions (0), RoundNearest); - } - double const pulse = map.predict_tempo_position (_real_section, bbt).first; - _real_section = map.add_tempo (_marker->tempo(), pulse, 0, _real_section->type(), MusicTime); + _real_section = map.add_tempo (_marker->tempo(), map.pulse_at_frame (frame), 0, _real_section->type(), MusicTime); } else { - if (use_snap && _editor->snap_type() == SnapToBar) { - map.round_bbt (bbt, -1, (frame > _real_section->frame()) ? RoundUpMaybe : RoundDownMaybe); - } else if (use_snap) { - map.round_bbt (bbt, _editor->get_grid_beat_divisions (0), RoundNearest); - } - if (use_snap) { - frame = map.predict_tempo_position (_real_section, bbt).second; - } _real_section = map.add_tempo (_marker->tempo(), 0.0, frame, _real_section->type(), AudioTime); } } @@ -3359,45 +3323,34 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move) show_verbose_cursor_text (strs.str()); } else if (_movable && !_real_section->locked_to_meter()) { + TempoMap& map (_editor->session()->tempo_map()); + const bool was_music = _real_section->position_lock_style() == MusicTime; - if (!_editor->snap_musical()) { - /* snap normally (this is not self-referential).*/ - pf = adjusted_current_frame (event); + pf = adjusted_current_frame (event); - } else { - /* but this is. - we can't use the map for anything related to tempo, - so we round bbt using meters, which have no dependency - on pulse for this kind of thing. - */ - TempoMap& map (_editor->session()->tempo_map()); - Timecode::BBT_Time when; - bool use_snap; + if (!_editor->snap_musical()) { - if (ArdourKeyboard::indicates_snap (event->button.state)) { - if (_editor->snap_mode() == Editing::SnapOff) { - use_snap = true; - } else { - use_snap = false; - } - } else { - if (_editor->snap_mode() == Editing::SnapOff) { - use_snap = false; - } else { - use_snap = true; - } + if (was_music) { + _real_section->set_position_lock_style (AudioTime); } - pf = adjusted_current_frame (event); - map.bbt_time (pf, when); + map.gui_move_tempo (_real_section, pf); + + if (was_music) { + _real_section->set_position_lock_style (MusicTime); + } - if (use_snap && _editor->snap_type() == SnapToBar) { - map.round_bbt (when, -1, (pf > _real_section->frame()) ? RoundUpMaybe : RoundDownMaybe); + } else { + if (!was_music) { + _real_section->set_position_lock_style (MusicTime); } - const pair future_pos = map.predict_tempo_position (_real_section, when); - map.gui_move_tempo (_real_section, future_pos); + map.gui_move_tempo (_real_section, pf); + + if (!was_music) { + _real_section->set_position_lock_style (AudioTime); + } } show_verbose_cursor_time (_real_section->frame()); diff --git a/libs/ardour/ardour/tempo.h b/libs/ardour/ardour/tempo.h index 160f7c266a..9cbd8b9727 100644 --- a/libs/ardour/ardour/tempo.h +++ b/libs/ardour/ardour/tempo.h @@ -399,7 +399,7 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible std::pair predict_tempo_position (TempoSection* section, const Timecode::BBT_Time& bbt); - void gui_move_tempo (TempoSection*, const std::pair& pulse); + void gui_move_tempo (TempoSection*, const framepos_t& frame); void gui_move_meter (MeterSection*, const framepos_t& frame); bool gui_change_tempo (TempoSection*, const Tempo& bpm); diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc index faa93632b8..c28a4c04a9 100644 --- a/libs/ardour/tempo.cc +++ b/libs/ardour/tempo.cc @@ -2395,7 +2395,7 @@ TempoMap::predict_tempo_position (TempoSection* section, const BBT_Time& bbt) } void -TempoMap::gui_move_tempo (TempoSection* ts, const pair& pulse) +TempoMap::gui_move_tempo (TempoSection* ts, const framepos_t& frame) { Metrics future_map; @@ -2403,8 +2403,9 @@ TempoMap::gui_move_tempo (TempoSection* ts, const pair& puls { Glib::Threads::RWLock::WriterLock lm (lock); TempoSection* tempo_copy = copy_metrics_and_point (_metrics, future_map, ts); - if (solve_map_pulse (future_map, tempo_copy, pulse.first)) { - solve_map_pulse (_metrics, ts, pulse.first); + const double pulse = pulse_at_frame_locked (future_map, frame); + if (solve_map_pulse (future_map, tempo_copy, pulse)) { + solve_map_pulse (_metrics, ts, pulse); recompute_meters (_metrics); } } @@ -2414,8 +2415,8 @@ TempoMap::gui_move_tempo (TempoSection* ts, const pair& puls { Glib::Threads::RWLock::WriterLock lm (lock); TempoSection* tempo_copy = copy_metrics_and_point (_metrics, future_map, ts); - if (solve_map_frame (future_map, tempo_copy, pulse.second)) { - solve_map_frame (_metrics, ts, pulse.second); + if (solve_map_frame (future_map, tempo_copy, frame)) { + solve_map_frame (_metrics, ts, frame); recompute_meters (_metrics); } } -- cgit v1.2.3