Das BlinkenSendButtons
[ardour.git] / libs / ardour / ardour / slave.h
index 1f21e28f406e60f1469383c94914ef7dda2c391f..43418c576d1a03331b418919ae123c4ba1f7b336 100644 (file)
@@ -25,9 +25,9 @@
 #include <jack/jack.h>
 
 #include <sigc++/signal.h>
-#include <ardour/ardour.h>
-#include <midi++/parser.h>
-#include <midi++/types.h>
+#include "ardour/ardour.h"
+#include "midi++/parser.h"
+#include "midi++/types.h"
 
 namespace MIDI {
        class Port;
@@ -103,8 +103,9 @@ class Slave {
         * 
         * @param speed - The transport speed requested
         * @param position - The transport position requested
+        * @return - The return value is currently ignored (see Session::follow_slave)
         */
-       virtual bool speed_and_position (float& speed, nframes_t& position) = 0;
+       virtual bool speed_and_position (double& speed, nframes_t& position) = 0;
        
        /**
         * reports to ARDOUR whether the Slave is currently synced to its external 
@@ -147,6 +148,11 @@ class Slave {
         *           the slave returns
         */
        virtual bool is_always_synced() const { return false; }
+       
+       /**
+        * @return - whether ARDOUR should use the slave speed without any adjustments 
+        */
+       virtual bool give_slave_full_control_over_transport_speed() const { return false; }
 };
 
 struct SafeTime {
@@ -168,7 +174,7 @@ class MTC_Slave : public Slave, public sigc::trackable {
        ~MTC_Slave ();
 
        void rebind (MIDI::Port&);
-       bool speed_and_position (float&, nframes_t&);
+       bool speed_and_position (double&, nframes_t&);
 
        bool locked() const;
        bool ok() const;
@@ -188,12 +194,12 @@ class MTC_Slave : public Slave, public sigc::trackable {
        nframes_t   last_inbound_frame;      /* when we got it; audio clocked */
        MIDI::byte  last_mtc_fps_byte;
 
-       float       mtc_speed;
+       double      mtc_speed;
        nframes_t   first_mtc_frame;
        nframes_t   first_mtc_time;
 
        static const int32_t accumulator_size = 128;
-       float   accumulator[accumulator_size];
+       double   accumulator[accumulator_size];
        int32_t accumulator_index;
        bool    have_first_accumulated_speed;
 
@@ -210,7 +216,7 @@ class MIDIClock_Slave : public Slave, public sigc::trackable {
        ~MIDIClock_Slave ();
 
        void rebind (MIDI::Port&);
-       bool speed_and_position (float&, nframes_t&);
+       bool speed_and_position (double&, nframes_t&);
 
        bool locked() const;
        bool ok() const;
@@ -218,7 +224,8 @@ class MIDIClock_Slave : public Slave, public sigc::trackable {
 
        nframes_t resolution() const;
        bool requires_seekahead () const { return false; }
-
+       bool give_slave_full_control_over_transport_speed() const { return true; }
+       
   private:
        Session&    session;
        MIDI::Port* port;
@@ -230,27 +237,46 @@ class MIDIClock_Slave : public Slave, public sigc::trackable {
        /// the duration of one ppqn in frame time
        double      one_ppqn_in_frames;
 
-       /// the time stamp and transport position of the last inbound MIDI clock message
+       /// the timestamp of the first MIDI clock message
+       nframes_t   first_timestamp;
+       
+       /// the time stamp and should-be transport position of the last inbound MIDI clock message
        nframes_t   last_timestamp;
-       double      last_position;
+       double      should_be_position;
        
-       /// The duration of the current MIDI clock frame in frames
-       nframes_t   current_midi_clock_frame_duration;
-
-       /// how many MIDI clock frames to average over
-       static const int32_t accumulator_size = 1;
-       double  accumulator[accumulator_size];
-       int32_t accumulator_index;
+       /// the number of midi clock messages received (zero-based)
+       /// since start
+       long midi_clock_count;
+       
+       //the delay locked loop (DLL), see www.kokkinizita.net/papers/usingdll.pdf
+       
+       /// time at the beginning of the MIDI clock frame
+       double t0;
+       
+       /// calculated end of the MIDI clock frame
+       double t1;
+       
+       /// loop error = real value - expected value
+       double e;
+       
+       /// second order loop error
+       double e2;
+       
+       /// DLL filter bandwidth
+       double bandwidth;
+       
+       /// DLL filter coefficients
+       double b, c, omega;
        
-       /// the running average of current_midi_clock_frame_duration
-       double  average_midi_clock_frame_duration;
-
        void reset ();
        void start (MIDI::Parser& parser, nframes_t timestamp);
+       void contineu (MIDI::Parser& parser, nframes_t timestamp);
        void stop (MIDI::Parser& parser, nframes_t timestamp);
+       void position (MIDI::Parser& parser, MIDI::byte* message, size_t size);
        // we can't use continue because it is a C++ keyword
-       void contineu (MIDI::Parser& parser, nframes_t timestamp);
        void calculate_one_ppqn_in_frames_at(nframes_t time);
+       nframes_t calculate_song_position(uint16_t song_position_in_sixteenth_notes);
+       void calculate_filter_coefficients();
        void update_midi_clock (MIDI::Parser& parser, nframes_t timestamp);
        void read_current (SafeTime *) const;
        bool stop_if_no_more_clock_events(nframes_t& pos, nframes_t now);
@@ -269,7 +295,7 @@ class ADAT_Slave : public Slave
        ADAT_Slave () {}
        ~ADAT_Slave () {}
 
-       bool speed_and_position (float& speed, nframes_t& pos) {
+       bool speed_and_position (double& speed, nframes_t& pos) {
                speed = 0;
                pos = 0;
                return false;
@@ -287,7 +313,7 @@ class JACK_Slave : public Slave
        JACK_Slave (jack_client_t*);
        ~JACK_Slave ();
 
-       bool speed_and_position (float& speed, nframes_t& pos);
+       bool speed_and_position (double& speed, nframes_t& pos);
 
        bool starting() const { return _starting; }
        bool locked() const;
@@ -299,7 +325,7 @@ class JACK_Slave : public Slave
 
   private:
        jack_client_t* jack;
-       float speed;
+       double speed;
        bool _starting;
 };