Add API to lookup MIDI Clock Beat position

This commit is contained in:
Robin Gareus 2020-05-29 22:48:16 +02:00
parent c1b72a289f
commit 8e52ea74da
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 20 additions and 0 deletions

View File

@ -374,6 +374,8 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
void get_grid (std::vector<BBTPoint>&,
samplepos_t start, samplepos_t end, uint32_t bar_mod = 0);
void midi_clock_beat_at_of_after (samplepos_t const pos, samplepos_t& clk_pos, uint32_t& clk_beat);
static const Tempo& default_tempo() { return _default_tempo; }
static const Meter& default_meter() { return _default_meter; }

View File

@ -4189,6 +4189,24 @@ TempoMap::get_grid (vector<TempoMap::BBTPoint>& points,
}
}
void
TempoMap::midi_clock_beat_at_of_after (samplepos_t const pos, samplepos_t& clk_pos, uint32_t& clk_beat)
{
/* Sequences are always assumed to start on a MIDI Beat of 0 (ie, the downbeat).
* Each MIDI Beat spans 6 MIDI Clocks. In other words, each MIDI Beat is a 16th note
* (since there are 24 MIDI Clocks in a quarter note, therefore 4 MIDI Beats also fit in a quarter).
* So, a master can sync playback to a resolution of any particular 16th note
*
* from http://midi.teragonaudio.com/tech/midispec/seq.htm
*/
Glib::Threads::RWLock::ReaderLock lm (lock);
/* pulse is a whole note */
clk_beat = ceil (16.0 * (pulse_at_minute_locked (_metrics, minute_at_sample (pos))));
clk_pos = sample_at_minute (minute_at_pulse_locked (_metrics, clk_beat / 16.0));
assert (clk_pos >= pos);
}
const TempoSection&
TempoMap::tempo_section_at_sample (samplepos_t sample) const
{