13
0

consolidate some TempoMap modifier methods

This commit is contained in:
Paul Davis 2020-11-25 12:51:17 -07:00
parent dade9994d8
commit 9f866a6bbe
3 changed files with 47 additions and 136 deletions

View File

@ -423,7 +423,7 @@ Editor::mouse_add_new_tempo_event (timepos_t pos)
if (qn > Beats()) {
XMLNode &before = map.get_state();
/* add music-locked ramped (?) tempo using the bpm/note type at sample*/
map.set_tempo (map.tempo_at (pos), qn);
map.set_tempo (map.tempo_at (pos), timepos_t (qn));
XMLNode &after = map.get_state();
_session->add_command(new MementoCommand<TempoMap>(map, &before, &after));

View File

@ -677,15 +677,40 @@ TempoMap::change_tempo (TempoPoint & p, Tempo const & t)
}
TempoPoint &
TempoMap::set_tempo (Tempo const & t, superclock_t sc)
TempoMap::set_tempo (Tempo const & t, BBT_Time const & bbt)
{
return set_tempo (t, timepos_t (quarter_note_at (bbt)));
}
TempoPoint &
TempoMap::set_tempo (Tempo const & t, timepos_t const & time)
{
TempoPoint * ret;
{
DEBUG_TRACE (DEBUG::TemporalMap, string_compose ("Set tempo @ %1 to %2\n", sc, t));
DEBUG_TRACE (DEBUG::TemporalMap, string_compose ("Set tempo @ %1 to %2\n", time, t));
if (time.is_beats()) {
/* tempo changes are required to be on-beat */
Beats on_beat = time.beats().round_to_beat();
superclock_t sc;
BBT_Time bbt;
TempoMetric metric (metric_at_locked (on_beat, false));
bbt = metric.bbt_at (on_beat);
sc = metric.superclock_at (on_beat);
TempoPoint tp (*this, t, sc, on_beat, bbt);
ret = add_tempo (tp);
} else {
Beats beats;
BBT_Time bbt;
superclock_t sc = time.superclocks();
TempoMetric tm (metric_at_locked (sc, false));
@ -699,6 +724,7 @@ TempoMap::set_tempo (Tempo const & t, superclock_t sc)
TempoPoint tp (*this, t, sc, beats, bbt);
ret = add_tempo (tp);
}
Changed ();
@ -706,73 +732,6 @@ TempoMap::set_tempo (Tempo const & t, superclock_t sc)
return *ret;
}
TempoPoint &
TempoMap::set_tempo (Tempo const & t, BBT_Time const & bbt)
{
TempoPoint * ret = 0;
{
DEBUG_TRACE (DEBUG::TemporalMap, string_compose ("Set tempo @ %1 to %2\n", bbt, t));
/* tempo changes are required to be on-beat */
BBT_Time on_beat = bbt.round_to_beat();
superclock_t sc;
Beats beats;
TempoMetric metric (metric_at_locked (on_beat, false));
beats = metric.quarters_at (on_beat);
sc = metric.superclock_at (on_beat);
TempoPoint tp (*this, t, sc, beats, on_beat);
ret = add_tempo (tp);
}
Changed ();
return *ret;
}
TempoPoint &
TempoMap::set_tempo (Tempo const & t, Beats const & beats)
{
TempoPoint * ret;
{
DEBUG_TRACE (DEBUG::TemporalMap, string_compose ("Set tempo @ %1 to %2\n", beats, t));
/* tempo changes are required to be on-beat */
Beats on_beat = beats.round_to_beat();
superclock_t sc;
BBT_Time bbt;
TempoMetric metric (metric_at_locked (on_beat, false));
bbt = metric.bbt_at (on_beat);
sc = metric.superclock_at (on_beat);
TempoPoint tp (*this, t, sc, on_beat, bbt);
ret = add_tempo (tp);
}
Changed ();
return *ret;
}
TempoPoint &
TempoMap::set_tempo (Tempo const & t, timepos_t const & time)
{
if (time.is_beats()) {
return set_tempo (t, time.beats());
}
return set_tempo (t, time.superclocks());
}
TempoPoint*
TempoMap::add_tempo (TempoPoint & tp)
{
@ -1319,53 +1278,13 @@ TempoMap::move_tempo (TempoPoint const & tp, timepos_t const & when, bool push)
MeterPoint &
TempoMap::set_meter (Meter const & m, timepos_t const & time)
{
MeterPoint * ret = 0;
DEBUG_TRACE (DEBUG::TemporalMap, string_compose ("Set meter @ %1 to %2\n", time, m));
if (time.is_beats()) {
return set_meter (m, time.beats());
}
return set_meter (m, time.superclocks());
}
MeterPoint &
TempoMap::set_meter (Meter const & t, BBT_Time const & bbt)
{
MeterPoint * ret = 0;
{
DEBUG_TRACE (DEBUG::TemporalMap, string_compose ("Set meter @ %1 to %2\n", bbt, t));
TempoMetric metric (metric_at_locked (bbt));
superclock_t sc;
Beats beats;
BBT_Time rounded_bbt;
/* meter changes are required to be on-bar */
rounded_bbt = metric.round_to_bar (bbt);
beats = metric.quarters_at (rounded_bbt);
sc = metric.superclock_at (beats);
MeterPoint mp (*this, t, sc, beats, rounded_bbt);
ret = add_meter (mp);
reset_starting_at (mp.sclock());
}
Changed ();
return *ret;
}
MeterPoint &
TempoMap::set_meter (Meter const & t, Beats const & beats)
{
MeterPoint * ret = 0;
{
DEBUG_TRACE (DEBUG::TemporalMap, string_compose ("Set meter @ %1 to %2\n", beats, t));
Beats beats (time.beats());
TempoMetric metric (metric_at_locked (beats));
/* meter changes are required to be on-bar */
@ -1376,24 +1295,13 @@ TempoMap::set_meter (Meter const & t, Beats const & beats)
const Beats rounded_beats = metric.quarters_at (rounded_bbt);
const superclock_t sc = metric.superclock_at (rounded_beats);
MeterPoint mp (*this, t, sc, rounded_beats, rounded_bbt);
MeterPoint mp (*this, m, sc, rounded_beats, rounded_bbt);
ret = add_meter (mp);
}
Changed ();
return *ret;
}
MeterPoint &
TempoMap::set_meter (Meter const & m, superclock_t sc)
{
MeterPoint * ret = 0;
{
DEBUG_TRACE (DEBUG::TemporalMap, string_compose ("Set meter @ %1 to %2\n", sc, m));
} else {
superclock_t sc (time.superclocks());
Beats beats;
BBT_Time bbt;
@ -1419,6 +1327,12 @@ TempoMap::set_meter (Meter const & m, superclock_t sc)
return *ret;
}
MeterPoint &
TempoMap::set_meter (Meter const & t, BBT_Time const & bbt)
{
return set_meter (t, timepos_t (quarter_note_at (bbt)));
}
void
TempoMap::remove_meter (MeterPoint const & mp)
{

View File

@ -646,26 +646,24 @@ class LIBTEMPORAL_API TempoMap : public PBD::StatefulDestructible
void remove_bartime (MusicTimePoint const & tp);
TempoPoint & set_tempo (Tempo const &, BBT_Time const &);
TempoPoint & set_tempo (Tempo const &, Beats const &);
TempoPoint & set_tempo (Tempo const &, timepos_t const &);
void remove_tempo (TempoPoint const &);
MeterPoint & set_meter (Meter const &, BBT_Time const &);
MeterPoint & set_meter (Meter const &, Beats const &);
MeterPoint & set_meter (Meter const &, timepos_t const &);
void remove_tempo (TempoPoint const &);
void remove_meter (MeterPoint const &);
/* these are a convenience method that just wrap some odd semantics */
bool move_tempo (TempoPoint const & point, timepos_t const & destination, bool push = false);
bool move_meter (MeterPoint const & point, timepos_t const & destination, bool push = false);
TimeDomain time_domain() const { return _time_domain; }
void set_time_domain (TimeDomain td);
/* END OF MODIFYING METHODS */
TimeDomain time_domain() const { return _time_domain; }
typedef std::list<Point*> Metrics;
template<class T> void apply_with_metrics (T& obj, void (T::*method)(Metrics const &)) {
@ -798,7 +796,6 @@ class LIBTEMPORAL_API TempoMap : public PBD::StatefulDestructible
int set_meters_from_state (XMLNode const &);
int set_music_times_from_state (XMLNode const &);
TempoPoint & set_tempo (Tempo const &, superclock_t);
MeterPoint & set_meter (Meter const &, superclock_t);
void dump_locked (std::ostream&) const;