Refactor tempo api, include quarter-note distance in frames method.
- moves frame rounding up to TempoMap, which is needed in order to calculate pulse distance without frame rounding. - the time unit for tempo is still minute, but this now also applies to meter sections. (new audio locked meter sections no longer require a frame position). - there is no longer a discontinuity in the pulse for audio-locked meter/tempi. - temporarily add debugging output in Region::set_position() to test for region beat not matching region frame.
This commit is contained in:
@@ -3198,7 +3198,7 @@ MeterMarkerDrag::motion (GdkEvent* event, bool first_move)
|
||||
}
|
||||
const double beat = map.beat_at_bbt (bbt);
|
||||
_real_section = map.add_meter (Meter (_marker->meter().divisions_per_bar(), _marker->meter().note_divisor())
|
||||
, beat, bbt, map.frame_at_bbt (bbt), _real_section->position_lock_style());
|
||||
, beat, bbt, _real_section->position_lock_style());
|
||||
if (!_real_section) {
|
||||
aborted (true);
|
||||
return;
|
||||
@@ -3341,7 +3341,8 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move)
|
||||
_editor->begin_reversible_command (_("copy tempo mark"));
|
||||
|
||||
if (_real_section->position_lock_style() == MusicTime) {
|
||||
_real_section = map.add_tempo (tempo, map.pulse_at_frame (frame), 0, type, MusicTime);
|
||||
const int32_t divisions = _editor->get_grid_music_divisions (event->button.state);
|
||||
_real_section = map.add_tempo (tempo, map.exact_qn_at_frame (frame, divisions), 0, type, MusicTime);
|
||||
} else {
|
||||
_real_section = map.add_tempo (tempo, 0.0, frame, type, AudioTime);
|
||||
}
|
||||
|
||||
@@ -1394,10 +1394,9 @@ Editor::toggle_marker_lock_style ()
|
||||
|
||||
const Meter meter (msp->divisions_per_bar(), msp->note_divisor());
|
||||
const Timecode::BBT_Time bbt (msp->bbt());
|
||||
const framepos_t frame = msp->frame();
|
||||
const PositionLockStyle pls = (msp->position_lock_style() == AudioTime) ? MusicTime : AudioTime;
|
||||
|
||||
_session->tempo_map().replace_meter (*msp, meter, bbt, frame, pls);
|
||||
_session->tempo_map().replace_meter (*msp, meter, bbt, pls);
|
||||
|
||||
XMLNode &after = _session->tempo_map().get_state();
|
||||
_session->add_command(new MementoCommand<TempoMap>(_session->tempo_map(), &before, &after));
|
||||
|
||||
@@ -409,9 +409,9 @@ Editor::mouse_add_new_meter_event (framepos_t frame)
|
||||
XMLNode &before = map.get_state();
|
||||
|
||||
if (meter_dialog.get_lock_style() == MusicTime) {
|
||||
map.add_meter (Meter (bpb, note_type), beat, requested, map.frame_at_beat (beat), MusicTime);
|
||||
map.add_meter (Meter (bpb, note_type), beat, requested, MusicTime);
|
||||
} else {
|
||||
map.add_meter (Meter (bpb, note_type), beat, requested, map.frame_at_beat (beat), AudioTime);
|
||||
map.add_meter (Meter (bpb, note_type), beat, requested, AudioTime);
|
||||
}
|
||||
|
||||
_session->add_command(new MementoCommand<TempoMap>(map, &before, &map.get_state()));
|
||||
@@ -462,13 +462,12 @@ Editor::edit_meter_section (MeterSection* section)
|
||||
Timecode::BBT_Time when;
|
||||
meter_dialog.get_bbt_time (when);
|
||||
|
||||
framepos_t const frame = _session->tempo_map().frame_at_bbt (when);
|
||||
const PositionLockStyle pls = (meter_dialog.get_lock_style() == AudioTime) ? AudioTime : MusicTime;
|
||||
|
||||
begin_reversible_command (_("replace meter mark"));
|
||||
XMLNode &before = _session->tempo_map().get_state();
|
||||
|
||||
_session->tempo_map().replace_meter (*section, meter, when, frame, pls);
|
||||
_session->tempo_map().replace_meter (*section, meter, when, pls);
|
||||
|
||||
XMLNode &after = _session->tempo_map().get_state();
|
||||
_session->add_command(new MementoCommand<TempoMap>(_session->tempo_map(), &before, &after));
|
||||
|
||||
@@ -131,7 +131,7 @@ TempoCurve::set_position (framepos_t frame, framepos_t end_frame)
|
||||
framepos_t current_frame = frame;
|
||||
|
||||
while (current_frame < (end_frame - frame_step)) {
|
||||
const double tempo_at = _tempo.tempo_at_frame (current_frame, editor.session()->frame_rate());
|
||||
const double tempo_at = _tempo.tempo_at_minute (_tempo.minute_at_frame (current_frame));
|
||||
const double y_pos = max ((curve_height) - (((tempo_at - _min_tempo) / (_max_tempo - _min_tempo)) * curve_height), 0.0);
|
||||
|
||||
points->push_back (ArdourCanvas::Duple (editor.sample_to_pixel (current_frame - frame), min (y_pos, curve_height)));
|
||||
@@ -139,7 +139,7 @@ TempoCurve::set_position (framepos_t frame, framepos_t end_frame)
|
||||
current_frame += frame_step;
|
||||
}
|
||||
|
||||
const double tempo_at = _tempo.tempo_at_frame (end_frame, editor.session()->frame_rate());
|
||||
const double tempo_at = _tempo.tempo_at_minute (_tempo.minute_at_frame (end_frame));
|
||||
const double y_pos = max ((curve_height) - (((tempo_at - _min_tempo) / (_max_tempo - _min_tempo)) * curve_height), 0.0);
|
||||
|
||||
points->push_back (ArdourCanvas::Duple (editor.sample_to_pixel ((end_frame - 1) - frame), min (y_pos, curve_height)));
|
||||
|
||||
@@ -62,15 +62,14 @@ class LIBARDOUR_API Tempo {
|
||||
double beats_per_minute () const { return _beats_per_minute; }
|
||||
void set_beats_per_minute (double bpm) { _beats_per_minute = bpm; }
|
||||
double note_type () const { return _note_type; }
|
||||
/** audio samples per beat
|
||||
/** audio samples per quarter note beat.
|
||||
* this is only useful for constant tempo and should not be used.
|
||||
* if you want an instantaneous value for this, use frames_per_beat_at() instead.
|
||||
* @param sr samplerate
|
||||
*/
|
||||
double frames_per_beat (framecnt_t sr) const {
|
||||
return (60.0 * sr) / _beats_per_minute;
|
||||
}
|
||||
double frames_per_pulse (framecnt_t sr) const {
|
||||
return (_note_type * 60.0 * sr) / _beats_per_minute;
|
||||
}
|
||||
|
||||
protected:
|
||||
double _beats_per_minute;
|
||||
@@ -105,19 +104,21 @@ class LIBARDOUR_API Meter {
|
||||
/** A section of timeline with a certain Tempo or Meter. */
|
||||
class LIBARDOUR_API MetricSection {
|
||||
public:
|
||||
MetricSection (double pulse, framepos_t frame, PositionLockStyle pls, bool is_tempo)
|
||||
: _pulse (pulse), _frame (frame), _movable (true), _position_lock_style (pls), _is_tempo (is_tempo) {}
|
||||
MetricSection (double pulse, double minute, PositionLockStyle pls, bool is_tempo, framecnt_t sample_rate)
|
||||
: _pulse (pulse), _minute (minute), _movable (true), _position_lock_style (pls), _is_tempo (is_tempo), _sample_rate (sample_rate) {}
|
||||
|
||||
virtual ~MetricSection() {}
|
||||
|
||||
const double& pulse () const { return _pulse; }
|
||||
void set_pulse (double pulse) { _pulse = pulse; }
|
||||
|
||||
framepos_t frame() const { return _frame; }
|
||||
virtual void set_frame (framepos_t f) {
|
||||
_frame = f;
|
||||
double minute() const { return _minute; }
|
||||
virtual void set_minute (double m) {
|
||||
_minute = m;
|
||||
}
|
||||
|
||||
framepos_t frame () const { return frame_at_minute (_minute); }
|
||||
|
||||
void set_movable (bool yn) { _movable = yn; }
|
||||
bool movable() const { return _movable; }
|
||||
|
||||
@@ -131,21 +132,26 @@ class LIBARDOUR_API MetricSection {
|
||||
void set_position_lock_style (PositionLockStyle ps) { _position_lock_style = ps; }
|
||||
bool is_tempo () const { return _is_tempo; }
|
||||
|
||||
framepos_t frame_at_minute (const double& time) const;
|
||||
double minute_at_frame (const framepos_t& frame) const;
|
||||
|
||||
private:
|
||||
|
||||
double _pulse;
|
||||
framepos_t _frame;
|
||||
double _minute;
|
||||
bool _movable;
|
||||
PositionLockStyle _position_lock_style;
|
||||
const bool _is_tempo;
|
||||
framecnt_t _sample_rate;
|
||||
};
|
||||
|
||||
/** A section of timeline with a certain Meter. */
|
||||
class LIBARDOUR_API MeterSection : public MetricSection, public Meter {
|
||||
public:
|
||||
MeterSection (double pulse, framepos_t frame, double beat, const Timecode::BBT_Time& bbt, double bpb, double note_type, PositionLockStyle pls)
|
||||
: MetricSection (pulse, frame, pls, false), Meter (bpb, note_type), _bbt (bbt), _beat (beat) {}
|
||||
MeterSection (double pulse, double minute, double beat, const Timecode::BBT_Time& bbt, double bpb, double note_type, PositionLockStyle pls, framecnt_t sr)
|
||||
: MetricSection (pulse, minute, pls, false, sr), Meter (bpb, note_type), _bbt (bbt), _beat (beat) {}
|
||||
|
||||
MeterSection (const XMLNode&);
|
||||
MeterSection (const XMLNode&, const framecnt_t sample_rate);
|
||||
|
||||
static const std::string xml_state_node_name;
|
||||
|
||||
@@ -173,10 +179,10 @@ class LIBARDOUR_API TempoSection : public MetricSection, public Tempo {
|
||||
Constant,
|
||||
};
|
||||
|
||||
TempoSection (const double& pulse, const framepos_t& frame, double qpm, double note_type, Type tempo_type, PositionLockStyle pls)
|
||||
: MetricSection (pulse, frame, pls, true), Tempo (qpm, note_type), _type (tempo_type), _c_func (0.0), _active (true), _locked_to_meter (false) {}
|
||||
TempoSection (const double& pulse, const double& minute, double qpm, double note_type, Type tempo_type, PositionLockStyle pls, framecnt_t sr)
|
||||
: MetricSection (pulse, minute, pls, true, sr), Tempo (qpm, note_type), _type (tempo_type), _c_func (0.0), _active (true), _locked_to_meter (false) {}
|
||||
|
||||
TempoSection (const XMLNode&);
|
||||
TempoSection (const XMLNode&, const framecnt_t sample_rate);
|
||||
|
||||
static const std::string xml_state_node_name;
|
||||
|
||||
@@ -194,25 +200,25 @@ class LIBARDOUR_API TempoSection : public MetricSection, public Tempo {
|
||||
bool locked_to_meter () const { return _locked_to_meter; }
|
||||
void set_locked_to_meter (bool yn) { _locked_to_meter = yn; }
|
||||
|
||||
double tempo_at_frame (const framepos_t& frame, const framecnt_t& frame_rate) const;
|
||||
framepos_t frame_at_tempo (const double& ppm, const double& beat, const framecnt_t& frame_rate) const;
|
||||
double tempo_at_minute (const double& minute) const;
|
||||
double minute_at_tempo (const double& bpm, const double& pulse) const;
|
||||
|
||||
double tempo_at_pulse (const double& pulse) const;
|
||||
double pulse_at_tempo (const double& ppm, const framepos_t& frame, const framecnt_t& frame_rate) const;
|
||||
double pulse_at_tempo (const double& bpm, const double& minute) const;
|
||||
|
||||
double pulse_at_frame (const framepos_t& frame, const framepos_t& frame_rate) const;
|
||||
framepos_t frame_at_pulse (const double& pulse, const framecnt_t& frame_rate) const;
|
||||
double pulse_at_frame (const framepos_t& frame) const;
|
||||
framepos_t frame_at_pulse (const double& pulse) const;
|
||||
|
||||
double compute_c_func_pulse (const double& end_bpm, const double& end_pulse, const framecnt_t& frame_rate);
|
||||
double compute_c_func_frame (const double& end_bpm, const framepos_t& end_frame, const framecnt_t& frame_rate) const;
|
||||
double pulse_at_minute (const double& minute) const;
|
||||
double minute_at_pulse (const double& pulse) const;
|
||||
|
||||
double compute_c_func_pulse (const double& end_bpm, const double& end_pulse) const;
|
||||
double compute_c_func_minute (const double& end_bpm, const double& end_minute) const;
|
||||
|
||||
Timecode::BBT_Time legacy_bbt () { return _legacy_bbt; }
|
||||
|
||||
private:
|
||||
|
||||
framepos_t minute_to_frame (const double& time, const framecnt_t& frame_rate) const;
|
||||
double frame_to_minute (const framepos_t& frame, const framecnt_t& frame_rate) const;
|
||||
|
||||
/* tempo ramp functions. zero-based with time in minutes,
|
||||
* 'tick tempo' in ticks per minute and tempo in bpm.
|
||||
* time relative to section start.
|
||||
@@ -252,11 +258,11 @@ typedef std::list<MetricSection*> Metrics;
|
||||
class LIBARDOUR_API TempoMetric {
|
||||
public:
|
||||
TempoMetric (const Meter& m, const Tempo& t)
|
||||
: _meter (&m), _tempo (&t), _frame (0), _pulse (0.0) {}
|
||||
: _meter (&m), _tempo (&t), _minute (0.0), _pulse (0.0) {}
|
||||
|
||||
void set_tempo (const Tempo& t) { _tempo = &t; }
|
||||
void set_meter (const Meter& m) { _meter = &m; }
|
||||
void set_frame (framepos_t f) { _frame = f; }
|
||||
void set_minute (double m) { _minute = m; }
|
||||
void set_pulse (const double& p) { _pulse = p; }
|
||||
|
||||
void set_metric (const MetricSection* section) {
|
||||
@@ -268,19 +274,19 @@ class LIBARDOUR_API TempoMetric {
|
||||
set_tempo(*tempo);
|
||||
}
|
||||
|
||||
set_frame (section->frame());
|
||||
set_minute (section->minute());
|
||||
set_pulse (section->pulse());
|
||||
}
|
||||
|
||||
const Meter& meter() const { return *_meter; }
|
||||
const Tempo& tempo() const { return *_tempo; }
|
||||
framepos_t frame() const { return _frame; }
|
||||
double minute() const { return _minute; }
|
||||
const double& pulse() const { return _pulse; }
|
||||
|
||||
private:
|
||||
const Meter* _meter;
|
||||
const Tempo* _tempo;
|
||||
framepos_t _frame;
|
||||
double _minute;
|
||||
double _pulse;
|
||||
};
|
||||
|
||||
@@ -348,7 +354,7 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
|
||||
* @param where bbt position of new section
|
||||
* @param frame frame position of new section. ignored if pls == MusicTime
|
||||
*/
|
||||
MeterSection* add_meter (const Meter&, const double& beat, const Timecode::BBT_Time& where, const framepos_t& frame, PositionLockStyle pls);
|
||||
MeterSection* add_meter (const Meter&, const double& beat, const Timecode::BBT_Time& where, PositionLockStyle pls);
|
||||
|
||||
void remove_tempo (const TempoSection&, bool send_signal);
|
||||
void remove_meter (const MeterSection&, bool send_signal);
|
||||
@@ -356,8 +362,7 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
|
||||
void replace_tempo (const TempoSection&, const Tempo&, const double& pulse, const framepos_t& frame
|
||||
, TempoSection::Type type, PositionLockStyle pls);
|
||||
|
||||
void replace_meter (const MeterSection&, const Meter&, const Timecode::BBT_Time& where, const framepos_t& frame
|
||||
, PositionLockStyle pls);
|
||||
void replace_meter (const MeterSection&, const Meter&, const Timecode::BBT_Time& where, PositionLockStyle pls);
|
||||
|
||||
framepos_t round_to_bar (framepos_t frame, RoundMode dir);
|
||||
framepos_t round_to_beat (framepos_t frame, RoundMode dir);
|
||||
@@ -410,6 +415,7 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
|
||||
framepos_t frame_at_tempo (const Tempo& tempo) const;
|
||||
|
||||
Tempo tempo_at_beat (const double& beat) const;
|
||||
double beat_at_tempo (const Tempo& tempo) const;
|
||||
|
||||
const Meter& meter_at_frame (framepos_t) const;
|
||||
|
||||
@@ -454,6 +460,8 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
|
||||
double quarter_note_at_beat (const double beat);
|
||||
double beat_at_quarter_note (const double beat);
|
||||
|
||||
framecnt_t frames_between_quarter_notes (const double start, const double end);
|
||||
|
||||
void gui_move_tempo (TempoSection*, const framepos_t& frame, const int& sub_num);
|
||||
void gui_move_meter (MeterSection*, const framepos_t& frame);
|
||||
bool gui_change_tempo (TempoSection*, const Tempo& bpm);
|
||||
@@ -470,20 +478,23 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
|
||||
|
||||
private:
|
||||
|
||||
double beat_at_frame_locked (const Metrics& metrics, const framecnt_t& frame) const;
|
||||
framepos_t frame_at_beat_locked (const Metrics& metrics, const double& beat) const;
|
||||
double beat_at_minute_locked (const Metrics& metrics, const double& minute) const;
|
||||
double minute_at_beat_locked (const Metrics& metrics, const double& beat) const;
|
||||
|
||||
double pulse_at_beat_locked (const Metrics& metrics, const double& beat) const;
|
||||
double beat_at_pulse_locked (const Metrics& metrics, const double& pulse) const;
|
||||
|
||||
double pulse_at_frame_locked (const Metrics& metrics, const framepos_t& frame) const;
|
||||
framepos_t frame_at_pulse_locked (const Metrics& metrics, const double& pulse) const;
|
||||
double pulse_at_minute_locked (const Metrics& metrics, const double& minute) const;
|
||||
double minute_at_pulse_locked (const Metrics& metrics, const double& pulse) const;
|
||||
|
||||
Tempo tempo_at_frame_locked (const Metrics& metrics, const framepos_t& frame) const;
|
||||
framepos_t frame_at_tempo_locked (const Metrics& metrics, const Tempo& tempo) const;
|
||||
Tempo tempo_at_minute_locked (const Metrics& metrics, const double& minute) const;
|
||||
double minute_at_tempo_locked (const Metrics& metrics, const Tempo& tempo) const;
|
||||
|
||||
Timecode::BBT_Time bbt_at_frame_locked (const Metrics& metrics, const framepos_t& frame) const;
|
||||
framepos_t frame_at_bbt_locked (const Metrics& metrics, const Timecode::BBT_Time&) const;
|
||||
Tempo tempo_at_pulse_locked (const Metrics& metrics, const double& pulse) const;
|
||||
double pulse_at_tempo_locked (const Metrics& metrics, const Tempo& tempo) const;
|
||||
|
||||
Timecode::BBT_Time bbt_at_minute_locked (const Metrics& metrics, const double& minute) const;
|
||||
double minute_at_bbt_locked (const Metrics& metrics, const Timecode::BBT_Time&) const;
|
||||
|
||||
double beat_at_bbt_locked (const Metrics& metrics, const Timecode::BBT_Time& bbt) const ;
|
||||
Timecode::BBT_Time bbt_at_beat_locked (const Metrics& metrics, const double& beats) const;
|
||||
@@ -491,28 +502,34 @@ private:
|
||||
double pulse_at_bbt_locked (const Metrics& metrics, const Timecode::BBT_Time& bbt) const;
|
||||
Timecode::BBT_Time bbt_at_pulse_locked (const Metrics& metrics, const double& pulse) const;
|
||||
|
||||
framepos_t frame_at_quarter_note_locked (const Metrics& metrics, const double quarter_note) const;
|
||||
double quarter_note_at_frame_locked (const Metrics& metrics, const framepos_t frame) const;
|
||||
double minute_at_quarter_note_locked (const Metrics& metrics, const double quarter_note) const;
|
||||
double quarter_note_at_minute_locked (const Metrics& metrics, const double minute) const;
|
||||
|
||||
double quarter_note_at_beat_locked (const Metrics& metrics, const double beat) const;
|
||||
double beat_at_quarter_note_locked (const Metrics& metrics, const double beat) const;
|
||||
|
||||
const TempoSection& tempo_section_at_frame_locked (const Metrics& metrics, framepos_t frame) const;
|
||||
double minutes_between_quarter_notes_locked (const Metrics& metrics, const double start_qn, const double end_qn);
|
||||
|
||||
const TempoSection& tempo_section_at_minute_locked (const Metrics& metrics, double minute) const;
|
||||
const TempoSection& tempo_section_at_beat_locked (const Metrics& metrics, const double& beat) const;
|
||||
|
||||
const MeterSection& meter_section_at_frame_locked (const Metrics& metrics, framepos_t frame) const;
|
||||
const MeterSection& meter_section_at_minute_locked (const Metrics& metrics, double minute) const;
|
||||
const MeterSection& meter_section_at_beat_locked (const Metrics& metrics, const double& beat) const;
|
||||
|
||||
bool check_solved (const Metrics& metrics) const;
|
||||
bool set_active_tempos (const Metrics& metrics, const framepos_t& frame);
|
||||
|
||||
bool solve_map_frame (Metrics& metrics, TempoSection* section, const framepos_t& frame);
|
||||
bool solve_map_minute (Metrics& metrics, TempoSection* section, const double& minute);
|
||||
bool solve_map_pulse (Metrics& metrics, TempoSection* section, const double& pulse);
|
||||
bool solve_map_frame (Metrics& metrics, MeterSection* section, const framepos_t& frame);
|
||||
bool solve_map_minute (Metrics& metrics, MeterSection* section, const double& minute);
|
||||
bool solve_map_bbt (Metrics& metrics, MeterSection* section, const Timecode::BBT_Time& bbt);
|
||||
|
||||
double exact_beat_at_frame_locked (const Metrics& metrics, const framepos_t& frame, const int32_t sub_num);
|
||||
double exact_qn_at_frame_locked (const Metrics& metrics, const framepos_t& frame, const int32_t sub_num);
|
||||
|
||||
double minute_at_frame (const framepos_t frame) const;
|
||||
framepos_t frame_at_minute (const double minute) const;
|
||||
|
||||
friend class ::BBTTest;
|
||||
friend class ::FrameposPlusBeatsTest;
|
||||
friend class ::FrameposMinusBeatsTest;
|
||||
@@ -538,11 +555,10 @@ private:
|
||||
|
||||
void do_insert (MetricSection* section);
|
||||
|
||||
TempoSection* add_tempo_locked (const Tempo&, double pulse, framepos_t frame
|
||||
TempoSection* add_tempo_locked (const Tempo&, double pulse, double minute
|
||||
, TempoSection::Type type, PositionLockStyle pls, bool recompute, bool locked_to_meter = false);
|
||||
|
||||
MeterSection* add_meter_locked (const Meter&, double beat, const Timecode::BBT_Time& where, framepos_t frame
|
||||
, PositionLockStyle pls, bool recompute);
|
||||
MeterSection* add_meter_locked (const Meter&, double beat, const Timecode::BBT_Time& where, PositionLockStyle pls, bool recompute);
|
||||
|
||||
bool remove_tempo_locked (const TempoSection&);
|
||||
bool remove_meter_locked (const MeterSection&);
|
||||
|
||||
@@ -596,12 +596,24 @@ Region::set_position (framepos_t pos, int32_t sub_num)
|
||||
|
||||
if (position_lock_style() == AudioTime) {
|
||||
set_position_internal (pos, true, sub_num);
|
||||
if (_session.tempo_map().frame_at_beat (_beat) != _position) {
|
||||
std::cout << name ()
|
||||
<< " Region::set_position AudioTime position error!!! FRAME AT BEAT : " <<_session.tempo_map().frame_at_beat (_beat)
|
||||
<< " position : " << _position << " has playlist : " << (playlist() == 0) << std::endl;
|
||||
}
|
||||
} else {
|
||||
if (!_session.loading()) {
|
||||
_beat = _session.tempo_map().exact_beat_at_frame (pos, sub_num);
|
||||
}
|
||||
|
||||
/* will set pulse accordingly */
|
||||
set_position_internal (pos, false, sub_num);
|
||||
|
||||
if (_session.tempo_map().frame_at_beat (_beat) != _position) {
|
||||
std::cout << name ()
|
||||
<< " Region::set_position MusicTime position error!!! FRAME AT BEAT : " <<_session.tempo_map().frame_at_beat (_beat)
|
||||
<< " position : " << _position << " beat : " << _beat << " has playlist : " << (playlist() == 0) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/* do this even if the position is the same. this helps out
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -17,7 +17,7 @@ BBTTest::addTest ()
|
||||
Meter meter(4.0, 4.0);
|
||||
|
||||
/* no need to supply the frame for a new music-locked meter */
|
||||
map.add_meter (meter, 4.0, BBT_Time(2, 1, 0), 0, MusicTime);
|
||||
map.add_meter (meter, 4.0, BBT_Time(2, 1, 0), MusicTime);
|
||||
|
||||
/* add some good stuff here */
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ FrameposPlusBeatsTest::singleTempoTest ()
|
||||
Tempo tempo (bpm);
|
||||
Meter meter (4, 4);
|
||||
|
||||
map.replace_meter (map.first_meter(), meter, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
|
||||
map.replace_meter (map.first_meter(), meter, BBT_Time (1, 1, 0), AudioTime);
|
||||
map.replace_tempo (map.first_tempo(), tempo, 0.0, 0, TempoSection::Constant, AudioTime);
|
||||
|
||||
/* Add 1 beat to beat 3 of the first bar */
|
||||
@@ -41,7 +41,7 @@ FrameposPlusBeatsTest::doubleTempoTest ()
|
||||
|
||||
TempoMap map (sampling_rate);
|
||||
Meter meter (4, 4);
|
||||
map.replace_meter (map.first_meter(), meter, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
|
||||
map.replace_meter (map.first_meter(), meter, BBT_Time (1, 1, 0), AudioTime);
|
||||
|
||||
/*
|
||||
120bpm at bar 1, 240bpm at bar 4
|
||||
@@ -94,7 +94,7 @@ FrameposPlusBeatsTest::doubleTempoWithMeterTest ()
|
||||
|
||||
TempoMap map (sampling_rate);
|
||||
Meter meterA (4, 4);
|
||||
map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
|
||||
map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), AudioTime);
|
||||
|
||||
/*
|
||||
120bpm at bar 1, 240bpm at bar 4
|
||||
@@ -120,7 +120,7 @@ FrameposPlusBeatsTest::doubleTempoWithMeterTest ()
|
||||
Tempo tempoB (240);
|
||||
map.add_tempo (tempoB, 12.0 / tempoA.note_type(), 0, TempoSection::Constant, MusicTime);
|
||||
Meter meterB (3, 8);
|
||||
map.add_meter (meterB, 12.0, BBT_Time (4, 1, 0), 0, MusicTime);
|
||||
map.add_meter (meterB, 12.0, BBT_Time (4, 1, 0), MusicTime);
|
||||
|
||||
/* Now some tests */
|
||||
|
||||
@@ -149,7 +149,7 @@ FrameposPlusBeatsTest::doubleTempoWithComplexMeterTest ()
|
||||
|
||||
TempoMap map (sampling_rate);
|
||||
Meter meterA (3, 4);
|
||||
map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
|
||||
map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), AudioTime);
|
||||
|
||||
/*
|
||||
120bpm at bar 1, 240bpm at bar 4
|
||||
@@ -177,7 +177,7 @@ FrameposPlusBeatsTest::doubleTempoWithComplexMeterTest ()
|
||||
Tempo tempoB (240, 4.0);
|
||||
map.add_tempo (tempoB, 12.0 / 4.0, 0, TempoSection::Constant, MusicTime);
|
||||
Meter meterB (5, 8);
|
||||
map.add_meter (meterB, 9.0, BBT_Time (4, 1, 0), 0, MusicTime);
|
||||
map.add_meter (meterB, 9.0, BBT_Time (4, 1, 0), MusicTime);
|
||||
/* Now some tests */
|
||||
|
||||
/* Add 1 beat to 1|2 */
|
||||
|
||||
@@ -20,7 +20,7 @@ FramewalkToBeatsTest::singleTempoTest ()
|
||||
Tempo tempo (bpm);
|
||||
Meter meter (4, 4);
|
||||
|
||||
map.replace_meter (map.meter_section_at_frame (0), meter, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
|
||||
map.replace_meter (map.meter_section_at_frame (0), meter, BBT_Time (1, 1, 0), AudioTime);
|
||||
map.replace_tempo (map.tempo_section_at_frame (0), tempo, 0.0, 0, TempoSection::Constant, AudioTime);
|
||||
|
||||
/* Walk 1 beats-worth of frames from beat 3 */
|
||||
@@ -47,7 +47,7 @@ FramewalkToBeatsTest::doubleTempoTest ()
|
||||
|
||||
TempoMap map (sampling_rate);
|
||||
Meter meter (4, 4);
|
||||
map.replace_meter (map.meter_section_at_frame (0), meter, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
|
||||
map.replace_meter (map.meter_section_at_frame (0), meter, BBT_Time (1, 1, 0), AudioTime);
|
||||
|
||||
/*
|
||||
120bpm at bar 1, 240bpm at bar 4
|
||||
@@ -104,7 +104,7 @@ FramewalkToBeatsTest::tripleTempoTest ()
|
||||
|
||||
TempoMap map (sampling_rate);
|
||||
Meter meter (4, 4);
|
||||
map.replace_meter (map.meter_section_at_frame (0), meter, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
|
||||
map.replace_meter (map.meter_section_at_frame (0), meter, BBT_Time (1, 1, 0), AudioTime);
|
||||
|
||||
/*
|
||||
120bpm at bar 1, 240bpm at bar 2, 160bpm at bar 3
|
||||
@@ -150,7 +150,7 @@ FramewalkToBeatsTest::singleTempoMeterTest ()
|
||||
Tempo tempo (bpm);
|
||||
Meter meter (7, 8);
|
||||
|
||||
map.replace_meter (map.meter_section_at_frame (0), meter, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
|
||||
map.replace_meter (map.meter_section_at_frame (0), meter, BBT_Time (1, 1, 0), AudioTime);
|
||||
map.replace_tempo (map.tempo_section_at_frame (0), tempo, 0.0, 0, TempoSection::Constant, AudioTime);
|
||||
|
||||
/* Walk 1 qn beats-worth of frames from beat 3 */
|
||||
|
||||
@@ -49,7 +49,7 @@ class TestSlaveSessionProxy : public ISlaveSessionProxy {
|
||||
{
|
||||
_tempo_map = new TempoMap (FRAME_RATE);
|
||||
_tempo_map->add_tempo (tempo, 0.0, 0, TempoSection::Constant, AudioTime);
|
||||
_tempo_map->add_meter (meter, 0.0, Timecode::BBT_Time(1, 1, 0), 0, AudioTime);
|
||||
_tempo_map->add_meter (meter, 0.0, Timecode::BBT_Time(1, 1, 0), AudioTime);
|
||||
}
|
||||
|
||||
// Controlling the mock object
|
||||
|
||||
@@ -8,13 +8,13 @@ using namespace ARDOUR;
|
||||
using namespace Timecode;
|
||||
|
||||
void
|
||||
TempoTest::recomputeMapTest ()
|
||||
TempoTest::recomputeMapTest48 ()
|
||||
{
|
||||
int const sampling_rate = 48000;
|
||||
|
||||
TempoMap map (sampling_rate);
|
||||
Meter meterA (4, 4);
|
||||
map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
|
||||
map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), AudioTime);
|
||||
|
||||
/*
|
||||
120bpm at bar 1, 240bpm at bar 4
|
||||
@@ -40,38 +40,303 @@ TempoTest::recomputeMapTest ()
|
||||
Tempo tempoB (240);
|
||||
map.add_tempo (tempoB, 3.0, 0, TempoSection::Constant, MusicTime);
|
||||
Meter meterB (3, 4);
|
||||
map.add_meter (meterB, 12.0, BBT_Time (4, 1, 0), 0, MusicTime);
|
||||
|
||||
map.add_meter (meterB, 12.0, BBT_Time (4, 1, 0), MusicTime);
|
||||
//map.dump (map._metrics, std::cout);
|
||||
list<MetricSection*>::iterator i = map._metrics.begin();
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (0), (*i)->frame ());
|
||||
i = map._metrics.end();
|
||||
--i;
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (288e3), (*i)->frame ());
|
||||
|
||||
/* check the tempo section for ecpected result (no map) */
|
||||
/* check the tempo section for expected result (no map) */
|
||||
const TempoSection& tsa (map.tempo_section_at_frame (0));
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (288e3), tsa.frame_at_pulse (3.0, sampling_rate));
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (144e3), tsa.frame_at_pulse (1.5, sampling_rate));
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (96e3), tsa.frame_at_pulse (1.0, sampling_rate));
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (288e3), tsa.frame_at_pulse (3.0));
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (144e3), tsa.frame_at_pulse (1.5));
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (96e3), tsa.frame_at_pulse (1.0));
|
||||
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (3.0, tsa.pulse_at_frame (288e3, sampling_rate), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.5, tsa.pulse_at_frame (144e3, sampling_rate), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, tsa.pulse_at_frame (96e3, sampling_rate), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (3.0, tsa.pulse_at_frame (288e3), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.5, tsa.pulse_at_frame (144e3), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, tsa.pulse_at_frame (96e3), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, tsa.minute_at_frame (60.0 * sampling_rate), 1e-17);
|
||||
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (0.1, tsa.minute_at_tempo (240.0, 3.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (0.1, tsa.minute_at_tempo (240.0, 3.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (0.1, tsa.minute_at_pulse (3.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (3.0, tsa.pulse_at_minute (0.1), 1e-17);
|
||||
|
||||
/* do the same via the map */
|
||||
|
||||
/* pulse */
|
||||
|
||||
/* pulse - frame*/
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (288e3), map.frame_at_pulse (3.0));
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (144e3), map.frame_at_pulse (1.5));
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (96e3), map.frame_at_pulse (1.0));
|
||||
|
||||
/* frame - pulse*/
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (3.0, map.pulse_at_frame (288e3), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.5, map.pulse_at_frame (144e3), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, map.pulse_at_frame (96e3), 1e-17);
|
||||
|
||||
/* pulse - internal minute based interface */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (0.1, map.minute_at_pulse_locked (map._metrics, 3.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (3.0, map.pulse_at_minute_locked (map._metrics, 0.1), 1e-17);
|
||||
|
||||
/* tempo */
|
||||
|
||||
/* tempo - frame */
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (288e3), map.frame_at_tempo (240.0));
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (240.0, map.tempo_at_frame (288e3).beats_per_minute(), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (120.0, map.tempo_at_frame (288e3 - 1).beats_per_minute(), 1e-17);
|
||||
|
||||
/* tempo - bbt (meter based) beat */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (240.0, map.tempo_at_beat (24.0).beats_per_minute(), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (240.0, map.tempo_at_beat (12.0).beats_per_minute(), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (120.0, map.tempo_at_beat (6.0).beats_per_minute(), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (120.0, map.tempo_at_beat (0.0).beats_per_minute(), 1e-17);
|
||||
/*bbt (meter based) beat - tempo */
|
||||
/* this is expected for constant tempi */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (12.0, map.beat_at_tempo (240.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (0.0, map.beat_at_tempo (120.0), 1e-17);
|
||||
|
||||
/* tempo - internal minute interface */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (240.0, map.tempo_at_minute_locked (map._metrics, 0.1).beats_per_minute(), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (0.1, map.minute_at_tempo_locked (map._metrics, tempoB), 1e-17);
|
||||
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (240.0, map.tempo_at_pulse_locked (map._metrics, 3.0).beats_per_minute(), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (3.0, map.pulse_at_tempo_locked (map._metrics, tempoB), 1e-17);
|
||||
}
|
||||
|
||||
void
|
||||
TempoTest::recomputeMapTest44 ()
|
||||
{
|
||||
int const sampling_rate = 44100;
|
||||
|
||||
TempoMap map (sampling_rate);
|
||||
Meter meterA (4, 4);
|
||||
map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), AudioTime);
|
||||
|
||||
/*
|
||||
120bpm at bar 1, 240bpm at bar 4
|
||||
|
||||
120bpm = 24e3 samples per beat
|
||||
240bpm = 12e3 samples per beat
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
|
||||
120bpm 240bpm
|
||||
0 beats 12 beats
|
||||
0 frames 288e3 frames
|
||||
0 pulses 3 pulses
|
||||
| | | | |
|
||||
| 1.1 1.2 1.3 1.4 | 2.1 2.2 2.3.2.4 | 3.1 3.2 3.3 3.4 | 4.1 4.2 4.3 |
|
||||
|
||||
*/
|
||||
|
||||
Tempo tempoA (120);
|
||||
map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Constant, AudioTime);
|
||||
Tempo tempoB (240);
|
||||
map.add_tempo (tempoB, 3.0, 0, TempoSection::Constant, MusicTime);
|
||||
Meter meterB (3, 4);
|
||||
map.add_meter (meterB, 12.0, BBT_Time (4, 1, 0), MusicTime);
|
||||
|
||||
list<MetricSection*>::iterator i = map._metrics.begin();
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (0), (*i)->frame ());
|
||||
i = map._metrics.end();
|
||||
--i;
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (288e3), (*i)->frame ());
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (264600), (*i)->frame ());
|
||||
|
||||
/* check the tempo section for expected result (no map) */
|
||||
const TempoSection& tsa (map.tempo_section_at_frame (0));
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (264600), tsa.frame_at_pulse (3.0));
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (132300), tsa.frame_at_pulse (1.5));
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (88200), tsa.frame_at_pulse (1.0));
|
||||
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (3.0, tsa.pulse_at_frame (264600), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.5, tsa.pulse_at_frame (132300), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, tsa.pulse_at_frame (88200), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, tsa.minute_at_frame (60.0 * sampling_rate), 1e-17);
|
||||
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (0.1, tsa.minute_at_tempo (240.0, 3.0), 1e-17);
|
||||
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (0.1, tsa.minute_at_tempo (240.0, 3.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (0.1, tsa.minute_at_pulse (3.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (3.0, tsa.pulse_at_minute (0.1), 1e-17);
|
||||
|
||||
/* do the same via the map */
|
||||
|
||||
/* pulse */
|
||||
|
||||
/* pulse - frame*/
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (264600), map.frame_at_pulse (3.0));
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (132300), map.frame_at_pulse (1.5));
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (88200), map.frame_at_pulse (1.0));
|
||||
|
||||
/* frame - pulse*/
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (3.0, map.pulse_at_frame (264600), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.5, map.pulse_at_frame (132300), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, map.pulse_at_frame (88200), 1e-17);
|
||||
|
||||
/* pulse - internal minute based interface */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (0.1, map.minute_at_pulse_locked (map._metrics, 3.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (3.0, map.pulse_at_minute_locked (map._metrics, 0.1), 1e-17);
|
||||
|
||||
/* tempo */
|
||||
|
||||
/* tempo - frame */
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (264600), map.frame_at_tempo (tempoB));
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (240.0, map.tempo_at_frame (264600).beats_per_minute(), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (120.0, map.tempo_at_frame (264600 - 1).beats_per_minute(), 1e-17);
|
||||
|
||||
/* tempo - meter-based beat (bbt beat) */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (240.0, map.tempo_at_beat (24.0).beats_per_minute(), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (240.0, map.tempo_at_beat (12.0).beats_per_minute(), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (120.0, map.tempo_at_beat (6.0).beats_per_minute(), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (120.0, map.tempo_at_beat (0.0).beats_per_minute(), 1e-17);
|
||||
/* meter-based beat (bbt beat) - tempo */
|
||||
/* this is expected for constant tempi */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (12.0, map.beat_at_tempo (240.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (0.0, map.beat_at_tempo (120.0), 1e-17);
|
||||
|
||||
/* tempo - internal minute interface */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (240.0, map.tempo_at_minute_locked (map._metrics, 0.1).beats_per_minute(), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (0.1, map.minute_at_tempo_locked (map._metrics, tempoB), 1e-17);
|
||||
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (240.0, map.tempo_at_pulse_locked (map._metrics, 3.0).beats_per_minute(), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (3.0, map.pulse_at_tempo_locked (map._metrics, tempoB), 1e-17);
|
||||
}
|
||||
|
||||
void
|
||||
TempoTest::qnDistanceTestConstant ()
|
||||
{
|
||||
int const sampling_rate = 44100;
|
||||
|
||||
TempoMap map (sampling_rate);
|
||||
Meter meterA (4, 4);
|
||||
map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), AudioTime);
|
||||
|
||||
/*
|
||||
120bpm at bar 1, 240bpm at bar 4
|
||||
|
||||
120bpm = 24e3 samples per beat
|
||||
240bpm = 12e3 samples per beat
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
|
||||
120bpm 240bpm
|
||||
0 beats 12 beats
|
||||
0 frames 288e3 frames
|
||||
0 pulses 3 pulses
|
||||
| | | | |
|
||||
| 1.1 1.2 1.3 1.4 | 2.1 2.2 2.3.2.4 | 3.1 3.2 3.3 3.4 | 4.1 4.2 4.3 |
|
||||
|
||||
*/
|
||||
|
||||
Tempo tempoA (120.0);
|
||||
map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Constant, AudioTime);
|
||||
Tempo tempoB (240.0);
|
||||
map.add_tempo (tempoB, 3.0, 0, TempoSection::Constant, MusicTime);
|
||||
|
||||
Tempo tempoC (130.3);
|
||||
map.add_tempo (tempoC, 6.0, 0, TempoSection::Constant, MusicTime);
|
||||
Tempo tempoD (90.4);
|
||||
map.add_tempo (tempoD, 9.0, 0, TempoSection::Constant, MusicTime);
|
||||
Tempo tempoE (110.6);
|
||||
map.add_tempo (tempoE, 12.0, 0, TempoSection::Constant, MusicTime);
|
||||
Tempo tempoF (123.7);
|
||||
map.add_tempo (tempoF, 15.0, 0, TempoSection::Constant, MusicTime);
|
||||
Meter meterB (3, 4);
|
||||
map.add_meter (meterB, 12.0, BBT_Time (4, 1, 0), MusicTime);
|
||||
|
||||
list<MetricSection*>::iterator i = map._metrics.begin();
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (0), (*i)->frame ());
|
||||
i = map._metrics.end();
|
||||
--i;
|
||||
CPPUNIT_ASSERT_EQUAL ((*i)->frame(), map.frames_between_quarter_notes (0.0, 60.0));
|
||||
|
||||
/* distance from beat 12.0 to 0.0 should be 6.0 seconds */
|
||||
CPPUNIT_ASSERT_EQUAL (framecnt_t (264600), map.frames_between_quarter_notes (0.0, 12.0));
|
||||
CPPUNIT_ASSERT_EQUAL (framecnt_t (396900), map.frames_between_quarter_notes (0.0, 24.0));
|
||||
CPPUNIT_ASSERT_EQUAL (framecnt_t (-264600), map.frames_between_quarter_notes (12.0, 0.0));
|
||||
CPPUNIT_ASSERT_EQUAL (framecnt_t (-396900), map.frames_between_quarter_notes (24.0, 0.0));
|
||||
}
|
||||
void
|
||||
TempoTest::qnDistanceTestRamp ()
|
||||
{
|
||||
int const sampling_rate = 44100;
|
||||
|
||||
TempoMap map (sampling_rate);
|
||||
Meter meterA (4, 4);
|
||||
map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), AudioTime);
|
||||
|
||||
/*
|
||||
120bpm at bar 1, 240bpm at bar 4
|
||||
|
||||
120bpm = 24e3 samples per beat
|
||||
240bpm = 12e3 samples per beat
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
|
||||
120bpm 240bpm
|
||||
0 beats 12 beats
|
||||
0 frames 288e3 frames
|
||||
0 pulses 3 pulses
|
||||
| | | | |
|
||||
| 1.1 1.2 1.3 1.4 | 2.1 2.2 2.3.2.4 | 3.1 3.2 3.3 3.4 | 4.1 4.2 4.3 |
|
||||
|
||||
*/
|
||||
|
||||
Tempo tempoA (120.2);
|
||||
map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Ramp, AudioTime);
|
||||
Tempo tempoB (240.5);
|
||||
map.add_tempo (tempoB, 3.0, 0, TempoSection::Ramp, MusicTime);
|
||||
|
||||
Tempo tempoC (130.1);
|
||||
map.add_tempo (tempoC, 0.0, 6 * sampling_rate, TempoSection::Ramp, AudioTime);
|
||||
Tempo tempoD (90.3);
|
||||
map.add_tempo (tempoD, 9.0, 0, TempoSection::Ramp, MusicTime);
|
||||
Tempo tempoE (110.7);
|
||||
map.add_tempo (tempoE, 12.0, 0, TempoSection::Ramp, MusicTime);
|
||||
Tempo tempoF (123.9);
|
||||
map.add_tempo (tempoF, 15.0, 0, TempoSection::Ramp, MusicTime);
|
||||
Tempo tempoG (111.8);
|
||||
map.add_tempo (tempoG, 0.0, (framepos_t) 2 * 60 * sampling_rate, TempoSection::Ramp, AudioTime);
|
||||
Meter meterB (3, 4);
|
||||
map.add_meter (meterB, 4.0, BBT_Time (2, 1, 0), AudioTime);
|
||||
map.recompute_map (map._metrics, 1);
|
||||
|
||||
list<MetricSection*>::iterator i = map._metrics.begin();
|
||||
CPPUNIT_ASSERT_EQUAL (framepos_t (0), (*i)->frame ());
|
||||
i = map._metrics.end();
|
||||
--i;
|
||||
/* tempoG */
|
||||
CPPUNIT_ASSERT_EQUAL ((*i)->frame(), map.frames_between_quarter_notes (0.0, (*i)->pulse() * 4.0));
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL ((*i)->minute(), map.minutes_between_quarter_notes_locked (map._metrics, 0.0, (*i)->pulse() * 4.0), 1e-17);
|
||||
|
||||
--i;
|
||||
CPPUNIT_ASSERT_EQUAL ((*i)->frame(), map.frames_between_quarter_notes (0.0, 60.0));
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL ((*i)->minute(), map.minutes_between_quarter_notes_locked (map._metrics, 0.0, 60.0), 1e-17);
|
||||
|
||||
--i;
|
||||
/* tempoE */
|
||||
CPPUNIT_ASSERT_EQUAL ((*i)->frame(), map.frames_between_quarter_notes (0.0, 48.0));
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL ((*i)->minute(), map.minutes_between_quarter_notes_locked (map._metrics, 0.0, 48.0), 1e-17);
|
||||
|
||||
--i;
|
||||
CPPUNIT_ASSERT_EQUAL ((*i)->frame(), map.frames_between_quarter_notes (0.0, 36.0));
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL ((*i)->minute(), map.minutes_between_quarter_notes_locked (map._metrics, 0.0, 36.0), 1e-17);
|
||||
|
||||
--i;
|
||||
/* tempoC */
|
||||
CPPUNIT_ASSERT_EQUAL (framecnt_t (6 * sampling_rate), map.frames_between_quarter_notes (0.0, (*i)->pulse() * 4.0));
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (0.1, map.minutes_between_quarter_notes_locked (map._metrics, 0.0, (*i)->pulse() * 4.0), 1e-17);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
@@ -85,7 +350,7 @@ TempoTest::rampTest48 ()
|
||||
Tempo tempoB (217.0, 4.0);
|
||||
map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Ramp, AudioTime);
|
||||
map.add_tempo (tempoB, 0.0, (framepos_t) 60 * sampling_rate, TempoSection::Ramp, AudioTime);
|
||||
map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
|
||||
map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), AudioTime);
|
||||
|
||||
/*
|
||||
|
||||
@@ -109,25 +374,31 @@ TempoTest::rampTest48 ()
|
||||
TempoSection& tA = map.first_tempo();
|
||||
const TempoSection& tB = map.tempo_section_at_frame ((framepos_t) 60 * sampling_rate);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL ((framepos_t) 60 * sampling_rate, tA.frame_at_tempo (tB.beats_per_minute(), 300.0, sampling_rate));
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (217.0, tA.tempo_at_frame ((framepos_t) 60 * sampling_rate, sampling_rate), 1e-17);
|
||||
CPPUNIT_ASSERT_EQUAL ((framepos_t) 60 * sampling_rate, tA.frame_at_pulse (tB.pulse(), sampling_rate));
|
||||
/* note 1e-14 here. (expm1) */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (tB.pulse(), tA.pulse_at_frame ((framepos_t) 60 * sampling_rate, sampling_rate), 1e-14);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, tA.minute_at_tempo (tB.beats_per_minute(), 300.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (217.0, tA.tempo_at_minute (1.0), 1e-17);
|
||||
CPPUNIT_ASSERT_EQUAL ((framepos_t) 60 * sampling_rate, tA.frame_at_pulse (tB.pulse()));
|
||||
|
||||
/* note 1e-14 here. pulse is two derivatives away from time */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (tB.pulse(), tA.pulse_at_frame ((framepos_t) 60 * sampling_rate), 1e-14);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (tB.pulse(), tA.pulse_at_minute (1.0), 1e-14);
|
||||
|
||||
/* note 1e-17 here. tempo is one derivative away from pulse, so we can get the same stuff with more precision */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (tB.pulse(), tA.pulse_at_tempo (217.0, 1.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, tA.minute_at_tempo (217.0, tB.pulse()), 1e-17);
|
||||
|
||||
/* self-check tempo at pulse @ 125 bpm. */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (125.0, tA.tempo_at_pulse (tA.pulse_at_tempo (125.0, 0, sampling_rate)), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (125.0, tA.tempo_at_pulse (tA.pulse_at_tempo (125.0, 0)), 1e-17);
|
||||
|
||||
/* check that tB's pulse is what tA thinks it should be */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (tB.pulse(), tA.pulse_at_tempo (217.0, 0, sampling_rate), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (tB.pulse(), tA.pulse_at_tempo (217.0, 0), 1e-17);
|
||||
|
||||
/* check that the tempo at the halfway mark (in pulses) is half the tempo delta.*/
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (147.0, tA.tempo_at_pulse (tB.pulse() / 2.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL ((tB.pulse() - tA.pulse()) / 2.0, tA.pulse_at_tempo (147.0, 0, sampling_rate), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL ((tB.pulse() - tA.pulse()) / 2.0, tA.pulse_at_tempo (147.0, 0), 1e-17);
|
||||
|
||||
/* self-check frame at pulse 20 seconds in. */
|
||||
const framepos_t target = 20 * sampling_rate;
|
||||
const framepos_t result = tA.frame_at_pulse (tA.pulse_at_frame (target, sampling_rate), sampling_rate);
|
||||
const framepos_t result = tA.frame_at_pulse (tA.pulse_at_frame (target));
|
||||
CPPUNIT_ASSERT_EQUAL (target, result);
|
||||
}
|
||||
|
||||
@@ -142,7 +413,7 @@ TempoTest::rampTest44 ()
|
||||
Tempo tempoB (217.0, 4.0);
|
||||
map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Ramp, AudioTime);
|
||||
map.add_tempo (tempoB, 0.0, (framepos_t) 60 * sampling_rate, TempoSection::Ramp, AudioTime);
|
||||
map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
|
||||
map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), AudioTime);
|
||||
|
||||
/*
|
||||
|
||||
@@ -166,24 +437,32 @@ TempoTest::rampTest44 ()
|
||||
TempoSection& tA = map.first_tempo();
|
||||
const TempoSection& tB = map.tempo_section_at_frame ((framepos_t) 60 * sampling_rate);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL ((framepos_t) 60 * sampling_rate, tA.frame_at_tempo (tB.beats_per_minute(), 300.0, sampling_rate));
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (217.0, tA.tempo_at_frame ((framepos_t) 60 * sampling_rate, sampling_rate), 1e-17);
|
||||
CPPUNIT_ASSERT_EQUAL ((framepos_t) 60 * sampling_rate, tA.frame_at_pulse (tB.pulse(), sampling_rate));
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (tB.pulse(), tA.pulse_at_frame ((framepos_t) 60 * sampling_rate, sampling_rate), 1e-14);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, tA.minute_at_tempo (tB.beats_per_minute(), 300.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (217.0, tA.tempo_at_minute (1.0), 1e-17);
|
||||
CPPUNIT_ASSERT_EQUAL ((framepos_t) 60 * sampling_rate, tA.frame_at_pulse (tB.pulse()));
|
||||
|
||||
/* note 1e-14 here. pulse is two derivatives away from time */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (tB.pulse(), tA.pulse_at_frame ((framepos_t) 60 * sampling_rate), 1e-14);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (tB.pulse(), tA.pulse_at_minute (1.0), 1e-14);
|
||||
|
||||
/* note 1e-17 here. tempo is one derivative away from pulse, so we can get the same stuff with more precision */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (tB.pulse(), tA.pulse_at_tempo (217.0, 1.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, tA.minute_at_tempo (217.0, tB.pulse()), 1e-17);
|
||||
|
||||
|
||||
/* self-check tempo at pulse @ 125 bpm. */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (125.0, tA.tempo_at_pulse (tA.pulse_at_tempo (125.0, 0, sampling_rate)), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (125.0, tA.tempo_at_pulse (tA.pulse_at_tempo (125.0, 0)), 1e-17);
|
||||
|
||||
/* check that tB's pulse is what tA thinks it should be */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (tB.pulse(), tA.pulse_at_tempo (217.0, 0, sampling_rate), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (tB.pulse(), tA.pulse_at_tempo (217.0, 0), 1e-17);
|
||||
|
||||
/* check that the tempo at the halfway mark (in pulses) is half the tempo delta.*/
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (147.0, tA.tempo_at_pulse (tB.pulse() / 2.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL ((tB.pulse() - tA.pulse()) / 2.0, tA.pulse_at_tempo (147.0, 0, sampling_rate), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL ((tB.pulse() - tA.pulse()) / 2.0, tA.pulse_at_tempo (147.0, 0), 1e-17);
|
||||
|
||||
/* self-check frame at pulse 20 seconds in. */
|
||||
const framepos_t target = 20 * sampling_rate;
|
||||
const framepos_t result = tA.frame_at_pulse (tA.pulse_at_frame (target, sampling_rate), sampling_rate);
|
||||
const framepos_t result = tA.frame_at_pulse (tA.pulse_at_frame (target));
|
||||
CPPUNIT_ASSERT_EQUAL (target, result);
|
||||
}
|
||||
|
||||
@@ -198,7 +477,7 @@ TempoTest::tempoAtPulseTest ()
|
||||
Tempo tempoB (160.0, 3.0);
|
||||
Tempo tempoC (123.0, 4.0);
|
||||
|
||||
map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), (framepos_t) 0, AudioTime);
|
||||
map.replace_meter (map.first_meter(), meterA, BBT_Time (1, 1, 0), AudioTime);
|
||||
map.replace_tempo (map.first_tempo(), tempoA, 0.0, 0, TempoSection::Ramp, AudioTime);
|
||||
|
||||
map.add_tempo (tempoB, 20.0, 0, TempoSection::Ramp, MusicTime);
|
||||
@@ -233,18 +512,27 @@ TempoTest::tempoAtPulseTest ()
|
||||
|
||||
/* check that the tempo at the halfway mark (in pulses) is half the tempo delta.*/
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (((80.0 - 160.0) / 2.0) + 160.0, tA->tempo_at_pulse (10.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (20.0 / 2.0, tA->pulse_at_tempo (120, 0, sampling_rate), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (20.0 / 2.0, tA->pulse_at_tempo (120, 0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (((160.0 - 123.0) / 2.0) + 123.0, tB->tempo_at_pulse (25.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (((20.0 - 30.0) / 2.0) + 30.0, tB->pulse_at_tempo (141.5, 0, sampling_rate), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (((20.0 - 30.0) / 2.0) + 30.0, tB->pulse_at_tempo (141.5, 0), 1e-17);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL (tB->frame(), tA->frame_at_pulse (20.0, sampling_rate));
|
||||
CPPUNIT_ASSERT_EQUAL (tC->frame(), tB->frame_at_pulse (30.0, sampling_rate));
|
||||
CPPUNIT_ASSERT_EQUAL (tB->frame(), tA->frame_at_pulse (20.0));
|
||||
CPPUNIT_ASSERT_EQUAL (tC->frame(), tB->frame_at_pulse (30.0));
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL (tB->frame(), tA->frame_at_tempo (160.0, 20.0, sampling_rate));
|
||||
CPPUNIT_ASSERT_EQUAL (tC->frame(), tB->frame_at_tempo (123.0, 30.0, sampling_rate));
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (tB->minute(), tA->minute_at_tempo (160.0, 20.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (tC->minute(), tB->minute_at_tempo (123.0, 30.0), 1e-17);
|
||||
|
||||
/* self-check tempo at pulse @ 125 bpm. */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (125.0, tA->tempo_at_pulse (tA->pulse_at_tempo (125.0, 0, sampling_rate)), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (125.0, tA->tempo_at_pulse (tA->pulse_at_tempo (125.0, 0)), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (160.0, tA->tempo_at_pulse (20.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (123.0, tB->tempo_at_pulse (30.0), 1e-17);
|
||||
/* test minute based measurements */
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (tB->minute(), tA->minute_at_pulse (20.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (tC->minute(), tB->minute_at_pulse (30.0), 1e-17);
|
||||
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (tB->minute(), tA->minute_at_tempo (160.0, 20.0), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (tC->minute(), tB->minute_at_tempo (123.0, 30.0), 1e-17);
|
||||
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (160.0, tA->tempo_at_minute (tB->minute()), 1e-17);
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL (123.0, tB->tempo_at_minute (tC->minute()), 1e-17);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
class TempoTest : public CppUnit::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE (TempoTest);
|
||||
CPPUNIT_TEST (recomputeMapTest);
|
||||
CPPUNIT_TEST (recomputeMapTest48);
|
||||
CPPUNIT_TEST (recomputeMapTest44);
|
||||
CPPUNIT_TEST (qnDistanceTestConstant);
|
||||
CPPUNIT_TEST (qnDistanceTestRamp);
|
||||
CPPUNIT_TEST (rampTest48);
|
||||
CPPUNIT_TEST (rampTest44);
|
||||
CPPUNIT_TEST (tempoAtPulseTest);
|
||||
@@ -16,6 +19,10 @@ public:
|
||||
void tearDown () {}
|
||||
|
||||
void recomputeMapTest ();
|
||||
void recomputeMapTest44 ();
|
||||
void recomputeMapTest48 ();
|
||||
void qnDistanceTestConstant ();
|
||||
void qnDistanceTestRamp ();
|
||||
void rampTest48 ();
|
||||
void rampTest44 ();
|
||||
void tempoAtPulseTest();
|
||||
|
||||
Reference in New Issue
Block a user