GUI chores to show nperiods option.
authorRobin Gareus <robin@gareus.org>
Sat, 5 Dec 2015 00:32:56 +0000 (01:32 +0100)
committerRobin Gareus <robin@gareus.org>
Sat, 5 Dec 2015 00:53:13 +0000 (01:53 +0100)
gtk2_ardour/engine_dialog.cc
gtk2_ardour/engine_dialog.h

index 8c0694713dfc01b5ae0b7497d2e895292966fb01..06736622088c144aef3d4bb53eb66efe6cb566c2 100644 (file)
@@ -321,6 +321,8 @@ EngineControl::connect_changed_signals ()
            sigc::mem_fun (*this, &EngineControl::sample_rate_changed));
        buffer_size_combo_connection = buffer_size_combo.signal_changed ().connect (
            sigc::mem_fun (*this, &EngineControl::buffer_size_changed));
+       nperiods_combo_connection = nperiods_combo.signal_changed ().connect (
+           sigc::mem_fun (*this, &EngineControl::nperiods_changed));
        device_combo_connection = device_combo.signal_changed ().connect (
            sigc::mem_fun (*this, &EngineControl::device_changed));
        midi_option_combo_connection = midi_option_combo.signal_changed ().connect (
@@ -350,6 +352,7 @@ EngineControl::block_changed_signals ()
                driver_combo_connection.block ();
                sample_rate_combo_connection.block ();
                buffer_size_combo_connection.block ();
+               nperiods_combo_connection.block ();
                device_combo_connection.block ();
                input_device_combo_connection.block ();
                output_device_combo_connection.block ();
@@ -370,6 +373,7 @@ EngineControl::unblock_changed_signals ()
                driver_combo_connection.unblock ();
                sample_rate_combo_connection.unblock ();
                buffer_size_combo_connection.unblock ();
+               nperiods_combo_connection.unblock ();
                device_combo_connection.unblock ();
                input_device_combo_connection.unblock ();
                output_device_combo_connection.unblock ();
@@ -572,9 +576,18 @@ EngineControl::build_full_control_notebook ()
        buffer_size_duration_label.set_alignment (0.0); /* left-align */
        basic_packer.attach (buffer_size_duration_label, 2, 3, row, row+1, SHRINK, (AttachOptions) 0);
 
-       /* button spans 2 rows */
+       int ctrl_btn_span = 1;
+       if (backend->can_set_period_size ()) {
+               row++;
+               label = manage (left_aligned_label (_("Periods:")));
+               basic_packer.attach (*label, 0, 1, row, row + 1, xopt, (AttachOptions) 0);
+               basic_packer.attach (nperiods_combo, 1, 2, row, row + 1, xopt, (AttachOptions) 0);
+               ++ctrl_btn_span;
+       }
 
-       basic_packer.attach (control_app_button, 3, 4, row-1, row+1, xopt, xopt);
+       /* button spans 2 or 3 rows */
+
+       basic_packer.attach (control_app_button, 3, 4, row - ctrl_btn_span, row + 1, xopt, xopt);
        row++;
 
        input_channels.set_name ("InputChannels");
@@ -831,6 +844,19 @@ EngineControl::update_sensitivity ()
                valid = false;
        }
 
+       if (get_popdown_string_count (nperiods_combo) > 0) {
+               if (!ARDOUR::AudioEngine::instance()->running()) {
+                       nperiods_combo.set_sensitive (true);
+               } else {
+                       nperiods_combo.set_sensitive (false);
+               }
+       } else {
+               nperiods_combo.set_sensitive (false);
+               if (backend->can_set_period_size()) {
+                       valid = false;
+               }
+       }
+
        if (_have_control) {
                start_stop_button.set_sensitive(true);
                start_stop_button.show();
@@ -1442,6 +1468,31 @@ EngineControl::set_buffersize_popdown_strings ()
        update_sensitivity ();
 }
 
+void
+EngineControl::set_nperiods_popdown_strings ()
+{
+       DEBUG_ECONTROL ("set_nperiods_popdown_strings");
+       boost::shared_ptr<ARDOUR::AudioBackend> backend = ARDOUR::AudioEngine::instance()->current_backend();
+       vector<uint32_t> np;
+       vector<string> s;
+
+       if (backend->can_set_period_size()) {
+               np = backend->available_period_sizes (get_driver());
+       }
+
+       for (vector<uint32_t>::const_iterator x = np.begin(); x != np.end(); ++x) {
+               s.push_back (nperiods_as_string (*x));
+       }
+
+       set_popdown_strings (nperiods_combo, s);
+
+       if (!s.empty()) {
+               set_active_text_if_present (nperiods_combo, nperiods_as_string (backend->period_size())); // XXX 
+       }
+
+       update_sensitivity ();
+}
+
 void
 EngineControl::device_changed ()
 {
@@ -1490,6 +1541,7 @@ EngineControl::device_changed ()
 
                set_samplerate_popdown_strings ();
                set_buffersize_popdown_strings ();
+               set_nperiods_popdown_strings ();
 
                /* TODO set min + max channel counts here */
 
@@ -1528,6 +1580,15 @@ EngineControl::bufsize_as_string (uint32_t sz)
        return buf;
 }
 
+string
+EngineControl::nperiods_as_string (uint32_t np)
+{
+       char buf[8];
+       snprintf (buf, sizeof (buf), "%u", np);
+       return buf;
+}
+
+
 void
 EngineControl::sample_rate_changed ()
 {
@@ -1547,6 +1608,13 @@ EngineControl::buffer_size_changed ()
        show_buffer_duration ();
 }
 
+void
+EngineControl::nperiods_changed ()
+{
+       DEBUG_ECONTROL ("nperiods_changed");
+       show_buffer_duration ();
+}
+
 void
 EngineControl::show_buffer_duration ()
 {
@@ -1559,17 +1627,12 @@ EngineControl::show_buffer_duration ()
        uint32_t samples = atoi (bs_text); /* will ignore trailing text */
        uint32_t rate = get_rate();
 
-       /* Developers: note the hard-coding of a double buffered model
-          in the (2 * samples) computation of latency. we always start
-          the audiobackend in this configuration.
-        */
-       /* note to jack1 developers: ardour also always starts the engine
-        * in async mode (no jack2 --sync option) which adds an extra cycle
-        * of latency with jack2 (and *3 would be correct)
-        * The value can also be wrong if jackd is started externally..
+       /* Except for ALSA and Dummy backends, we don't know the number of periods
+        * per cycle and settings.
         *
-        * At the time of writing the ALSA backend always uses double-buffering *2,
-        * The Dummy backend *1, and who knows what ASIO really does :)
+        * jack1 vs jack2 have different default latencies since jack2 start
+        * in async-mode unless --sync is given which adds an extra cycle
+        * of latency. The value is not known if jackd is started externally..
         *
         * So just display the period size, that's also what
         * ARDOUR_UI::update_sample_rate() does for the status bar.
@@ -1762,6 +1825,7 @@ EngineControl::store_state (State state)
        state->output_device = get_output_device_name ();
        state->sample_rate = get_rate ();
        state->buffer_size = get_buffer_size ();
+       state->n_periods = get_nperiods ();
        state->input_latency = get_input_latency ();
        state->output_latency = get_output_latency ();
        state->input_channels = get_input_channels ();
@@ -1788,6 +1852,8 @@ EngineControl::maybe_display_saved_state ()
                        sample_rate_combo.set_active_text (rate_as_string (state->sample_rate));
                }
                set_active_text_if_present (buffer_size_combo, bufsize_as_string (state->buffer_size));
+
+               set_active_text_if_present (nperiods_combo, nperiods_as_string (state->n_periods));
                /* call this explicitly because we're ignoring changes to
                   the controls at this point.
                 */
@@ -1826,6 +1892,7 @@ EngineControl::get_state ()
                        node->add_property ("output-device", (*i)->output_device);
                        node->add_property ("sample-rate", (*i)->sample_rate);
                        node->add_property ("buffer-size", (*i)->buffer_size);
+                       node->add_property ("n-periods", (*i)->n_periods);
                        node->add_property ("input-latency", (*i)->input_latency);
                        node->add_property ("output-latency", (*i)->output_latency);
                        node->add_property ("input-channels", (*i)->input_channels);
@@ -1943,6 +2010,13 @@ EngineControl::set_state (const XMLNode& root)
                        }
                        state->buffer_size = atoi (prop->value ());
 
+                       if ((prop = grandchild->property ("n-periods")) == 0) {
+                               // optional (new value in 4.5)
+                               state->n_periods = 0;
+                       } else {
+                               state->n_periods = atoi (prop->value ());
+                       }
+
                        if ((prop = grandchild->property ("input-latency")) == 0) {
                                continue;
                        }
@@ -2137,6 +2211,7 @@ EngineControl::set_current_state (const State& state)
        output_device_combo.set_active_text (state->output_device);
        sample_rate_combo.set_active_text (rate_as_string (state->sample_rate));
        set_active_text_if_present (buffer_size_combo, bufsize_as_string (state->buffer_size));
+       set_active_text_if_present (nperiods_combo, nperiods_as_string (state->n_periods));
        input_latency.set_value (state->input_latency);
        output_latency.set_value (state->output_latency);
        midi_option_combo.set_active_text (state->midi_option);
@@ -2161,6 +2236,7 @@ EngineControl::push_state_to_backend (bool start)
        bool change_device = false;
        bool change_rate = false;
        bool change_bufsize = false;
+       bool change_nperiods = false;
        bool change_latency = false;
        bool change_channels = false;
        bool change_midi = false;
@@ -2205,6 +2281,10 @@ EngineControl::push_state_to_backend (bool start)
                                change_bufsize = true;
                        }
 
+                       if (backend->can_set_period_size() && get_nperiods() != backend->period_size()) {
+                               change_nperiods = true;
+                       }
+
                        if (get_midi_option() != backend->midi_option()) {
                                change_midi = true;
                        }
@@ -2244,6 +2324,7 @@ EngineControl::push_state_to_backend (bool start)
                        change_channels = true;
                        change_latency = true;
                        change_midi = true;
+                       change_nperiods = backend->can_set_period_size();
                }
 
        } else {
@@ -2301,7 +2382,7 @@ EngineControl::push_state_to_backend (bool start)
 
        /* determine if we need to stop the backend before changing parameters */
 
-       if (change_driver || change_device || change_channels ||
+       if (change_driver || change_device || change_channels || change_nperiods ||
                        (change_latency && !backend->can_change_systemic_latency_when_running ()) ||
                        (change_rate && !backend->can_change_sample_rate_when_running()) ||
                        change_midi ||
@@ -2311,6 +2392,7 @@ EngineControl::push_state_to_backend (bool start)
                restart_required = false;
        }
 
+
        if (was_running) {
                if (restart_required) {
                        if (ARDOUR::AudioEngine::instance()->stop()) {
@@ -2346,6 +2428,10 @@ EngineControl::push_state_to_backend (bool start)
                error << string_compose (_("Cannot set buffer size to %1"), get_buffer_size()) << endmsg;
                return -1;
        }
+       if (change_nperiods && backend->set_peridod_size (get_nperiods())) {
+               error << string_compose (_("Cannot set periods to %1"), get_nperiods()) << endmsg;
+               return -1;
+       }
 
        if (change_channels || get_input_channels() == 0 || get_output_channels() == 0) {
                if (backend->set_input_channels (get_input_channels())) {
@@ -2473,6 +2559,13 @@ EngineControl::get_buffer_size () const
        return samples;
 }
 
+uint32_t
+EngineControl::get_nperiods () const
+{
+       string txt = nperiods_combo.get_active_text ();
+       return atoi (txt.c_str());
+}
+
 string
 EngineControl::get_midi_option () const
 {
@@ -2906,6 +2999,10 @@ EngineControl::engine_running ()
        set_active_text_if_present (buffer_size_combo, bufsize_as_string (backend->buffer_size()));
        sample_rate_combo.set_active_text (rate_as_string (backend->sample_rate()));
 
+       if (backend->can_set_period_size ()) {
+               set_active_text_if_present (nperiods_combo, nperiods_as_string (backend->period_size()));
+       }
+
        connect_disconnect_button.set_label (string_compose (_("Disconnect from %1"), backend->name()));
        connect_disconnect_button.show();
 
index aa768bc890c87191e8fae1e122fce624b654b999..d5c54d088e121dbbbdd6ae4665d4169bc1ef1dbf 100644 (file)
@@ -70,6 +70,7 @@ class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
     Gtk::ComboBoxText midi_option_combo;
     Gtk::ComboBoxText buffer_size_combo;
     Gtk::Label        buffer_size_duration_label;
+    Gtk::ComboBoxText nperiods_combo;
     Gtk::Adjustment input_latency_adjustment;
     Gtk::SpinButton input_latency;
     Gtk::Adjustment output_latency_adjustment;
@@ -128,6 +129,7 @@ class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
     void backend_changed ();
     void sample_rate_changed ();
     void buffer_size_changed ();
+    void nperiods_changed ();
     void parameter_changed ();
     void midi_option_changed ();
 
@@ -137,7 +139,8 @@ class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
 
        void update_midi_options ();
 
-    std::string bufsize_as_string (uint32_t);
+       std::string bufsize_as_string (uint32_t);
+       std::string nperiods_as_string (uint32_t);
 
        std::vector<float> get_default_sample_rates ();
        std::vector<uint32_t> get_default_buffer_sizes ();
@@ -147,6 +150,7 @@ class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
 
     float get_rate() const;
     uint32_t get_buffer_size() const;
+    uint32_t get_nperiods() const;
     uint32_t get_input_channels() const;
     uint32_t get_output_channels() const;
     uint32_t get_input_latency() const;
@@ -170,6 +174,7 @@ class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
     bool set_output_device_popdown_strings ();
     void set_samplerate_popdown_strings ();
     void set_buffersize_popdown_strings ();
+    void set_nperiods_popdown_strings ();
     void list_devices ();
     void show_buffer_duration ();
 
@@ -210,6 +215,7 @@ class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
        std::string output_device;
        float sample_rate;
        uint32_t buffer_size;
+       uint32_t n_periods;
        uint32_t input_latency;
        uint32_t output_latency;
        uint32_t input_channels;
@@ -284,6 +290,7 @@ class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
        sigc::connection driver_combo_connection;
        sigc::connection sample_rate_combo_connection;
        sigc::connection buffer_size_combo_connection;
+       sigc::connection nperiods_combo_connection;
        sigc::connection device_combo_connection;
        sigc::connection input_device_combo_connection;
        sigc::connection output_device_combo_connection;