Give the Windows MMTimer test a better chance of passing
[ardour.git] / libs / ardour / session_vst.cc
index ad732e052a185f632a77233b7e0af7e68c08e84f..a614fef956dae893586f41cad414f24a57b077eb 100644 (file)
@@ -34,7 +34,7 @@
 #include <fst.h>
 #endif
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace ARDOUR;
 
@@ -200,53 +200,34 @@ intptr_t Session::vst_callback (
 
                timeinfo->nanoSeconds = g_get_monotonic_time () * 1000;
 
-               if (session) {
-                       framepos_t now = session->transport_frame();
+               if (plug && session) {
+                       framepos_t now = plug->transport_frame();
 
                        timeinfo->samplePos = now;
                        timeinfo->sampleRate = session->frame_rate();
 
-                       const TempoMetric& tm (session->tempo_map().metric_at (now));
-
                        if (value & (kVstTempoValid)) {
-                               const Tempo& t (tm.tempo());
+                               const Tempo& t (session->tempo_map().tempo_at_frame (now));
                                timeinfo->tempo = t.beats_per_minute ();
                                newflags |= (kVstTempoValid);
                        }
                        if (value & (kVstTimeSigValid)) {
-                               const Meter& m (tm.meter());
-                               timeinfo->timeSigNumerator = m.divisions_per_bar ();
-                               timeinfo->timeSigDenominator = m.note_divisor ();
+                               const MeterSection& ms (session->tempo_map().meter_section_at_frame (now));
+                               timeinfo->timeSigNumerator = ms.divisions_per_bar ();
+                               timeinfo->timeSigDenominator = ms.note_divisor ();
                                newflags |= (kVstTimeSigValid);
                        }
                        if ((value & (kVstPpqPosValid)) || (value & (kVstBarsValid))) {
                                Timecode::BBT_Time bbt;
 
                                try {
-                                       session->tempo_map().bbt_time (now, bbt);
-
-                                       /* PPQ = pulse per quarter
-                                        * VST's "pulse" is our "division".
-                                        *
-                                        * 8 divisions per bar, 1 division = quarter, so 8 quarters per bar, ppq = 1
-                                        * 8 divisions per bar, 1 division = eighth, so  4 quarters per bar, ppq = 2
-                                        * 4 divisions per bar, 1 division = quarter, so  4 quarters per bar, ppq = 1
-                                        * 4 divisions per bar, 1 division = half, so 8 quarters per bar, ppq = 0.5
-                                        * 4 divisions per bar, 1 division = fifth, so (4 * 5/4) quarters per bar, ppq = 5/4
-                                        *
-                                        * general: divs_per_bar / (note_type / 4.0)
-                                        */
-                                       double ppq_scaling =  tm.meter().note_divisor() / 4.0;
-
-                                       /* Note that this assumes constant meter/tempo throughout the session. Stupid VST */
-                                       double ppqBar = double(bbt.bars - 1) * tm.meter().divisions_per_bar();
-                                       double ppqBeat = double(bbt.beats - 1);
-                                       double ppqTick = double(bbt.ticks) / Timecode::BBT_Time::ticks_per_beat;
-
-                                       ppqBar *= ppq_scaling;
-                                       ppqBeat *= ppq_scaling;
-                                       ppqTick *= ppq_scaling;
-
+                                       bbt = session->tempo_map().bbt_at_frame_rt (now);
+                                       bbt.beats = 1;
+                                       bbt.ticks = 0;
+                                       /* exact quarter note */
+                                       double ppqBar = session->tempo_map().pulse_at_bbt_rt (bbt) * 4.0;
+                                       /* quarter note at frame position (not rounded to note subdivision) */
+                                       double ppqPos = session->tempo_map().quarter_note_at_frame_rt (now);
                                        if (value & (kVstPpqPosValid)) {
                                                timeinfo->ppqPos = ppqPos;
                                                newflags |= kVstPpqPosValid;
@@ -299,7 +280,7 @@ intptr_t Session::vst_callback (
                                newflags |= kVstTransportRecording;
                        }
 
-                       if (session->transport_speed () != 0.0f) {
+                       if (plug->transport_speed () != 0.0f) {
                                newflags |= kVstTransportPlaying;
                        }
 
@@ -307,14 +288,8 @@ intptr_t Session::vst_callback (
                                newflags |= kVstTransportCycleActive;
                                Location * looploc = session->locations ()->auto_loop_location ();
                                if (looploc) try {
-                                       double ppqBar;
-                                       Timecode::BBT_Time bbt;
-
-                                       session->tempo_map().bbt_time_rt (looploc->start (), bbt);
-                                       timeinfo->cycleStartPos = vst_ppq (tm, bbt, ppqBar);
-
-                                       session->tempo_map().bbt_time_rt (looploc->end (), bbt);
-                                       timeinfo->cycleEndPos = vst_ppq (tm, bbt, ppqBar);
+                                       timeinfo->cycleStartPos = session->tempo_map ().quarter_note_at_frame_rt (looploc->start ());
+                                       timeinfo->cycleEndPos = session->tempo_map ().quarter_note_at_frame_rt (looploc->end ());
 
                                        newflags |= kVstCyclePosValid;
                                } catch (...) { }
@@ -568,4 +543,3 @@ intptr_t Session::vst_callback (
 
        return 0;
 }
-