Tidy up tempo.h and add some documentation.

Fix some const violating casts.
No functional changes.

git-svn-id: svn://localhost/ardour2/branches/3.0@13512 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
David Robillard 2012-11-16 22:56:47 +00:00
parent 6b6ef35f3e
commit dd78c6ed71
2 changed files with 78 additions and 72 deletions

View file

@ -34,17 +34,17 @@
#include "ardour/ardour.h" #include "ardour/ardour.h"
class XMLNode;
class BBTTest; class BBTTest;
class FrameposPlusBeatsTest; class FrameposPlusBeatsTest;
class TempoTest; class TempoTest;
class XMLNode;
namespace ARDOUR { namespace ARDOUR {
class Meter; class Meter;
class TempoMap; class TempoMap;
/** Tempo, the speed at which musical time progresses (BPM). */
class Tempo { class Tempo {
public: public:
Tempo (double bpm, double type=4.0) // defaulting to quarter note Tempo (double bpm, double type=4.0) // defaulting to quarter note
@ -52,13 +52,16 @@ class Tempo {
double beats_per_minute () const { return _beats_per_minute;} double beats_per_minute () const { return _beats_per_minute;}
double note_type () const { return _note_type;} double note_type () const { return _note_type;}
double frames_per_beat (framecnt_t sr) const; double frames_per_beat (framecnt_t sr) const {
return (60.0 * sr) / _beats_per_minute;
}
protected: protected:
double _beats_per_minute; double _beats_per_minute;
double _note_type; double _note_type;
}; };
/** Meter, or time signature (beats per bar, and which note type is a beat). */
class Meter { class Meter {
public: public:
Meter (double dpb, double bt) Meter (double dpb, double bt)
@ -83,6 +86,7 @@ class Meter {
double _note_type; double _note_type;
}; };
/** A section of timeline with a certain Tempo or Meter. */
class MetricSection { class MetricSection {
public: public:
MetricSection (const Timecode::BBT_Time& start) MetricSection (const Timecode::BBT_Time& start)
@ -118,6 +122,7 @@ class MetricSection {
bool _movable; bool _movable;
}; };
/** A section of timeline with a certain Meter. */
class MeterSection : public MetricSection, public Meter { class MeterSection : public MetricSection, public Meter {
public: public:
MeterSection (const Timecode::BBT_Time& start, double bpb, double note_type) MeterSection (const Timecode::BBT_Time& start, double bpb, double note_type)
@ -131,6 +136,7 @@ class MeterSection : public MetricSection, public Meter {
XMLNode& get_state() const; XMLNode& get_state() const;
}; };
/** A section of timeline with a certain Tempo. */
class TempoSection : public MetricSection, public Tempo { class TempoSection : public MetricSection, public Tempo {
public: public:
TempoSection (const Timecode::BBT_Time& start, double qpm, double note_type) TempoSection (const Timecode::BBT_Time& start, double qpm, double note_type)
@ -161,12 +167,13 @@ class TempoSection : public MetricSection, public Tempo {
typedef std::list<MetricSection*> Metrics; typedef std::list<MetricSection*> Metrics;
/** Helper class that we use to be able to keep track of which /** Helper class to keep track of the Meter *AND* Tempo in effect
meter *AND* tempo are in effect at a given point in time. at a given point in time.
*/ */
class TempoMetric { class TempoMetric {
public: public:
TempoMetric (const Meter& m, const Tempo& t) : _meter (&m), _tempo (&t), _frame (0) {} TempoMetric (const Meter& m, const Tempo& t)
: _meter (&m), _tempo (&t), _frame (0) {}
void set_tempo (const Tempo& t) { _tempo = &t; } void set_tempo (const Tempo& t) { _tempo = &t; }
void set_meter (const Meter& m) { _meter = &m; } void set_meter (const Meter& m) { _meter = &m; }
@ -236,6 +243,7 @@ class TempoMap : public PBD::StatefulDestructible
*/ */
void bbt_time (framepos_t when, Timecode::BBT_Time&); void bbt_time (framepos_t when, Timecode::BBT_Time&);
/* realtime safe variant of ::bbt_time(), will throw /* realtime safe variant of ::bbt_time(), will throw
std::logic_error if the map is not large enough std::logic_error if the map is not large enough
to provide an answer. to provide an answer.
@ -267,11 +275,11 @@ class TempoMap : public PBD::StatefulDestructible
const TempoSection& tempo_section_at (framepos_t) const; const TempoSection& tempo_section_at (framepos_t) const;
void add_tempo(const Tempo&, Timecode::BBT_Time where); void add_tempo (const Tempo&, Timecode::BBT_Time where);
void add_meter(const Meter&, Timecode::BBT_Time where); void add_meter (const Meter&, Timecode::BBT_Time where);
void remove_tempo(const TempoSection&, bool send_signal); void remove_tempo (const TempoSection&, bool send_signal);
void remove_meter(const MeterSection&, bool send_signal); void remove_meter (const MeterSection&, bool send_signal);
void replace_tempo (const TempoSection&, const Tempo&, const Timecode::BBT_Time& where); void replace_tempo (const TempoSection&, const Tempo&, const Timecode::BBT_Time& where);
void replace_meter (const MeterSection&, const Meter&, const Timecode::BBT_Time& where); void replace_meter (const MeterSection&, const Meter&, const Timecode::BBT_Time& where);
@ -292,7 +300,6 @@ class TempoMap : public PBD::StatefulDestructible
TempoMetric metric_at (Timecode::BBT_Time bbt) const; TempoMetric metric_at (Timecode::BBT_Time bbt) const;
TempoMetric metric_at (framepos_t) const; TempoMetric metric_at (framepos_t) const;
void change_existing_tempo_at (framepos_t, double bpm, double note_type); void change_existing_tempo_at (framepos_t, double bpm, double note_type);
void change_initial_tempo (double bpm, double note_type); void change_initial_tempo (double bpm, double note_type);

View file

@ -43,12 +43,6 @@ using Timecode::BBT_Time;
Meter TempoMap::_default_meter (4.0, 4.0); Meter TempoMap::_default_meter (4.0, 4.0);
Tempo TempoMap::_default_tempo (120.0); Tempo TempoMap::_default_tempo (120.0);
double
Tempo::frames_per_beat (framecnt_t sr) const
{
return (60.0 * sr) / _beats_per_minute;
}
/***********************************************************************/ /***********************************************************************/
double double
@ -1856,8 +1850,9 @@ TempoMap::framepos_plus_beats (framepos_t pos, Evoral::MusicalTime beats) const
next_tempo -> first tempo after "pos", possibly metrics.end() 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", DEBUG_TRACE (DEBUG::TempoMath,
pos, beats, *((Tempo*)tempo), tempo->frame())); string_compose ("frame %1 plus %2 beats, start with tempo = %3 @ %4\n",
pos, beats, *((const Tempo*)tempo), tempo->frame()));
while (beats) { while (beats) {
@ -1887,7 +1882,7 @@ TempoMap::framepos_plus_beats (framepos_t pos, Evoral::MusicalTime beats) const
tempo = dynamic_cast<const TempoSection*>(*next_tempo); tempo = dynamic_cast<const TempoSection*>(*next_tempo);
DEBUG_TRACE (DEBUG::TempoMath, string_compose ("\tnew tempo = %1 @ %2 fpb = %3\n", 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))); tempo->frames_per_beat (_frame_rate)));
while (next_tempo != metrics.end ()) { while (next_tempo != metrics.end ()) {
@ -1955,8 +1950,9 @@ TempoMap::framepos_minus_beats (framepos_t pos, Evoral::MusicalTime beats) const
} }
} }
DEBUG_TRACE (DEBUG::TempoMath, string_compose ("frame %1 minus %2 beats, start with tempo = %3 @ %4 prev at beg? %5\n", DEBUG_TRACE (DEBUG::TempoMath,
pos, beats, *((Tempo*)tempo), tempo->frame(), 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())); prev_tempo == metrics.rend()));
/* We now have: /* We now have:
@ -1992,8 +1988,9 @@ TempoMap::framepos_minus_beats (framepos_t pos, Evoral::MusicalTime beats) const
tempo = dynamic_cast<const TempoSection*>(*prev_tempo); tempo = dynamic_cast<const TempoSection*>(*prev_tempo);
DEBUG_TRACE (DEBUG::TempoMath, string_compose ("\tnew tempo = %1 @ %2 fpb = %3\n", DEBUG_TRACE (DEBUG::TempoMath,
*((Tempo*)tempo), tempo->frame(), string_compose ("\tnew tempo = %1 @ %2 fpb = %3\n",
*((const Tempo*)tempo), tempo->frame(),
tempo->frames_per_beat (_frame_rate))); tempo->frames_per_beat (_frame_rate)));
while (prev_tempo != metrics.rend ()) { while (prev_tempo != metrics.rend ()) {
@ -2184,8 +2181,9 @@ TempoMap::framewalk_to_beats (framepos_t pos, framecnt_t distance) const
assert (tempo); assert (tempo);
DEBUG_TRACE (DEBUG::TempoMath, string_compose ("frame %1 walk by %2 frames, start with tempo = %3 @ %4\n", DEBUG_TRACE (DEBUG::TempoMath,
pos, distance, *((Tempo*)tempo), tempo->frame())); 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; Evoral::MusicalTime beats = 0;
@ -2226,8 +2224,9 @@ TempoMap::framewalk_to_beats (framepos_t pos, framecnt_t distance) const
tempo = dynamic_cast<const TempoSection*>(*next_tempo); tempo = dynamic_cast<const TempoSection*>(*next_tempo);
DEBUG_TRACE (DEBUG::TempoMath, string_compose ("\tnew tempo = %1 @ %2 fpb = %3\n", DEBUG_TRACE (DEBUG::TempoMath,
*((Tempo*)tempo), tempo->frame(), string_compose ("\tnew tempo = %1 @ %2 fpb = %3\n",
*((const Tempo*)tempo), tempo->frame(),
tempo->frames_per_beat (_frame_rate))); tempo->frames_per_beat (_frame_rate)));
while (next_tempo != metrics.end ()) { while (next_tempo != metrics.end ()) {
@ -2335,9 +2334,9 @@ operator<< (std::ostream& o, const MetricSection& section) {
const MeterSection* ms; const MeterSection* ms;
if ((ts = dynamic_cast<const TempoSection*> (&section)) != 0) { if ((ts = dynamic_cast<const TempoSection*> (&section)) != 0) {
o << *((Tempo*) ts); o << *((const Tempo*) ts);
} else if ((ms = dynamic_cast<const MeterSection*> (&section)) != 0) { } else if ((ms = dynamic_cast<const MeterSection*> (&section)) != 0) {
o << *((Meter*) ms); o << *((const Meter*) ms);
} }
return o; return o;