diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index fca86c585b..c4e037a5bf 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -490,17 +490,6 @@ ARDOUR_UI::post_engine () Config->ParameterChanged.connect (forever_connections, MISSING_INVALIDATOR, boost::bind (&ARDOUR_UI::parameter_changed, this, _1), gui_context()); boost::function pc (boost::bind (&ARDOUR_UI::parameter_changed, this, _1)); Config->map_parameters (pc); - - /* now start and maybe save state */ - - if (do_engine_start () == 0) { - if (_session && _session_is_new) { - /* we need to retain initial visual - settings for a new session - */ - _session->save_state (""); - } - } } ARDOUR_UI::~ARDOUR_UI () @@ -2035,7 +2024,8 @@ ARDOUR_UI::engine_stopped () void ARDOUR_UI::engine_running () { - ENSURE_GUI_THREAD (*this, &ARDOUR_UI::engine_running) + post_engine(); + ActionManager::set_sensitive (ActionManager::jack_sensitive_actions, true); ActionManager::set_sensitive (ActionManager::jack_opposite_sensitive_actions, false); @@ -2127,24 +2117,6 @@ JACK, reconnect and save the session."), PROGRAM_NAME); } } -int32_t -ARDOUR_UI::do_engine_start () -{ - try { - engine->start(); - } - - catch (...) { - engine->stop (); - error << _("Unable to start the session running") - << endmsg; - unload_session (); - return -2; - } - - return 0; -} - void ARDOUR_UI::update_clocks () { diff --git a/gtk2_ardour/engine_dialog.cc b/gtk2_ardour/engine_dialog.cc index b4e5c72050..3a06fb5072 100644 --- a/gtk2_ardour/engine_dialog.cc +++ b/gtk2_ardour/engine_dialog.cc @@ -17,6 +17,7 @@ */ +#include #include #include #include @@ -27,20 +28,9 @@ #include #include -#include "pbd/epa.h" +#include "pbd/error.h" #include "pbd/xml++.h" -#ifdef __APPLE__ -#include -#include -#include -#include -#elif !defined(__FreeBSD__) -#include -#endif - -#include - #include #include @@ -50,11 +40,6 @@ #include "pbd/convert.h" #include "pbd/error.h" -#include "pbd/pathscanner.h" - -#ifdef __APPLE -#include -#endif #include "engine_dialog.h" #include "i18n.h" @@ -355,19 +340,6 @@ EngineControl::interface_changed () buffer_size_combo.set_active_text (s.front()); } -uint32_t -EngineControl::get_rate () -{ - double r = atof (sample_rate_combo.get_active_text ()); - /* the string may have been translated with an abbreviation for - * thousands, so use a crude heuristic to fix this. - */ - if (r < 1000.0) { - r *= 1000.0; - } - return lrint (r); -} - void EngineControl::redisplay_latency () { @@ -507,6 +479,7 @@ EngineControl::get_state () void EngineControl::set_state (const XMLNode& root) { +#if 0 XMLNodeList clist; XMLNodeConstIterator citer; XMLNode* child; @@ -516,7 +489,7 @@ EngineControl::set_state (const XMLNode& root) int val; string strval; -#if 0 + if ( (child = root.child ("driver"))){ prop = child->property("val"); @@ -655,6 +628,120 @@ EngineControl::set_state (const XMLNode& root) } int -EngineControl::setup_engine () +EngineControl::setup_engine (bool start) { + boost::shared_ptr backend = ARDOUR::AudioEngine::instance()->current_backend(); + assert (backend); + + /* grab the parameters from the GUI and apply them */ + + try { + if (backend->requires_driver_selection()) { + if (backend->set_driver (get_driver())) { + return -1; + } + } + + if (backend->set_device_name (get_device_name())) { + return -1; + } + + if (backend->set_sample_rate (get_rate())) { + error << string_compose (_("Cannot set sample rate to %1"), get_rate()) << endmsg; + return -1; + } + if (backend->set_buffer_size (get_buffer_size())) { + error << string_compose (_("Cannot set buffer size to %1"), get_buffer_size()) << endmsg; + return -1; + } + if (backend->set_input_channels (get_input_channels())) { + error << string_compose (_("Cannot set input channels to %1"), get_input_channels()) << endmsg; + return -1; + } + if (backend->set_output_channels (get_output_channels())) { + error << string_compose (_("Cannot set output channels to %1"), get_output_channels()) << endmsg; + return -1; + } + if (backend->set_systemic_input_latency (get_input_latency())) { + error << string_compose (_("Cannot set input latency to %1"), get_input_latency()) << endmsg; + return -1; + } + if (backend->set_systemic_output_latency (get_output_latency())) { + error << string_compose (_("Cannot set output latency to %1"), get_output_latency()) << endmsg; + return -1; + } + + if (start) { + return ARDOUR::AudioEngine::instance()->start(); + } + + return 0; + + } catch (...) { + cerr << "exception thrown...\n"; + return -1; + } } + +uint32_t +EngineControl::get_rate () const +{ + double r = atof (sample_rate_combo.get_active_text ()); + /* the string may have been translated with an abbreviation for + * thousands, so use a crude heuristic to fix this. + */ + if (r < 1000.0) { + r *= 1000.0; + } + return lrint (r); +} + +uint32_t +EngineControl::get_buffer_size () const +{ + string txt = buffer_size_combo.get_active_text (); + uint32_t samples; + + if (sscanf (txt.c_str(), "%d", &samples) != 1) { + throw exception (); + } + + return samples; +} + +uint32_t +EngineControl::get_input_channels() const +{ + return (uint32_t) input_channels_adjustment.get_value(); +} + +uint32_t +EngineControl::get_output_channels() const +{ + return (uint32_t) output_channels_adjustment.get_value(); +} + +uint32_t +EngineControl::get_input_latency() const +{ + return (uint32_t) input_latency_adjustment.get_value(); +} + +uint32_t +EngineControl::get_output_latency() const +{ + return (uint32_t) output_latency_adjustment.get_value(); +} + +string +EngineControl::get_driver () const +{ + return driver_combo.get_active_text (); +} + +string +EngineControl::get_device_name () const +{ + return interface_combo.get_active_text (); +} + diff --git a/gtk2_ardour/engine_dialog.h b/gtk2_ardour/engine_dialog.h index ac96fbc520..07cf0afa8f 100644 --- a/gtk2_ardour/engine_dialog.h +++ b/gtk2_ardour/engine_dialog.h @@ -40,7 +40,7 @@ class EngineControl : public Gtk::VBox { ~EngineControl (); static bool need_setup (); - int setup_engine (); + int setup_engine (bool start); bool was_used() const { return _used; } XMLNode& get_state (); @@ -104,7 +104,16 @@ class EngineControl : public Gtk::VBox { void backend_changed (); void redisplay_latency (); - uint32_t get_rate(); + + uint32_t get_rate() const; + uint32_t get_buffer_size() const; + uint32_t get_input_channels() const; + uint32_t get_output_channels() const; + uint32_t get_input_latency() const; + uint32_t get_output_latency() const; + std::string get_device_name() const; + std::string get_driver() const; + void audio_mode_changed (); void interface_changed (); void list_devices (); diff --git a/gtk2_ardour/startup.cc b/gtk2_ardour/startup.cc index 8314a0986e..bfd9c88633 100644 --- a/gtk2_ardour/startup.cc +++ b/gtk2_ardour/startup.cc @@ -662,8 +662,10 @@ ArdourStartup::on_delete_event (GdkEventAny*) void ArdourStartup::on_apply () { + cerr << "apply, engine = " << engine_dialog << endl; if (engine_dialog) { - if (engine_dialog->setup_engine ()) { + cerr << "Set up engine\n"; + if (engine_dialog->setup_engine (true)) { set_current_page (audio_page_index); return; } diff --git a/libs/ardour/jack_audiobackend.cc b/libs/ardour/jack_audiobackend.cc index 97031cfaff..8ab8428555 100644 --- a/libs/ardour/jack_audiobackend.cc +++ b/libs/ardour/jack_audiobackend.cc @@ -197,13 +197,13 @@ JACKAudioBackend::set_device_name (const string& dev) int JACKAudioBackend::set_sample_rate (float sr) { - GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1); - if (!connected()) { _target_sample_rate = sr; return 0; } + GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1); + if (sr == jack_get_sample_rate (_priv_jack)) { return 0; } @@ -214,13 +214,13 @@ JACKAudioBackend::set_sample_rate (float sr) int JACKAudioBackend::set_buffer_size (uint32_t nframes) { - GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1); - if (!connected()) { _target_buffer_size = nframes; return 0; } + GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1); + if (nframes == jack_get_buffer_size (_priv_jack)) { return 0; } @@ -384,6 +384,8 @@ JACKAudioBackend::setup_jack_startup_command () JackCommandLineOptions options; + get_jack_default_server_path (options.server_path); + options.driver = _target_driver; options.samplerate = _target_sample_rate; options.period_size = _target_buffer_size; options.num_periods = 2; @@ -394,7 +396,9 @@ JACKAudioBackend::setup_jack_startup_command () if (_target_sample_format == FormatInt16) { options.force16_bit = _target_sample_format; } - + options.realtime = true; + options.ports_max = 2048; + /* this must always be true for any server instance we start ourselves */ @@ -422,7 +426,6 @@ JACKAudioBackend::start () setup_jack_startup_command (); } - std::cerr << "Open JACK connection\n"; _jack_connection->open (); } diff --git a/libs/ardour/jack_utils.cc b/libs/ardour/jack_utils.cc index 606b71603a..ea1aea2623 100644 --- a/libs/ardour/jack_utils.cc +++ b/libs/ardour/jack_utils.cc @@ -667,7 +667,7 @@ ARDOUR::JackCommandLineOptions::JackCommandLineOptions () , ports_max(128) , realtime(true) , priority(0) - , unlock_gui_libs(true) + , unlock_gui_libs(false) , verbose(false) , temporary(true) , driver() @@ -759,14 +759,12 @@ ARDOUR::get_jack_command_line_string (const JackCommandLineOptions& options, str string command_line_output_device_name; if (!get_jack_command_line_audio_device_name (options.driver, - options.input_device, command_line_input_device_name)) - { + options.input_device, command_line_input_device_name)) { return false; } if (!get_jack_command_line_audio_device_name (options.driver, - options.output_device, command_line_output_device_name)) - { + options.output_device, command_line_output_device_name)) { return false; }