+ BBT_Time last_metric_start;
+
+ if ((*i).tempo->frame() > (*i).meter->frame()) {
+ last_metric_start = (*i).tempo->start();
+ } else {
+ last_metric_start = (*i).meter->start();
+ }
+
+ /* find the metric immediately after the tempo + meter sections for the
+ * last point in the map
+ */
+
+ for (next_metric = metrics.begin(); next_metric != metrics.end(); ++next_metric) {
+ if ((*next_metric)->start() > last_metric_start) {
+ break;
+ }
+ }
+
+ /* we cast away const here because this is the one place where we need
+ * to actually modify the frame time of each metric section.
+ */
+
+ _extend_map (const_cast<TempoSection*> ((*i).tempo),
+ const_cast<MeterSection*> ((*i).meter),
+ next_metric, BBT_Time ((*i).bar, (*i).beat, 0), (*i).frame, end);
+}
+
+void
+TempoMap::_extend_map (TempoSection* tempo, MeterSection* meter,
+ Metrics::iterator next_metric,
+ BBT_Time current, framepos_t current_frame, framepos_t end)
+{
+ /* CALLER MUST HOLD WRITE LOCK */
+
+ TempoSection* ts;
+ MeterSection* ms;
+ double beat_frames;
+ double current_frame_exact;
+ framepos_t bar_start_frame;
+
+ DEBUG_TRACE (DEBUG::TempoMath, string_compose ("Extend map to %1 from %2 = %3\n", end, current, current_frame));
+
+ if (current.beats == 1) {
+ bar_start_frame = current_frame;
+ } else {
+ bar_start_frame = 0;
+ }
+
+ beat_frames = meter->frames_per_grid (*tempo,_frame_rate);
+ current_frame_exact = current_frame;
+
+ while (current_frame < end) {
+
+ current.beats++;
+ current_frame_exact += beat_frames;
+ current_frame = llrint(current_frame_exact);
+
+ if (current.beats > meter->divisions_per_bar()) {
+ current.bars++;
+ current.beats = 1;
+ }
+
+ if (next_metric != metrics.end()) {
+
+ /* no operator >= so invert operator < */
+
+ DEBUG_TRACE (DEBUG::TempoMath, string_compose ("now at %1 next metric @ %2\n", current, (*next_metric)->start()));
+
+ if (!(current < (*next_metric)->start())) {
+
+ set_metrics:
+ if (((ts = dynamic_cast<TempoSection*> (*next_metric)) != 0)) {