Update Latency GUI behavior
authorRobin Gareus <robin@gareus.org>
Wed, 17 Jul 2019 15:04:25 +0000 (17:04 +0200)
committerRobin Gareus <robin@gareus.org>
Wed, 17 Jul 2019 15:31:08 +0000 (17:31 +0200)
This allows to set the current nominal latency as custom latency.
Previously it was not possible to use the "initial_value" as custom
parameter.

gtk2_ardour/latency_gui.cc
gtk2_ardour/latency_gui.h

index 61e9d15eeaf986dbfee335ce2aaef3297d0a6a9d..a323b4fbc2ad89633b39da7535690cec93aa14ac 100644 (file)
@@ -65,12 +65,12 @@ LatencyBarController::get_label (double&)
        return s.str ();
 }
 
-LatencyGUI::LatencyGUI (Latent& l, samplepos_t sr, samplepos_t psz, bool apply)
+LatencyGUI::LatencyGUI (Latent& l, samplepos_t sr, samplepos_t psz)
        : _latent (l)
-       , initial_value (_latent.effective_latency ())
        , sample_rate (sr)
        , period_size (psz)
        , ignored (new PBD::IgnorableControllable())
+       , _ignore_change (false)
        , adjustment (0, 0.0, sample_rate, 1.0, sample_rate / 1000.0f) /* max 1 second, step by samples, page by msecs */
        , bc (adjustment, this)
        , reset_button (_("Reset"))
@@ -104,6 +104,12 @@ LatencyGUI::LatencyGUI (Latent& l, samplepos_t sr, samplepos_t psz, bool apply)
        plus_button.signal_clicked().connect (sigc::bind (sigc::mem_fun (*this, &LatencyGUI::change_latency_from_button), 1));
        reset_button.signal_clicked().connect (sigc::mem_fun (*this, &LatencyGUI::reset));
 
+       /* Limit value to adjustment range (max = sample_rate).
+        * Otherwise if the signal_latency() is larger than the adjustment's max,
+        * LatencyGUI::finish() would set the adjustment's max value as custom-latency.
+        */
+       adjustment.set_value (std::min (sample_rate, _latent.signal_latency ()));
+
        adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &LatencyGUI::finish));
 
        bc.set_size_request (-1, 25);
@@ -117,28 +123,26 @@ LatencyGUI::LatencyGUI (Latent& l, samplepos_t sr, samplepos_t psz, bool apply)
 void
 LatencyGUI::finish ()
 {
-       samplepos_t new_value = (samplepos_t) adjustment.get_value();
-       if (new_value != initial_value) {
-               _latent.set_user_latency (new_value);
+       if (_ignore_change) {
+               return;
        }
+       samplepos_t new_value = (samplepos_t) adjustment.get_value();
+       _latent.set_user_latency (new_value);
 }
 
 void
 LatencyGUI::reset ()
 {
        _latent.unset_user_latency ();
-       initial_value = std::min (sample_rate, _latent.signal_latency ());
-       adjustment.set_value (initial_value);
+       PBD::Unwinder<bool> uw (_ignore_change, true);
+       adjustment.set_value (std::min (sample_rate, _latent.signal_latency ()));
 }
 
 void
 LatencyGUI::refresh ()
 {
-       /* limit to adjustment range, otherwise LatencyGUI::finish() would
-        * set the adjustment's value as custom-latency
-        */
-       initial_value = std::min (sample_rate, _latent.effective_latency ());
-       adjustment.set_value (initial_value);
+       PBD::Unwinder<bool> uw (_ignore_change, true);
+       adjustment.set_value (std::min (sample_rate, _latent.effective_latency ()));
 }
 
 void
index 943944571ea59f1956ad0b22a657c46169578a6a..25e469abfc22308e8fbc1f4055c1ae6b2795bacd 100644 (file)
@@ -60,17 +60,19 @@ public:
        LatencyGUI (ARDOUR::Latent&, samplepos_t sample_rate, samplepos_t period_size);
        ~LatencyGUI() { }
 
-       void finish ();
-       void reset ();
        void refresh ();
 
 private:
+       void reset ();
+       void finish ();
+
        ARDOUR::Latent& _latent;
-       samplepos_t initial_value;
        samplepos_t sample_rate;
        samplepos_t period_size;
+
        boost::shared_ptr<PBD::IgnorableControllable> ignored;
 
+       bool _ignore_change;
        Gtk::Adjustment adjustment;
        LatencyBarController bc;
        Gtk::HBox hbox1;