13
0

initial addition and use of BBT_Argument

Currently this is interchangeable with BBT_Time, but soon will
be handled differently
This commit is contained in:
Paul Davis 2023-02-10 16:06:08 -07:00
parent 3c57085756
commit 43c8fae709
4 changed files with 73 additions and 24 deletions

View File

@ -788,11 +788,11 @@ LuaBindings::common (lua_State* L)
.addFunction ("set_continuing", &Temporal::TempoMap::set_continuing)
.addFunction ("tempo_at", (Temporal::TempoPoint const& (Temporal::TempoMap::*)(Temporal::timepos_t const &) const) &Temporal::TempoMap::tempo_at)
.addFunction ("tempo_at_bbt", (Temporal::TempoPoint const& (Temporal::TempoMap::*)(Temporal::BBT_Time const &) const) &Temporal::TempoMap::tempo_at)
.addFunction ("tempo_at_bbt", (Temporal::TempoPoint const& (Temporal::TempoMap::*)(Temporal::BBT_Argument const &) const) &Temporal::TempoMap::tempo_at)
.addFunction ("tempo_at_beats", (Temporal::TempoPoint const& (Temporal::TempoMap::*)(Temporal::Beats const &) const) &Temporal::TempoMap::tempo_at)
.addFunction ("meter_at", (Temporal::MeterPoint const& (Temporal::TempoMap::*)(Temporal::timepos_t const &) const) &Temporal::TempoMap::meter_at)
.addFunction ("meter_at_bbt", (Temporal::MeterPoint const& (Temporal::TempoMap::*)(Temporal::BBT_Time const &) const) &Temporal::TempoMap::meter_at)
.addFunction ("meter_at_bbt", (Temporal::MeterPoint const& (Temporal::TempoMap::*)(Temporal::BBT_Argument const &) const) &Temporal::TempoMap::meter_at)
.addFunction ("meter_at_beats", (Temporal::MeterPoint const& (Temporal::TempoMap::*)(Temporal::Beats const &) const) &Temporal::TempoMap::meter_at)
.addFunction ("bbt_at", (Temporal::BBT_Time (Temporal::TempoMap::*)(Temporal::timepos_t const &) const) &Temporal::TempoMap::bbt_at)
@ -802,12 +802,12 @@ LuaBindings::common (lua_State* L)
.addFunction ("tempo_at_sc", (Temporal::TempoPoint const& (Temporal::TempoMap::*)(superclock_t) const) &Temporal::TempoMap::tempo_at)
.addFunction ("meter_at_sc", (Temporal::MeterPoint const& (Temporal::TempoMap::*)(superclock_t) const) &Temporal::TempoMap::meter_at)
.addFunction ("superclock_at", (superclock_t (Temporal::TempoMap::*)(Temporal::timepos_t const &) const) &Temporal::TempoMap::superclock_at)
.addFunction ("superclock_at_bbt", (superclock_t (Temporal::TempoMap::*)(Temporal::BBT_Time const &) const) &Temporal::TempoMap::superclock_at)
.addFunction ("superclock_at_bbt", (superclock_t (Temporal::TempoMap::*)(Temporal::BBT_Argument const &) const) &Temporal::TempoMap::superclock_at)
.addFunction ("superclock_at_beats", (superclock_t (Temporal::TempoMap::*)(Temporal::Beats const &) const) &Temporal::TempoMap::superclock_at)
#endif
.addFunction ("quarters_at", (Temporal::Beats (Temporal::TempoMap::*)(Temporal::timepos_t const &) const) &Temporal::TempoMap::quarters_at)
.addFunction ("quarters_at_bbt", (Temporal::Beats (Temporal::TempoMap::*)(Temporal::BBT_Time const &) const) &Temporal::TempoMap::quarters_at)
.addFunction ("quarters_at_bbt", (Temporal::Beats (Temporal::TempoMap::*)(Temporal::BBT_Argument const &) const) &Temporal::TempoMap::quarters_at)
.addFunction ("quarters_at_sample", &Temporal::TempoMap::quarters_at_sample)
.addFunction ("sample_at", (samplepos_t (Temporal::TempoMap::*)(Temporal::timepos_t const &) const) &Temporal::TempoMap::sample_at)
@ -816,7 +816,7 @@ LuaBindings::common (lua_State* L)
.addFunction ("bbt_duration_at", &Temporal::TempoMap::bbt_duration_at)
.addFunction ("bbtwalk_to_quarters", (Temporal::Beats (Temporal::TempoMap::*)(Temporal::Beats const &, Temporal::BBT_Offset const &) const) &Temporal::TempoMap::bbtwalk_to_quarters)
.addFunction ("bbtwalk_to_quarters_bbt", (Temporal::Beats (Temporal::TempoMap::*)(Temporal::BBT_Time const &, Temporal::BBT_Offset const &) const) &Temporal::TempoMap::bbtwalk_to_quarters)
.addFunction ("bbtwalk_to_quarters_bbt", (Temporal::Beats (Temporal::TempoMap::*)(Temporal::BBT_Argument const &, Temporal::BBT_Offset const &) const) &Temporal::TempoMap::bbtwalk_to_quarters)
.addFunction ("convert_duration", &Temporal::TempoMap::convert_duration)
.addFunction ("bbt_walk", &Temporal::TempoMap::bbt_walk)

View File

@ -824,7 +824,7 @@ TempoMap::replace_tempo (TempoPoint const & old, Tempo const & t, timepos_t cons
}
TempoPoint &
TempoMap::set_tempo (Tempo const & t, BBT_Time const & bbt)
TempoMap::set_tempo (Tempo const & t, BBT_Argument const & bbt)
{
return set_tempo (t, timepos_t (quarters_at (bbt)));
}
@ -1615,7 +1615,7 @@ TempoMap::set_meter (Meter const & m, timepos_t const & time)
}
MeterPoint &
TempoMap::set_meter (Meter const & t, BBT_Time const & bbt)
TempoMap::set_meter (Meter const & t, BBT_Argument const & bbt)
{
return set_meter (t, timepos_t (quarters_at (bbt)));
}
@ -1718,7 +1718,7 @@ TempoMap::superclock_at (Temporal::Beats const & qn) const
}
superclock_t
TempoMap::superclock_at (Temporal::BBT_Time const & bbt) const
TempoMap::superclock_at (Temporal::BBT_Argument const & bbt) const
{
return metric_at (bbt).superclock_at (bbt);
}
@ -1768,7 +1768,7 @@ TempoMap::bbtwalk_to_quarters (Beats const & pos, BBT_Offset const & distance) c
}
Temporal::Beats
TempoMap::bbtwalk_to_quarters (BBT_Time const & pos, BBT_Offset const & distance) const
TempoMap::bbtwalk_to_quarters (BBT_Argument const & pos, BBT_Offset const & distance) const
{
return quarters_at (bbt_walk (pos, distance)) - quarters_at (pos);
}
@ -2335,7 +2335,7 @@ std::operator<<(std::ostream& str, TempoMapPoint const & tmp)
}
BBT_Time
TempoMap::bbt_walk (BBT_Time const & bbt, BBT_Offset const & o) const
TempoMap::bbt_walk (BBT_Argument const & bbt, BBT_Offset const & o) const
{
BBT_Offset offset (o);
BBT_Time start (bbt);
@ -2469,7 +2469,7 @@ TempoMap::quarters_at (timepos_t const & pos) const
}
Temporal::Beats
TempoMap::quarters_at (Temporal::BBT_Time const & bbt) const
TempoMap::quarters_at (Temporal::BBT_Argument const & bbt) const
{
return metric_at (bbt).quarters_at (bbt);
}
@ -3053,7 +3053,7 @@ TempoMap::metric_at (Beats const & b, bool can_match) const
}
TempoMetric
TempoMap::metric_at (BBT_Time const & bbt, bool can_match) const
TempoMap::metric_at (BBT_Argument const & bbt, bool can_match) const
{
TempoPoint const * tp = 0;
MeterPoint const * mp = 0;

View File

@ -0,0 +1,48 @@
/*
Copyright (C) 2023 Paul Davis
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __libtemporal_bbt_argument_h__
#define __libtemporal_bbt_argument_h__
#include "temporal/bbt_time.h"
#include "temporal/timeline.h"
namespace Temporal {
struct LIBTEMPORAL_API BBT_Argument : public BBT_Time
{
public:
BBT_Argument () : BBT_Time (), _reference (Temporal::timepos_t (Temporal::BeatTime)) {}
BBT_Argument (int32_t B, int32_t b, int32_t t) : BBT_Time (B, b, t), _reference (Temporal::timepos_t (Temporal::BeatTime)) {}
BBT_Argument (Temporal::timepos_t const & r) : BBT_Time (), _reference (r) {}
BBT_Argument (Temporal::timepos_t const & r, int32_t B, int32_t b, int32_t t) : BBT_Time (B, b, t), _reference (r) {}
/*explicit*/ BBT_Argument (BBT_Time const & bbt) : BBT_Time (bbt), _reference (Temporal::timepos_t (Temporal::BeatTime)) {}
BBT_Argument (Temporal::timepos_t const & r, BBT_Time const & bbt) : BBT_Time (bbt), _reference (r) {}
Temporal::timepos_t reference() const { return _reference; }
private:
Temporal::timepos_t _reference;
};
} // end namespace
#endif /* __libtemporal_bbt_argument_h__ */

View File

@ -39,6 +39,7 @@
#include "temporal/visibility.h"
#include "temporal/beats.h"
#include "temporal/bbt_argument.h"
#include "temporal/bbt_time.h"
#include "temporal/superclock.h"
#include "temporal/timeline.h"
@ -736,12 +737,12 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
LIBTEMPORAL_API void set_bartime (BBT_Time const &, timepos_t const &, std::string name = std::string());
LIBTEMPORAL_API void remove_bartime (MusicTimePoint const & tp, bool with_reset = true);
LIBTEMPORAL_API TempoPoint& set_tempo (Tempo const &, BBT_Time const &);
LIBTEMPORAL_API TempoPoint& set_tempo (Tempo const &, BBT_Argument const &);
LIBTEMPORAL_API TempoPoint& set_tempo (Tempo const &, timepos_t const &);
LIBTEMPORAL_API void replace_tempo (TempoPoint const & old, Tempo const & thenew, timepos_t const &);
LIBTEMPORAL_API MeterPoint& set_meter (Meter const &, BBT_Time const &);
LIBTEMPORAL_API MeterPoint& set_meter (Meter const &, BBT_Argument const &);
LIBTEMPORAL_API MeterPoint& set_meter (Meter const &, timepos_t const &);
LIBTEMPORAL_API void remove_tempo (TempoPoint const &, bool with_reset = true);
@ -794,7 +795,7 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
*/
LIBTEMPORAL_API TempoMetric metric_at (superclock_t, bool can_match = true) const;
LIBTEMPORAL_API TempoMetric metric_at (Beats const &, bool can_match = true) const;
LIBTEMPORAL_API TempoMetric metric_at (BBT_Time const &, bool can_match = true) const;
LIBTEMPORAL_API TempoMetric metric_at (BBT_Argument const &, bool can_match = true) const;
private:
template<typename TimeType, typename Comparator> TempoPoint const & _tempo_at (TimeType when, Comparator cmp) const {
@ -835,12 +836,12 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
LIBTEMPORAL_API MeterPoint const& meter_at (timepos_t const & p) const;
LIBTEMPORAL_API MeterPoint const& meter_at (superclock_t sc) const { return _meter_at (sc, Point::sclock_comparator()); }
LIBTEMPORAL_API MeterPoint const& meter_at (Beats const & b) const { return _meter_at (b, Point::beat_comparator()); }
LIBTEMPORAL_API MeterPoint const& meter_at (BBT_Time const & bbt) const { return _meter_at (bbt, Point::bbt_comparator()); }
LIBTEMPORAL_API MeterPoint const& meter_at (BBT_Argument const & bbt) const { return _meter_at (bbt, Point::bbt_comparator()); }
LIBTEMPORAL_API TempoPoint const& tempo_at (timepos_t const & p) const;
LIBTEMPORAL_API TempoPoint const& tempo_at (superclock_t sc) const { return _tempo_at (sc, Point::sclock_comparator()); }
LIBTEMPORAL_API TempoPoint const& tempo_at (Beats const & b) const { return _tempo_at (b, Point::beat_comparator()); }
LIBTEMPORAL_API TempoPoint const& tempo_at (BBT_Time const & bbt) const { return _tempo_at (bbt, Point::bbt_comparator()); }
LIBTEMPORAL_API TempoPoint const& tempo_at (BBT_Argument const & bbt) const { return _tempo_at (bbt, Point::bbt_comparator()); }
/* convenience function that hides some complexities behind fetching
* the bpm at position
@ -848,22 +849,22 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
LIBTEMPORAL_API double quarters_per_minute_at (timepos_t const & pos) const;
/* convenience function */
LIBTEMPORAL_API BBT_Time round_to_bar (BBT_Time const & bbt) const {
LIBTEMPORAL_API BBT_Time round_to_bar (BBT_Argument const & bbt) const {
return metric_at (bbt).meter().round_to_bar (bbt);
}
LIBTEMPORAL_API BBT_Time bbt_at (timepos_t const &) const;
LIBTEMPORAL_API BBT_Time bbt_at (Beats const &) const;
LIBTEMPORAL_API Beats quarters_at (BBT_Time const &) const;
LIBTEMPORAL_API Beats quarters_at (BBT_Argument const &) const;
LIBTEMPORAL_API Beats quarters_at (timepos_t const &) const;
LIBTEMPORAL_API superclock_t superclock_at (Beats const &) const;
LIBTEMPORAL_API superclock_t superclock_at (BBT_Time const &) const;
LIBTEMPORAL_API superclock_t superclock_at (BBT_Argument const &) const;
LIBTEMPORAL_API superclock_t superclock_at (timepos_t const &) const;
LIBTEMPORAL_API samplepos_t sample_at (Beats const & b) const { return superclock_to_samples (superclock_at (b), TEMPORAL_SAMPLE_RATE); }
LIBTEMPORAL_API samplepos_t sample_at (BBT_Time const & b) const { return superclock_to_samples (superclock_at (b), TEMPORAL_SAMPLE_RATE); }
LIBTEMPORAL_API samplepos_t sample_at (BBT_Argument const & b) const { return superclock_to_samples (superclock_at (b), TEMPORAL_SAMPLE_RATE); }
LIBTEMPORAL_API samplepos_t sample_at (timepos_t const & t) const { return superclock_to_samples (superclock_at (t), TEMPORAL_SAMPLE_RATE); }
/* ways to walk along the tempo map, measure distance between points,
@ -875,11 +876,11 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
LIBTEMPORAL_API timecnt_t bbt_duration_at (timepos_t const & pos, BBT_Offset const & bbt) const;
LIBTEMPORAL_API Beats bbtwalk_to_quarters (Beats const & start, BBT_Offset const & distance) const;
LIBTEMPORAL_API Beats bbtwalk_to_quarters (BBT_Time const & start, BBT_Offset const & distance) const;
LIBTEMPORAL_API Beats bbtwalk_to_quarters (BBT_Argument const & start, BBT_Offset const & distance) const;
LIBTEMPORAL_API Temporal::timecnt_t convert_duration (Temporal::timecnt_t const & duration, Temporal::timepos_t const &, Temporal::TimeDomain domain) const;
LIBTEMPORAL_API BBT_Time bbt_walk (BBT_Time const &, BBT_Offset const &) const;
LIBTEMPORAL_API BBT_Time bbt_walk (BBT_Argument const &, BBT_Offset const &) const;
LIBTEMPORAL_API void get_grid (TempoMapPoints & points, superclock_t start, superclock_t end, uint32_t bar_mod = 0, uint32_t beat_div = 1) const;
LIBTEMPORAL_API uint32_t count_bars (Beats const & start, Beats const & end) const;
@ -1022,7 +1023,7 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
* other similar call sites where we do not modify the map
*/
Points::const_iterator get_tempo_and_meter (TempoPoint const *& t, MeterPoint const *& m, BBT_Time const & bbt, bool can_match, bool ret_iterator_after_not_at) const {
Points::const_iterator get_tempo_and_meter (TempoPoint const *& t, MeterPoint const *& m, BBT_Argument const & bbt, bool can_match, bool ret_iterator_after_not_at) const {
/* because `this` is const (because the method is marked
* const), the following: