temporal: some cleanup of the GridIterator API
This commit is contained in:
parent
a857a0af4d
commit
cbaa335946
@ -299,7 +299,7 @@ Session::locate (samplepos_t target_sample, bool for_loop_end, bool force, bool
|
||||
}
|
||||
|
||||
_last_roll_location = _last_roll_or_reversal_location = _transport_sample;
|
||||
_click_iterator.valid = false;
|
||||
_click_iterator.invalidate ();
|
||||
|
||||
Located (); /* EMIT SIGNAL */
|
||||
}
|
||||
|
@ -774,6 +774,17 @@ MusicTimePoint::set_name (std::string const & str)
|
||||
/* XXX need a signal or something to announce change */
|
||||
}
|
||||
|
||||
bool
|
||||
GridIterator::valid_for (TempoMap const & m, superclock_t start) const
|
||||
{
|
||||
if (!valid || start != end || map != &m) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* TEMPOMAP */
|
||||
|
||||
TempoMap::TempoMap (Tempo const & initial_tempo, Meter const & initial_meter)
|
||||
@ -2540,15 +2551,16 @@ TempoMap::get_grid (TempoMapPoints& ret, superclock_t rstart, superclock_t end,
|
||||
void
|
||||
TempoMap::get_grid_with_iterator (GridIterator& iter, TempoMapPoints& ret, superclock_t rstart, superclock_t end, uint32_t bar_mod, uint32_t beat_div) const
|
||||
{
|
||||
DEBUG_TRACE (DEBUG::Grid, string_compose (">>> GRID-I START %1 .. %2 (barmod = %3) iter valid ? %4 iter for %5\n", rstart, end, bar_mod, iter.valid, iter.end));
|
||||
DEBUG_TRACE (DEBUG::Grid, string_compose (">>> GRID-I START %1 .. %2 (barmod = %3) iter valid ? %4 iter for %5\n", rstart, end, bar_mod, iter.valid_for (*this, rstart), iter.end));
|
||||
|
||||
if (!iter.valid || rstart != iter.end) {
|
||||
if (!iter.valid_for (*this, rstart)) {
|
||||
std::cerr << "iterator @ " << &iter << " invalid, valid = " << iter.valid_for (*this, rstart) << " end " << iter.end << " rs " << rstart << std::endl;
|
||||
Points::const_iterator p = get_grid (ret, rstart, end, bar_mod, beat_div);
|
||||
if (!ret.empty()) {
|
||||
TempoMapPoint& tmp (ret.back());
|
||||
iter = GridIterator (&tmp.tempo(), &tmp.meter(), tmp.sclock(), tmp.beats(), tmp.bbt(), p, end);
|
||||
iter = GridIterator (*this, &tmp.tempo(), &tmp.meter(), tmp.sclock(), tmp.beats(), tmp.bbt(), p, end);
|
||||
} else {
|
||||
iter.end = end;
|
||||
iter.catch_up_to (end);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -2567,9 +2579,9 @@ TempoMap::get_grid_with_iterator (GridIterator& iter, TempoMapPoints& ret, super
|
||||
|
||||
if (!ret.empty()) {
|
||||
TempoMapPoint& tmp (ret.back());
|
||||
iter = GridIterator (&metric.tempo(), &metric.meter(), tmp.sclock(), tmp.beats(), tmp.bbt(), p, end);
|
||||
iter = GridIterator (*this, &metric.tempo(), &metric.meter(), tmp.sclock(), tmp.beats(), tmp.bbt(), p, end);
|
||||
} else {
|
||||
iter.end = end;
|
||||
iter.catch_up_to (end);
|
||||
}
|
||||
|
||||
DEBUG_TRACE (DEBUG::Grid, "<<< GRID-I DONE\n");
|
||||
|
@ -647,23 +647,28 @@ typedef boost::intrusive::list<MeterPoint, boost::intrusive::base_hook<meter_hoo
|
||||
typedef boost::intrusive::list<MusicTimePoint, boost::intrusive::base_hook<bartime_hook>> MusicTimes;
|
||||
typedef boost::intrusive::list<Point, boost::intrusive::base_hook<point_hook>> Points;
|
||||
|
||||
struct LIBTEMPORAL_API GridIterator
|
||||
class LIBTEMPORAL_API GridIterator
|
||||
{
|
||||
GridIterator () : valid (false), sclock (0), tempo (nullptr), meter (nullptr), end (0) {}
|
||||
GridIterator (TempoPoint const * tp, MeterPoint const * mp, superclock_t sc, Beats const & b, BBT_Time const & bb, Points::const_iterator p, superclock_t e)
|
||||
: valid (false)
|
||||
, sclock (sc)
|
||||
public:
|
||||
GridIterator () : sclock (0), tempo (nullptr), meter (nullptr), end (0), valid (false), map (nullptr) {}
|
||||
GridIterator (TempoMap const & m, TempoPoint const * tp, MeterPoint const * mp, superclock_t sc, Beats const & b, BBT_Time const & bb, Points::const_iterator p, superclock_t e)
|
||||
: sclock (sc)
|
||||
, beats (b)
|
||||
, bbt (bb)
|
||||
, tempo (tp)
|
||||
, meter (mp)
|
||||
, points_iterator (p)
|
||||
, end (e)
|
||||
, valid (false)
|
||||
, map (&m)
|
||||
{
|
||||
valid = (tempo && meter);
|
||||
}
|
||||
|
||||
bool valid;
|
||||
bool valid_for (TempoMap const & map, superclock_t start) const;
|
||||
void catch_up_to (superclock_t e) { end = e; }
|
||||
void invalidate () { valid = false; }
|
||||
|
||||
superclock_t sclock;
|
||||
Beats beats;
|
||||
BBT_Time bbt;
|
||||
@ -671,6 +676,10 @@ struct LIBTEMPORAL_API GridIterator
|
||||
MeterPoint const * meter;
|
||||
Points::const_iterator points_iterator;
|
||||
superclock_t end;
|
||||
|
||||
private:
|
||||
bool valid;
|
||||
TempoMap const * map;
|
||||
};
|
||||
|
||||
class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
|
||||
@ -940,11 +949,14 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
|
||||
Meters const & meters() const { return _meters; }
|
||||
MusicTimes const & bartimes() const { return _bartimes; }
|
||||
|
||||
|
||||
LIBTEMPORAL_API Points::const_iterator get_grid (TempoMapPoints & points, superclock_t start, superclock_t end, uint32_t bar_mod = 0, uint32_t beat_div = 1) const;
|
||||
|
||||
LIBTEMPORAL_API void grid (TempoMapPoints& points, superclock_t start, superclock_t end, uint32_t bar_mod = 0, uint32_t beat_div = 1) const {
|
||||
get_grid (points, start, end, bar_mod, beat_div);
|
||||
}
|
||||
|
||||
LIBTEMPORAL_API Points::const_iterator get_grid (TempoMapPoints & points, superclock_t start, superclock_t end, uint32_t bar_mod = 0, uint32_t beat_div = 1) const;
|
||||
|
||||
LIBTEMPORAL_API void get_grid_with_iterator (GridIterator& iter, TempoMapPoints& ret, superclock_t rstart, superclock_t end, uint32_t bar_mod = 0, uint32_t beat_div = 1) const;
|
||||
|
||||
struct EmptyTempoMapException : public std::exception {
|
||||
|
Loading…
Reference in New Issue
Block a user