some rather simple code to allow MIDI Clock to set the tempo of the session.
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 8 Oct 2018 16:59:51 +0000 (12:59 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 8 Oct 2018 16:59:51 +0000 (12:59 -0400)
This is only allowed if the session has only 1 tempo marker

libs/ardour/ardour/session.h
libs/ardour/midi_clock_slave.cc
libs/ardour/session.cc

index 455a1d63378b0135a9ddd8f14a306f20d4ffe801..e63c68f6046c178f007963ee6f52af5b0915fa74 100644 (file)
@@ -734,6 +734,7 @@ public:
 
        TempoMap&       tempo_map()       { return *_tempo_map; }
        const TempoMap& tempo_map() const { return *_tempo_map; }
+       void maybe_update_tempo_from_midiclock_tempo (float bpm);
 
        unsigned int    get_xrun_count () const {return _xrun_count; }
        void            reset_xrun_count () {_xrun_count = 0; }
index d714eecac1886d1feba5192c990619d82e74e48f..706032887d8f2267ea72c3c666405b7a5620a1b4 100644 (file)
@@ -36,6 +36,7 @@
 #include "ardour/session.h"
 #include "ardour/tempo.h"
 #include "ardour/transport_master.h"
+#include "ardour/transport_master_manager.h"
 
 #include "pbd/i18n.h"
 
@@ -219,7 +220,6 @@ MIDIClock_TransportMaster::update_midi_clock (Parser& /*parser*/, samplepos_t ti
 
                const double samples_per_quarter = (timestamp - current.timestamp) * 24.0;
                const double instantaneous_bpm = (ENGINE->sample_rate() * 60.0) / samples_per_quarter;
-               const double lpf_coeff = 0.05;
 
                const double predicted_clock_interval_in_samples = (t1 - t0);
 
@@ -233,6 +233,8 @@ MIDIClock_TransportMaster::update_midi_clock (Parser& /*parser*/, samplepos_t ti
                 * change of more than 20% of the current tempo.
                 */
 
+               const double lpf_coeff = 0.063;
+
                if (fabs (instantaneous_bpm - _bpm) > (0.20 * _bpm)) {
                        _bpm = instantaneous_bpm;
                } else {
@@ -250,6 +252,10 @@ MIDIClock_TransportMaster::update_midi_clock (Parser& /*parser*/, samplepos_t ti
 
                midi_clock_count++;
                current.update (current.position + one_ppqn_in_samples, timestamp, speed);
+
+               if (TransportMasterManager::instance().current().get() == this) {
+                       _session->maybe_update_tempo_from_midiclock_tempo (_bpm);
+               }
        }
 
        DEBUG_TRACE (DEBUG::MidiClock, string_compose ("clock #%1 @ %2 should-be %3 transport %4 error %5 appspeed %6 "
index f8fc5639f7ee090c6f0b6ace15767e535bc793de..064a929b434a8c9b4dac1a40c59bcb6a615ca2df 100644 (file)
@@ -7276,3 +7276,16 @@ Session::cancel_all_solo ()
        set_controls (stripable_list_to_control_list (sl, &Stripable::solo_control), 0.0, Controllable::NoGroup);
        clear_all_solo_state (routes.reader());
 }
+
+void
+Session::maybe_update_tempo_from_midiclock_tempo (float bpm)
+{
+       if (_tempo_map->n_tempos() == 1) {
+               TempoSection& ts (_tempo_map->tempo_section_at_sample (0));
+               if (fabs (ts.note_types_per_minute() - bpm) > (0.01 * ts.note_types_per_minute())) {
+                       const Tempo tempo (bpm, 4.0, bpm);
+                       std::cerr << "new tempo " << bpm << " old " << ts.note_types_per_minute() << std::endl;
+                       _tempo_map->replace_tempo (ts, tempo, 0.0, 0.0, AudioTime);
+               }
+       }
+}