From 125f7ea27364b55451af1dfcd7474ccfa3a7c3a0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 17 Jun 2021 11:04:15 -0400 Subject: [PATCH] WIP: Add SessionControllerHandleRef This can be used to ensure that whenever this has a reference to a session, it also has a session controller set up to use that session. Towards sharing code between ARDOUR_UI and SessionController. WIP: SessionHandleRef|Ptr are not safe abstractions, so this isn't either, since derived types can and do manually mess around with the session pointer. Probably lifetime bugs here, and probably a good idea to statically prevent that, but a /lot/ of existing code uses _session directly. --- gtk2_ardour/ardour_ui.h | 4 +- .../ardour/ardour/session_controller_handle.h | 58 ++++++++++++++++ libs/ardour/session_controller_handle.cc | 69 +++++++++++++++++++ libs/ardour/wscript | 1 + 4 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 libs/ardour/ardour/session_controller_handle.h create mode 100644 libs/ardour/session_controller_handle.cc diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index e49c92666e..0c7e32f909 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -76,7 +76,7 @@ #include "ardour/types.h" #include "ardour/utils.h" #include "ardour/plugin.h" -#include "ardour/session_handle.h" +#include "ardour/session_controller_handle.h" #include "ardour/system_exec.h" #include "video_timeline.h" @@ -187,7 +187,7 @@ namespace ArdourWidgets { #define MAX_LUA_ACTION_SCRIPTS 32 #define MAX_LUA_ACTION_BUTTONS 12 -class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr, public TransportControlProvider +class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionControllerHandlePtr, public TransportControlProvider { public: ARDOUR_UI (int *argcp, char **argvp[], const char* localedir); diff --git a/libs/ardour/ardour/session_controller_handle.h b/libs/ardour/ardour/session_controller_handle.h new file mode 100644 index 0000000000..2443eda388 --- /dev/null +++ b/libs/ardour/ardour/session_controller_handle.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2009-2017 Paul Davis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __libardour_session_controller_handle_h__ +#define __libardour_session_controller_handle_h__ + +#include "ardour/libardour_visibility.h" +#include "ardour/session_controller.h" +#include "ardour/session_handle.h" + +namespace ARDOUR { + +class Session; +class SessionController; + +class LIBARDOUR_API SessionControllerHandleRef : public SessionHandleRef +{ + public: + SessionControllerHandleRef (Session& s); + + virtual ~SessionControllerHandleRef (); + + protected: + SessionController _controller; +}; + +class LIBARDOUR_API SessionControllerHandlePtr : public SessionHandlePtr +{ + public: + SessionControllerHandlePtr (Session* s); + SessionControllerHandlePtr (); + + virtual ~SessionControllerHandlePtr (); + + virtual void set_session (Session *); + + protected: + SessionController _controller; +}; + +} /* namespace */ + +#endif /* __libardour_session_controller_handle_h__ */ diff --git a/libs/ardour/session_controller_handle.cc b/libs/ardour/session_controller_handle.cc new file mode 100644 index 0000000000..284483f3a5 --- /dev/null +++ b/libs/ardour/session_controller_handle.cc @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2009-2016 Paul Davis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "pbd/demangle.h" +#include "pbd/error.h" + +#include "ardour/boost_debug.h" +#include "ardour/session.h" +#include "ardour/session_controller.h" +#include "ardour/session_controller_handle.h" + +#include "pbd/i18n.h" + +using namespace std; +using namespace ARDOUR; +using namespace PBD; + +SessionControllerHandleRef::SessionControllerHandleRef (Session& s) + : SessionHandleRef (s) + , _controller (&s) +{ + _session.DropReferences.connect_same_thread (*this, boost::bind (&SessionControllerHandleRef::session_going_away, this)); + _session.Destroyed.connect_same_thread (*this, boost::bind (&SessionControllerHandleRef::insanity_check, this)); +} + +SessionControllerHandleRef::~SessionControllerHandleRef () +{ +} + +/*-------------------------*/ + +SessionControllerHandlePtr::SessionControllerHandlePtr (Session* s) + : SessionHandlePtr (s) + , _controller (s) +{ +} + +SessionControllerHandlePtr::SessionControllerHandlePtr () + : SessionHandlePtr () + , _controller (NULL) +{ +} + +SessionControllerHandlePtr::~SessionControllerHandlePtr () +{ +} + +void +SessionControllerHandlePtr::set_session (Session* s) +{ + SessionHandlePtr::set_session (s); + + _controller = SessionController (s); +} diff --git a/libs/ardour/wscript b/libs/ardour/wscript index 57e47b9145..f9dd2d9d4b 100644 --- a/libs/ardour/wscript +++ b/libs/ardour/wscript @@ -214,6 +214,7 @@ libardour_sources = [ 'session_command.cc', 'session_configuration.cc', 'session_controller.cc', + 'session_controller_handle.cc', 'session_directory.cc', 'session_events.cc', 'session_export.cc',