mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-18 12:46:32 +01:00
Move various code up the Property / Stateful hierarchies.
git-svn-id: svn://localhost/ardour2/branches/3.0@7682 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
7b29752441
commit
fde848282d
8 changed files with 90 additions and 78 deletions
|
|
@ -35,7 +35,6 @@
|
||||||
|
|
||||||
#include "pbd/undo.h"
|
#include "pbd/undo.h"
|
||||||
#include "pbd/stateful.h"
|
#include "pbd/stateful.h"
|
||||||
#include "pbd/stateful_owner.h"
|
|
||||||
#include "pbd/statefuldestructible.h"
|
#include "pbd/statefuldestructible.h"
|
||||||
#include "pbd/sequence_property.h"
|
#include "pbd/sequence_property.h"
|
||||||
|
|
||||||
|
|
@ -74,9 +73,8 @@ class RegionListProperty : public PBD::SequenceProperty<std::list<boost::shared_
|
||||||
Playlist& _playlist;
|
Playlist& _playlist;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Playlist : public SessionObject
|
class Playlist : public SessionObject , public boost::enable_shared_from_this<Playlist>
|
||||||
, public PBD::StatefulOwner
|
{
|
||||||
, public boost::enable_shared_from_this<Playlist> {
|
|
||||||
public:
|
public:
|
||||||
typedef std::list<boost::shared_ptr<Region> > RegionList;
|
typedef std::list<boost::shared_ptr<Region> > RegionList;
|
||||||
static void make_property_quarks ();
|
static void make_property_quarks ();
|
||||||
|
|
@ -88,13 +86,10 @@ class Playlist : public SessionObject
|
||||||
|
|
||||||
virtual ~Playlist ();
|
virtual ~Playlist ();
|
||||||
|
|
||||||
bool set_property (const PBD::PropertyBase&);
|
|
||||||
void update (const RegionListProperty::ChangeRecord&);
|
void update (const RegionListProperty::ChangeRecord&);
|
||||||
void clear_owned_history ();
|
void clear_owned_history ();
|
||||||
void rdiff (std::vector<PBD::StatefulDiffCommand*>&) const;
|
void rdiff (std::vector<PBD::StatefulDiffCommand*>&) const;
|
||||||
|
|
||||||
PBD::PropertyList* property_factory (const XMLNode&) const;
|
|
||||||
|
|
||||||
boost::shared_ptr<Region> region_by_id (const PBD::ID&);
|
boost::shared_ptr<Region> region_by_id (const PBD::ID&);
|
||||||
|
|
||||||
void set_region_ownership ();
|
void set_region_ownership ();
|
||||||
|
|
|
||||||
|
|
@ -88,8 +88,6 @@ class Region
|
||||||
|
|
||||||
static PBD::Signal2<void,boost::shared_ptr<ARDOUR::Region>, const PBD::PropertyChange&> RegionPropertyChanged;
|
static PBD::Signal2<void,boost::shared_ptr<ARDOUR::Region>, const PBD::PropertyChange&> RegionPropertyChanged;
|
||||||
|
|
||||||
PBD::PropertyList* property_factory (const XMLNode&) const;
|
|
||||||
|
|
||||||
virtual ~Region();
|
virtual ~Region();
|
||||||
|
|
||||||
/** Note: changing the name of a Region does not constitute an edit */
|
/** Note: changing the name of a Region does not constitute an edit */
|
||||||
|
|
|
||||||
|
|
@ -2079,38 +2079,18 @@ Playlist::mark_session_dirty ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
Playlist::set_property (const PropertyBase& prop)
|
|
||||||
{
|
|
||||||
if (prop == Properties::regions.property_id) {
|
|
||||||
const RegionListProperty::ChangeRecord& change (dynamic_cast<const RegionListProperty*>(&prop)->change());
|
|
||||||
regions.update (change);
|
|
||||||
return (!change.added.empty() && !change.removed.empty());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Playlist::rdiff (vector<StatefulDiffCommand*>& cmds) const
|
Playlist::rdiff (vector<StatefulDiffCommand*>& cmds) const
|
||||||
{
|
{
|
||||||
RegionLock rlock (const_cast<Playlist *> (this));
|
RegionLock rlock (const_cast<Playlist *> (this));
|
||||||
|
Stateful::rdiff (cmds);
|
||||||
for (RegionList::const_iterator i = regions.begin(); i != regions.end(); ++i) {
|
|
||||||
if ((*i)->changed ()) {
|
|
||||||
StatefulDiffCommand* sdc = new StatefulDiffCommand (*i);
|
|
||||||
cmds.push_back (sdc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Playlist::clear_owned_history ()
|
Playlist::clear_owned_history ()
|
||||||
{
|
{
|
||||||
RegionLock rlock (this);
|
RegionLock rlock (this);
|
||||||
|
Stateful::clear_owned_history ();
|
||||||
for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) {
|
|
||||||
(*i)->clear_history ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -2132,32 +2112,6 @@ Playlist::update (const RegionListProperty::ChangeRecord& change)
|
||||||
thaw ();
|
thaw ();
|
||||||
}
|
}
|
||||||
|
|
||||||
PropertyList*
|
|
||||||
Playlist::property_factory (const XMLNode& history_node) const
|
|
||||||
{
|
|
||||||
const XMLNodeList& children (history_node.children());
|
|
||||||
PropertyList* prop_list = 0;
|
|
||||||
|
|
||||||
for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
|
|
||||||
|
|
||||||
if ((*i)->name() == capitalize (regions.property_name())) {
|
|
||||||
|
|
||||||
RegionListProperty* rlp = new RegionListProperty (*const_cast<Playlist*> (this));
|
|
||||||
|
|
||||||
if (rlp->set_change (**i)) {
|
|
||||||
if (!prop_list) {
|
|
||||||
prop_list = new PropertyList();
|
|
||||||
}
|
|
||||||
prop_list->add (rlp);
|
|
||||||
} else {
|
|
||||||
delete rlp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return prop_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
Playlist::set_state (const XMLNode& node, int version)
|
Playlist::set_state (const XMLNode& node, int version)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1582,19 +1582,3 @@ Region::use_sources (SourceList const & s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PropertyList*
|
|
||||||
Region::property_factory (const XMLNode& history_node) const
|
|
||||||
{
|
|
||||||
PropertyList* prop_list = new PropertyList;
|
|
||||||
|
|
||||||
for (OwnedPropertyList::const_iterator i = _properties->begin(); i != _properties->end(); ++i) {
|
|
||||||
PropertyBase* prop = i->second->maybe_clone_self_if_found_in_history_node (history_node);
|
|
||||||
|
|
||||||
if (prop) {
|
|
||||||
prop_list->add (prop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return prop_list;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "pbd/xml++.h"
|
#include "pbd/xml++.h"
|
||||||
|
|
||||||
|
|
@ -30,6 +31,7 @@ class Command;
|
||||||
namespace PBD {
|
namespace PBD {
|
||||||
|
|
||||||
class PropertyList;
|
class PropertyList;
|
||||||
|
class StatefulDiffCommand;
|
||||||
|
|
||||||
/** A unique identifier for a property of a Stateful object */
|
/** A unique identifier for a property of a Stateful object */
|
||||||
typedef GQuark PropertyID;
|
typedef GQuark PropertyID;
|
||||||
|
|
@ -89,6 +91,9 @@ public:
|
||||||
/** Forget about any old value for this state */
|
/** Forget about any old value for this state */
|
||||||
virtual void clear_history () = 0;
|
virtual void clear_history () = 0;
|
||||||
|
|
||||||
|
/** Tell any things we own to forget about their old values */
|
||||||
|
virtual void clear_owned_history () {}
|
||||||
|
|
||||||
/** Get any change in this property as XML and add it to a node */
|
/** Get any change in this property as XML and add it to a node */
|
||||||
virtual void get_change (XMLNode *) const = 0;
|
virtual void get_change (XMLNode *) const = 0;
|
||||||
|
|
||||||
|
|
@ -99,6 +104,9 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual void diff (PropertyList& undo, PropertyList& redo, Command*) const = 0;
|
virtual void diff (PropertyList& undo, PropertyList& redo, Command*) const = 0;
|
||||||
|
|
||||||
|
/** Collect StatefulDiffCommands for changes to anything that we own */
|
||||||
|
virtual void rdiff (std::vector<StatefulDiffCommand*> &) const {}
|
||||||
|
|
||||||
virtual PropertyBase* maybe_clone_self_if_found_in_history_node (const XMLNode&) const { return 0; }
|
virtual PropertyBase* maybe_clone_self_if_found_in_history_node (const XMLNode&) const { return 0; }
|
||||||
|
|
||||||
/** Set our value from an XML node.
|
/** Set our value from an XML node.
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,44 @@ class SequenceProperty : public PropertyBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SequenceProperty<Container>* maybe_clone_self_if_found_in_history_node (XMLNode const & node) const {
|
||||||
|
|
||||||
|
XMLNodeList const children = node.children ();
|
||||||
|
|
||||||
|
for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
|
||||||
|
|
||||||
|
if ((*i)->name() == capitalize (property_name())) {
|
||||||
|
|
||||||
|
SequenceProperty<Container>* p = create ();
|
||||||
|
|
||||||
|
if (p->set_change (**i)) {
|
||||||
|
return p;
|
||||||
|
} else {
|
||||||
|
delete p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear_owned_history () {
|
||||||
|
for (typename Container::iterator i = begin(); i != end(); ++i) {
|
||||||
|
(*i)->clear_history ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void rdiff (std::vector<StatefulDiffCommand*>& cmds) const {
|
||||||
|
for (typename Container::const_iterator i = begin(); i != end(); ++i) {
|
||||||
|
if ((*i)->changed ()) {
|
||||||
|
StatefulDiffCommand* sdc = new StatefulDiffCommand (*i);
|
||||||
|
cmds.push_back (sdc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Container rlist() { return _val; }
|
Container rlist() { return _val; }
|
||||||
|
|
||||||
/* Wrap salient methods of Sequence
|
/* Wrap salient methods of Sequence
|
||||||
|
|
|
||||||
|
|
@ -68,12 +68,14 @@ class Stateful {
|
||||||
/* history management */
|
/* history management */
|
||||||
|
|
||||||
void clear_history ();
|
void clear_history ();
|
||||||
|
virtual void clear_owned_history ();
|
||||||
void diff (PropertyList&, PropertyList&, Command*) const;
|
void diff (PropertyList&, PropertyList&, Command*) const;
|
||||||
|
virtual void rdiff (std::vector<StatefulDiffCommand*> &) const;
|
||||||
bool changed() const;
|
bool changed() const;
|
||||||
|
|
||||||
/* create a property list from an XMLNode
|
/* create a property list from an XMLNode
|
||||||
*/
|
*/
|
||||||
virtual PropertyList* property_factory(const XMLNode&) const { return 0; }
|
virtual PropertyList* property_factory (const XMLNode&) const;
|
||||||
|
|
||||||
/* How stateful's notify of changes to their properties
|
/* How stateful's notify of changes to their properties
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -314,4 +314,37 @@ Stateful::apply_change (const PropertyBase& prop)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PropertyList*
|
||||||
|
Stateful::property_factory (const XMLNode& history_node) const
|
||||||
|
{
|
||||||
|
PropertyList* prop_list = new PropertyList;
|
||||||
|
|
||||||
|
for (OwnedPropertyList::const_iterator i = _properties->begin(); i != _properties->end(); ++i) {
|
||||||
|
PropertyBase* prop = i->second->maybe_clone_self_if_found_in_history_node (history_node);
|
||||||
|
|
||||||
|
if (prop) {
|
||||||
|
prop_list->add (prop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return prop_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Stateful::rdiff (vector<StatefulDiffCommand*>& cmds) const
|
||||||
|
{
|
||||||
|
for (OwnedPropertyList::const_iterator i = _properties->begin(); i != _properties->end(); ++i) {
|
||||||
|
i->second->rdiff (cmds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Stateful::clear_owned_history ()
|
||||||
|
{
|
||||||
|
for (OwnedPropertyList::iterator i = _properties->begin(); i != _properties->end(); ++i) {
|
||||||
|
i->second->clear_owned_history ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace PBD
|
} // namespace PBD
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue