From e800d595dc149eb75d40db6895f1e86cc5f0fe9a Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 2 Nov 2016 15:20:54 +0000 Subject: [PATCH] explanatory comment for MidiRegion::set_start_beats_from_start_frames() --- libs/ardour/midi_region.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libs/ardour/midi_region.cc b/libs/ardour/midi_region.cc index 7d7619680a..a2838bdc55 100644 --- a/libs/ardour/midi_region.cc +++ b/libs/ardour/midi_region.cc @@ -223,6 +223,20 @@ MidiRegion::post_set (const PropertyChange& pc) void MidiRegion::set_start_beats_from_start_frames () { + /* _start gives an offset *in samples* into the source file. we want to + compute (and cache) the offset into the source file using musical + time. + + _pulse gives the position of the region in musical time, which has + the same relationship to _position that _start_beats does to _start. + + so, convert pulses into quarter notes, then compute the offset from + the result (region position in quarter notes) from the quarter note + position computed using position and start. The use of quarter notes + here seems optional, but we happen to have API to compute that in + TempoMap. + */ + _start_beats = (pulse() * 4.0) - _session.tempo_map().quarter_note_at_frame (_position - _start); }