gain_line->view_to_model_y (y);
+#ifdef FIX_ME_TO_NOT_USE_STATE_MANAGER
trackview.session().begin_reversible_command (_("add gain control point"));
trackview.session().add_undo (region.envelope().get_memento());
-
+#endif
if (!region.envelope_active()) {
trackview.session().add_undo( bind( mem_fun(region, &AudioRegion::set_envelope_active), false) );
region.envelope().add (fx, y);
+#ifdef FIX_ME_TO_NOT_USE_STATE_MANAGER
trackview.session().add_redo_no_execute (region.envelope().get_memento());
trackview.session().commit_reversible_command ();
+#endif
}
void
}
}
+
StreamView::remove_region_view(r);
}
}
+#ifdef STATE_MANAGER
// This is copied into AudioRegionGainLine
UndoAction
AutomationLine::get_memento ()
{
return alist.get_memento();
}
+#endif
void
AutomationLine::list_changed (Change ignored)
ShapeType _shape;
};
-class AutomationLine : public PBD::StatefulDestructible
+class AutomationLine : public sigc::trackable, public PBD::StatefulThingWithGoingAway
{
public:
AutomationLine (const string & name, TimeAxisView&, ArdourCanvas::Group&, ARDOUR::AutomationList&);
void reset_callback (const ARDOUR::AutomationList&);
void list_changed (ARDOUR::Change);
+#ifdef STATE_MANAGER
UndoAction get_memento();
+#endif
virtual bool event_handler (GdkEvent*);
CrossfadeView::~CrossfadeView ()
{
- GoingAway (this) ; /* EMIT_SIGNAL */
+ GoingAway (this) ; /* EMIT_SIGNAL */
}
void
continue;
XMLNode &before = arv->region()->get_state();
arv->audio_region()->normalize_to (0.0f);
- // session->add_command (new MementoCommand<Region>(*(arv->region().get()), &before, &arv->region()->get_state()));
+ session->add_command (new MementoCommand<Region>(*(arv->region().get()), &before, &arv->region()->get_state()));
}
commit_reversible_command ();
class ImageFrameTimeAxis;
class MarkerView;
-class PublicEditor : public Gtk::Window, public PBD::StatefulDestructible {
+class PublicEditor : public Gtk::Window, public PBD::StatefulThingWithGoingAway {
public:
PublicEditor();
virtual ~PublicEditor();
sigc::signal<void> ZoomChanged;
sigc::signal<void> Resized;
sigc::signal<void> Realized;
+ sigc::signal<void> GoingAway;
Glib::RefPtr<Gtk::ActionGroup> editor_actions;
}
+#ifdef STATE_MANAGER
// This is a copy from AutomationList
UndoAction
AudioRegionGainLine::get_memento ()
{
return alist.get_memento();
}
+#endif
ARDOUR::Session& session;
AudioRegionView& rv;
+#ifdef STATE_MANAGER
UndoAction get_memento();
+#endif
};
set_color (unique_random_color());
}
- new Shiva<Route,RouteUI> (*_route, *this);
+ new PairedShiva<Route,RouteUI> (*_route, *this);
_route->active_changed.connect (mem_fun (*this, &RouteUI::route_active_changed));
};
- class AutomationList : public StateManager, public PBD::StatefulDestructible
+class AutomationList : public PBD::StatefulDestructible
{
public:
typedef std::list<ControlEvent*> AutomationEventList;
(obj.*method)(*this);
}
+ sigc::signal<void,Change> StateChanged;
+
+#ifdef STATE_MANAGER
UndoAction get_memento () const;
+#endif
virtual void store_state (XMLNode& node) const;
virtual void load_state (const XMLNode&);
virtual double unlocked_eval (double where);
+#ifdef STATE_MANAGER
Change restore_state (StateManager::State&);
StateManager::State* state_factory (std::string why) const;
+#endif
virtual ControlEvent* point_factory (double,double) const;
virtual ControlEvent* point_factory (const ControlEvent&) const;
ControlEvent* point_factory (double,double) const;
ControlEvent* point_factory (const ControlEvent&) const;
+#ifdef STATE_MANAGER
Change restore_state (StateManager::State&);
+#endif
private:
AutomationList::iterator last_bound;
* An IO can contain ports of varying types, making routes/inserts/etc with
* varied combinations of types (eg MIDI and audio) possible.
*/
-class IO : public PBD::StatefulDestructible, public ARDOUR::StateManager
+class IO : public PBD::StatefulDestructible
{
public:
XMLNode& get_state (void);
int set_state (const XMLNode&);
+#ifdef STATE_MANAGER
virtual UndoAction get_memento() const;
-
+#endif
static int disable_connecting (void);
/* state management */
+#ifdef STATE_MANAGER
Change restore_state (State&);
StateManager::State* state_factory (std::string why) const;
+#endif
AutoState _gain_automation_state;
AutoStyle _gain_automation_style;
bool set_flag_internal (bool yn, Flags flag);
};
-class Locations : public StateManager, public PBD::StatefulDestructible
+class Locations : public PBD::StatefulDestructible
{
public:
typedef std::list<Location *> LocationList;
sigc::signal<void> changed;
sigc::signal<void,Location*> added;
sigc::signal<void,Location*> removed;
+ sigc::signal<void,Change> StateChanged;
template<class T> void apply (T& obj, void (T::*method)(LocationList&)) {
Glib::Mutex::Lock lm (lock);
(obj.*method)(locations, arg);
}
+#ifdef STATE_MANAGER
UndoAction get_memento () const;
+#endif
private:
+#ifdef STATE_MANAGER
struct State : public ARDOUR::StateManager::State {
LocationList locations;
LocationList states;
State (std::string why) : ARDOUR::StateManager::State (why) {}
};
-
+#endif
LocationList locations;
Location *current_location;
mutable Glib::Mutex lock;
int set_current_unlocked (Location *);
void location_changed (Location*);
-
+#ifdef STATE_MANAGER
Change restore_state (StateManager::State&);
StateManager::State* state_factory (std::string why) const;
+#endif
};
} // namespace ARDOUR
current_trans->add_command (cmd);
}
- std::map<PBD::ID, PBD::StatefulDestructible*> registry;
+ std::map<PBD::ID, PBD::StatefulThingWithGoingAway*> registry;
// these commands are implemented in libs/ardour/session_command.cc
Command *memento_command_factory(XMLNode *n);
- void register_with_memento_command_factory(PBD::ID, PBD::StatefulDestructible *);
+ void register_with_memento_command_factory(PBD::ID, PBD::StatefulThingWithGoingAway *);
class GlobalSoloStateCommand : public Command
{
typedef list<MetricSection*> Metrics;
+#ifdef STATE_MANAGER
class TempoMapState : public StateManager::State {
public:
TempoMapState (std::string why)
Metrics *metrics;
};
+#endif
-class TempoMap : public StateManager, public PBD::StatefulDestructible
+class TempoMap : public PBD::StatefulDestructible
{
public:
void dump (std::ostream&) const;
void clear ();
+#ifdef STATE_MANAGER
UndoAction get_memento() const;
+#endif
/* this is a helper class that we use to be able to keep
track of which meter *AND* tempo are in effect at
Metric metric_at (nframes_t) const;
void bbt_time_with_metric (nframes_t, BBT_Time&, const Metric&) const;
+ sigc::signal<void,ARDOUR::Change> StateChanged;
+
private:
static Tempo _default_tempo;
static Meter _default_meter;
int move_metric_section (MetricSection&, const BBT_Time& to);
void do_insert (MetricSection* section);
+#ifdef STATE_MANAGER
Change restore_state (StateManager::State&);
StateManager::State* state_factory (std::string why) const;
/* override state_manager::save_state so we can check in_set_state */
void save_state (std::string why);
-
+#endif
};
}; /* namespace ARDOUR */
/* drop connections to signals */
notify_callbacks ();
-
-
- cerr << "deleting crossfades " << _crossfades.size() << endl;
for (Crossfades::iterator x = _crossfades.begin(); x != _crossfades.end(); ) {
Crossfades::iterator tmp;
delete *x;
- cerr << _crossfades.size() << " to go\n";
-
x = tmp;
}
-
- cerr << "done\n";
}
struct RegionSortByLayer {
return;
}
- cerr << "Check dependents of " << r->name() << endl;
-
if ((region = boost::dynamic_pointer_cast<AudioRegion> (r)) == 0) {
fatal << _("programming error: non-audio Region tested for overlap in audio playlist")
<< endmsg;
{
Crossfades::iterator ci;
- cerr << "adding xfade involving " << xfade.in()->name() << " and " << xfade.out()->name() << endl;
-
for (ci = _crossfades.begin(); ci != _crossfades.end(); ++ci) {
- cerr << "\tcompare to " << (*ci)->in()->name() << " and " << (*ci)->out()->name() << endl;
if (*(*ci) == xfade) { // Crossfade::operator==()
break;
}
FreezeRecordInsertInfo* frii = new FreezeRecordInsertInfo ((*r)->get_state(), insert);
frii->id = insert->id();
+#ifdef STATE_MANAGER
frii->memento = (*r)->get_memento();
-
+#endif
_freeze_record.insert_info.push_back (frii);
/* now deactivate the insert */
AudioRegion::~AudioRegion ()
{
- cerr << "====== " << _name << " DESTRUCTOR @ " << this << endl;
notify_callbacks ();
GoingAway (); /* EMIT SIGNAL */
}
lookup_cache.range.first = events.end();
if (!no_state) {
+#ifdef STATE_MANAGER
save_state (_("initial"));
+#endif
}
AutomationListCreated(this);
AutomationList::~AutomationList()
{
- std::set<ControlEvent*> all_events;
- AutomationList::State* asp;
-
GoingAway ();
for (AutomationEventList::iterator x = events.begin(); x != events.end(); ++x) {
- all_events.insert (*x);
+ delete (*x);
}
+#ifdef STATE_MANAGER
+ std::set<ControlEvent*> all_events;
+ AutomationList::State* asp;
+
for (StateMap::iterator i = states.begin(); i != states.end(); ++i) {
if ((asp = dynamic_cast<AutomationList::State*> (*i)) != 0) {
for (std::set<ControlEvent*>::iterator i = all_events.begin(); i != all_events.end(); ++i) {
delete (*i);
}
+#endif
}
bool
Glib::Mutex::Lock lm (lock);
events.clear ();
if (!no_state) {
+#ifdef STATE_MANAGER
save_state (_("cleared"));
+#endif
}
mark_dirty ();
}
(*i)->when = floor ((*i)->when * factor);
}
+#ifdef STATE_MANAGER
save_state ("x-scaled");
+#endif
mark_dirty ();
}
mark_dirty ();
if (!no_state && !for_loading) {
+#ifdef STATE_MANAGER
save_state (_("added event"));
+#endif
}
}
events.erase (i);
reposition_for_rt_add (0);
if (!no_state) {
+#ifdef STATE_MANAGER
save_state (_("removed event"));
+#endif
}
mark_dirty ();
}
events.erase (start, end);
reposition_for_rt_add (0);
if (!no_state) {
+#ifdef STATE_MANAGER
save_state (_("removed multiple events"));
+#endif
}
mark_dirty ();
}
reset = true;
if (!no_state) {
+#ifdef STATE_MANAGER
save_state (_("removed range"));
+#endif
}
mark_dirty ();
reposition_for_rt_add (0);
erased = true;
if (!no_state) {
+#ifdef STATE_MANAGER
save_state (_("removed range"));
+#endif
}
mark_dirty ();
}
}
if (!no_state) {
+#ifdef STATE_MANAGER
save_state (_("event range adjusted"));
+#endif
}
mark_dirty ();
(*iter)->when = when;
(*iter)->value = val;
if (!no_state) {
+#ifdef STATE_MANAGER
save_state (_("event adjusted"));
+#endif
}
mark_dirty ();
}
}
+#ifdef STATE_MANAGER
StateManager::State*
AutomationList::state_factory (std::string why) const
{
{
return sigc::bind (mem_fun (*(const_cast<AutomationList*> (this)), &StateManager::use_state), _current_state_id);
}
+#endif
void
AutomationList::set_max_xval (double x)
if (changed) {
reposition_for_rt_add (0);
if (!no_state) {
+#ifdef STATE_MANAGER
save_state (_("cut/copy/clear"));
+#endif
}
}
}
if (!no_state) {
+#ifdef STATE_MANAGER
save_state (_("copy"));
+#endif
}
}
reposition_for_rt_add (0);
if (!no_state) {
+#ifdef STATE_MANAGER
save_state (_("paste"));
+#endif
}
mark_dirty ();
nframes_t x;
double y;
+ freeze ();
+
clear ();
for (i = elist.begin(); i != elist.end(); ++i) {
add (x, y);
}
+
+ thaw ();
}
XMLNode &AutomationList::get_state ()
}
_length = 0;
+ _active = Config->get_xfades_active();
+
initialize();
if (set_state (node)) {
Crossfade::~Crossfade ()
{
- cerr << "Deleting xfade @ " << this << endl;
Invalidated (this);
- cerr << "invalidation signal sent\n";
}
void
return new CurvePoint (other.when, other.value);
}
+#ifdef STATE_MANAGER
Change
Curve::restore_state (StateManager::State& state)
{
mark_dirty ();
return AutomationList::restore_state (state);
}
-
+#endif
extern "C" {
init ();
+#ifdef STATE_MANAGER
save_state (_("initial state"));
+#endif
{
Glib::Mutex::Lock em (_session.engine().process_lock());
set_automatable ();
+#ifdef STATE_MANAGER
save_state (_("initial state"));
+#endif
_plugins[0]->ParameterChanged.connect (mem_fun (*this, &PluginInsert::parameter_changed));
init ();
+#ifdef STATE_MANAGER
save_state (_("initial state"));
+#endif
RedirectCreated (this); /* EMIT SIGNAL */
}
: Insert (s, p, 1, -1, 1, -1)
{
init ();
+#ifdef STATE_MANAGER
save_state (_("initial state"));
RedirectCreated (this); /* EMIT SIGNAL */
+#endif
+
}
PortInsert::PortInsert (const PortInsert& other)
: Insert (other._session, other.placement(), 1, -1, 1, -1)
{
init ();
+#ifdef STATE_MANAGER
save_state (_("initial state"));
RedirectCreated (this); /* EMIT SIGNAL */
+#endif
+
}
void
}
}
+#ifdef STATE_MANAGER
UndoAction
IO::get_memento() const
{
StateManager::State* state = new StateManager::State (why);
return state;
}
+#endif
/**
Update the peak meters.
}
}
+#ifdef STATE_MANAGER
_gain_automation_curve.save_state (_("loaded from disk"));
+#endif
return 0;
}
if (_gain_automation_curve.automation_state() != Off) {
+#ifdef STATE_MANAGER
if (gain_automation_recording()) {
_gain_automation_curve.save_state (_("automation write/touch"));
}
+#endif
/* the src=0 condition is a special signal to not propagate
automation gain changes into the mix group when locating.
{
current_location = 0;
+#ifdef STATE_MANAGER
save_state (_("initial"));
+#endif
}
Locations::~Locations ()
{
+ for (LocationList::iterator i = locations.begin(); i != locations.end(); ) {
+ LocationList::iterator tmp = i;
+ ++tmp;
+ delete *i;
+ i = tmp;
+ }
+
+#ifdef STATE_MANAGER
+
std::set<Location*> all_locations;
+
for (StateMap::iterator siter = states.begin(); siter != states.end(); ++siter) {
State* lstate = dynamic_cast<State*> (*siter);
}
set_delete (&all_locations);
+#endif
}
int
current_location = 0;
}
+#ifdef STATE_MANAGER
save_state (_("clear"));
+#endif
changed (); /* EMIT SIGNAL */
current_changed (0); /* EMIT SIGNAL */
}
}
+#ifdef STATE_MANAGER
save_state (_("clear markers"));
+#endif
changed (); /* EMIT SIGNAL */
}
current_location = 0;
}
+#ifdef STATE_MANAGER
save_state (_("clear ranges"));
+#endif
changed (); /* EMIT SIGNAL */
current_changed (0); /* EMIT SIGNAL */
}
}
+#ifdef STATE_MANAGER
save_state (_("add"));
+#endif
added (loc); /* EMIT SIGNAL */
}
if (was_removed) {
+#ifdef STATE_MANAGER
save_state (_("remove"));
+#endif
removed (loc); /* EMIT SIGNAL */
void
Locations::location_changed (Location* loc)
{
+#ifdef STATE_MANAGER
save_state (X_("location changed"));
+#endif
changed (); /* EMIT SIGNAL */
}
return 0;
}
+#ifdef STATE_MANAGER
StateManager::State*
Locations::state_factory (std::string why) const
{
{
return sigc::bind (mem_fun (*(const_cast<Locations*> (this)), &StateManager::use_state), _current_state_id);
}
+#endif
uint32_t
Locations::num_range_markers () const
if (_automation.automation_state() != Off) {
if (_automation.automation_write()) {
+#ifdef STATE_MANAGER
_automation.save_state (_("automation write pass"));
+#endif
}
set_position (_automation.eval (frame));
/* now that we are done loading */
+#ifdef STATE_MANAGER
_automation.save_state (_("loaded from disk"));
+#endif
_automation.StateChanged (Change (0));
return 0;
tosave.insert (port);
}
+#ifdef STATE_MANAGER
for (set<uint32_t>::iterator i = tosave.begin(); i != tosave.end(); ++i) {
automation_list (*i).save_state (_("loaded from disk"));
}
+#endif
return 0;
Redirect::set_active (bool yn, void* src)
{
_active = yn;
+#ifdef STATE_MANAGER
save_state (_("active_changed"));
+#endif
active_changed (this, src);
_session.set_dirty ();
}
{
_metering = false;
expected_inputs = 0;
+#ifdef STATE_MANAGER
save_state (_("initial state"));
+#endif
RedirectCreated (this); /* EMIT SIGNAL */
}
throw failed_constructor();
}
+#ifdef STATE_MANAGER
save_state (_("initial state"));
+#endif
+
RedirectCreated (this); /* EMIT SIGNAL */
}
{
_metering = false;
expected_inputs = 0;
+#ifdef STATE_MANAGER
save_state (_("initial state"));
+#endif
+
RedirectCreated (this); /* EMIT SIGNAL */
}
}
AudioDiskstream::free_working_buffers();
+
+ /* this should cause deletion of the auditioner */
+
+ // auditioner.reset ();
#undef TRACK_DESTRUCTION
#ifdef TRACK_DESTRUCTION
tmp = i;
++tmp;
- cerr << "dropping refs on an audio region (" << i->second->name() << " @ " << i->second << ") with UC = " << i->second.use_count() << endl;
i->second->drop_references ();
- cerr << "AFTER: UC = " << i->second.use_count() << endl;
i = tmp;
}
for (i = r->begin(); i != r->end(); ++i) {
trace_terminal (*i, *i);
- }
-
+ }
+
RouteSorter cmp;
r->sort (cmp);
+ /* don't leave dangling references to routes in Route::fed_by */
+
+ for (i = r->begin(); i != r->end(); ++i) {
+ (*i)->fed_by.clear ();
+ }
+
#if 0
cerr << "finished route resort\n";
goto run_clicks;
}
- if (points->empty()) {
- delete points;
- goto run_clicks;
- }
-
- for (TempoMap::BBTPointList::iterator i = points->begin(); i != points->end(); ++i) {
- switch ((*i).type) {
- case TempoMap::Beat:
- if (click_emphasis_data == 0 || (click_emphasis_data && (*i).beat != 1)) {
- clicks.push_back (new Click ((*i).frame, click_length, click_data));
+ if (!points->empty()) {
+
+ for (TempoMap::BBTPointList::iterator i = points->begin(); i != points->end(); ++i) {
+ switch ((*i).type) {
+ case TempoMap::Beat:
+ if (click_emphasis_data == 0 || (click_emphasis_data && (*i).beat != 1)) {
+ clicks.push_back (new Click ((*i).frame, click_length, click_data));
+ }
+ break;
+
+ case TempoMap::Bar:
+ if (click_emphasis_data) {
+ clicks.push_back (new Click ((*i).frame, click_emphasis_length, click_emphasis_data));
+ }
+ break;
}
- break;
-
- case TempoMap::Bar:
- if (click_emphasis_data) {
- clicks.push_back (new Click ((*i).frame, click_emphasis_length, click_emphasis_data));
- }
- break;
}
}
+
+ delete points;
delete points;
run_clicks:
+
memset (buf, 0, sizeof (Sample) * nframes);
for (list<Click*>::iterator i = clicks.begin(); i != clicks.end(); ) {
#include <ardour/audiosource.h>
#include <ardour/audioregion.h>
#include <pbd/error.h>
+#include <pbd/statefuldestructible.h>
+
using namespace PBD;
-#include "i18n.h"
+#include "i18n.h"
namespace ARDOUR {
-void Session::register_with_memento_command_factory(PBD::ID id, StatefulDestructible *ptr)
+void Session::register_with_memento_command_factory(PBD::ID id, PBD::StatefulThingWithGoingAway *ptr)
{
registry[id] = ptr;
}
if (automation_lists.count(id))
return new MementoCommand<AutomationList>(*automation_lists[id], before, after);
} else if (registry.count(id)) { // For Editor and AutomationLine which are off-limits here
- return new MementoCommand<StatefulDestructible>(*registry[id], before, after);
+ return new MementoCommand<PBD::StatefulThingWithGoingAway>(*registry[id], before, after);
}
/* we failed */
Curve::CurveCreated.connect (mem_fun (*this, &Session::add_curve));
AutomationList::AutomationListCreated.connect (mem_fun (*this, &Session::add_automation_list));
- Controllable::GoingAway.connect (mem_fun (*this, &Session::remove_controllable));
+ Controllable::Destroyed.connect (mem_fun (*this, &Session::remove_controllable));
IO::MoreOutputs.connect (mem_fun (*this, &Session::ensure_passthru_buffers));
start_location = location;
}
+#ifdef STATE_MANAGER
_locations.save_state (_("initial state"));
+#endif
if ((child = find_named_node (node, "EditGroups")) == 0) {
error << _("Session: XML state has no edit groups section") << endmsg;
_frame_rate = fr;
last_bbt_valid = false;
BBT_Time start;
+#ifdef STATE_MANAGER
in_set_state = false;
+#endif
start.bars = 1;
start.beats = 1;
metrics->push_back (t);
metrics->push_back (m);
+#ifdef STATE_MANAGER
save_state (_("initial"));
+#endif
}
TempoMap::~TempoMap ()
section.set_start (corrected);
metrics->sort (cmp);
timestamp_metrics ();
+#ifdef STATE_MANAGER
save_state (_("move metric"));
+#endif
return 0;
}
TempoMap::move_tempo (TempoSection& tempo, const BBT_Time& when)
{
if (move_metric_section (tempo, when) == 0) {
- send_state_changed (Change (0));
+ StateChanged (Change (0));
}
}
TempoMap::move_meter (MeterSection& meter, const BBT_Time& when)
{
if (move_metric_section (meter, when) == 0) {
- send_state_changed (Change (0));
+ StateChanged (Change (0));
}
}
}
if (removed) {
- send_state_changed (Change (0));
+ StateChanged (Change (0));
}
}
}
if (removed) {
+#ifdef STATE_MANAGER
save_state (_("metric removed"));
+#endif
}
}
if (removed) {
- send_state_changed (Change (0));
+ StateChanged (Change (0));
}
}
do_insert (new TempoSection (where, tempo.beats_per_minute()));
+#ifdef STATE_MANAGER
save_state (_("add tempo"));
+#endif
}
- send_state_changed (Change (0));
+ StateChanged (Change (0));
}
void
}
if (replaced) {
+#ifdef STATE_MANAGER
save_state (_("replace tempo"));
+#endif
}
}
if (replaced) {
- send_state_changed (Change (0));
+ StateChanged (Change (0));
}
}
do_insert (new MeterSection (where, meter.beats_per_bar(), meter.note_divisor()));
+#ifdef STATE_MANAGER
save_state (_("add meter"));
+#endif
}
- send_state_changed (Change (0));
+ StateChanged (Change (0));
}
void
}
if (replaced) {
+#ifdef STATE_MANAGER
save_state (_("replaced meter"));
+#endif
}
}
if (replaced) {
- send_state_changed (Change (0));
+ StateChanged (Change (0));
}
}
XMLNodeConstIterator niter;
Metrics old_metrics (*metrics);
+#ifdef STATE_MANAGER
in_set_state = true;
+#endif
metrics->clear();
timestamp_metrics ();
}
+#ifdef STATE_MANAGER
in_set_state = false;
+#endif
}
/* This state needs to be saved. This string will never be a part of the
If this state is not saved, there is no way to reach it through undo actions.
*/
+
+#ifdef STATE_MANAGER
save_state(_("load XML data"));
+#endif
- send_state_changed (Change (0));
+ StateChanged (Change (0));
return 0;
}
}
}
+#ifdef STATE_MANAGER
UndoAction
TempoMap::get_memento () const
{
StateManager::save_state (why);
}
}
+#endif
using namespace PBD;
-sigc::signal<void,Controllable*> Controllable::GoingAway;
+sigc::signal<void,Controllable*> Controllable::Destroyed;
sigc::signal<bool,Controllable*> Controllable::StartLearning;
sigc::signal<void,Controllable*> Controllable::StopLearning;
#ifndef __lib_pbd_command_h__
#define __lib_pbd_command_h__
-#include <pbd/stateful.h>
-#include <pbd/destructible.h>
+#include <pbd/statefuldestructible.h>
-class Command : public Stateful, public PBD::Destructible
+class Command : public PBD::StatefulDestructible
{
public:
virtual ~Command() {}
#include <sigc++/trackable.h>
#include <sigc++/signal.h>
-#include <pbd/stateful.h>
-#include <pbd/id.h>
+#include <pbd/statefuldestructible.h>
class XMLNode;
namespace PBD {
-class Controllable : public virtual sigc::trackable, public Stateful {
+class Controllable : public PBD::StatefulDestructible {
public:
Controllable (std::string name);
- virtual ~Controllable() { GoingAway (this); }
+ virtual ~Controllable() { Destroyed (this); }
virtual void set_value (float) = 0;
virtual float get_value (void) const = 0;
sigc::signal<void> LearningFinished;
- static sigc::signal<void,Controllable*> GoingAway;
-
static sigc::signal<bool,PBD::Controllable*> StartLearning;
static sigc::signal<void,PBD::Controllable*> StopLearning;
+ static sigc::signal<void,Controllable*> Destroyed;
+
sigc::signal<void> Changed;
int set_state (const XMLNode&);
namespace PBD {
-class Destructible : public virtual sigc::trackable {
- public:
- Destructible() {}
- virtual ~Destructible () {}
+/* be very very careful using this class. it does not inherit from sigc::trackable and thus
+ should only be used in multiple-inheritance situations involving another type
+ that does inherit from sigc::trackable (or sigc::trackable itself)
+*/
+class ThingWithGoingAway {
+ public:
+ virtual ~ThingWithGoingAway () {}
sigc::signal<void> GoingAway;
+};
+class Destructible : public sigc::trackable, public ThingWithGoingAway {
+ public:
+ virtual ~Destructible () {}
void drop_references () const { GoingAway(); }
+
};
}
#include <pbd/command.h>
#include <pbd/stacktrace.h>
#include <pbd/xml++.h>
+#include <pbd/shiva.h>
+
#include <sigc++/slot.h>
#include <typeinfo>
-/* grrr, strict C++ says that static member functions are not C functions, but we also want
- to be able to pack this into a sigc::ptr_fun and not sigc::mem_fun, so we have to make
- it a genuine function rather than a member.
-*/
-
-static void object_death (Command* mc) {
- cerr << "\n\n\n---> OBJECT DEATH FIRED FOR " << mc << endl;
- delete mc;
-}
-
/** This command class is initialized with before and after mementos
* (from Stateful::get_state()), so undo becomes restoring the before
* memento, and redo is restoring the after memento.
XMLNode *after
)
: obj(object), before(before), after(after) {
- cerr << "MC @ " << this << " is a " << typeid (obj_T).name() << endl;
- obj.GoingAway.connect (sigc::bind (sigc::ptr_fun (object_death), static_cast<Command*>(this)));
+ /* catch destruction of the object */
+ new PBD::Shiva<obj_T,MementoCommand<obj_T> > (object, *this);
}
~MementoCommand () {
namespace PBD {
-template<typename ObjectWithGoingAway, typename ObjectToBeDestroyed>
-
/* named after the Hindu god Shiva, The Destroyer */
+template<typename ObjectWithGoingAway, typename ObjectToBeDestroyed>
class Shiva {
public:
Shiva (ObjectWithGoingAway& emitter, ObjectToBeDestroyed& receiver) {
/* if the emitter goes away, destroy the receiver */
- _connection1 = emitter.GoingAway.connect
+ _connection = emitter.GoingAway.connect
(sigc::bind (sigc::mem_fun
(*this, &Shiva<ObjectWithGoingAway,ObjectToBeDestroyed>::destroy),
&receiver));
+ }
+
+ ~Shiva() {
+ forget ();
+ }
+
+ private:
+ sigc::connection _connection;
+
+ void destroy (ObjectToBeDestroyed* obj) {
+ delete obj;
+ forget ();
+ }
+
+ void forget () {
+ _connection.disconnect ();
+ }
+
+};
+
+template<typename ObjectWithGoingAway, typename ObjectToBeDestroyed>
+class ProxyShiva {
+ public:
+ ProxyShiva (ObjectWithGoingAway& emitter, ObjectToBeDestroyed& receiver, void (*callback)(ObjectToBeDestroyed*, ObjectWithGoingAway*)) {
+
+ /* if the emitter goes away, destroy the receiver */
+
+ _callback = callback;
+ _callback_argument1 = &receiver;
+ _callback_argument2 = &emitter;
+
+ _connection = emitter.GoingAway.connect
+ (sigc::bind (sigc::mem_fun
+ (*this, &ProxyShiva<ObjectWithGoingAway,ObjectToBeDestroyed>::destroy),
+ &receiver));
+ }
+
+ ~ProxyShiva() {
+ forget ();
+ }
+
+ private:
+ sigc::connection _connection;
+ void (*_callback) (ObjectToBeDestroyed*, ObjectWithGoingAway*);
+ ObjectToBeDestroyed* _callback_argument1;
+ ObjectWithGoingAway* _callback_argument2;
+
+ void destroy (ObjectToBeDestroyed* obj) {
+ /* callback must destroy obj if appropriate, not done here */
+ _callback (obj, _callback_argument2);
+ forget ();
+ }
+
+ void forget () {
+ _connection.disconnect ();
+ }
+};
+
+template<typename ObjectWithGoingAway, typename ObjectToBeDestroyed>
+class PairedShiva {
+ public:
+ PairedShiva (ObjectWithGoingAway& emitter, ObjectToBeDestroyed& receiver) {
+
+ /* if the emitter goes away, destroy the receiver */
+
+ _connection1 = emitter.GoingAway.connect
+ (sigc::bind (sigc::mem_fun
+ (*this, &PairedShiva<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));
+ (sigc::mem_fun (*this, &PairedShiva<ObjectWithGoingAway,ObjectToBeDestroyed>::forget));
}
- ~Shiva() {
+ ~PairedShiva() {
forget ();
}
#include <pbd/destructible.h>
namespace PBD {
+
class StatefulDestructible : public Stateful, public Destructible
{
};
+
+/* be very very careful using this class. it does not inherit from sigc::trackable and thus
+ should only be used in multiple-inheritance situations involving another type
+ that does inherit from sigc::trackable (or sigc::trackable itself)
+*/
+
+class StatefulThingWithGoingAway : public Stateful, public ThingWithGoingAway
+{
+};
+
}
+
#endif /* __pbd_stateful_destructible_h__ */
struct timeval _timestamp;
std::string _name;
bool _clearing;
+
+ friend void command_death (UndoTransaction*, Command *);
};
class UndoHistory
#include <pbd/undo.h>
#include <pbd/xml++.h>
+#include <pbd/shiva.h>
#include <sigc++/bind.h>
using namespace std;
using namespace sigc;
-/* grrr, strict C++ says that static member functions are not C functions, but we also want
- to be able to pack this into a sigc::ptr_fun and not sigc::mem_fun, so we have to make
- it a genuine function rather than a member.
-*/
-
-static void command_death (UndoTransaction* ut, Command* c)
-{
- if (ut->clearing()) {
- return;
- }
-
- ut->remove_command (c);
-
- if (ut->empty()) {
- delete ut;
- }
-}
-
-
UndoTransaction::UndoTransaction ()
{
_clearing = false;
clear ();
}
+void
+command_death (UndoTransaction* ut, Command* c)
+{
+ if (ut->clearing()) {
+ return;
+ }
+
+ ut->remove_command (c);
+
+ if (ut->empty()) {
+ delete ut;
+ }
+}
+
UndoTransaction&
UndoTransaction::operator= (const UndoTransaction& rhs)
{
void
UndoTransaction::add_command (Command *const action)
{
- action->GoingAway.connect (bind (sigc::ptr_fun (command_death), this, const_cast<Command*>(action)));
+ /* catch death */
+ new PBD::ProxyShiva<Command,UndoTransaction> (*action, *this, &command_death);
actions.push_back (action);
}