Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some audio backend cleanup / refactor #943

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gtk2_ardour/ardour_ui_startup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ ARDOUR_UI::load_from_application_api (const std::string& path)
#else
"JACK",
#endif
ARDOUR_COMMAND_LINE::backend_client_name, "")) {
ARDOUR_COMMAND_LINE::backend_session_id, "")) {
error << _("NSM: The JACK backend is mandatory and can not be loaded.") << endmsg;
return;
}
Expand Down
14 changes: 7 additions & 7 deletions gtk2_ardour/engine_dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ EngineControl::backend_changed ()
string backend_name = backend_combo.get_active_text ();
std::shared_ptr<ARDOUR::AudioBackend> backend;

if (!(backend = ARDOUR::AudioEngine::instance ()->set_backend (backend_name, ARDOUR_COMMAND_LINE::backend_client_name, ""))) {
if (!(backend = ARDOUR::AudioEngine::instance ()->set_backend (backend_name, ARDOUR_COMMAND_LINE::backend_session_id, ""))) {
/* eh? setting the backend failed... how ? */
/* A: stale config contains a backend that does not exist in current build */
return;
Expand Down Expand Up @@ -1146,7 +1146,7 @@ EngineControl::get_default_device (const string& current_device_name,
using namespace ARDOUR;

string default_device_name =
AudioBackend::get_standard_device_name (AudioBackend::DeviceDefault);
AudioBackend::get_default_device_name ();

vector<string>::const_iterator i;

Expand All @@ -1158,7 +1158,7 @@ EngineControl::get_default_device (const string& current_device_name,
}

string none_device_name =
AudioBackend::get_standard_device_name (AudioBackend::DeviceNone);
AudioBackend::get_none_device_name ();

// Use the first device that isn't "None"
for (i = available_devices.begin (); i != available_devices.end (); ++i) {
Expand Down Expand Up @@ -1581,7 +1581,7 @@ EngineControl::input_device_changed ()

std::shared_ptr<ARDOUR::AudioBackend> backend = ARDOUR::AudioEngine::instance ()->current_backend ();
if (backend && backend->match_input_output_devices_or_none ()) {
const std::string& dev_none = ARDOUR::AudioBackend::get_standard_device_name (ARDOUR::AudioBackend::DeviceNone);
const std::string& dev_none = ARDOUR::AudioBackend::get_none_device_name ();

if (get_output_device_name () != dev_none && get_input_device_name () != dev_none && get_input_device_name () != get_output_device_name ()) {
block_changed_signals ();
Expand All @@ -1603,7 +1603,7 @@ EngineControl::output_device_changed ()
DEBUG_ECONTROL ("output_device_changed");
std::shared_ptr<ARDOUR::AudioBackend> backend = ARDOUR::AudioEngine::instance ()->current_backend ();
if (backend && backend->match_input_output_devices_or_none ()) {
const std::string& dev_none = ARDOUR::AudioBackend::get_standard_device_name (ARDOUR::AudioBackend::DeviceNone);
const std::string& dev_none = ARDOUR::AudioBackend::get_none_device_name ();

if (get_input_device_name () != dev_none && get_input_device_name () != dev_none && get_input_device_name () != get_output_device_name ()) {
block_changed_signals ();
Expand Down Expand Up @@ -2207,7 +2207,7 @@ EngineControl::set_current_state (const State& state)

std::shared_ptr<ARDOUR::AudioBackend> backend;

if (!(backend = ARDOUR::AudioEngine::instance ()->set_backend (state->backend, ARDOUR_COMMAND_LINE::backend_client_name, ""))) {
if (!(backend = ARDOUR::AudioEngine::instance ()->set_backend (state->backend, ARDOUR_COMMAND_LINE::backend_session_id, ""))) {
DEBUG_ECONTROL (string_compose ("Unable to set backend to %1", state->backend));
// this shouldn't happen as the invalid backend names should have been
// removed from the list of states.
Expand Down Expand Up @@ -2489,7 +2489,7 @@ 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 ())) {
if (change_nperiods && backend->set_period_size (get_nperiods ())) {
error << string_compose (_("Cannot set periods to %1"), get_nperiods ()) << endmsg;
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion gtk2_ardour/nsm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ NSM_Client::command_open(const char* name,
{
int r = ERR_OK;

ARDOUR_COMMAND_LINE::backend_client_name = client_id;
ARDOUR_COMMAND_LINE::backend_session_id = client_id;
ARDOUR_COMMAND_LINE::session_name = "";

/* this appears asynchronous, but almost certainly is
Expand Down
6 changes: 3 additions & 3 deletions gtk2_ardour/opts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
using namespace std;

string ARDOUR_COMMAND_LINE::session_name = "";
string ARDOUR_COMMAND_LINE::backend_client_name = PBD::downcase(PROGRAM_NAME);
string ARDOUR_COMMAND_LINE::backend_session_id = PBD::downcase(PROGRAM_NAME);
bool ARDOUR_COMMAND_LINE::show_key_actions = false;
bool ARDOUR_COMMAND_LINE::show_actions = false;
bool ARDOUR_COMMAND_LINE::no_splash = false;
Expand Down Expand Up @@ -72,7 +72,7 @@ print_help (const char *execname)
<< _(" -A, --actions Print all possible menu action names\n")
<< _(" -b, --bindings Display all current key bindings\n")
<< _(" -B, --bypass-plugins Bypass all plugins in an existing session\n")
<< _(" -c, --name <name> Use a specific backend client name, default is ardour\n")
<< _(" -c, --name <session-id> Specify audio backend client session id, default is ardour\n")
<< _(" -d, --disable-plugins Disable all plugins (safe mode)\n")
#ifndef NDEBUG
<< _(" -D, --debug <options> Set debug flags. Use \"-D list\" to see available options\n")
Expand Down Expand Up @@ -218,7 +218,7 @@ ARDOUR_COMMAND_LINE::parse_opts (int argc, char *argv[])
break;

case 'c':
backend_client_name = optarg;
backend_session_id = optarg;
break;

case 'k':
Expand Down
2 changes: 1 addition & 1 deletion gtk2_ardour/opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extern bool show_key_actions;
extern bool show_actions;
extern bool no_splash;
extern bool just_version;
extern std::string backend_client_name;
extern std::string backend_session_id;
extern bool new_session;
extern bool try_hw_optimization;
extern bool no_connect_ports;
Expand Down
8 changes: 4 additions & 4 deletions headless/load_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ using namespace PBD;

static const char* localedir = LOCALEDIR;

static string backend_client_name;
static string backend_session_id;
static CrossThreadChannel xthread (true);
static TestReceiver test_receiver;

Expand All @@ -72,7 +72,7 @@ load_session (string dir, string state)

AudioEngine* engine = AudioEngine::create ();

if (!engine->set_backend (backend_name, backend_client_name, "")) {
if (!engine->set_backend (backend_name, backend_session_id, "")) {
std::cerr << "Cannot set Audio/MIDI engine backend\n";
exit (EXIT_FAILURE);
}
Expand Down Expand Up @@ -172,7 +172,7 @@ main (int argc, char* argv[])

bool try_hw_optimization = true;

backend_client_name = PBD::downcase (std::string (PROGRAM_NAME));
backend_session_id = PBD::downcase (std::string (PROGRAM_NAME));

int c;
while ((c = getopt_long (argc, argv, optstring, longopts, (int*)0)) != EOF) {
Expand All @@ -191,7 +191,7 @@ main (int argc, char* argv[])
break;

case 'c':
backend_client_name = optarg;
backend_session_id = optarg;
break;

case 'B':
Expand Down
25 changes: 8 additions & 17 deletions libs/ardour/ardour/audio_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ namespace ARDOUR
struct LIBARDOUR_API AudioBackendInfo {
const char* name;

/** Using arg1 and arg2, initialize this audiobackend.
/** Using client_name and session_id, initialize this audiobackend.
*
* Returns zero on success, non-zero otherwise.
*/
int (*instantiate) (const std::string& arg1, const std::string& arg2);
int (*instantiate) (const std::string& client_name, const std::string& session_id);

/** Release all resources associated with this audiobackend */
int (*deinstantiate) (void);
Expand Down Expand Up @@ -131,12 +131,8 @@ class LIBARDOUR_API AudioBackend : public PortEngine

static std::string get_error_string (ErrorCode);

enum StandardDeviceName {
DeviceNone,
DeviceDefault
};

static std::string get_standard_device_name (StandardDeviceName);
static std::string get_none_device_name ();
static std::string get_default_device_name ();

/** Return the AudioBackendInfo object from which this backend
* was constructed.
Expand All @@ -153,15 +149,10 @@ class LIBARDOUR_API AudioBackend : public PortEngine
*/
virtual std::string name () const = 0;

/** Return true if the callback from the underlying mechanism/API
* (CoreAudio, JACK, ASIO etc.) occurs in a thread subject to realtime
* constraints. Return false otherwise.
*/
virtual bool is_realtime () const = 0;

/** Return true if the backed is JACK */
/** Return true if the backend is JACK */
virtual bool is_jack () const { return false; }

/** Return the priority to be set with pbd_set_engine_rt_priority. */
virtual int client_real_time_priority () { return 0; }

/* Discovering devices and parameters */
Expand Down Expand Up @@ -232,7 +223,7 @@ class LIBARDOUR_API AudioBackend : public PortEngine
* of allowing one to be "None".
*
* ie. Input Device must match Output Device, except if either of them
* is get_standard_device_name (DeviceNone).
* is get_none_device_name ().
*/
virtual bool match_input_output_devices_or_none () const
{
Expand Down Expand Up @@ -291,7 +282,7 @@ class LIBARDOUR_API AudioBackend : public PortEngine
/** Set the period size to be used.
* must be called before starting the backend.
*/
virtual int set_peridod_size (uint32_t)
virtual int set_period_size (uint32_t)
{
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion libs/ardour/ardour/audioengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class LIBARDOUR_API AudioEngine : public PortManager, public SessionHandlePtr
int discover_backends();
std::vector<const AudioBackendInfo*> available_backends() const;
std::string current_backend_name () const;
std::shared_ptr<AudioBackend> set_backend (const std::string&, const std::string& arg1, const std::string& arg2);
std::shared_ptr<AudioBackend> set_backend (const std::string& name, const std::string& client_name, const std::string& session_id);
std::shared_ptr<AudioBackend> current_backend() const { return _backend; }
bool setup_required () const;
bool is_jack () const;
Expand Down
16 changes: 8 additions & 8 deletions libs/ardour/audio_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ AudioBackend::get_error_string (ErrorCode error_code)
}

std::string
AudioBackend::get_standard_device_name (StandardDeviceName device_name)
AudioBackend::get_none_device_name ()
{
switch (device_name) {
case DeviceNone:
return _("None");
case DeviceDefault:
return _("Default");
}
return std::string();
return _("None");
}

std::string
AudioBackend::get_default_device_name ()
{
return _("Default");
}

} // namespace ARDOUR
10 changes: 3 additions & 7 deletions libs/ardour/audioengine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ AudioEngine::drop_backend ()
}

std::shared_ptr<AudioBackend>
AudioEngine::set_backend (const std::string& name, const std::string& arg1, const std::string& arg2)
AudioEngine::set_backend (const std::string& name, const std::string& client_name, const std::string& session_id)
{
BackendMap::iterator b = _backends.find (name);

Expand All @@ -1026,7 +1026,7 @@ AudioEngine::set_backend (const std::string& name, const std::string& arg1, cons
drop_backend ();

try {
if (b->second->instantiate (arg1, arg2)) {
if (b->second->instantiate (client_name, session_id)) {
throw failed_constructor ();
}

Expand Down Expand Up @@ -1067,11 +1067,7 @@ AudioEngine::start (bool for_latency)
return -1;
}

if (_backend->is_realtime ()) {
pbd_set_engine_rt_priority (_backend->client_real_time_priority ());
} else {
pbd_set_engine_rt_priority (0);
}
pbd_set_engine_rt_priority (_backend->client_real_time_priority ());

_running = true;

Expand Down
2 changes: 1 addition & 1 deletion libs/ardour/luabindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2920,7 +2920,7 @@ LuaBindings::common (lua_State* L)

.addFunction ("set_sample_rate", &AudioBackend::set_sample_rate)
.addFunction ("set_buffer_size", &AudioBackend::set_buffer_size)
.addFunction ("set_peridod_size", &AudioBackend::set_peridod_size)
.addFunction ("set_period_size", &AudioBackend::set_period_size)

.addFunction ("enumerate_drivers", &AudioBackend::enumerate_drivers)
.addFunction ("driver_name", &AudioBackend::driver_name)
Expand Down
Loading