new SnapBBT debug option, split out BBT_time and start work on BBT arithmetic framework. this will cause a full recompile, so find something else to do

git-svn-id: svn://localhost/ardour2/branches/3.0@5936 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2009-10-27 02:24:56 +00:00
parent 9ad08bfe97
commit 68a3144344
12 changed files with 64 additions and 86 deletions

View file

@ -673,7 +673,7 @@ AudioClock::set_bbt (nframes_t when, bool force)
pos = bbt_reference_time; pos = bbt_reference_time;
} }
TempoMap::Metric m (session->tempo_map().metric_at (pos)); TempoMetric m (session->tempo_map().metric_at (pos));
sprintf (buf, "%-5.2f", m.tempo().beats_per_minute()); sprintf (buf, "%-5.2f", m.tempo().beats_per_minute());
if (bbt_lower_info_label->get_text() != buf) { if (bbt_lower_info_label->get_text() != buf) {

View file

@ -81,6 +81,7 @@ list_debug_options ()
cerr << "\tMidiSourceIO\n"; cerr << "\tMidiSourceIO\n";
cerr << "\tMidiPlaylistIO\n"; cerr << "\tMidiPlaylistIO\n";
cerr << "\tMidiDiskstreamIO\n"; cerr << "\tMidiDiskstreamIO\n";
cerr << "\tSnapBBT\n";
} }
static int static int
@ -108,12 +109,12 @@ parse_debug_options (const char* str)
if (strcasecmp (p, "midisourceio") == 0) { if (strcasecmp (p, "midisourceio") == 0) {
bits |= ARDOUR::DEBUG::MidiSourceIO; bits |= ARDOUR::DEBUG::MidiSourceIO;
} } else if (strcasecmp (p, "midiplaylistio") == 0) {
if (strcasecmp (p, "midiplaylistio") == 0) {
bits |= ARDOUR::DEBUG::MidiPlaylistIO; bits |= ARDOUR::DEBUG::MidiPlaylistIO;
} } else if (strcasecmp (p, "mididiskstreamio") == 0) {
if (strcasecmp (p, "mididiskstreamio") == 0) {
bits |= ARDOUR::DEBUG::MidiDiskstreamIO; bits |= ARDOUR::DEBUG::MidiDiskstreamIO;
} else if (strcasecmp (p, "snapbbt") == 0) {
bits |= ARDOUR::DEBUG::SnapBBT;
} }
p = strtok_r (0, ",", &sp); p = strtok_r (0, ",", &sp);

View file

@ -222,7 +222,7 @@ SessionOptionEditor::SessionOptionEditor (Session* s)
add_option (_("Sync"), spf); add_option (_("Sync"), spf);
ComboOption<SmpteFormat>* smf = new ComboOption<SmpteFormat> ( ComboOption<TimecodeFormat>* smf = new ComboOption<TimecodeFormat> (
"timecode-format", "timecode-format",
_("Timecode frames-per-second"), _("Timecode frames-per-second"),
mem_fun (*_session_config, &SessionConfiguration::get_timecode_format), mem_fun (*_session_config, &SessionConfiguration::get_timecode_format),

View file

@ -37,7 +37,8 @@ namespace ARDOUR {
enum DebugBits { enum DebugBits {
MidiSourceIO = 0x1, MidiSourceIO = 0x1,
MidiPlaylistIO = 0x2, MidiPlaylistIO = 0x2,
MidiDiskstreamIO = 0x4 MidiDiskstreamIO = 0x4,
SnapBBT = 0x8
}; };
} }

View file

@ -33,7 +33,7 @@ CONFIG_VARIABLE (bool, auto_input, "auto-input", true)
CONFIG_VARIABLE (bool, punch_in, "punch-in", false) CONFIG_VARIABLE (bool, punch_in, "punch-in", false)
CONFIG_VARIABLE (bool, punch_out, "punch-out", false) CONFIG_VARIABLE (bool, punch_out, "punch-out", false)
CONFIG_VARIABLE (uint32_t, subframes_per_frame, "subframes-per-frame", 100) CONFIG_VARIABLE (uint32_t, subframes_per_frame, "subframes-per-frame", 100)
CONFIG_VARIABLE (SmpteFormat, timecode_format, "timecode-format", timecode_30) CONFIG_VARIABLE (TimecodeFormat, timecode_format, "timecode-format", timecode_30)
CONFIG_VARIABLE_SPECIAL(Glib::ustring, raid_path, "raid-path", "", path_expand) CONFIG_VARIABLE_SPECIAL(Glib::ustring, raid_path, "raid-path", "", path_expand)
CONFIG_VARIABLE (std::string, bwf_country_code, "bwf-country-code", "US") CONFIG_VARIABLE (std::string, bwf_country_code, "bwf-country-code", "US")
CONFIG_VARIABLE (std::string, bwf_organization_code, "bwf-organization-code", "US") CONFIG_VARIABLE (std::string, bwf_organization_code, "bwf-organization-code", "US")

View file

@ -140,6 +140,30 @@ 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
meter *AND* tempo are in effect at a given point in time.
*/
class TempoMetric {
public:
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; }
void set_frame (nframes_t f) { _frame = f; }
void set_start (const BBT_Time& t) { _start = t; }
const Meter& meter() const { return *_meter; }
const Tempo& tempo() const { return *_tempo; }
nframes_t frame() const { return _frame; }
const BBT_Time& start() const { return _start; }
private:
const Meter* _meter;
const Tempo* _tempo;
nframes_t _frame;
BBT_Time _start;
};
class TempoMap : public PBD::StatefulDestructible class TempoMap : public PBD::StatefulDestructible
{ {
public: public:
@ -217,33 +241,9 @@ class TempoMap : public PBD::StatefulDestructible
void dump (std::ostream&) const; void dump (std::ostream&) const;
void clear (); void clear ();
/** Helper class that we use to be able to keep track of which TempoMetric metric_at (BBT_Time bbt) const;
meter *AND* tempo are in effect at a given point in time. TempoMetric metric_at (nframes_t) const;
*/ void bbt_time_with_metric (nframes_t, BBT_Time&, const TempoMetric&) const;
class Metric {
public:
Metric (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; }
void set_frame (nframes_t f) { _frame = f; }
void set_start (const BBT_Time& t) { _start = t; }
const Meter& meter() const { return *_meter; }
const Tempo& tempo() const { return *_tempo; }
nframes_t frame() const { return _frame; }
const BBT_Time& start() const { return _start; }
private:
const Meter* _meter;
const Tempo* _tempo;
nframes_t _frame;
BBT_Time _start;
};
Metric metric_at (BBT_Time bbt) const;
Metric metric_at (nframes_t) const;
void bbt_time_with_metric (nframes_t, BBT_Time&, const Metric&) const;
void change_existing_tempo_at (nframes_t, double bpm, double note_type); void change_existing_tempo_at (nframes_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

@ -34,6 +34,8 @@
#include "control_protocol/timecode.h" #include "control_protocol/timecode.h"
#include "pbd/id.h" #include "pbd/id.h"
#include "ardour/bbt_time.h"
#include <map> #include <map>
#if __GNUC__ < 3 #if __GNUC__ < 3
@ -156,34 +158,7 @@ namespace ARDOUR {
TrackColor TrackColor
}; };
struct BBT_Time { enum TimecodeFormat {
uint32_t bars;
uint32_t beats;
uint32_t ticks;
BBT_Time() {
bars = 1;
beats = 1;
ticks = 0;
}
/* we can't define arithmetic operators for BBT_Time, because
the results depend on a TempoMap, but we can define
a useful check on the less-than condition.
*/
bool operator< (const BBT_Time& other) const {
return bars < other.bars ||
(bars == other.bars && beats < other.beats) ||
(bars == other.bars && beats == other.beats && ticks < other.ticks);
}
bool operator== (const BBT_Time& other) const {
return bars == other.bars && beats == other.beats && ticks == other.ticks;
}
};
enum SmpteFormat {
timecode_23976, timecode_23976,
timecode_24, timecode_24,
timecode_24976, timecode_24976,
@ -467,7 +442,7 @@ std::istream& operator>>(std::istream& o, ARDOUR::CrossfadeModel& sf);
std::istream& operator>>(std::istream& o, ARDOUR::SlaveSource& sf); std::istream& operator>>(std::istream& o, ARDOUR::SlaveSource& sf);
std::istream& operator>>(std::istream& o, ARDOUR::ShuttleBehaviour& sf); std::istream& operator>>(std::istream& o, ARDOUR::ShuttleBehaviour& sf);
std::istream& operator>>(std::istream& o, ARDOUR::ShuttleUnits& sf); std::istream& operator>>(std::istream& o, ARDOUR::ShuttleUnits& sf);
std::istream& operator>>(std::istream& o, ARDOUR::SmpteFormat& sf); std::istream& operator>>(std::istream& o, ARDOUR::TimecodeFormat& sf);
std::istream& operator>>(std::istream& o, ARDOUR::DenormalModel& sf); std::istream& operator>>(std::istream& o, ARDOUR::DenormalModel& sf);
std::istream& operator>>(std::istream& o, ARDOUR::WaveformScale& sf); std::istream& operator>>(std::istream& o, ARDOUR::WaveformScale& sf);
std::istream& operator>>(std::istream& o, ARDOUR::WaveformShape& sf); std::istream& operator>>(std::istream& o, ARDOUR::WaveformShape& sf);

View file

@ -75,7 +75,7 @@ setup_enum_writer ()
ShuttleUnits _ShuttleUnits; ShuttleUnits _ShuttleUnits;
Session::RecordState _Session_RecordState; Session::RecordState _Session_RecordState;
Session::Event::Type _Session_Event_Type; Session::Event::Type _Session_Event_Type;
SmpteFormat _Session_SmpteFormat; TimecodeFormat _Session_TimecodeFormat;
Session::PullupFormat _Session_PullupFormat; Session::PullupFormat _Session_PullupFormat;
AudioRegion::FadeShape _AudioRegion_FadeShape; AudioRegion::FadeShape _AudioRegion_FadeShape;
Panner::LinkDirection _Panner_LinkDirection; Panner::LinkDirection _Panner_LinkDirection;
@ -321,7 +321,7 @@ setup_enum_writer ()
REGISTER_ENUM (timecode_30drop); REGISTER_ENUM (timecode_30drop);
REGISTER_ENUM (timecode_5994); REGISTER_ENUM (timecode_5994);
REGISTER_ENUM (timecode_60); REGISTER_ENUM (timecode_60);
REGISTER (_Session_SmpteFormat); REGISTER (_Session_TimecodeFormat);
REGISTER_CLASS_ENUM (Session, pullup_Plus4Plus1); REGISTER_CLASS_ENUM (Session, pullup_Plus4Plus1);
REGISTER_CLASS_ENUM (Session, pullup_Plus4); REGISTER_CLASS_ENUM (Session, pullup_Plus4);

View file

@ -637,7 +637,7 @@ std::istream& operator>>(std::istream& o, CrossfadeModel& var) { return int_to_t
std::istream& operator>>(std::istream& o, SlaveSource& var) { return int_to_type<SlaveSource> (o, var); } std::istream& operator>>(std::istream& o, SlaveSource& var) { return int_to_type<SlaveSource> (o, var); }
std::istream& operator>>(std::istream& o, ShuttleBehaviour& var) { return int_to_type<ShuttleBehaviour> (o, var); } std::istream& operator>>(std::istream& o, ShuttleBehaviour& var) { return int_to_type<ShuttleBehaviour> (o, var); }
std::istream& operator>>(std::istream& o, ShuttleUnits& var) { return int_to_type<ShuttleUnits> (o, var); } std::istream& operator>>(std::istream& o, ShuttleUnits& var) { return int_to_type<ShuttleUnits> (o, var); }
std::istream& operator>>(std::istream& o, SmpteFormat& var) { return int_to_type<SmpteFormat> (o, var); } std::istream& operator>>(std::istream& o, TimecodeFormat& var) { return int_to_type<TimecodeFormat> (o, var); }
std::istream& operator>>(std::istream& o, DenormalModel& var) { return int_to_type<DenormalModel> (o, var); } std::istream& operator>>(std::istream& o, DenormalModel& var) { return int_to_type<DenormalModel> (o, var); }
std::istream& operator>>(std::istream& o, WaveformScale& var) { return int_to_type<WaveformScale> (o, var); } std::istream& operator>>(std::istream& o, WaveformScale& var) { return int_to_type<WaveformScale> (o, var); }
std::istream& operator>>(std::istream& o, WaveformShape& var) { return int_to_type<WaveformShape> (o, var); } std::istream& operator>>(std::istream& o, WaveformShape& var) { return int_to_type<WaveformShape> (o, var); }

View file

@ -501,7 +501,7 @@ Session::jack_timebase_callback (jack_transport_state_t /*state*/,
if (_tempo_map) { if (_tempo_map) {
TempoMap::Metric metric (_tempo_map->metric_at (_transport_frame)); TempoMetric metric (_tempo_map->metric_at (_transport_frame));
_tempo_map->bbt_time_with_metric (_transport_frame, bbt, metric); _tempo_map->bbt_time_with_metric (_transport_frame, bbt, metric);
pos->bar = bbt.bars; pos->bar = bbt.bars;

View file

@ -26,6 +26,7 @@
#include <glibmm/thread.h> #include <glibmm/thread.h>
#include "pbd/xml++.h" #include "pbd/xml++.h"
#include "ardour/debug.h"
#include "ardour/tempo.h" #include "ardour/tempo.h"
#include "ardour/utils.h" #include "ardour/utils.h"
@ -656,7 +657,7 @@ TempoMap::timestamp_metrics (bool use_bbt)
for (i = metrics->begin(); i != metrics->end(); ++i) { for (i = metrics->begin(); i != metrics->end(); ++i) {
BBT_Time bbt; BBT_Time bbt;
Metric metric (*meter, *tempo); TempoMetric metric (*meter, *tempo);
if (prev) { if (prev) {
metric.set_start (prev->start()); metric.set_start (prev->start());
@ -713,10 +714,10 @@ TempoMap::timestamp_metrics (bool use_bbt)
} }
TempoMap::Metric TempoMetric
TempoMap::metric_at (nframes_t frame) const TempoMap::metric_at (nframes_t frame) const
{ {
Metric m (first_meter(), first_tempo()); TempoMetric m (first_meter(), first_tempo());
const Meter* meter; const Meter* meter;
const Tempo* tempo; const Tempo* tempo;
@ -746,10 +747,10 @@ TempoMap::metric_at (nframes_t frame) const
return m; return m;
} }
TempoMap::Metric TempoMetric
TempoMap::metric_at (BBT_Time bbt) const TempoMap::metric_at (BBT_Time bbt) const
{ {
Metric m (first_meter(), first_tempo()); TempoMetric m (first_meter(), first_tempo());
const Meter* meter; const Meter* meter;
const Tempo* tempo; const Tempo* tempo;
@ -797,7 +798,7 @@ TempoMap::bbt_time_unlocked (nframes_t frame, BBT_Time& bbt) const
} }
void void
TempoMap::bbt_time_with_metric (nframes_t frame, BBT_Time& bbt, const Metric& metric) const TempoMap::bbt_time_with_metric (nframes_t frame, BBT_Time& bbt, const TempoMetric& metric) const
{ {
nframes_t frame_diff; nframes_t frame_diff;
@ -853,7 +854,7 @@ TempoMap::count_frames_between ( const BBT_Time& start, const BBT_Time& end) con
nframes_t start_frame = 0; nframes_t start_frame = 0;
nframes_t end_frame = 0; nframes_t end_frame = 0;
Metric m = metric_at (start); TempoMetric m = metric_at (start);
uint32_t bar_offset = start.bars - m.start().bars; uint32_t bar_offset = start.bars - m.start().bars;
@ -965,7 +966,7 @@ TempoMap::bbt_duration_at_unlocked (const BBT_Time& when, const BBT_Time& bbt, i
result.beats = 1; result.beats = 1;
result.ticks = 0; result.ticks = 0;
Metric metric = metric_at(result); TempoMetric metric = metric_at(result);
beats_per_bar = metric.meter().beats_per_bar(); beats_per_bar = metric.meter().beats_per_bar();
@ -1192,13 +1193,15 @@ TempoMap::round_to_beat_subdivision (nframes_t fr, int sub_num, int dir)
nframes_t nframes_t
TempoMap::round_to_type (nframes_t frame, int dir, BBTPointType type) TempoMap::round_to_type (nframes_t frame, int dir, BBTPointType type)
{ {
Metric metric = metric_at (frame); TempoMetric metric = metric_at (frame);
BBT_Time bbt; BBT_Time bbt;
BBT_Time start; BBT_Time start;
bbt_time_with_metric (frame, bbt, metric); bbt_time_with_metric (frame, bbt, metric);
switch (type) { switch (type) {
case Bar: case Bar:
DEBUG_TRACE(DEBUG::SnapBBT, string_compose ("round from %1 (%3) to bars in direction %2\n", frame, (dir < 0 ? "back" : "forward"), bbt));
if (dir < 0) { if (dir < 0) {
if (bbt.bars > 1) { if (bbt.bars > 1) {
bbt.bars--; bbt.bars--;
@ -1219,10 +1222,12 @@ TempoMap::round_to_type (nframes_t frame, int dir, BBTPointType type)
break; break;
case Beat: case Beat:
DEBUG_TRACE(DEBUG::SnapBBT, string_compose ("round from %1 (%3) to beat in direction %2\n", frame, (dir < 0 ? "back" : "forward"), bbt));
if (dir < 0) { if (dir < 0) {
if (bbt.beats > 1) { if (bbt.beats > 1) {
bbt.beats--; bbt.beats--;
} }
} else if (dir > 0) { } else if (dir > 0) {
if (bbt.ticks > 0) { if (bbt.ticks > 0) {
bbt.beats++; bbt.beats++;
@ -1243,12 +1248,7 @@ TempoMap::round_to_type (nframes_t frame, int dir, BBTPointType type)
} }
/* DEBUG_TRACE(DEBUG::SnapBBT, string_compose ("\tat %1 count frames from %2 to %3 = %4\n", metric.frame(), metric.start(), bbt, count_frames_between (metric.start(), bbt)));
cerr << "for " << frame << " round to " << bbt << " using "
<< metric.start()
<< endl;
*/
return metric.frame() + count_frames_between (metric.start(), bbt); return metric.frame() + count_frames_between (metric.start(), bbt);
} }
@ -1471,7 +1471,7 @@ TempoMap::tempo_section_at (nframes_t frame)
const Tempo& const Tempo&
TempoMap::tempo_at (nframes_t frame) const TempoMap::tempo_at (nframes_t frame) const
{ {
Metric m (metric_at (frame)); TempoMetric m (metric_at (frame));
return m.tempo(); return m.tempo();
} }
@ -1479,7 +1479,7 @@ TempoMap::tempo_at (nframes_t frame) const
const Meter& const Meter&
TempoMap::meter_at (nframes_t frame) const TempoMap::meter_at (nframes_t frame) const
{ {
Metric m (metric_at (frame)); TempoMetric m (metric_at (frame));
return m.meter(); return m.meter();
} }

View file

@ -55,6 +55,7 @@ libardour_sources = [
'automation.cc', 'automation.cc',
'automation_control.cc', 'automation_control.cc',
'automation_list.cc', 'automation_list.cc',
'bbt_time.cc',
'beats_frames_converter.cc', 'beats_frames_converter.cc',
'broadcast_info.cc', 'broadcast_info.cc',
'buffer.cc', 'buffer.cc',