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:
parent
6b6ef35f3e
commit
dd78c6ed71
@ -34,17 +34,17 @@
|
||||
|
||||
#include "ardour/ardour.h"
|
||||
|
||||
class XMLNode;
|
||||
|
||||
class BBTTest;
|
||||
class FrameposPlusBeatsTest;
|
||||
class TempoTest;
|
||||
class XMLNode;
|
||||
|
||||
namespace ARDOUR {
|
||||
|
||||
class Meter;
|
||||
class TempoMap;
|
||||
|
||||
/** Tempo, the speed at which musical time progresses (BPM). */
|
||||
class Tempo {
|
||||
public:
|
||||
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 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:
|
||||
double _beats_per_minute;
|
||||
double _note_type;
|
||||
};
|
||||
|
||||
/** Meter, or time signature (beats per bar, and which note type is a beat). */
|
||||
class Meter {
|
||||
public:
|
||||
Meter (double dpb, double bt)
|
||||
@ -83,6 +86,7 @@ class Meter {
|
||||
double _note_type;
|
||||
};
|
||||
|
||||
/** A section of timeline with a certain Tempo or Meter. */
|
||||
class MetricSection {
|
||||
public:
|
||||
MetricSection (const Timecode::BBT_Time& start)
|
||||
@ -118,6 +122,7 @@ class MetricSection {
|
||||
bool _movable;
|
||||
};
|
||||
|
||||
/** A section of timeline with a certain Meter. */
|
||||
class MeterSection : public MetricSection, public Meter {
|
||||
public:
|
||||
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;
|
||||
};
|
||||
|
||||
/** A section of timeline with a certain Tempo. */
|
||||
class TempoSection : public MetricSection, public Tempo {
|
||||
public:
|
||||
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;
|
||||
|
||||
/** Helper class that we use to be able to keep track of which
|
||||
meter *AND* tempo are in effect at a given point in time.
|
||||
/** Helper class to keep track of the Meter *AND* Tempo in effect
|
||||
at a given point in time.
|
||||
*/
|
||||
class TempoMetric {
|
||||
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_meter (const Meter& m) { _meter = &m; }
|
||||
@ -236,6 +243,7 @@ class TempoMap : public PBD::StatefulDestructible
|
||||
*/
|
||||
|
||||
void bbt_time (framepos_t when, Timecode::BBT_Time&);
|
||||
|
||||
/* realtime safe variant of ::bbt_time(), will throw
|
||||
std::logic_error if the map is not large enough
|
||||
to provide an answer.
|
||||
@ -292,7 +300,6 @@ class TempoMap : public PBD::StatefulDestructible
|
||||
TempoMetric metric_at (Timecode::BBT_Time bbt) const;
|
||||
TempoMetric metric_at (framepos_t) const;
|
||||
|
||||
|
||||
void change_existing_tempo_at (framepos_t, double bpm, double note_type);
|
||||
void change_initial_tempo (double bpm, double note_type);
|
||||
|
||||
|
@ -43,12 +43,6 @@ using Timecode::BBT_Time;
|
||||
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
|
||||
@ -1856,8 +1850,9 @@ TempoMap::framepos_plus_beats (framepos_t pos, Evoral::MusicalTime beats) const
|
||||
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) {
|
||||
|
||||
@ -1887,7 +1882,7 @@ TempoMap::framepos_plus_beats (framepos_t pos, Evoral::MusicalTime beats) const
|
||||
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 ()) {
|
||||
@ -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",
|
||||
pos, beats, *((Tempo*)tempo), tempo->frame(),
|
||||
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:
|
||||
@ -1992,8 +1988,9 @@ TempoMap::framepos_minus_beats (framepos_t pos, Evoral::MusicalTime beats) const
|
||||
|
||||
tempo = dynamic_cast<const TempoSection*>(*prev_tempo);
|
||||
|
||||
DEBUG_TRACE (DEBUG::TempoMath, string_compose ("\tnew tempo = %1 @ %2 fpb = %3\n",
|
||||
*((Tempo*)tempo), tempo->frame(),
|
||||
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 ()) {
|
||||
@ -2184,8 +2181,9 @@ TempoMap::framewalk_to_beats (framepos_t pos, framecnt_t distance) const
|
||||
|
||||
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;
|
||||
|
||||
@ -2226,8 +2224,9 @@ TempoMap::framewalk_to_beats (framepos_t pos, framecnt_t distance) const
|
||||
|
||||
tempo = dynamic_cast<const TempoSection*>(*next_tempo);
|
||||
|
||||
DEBUG_TRACE (DEBUG::TempoMath, string_compose ("\tnew tempo = %1 @ %2 fpb = %3\n",
|
||||
*((Tempo*)tempo), tempo->frame(),
|
||||
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 ()) {
|
||||
@ -2335,9 +2334,9 @@ operator<< (std::ostream& o, const MetricSection& section) {
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user