From a6e02c0d71b67f3c571229c932dc20ee476df69b Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 17 Jan 2017 20:43:55 +0100 Subject: Implement Count-In (before recording), fixed BPM, up to 2 bars --- libs/ardour/session_transport.cc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'libs/ardour/session_transport.cc') diff --git a/libs/ardour/session_transport.cc b/libs/ardour/session_transport.cc index 5f1384d292..a6d25f05ab 100644 --- a/libs/ardour/session_transport.cc +++ b/libs/ardour/session_transport.cc @@ -45,6 +45,7 @@ #include "ardour/scene_changer.h" #include "ardour/session.h" #include "ardour/slave.h" +#include "ardour/tempo.h" #include "ardour/operations.h" #include "pbd/i18n.h" @@ -1616,6 +1617,38 @@ Session::start_transport () if (!dynamic_cast(_slave)) { send_immediate_mmc (MIDI::MachineControlCommand (MIDI::MachineControl::cmdDeferredPlay)); } + + if (actively_recording() && click_data && config.get_count_in ()) { + /* calculate count-in duration (in audio samples) + * - use [fixed] tempo/meter at _transport_frame + * - calc duration of 1 bar + time-to-beat before or at transport_frame + */ + const Tempo& tempo = _tempo_map->tempo_at_frame (_transport_frame); + const Meter& meter = _tempo_map->meter_at_frame (_transport_frame); + + double div = meter.divisions_per_bar (); + double pulses = _tempo_map->exact_qn_at_frame (_transport_frame, 0) * div / 4.0; + double beats_left = fmod (pulses, div); + + _count_in_samples = meter.frames_per_bar (tempo, _current_frame_rate); + + double dt = _count_in_samples / div; + if (beats_left == 0) { + /* at bar boundary, count-in 2 bars before start. */ + _count_in_samples *= 2; + } else { + /* beats left after full bar until roll position */ + _count_in_samples += meter.frames_per_grid (tempo, _current_frame_rate) * beats_left; + } + + int clickbeat = 0; + framepos_t cf = _transport_frame - _count_in_samples; + while (cf < _transport_frame) { + add_click (cf - _worst_track_latency, clickbeat == 0); + cf += dt; + clickbeat = fmod (clickbeat + 1, div); + } + } } DEBUG_TRACE (DEBUG::Transport, string_compose ("send TSC4 with speed = %1\n", _transport_speed)); -- cgit v1.2.3