diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2012-06-21 15:00:10 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2012-06-21 15:00:10 +0000 |
commit | 8c87102688c06409850b6c7543a17932117a7a94 (patch) | |
tree | af17b3b21a09c58aa21d24cfb6eb1a9bc23732b6 /libs | |
parent | 83941f9988c5eef8ac86f180978547b1259ce095 (diff) |
a putatively better approach to cleaning up ports at session closing
git-svn-id: svn://localhost/ardour2/branches/3.0@12807 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/ardour/port.h | 3 | ||||
-rw-r--r-- | libs/ardour/audioengine.cc | 24 | ||||
-rw-r--r-- | libs/ardour/port.cc | 16 | ||||
-rw-r--r-- | libs/ardour/session.cc | 6 |
4 files changed, 38 insertions, 11 deletions
diff --git a/libs/ardour/ardour/port.h b/libs/ardour/ardour/port.h index 37101950d5..e225117d94 100644 --- a/libs/ardour/ardour/port.h +++ b/libs/ardour/ardour/port.h @@ -126,6 +126,7 @@ public: PBD::Signal1<void,bool> MonitorInputChanged; static PBD::Signal2<void,boost::shared_ptr<Port>,boost::shared_ptr<Port> > PostDisconnect; + static PBD::Signal0<void> PortDrop; static void set_cycle_framecnt (pframes_t n) { _cycle_nframes = n; @@ -167,6 +168,8 @@ private: */ std::set<std::string> _connections; + void drop (); + PBD::ScopedConnection drop_connection; }; } diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index 26f8311c8d..5642db8932 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -479,6 +479,21 @@ AudioEngine::process_callback (pframes_t nframes) /* perform the actual session removal */ _session = 0; session_remove_pending = false; + + /* pump one cycle of silence into the ports + before the session tears them all down + (asynchronously). + */ + + boost::shared_ptr<Ports> p = ports.reader(); + + for (Ports::iterator i = p->begin(); i != p->end(); ++i) { + + if (i->second->sends_output()) { + i->second->get_buffer (nframes).silence (nframes); + } + } + session_removed.signal(); } @@ -486,15 +501,6 @@ AudioEngine::process_callback (pframes_t nframes) if (!_freewheeling) { MIDI::Manager::instance()->cycle_start(nframes); MIDI::Manager::instance()->cycle_end(); - - boost::shared_ptr<Ports> p = ports.reader(); - - for (Ports::iterator i = p->begin(); i != p->end(); ++i) { - - if (i->second->sends_output()) { - i->second->get_buffer (nframes).silence (nframes); - } - } } _processed_frames = next_processed_frames; diff --git a/libs/ardour/port.cc b/libs/ardour/port.cc index b0c4b43c06..3473b73617 100644 --- a/libs/ardour/port.cc +++ b/libs/ardour/port.cc @@ -38,6 +38,7 @@ using namespace ARDOUR; using namespace PBD; PBD::Signal2<void,boost::shared_ptr<Port>, boost::shared_ptr<Port> > Port::PostDisconnect; +PBD::Signal0<void> Port::PortDrop; AudioEngine* Port::_engine = 0; bool Port::_connecting_blocked = false; @@ -71,13 +72,24 @@ Port::Port (std::string const & n, DataType t, Flags f) cerr << "Failed to register JACK port \"" << _name << "\", reason is unknown from here\n"; throw failed_constructor (); } + + PortDrop.connect_same_thread (drop_connection, boost::bind (&Port::drop, this)); } /** Port destructor */ Port::~Port () { - if (_engine->jack ()) { - jack_port_unregister (_engine->jack (), _jack_port); + drop (); +} + +void +Port::drop () +{ + if (_jack_port) { + if (_engine->jack ()) { + jack_port_unregister (_engine->jack (), _jack_port); + } + _jack_port = 0; } } diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 9eb4c223d0..5758130092 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -234,6 +234,12 @@ Session::destroy () _engine.remove_session (); + /* deregister all ports - there will be no process or any other + * callbacks from the engine any more. + */ + + Port::PortDrop (); /* EMIT SIGNAL */ + /* clear history so that no references to objects are held any more */ _history.clear (); |