add lots more BBT-based time info for VST plugins (see 5737)
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 15 Jan 2014 21:08:27 +0000 (16:08 -0500)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 15 Jan 2014 21:08:27 +0000 (16:08 -0500)
libs/ardour/session_vst.cc

index 644fb19ffbd1c38a11081437d9360f237991f676..b2e9b14c1a4acf1f87df3800ed972150fe51960b 100644 (file)
@@ -17,7 +17,9 @@
 
 */
 
+#ifndef COMPILER_MSVC
 #include <stdbool.h>
+#endif
 #include <cstdio>
 
 #include "ardour/session.h"
@@ -59,11 +61,19 @@ intptr_t Session::vst_callback (
        if (effect && effect->user) {
                plug = (VSTPlugin *) (effect->user);
                session = &plug->session();
+#ifdef COMPILER_MSVC
+               SHOW_CALLBACK ("am callback 0x%x, opcode = %d, plugin = \"%s\" ", (int) pthread_self().p, opcode, plug->name());
+#else
                SHOW_CALLBACK ("am callback 0x%x, opcode = %d, plugin = \"%s\" ", (int) pthread_self(), opcode, plug->name());
+#endif
        } else {
                plug = 0;
                session = 0;
+#ifdef COMPILER_MSVC
+               SHOW_CALLBACK ("am callback 0x%x, opcode = %d", (int) pthread_self().p, opcode);
+#else
                SHOW_CALLBACK ("am callback 0x%x, opcode = %d", (int) pthread_self(), opcode);
+#endif
        }
 
        switch(opcode){
@@ -121,21 +131,56 @@ intptr_t Session::vst_callback (
                // conversions
                memset(&_timeInfo, 0, sizeof(_timeInfo));
                if (session) {
-                       _timeInfo.samplePos = session->transport_frame();
+                       framepos_t now = session->transport_frame();
+                       _timeInfo.samplePos = now;
                        _timeInfo.sampleRate = session->frame_rate();
                        _timeInfo.flags = 0;
 
+                       const TempoMetric& tm (session->tempo_map().metric_at (now));
+
                        if (value & (kVstTempoValid)) {
-                               const Tempo& t (session->tempo_map().tempo_at (session->transport_frame()));
+                               const Tempo& t (tm.tempo());
                                _timeInfo.tempo = t.beats_per_minute ();
                                _timeInfo.flags |= (kVstTempoValid);
                        }
                        if (value & (kVstBarsValid)) {
-                               const Meter& m (session->tempo_map().meter_at (session->transport_frame()));
+                               const Meter& m (tm.meter());
                                _timeInfo.timeSigNumerator = m.divisions_per_bar ();
                                _timeInfo.timeSigDenominator = m.note_divisor ();
                                _timeInfo.flags |= (kVstBarsValid);
                        }
+                       if (value & (kVstPpqPosValid)) {
+                               Timecode::BBT_Time bbt;
+                               try {
+                                       session->tempo_map().bbt_time_rt (now, bbt);
+                                       
+                                       /* Note that this assumes constant
+                                          meter/tempo throughout the session. We
+                                          can do better than this, because
+                                          progressive rock fans demand it.
+                                       */
+                                       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;
+                                       // PPQ Pos
+                                       _timeInfo.ppqPos = ppqBar + ppqBeat + ppqTick;
+                                       _timeInfo.flags |= (kVstPpqPosValid);
+                               } catch (...) {
+                                       /* relax */
+                               }
+                       }
+
+                       _timeInfo.tempo = tm.tempo().beats_per_minute();
+                       _timeInfo.flags |= kVstTempoValid;
+                       
+                       // Bars
+                       // _timeInfo.barStartPos = ppqBar;
+                       // _timeInfo.flags |= kVstBarsValid;
+                       
+                       // Time Signature
+                       _timeInfo.timeSigNumerator = tm.meter().divisions_per_bar();
+                       _timeInfo.timeSigDenominator = tm.meter().note_divisor();
+                       _timeInfo.flags |= kVstTimeSigValid;
 
                        if (session->transport_speed() != 0.0f) {
                                _timeInfo.flags |= kVstTransportPlaying;