summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authornick_m <mainsbridge@gmail.com>2016-05-21 05:33:31 +1000
committernick_m <mainsbridge@gmail.com>2016-05-27 23:38:17 +1000
commitf182235410d3121929c8357cf61bc66f56a2b4a0 (patch)
tree4212903234bf6d4348e2756273253f82e1a04a3c /libs
parentd1a075110afa8efe1944ba7a9a2ba6be985c8291 (diff)
Tempo ramps - consolidate TempoMap::predict_tempo()
Diffstat (limited to 'libs')
-rw-r--r--libs/ardour/ardour/tempo.h9
-rw-r--r--libs/ardour/tempo.cc60
2 files changed, 24 insertions, 45 deletions
diff --git a/libs/ardour/ardour/tempo.h b/libs/ardour/ardour/tempo.h
index f3b94e05ee..a3eec81bb9 100644
--- a/libs/ardour/ardour/tempo.h
+++ b/libs/ardour/ardour/tempo.h
@@ -374,14 +374,14 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
const MeterSection& meter_section_at_beat (double beat) const;
- /** add a tempo section locked to pls. ignored values are set in recompute_tempos()
+ /** add a tempo section locked to pls. ignored values will be set in recompute_tempos()
* @param pulse pulse position of new section. ignored if pls == AudioTime
* @param frame frame position of new section. ignored if pls == MusicTime
* @param type type of new tempo section (Ramp, Constant)
*/
TempoSection* add_tempo (const Tempo&, const double& pulse, const framepos_t& frame, TempoSection::Type type, PositionLockStyle pls);
- /** add an meter section locked to pls.. ignored values are set in recompute_meters()
+ /** add an meter section locked to pls.. ignored values will be set in recompute_meters()
* @param beat beat position of new section
* @param where bbt position of new section
* @param frame frame position of new section. ignored if pls == MusicTime
@@ -391,15 +391,14 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
void remove_tempo (const TempoSection&, bool send_signal);
void remove_meter (const MeterSection&, bool send_signal);
- framepos_t predict_tempo_frame (TempoSection* section, const Timecode::BBT_Time& bbt);
- double predict_tempo_pulse (TempoSection* section, const Timecode::BBT_Time& bbt);
-
void replace_tempo (const TempoSection&, const Tempo&, const double& pulse, const framepos_t& frame
, TempoSection::Type type, PositionLockStyle pls);
void replace_meter (const MeterSection&, const Meter&, const Timecode::BBT_Time& where, const framepos_t& frame
, PositionLockStyle pls);
+ std::pair<double, framepos_t> predict_tempo (TempoSection* section, const Timecode::BBT_Time& bbt);
+
void gui_move_tempo_frame (TempoSection*, const framepos_t& frame);
void gui_move_tempo_beat (TempoSection*, const double& beat);
void gui_move_meter_frame (MeterSection*, const framepos_t& frame);
diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc
index 874c42e8f0..87e1620425 100644
--- a/libs/ardour/tempo.cc
+++ b/libs/ardour/tempo.cc
@@ -2005,6 +2005,7 @@ TempoMap::solve_map_frame (Metrics& imaginary, MeterSection* section, const fram
MeterSection* prev_m = 0;
Metrics future_map;
+ TempoSection* tempo_copy = copy_metrics_and_point (imaginary, future_map, meter_locked_tempo);
bool solved = false;
for (Metrics::iterator i = imaginary.begin(); i != imaginary.end(); ++i) {
@@ -2017,11 +2018,11 @@ TempoMap::solve_map_frame (Metrics& imaginary, MeterSection* section, const fram
/* set the frame/pulse corresponding to its musical position,
* as an earlier time than this has been requested.
*/
-
- TempoSection* tempo_copy = copy_metrics_and_point (imaginary, future_map, meter_locked_tempo);
const double new_pulse = ((section->beat() - prev_m->beat())
/ prev_m->note_divisor()) + prev_m->pulse();
+
const framepos_t smallest_frame = frame_at_pulse_locked (future_map, new_pulse);
+
if ((solved = solve_map_frame (future_map, tempo_copy, smallest_frame))) {
meter_locked_tempo->set_pulse (new_pulse);
solve_map_frame (imaginary, meter_locked_tempo, smallest_frame);
@@ -2041,8 +2042,7 @@ TempoMap::solve_map_frame (Metrics& imaginary, MeterSection* section, const fram
return false;
}
} else {
-
- TempoSection* tempo_copy = copy_metrics_and_point (imaginary, future_map, meter_locked_tempo);
+ /* all is ok. set section's tempo */
MeterSection* meter_copy = const_cast<MeterSection*> (&meter_section_at_locked (future_map, section->frame()));
meter_copy->set_frame (frame);
@@ -2068,8 +2068,6 @@ TempoMap::solve_map_frame (Metrics& imaginary, MeterSection* section, const fram
} else {
/* not movable (first meter atm) */
- TempoSection* tempo_copy = copy_metrics_and_point (imaginary, future_map, meter_locked_tempo);
-
tempo_copy->set_frame (frame);
tempo_copy->set_pulse (0.0);
@@ -2149,6 +2147,7 @@ TempoMap::solve_map_bbt (Metrics& imaginary, MeterSection* section, const BBT_Ti
if (m->position_lock_style() == AudioTime) {
TempoSection* meter_locked_tempo = 0;
+
for (Metrics::const_iterator ii = imaginary.begin(); ii != imaginary.end(); ++ii) {
TempoSection* t;
if ((t = dynamic_cast<TempoSection*> (*ii)) != 0) {
@@ -2159,6 +2158,10 @@ TempoMap::solve_map_bbt (Metrics& imaginary, MeterSection* section, const BBT_Ti
}
}
+ if (!meter_locked_tempo) {
+ return false;
+ }
+
if (prev_m) {
const double beats = ((m->bbt().bars - prev_m->bbt().bars) * prev_m->divisions_per_bar());
@@ -2174,10 +2177,8 @@ TempoMap::solve_map_bbt (Metrics& imaginary, MeterSection* section, const BBT_Ti
} else {
b_bbt = make_pair (0.0, BBT_Time (1, 1, 0));
}
- if (meter_locked_tempo) {
- meter_locked_tempo->set_pulse (new_pulse);
- recompute_tempos (imaginary);
- }
+
+ meter_locked_tempo->set_pulse (new_pulse);
m->set_beat (b_bbt);
m->set_pulse (new_pulse);
@@ -2312,45 +2313,24 @@ TempoMap::can_solve_bbt (TempoSection* ts, const BBT_Time& bbt)
* @param bbt - the bbt where the altered tempo will fall
* @return returns - the position in frames where the new tempo section will lie.
*/
-framepos_t
-TempoMap::predict_tempo_frame (TempoSection* section, const BBT_Time& bbt)
+pair<double, framepos_t>
+TempoMap::predict_tempo (TempoSection* section, const BBT_Time& bbt)
{
- Glib::Threads::RWLock::ReaderLock lm (lock);
Metrics future_map;
- framepos_t ret = 0;
- TempoSection* tempo_copy = copy_metrics_and_point (_metrics, future_map, section);
- if (!tempo_copy) {
- return 0;
- }
- const double beat = bbt_to_beats_locked (future_map, bbt);
+ pair<double, framepos_t> ret = make_pair (0.0, 0);
- if (solve_map_pulse (future_map, tempo_copy, pulse_at_beat_locked (future_map, beat))) {
- ret = tempo_copy->frame();
- } else {
- ret = section->frame();
- }
-
- Metrics::const_iterator d = future_map.begin();
- while (d != future_map.end()) {
- delete (*d);
- ++d;
- }
- return ret;
-}
-
-double
-TempoMap::predict_tempo_pulse (TempoSection* section, const BBT_Time& bbt)
-{
Glib::Threads::RWLock::ReaderLock lm (lock);
- Metrics future_map;
- double ret = 0.0;
+
TempoSection* tempo_copy = copy_metrics_and_point (_metrics, future_map, section);
+
const double beat = bbt_to_beats_locked (future_map, bbt);
if (solve_map_pulse (future_map, tempo_copy, pulse_at_beat_locked (future_map, beat))) {
- ret = tempo_copy->pulse();
+ ret.first = tempo_copy->pulse();
+ ret.second = tempo_copy->frame();
} else {
- ret = section->pulse();
+ ret.first = section->pulse();
+ ret.second = section->frame();
}
Metrics::const_iterator d = future_map.begin();