another unusued parameter fix
[ardour.git] / libs / ardour / midi_clock_slave.cc
index 5dfd63fe1a65afc5896a96d0989a3a203bfc6b13..ef2d22ab18e61088d43a421084c6a0103fed21d5 100644 (file)
 #include "pbd/error.h"
 #include "pbd/failed_constructor.h"
 #include "pbd/pthread_utils.h"
+#include "pbd/convert.h"
 
 #include "midi++/port.h"
 
 #include "ardour/debug.h"
 #include "ardour/slave.h"
-#include "ardour/session.h"
-#include "ardour/audioengine.h"
-#include "ardour/cycles.h"
 #include "ardour/tempo.h"
 
-
 #include "i18n.h"
 
 using namespace std;
@@ -44,8 +41,6 @@ using namespace ARDOUR;
 using namespace MIDI;
 using namespace PBD;
 
-#define DEBUG_MIDI_CLOCK 1
-
 MIDIClock_Slave::MIDIClock_Slave (Session& s, MIDI::Port& p, int ppqn)
        : ppqn (ppqn)
        , bandwidth (1.0 / 60.0) // 1 BpM = 1 / 60 Hz
@@ -88,10 +83,7 @@ void
 MIDIClock_Slave::calculate_one_ppqn_in_frames_at(framepos_t time)
 {
        const Tempo& current_tempo = session->tempo_map().tempo_at(time);
-       const Meter& current_meter = session->tempo_map().meter_at(time);
-       double frames_per_beat =
-               current_tempo.frames_per_beat(session->frame_rate(),
-                                             current_meter);
+       double frames_per_beat = current_tempo.frames_per_beat(session->frame_rate());
 
        double quarter_notes_per_beat = 4.0 / current_tempo.note_type();
        double frames_per_quarter_note = frames_per_beat / quarter_notes_per_beat;
@@ -184,7 +176,7 @@ MIDIClock_Slave::update_midi_clock (Parser& /*parser*/, framepos_t timestamp)
                                                       t1 * session->frame_rate(),
                                                       session->frame_rate(),
                                                       ((t1 - t0) * session->frame_rate()) / one_ppqn_in_frames));
-       
+
        last_timestamp = timestamp;
 }
 
@@ -211,8 +203,9 @@ MIDIClock_Slave::reset ()
 
        _starting = true;
        _started  = true;
-       
+
        // session->request_locate(0, false);
+       current_delta = 0;
 }
 
 void
@@ -334,7 +327,7 @@ MIDIClock_Slave::speed_and_position (double& speed, framepos_t& pos)
 
        // calculate speed
        speed = ((t1 - t0) * session->frame_rate()) / one_ppqn_in_frames;
-       
+
        // provide a 3% deadzone to lock the speed
        if (fabs(speed - 1.0) <= 0.03)
                speed = 1.0;
@@ -351,6 +344,7 @@ MIDIClock_Slave::speed_and_position (double& speed, framepos_t& pos)
        }
 
        DEBUG_TRACE (DEBUG::MidiClock, string_compose ("speed_and_position: %1 & %2 <-> %3 (transport)\n", speed, pos, session->transport_frame()));
+       current_delta = pos - session->transport_frame();
 
        return true;
 }
@@ -362,3 +356,16 @@ MIDIClock_Slave::resolution() const
        return (framecnt_t) one_ppqn_in_frames * ppqn;
 }
 
+std::string
+MIDIClock_Slave::approximate_current_delta() const
+{
+       char delta[80];
+       if (last_timestamp == 0 || _starting) {
+               snprintf(delta, sizeof(delta), "\u2012\u2012\u2012\u2012");
+       } else {
+               snprintf(delta, sizeof(delta), "\u0394<span foreground=\"green\" face=\"monospace\" >%s%s%" PRIi64 "</span> sm",
+                               LEADINGZERO(abs(current_delta)), PLUSMINUS(-current_delta), abs(current_delta));
+       }
+       return std::string(delta);
+}
+