* fixed jitter problems for midi clock and removed superfluous UI elements
authorHans Baier <hansfbaier@googlemail.com>
Sat, 25 Oct 2008 08:28:10 +0000 (08:28 +0000)
committerHans Baier <hansfbaier@googlemail.com>
Sat, 25 Oct 2008 08:28:10 +0000 (08:28 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@4008 d708f5d6-7413-0410-9779-e7cbd77b26cf

14 files changed:
gtk2_ardour/ardour_ui.h
gtk2_ardour/ardour_ui_ed.cc
gtk2_ardour/ardour_ui_options.cc
libs/ardour/ardour/configuration_vars.h
libs/ardour/ardour/session.h
libs/ardour/ardour/slave.h
libs/ardour/midi_clock_slave.cc
libs/ardour/session_midi.cc
libs/midi++2/jack_midiport.cc
libs/midi++2/midi++/jack.h
libs/midi++2/midi++/parser.h
libs/midi++2/midi++/port.h
libs/midi++2/midiparser.cc
libs/pbd/pbd/ringbuffer.h

index dccf5ef38a2ea18489339031e9954c7d6bed00f5..64cdf1348f2490c61ae66f7704e874a357ef9c6b 100644 (file)
@@ -701,7 +701,6 @@ class ARDOUR_UI : public Gtkmm2ext::UI
        void toggle_use_mmc ();
        void toggle_send_mmc ();
        void toggle_send_mtc ();
-       void toggle_use_midi_clock ();
 
        void toggle_use_osc ();
 
index 9f9ac269f199a4883bc9d0dd9231a47a59c136b9..89fa04c79bcf4aa0239981374369d87f366c1acb 100644 (file)
@@ -436,8 +436,6 @@ ARDOUR_UI::install_actions ()
        ActionManager::session_sensitive_actions.push_back (act);
        act = ActionManager::register_toggle_action (option_actions, X_("UseMMC"), _("Use MMC"), mem_fun (*this, &ARDOUR_UI::toggle_use_mmc));
        ActionManager::session_sensitive_actions.push_back (act);
-       act = ActionManager::register_toggle_action (option_actions, X_("UseMIDIClock"), _("Use MIDI Clock"), mem_fun (*this, &ARDOUR_UI::toggle_use_midi_clock));
-       ActionManager::session_sensitive_actions.push_back (act);
        act = ActionManager::register_toggle_action (option_actions, X_("SendMIDIfeedback"), _("Send MIDI feedback"), mem_fun (*this, &ARDOUR_UI::toggle_send_midi_feedback));
        ActionManager::session_sensitive_actions.push_back (act);
 
index 4c1aae1583b46480fb377e58fe5e89f034474c5f..410c39268c026b4516f046f0b163ae6c5b280270 100644 (file)
@@ -67,12 +67,6 @@ ARDOUR_UI::toggle_use_mmc ()
        ActionManager::toggle_config_state ("options", "UseMMC", &Configuration::set_mmc_control, &Configuration::get_mmc_control);
 }
 
-void
-ARDOUR_UI::toggle_use_midi_clock ()
-{
-       ActionManager::toggle_config_state ("options", "UseMIDIClock", &Configuration::set_midi_clock_control, &Configuration::get_midi_clock_control);
-}
-
 void
 ARDOUR_UI::toggle_use_osc ()
 {
@@ -1108,8 +1102,6 @@ ARDOUR_UI::parameter_changed (const char* parameter_name)
 
        } else if (PARAM_IS ("mmc-control")) {
                ActionManager::map_some_state ("options", "UseMMC", &Configuration::get_mmc_control);
-       } else if (PARAM_IS ("midi-clock-control")) {
-               ActionManager::map_some_state ("options", "UseMIDIClock", &Configuration::get_midi_clock_control);
        } else if (PARAM_IS ("midi-feedback")) {
                ActionManager::map_some_state ("options", "SendMIDIfeedback", &Configuration::get_midi_feedback);
        } else if (PARAM_IS ("do-not-record-plugins")) {
index f433cf94a7aab870f45853fa4fb30acbdf47cfd2..055d47b7c1bf89c03caab062e150032b8e66db1a 100644 (file)
@@ -36,7 +36,6 @@ CONFIG_VARIABLE (bool, trace_midi_output, "trace-midi-output", false)
 CONFIG_VARIABLE (bool, send_mtc, "send-mtc", false)
 CONFIG_VARIABLE (bool, send_mmc, "send-mmc", true)
 CONFIG_VARIABLE (bool, mmc_control, "mmc-control", true)
-CONFIG_VARIABLE (bool, midi_clock_control, "midi-clock-control", false)
 CONFIG_VARIABLE (bool, midi_feedback, "midi-feedback", false)
 CONFIG_VARIABLE (uint8_t, mmc_receive_device_id, "mmc-receive-device-id", 0)
 CONFIG_VARIABLE (uint8_t, mmc_send_device_id, "mmc-send-device-id", 0)
index dff59e024389c14c5db17d85c65063529403d59e..ff2bc9c12727c4be3e5f15f1c705a4ff070b8f53 100644 (file)
@@ -1306,13 +1306,9 @@ class Session : public PBD::StatefulDestructible
 
        void deliver_mmc (MIDI::MachineControl::Command, nframes_t);
 
-       void spp_start (MIDI::Parser&);
-       void spp_continue (MIDI::Parser&);
-       void spp_stop (MIDI::Parser&);
-
-       void midi_clock_start (MIDI::Parser&);
-       void midi_clock_continue (MIDI::Parser&);
-       void midi_clock_stop (MIDI::Parser&);
+       void spp_start (MIDI::Parser&, nframes_t timestamp);
+       void spp_continue (MIDI::Parser&, nframes_t timestamp);
+       void spp_stop (MIDI::Parser&, nframes_t timestamp);
 
        void mmc_deferred_play (MIDI::MachineControl &);
        void mmc_stop (MIDI::MachineControl &);
index 7c7f1d98ce82ffc75e6020454db9952c5b6a8b87..9460d4d83c2bf3831e8597739ab5b174ea1bb001 100644 (file)
@@ -143,9 +143,9 @@ class MIDIClock_Slave : public Slave, public sigc::trackable {
        float   average;
 
        void reset ();
-       void start (MIDI::Parser& parser);
-       void stop (MIDI::Parser& parser);
-       void update_midi_clock (MIDI::Parser& parser);
+       void start (MIDI::Parser& parser, nframes_t timestamp);
+       void stop (MIDI::Parser& parser, nframes_t timestamp);
+       void update_midi_clock (MIDI::Parser& parser, nframes_t timestamp);
        void read_current (SafeTime *) const;
 
        bool _started;
index 42ce24c4389e4aa5b1eadc5c1f9c277abcda1d7b..aee640e16e7cc4fabbb33c89668b223dc445f77b 100644 (file)
 #include <pbd/pthread_utils.h>
 
 #include <midi++/port.h>
+#include <midi++/jack.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 ARDOUR;
@@ -73,9 +75,9 @@ MIDIClock_Slave::rebind (MIDI::Port& p)
 }
 
 void
-MIDIClock_Slave::update_midi_clock (Parser& parser)
+MIDIClock_Slave::update_midi_clock (Parser& parser, nframes_t timestamp)
 {      
-       nframes_t now = session.engine().frame_time();
+       nframes_t now = timestamp;
 
        SafeTime last;
        read_current (&last);
@@ -109,8 +111,14 @@ MIDIClock_Slave::update_midi_clock (Parser& parser)
                average += accumulator[i];
        average /= accumulator_size;
        
+       JACK_MidiPort *jack_port = dynamic_cast<JACK_MidiPort *>(port);
+       pthread_t process_thread_id = 0;
+       if(jack_port) {
+               process_thread_id = jack_port->get_process_thread();
+       }
        
-       std::cerr << "got MIDI Clock message at time " << now  
+       std::cerr << "Thread " << pthread_name() << " with id " << pthread_self() << " process Thread ID: " << process_thread_id
+                 << " got MIDI Clock message at time " << now  
                  << " real delta: " << midi_clock_frame 
                  << " reference: " << one_ppqn_in_frames
                  << " accu index: " << accumulator_index
@@ -127,7 +135,7 @@ MIDIClock_Slave::update_midi_clock (Parser& parser)
 }
 
 void
-MIDIClock_Slave::start (Parser& parser)
+MIDIClock_Slave::start (Parser& parser, nframes_t timestamp)
 {
        
        nframes_t now = session.engine().frame_time();
@@ -154,7 +162,7 @@ MIDIClock_Slave::start (Parser& parser)
 }
 
 void
-MIDIClock_Slave::stop (Parser& parser)
+MIDIClock_Slave::stop (Parser& parser, nframes_t timestamp)
 {
        std::cerr << "MIDIClock_Slave got stop message" << endl;
 
@@ -225,7 +233,7 @@ MIDIClock_Slave::speed_and_position (float& speed, nframes_t& pos)
                pos = last.position;
                session.request_locate (pos, false);
                session.request_transport_speed (0);
-               this->stop(*port->input());
+               this->stop(*port->input(), now);
                reset();
                return false;
        }
@@ -238,7 +246,8 @@ MIDIClock_Slave::speed_and_position (float& speed, nframes_t& pos)
 
        speed = midi_clock_speed;
        
-       cerr << " final speed: " << speed << " elapsed: " << elapsed << " elapsed (scaled)  " << elapsed * speed << " position: " << pos << endl;
+       cerr << " final speed: " << speed << " elapsed: " << elapsed << " elapsed (scaled)  " << elapsed * speed << " position: " << pos 
+            << " Thread ID: " << pthread_self() << endl;
        return true;
 }
 
index dd927a3add97a3e8be01864af4eff05a82df98c3..64903f24a226b3c6765cd971fdcde3fb9a61b767 100644 (file)
@@ -317,10 +317,6 @@ Session::set_midi_clock_port (string port_tag)
 
        Config->set_midi_clock_port_name (port_tag);
 
-       _midi_clock_port->input()->start.connect (mem_fun (*this, &Session::midi_clock_start));
-       _midi_clock_port->input()->contineu.connect (mem_fun (*this, &Session::midi_clock_continue));
-       _midi_clock_port->input()->stop.connect (mem_fun (*this, &Session::midi_clock_stop));
-
   out:
        MIDIClock_PortChanged(); /* EMIT SIGNAL */
        change_midi_ports ();
@@ -496,7 +492,7 @@ Session::setup_midi_control ()
 }
 
 void
-Session::spp_start (Parser& ignored)
+Session::spp_start (Parser& ignored, nframes_t timestamp)
 {
        if (Config->get_mmc_control() && (Config->get_slave_source() != MTC)) {
                request_transport_speed (1.0);
@@ -504,40 +500,41 @@ Session::spp_start (Parser& ignored)
 }
 
 void
-Session::spp_continue (Parser& ignored)
+Session::spp_continue (Parser& ignored, nframes_t timestamp)
 {
-       spp_start (ignored);
+       spp_start (ignored, timestamp);
 }
 
 void
-Session::spp_stop (Parser& ignored)
+Session::spp_stop (Parser& ignored, nframes_t timestamp)
 {
        if (Config->get_mmc_control()) {
                request_stop ();
        }
 }
-
+/*
 void
-Session::midi_clock_start (Parser& ignored)
+Session::midi_clock_start (Parser& ignored, nframes_t timestamp)
 {
-       if (Config->get_midi_clock_control() && (Config->get_slave_source() == MIDIClock)) {
+       if (Config->get_slave_source() == MIDIClock) {
                request_transport_speed (1.0);
        }
 }
 
 void
-Session::midi_clock_continue (Parser& ignored)
+Session::midi_clock_continue (Parser& parser, nframes_t timestamp)
 {
-       midi_clock_start (ignored);
+       midi_clock_start (parser, 0);
 }
 
 void
-Session::midi_clock_stop (Parser& ignored)
+Session::midi_clock_stop (Parser& ignored, nframes_t timestamp)
 {
-       if (Config->get_midi_clock_control()) {
+       if (Config->get_slave_source() == MIDIClock) {
                request_stop ();
        }
 }
+*/
 
 void
 Session::mmc_deferred_play (MIDI::MachineControl &mmc)
index fc1ba234a3b4f27c3253a5bcc5c73a135fe1f0e6..d00e537a5217c909e146a13b4c754db97d140ea7 100644 (file)
@@ -78,6 +78,8 @@ JACK_MidiPort::cycle_start (nframes_t nframes)
                if (input_parser) {
                        input_parser->raw_preparse (*input_parser, ev.buffer, ev.size);
                        for (size_t i = 0; i < ev.size; i++) {
+                               // the midi events here are used for MIDI clock only
+                               input_parser->set_midi_clock_timestamp(ev.time + jack_last_frame_time(_jack_client));
                                input_parser->scanner (ev.buffer[i]);
                        }       
                        input_parser->raw_postparse (*input_parser, ev.buffer, ev.size);
index 10a121baee028adfe5b5bb1c9cf3e90816acc4ca..6c086210892992bfdb3c6b76979c6a31446bb425 100644 (file)
@@ -60,7 +60,9 @@ public:
        virtual void set_state (const XMLNode&);
 
        static void set_process_thread (pthread_t);
-
+       static pthread_t get_process_thread () { return _process_thread; }
+       static bool is_process_thread();
+       
   protected:
        std::string get_typestring () const {
                return typestring;
@@ -78,7 +80,7 @@ private:
        void flush (void* jack_port_buffer);
 
        static pthread_t _process_thread;
-       static bool is_process_thread();
+       
 
        RingBuffer<Evoral::Event> non_process_thread_fifo;
        Glib::Mutex non_process_thread_fifo_lock;
index 73c7c75f614732dbce9ac36e9afb4939243d7aee..6733740ff797bf35d10445f03d7b82f22f834eed 100644 (file)
@@ -74,15 +74,15 @@ class Parser : public sigc::trackable {
        Signal                position;
        Signal                song;
 
-       Signal                        mtc;
+       Signal                       mtc;
        sigc::signal<void,Parser&>   mtc_qtr;
 
-       sigc::signal<void, Parser &>          all_notes_off;
-       sigc::signal<void, Parser &>          tune;
-       sigc::signal<void, Parser &>          timing;
-       sigc::signal<void, Parser &>          start;
-       sigc::signal<void, Parser &>          stop;
-       sigc::signal<void, Parser &>          contineu;  /* note spelling */
+       sigc::signal<void, Parser &>                     all_notes_off;
+       sigc::signal<void, Parser &>                     tune;
+       sigc::signal<void, Parser &, nframes_t>          timing;
+       sigc::signal<void, Parser &, nframes_t>          start;
+       sigc::signal<void, Parser &, nframes_t>          stop;
+       sigc::signal<void, Parser &, nframes_t>          contineu;  /* note spelling */
        sigc::signal<void, Parser &>          active_sense;
        sigc::signal<void, Parser &>          reset;
        sigc::signal<void, Parser &>          eox;
@@ -121,6 +121,9 @@ class Parser : public sigc::trackable {
        MTC_Status  mtc_running() const { return _mtc_running; }
        const byte *mtc_current() const { return _mtc_time; }
        bool        mtc_locked() const  { return _mtc_locked; }
+       
+       const nframes_t get_midi_clock_timestamp() const { return _midi_clock_timestamp; }
+       void set_midi_clock_timestamp(const nframes_t timestamp) { _midi_clock_timestamp = timestamp; } 
 
        sigc::signal<void,MTC_Status> mtc_status;
        sigc::signal<bool>            mtc_skipped;
@@ -168,6 +171,8 @@ class Parser : public sigc::trackable {
        MTC_Status _mtc_running;
        bool       _mtc_locked;
        byte last_qtr_frame;
+       
+       nframes_t _midi_clock_timestamp;
 
        ParseState pre_variable_state;
        MIDI::eventType pre_variable_msgtype;
index 74ed206932728b47f1f6f0e015d03f38c5d48b16..7522bc520f483fcc833f3c608269c6de08ec39eb 100644 (file)
@@ -87,7 +87,7 @@ class Port : public sigc::trackable {
        int three_byte_msg (byte a, byte b, byte c, timestamp_t timestamp) {
                byte msg[3];
 
-               msg[0] = a;
+               msg[0] = a;
                msg[1] = b;
                msg[2] = c;
 
index b533195c5f318ce25e69b184c23791c20b342351..423e833d2ca17bcec3f57f2b09f59339ea90eaa9 100644 (file)
@@ -538,16 +538,16 @@ Parser::realtime_msg(unsigned char inbyte)
 
        switch (inbyte) {
        case 0xf8:
-               timing (*this);
+               timing (*this, _midi_clock_timestamp);
                break;
        case 0xfa:
-               start (*this);
+               start (*this, _midi_clock_timestamp);
                break;
        case 0xfb:
-               contineu (*this);
+               contineu (*this, _midi_clock_timestamp);
                break;
        case 0xfc:
-               stop (*this);
+               stop (*this, _midi_clock_timestamp);
                break;
        case 0xfe:
                /* !!! active sense message in realtime_msg: should not reach here
index 3502bed21b71cfac2759957b2158f057bfe204a4..a84ed73e7f951db51b84d53fbaac244873ceb72e 100644 (file)
@@ -56,7 +56,7 @@ class RingBuffer
        }
        
        guint read  (T *dest, guint cnt);
-       guint  write (T *src, guint cnt);
+       guint write (T *src,  guint cnt);
 
        struct rw_vector {
            T *buf[2];