Tempo ramps - multiple audio-locked meters are go.
authornick_m <mainsbridge@gmail.com>
Wed, 30 Mar 2016 19:45:44 +0000 (06:45 +1100)
committernick_m <mainsbridge@gmail.com>
Fri, 27 May 2016 13:38:13 +0000 (23:38 +1000)
- more or less

libs/ardour/tempo.cc

index 151ad56d2b0c2df04d0de5b8b5b3150fc0ad5a63..77d841897008d4daa6197328ae6e1993c2156910 100644 (file)
@@ -1262,10 +1262,11 @@ TempoMap::recompute_meters (Metrics& metrics)
                                double pulse = 0.0;
                                pair<double, BBT_Time> b_bbt;
                                if (meter->movable()) {
-                                       const double beats = ((pulse_at_frame_locked (metrics, meter->frame()) - prev_m->pulse()) * prev_m->note_divisor()) - prev_m->beat();
-                                       b_bbt = make_pair (ceil (beats), BBT_Time (accumulated_bars + 1, 1, 0));
-                                       const double true_pulse = prev_m->pulse() + (ceil (beats) - prev_m->beat()) / prev_m->note_divisor();
+                                       double beats = ((pulse_at_frame_locked (metrics, meter->frame()) - prev_m->pulse()) * prev_m->note_divisor()) - prev_m->beat();
+                                       double ceil_beats = beats + prev_m->divisions_per_bar() - fmod (beats, prev_m->divisions_per_bar());
+                                       const double true_pulse = prev_m->pulse() + (ceil_beats - prev_m->beat()) / prev_m->note_divisor();
                                        const double pulse_off = true_pulse - ((beats - prev_m->beat()) / prev_m->note_divisor());
+                                       b_bbt = make_pair (ceil_beats, BBT_Time (accumulated_bars + 1, 1, 0));
                                        pulse = true_pulse - pulse_off;
                                } else {
                                        b_bbt = make_pair (0.0, BBT_Time (1, 1, 0));
@@ -2014,16 +2015,15 @@ TempoMap::solve_map (Metrics& imaginary, MeterSection* section, const Meter& mt,
                        if (m == section){
                                /*
                                  here we set the beat for this frame.
-                                 we're going to set it 'incorrectly' to the next integer and use this difference
-                                 to find the meter's pulse.
-                                 (meters should fall on integral beats to keep us sane)
-                                 XXX do it to the bar, you fool, not the beat!  - and don't forget to recompute_meters that way too.
+                                 we set it 'incorrectly' to the next bar's beat
+                                 and use this difference to find the meter's pulse.
                                */
                                double pulse = 0.0;
                                pair<double, BBT_Time> b_bbt;
                                if (m->movable()) {
                                        double beats = ((pulse_at_frame_locked (imaginary, frame) - prev_ms->pulse()) * prev_ms->note_divisor()) - prev_ms->beat();
-                                       b_bbt = make_pair (ceil (beats), BBT_Time (accumulated_bars + 1, 1, 0));
+                                       double ceil_beats = beats + prev_ms->divisions_per_bar() - fmod (beats,  prev_ms->divisions_per_bar());
+                                       b_bbt = make_pair (ceil_beats, BBT_Time (accumulated_bars + 1, 1, 0));
                                        const double true_pulse = prev_ms->pulse() + ((ceil (beats) - prev_ms->beat()) / prev_ms->note_divisor());
                                        const double pulse_off = true_pulse - ((beats - prev_ms->beat()) / prev_ms->note_divisor());
                                        pulse = true_pulse - pulse_off;
@@ -2044,10 +2044,11 @@ TempoMap::solve_map (Metrics& imaginary, MeterSection* section, const Meter& mt,
                                        double pulse = 0.0;
                                        pair<double, BBT_Time> b_bbt;
                                        if (m->movable()) {
-                                               const double beats = ((pulse_at_frame_locked (imaginary, m->frame()) - prev_ms->pulse()) * prev_ms->note_divisor()) - prev_ms->beat();
+                                               double beats = ((pulse_at_frame_locked (imaginary, m->frame()) - prev_ms->pulse()) * prev_ms->note_divisor()) - prev_ms->beat();
+                                               double ceil_beats = beats + prev_ms->divisions_per_bar() - fmod (beats , prev_ms->divisions_per_bar());
                                                const double true_pulse = prev_ms->pulse() + (m->beat() - prev_ms->beat()) / prev_ms->note_divisor();
-                                               const double pulse_off = true_pulse - ((beats - prev_ms->beat()) / prev_ms->note_divisor());
-                                               b_bbt = make_pair (ceil (beats), BBT_Time (accumulated_bars + 1, 1, 0));
+                                               const double pulse_off = true_pulse - ((ceil_beats - prev_ms->beat()) / prev_ms->note_divisor());
+                                               b_bbt = make_pair (ceil_beats, BBT_Time (accumulated_bars + 1, 1, 0));
                                                pulse = true_pulse - pulse_off;
                                        } else {
                                                b_bbt = make_pair (0.0, BBT_Time (1, 1, 0));
@@ -2102,11 +2103,20 @@ TempoMap::solve_map (Metrics& imaginary, MeterSection* section, const Meter& mt,
                                        m->set_frame (frame_at_pulse_locked (imaginary, pulse));
                                        m->set_pulse (pulse);
                                } else {
-                                       if (!m->movable()) {
-                                               pair<double, BBT_Time> b_bbt = make_pair (0.0, BBT_Time (1, 1, 0));
-                                               m->set_beat (b_bbt);
+                                       double pulse = 0.0;
+                                       pair<double, BBT_Time> b_bbt;
+                                       if (m->movable()) {
+                                               double beats = ((pulse_at_frame_locked (imaginary, m->frame()) - prev_ms->pulse()) * prev_ms->note_divisor()) - prev_ms->beat();
+                                               double ceil_beats = beats + prev_ms->divisions_per_bar() - fmod (beats , prev_ms->divisions_per_bar());
+                                               const double true_pulse = prev_ms->pulse() + (m->beat() - prev_ms->beat()) / prev_ms->note_divisor();
+                                               const double pulse_off = true_pulse - ((ceil_beats - prev_ms->beat()) / prev_ms->note_divisor());
+                                               b_bbt = make_pair (ceil_beats, BBT_Time (accumulated_bars + 1, 1, 0));
+                                               pulse = true_pulse - pulse_off;
+                                       } else {
+                                               b_bbt = make_pair (0.0, BBT_Time (1, 1, 0));
+                                               pulse = 0.0;
                                        }
-                                       const double pulse = prev_ms->pulse() + (m->beat() - prev_ms->beat()) / prev_ms->note_divisor();
+                                       m->set_beat (b_bbt);
                                        m->set_pulse (pulse);
                                }
                        }