can now start JACK based on config dialog

This commit is contained in:
Paul Davis 2013-08-05 12:51:51 -04:00
parent 7218bd91de
commit a66e3859e1
6 changed files with 147 additions and 76 deletions

View File

@ -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<void (string)> 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 ()
{

View File

@ -17,6 +17,7 @@
*/
#include <exception>
#include <vector>
#include <cmath>
#include <fstream>
@ -27,20 +28,9 @@
#include <glibmm.h>
#include <gtkmm/messagedialog.h>
#include "pbd/epa.h"
#include "pbd/error.h"
#include "pbd/xml++.h"
#ifdef __APPLE__
#include <CoreAudio/CoreAudio.h>
#include <CoreFoundation/CFString.h>
#include <sys/param.h>
#include <mach-o/dyld.h>
#elif !defined(__FreeBSD__)
#include <alsa/asoundlib.h>
#endif
#include <jack/jack.h>
#include <gtkmm/stock.h>
#include <gtkmm2ext/utils.h>
@ -50,11 +40,6 @@
#include "pbd/convert.h"
#include "pbd/error.h"
#include "pbd/pathscanner.h"
#ifdef __APPLE
#include <CFBundle.h>
#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<ARDOUR::AudioBackend> 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 ();
}

View File

@ -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 ();

View File

@ -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;
}

View File

@ -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 ();
}

View File

@ -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;
}