summaryrefslogtreecommitdiff
path: root/libs/ardour/tempo.cc
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/ardour/tempo.cc
parentd1a075110afa8efe1944ba7a9a2ba6be985c8291 (diff)
Tempo ramps - consolidate TempoMap::predict_tempo()
Diffstat (limited to 'libs/ardour/tempo.cc')
-rw-r--r--libs/ardour/tempo.cc60
1 files changed, 20 insertions, 40 deletions
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();