From 7b5d61b7a5b6bc04b243b47b9358e9f487f73d15 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 27 Jun 2021 16:36:59 +0200 Subject: [PATCH] Fix transport master crash when switching backends Port registration happens asynchronously. During the first process callbacks the timecode/clock input ports may not have been re-established. --- libs/ardour/ltc_slave.cc | 5 +++++ libs/ardour/midi_clock_slave.cc | 8 ++++++++ libs/ardour/mtc_slave.cc | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/libs/ardour/ltc_slave.cc b/libs/ardour/ltc_slave.cc index 6a2f71dacb..8b3a4eb966 100644 --- a/libs/ardour/ltc_slave.cc +++ b/libs/ardour/ltc_slave.cc @@ -525,6 +525,11 @@ LTC_TransportMaster::process_ltc(samplepos_t const now) void LTC_TransportMaster::pre_process (ARDOUR::pframes_t nframes, samplepos_t now, boost::optional session_pos) { + if (!_port) { + reset (true); + return; + } + Sample* in = (Sample*) AudioEngine::instance()->port_engine().get_buffer (_port->port_handle(), nframes); sampleoffset_t skip; diff --git a/libs/ardour/midi_clock_slave.cc b/libs/ardour/midi_clock_slave.cc index c650b993ed..b76182f1fb 100644 --- a/libs/ardour/midi_clock_slave.cc +++ b/libs/ardour/midi_clock_slave.cc @@ -119,6 +119,14 @@ void MIDIClock_TransportMaster::pre_process (MIDI::pframes_t nframes, samplepos_t now, boost::optional session_pos) { /* Read and parse incoming MIDI */ + if (!_midi_port) { + _bpm = 0.0; + _running = false; + _current_delta = 0; + midi_clock_count = 0; + DEBUG_TRACE (DEBUG::MidiClock, "No MIDI Clock port registered"); + return; + } DEBUG_TRACE (DEBUG::MidiClock, string_compose ("preprocess with lt = %1 @ %2, running ? %3\n", current.timestamp, now, _running)); diff --git a/libs/ardour/mtc_slave.cc b/libs/ardour/mtc_slave.cc index 5a620c74b0..22dda80cb1 100644 --- a/libs/ardour/mtc_slave.cc +++ b/libs/ardour/mtc_slave.cc @@ -131,6 +131,12 @@ MTC_TransportMaster::pre_process (MIDI::pframes_t nframes, samplepos_t now, boos maybe_reset (); + if (!_midi_port) { + _current_delta = 0; + DEBUG_TRACE (DEBUG::MTC, "No MTC port registered"); + return; + } + _midi_port->read_and_parse_entire_midi_buffer_with_no_speed_adjustment (nframes, parser, now); if (session_pos) {