class TempoMap;
-/** Converter between beats and frames. Takes `distances' in beats or frames
+/** Converter between beats and frames. Takes durations in beats or frames
* and converts them using the tempo at the \a origin supplied to the constructor.
+ * Note that this does not covert positions, only durations.
*/
class BeatsFramesConverter : public Evoral::TimeConverter<double,framepos_t> {
public:
- BeatsFramesConverter(const TempoMap& tempo_map, framepos_t origin)
- : Evoral::TimeConverter<double, framepos_t> (origin)
- , _tempo_map(tempo_map)
- {}
+ BeatsFramesConverter (const TempoMap& tempo_map, framepos_t origin)
+ : Evoral::TimeConverter<double, framepos_t> (origin)
+ , _tempo_map(tempo_map)
+ {}
- framepos_t to(double beats) const;
- double from(framepos_t frames) const;
+ framepos_t to (double beats) const;
+ double from (framepos_t frames) const;
private:
const TempoMap& _tempo_map;
namespace ARDOUR {
framecnt_t
-BeatsFramesConverter::to(double beats) const
+BeatsFramesConverter::to (double beats) const
{
- return _tempo_map.framepos_plus_bbt (_origin_b, Timecode::BBT_Time(beats));
+ return _tempo_map.framepos_plus_bbt (_origin_b, Timecode::BBT_Time(beats)) - _origin_b;
}
double
MidiRegion::update_length_beats ()
{
cerr << name() << " Updating length beats, currently = " << _length_beats << " w/length = " << _length << endl;
- BeatsFramesConverter converter (_session.tempo_map(), _position - _start);
+ BeatsFramesConverter converter (_session.tempo_map(), _position);
_length_beats = converter.from (_length);
cerr << "\tnew value: " << _length_beats << endl;
}
at the new position (tempo map may dictate a different number of frames
*/
BeatsFramesConverter converter (_session.tempo_map(), _position - _start);
- cerr << name() << " change frame length to " << converter.to (_length_beats) << endl;
Region::set_length_internal (converter.to (_length_beats));
}
}
*/
if (ddist < frames_per_beat) {
- beats += BBT_Time::ticks_per_beat * (ddist/frames_per_beat);
+ beats += (1.0/BBT_Time::ticks_per_beat) * (ddist/frames_per_beat);
break;
}
ddist -= frames_per_beat;
dpos += frames_per_beat;
beats += 1.0;
-
+
/* check if we need to use a new metric section: has adding frames moved us
to or after the start of the next metric section? in which case, use it.
*/