From 220706459f3e14739b8e01cfbbd13e1dbc8c8bde Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 9 Feb 2021 15:42:05 -0700 Subject: [PATCH] fix problem with attempting to set virtual keyboard port pretty name from a port registration callback The JACK API doesn't allow server calls from inside a server callback, even though JACK2 doesn't enforce this. It would be nice to find a way to NOT call Session::setup_bundles() from every port registration callback, too. --- libs/ardour/ardour/session.h | 2 ++ libs/ardour/session.cc | 10 ++++++++++ libs/ardour/session_bundles.cc | 10 +++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 116d954a00..c26875f201 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -2234,6 +2234,8 @@ private: bool _had_destructive_tracks; std::string unnamed_file_name () const; + + gint _update_pretty_names; }; diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 3036c57223..c64e872a2c 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -327,6 +327,7 @@ Session::Session (AudioEngine &eng, , _selection (new CoreSelection (*this)) , _global_locate_pending (false) , _had_destructive_tracks (false) + , _update_pretty_names (0) { created_with = string_compose ("%1 %2", PROGRAM_NAME, revision); @@ -7147,6 +7148,15 @@ Session::auto_connect_thread_run () } } + + if (_midi_ports && g_atomic_int_get (&_update_pretty_names)) { + boost::shared_ptr ap = boost::dynamic_pointer_cast (vkbd_output_port ()); + if (ap->pretty_name () != _("Virtual Keyboard")) { + ap->set_pretty_name (_("Virtual Keyboard")); + } + g_atomic_int_set (&_update_pretty_names, 0); + } + if (_engine.port_deletions_pending ().read_space () > 0) { // this may call ARDOUR::Port::drop ... jack_port_unregister () // jack1 cannot cope with removing ports while processing diff --git a/libs/ardour/session_bundles.cc b/libs/ardour/session_bundles.cc index 6d0ea23185..ab3230f58d 100644 --- a/libs/ardour/session_bundles.cc +++ b/libs/ardour/session_bundles.cc @@ -125,7 +125,15 @@ Session::setup_bundles () if (_midi_ports) { boost::shared_ptr ap = boost::dynamic_pointer_cast (vkbd_output_port ()); inputs[DataType::MIDI].push_back (AudioEngine::instance()->make_port_name_non_relative (ap->name ())); - ap->set_pretty_name (_("Virtual Keyboard")); + + /* JACK semantics prevent us directly calling the + pretty-name/metadata API from a server callback, and this is + called from a port registration callback. So defer to the + auto-connect thread, which does this sort of thing anyway. + */ + + g_atomic_int_set (&_update_pretty_names, 1); + auto_connect_thread_wakeup (); } /* Create a set of Bundle objects that map