more object lifetime management fixes, plus a couple of tiny cleanups

git-svn-id: svn://localhost/ardour2/trunk@992 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2006-10-18 17:42:59 +00:00
parent 177b2a2a17
commit 0c31e4c4f3
12 changed files with 76 additions and 48 deletions

View File

@ -291,8 +291,6 @@
<menuitem action='SendMTC'/>
<menuitem action='SendMMC'/>
<menuitem action='UseMMC'/>
<menuitem action='SendMIDIfeedback'/>
<menuitem action='UseMIDIcontrol'/>
<separator/>
<menuitem action='StopPluginsWithTransport'/>
<menuitem action='DoNotRunPluginsWhileRecording'/>

View File

@ -951,8 +951,8 @@ Editor::scroll_forward (float pages)
}
}
if (ULONG_MAX - cnt < leftmost_frame) {
frame = ULONG_MAX - cnt;
if (max_frames - cnt < leftmost_frame) {
frame = max_frames - cnt;
} else {
frame = leftmost_frame + cnt;
}

View File

@ -26,6 +26,8 @@
#include <ardour/route_group.h>
#include <pbd/memento_command.h>
#include <pbd/stacktrace.h>
#include <pbd/shiva.h>
#include "route_ui.h"
#include "keyboard.h"
@ -44,7 +46,6 @@ using namespace Gtkmm2ext;
using namespace ARDOUR;
using namespace PBD;
RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, ARDOUR::Session& sess, const char* m_name,
const char* s_name, const char* r_name)
: AxisView(sess),
@ -65,7 +66,8 @@ RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, ARDOUR::Session& sess, co
set_color (unique_random_color());
}
_route->GoingAway.connect (mem_fun (*this, &RouteUI::route_removed));
new Shiva<Route,RouteUI> (*_route, *this);
_route->active_changed.connect (mem_fun (*this, &RouteUI::route_active_changed));
mute_button = manage (new BindableToggleButton (_route->mute_control(), m_name ));
@ -95,6 +97,7 @@ RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, ARDOUR::Session& sess, co
RouteUI::~RouteUI()
{
GoingAway (); /* EMIT SIGNAL */
delete mute_menu;
}
@ -729,13 +732,6 @@ RouteUI::idle_remove_this_route (RouteUI *rui)
return FALSE;
}
void
RouteUI::route_removed ()
{
ENSURE_GUI_THREAD(mem_fun (*this, &RouteUI::route_removed));
delete this;
}
void
RouteUI::route_rename ()
{

View File

@ -153,6 +153,8 @@ class RouteUI : public virtual AxisView
void reversibly_apply_route_boolean (string name, void (ARDOUR::Route::*func)(bool, void*), bool, void *);
void reversibly_apply_audio_track_boolean (string name, void (ARDOUR::AudioTrack::*func)(bool, void*), bool, void *);
sigc::signal<void> GoingAway;
};
#endif /* __ardour_route_ui__ */

View File

@ -97,14 +97,6 @@ SendUI::outs_changed (IOChange change, void* ignored)
}
}
void
SendUI::send_going_away ()
{
ENSURE_GUI_THREAD (mem_fun (*this, &SendUI::send_going_away))
delete this;
}
void
SendUI::update ()
{
@ -146,7 +138,6 @@ void
SendUIWindow::send_going_away ()
{
ENSURE_GUI_THREAD (mem_fun (*this, &SendUIWindow::send_going_away));
delete this;
delete_when_idle (this);
}

View File

@ -54,7 +54,6 @@ class SendUI : public Gtk::HBox
sigc::connection screen_update_connection;
sigc::connection fast_screen_update_connection;
void send_going_away ();
void ins_changed (ARDOUR::IOChange, void*);
void outs_changed (ARDOUR::IOChange, void*);
};

View File

@ -168,7 +168,7 @@ class Playlist : public StateManager, public PBD::StatefulDestructible {
friend class RegionLock;
RegionList regions;
RegionList regions; /* the current list of regions in the playlist */
string _name;
Session& _session;
mutable gint block_notifications;
@ -221,7 +221,7 @@ class Playlist : public StateManager, public PBD::StatefulDestructible {
void mark_session_dirty();
void region_changed_proxy (Change, boost::shared_ptr<Region>);
void region_changed_proxy (Change, boost::weak_ptr<Region>);
virtual bool region_changed (Change, boost::shared_ptr<Region>);
void region_bounds_changed (Change, boost::shared_ptr<Region>);

View File

@ -126,7 +126,6 @@ AudioPlaylist::AudioPlaylist (const AudioPlaylist& other, nframes_t start, nfram
AudioPlaylist::~AudioPlaylist ()
{
set<Crossfade*> all_xfades;
set<Region*> all_regions;
GoingAway (); /* EMIT SIGNAL */

View File

@ -532,7 +532,8 @@ Playlist::add_region_internal (boost::shared_ptr<Region> region, nframes_t posit
}
}
region->StateChanged.connect (sigc::bind (mem_fun (this, &Playlist::region_changed_proxy), region));
region->StateChanged.connect (sigc::bind (mem_fun (this, &Playlist::region_changed_proxy),
boost::weak_ptr<Region> (region)));
}
void
@ -1148,8 +1149,14 @@ Playlist::region_bounds_changed (Change what_changed, boost::shared_ptr<Region>
}
void
Playlist::region_changed_proxy (Change what_changed, boost::shared_ptr<Region> region)
Playlist::region_changed_proxy (Change what_changed, boost::weak_ptr<Region> weak_region)
{
boost::shared_ptr<Region> region (weak_region.lock());
if (!region) {
return;
}
/* this makes a virtual call to the right kind of playlist ... */
region_changed (what_changed, region);
@ -1373,21 +1380,15 @@ Playlist::set_state (const XMLNode& node)
if (child->name() == "Region") {
#if 0
if ((prop = child->property ("id")) == 0) {
error << _("region state node has no ID, ignored") << endmsg;
continue;
}
ID id = prop->value ();
if ((region = region_by_id (id)) == 0) {
#endif
if ((region = RegionFactory::create (_session, *child, true)) == 0) {
error << _("Playlist: cannot create region from state file") << endmsg;
continue;
}
// }
if ((region = RegionFactory::create (_session, *child, true)) == 0) {
error << _("Playlist: cannot create region from state file") << endmsg;
continue;
}
add_region (region, region->position(), 1.0, false);

View File

@ -1296,8 +1296,6 @@ Session::XMLRegionFactory (const XMLNode& node, bool full)
cerr << "no name for this region\n";
abort ();
}
cerr << "name of this region = " << prop->value() << endl;
if ((prop = node.property (X_("source-0"))) == 0) {
if ((prop = node.property ("source")) == 0) {

View File

@ -1,7 +0,0 @@
#ifndef __libmisc_restartable_rw__h__
#define __libmisc_restartable_rw__h__
extern int restartable_write (int fd, unsigned char *buf, size_t cnt);
extern int restartable_read (int fd, unsigned char *buf, size_t cnt);
#endif // __libmisc_restartable_rw__h__

51
libs/pbd/pbd/shiva.h Normal file
View File

@ -0,0 +1,51 @@
#ifndef __pbd_shiva_h__
#define __pbd_shiva_h__
#include <sigc++/sigc++.h>
namespace PBD {
template<typename ObjectWithGoingAway, typename ObjectToBeDestroyed>
/* named after the Hindu god Shiva, The Destroyer */
class Shiva {
public:
Shiva (ObjectWithGoingAway& emitter, ObjectToBeDestroyed& receiver) {
/* if the emitter goes away, destroy the receiver */
_connection1 = emitter.GoingAway.connect
(sigc::bind (sigc::mem_fun
(*this, &Shiva<ObjectWithGoingAway,ObjectToBeDestroyed>::destroy),
&receiver));
/* if the receiver goes away, forget all this nonsense */
_connection2 = receiver.GoingAway.connect
(sigc::mem_fun (*this, &Shiva<ObjectWithGoingAway,ObjectToBeDestroyed>::forget));
}
~Shiva() {
forget ();
}
private:
sigc::connection _connection1;
sigc::connection _connection2;
void destroy (ObjectToBeDestroyed* obj) {
delete obj;
forget ();
}
void forget () {
_connection1.disconnect ();
_connection2.disconnect ();
}
};
}
#endif /* __pbd_shiva_h__ */