Ardour  9.0-pre0-1786-g726295c4ce
temporal/temporal/tempo.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 Paul Davis
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18 
19 #pragma once
20 
21 #include <list>
22 #include <string>
23 #include <vector>
24 #include <cmath>
25 #include <exception>
26 #include <unordered_map>
27 
28 #include <boost/intrusive/list.hpp>
29 
30 #include <glibmm/threads.h>
31 
32 #include "pbd/command.h"
33 #include "pbd/enum_convert.h"
34 #include "pbd/integer_division.h"
35 #include "pbd/memento_command.h"
36 #include "pbd/rcu.h"
37 #include "pbd/signals.h"
39 
40 #include "temporal/visibility.h"
41 #include "temporal/beats.h"
42 #include "temporal/bbt_argument.h"
43 #include "temporal/bbt_time.h"
44 #include "temporal/domain_swap.h"
45 #include "temporal/superclock.h"
46 #include "temporal/timeline.h"
47 #include "temporal/types.h"
48 
49 /* A tempo map is built from 3 types of entities
50 
51  1) tempo markers
52  2) meter (time signature) markers
53  3) position markers
54 
55  Beats increase monotonically throughout the tempo map (BBT may not).
56 
57  The map has a single time domain at any time.
58 */
59 
60 namespace Temporal {
61 
62 class Meter;
63 class TempoMap;
64 class TempoMapCutBuffer;
65 class ScopedTempoMapOwner;
66 
67 class MapOwned {
68  protected:
69  MapOwned (TempoMap const & map) : _map (&map) {}
70  virtual ~MapOwned () {}
71 
72  public:
73  TempoMap const & map() const { return *_map; }
74 
75  protected:
76  friend class TempoMap;
77  void set_map (TempoMap const & map) { _map = &map; }
78  TempoMap const * _map;
79 };
80 
81 /* Conceptually, Point is similar to timepos_t. However, whereas timepos_t can
82  * use the TempoMap to translate between time domains, Point cannot. Why not?
83  * Because Point is foundational in building the tempo map, and we cannot
84  * create a circular functional dependency between them. So a Point always has
85  * its superclock and beat time defined and no translation between them is possible.
86  */
87 
88 typedef boost::intrusive::list_base_hook<boost::intrusive::tag<struct point_tag>> point_hook;
89 class /*LIBTEMPORAL_API*/ Point : public point_hook, public MapOwned {
90  public:
91  LIBTEMPORAL_API Point (TempoMap const & map, superclock_t sc, Beats const & b, BBT_Time const & bbt) : MapOwned (map), _sclock (sc), _quarters (b), _bbt (bbt) {}
93 
94  LIBTEMPORAL_API virtual ~Point() {}
95 
96  LIBTEMPORAL_API void set (superclock_t sc, Beats const & b, BBT_Time const & bbt) {
97  _sclock = sc;
98  _quarters = b;
99  _bbt = bbt;
100  }
101 
103  LIBTEMPORAL_API Beats const & beats() const { return _quarters; }
104  LIBTEMPORAL_API BBT_Time const & bbt() const { return _bbt; }
105  LIBTEMPORAL_API samplepos_t sample (int sr) const { return superclock_to_samples (sclock(), sr); }
106 
107  LIBTEMPORAL_API virtual timepos_t time() const = 0;
108 
110  bool operator() (Point const & a, Point const & b) const {
111  return a.sclock() < b.sclock();
112  }
113  bool operator() (Point const & a, superclock_t sc) const {
114  return a.sclock() < sc;
115  }
116  };
117 
119  bool operator() (Point const * a, Point const * b) const {
120  return a->sclock() < b->sclock();
121  }
122  };
123 
125  bool operator() (Point const & a, Point const & b) const {
126  return a.beats() < b.beats();
127  }
128  bool operator() (Point const & a, Beats const & beats) const {
129  return a.beats() < beats;
130  }
131  };
132 
134  bool operator() (Point const & a, Point const & b) const {
135  return a.bbt() < b.bbt();
136  }
137  bool operator() (Point const & a, BBT_Time const & bbt) const {
138  return a.bbt() < bbt;
139  }
140  };
141 
142  /* all time members are supposed to be synced at all times, so we need
143  test only one.
144  */
145  LIBTEMPORAL_API inline bool operator== (Point const & other) const { return _sclock == other._sclock; }
146  LIBTEMPORAL_API inline bool operator!= (Point const & other) const { return _sclock != other._sclock; }
147 
148  protected:
152 
153  void add_state (XMLNode &) const;
154 
155  protected:
156  friend class TempoMap;
158 };
159 
164  public:
165  enum Type {
167  Constant
168  };
169 
170  static std::string xml_node_name;
171 
172  Tempo (XMLNode const &);
173  virtual ~Tempo () {}
174 
179  Tempo (double npm, int8_t note_type)
180  : _npm (npm)
181  , _enpm (npm)
182  , _superclocks_per_note_type (double_npm_to_scpn (npm))
183  , _end_superclocks_per_note_type (double_npm_to_scpn (npm))
184  , _note_type (note_type)
185  , _locked_to_meter (false)
186  , _continuing (false)
187  {}
188 
189  Tempo (double npm, double enpm, int8_t note_type)
190  : _npm (npm)
191  , _enpm (npm)
192  , _superclocks_per_note_type (double_npm_to_scpn (npm))
193  , _end_superclocks_per_note_type (double_npm_to_scpn (enpm))
194  , _note_type (note_type)
195  , _locked_to_meter (false)
196  , _continuing (false)
197  {}
198 
199  /* these five methods should only be used to show and collect information to the user (for whom
200  * bpm as a floating point number is the obvious representation)
201  */
202  double note_types_per_minute () const { return ((double) superclock_ticks_per_second() * 60.0) / (double) _superclocks_per_note_type; }
203  double end_note_types_per_minute () const { return ((double) superclock_ticks_per_second() * 60.0) / (double) _end_superclocks_per_note_type; }
204  double quarter_notes_per_minute() const { return ((double) superclock_ticks_per_second() * 60.0 * 4.0) / (_note_type * (double) _superclocks_per_note_type); }
205  double samples_per_note_type(int sr) const { return superclock_to_samples (superclocks_per_note_type (), sr); }
206  double samples_per_quarter_note(int sr) const { return superclock_to_samples (superclocks_per_quarter_note(), sr); }
207 
208  void set_note_types_per_minute (double npm);
209 
210  int note_type () const { return _note_type; }
211 
213  return _superclocks_per_note_type;
214  }
215  superclock_t superclocks_per_note_type (int note_type) const {
216  return (_superclocks_per_note_type * _note_type) / note_type;
217  }
219  return superclocks_per_note_type (4);
220  }
222  return _end_superclocks_per_note_type;
223  }
225  return (_end_superclocks_per_note_type * _note_type) / note_type;
226  }
228  return end_superclocks_per_note_type (4);
229  }
230 
231  bool locked_to_meter () const { return _locked_to_meter; }
232  void set_locked_to_meter (bool yn) { _locked_to_meter = yn; }
233 
234  bool continuing() const { return _continuing; }
235  void set_continuing (bool yn);
236 
237  Type type() const { return _superclocks_per_note_type == _end_superclocks_per_note_type ? Constant : Ramped; }
238  bool ramped () const { return _superclocks_per_note_type != _end_superclocks_per_note_type; }
239 
240  XMLNode& get_state () const;
241  int set_state (XMLNode const&, int version);
242 
243  bool operator== (Tempo const & other) const {
244  return _superclocks_per_note_type == other._superclocks_per_note_type &&
245  _end_superclocks_per_note_type == other._end_superclocks_per_note_type &&
246  _note_type == other._note_type &&
247  _locked_to_meter == other._locked_to_meter &&
248  _continuing == other._continuing;
249  }
250 
251  bool operator!= (Tempo const & other) const {
252  return _superclocks_per_note_type != other._superclocks_per_note_type ||
253  _end_superclocks_per_note_type != other._end_superclocks_per_note_type ||
254  _note_type != other._note_type ||
255  _locked_to_meter != other._locked_to_meter ||
256  _continuing != other._continuing;
257  }
258 
259  protected:
260  double _npm;
261  double _enpm;
264  int8_t _note_type;
265  bool _locked_to_meter; /* XXX name has unclear meaning with nutempo */
266  bool _continuing; /* true if our effective end tempo is defined
267  * by the following tempo in the TempoMap;
268  * false if we use our own end tempo. */
269 
270  static inline superclock_t double_npm_to_scpn (double npm) { return (superclock_t) llround ((60./npm) * superclock_ticks_per_second()); }
271 
272  protected:
273  friend class TempoMap;
274  void set_end_npm (double);
275 };
276 
279  public:
280 
281  static std::string xml_node_name;
282 
283  Meter (XMLNode const &);
284  Meter (int8_t dpb, int8_t nv) : _note_value (nv), _divisions_per_bar (dpb) {}
285  Meter (Meter const & other) : _note_value (other._note_value), _divisions_per_bar (other._divisions_per_bar) {}
286 
287  virtual ~Meter () {}
288 
289  int divisions_per_bar () const { return _divisions_per_bar; }
290  int note_value() const { return _note_value; }
291 
292  int32_t ticks_per_grid () const { return (4 * Beats::PPQN) / _note_value; }
293 
294  inline bool operator==(const Meter& other) const { return _divisions_per_bar == other.divisions_per_bar() && _note_value == other.note_value(); }
295  inline bool operator!=(const Meter& other) const { return _divisions_per_bar != other.divisions_per_bar() || _note_value != other.note_value(); }
296 
297  Meter& operator=(Meter const & other) {
298  if (&other != this) {
299  _divisions_per_bar = other._divisions_per_bar;
300  _note_value = other._note_value;
301  }
302  return *this;
303  }
304 
305  BBT_Offset bbt_delta (BBT_Time const & later, BBT_Time const &earlier) const;
306  BBT_Time bbt_add (BBT_Time const & bbt, BBT_Offset const & add) const;
307  BBT_Time bbt_subtract (BBT_Time const & bbt, BBT_Offset const & sub) const;
308  BBT_Time round_to_bar (BBT_Time const &) const;
310  BBT_Time round_up_to_beat_div (BBT_Time const &, int beat_div) const;
311  BBT_Time round_up_to_beat (BBT_Time const & bbt) const { return round_up_to_beat_div (bbt, 1); }
312  BBT_Time round_to_beat (BBT_Time const &) const;
313  Beats to_quarters (BBT_Offset const &) const;
314 
315  Beats round_to_beat (Beats const &) const;
316 
317  XMLNode& get_state () const;
318  int set_state (XMLNode const&, int version);
319 
320  protected:
324  int8_t _note_value;
325  /* how many of '_note_value' make up a bar or measure */
327 };
328 
329 /* A MeterPoint is literally just the combination of a Meter with a Point
330  */
331 typedef boost::intrusive::list_base_hook<boost::intrusive::tag<struct meterpoint_tag>> meter_hook;
332 class /*LIBTEMPORAL_API*/ MeterPoint : public Meter, public meter_hook, public virtual Point
333 {
334  public:
335  LIBTEMPORAL_API MeterPoint (TempoMap const & map, Meter const & m, superclock_t sc, Beats const & b, BBT_Time const & bbt) : Point (map, sc, b, bbt), Meter (m) {}
337  LIBTEMPORAL_API MeterPoint (Meter const & m, Point const & p) : Point (p), Meter (m) {}
338 
339  virtual ~MeterPoint () {}
340 
343 
344  LIBTEMPORAL_API bool operator== (MeterPoint const & other) const {
345  return Meter::operator== (other) && Point::operator== (other);
346  }
347  LIBTEMPORAL_API bool operator!= (MeterPoint const & other) const {
348  return Meter::operator!= (other) || Point::operator!= (other);
349  }
350 
352 
353  LIBTEMPORAL_API timepos_t time() const { return timepos_t (beats()); }
354 };
355 
356 /* A TempoPoint is a combination of a Tempo with a Point. However, if the temp
357  * is ramped, then at some point we will need to compute the ramp coefficient
358  * (_omega) and store it so that we can compute tempo-at-time and
359  * time-at-quarter-note on demand.
360  */
361 
362 typedef boost::intrusive::list_base_hook<boost::intrusive::tag<struct tempo_tag>> tempo_hook;
363 class /*LIBTEMPORAL_API*/ TempoPoint : public Tempo, public tempo_hook, public virtual Point
364 {
365  public:
366  LIBTEMPORAL_API TempoPoint (TempoMap const & map, Tempo const & t, superclock_t sc, Beats const & b, BBT_Time const & bbt) : Point (map, sc, b, bbt), Tempo (t), _omega (0.) {}
367  LIBTEMPORAL_API TempoPoint (Tempo const & t, Point const & p) : Point (p), Tempo (t), _omega (0.) {}
369 
370  virtual ~TempoPoint () {}
371 
372  /* just change the tempo component, without moving */
374  *((Tempo*)this) = t;
375  return *this;
376  }
377 
378  /* Given that this tempo point controls tempo for the time indicated by
379  * the argument of the following 3 functions, return information about
380  * that time. The first 3 return convert between domains (with
381  * ::sample_at() just being a convenience function); the third returns
382  * information about the tempo at that time.
383  */
384 
388 
389  /* XXX at some point, we have had discussions about representing tempo
390  * as a rational number rather than a double. We have not reached that
391  * point yet (Nov 2021), and so at this point, this method is the
392  * canonical way to get "bpm at position" from a TempoPoint object.
393  */
394 
397  }
398 
399  LIBTEMPORAL_API double omega() const { return _omega; }
400 
402  LIBTEMPORAL_API void compute_omega_from_distance_and_next_tempo (Beats const & quarter_duration, TempoPoint const & next_tempo);
403  LIBTEMPORAL_API void compute_omega_from_quarter_duration (Beats const & quarter_duration, superclock_t end_scpqn);
404 
405  LIBTEMPORAL_API bool actually_ramped () const { return Tempo::ramped() && ( _omega != 0); /* do not need to check both omegas */ }
406 
408  LIBTEMPORAL_API int set_state (XMLNode const&, int version);
409 
410  LIBTEMPORAL_API bool operator== (TempoPoint const & other) const {
411  return Tempo::operator== (other) && Point::operator== (other);
412  }
413  LIBTEMPORAL_API bool operator!= (TempoPoint const & other) const {
414  return Tempo::operator!= (other) || Point::operator!= (other);
415  }
416 
419 
420  LIBTEMPORAL_API timepos_t time() const { return timepos_t (beats()); }
421 
422  private:
423  double _omega;
424 
425  friend TempoMap;
426  void set_omega (double v);
427 };
428 
445 {
446  public:
447  TempoMetric (TempoPoint const & t, MeterPoint const & m);
448  virtual ~TempoMetric () {}
449 
450  superclock_t reftime() const { return _reftime; }
451 
452  TempoPoint const & tempo() const { return *_tempo; }
453  MeterPoint const & meter() const { return *_meter; }
454 
455  TempoPoint & get_editable_tempo() const { return *const_cast<TempoPoint*> (_tempo); }
456  MeterPoint & get_editable_meter() const { return *const_cast<MeterPoint*> (_meter); }
457 
458  /* even more convenient wrappers for individual aspects of a
459  * TempoMetric (i.e. just tempo or just meter information required
460  */
461 
462  superclock_t superclock_at (Beats const & qn) const { return _tempo->superclock_at (qn); }
463  samplepos_t sample_at (Beats const & qn) const { return _tempo->sample_at (qn); }
464  Beats quarters_at (BBT_Time const & bbt) const { return _meter->quarters_at (bbt); }
465  BBT_Argument bbt_at (Beats const & beats) const { return BBT_Argument (reftime(), _meter->bbt_at (beats)); }
466 
467  superclock_t superclocks_per_note_type () const { return _tempo->superclocks_per_note_type (); }
468  superclock_t end_superclocks_per_note_type () const {return _tempo->end_superclocks_per_note_type (); }
469  superclock_t superclocks_per_note_type (int note_type) const {return _tempo->superclocks_per_note_type (note_type); }
470  superclock_t superclocks_per_quarter_note () const {return _tempo->superclocks_per_quarter_note (); }
471 
472  int note_type () const { return _tempo->note_type(); }
473  int divisions_per_bar () const { return _meter->divisions_per_bar(); }
474  int note_value() const { return _meter->note_value(); }
475  BBT_Argument bbt_add (BBT_Time const & bbt, BBT_Offset const & add) const { return BBT_Argument (reftime(), _meter->bbt_add (bbt, add)); }
476  BBT_Argument bbt_subtract (BBT_Time const & bbt, BBT_Offset const & sub) const { return BBT_Argument (reftime(), _meter->bbt_subtract (bbt, sub)); }
477  BBT_Argument round_to_bar (BBT_Time const & bbt) const { return BBT_Argument (reftime(), _meter->round_to_bar (bbt)); }
478  BBT_Argument round_up_to_bar (BBT_Time const & bbt) const { return BBT_Argument (reftime(), _meter->round_up_to_bar (bbt)); }
479  Beats to_quarters (BBT_Offset const & bbo) const { return _meter->to_quarters (bbo); }
480  Beats round_to_beat (Beats const & b) const { return _meter->round_to_beat (b); }
481 
482  /* combination methods that require both tempo and meter information */
483 
485  return superclocks_per_grid () * _meter->divisions_per_bar();
486  }
488  return PBD::muldiv_round (_tempo->superclocks_per_note_type(), _tempo->note_type(), (int64_t) _meter->note_value());
489  }
490 
492  if (!_tempo->actually_ramped()) {
493  return _tempo->superclocks_per_note_type ();
494  }
495  return _tempo->superclocks_per_note_type() * exp (-_tempo->omega() * (sc - _tempo->sclock()));
496  }
497 
498  BBT_Argument bbt_at (timepos_t const &) const;
500 
502  return superclock_to_samples (superclocks_per_bar (), sr);
503  }
504 
505  Beats quarters_at_sample (samplepos_t sc) const { return quarters_at_superclock (samples_to_superclock (sc, TEMPORAL_SAMPLE_RATE)); }
506  Beats quarters_at_superclock (superclock_t sc) const { return _tempo->quarters_at_superclock (sc); }
507 
508  protected:
512 
513 };
514 
515 /* A music time point is a place where BBT time is reset from
516  * whatever it would be when just inferring from the usual counting. Its
517  * position is given by a Point that might use superclock or Beats, and the
518  * Point's BBT time member is overwritten.
519  */
520 typedef boost::intrusive::list_base_hook<boost::intrusive::tag<struct bartime_tag>> bartime_hook;
521 class /*LIBTEMPORAL_API*/ MusicTimePoint : public bartime_hook, public virtual TempoPoint, public virtual MeterPoint
522 {
523  public:
524  LIBTEMPORAL_API MusicTimePoint (TempoMap const & map, superclock_t sc, Beats const & b, BBT_Time const & bbt, Tempo const & t, Meter const & m, std::string name = std::string())
525  : Point (map, sc, b, bbt), TempoPoint (t, *this), MeterPoint (m, *this), _name (name) {}
526 
528 
529  virtual ~MusicTimePoint () {}
530 
531  LIBTEMPORAL_API bool operator== (MusicTimePoint const & other) const {
532  return TempoPoint::operator== (other) && MeterPoint::operator== (other);
533  }
534 
536 
537  LIBTEMPORAL_API std::string name() const { return _name; }
538  LIBTEMPORAL_API void set_name (std::string const &);
539 
541 
542  private:
543  std::string _name;
544 };
545 
550 /* TempoMap concepts
551 
552  we have several different ways of talking about time:
553 
554  * PULSE : whole notes, just because. These are linearly related to any other
555  note type, so if you know a number of pulses (whole notes), you
556  know the corresponding number of any other note type (e.g. quarter
557  notes).
558 
559  * QUARTER NOTES : just what the name says. A lot of MIDI software and
560  concepts assume that a "beat" is a quarter-note.
561 
562  * BEAT : a fraction of a PULSE. Defined by the meter in effect, so requires
563  meter (time signature) information to convert to/from PULSE or QUARTER NOTES.
564  In a 5/8 time, a BEAT is 1/8th note. In a 4/4 time, a beat is quarter note.
565  This means that measuring time in BEATS is potentially non-linear (if
566  the time signature changes, there will be a different number of BEATS
567  corresponding to a given time in any other unit).
568 
569  * SUPERCLOCK : a very high resolution clock whose frequency
570  has as factors all common sample rates and all common note
571  type divisors. Related to MINUTES or SAMPLES only when a
572  sample rate is known. Related to PULSE or QUARTER NOTES only
573  when a tempo is known.
574 
575  * MINUTES : wallclock time measurement. related to SAMPLES or SUPERCLOCK
576  only when a sample rate is known.
577 
578 
579  * SAMPLES : audio time measurement. Related to MINUTES or SUPERCLOCK only
580  when a sample rate is known
581 
582  * BBT : bars|beats|ticks ... linearly related to BEATS but with the added
583  semantics of bars ("measures") added, in which beats are broken up
584  into groups of bars ("measures"). Requires meter (time signature)
585  information to compute to/from a given BEATS value. Contains no
586  additional time information compared to BEATS, but does have
587  additional semantic information.
588 
589  Nick sez: not every note onset is on a tick
590  Paul wonders: if it's 8 samples off, does it matter?
591  Nick sez: it should not phase with existing audio
592 
593  */
594 
596 {
597  public:
598  TempoMapPoint (TempoMap const & map, TempoMetric const & tm, superclock_t sc, Beats const & q, BBT_Time const & bbt)
599  : Point (map, sc, q, bbt), TempoMetric (tm) {}
601 
602  bool is_explicit_meter() const { return _meter->sclock() == sclock(); }
603  bool is_explicit_tempo() const { return _tempo->sclock() == sclock(); }
604  bool is_explicit_position() const { return false; }
605  bool is_explicit () const { return is_explicit_meter() || is_explicit_tempo() || is_explicit_position(); }
606 
607  timepos_t time() const { if (is_explicit_meter()) { return _meter->time(); } else if (is_explicit_tempo()) { return _tempo->time(); } else { return timepos_t::from_superclock (sclock()); } }
608 };
609 
610 typedef std::vector<TempoMapPoint> TempoMapPoints;
611 
612 typedef boost::intrusive::list<TempoPoint, boost::intrusive::base_hook<tempo_hook>> Tempos;
613 typedef boost::intrusive::list<MeterPoint, boost::intrusive::base_hook<meter_hook>> Meters;
614 typedef boost::intrusive::list<MusicTimePoint, boost::intrusive::base_hook<bartime_hook>> MusicTimes;
615 typedef boost::intrusive::list<Point, boost::intrusive::base_hook<point_hook>> Points;
616 
617 /* An object used to retain "position" across calls to get_grid()
618  */
620 {
621  public:
622  GridIterator () : sclock (0), tempo (nullptr), meter (nullptr), end (0), bar_mod (0), beat_div (1), valid (false), map (nullptr) {}
623  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,
624  uint32_t bmod, uint32_t bdiv)
625  : sclock (sc)
626  , beats (b)
627  , bbt (bb)
628  , tempo (tp)
629  , meter (mp)
630  , points_iterator (p)
631  , end (e)
632  , bar_mod (bmod)
633  , beat_div (bdiv)
634  , valid (false)
635  , map (&m)
636  {
637  valid = (tempo && meter);
638  }
639 
640  void set (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,
641  uint32_t bmod, uint32_t bdiv) {
642  map = &m;
643  tempo = tp;
644  meter = mp;
645  sclock = sc;
646  beats = b;
647  bbt = bb;
648  points_iterator = p;
649  end = e;
650  bar_mod = bmod;
651  beat_div = bdiv;
652  }
653 
654  bool valid_for (TempoMap const & map, superclock_t start, uint32_t bar_mod, uint32_t beat_div) const;
655  void catch_up_to (superclock_t e) { end = e; }
656  void invalidate () { valid = false; }
657 
658 
659  /* These 3 members hold the position of the last discovered grid point */
663 
664  /* These 3 members hold the TempoMetric information that was in effect
665  * at the *end* of the last use of the GridIterator
666  */
667  TempoPoint const * tempo;
668  MeterPoint const * meter;
669 
670  /* the iterator in the tempo map's _points list that points to the next
671  * point to be considered, or _points.end()
672  */
673  Points::const_iterator points_iterator;
674 
675  /* The position of the end of the last use of the GridIterator. For the
676  iterator to be considered valid on the next call, the start must
677  match this value (see ::valid_for() above).
678  */
680 
681 
682  /* bar modulus and beat division used by GridIterator. These must match
683  the current call to ::get_grid() for the iterator to
684  be valid.
685  */
686 
687  uint32_t bar_mod;
688  uint32_t beat_div;
689 
690  private:
691  bool valid;
692 
693  TempoMap const * map; /* nullptr or the map instance this GridIterator
694  * was last used with.
695  */
696 };
697 
698 class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
699 {
700  /* Any given thread must be able to carry out tempo-related arithmetic
701  * and time domain conversions using a consistent version of a
702  * TempoMap. The map could be updated at any time, and for any reason
703  * (typically from a GUI thread), but some other thread could be
704  * using the map to convert from audio to music time (for example).
705  *
706  * We do not want to use locks for this - this math may happen in a
707  * realtime thread, and even worse, the lock may need to be held for
708  * long periods of time in order to have the desired effect: a thread
709  * may be performing some tempo-based arithmetic as part of a complex
710  * operation that requires multiple steps. The tempo map it uses must
711  * remain consistent across all steps, and so we would have to hold the
712  * lock across them all. That would create awkward and difficult
713  * semantics for map users - somewhat arbitrary rules about how long
714  * one could hold the map for, etc.
715  *
716  * Elsewhere in the codebase, we use RCU to solve this sort of
717  * issue. For example, if we need to operate on the current list of
718  * Routes, we get read-only copy of the list, and iterate over it,
719  * knowing that even if the canonical version is being changed, the
720  * copy we are using will not.
721  *
722  * However, the tempo map's use is often implicit rather than
723  * explicit. The callstack to convert between an audio domain time and
724  * a music domain time should not require passing a tempo map into
725  * every call.
726  *
727  * The approach taken here is to use a combination of RCU and
728  * thread-local variables. Any given thread is by definition ... single
729  * threaded. If the thread has a thread-local copy of a tempo map, it
730  * will not change except at explicit calls to change it. The tempo map
731  * can be accessed from any method executed by the thread. But the
732  * relationship between the thread-local copy and "actual" tempo map(s)
733  * is managed via RCU, meaning that read-only access is cheap (no
734  * actual copy required).
735  *
736  */
737  public:
738  typedef std::shared_ptr<TempoMap const> SharedPtr;
739  typedef std::shared_ptr<TempoMap> WritableSharedPtr;
740  private:
741  static thread_local SharedPtr _tempo_map_p;
743  static bool fetch_condition ();
744  public:
745  LIBTEMPORAL_API static void init ();
746 
748  LIBTEMPORAL_API static SharedPtr use() { assert (_tempo_map_p); return _tempo_map_p; }
750  /* No fetch condition for this, to be used only in association with LocalTempoMapScope */
751  LIBTEMPORAL_API static SharedPtr global_fetch() { return _map_mgr.reader(); }
752 
753  /* Used only by the ARDOUR::AudioEngine API to reset the process thread
754  * tempo map only when it has changed.
755  */
756 
757  LIBTEMPORAL_API static SharedPtr read() { return _map_mgr.reader(); }
758 
759  /* Because WritableSharedPtr can be implicitly cast to SharedPtr, this
760  * can be used on either a write_copy()'ed map, or one obtained via the
761  * RCU reader() method.
762  */
763  LIBTEMPORAL_API static void set (SharedPtr new_map) { _tempo_map_p = new_map; }
764 
765  /* API for typical tempo map changes */
766 
770 
771  /* not part of public API */
772  superclock_t reftime(TempoPoint const &, MeterPoint const &) const;
773 
774  /* and now on with the rest of the show ... */
775 
776  public:
778  LIBTEMPORAL_API TempoMap (Tempo const& initial_tempo, Meter const& initial_meter);
780  LIBTEMPORAL_API TempoMap (XMLNode const&, int version);
782 
783  /* For use ONLY when building a tempo map from an SMF tempo map */
788 
790 
792 
793  /* methods which modify the map. These must all be called using
794  * RCU-style semantics: get a writable copy, modify it, then update via
795  * the RCU manager.
796  */
797 
800 
802 
804 
805  LIBTEMPORAL_API void set_bartime (BBT_Time const &, timepos_t const &, std::string name = std::string());
806  LIBTEMPORAL_API void remove_bartime (MusicTimePoint const & tp, bool with_reset = true);
807  LIBTEMPORAL_API void replace_bartime (MusicTimePoint & tp, bool with_reset = true);
808 
811 
812  LIBTEMPORAL_API void replace_tempo (TempoPoint const & old, Tempo const & thenew, timepos_t const &);
813 
816 
817  LIBTEMPORAL_API void remove_tempo (TempoPoint const &, bool with_reset = true);
818  LIBTEMPORAL_API void remove_meter (MeterPoint const &, bool with_reset = true);
819 
820  /* these are a convenience method that just wrap some odd semantics */
821  LIBTEMPORAL_API bool move_tempo (TempoPoint const & point, timepos_t const & destination, bool push = false);
822  LIBTEMPORAL_API bool move_meter (MeterPoint const & point, timepos_t const & destination, bool push = false);
823 
824  LIBTEMPORAL_API int set_state (XMLNode const&, int version);
825 
826  LIBTEMPORAL_API void constant_twist_tempi (TempoPoint& prev, TempoPoint& focus, TempoPoint& next, double tempo_delta);
827  LIBTEMPORAL_API void ramped_twist_tempi (TempoPoint& prev, TempoPoint& focus, TempoPoint& next, double tempo_delta);
828 
829  LIBTEMPORAL_API void stretch_tempo (TempoPoint& ts, double new_npm);
831 
832  LIBTEMPORAL_API bool clear_tempos_before (timepos_t const &, bool stop_at_music_time);
833  LIBTEMPORAL_API bool clear_tempos_after (timepos_t const &, bool stop_at_music_time);
834 
835  /* END OF MODIFYING METHODS */
836 
837  /* rather than giving direct access to the intrusive list members,
838  * offer one that uses an STL container instead.
839  */
840 
841  typedef std::list<Point const *> Metrics;
842 
843  void get_metrics (Metrics& m) const {
844  for (auto const & p : _points) {
845  m.push_back (&p);
846  }
847  }
848 
849  LIBTEMPORAL_API bool can_remove (TempoPoint const &) const;
850  LIBTEMPORAL_API bool can_remove (MeterPoint const &) const;
851 
852  LIBTEMPORAL_API bool is_initial (TempoPoint const &) const;
853  LIBTEMPORAL_API bool is_initial (MeterPoint const &) const;
854 
855  LIBTEMPORAL_API uint32_t n_meters() const;
856  LIBTEMPORAL_API uint32_t n_tempos() const;
857 
860 
863 
864  LIBTEMPORAL_API bool tempo_exists_before (TempoPoint const & t) const { return (bool) previous_tempo (t); }
865  LIBTEMPORAL_API bool tempo_exists_after (TempoPoint const & t) const { return (bool) next_tempo (t); }
866 
867  LIBTEMPORAL_API Meter const* next_meter (Meter const &) const;
868 
870 
871  /* These return the TempoMetric in effect at the given time. If
872  can_match is true, then the TempoMetric may refer to a Tempo or
873  Meter at the given time. If can_match is false, the TempoMetric will
874  only refer to the Tempo or Metric preceding the given time.
875  */
876  LIBTEMPORAL_API TempoMetric metric_at (Beats const &, bool can_match = true) const;
877  LIBTEMPORAL_API TempoMetric metric_at (BBT_Argument const &, bool can_match = true) const;
878 
879  LIBTEMPORAL_API TempoMapCutBuffer* cut (timepos_t const & start, timepos_t const & end, bool ripple);
881  LIBTEMPORAL_API void paste (TempoMapCutBuffer const &, timepos_t const & position, bool ripple, std::string = std::string());
882 
883  LIBTEMPORAL_API void shift (timepos_t const & at, BBT_Offset const & by);
884  LIBTEMPORAL_API void shift (timepos_t const & at, timecnt_t const & by);
885 
887 
888  private:
889  template<typename TimeType, typename Comparator> TempoPoint const & _tempo_at (TimeType when, Comparator cmp) const {
890  assert (!_tempos.empty());
891 
892  if (_tempos.size() == 1) {
893  return _tempos.front();
894  }
895 
896  Tempos::const_iterator prev = _tempos.end();
897  for (Tempos::const_iterator t = _tempos.begin(); t != _tempos.end(); ++t) {
898  if (cmp (*t, when)) {
899  prev = t;
900  } else {
901  break;
902  }
903  }
904  if (prev == _tempos.end()) {
905  return _tempos.front();
906  }
907  return *prev;
908  }
909 
910  template<typename TimeType, typename Comparator> MeterPoint const & _meter_at (TimeType when, Comparator cmp) const {
911  assert (!_meters.empty());
912 
913  if (_meters.size() == 1) {
914  return _meters.front();
915  }
916 
917  Meters::const_iterator prev = _meters.end();
918  for (Meters::const_iterator m = _meters.begin(); m != _meters.end(); ++m) {
919  if (cmp (*m, when)) {
920  prev = m;
921  } else {
922  break;
923  }
924  }
925  if (prev == _meters.end()) {
926  return _meters.front();
927  }
928  return *prev;
929  }
930 
931  public:
932  LIBTEMPORAL_API MeterPoint const& meter_at (timepos_t const & p) const;
934  LIBTEMPORAL_API MeterPoint const& meter_at (Beats const & b) const { return _meter_at (b, Point::beat_comparator()); }
935  LIBTEMPORAL_API MeterPoint const& meter_at (BBT_Argument const & bbt) const { return _meter_at (bbt, Point::bbt_comparator()); }
936 
937  LIBTEMPORAL_API TempoPoint const& tempo_at (timepos_t const & p) const;
939  LIBTEMPORAL_API TempoPoint const& tempo_at (Beats const & b) const { return _tempo_at (b, Point::beat_comparator()); }
940  LIBTEMPORAL_API TempoPoint const& tempo_at (BBT_Argument const & bbt) const { return _tempo_at (bbt, Point::bbt_comparator()); }
941 
944 
945  /* convenience function that hides some complexities behind fetching
946  * the bpm at position
947  */
949 
950  /* convenience functions */
952  return metric_at (bbt).round_to_bar (bbt);
953  }
955  return metric_at (bbt).round_up_to_bar (bbt);
956  }
957 
960 
963 
967 
971 
972  /* ways to walk along the tempo map, measure distance between points,
973  * etc.
974  */
975 
978 
980  LIBTEMPORAL_API Beats bbtwalk_to_quarters (Beats const & start, BBT_Offset const & distance) const;
982 
984 
986 
988 
989  Tempos const & tempos() const { return _tempos; }
990  Meters const & meters() const { return _meters; }
991  MusicTimes const & bartimes() const { return _bartimes; }
992 
993 
994  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;
995  LIBTEMPORAL_API void get_grid (GridIterator& iter, TempoMapPoints& ret, superclock_t rstart, superclock_t end, uint32_t bar_mod = 0, uint32_t beat_div = 1) const;
996 
997  /* This version exists for Lua bindings, to avoid having to wrap Points::iterator etc. */
998  LIBTEMPORAL_API void grid (TempoMapPoints& points, superclock_t start, superclock_t end, uint32_t bar_mod = 0, uint32_t beat_div = 1) const {
999  get_grid (points, start, end, bar_mod, beat_div);
1000  }
1001 
1002  struct EmptyTempoMapException : public std::exception {
1003  virtual const char* what() const throw() { return "TempoMap is empty"; }
1004  };
1005 
1006  LIBTEMPORAL_API void dump (std::ostream&) const;
1007 
1009 
1011 
1014 
1015  LIBTEMPORAL_API void midi_clock_beat_at_or_after (samplepos_t const pos, samplepos_t& clk_pos, uint32_t& clk_beat) const;
1016 
1017  static void map_assert (bool expr, char const * exprstr, char const * file, int line);
1018 
1022 
1023  private:
1029 
1033 
1038 
1040 
1044 
1045  void add_point (Point &);
1046 
1048  void reset_starting_at (Beats const &);
1049 
1050  void remove_point (Point const &);
1051 
1052  void copy_points (TempoMap const & other);
1053 
1055 
1056  template<typename T, typename T1> struct const_traits {
1057  typedef Points::const_iterator iterator_type;
1058  typedef TempoPoint const * tempo_point_type;
1059  typedef MeterPoint const * meter_point_type;
1060  using time_reference = T;
1061  using time_type = T1;
1062  };
1063 
1064  template<typename T, typename T1> struct non_const_traits {
1065  typedef Points::iterator iterator_type;
1068  using time_reference = T;
1069  using time_type = T1;
1070  };
1071 
1072  /* A somewhat complex method that sets a TempoPoint* and MeterPoint* to
1073  * refer to the correct tempo and meter points for the given start
1074  * time.
1075  *
1076  * It also returns an iterator which may point at the latter of the two
1077  * points (tempo & meter; always the meter point if they are at the
1078  * same time) OR may point at the iterator *after* the latter of the
1079  * two, depending on whether or not @p ret_iterator_after_not_at is
1080  * true or false.
1081  *
1082  * If @p can_match is true, the points used can be located at the
1083  * given time. If false, they must be before it. Setting it to false is
1084  * useful when you need to know the TempoMetric in effect at a given
1085  * time if there was no tempo or meter point at that time.
1086  *
1087  * The templated structure here is to avoid code duplication in 2
1088  * separate versions of this method, one that would be const, and one
1089  * that would be non-const. This is a challenging problem in C++, and
1090  * seems best solved by using a "traits" object as shown here.
1091  *
1092  * The begini, endi, tstart and mstart arguments are an additional
1093  * complication. If we try to use e.g. _points.begin() inside the
1094  * method, which is labelled const, we will always get the const
1095  * version of the iterator. This const iterator type will conflict with
1096  * the non-const iterator type defined by the "non_const_traits"
1097  * type. The same happens with _tempos.front() etc. This problem is
1098  * addressed by calling these methods in the caller method, which maybe
1099  * const or non-const, and will provide appropriate versions based on that.
1100  */
1101 
1102  template<class constness_traits_t> typename constness_traits_t::iterator_type
1103  _get_tempo_and_meter (typename constness_traits_t::tempo_point_type &,
1104  typename constness_traits_t::meter_point_type &,
1105  typename constness_traits_t::time_reference (Point::*)() const,
1106  typename constness_traits_t::time_type,
1107  typename constness_traits_t::iterator_type begini,
1108  typename constness_traits_t::iterator_type endi,
1109  typename constness_traits_t::tempo_point_type tstart,
1110  typename constness_traits_t::meter_point_type mstart,
1111  bool can_match,
1112  bool ret_iterator_after_not_at) const;
1113 
1114  /* fetch non-const tempo/meter pairs and iterator (used in
1115  * ::reset_starting_at() in which we will modify points.
1116  */
1117 
1118  Points::iterator get_tempo_and_meter (TempoPoint *& t, MeterPoint *& m, superclock_t sc, bool can_match, bool ret_iterator_after_not_at) {
1119 
1120  /* because `this` is non-const (because the method is not
1121  * marked const), the following:
1122 
1123  _points.begin()
1124  _points.end()
1125  _tempos.front()
1126  _meters.front()
1127 
1128  will all be the non-const versions of these methods.
1129  */
1130 
1131  if (_tempos.size() == 1 && _meters.size() == 1) { t = &_tempos.front(); m = &_meters.front(); return _points.end(); }
1132  return _get_tempo_and_meter<non_const_traits<superclock_t, superclock_t> > (t, m, &Point::sclock, sc, _points.begin(), _points.end(), &_tempos.front(), &_meters.front(), can_match, ret_iterator_after_not_at);
1133  }
1134 
1135  /* fetch const tempo/meter pairs and iterator (used in metric_at() and
1136  * other similar call sites where we do not modify the map
1137  */
1138 
1139  Points::const_iterator get_tempo_and_meter (TempoPoint const *& t, MeterPoint const *& m, superclock_t sc, bool can_match, bool ret_iterator_after_not_at) const {
1140  if (_tempos.size() == 1 && _meters.size() == 1) { t = &_tempos.front(); m = &_meters.front(); return _points.end(); }
1141  return _get_tempo_and_meter<const_traits<superclock_t, superclock_t> > (t, m, &Point::sclock, sc, _points.begin(), _points.end(), &_tempos.front(), &_meters.front(), can_match, ret_iterator_after_not_at);
1142  }
1143  Points::const_iterator get_tempo_and_meter (TempoPoint const *& t, MeterPoint const *& m, Beats const & b, bool can_match, bool ret_iterator_after_not_at) const {
1144  if (_tempos.size() == 1 && _meters.size() == 1) { t = &_tempos.front(); m = &_meters.front(); return _points.end(); }
1145  return _get_tempo_and_meter<const_traits<Beats const &, Beats> > (t, m, &Point::beats, b, _points.begin(), _points.end(), &_tempos.front(), &_meters.front(), can_match, ret_iterator_after_not_at);
1146  }
1147  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 {
1148 
1149  if (_tempos.size() == 1 && _meters.size() == 1) { t = &_tempos.front(); m = &_meters.front(); return _points.end(); }
1150 
1151  /* Skip through the tempo map to find the tempo and meter in
1152  * effect at the bbt's "reference" time, and use them as the
1153  * starting point for the normal operation of
1154  * _get_tempo_and_meter ()
1155  */
1156 
1157  Tempos::const_iterator tp = _tempos.begin();
1158  Meters::const_iterator mp = _meters.begin();
1159  superclock_t ref = bbt.reference();
1160 
1161  if (ref != 0) {
1162  while (tp != _tempos.end()) {
1163  Tempos::const_iterator nxt = tp; ++nxt;
1164  if (nxt == _tempos.end() || nxt->sclock() > ref) {
1165  break;
1166  }
1167  tp = nxt;
1168  }
1169  while (mp != _meters.end()) {
1170  Meters::const_iterator nxt = mp; ++nxt;
1171  if (nxt == _meters.end() || mp->sclock() > ref) {
1172  break;
1173  }
1174  mp = nxt;
1175  }
1176  }
1177 
1178  return _get_tempo_and_meter<const_traits<BBT_Time const &, BBT_Time> > (t, m, &Point::bbt, bbt, _points.begin(), _points.end(), &(*tp), &(*mp), can_match, ret_iterator_after_not_at);
1179  }
1180 
1181  /* This is private, and should not be callable from outside the map
1182  because of potential confusion between samplepos_t and
1183  superclock_t. The timepos_t variant of ::metric_at() handles any
1184  samplepos_t-passing call.
1185  */
1186  TempoMetric metric_at (superclock_t, bool can_match = true) const;
1187 
1188  /* parsing legacy tempo maps */
1189 
1191  {
1193  double pulses;
1196  double note_type;
1197  bool continuing; /* "clamped" in actual legacy stuff */
1198  };
1199 
1201  {
1203  double pulses;
1205  double beat;
1207  double note_type;
1208  };
1209 
1212  int set_state_3x (XMLNode const &);
1213  TempoPoint & set_tempo (Tempo const & t, timepos_t const & time, Beats const & beats);
1214 
1215  friend class TempoPoint;
1216  friend class MeterPoint;
1217  friend class TempoMetric;
1218 
1219  bool solve_ramped_twist (TempoPoint&, TempoPoint&); /* this is implemented by iteration, and it might fail. */
1220  bool solve_constant_twist (TempoPoint&, TempoPoint&); //TODO: currently also done by iteration; should be possible to calculate directly
1221 
1225 
1226  void reset_section (Points::iterator& begin, Points::iterator& end, superclock_t, TempoMetric& metric);
1227 
1228  TempoMapCutBuffer* cut_copy (timepos_t const & start, timepos_t const & end, bool copy, bool ripple);
1229 
1230  void fill_grid_by_walking (TempoMapPoints& ret, Points::const_iterator& p, TempoMetric& metric, superclock_t& start, superclock_t rstart,
1231  superclock_t end, int bar_mod, int beat_div, Beats& beats, BBT_Time& bbt) const;
1232  void fill_grid_with_final_metric (TempoMapPoints& ret, TempoMetric metric, superclock_t start, superclock_t rstart, superclock_t end, int bar_mod, int beat_div, Beats beats, BBT_Time bbt) const;
1233 };
1234 
1236 {
1237  public:
1240 
1241  timecnt_t duration() const { return _duration; }
1242 
1243  void add_start_tempo (Tempo const & t);
1244  void add_end_tempo (Tempo const & t);
1245  void add_start_meter (Meter const & t);
1246  void add_end_meter (Meter const & t);
1247 
1248  Tempo const * start_tempo () const { return _start_tempo; }
1249  Tempo const * end_tempo () const { return _end_tempo; }
1250 
1251  Meter const * start_meter () const { return _start_meter; }
1252  Meter const * end_meter () const { return _end_meter; }
1253 
1254  typedef boost::intrusive::list<TempoPoint, boost::intrusive::base_hook<tempo_hook>> Tempos;
1255  typedef boost::intrusive::list<MeterPoint, boost::intrusive::base_hook<meter_hook>> Meters;
1256  typedef boost::intrusive::list<MusicTimePoint, boost::intrusive::base_hook<bartime_hook>> MusicTimes;
1257  typedef boost::intrusive::list<Point, boost::intrusive::base_hook<point_hook>> Points;
1258 
1259  void add (TempoPoint const &);
1260  void add (MeterPoint const &);
1261  void add (MusicTimePoint const &);
1262  void add (Point const &);
1263 
1264  void clear ();
1265  void dump (std::ostream&);
1266 
1267  Tempos const & tempos() const { return _tempos; }
1268  Meters const & meters() const { return _meters; }
1269  MusicTimes const & bartimes() const { return _bartimes; }
1270  Points const & points() const { return _points; }
1271 
1272  bool empty() const {
1273  return _tempos.empty() && _meters.empty() && _bartimes.empty() && _points.empty();
1274  }
1275 
1276  private:
1282 
1287 };
1288 
1290  public:
1291 
1292  TempoCommand (std::string const & name, XMLNode const * before, XMLNode const * after);
1295 
1296  const std::string& name () const { return _name; }
1297 
1298  void operator() ();
1299  void undo ();
1300 
1301  XMLNode & get_state () const;
1302 
1303  protected:
1304  std::string _name;
1305  XMLNode const * _before;
1306  XMLNode const * _after;
1307 };
1308 
1309 } /* end of namespace Temporal */
1310 
1311 #ifdef COMPILER_MSVC
1312 #pragma warning(disable:4101)
1313 #endif
1314 
1315 namespace std {
1316 LIBTEMPORAL_API std::ostream& operator<<(std::ostream& str, Temporal::TempoMapPoint const &);
1317 LIBTEMPORAL_API std::ostream& operator<<(std::ostream& str, Temporal::Tempo const &);
1318 LIBTEMPORAL_API std::ostream& operator<<(std::ostream& str, Temporal::Meter const &);
1319 LIBTEMPORAL_API std::ostream& operator<<(std::ostream& str, Temporal::Point const &);
1320 LIBTEMPORAL_API std::ostream& operator<<(std::ostream& str, Temporal::TempoPoint const &);
1321 LIBTEMPORAL_API std::ostream& operator<<(std::ostream& str, Temporal::MeterPoint const &);
1322 LIBTEMPORAL_API std::ostream& operator<<(std::ostream& str, Temporal::MusicTimePoint const &);
1323 LIBTEMPORAL_API std::ostream& operator<<(std::ostream& str, Temporal::TempoMetric const &);
1324 }
std::ostream & operator<<(std::ostream &o, ARDOUR::Bundle const &)
static const int32_t PPQN
Definition: beats.h:67
Beats round_to_beat() const
Definition: beats.h:130
bool valid_for(TempoMap const &map, superclock_t start, uint32_t bar_mod, uint32_t beat_div) const
Points::const_iterator points_iterator
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, uint32_t bmod, uint32_t bdiv)
void catch_up_to(superclock_t e)
void set(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, uint32_t bmod, uint32_t bdiv)
TempoMap const & map() const
MapOwned(TempoMap const &map)
void set_map(TempoMap const &map)
MeterPoint(TempoMap const &map, XMLNode const &)
MeterPoint(TempoMap const &map, Meter const &m, superclock_t sc, Beats const &b, BBT_Time const &bbt)
Beats quarters_at(BBT_Time const &bbt) const
XMLNode & get_state() const
BBT_Time bbt_at(Beats const &beats) const
bool operator==(MeterPoint const &other) const
MeterPoint(Meter const &m, Point const &p)
bool operator!=(MeterPoint const &other) const
BBT_Time bbt_subtract(BBT_Time const &bbt, BBT_Offset const &sub) const
BBT_Time round_up_to_bar(BBT_Time const &) const
Meter & operator=(Meter const &other)
BBT_Time round_up_to_beat_div(BBT_Time const &, int beat_div) const
Meter(XMLNode const &)
BBT_Offset bbt_delta(BBT_Time const &later, BBT_Time const &earlier) const
Beats round_to_beat(Beats const &) const
BBT_Time round_up_to_beat(BBT_Time const &bbt) const
Meter(int8_t dpb, int8_t nv)
BBT_Time bbt_add(BBT_Time const &bbt, BBT_Offset const &add) const
BBT_Time round_to_bar(BBT_Time const &) const
Beats to_quarters(BBT_Offset const &) const
bool operator==(const Meter &other) const
Meter(Meter const &other)
int set_state(XMLNode const &, int version)
int32_t ticks_per_grid() const
XMLNode & get_state() const
bool operator!=(const Meter &other) const
BBT_Time round_to_beat(BBT_Time const &) const
static std::string xml_node_name
bool operator==(MusicTimePoint const &other) const
XMLNode & get_state() const
void set_name(std::string const &)
MusicTimePoint(TempoMap const &map, superclock_t sc, Beats const &b, BBT_Time const &bbt, Tempo const &t, Meter const &m, std::string name=std::string())
MusicTimePoint(TempoMap const &map, XMLNode const &)
void set(superclock_t sc, Beats const &b, BBT_Time const &bbt)
void add_state(XMLNode &) const
bool operator!=(Point const &other) const
samplepos_t sample(int sr) const
virtual timepos_t time() const =0
Point(TempoMap const &map, superclock_t sc, Beats const &b, BBT_Time const &bbt)
Point(TempoMap const &map, XMLNode const &)
superclock_t sclock() const
Beats const & beats() const
bool operator==(Point const &other) const
void map_reset_set_sclock_for_sr_change(superclock_t sc)
BBT_Time const & bbt() const
const std::string & name() const
TempoCommand(std::string const &name, XMLNode const *before, XMLNode const *after)
TempoCommand(XMLNode const &)
XMLNode & get_state() const
void dump(std::ostream &)
void add_end_tempo(Tempo const &t)
void add_end_meter(Meter const &t)
void add_start_meter(Meter const &t)
TempoMapCutBuffer(timecnt_t const &)
void add(MeterPoint const &)
void add(MusicTimePoint const &)
boost::intrusive::list< TempoPoint, boost::intrusive::base_hook< tempo_hook > > Tempos
boost::intrusive::list< MusicTimePoint, boost::intrusive::base_hook< bartime_hook > > MusicTimes
boost::intrusive::list< Point, boost::intrusive::base_hook< point_hook > > Points
void add(TempoPoint const &)
MusicTimes const & bartimes() const
boost::intrusive::list< MeterPoint, boost::intrusive::base_hook< meter_hook > > Meters
void add_start_tempo(Tempo const &t)
void add(Point const &)
TempoMapPoint(TempoMap const &map, TempoMetric const &tm, superclock_t sc, Beats const &q, BBT_Time const &bbt)
void copy_points(TempoMap const &other)
static void abort_update()
bool set_continuing(TempoPoint &, bool)
MeterPoint const & meter_at(superclock_t sc) const
static void init()
bool tempo_exists_before(TempoPoint const &t) const
Points::const_iterator get_grid(TempoMapPoints &points, superclock_t start, superclock_t end, uint32_t bar_mod=0, uint32_t beat_div=1) const
void fill_grid_with_final_metric(TempoMapPoints &ret, TempoMetric metric, superclock_t start, superclock_t rstart, superclock_t end, int bar_mod, int beat_div, Beats beats, BBT_Time bbt) const
bool move_tempo(TempoPoint const &point, timepos_t const &destination, bool push=false)
MeterPoint * add_meter(MeterPoint *)
uint32_t n_tempos() const
Beats quarters_at_superclock(superclock_t sc) const
bool solve_ramped_twist(TempoPoint &, TempoPoint &)
bool is_initial(MeterPoint const &) const
TempoPoint * add_tempo(TempoPoint *)
bool core_remove_tempo(TempoPoint const &)
bool tempo_exists_after(TempoPoint const &t) const
static thread_local SharedPtr _tempo_map_p
MeterPoint const & _meter_at(TimeType when, Comparator cmp) const
Beats quarters_at(timepos_t const &) const
MeterPoint const & meter_at(Beats const &b) const
bool can_remove(TempoPoint const &) const
BBT_Argument bbt_at(Beats const &) const
Beats bbtwalk_to_quarters(Beats const &start, BBT_Offset const &distance) const
void stretch_tempo(TempoPoint &ts, double new_npm)
MusicTimePoint * add_or_replace_bartime(MusicTimePoint *)
bool core_remove_bartime(MusicTimePoint const &)
bool solve_constant_twist(TempoPoint &, TempoPoint &)
void shift(timepos_t const &at, timecnt_t const &by)
static void update_thread_tempo_map()
TempoPoint * core_add_tempo(TempoPoint *, bool &)
ScopedTempoMapOwner * scope_owner() const
static WritableSharedPtr write_copy()
void shift(timepos_t const &at, BBT_Offset const &by)
TempoMap(XMLNode const &, int version)
MusicTimes const & bartimes() const
TempoPoint const & tempo_at(superclock_t sc) const
void ramped_twist_tempi(TempoPoint &prev, TempoPoint &focus, TempoPoint &next, double tempo_delta)
Meter const * next_meter(Meter const &) const
int parse_meter_state_3x(const XMLNode &node, LegacyMeterState &lts)
samplepos_t sample_at(BBT_Argument const &b) const
MeterPoint * core_add_meter(MeterPoint *, bool &)
timecnt_t bbt_duration_at(timepos_t const &pos, BBT_Offset const &bbt) const
Beats scwalk_to_quarters(Beats const &pos, superclock_t distance) const
void remove_tempo(TempoPoint const &, bool with_reset=true)
TempoPoint const & _tempo_at(TimeType when, Comparator cmp) const
void remove_point(Point const &)
void dump(std::ostream &) const
uint32_t n_meters() const
TempoPoint & set_tempo(Tempo const &, timepos_t const &)
void reset_starting_at(Beats const &)
int set_state(XMLNode const &, int version)
void stretch_tempo_end(TempoPoint *ts, samplepos_t sample, samplepos_t end_sample)
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
bool set_ramped(TempoPoint &, bool)
MeterPoint & set_meter(Meter const &, BBT_Argument const &)
MeterPoint const * previous_meter(MeterPoint const &) const
void remove_bartime(MusicTimePoint const &tp, bool with_reset=true)
samplepos_t sample_at(timepos_t const &t) const
BBT_Offset bbt_distance(BBT_Argument const &a, BBT_Argument const &b) const
TempoPoint const & tempo_at(Beats const &b) const
TempoPoint const * next_tempo(TempoPoint const &) const
int set_meters_from_state(XMLNode const &)
double min_notes_per_minute() const
void fill_grid_by_walking(TempoMapPoints &ret, Points::const_iterator &p, TempoMetric &metric, superclock_t &start, superclock_t rstart, superclock_t end, int bar_mod, int beat_div, Beats &beats, BBT_Time &bbt) const
void smf_add(TempoPoint &)
bool remove_time(timepos_t const &pos, timecnt_t const &duration)
double max_notes_per_minute() const
constness_traits_t::iterator_type _get_tempo_and_meter(typename constness_traits_t::tempo_point_type &, typename constness_traits_t::meter_point_type &, typename constness_traits_t::time_reference(Point::*)() const, typename constness_traits_t::time_type, typename constness_traits_t::iterator_type begini, typename constness_traits_t::iterator_type endi, typename constness_traits_t::tempo_point_type tstart, typename constness_traits_t::meter_point_type mstart, bool can_match, bool ret_iterator_after_not_at) const
std::list< Point const * > Metrics
TempoMetric metric_at(timepos_t const &) const
int set_state_3x(XMLNode const &)
Meters const & meters() const
std::shared_ptr< TempoMap > WritableSharedPtr
BBT_Argument bbt_at(timepos_t const &) const
bool is_initial(TempoPoint const &) const
TempoPoint & set_tempo(Tempo const &t, timepos_t const &time, Beats const &beats)
void replace_bartime(MusicTimePoint &tp, bool with_reset=true)
superclock_t superclock_at(BBT_Argument const &) const
int set_music_times_from_state(XMLNode const &)
Points::const_iterator get_tempo_and_meter(TempoPoint const *&t, MeterPoint const *&m, superclock_t sc, bool can_match, bool ret_iterator_after_not_at) const
Beats quarters_at_sample(samplepos_t sc) const
TempoPoint const & tempo_at(BBT_Argument const &bbt) const
TempoMetric metric_at(superclock_t, bool can_match=true) const
void midi_clock_beat_at_or_after(samplepos_t const pos, samplepos_t &clk_pos, uint32_t &clk_beat) const
TempoMetric metric_at(BBT_Argument const &, bool can_match=true) const
superclock_t reftime(TempoPoint const &, MeterPoint const &) const
static SharedPtr global_fetch()
MusicTimePoint * core_add_bartime(MusicTimePoint *, bool &)
static int update(WritableSharedPtr m)
samplepos_t sample_at(Beats const &b) const
void get_metrics(Metrics &m) const
Beats bbtwalk_to_quarters(BBT_Argument const &start, BBT_Offset const &distance) const
void core_add_point(Point *)
void set_scope_owner(ScopedTempoMapOwner &)
void grid(TempoMapPoints &points, superclock_t start, superclock_t end, uint32_t bar_mod=0, uint32_t beat_div=1) const
static void set(SharedPtr new_map)
std::shared_ptr< TempoMap const > SharedPtr
TempoMap(Tempo const &initial_tempo, Meter const &initial_meter)
bool clear_tempos_after(timepos_t const &, bool stop_at_music_time)
MeterPoint & set_meter(Meter const &, superclock_t)
MeterPoint const * next_meter(MeterPoint const &) const
MeterPoint & set_meter(Meter const &, timepos_t const &)
XMLNode & get_state() const
void replace_tempo(TempoPoint const &old, Tempo const &thenew, timepos_t const &)
Points::iterator get_tempo_and_meter(TempoPoint *&t, MeterPoint *&m, superclock_t sc, bool can_match, bool ret_iterator_after_not_at)
static PBD::Signal< void()> MapChanged
TempoPoint const * previous_tempo(TempoPoint const &) const
TempoMetric metric_at(Beats const &, bool can_match=true) const
BBT_Argument round_up_to_bar(BBT_Argument const &bbt) const
void reset_section(Points::iterator &begin, Points::iterator &end, superclock_t, TempoMetric &metric)
MeterPoint const & meter_at(BBT_Argument const &bbt) const
static SerializedRCUManager< TempoMap > _map_mgr
int set_tempos_from_state(XMLNode const &)
static bool fetch_condition()
TempoPoint const & tempo_at(timepos_t const &p) const
double quarters_per_minute_at(timepos_t const &pos) const
Beats quarters_at(BBT_Argument const &) const
BBT_Argument round_to_bar(BBT_Argument const &bbt) const
TempoPoint & set_tempo(Tempo const &, BBT_Argument const &)
static SharedPtr fetch()
void get_grid(GridIterator &iter, TempoMapPoints &ret, superclock_t rstart, superclock_t end, uint32_t bar_mod=0, uint32_t beat_div=1) const
timepos_t duration(TimeDomain) const
void smf_add(MeterPoint &)
Tempos const & tempos() const
void change_tempo(TempoPoint &, Tempo const &)
TempoMap(TempoMap const &)
TempoMapCutBuffer * cut_copy(timepos_t const &start, timepos_t const &end, bool copy, bool ripple)
TempoMapCutBuffer * cut(timepos_t const &start, timepos_t const &end, bool ripple)
MeterPoint const & meter_at(timepos_t const &p) const
int parse_tempo_state_3x(const XMLNode &node, LegacyTempoState &lts)
void add_point(Point &)
Beats scwalk_to_quarters(superclock_t pos, superclock_t distance) const
superclock_t superclock_at(timepos_t const &) const
superclock_t superclock_at(Beats const &) const
bool can_remove(MeterPoint const &) const
static void map_assert(bool expr, char const *exprstr, char const *file, int line)
Points::const_iterator get_tempo_and_meter(TempoPoint const *&t, MeterPoint const *&m, Beats const &b, bool can_match, bool ret_iterator_after_not_at) const
bool core_remove_meter(MeterPoint const &)
TempoMapCutBuffer * copy(timepos_t const &start, timepos_t const &end)
Temporal::timecnt_t convert_duration(Temporal::timecnt_t const &duration, Temporal::timepos_t const &, Temporal::TimeDomain domain) const
bool move_meter(MeterPoint const &point, timepos_t const &destination, bool push=false)
BBT_Argument bbt_at(superclock_t sc) const
ScopedTempoMapOwner * _scope_owner
void reset_starting_at(superclock_t)
void paste(TempoMapCutBuffer const &, timepos_t const &position, bool ripple, std::string=std::string())
void set_bartime(BBT_Time const &, timepos_t const &, std::string name=std::string())
void sample_rate_changed(samplecnt_t new_sr)
bool clear_tempos_before(timepos_t const &, bool stop_at_music_time)
void constant_twist_tempi(TempoPoint &prev, TempoPoint &focus, TempoPoint &next, double tempo_delta)
TempoMap & operator=(TempoMap const &)
void remove_meter(MeterPoint const &, bool with_reset=true)
BBT_Argument bbt_walk(BBT_Argument const &, BBT_Offset const &) const
samplepos_t samples_per_bar(samplecnt_t sr) const
BBT_Argument round_up_to_bar(BBT_Time const &bbt) const
superclock_t superclock_at(Beats const &qn) const
samplepos_t sample_at(Beats const &qn) const
Beats quarters_at(BBT_Time const &bbt) const
TempoPoint const & tempo() const
BBT_Argument round_to_bar(BBT_Time const &bbt) const
MeterPoint const & meter() const
superclock_t superclocks_per_note_type_at_superclock(superclock_t sc) const
superclock_t superclocks_per_note_type() const
superclock_t superclock_at(BBT_Time const &) const
superclock_t superclocks_per_quarter_note() const
BBT_Argument bbt_add(BBT_Time const &bbt, BBT_Offset const &add) const
superclock_t superclocks_per_note_type(int note_type) const
BBT_Argument bbt_at(Beats const &beats) const
MeterPoint & get_editable_meter() const
BBT_Argument bbt_subtract(BBT_Time const &bbt, BBT_Offset const &sub) const
superclock_t end_superclocks_per_note_type() const
TempoMetric(TempoPoint const &t, MeterPoint const &m)
superclock_t superclocks_per_bar() const
Beats quarters_at_superclock(superclock_t sc) const
TempoPoint & get_editable_tempo() const
Beats quarters_at_sample(samplepos_t sc) const
BBT_Argument bbt_at(timepos_t const &) const
Beats to_quarters(BBT_Offset const &bbo) const
superclock_t superclocks_per_grid() const
Beats round_to_beat(Beats const &b) const
superclock_t reftime() const
bool operator==(TempoPoint const &other) const
Beats quarters_at_sample(samplepos_t sc) const
samplepos_t sample_at(Beats const &qn) const
TempoPoint(TempoMap const &map, XMLNode const &)
void compute_omega_from_next_tempo(TempoPoint const &next_tempo)
superclock_t superclock_at(Beats const &qn) const
XMLNode & get_state() const
TempoPoint(Tempo const &t, Point const &p)
double note_types_per_minute_at_DOUBLE(timepos_t const &pos) const
bool operator!=(TempoPoint const &other) const
void compute_omega_from_quarter_duration(Beats const &quarter_duration, superclock_t end_scpqn)
void compute_omega_from_distance_and_next_tempo(Beats const &quarter_duration, TempoPoint const &next_tempo)
TempoPoint(TempoMap const &map, Tempo const &t, superclock_t sc, Beats const &b, BBT_Time const &bbt)
int set_state(XMLNode const &, int version)
void set_omega(double v)
Beats quarters_at_superclock(superclock_t sc) const
superclock_t superclocks_per_note_type_at(timepos_t const &) const
TempoPoint & operator=(Tempo const &t)
bool operator!=(Tempo const &other) const
Tempo(XMLNode const &)
double samples_per_quarter_note(int sr) const
void set_locked_to_meter(bool yn)
Tempo(double npm, double enpm, int8_t note_type)
double note_types_per_minute() const
superclock_t superclocks_per_quarter_note() const
superclock_t _superclocks_per_note_type
double end_note_types_per_minute() const
double samples_per_note_type(int sr) const
static std::string xml_node_name
superclock_t superclocks_per_note_type() const
int set_state(XMLNode const &, int version)
superclock_t end_superclocks_per_note_type() const
void set_end_npm(double)
bool operator==(Tempo const &other) const
double quarter_notes_per_minute() const
superclock_t superclocks_per_note_type(int note_type) const
void set_note_types_per_minute(double npm)
Tempo(double npm, int8_t note_type)
superclock_t end_superclocks_per_note_type(int note_type) const
superclock_t _end_superclocks_per_note_type
XMLNode & get_state() const
superclock_t end_superclocks_per_quarter_note() const
static superclock_t double_npm_to_scpn(double npm)
void set_continuing(bool yn)
static timepos_t from_superclock(superclock_t s)
Definition: timeline.h:73
Definition: xml++.h:114
GtkImageIconNameData name
Definition: gtkimage.h:6
PBD::PropertyDescriptor< timepos_t > start
Temporal::timepos_t timepos_t
void add(const Gtk::StockItem &item)
int64_t muldiv_round(int64_t v, int64_t n, int64_t d)
static superclock_t superclock_to_samples(superclock_t s, int sr)
Definition: superclock.h:48
boost::intrusive::list_base_hook< boost::intrusive::tag< struct point_tag > > point_hook
boost::intrusive::list_base_hook< boost::intrusive::tag< struct tempo_tag > > tempo_hook
std::vector< TempoMapPoint > TempoMapPoints
boost::intrusive::list< Point, boost::intrusive::base_hook< point_hook > > Points
boost::intrusive::list< TempoPoint, boost::intrusive::base_hook< tempo_hook > > Tempos
static superclock_t samples_to_superclock(int64_t samples, int sr)
Definition: superclock.h:49
static superclock_t superclock_ticks_per_second()
Definition: superclock.h:45
boost::intrusive::list_base_hook< boost::intrusive::tag< struct bartime_tag > > bartime_hook
boost::intrusive::list< MeterPoint, boost::intrusive::base_hook< meter_hook > > Meters
boost::intrusive::list_base_hook< boost::intrusive::tag< struct meterpoint_tag > > meter_hook
int64_t superclock_t
Definition: superclock.h:34
boost::intrusive::list< MusicTimePoint, boost::intrusive::base_hook< bartime_hook > > MusicTimes
void push(lua_State *L, T t)
Definition: LuaBridge.h:159
bool operator==(const ProcessorSelection &a, const ProcessorSelection &b)
superclock_t reference() const
Definition: bbt_argument.h:38
#define TEMPORAL_SAMPLE_RATE
Definition: superclock.h:58
#define LIBTEMPORAL_API