+ _map.push_back (BBTPoint (*meter, *tempo,(framepos_t) llrint(current_frame), 1, 1));
+
+ if (end == 0) {
+ /* silly call from Session::process() during startup
+ */
+ return;
+ }
+
+ _extend_map (tempo, meter, next_metric, current, current_frame, end);
+}
+
+void
+TempoMap::extend_map (framepos_t end)
+{
+ /* CALLER MUST HOLD WRITE LOCK */
+
+ if (_map.empty()) {
+ recompute_map (false, end);
+ return;
+ }
+
+ BBTPointList::const_iterator i = _map.end();
+ Metrics::iterator next_metric;
+
+ --i;
+
+ 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;