Meter TempoMap::_default_meter (4.0, 4.0);
Tempo TempoMap::_default_tempo (120.0);
-double
-Tempo::frames_per_beat (framecnt_t sr) const
-{
- return (60.0 * sr) / _beats_per_minute;
-}
-
/***********************************************************************/
double
if (!(current < (*next_metric)->start())) {
- set_metrics:
+ set_metrics:
if (((ts = dynamic_cast<TempoSection*> (*next_metric)) != 0)) {
tempo = ts;
double next_beat_frames = tempo->frames_per_beat (_frame_rate);
DEBUG_TRACE (DEBUG::TempoMath, string_compose ("bumped into non-beat-aligned tempo metric at %1 = %2, adjust next beat using %3\n",
- tempo->start(), current_frame, tempo->bar_offset()));
+ tempo->start(), current_frame, tempo->bar_offset()));
/* back up to previous beat */
current_frame -= beat_frames;
* bar start
*/
tempo->set_frame (bar_start_frame +
- llrint ((ts->bar_offset() * meter->divisions_per_bar() * beat_frames)));
+ llrint ((ts->bar_offset() * meter->divisions_per_bar() * beat_frames)));
/* advance to the location of
* the new (adjusted) beat. do
} else {
DEBUG_TRACE (DEBUG::TempoMath, string_compose ("bumped into beat-aligned tempo metric at %1 = %2\n",
- tempo->start(), current_frame));
+ tempo->start(), current_frame));
tempo->set_frame (current_frame);
}
*/
DEBUG_TRACE (DEBUG::TempoMath, string_compose ("bumped into meter section at %1 vs %2 (%3)\n",
- meter->start(), current, current_frame));
+ meter->start(), current, current_frame));
assert (current.beats == 1);
beat_frames = meter->frames_per_grid (*tempo, _frame_rate);
DEBUG_TRACE (DEBUG::TempoMath, string_compose ("New metric with beat frames = %1 dpb %2 meter %3 tempo %4\n",
- beat_frames, meter->divisions_per_bar(), *((Meter*)meter), *((Tempo*)tempo)));
+ beat_frames, meter->divisions_per_bar(), *((Meter*)meter), *((Tempo*)tempo)));
++next_metric;
if (next_metric != metrics.end() && ((*next_metric)->start() == current)) {
/* same position so go back and set this one up before advancing
- */
+ */
goto set_metrics;
}
/* no more metrics - we've timestamped them all, stop here */
if (end == max_framepos) {
DEBUG_TRACE (DEBUG::TempoMath, string_compose ("stop extending map now that we've reach the end @ %1|%2 = %3\n",
- current.bars, current.beats, current_frame));
+ current.bars, current.beats, current_frame));
break;
}
}
}
TempoMetric
-TempoMap::metric_at (framepos_t frame) const
+TempoMap::metric_at (framepos_t frame, Metrics::const_iterator* last) const
{
Glib::Threads::RWLock::ReaderLock lm (lock);
TempoMetric m (first_meter(), first_tempo());
- const Meter* meter;
- const Tempo* tempo;
/* at this point, we are *guaranteed* to have m.meter and m.tempo pointing
at something, because we insert the default tempo and meter during
break;
}
- if ((tempo = dynamic_cast<const TempoSection*>(*i)) != 0) {
- m.set_tempo (*tempo);
- } else if ((meter = dynamic_cast<const MeterSection*>(*i)) != 0) {
- m.set_meter (*meter);
- }
+ m.set_metric(*i);
- m.set_frame ((*i)->frame ());
- m.set_start ((*i)->start ());
+ if (last) {
+ *last = i;
+ }
}
return m;
{
Glib::Threads::RWLock::ReaderLock lm (lock);
TempoMetric m (first_meter(), first_tempo());
- const Meter* meter;
- const Tempo* tempo;
/* at this point, we are *guaranteed* to have m.meter and m.tempo pointing
at something, because we insert the default tempo and meter during
break;
}
- if ((tempo = dynamic_cast<const TempoSection*>(*i)) != 0) {
- m.set_tempo (*tempo);
- } else if ((meter = dynamic_cast<const MeterSection*>(*i)) != 0) {
- m.set_meter (*meter);
- }
-
- m.set_frame ((*i)->frame ());
- m.set_start (section_start);
+ m.set_metric (*i);
}
return m;
bbt.ticks = 0;
} else {
bbt.ticks = llrint (((frame - (*i).frame) / (*i).tempo->frames_per_beat(_frame_rate)) *
- BBT_Time::ticks_per_beat);
+ BBT_Time::ticks_per_beat);
}
}
next_tempo -> first tempo after "pos", possibly metrics.end()
*/
- DEBUG_TRACE (DEBUG::TempoMath, string_compose ("frame %1 plus %2 beats, start with tempo = %3 @ %4\n",
- pos, beats, *((Tempo*)tempo), tempo->frame()));
+ DEBUG_TRACE (DEBUG::TempoMath,
+ string_compose ("frame %1 plus %2 beats, start with tempo = %3 @ %4\n",
+ pos, beats, *((const Tempo*)tempo), tempo->frame()));
while (beats) {
tempo = dynamic_cast<const TempoSection*>(*next_tempo);
DEBUG_TRACE (DEBUG::TempoMath, string_compose ("\tnew tempo = %1 @ %2 fpb = %3\n",
- *((Tempo*)tempo), tempo->frame(),
+ *((const Tempo*)tempo), tempo->frame(),
tempo->frames_per_beat (_frame_rate)));
while (next_tempo != metrics.end ()) {
}
}
- DEBUG_TRACE (DEBUG::TempoMath, string_compose ("frame %1 minus %2 beats, start with tempo = %3 @ %4 prev at beg? %5\n",
- pos, beats, *((Tempo*)tempo), tempo->frame(),
- prev_tempo == metrics.rend()));
+ DEBUG_TRACE (DEBUG::TempoMath,
+ string_compose ("frame %1 minus %2 beats, start with tempo = %3 @ %4 prev at beg? %5\n",
+ pos, beats, *((const Tempo*)tempo), tempo->frame(),
+ prev_tempo == metrics.rend()));
/* We now have:
tempo = dynamic_cast<const TempoSection*>(*prev_tempo);
- DEBUG_TRACE (DEBUG::TempoMath, string_compose ("\tnew tempo = %1 @ %2 fpb = %3\n",
- *((Tempo*)tempo), tempo->frame(),
- tempo->frames_per_beat (_frame_rate)));
+ DEBUG_TRACE (DEBUG::TempoMath,
+ string_compose ("\tnew tempo = %1 @ %2 fpb = %3\n",
+ *((const Tempo*)tempo), tempo->frame(),
+ tempo->frames_per_beat (_frame_rate)));
while (prev_tempo != metrics.rend ()) {
assert (tempo);
- DEBUG_TRACE (DEBUG::TempoMath, string_compose ("frame %1 walk by %2 frames, start with tempo = %3 @ %4\n",
- pos, distance, *((Tempo*)tempo), tempo->frame()));
+ DEBUG_TRACE (DEBUG::TempoMath,
+ string_compose ("frame %1 walk by %2 frames, start with tempo = %3 @ %4\n",
+ pos, distance, *((const Tempo*)tempo), tempo->frame()));
Evoral::MusicalTime beats = 0;
tempo = dynamic_cast<const TempoSection*>(*next_tempo);
- DEBUG_TRACE (DEBUG::TempoMath, string_compose ("\tnew tempo = %1 @ %2 fpb = %3\n",
- *((Tempo*)tempo), tempo->frame(),
- tempo->frames_per_beat (_frame_rate)));
+ DEBUG_TRACE (DEBUG::TempoMath,
+ string_compose ("\tnew tempo = %1 @ %2 fpb = %3\n",
+ *((const Tempo*)tempo), tempo->frame(),
+ tempo->frames_per_beat (_frame_rate)));
while (next_tempo != metrics.end ()) {
const MeterSection* ms;
if ((ts = dynamic_cast<const TempoSection*> (§ion)) != 0) {
- o << *((Tempo*) ts);
+ o << *((const Tempo*) ts);
} else if ((ms = dynamic_cast<const MeterSection*> (§ion)) != 0) {
- o << *((Meter*) ms);
+ o << *((const Meter*) ms);
}
return o;