diff options
author | Carl Hetherington <carl@carlh.net> | 2010-02-10 01:38:20 +0000 |
---|---|---|
committer | Carl Hetherington <carl@carlh.net> | 2010-02-10 01:38:20 +0000 |
commit | 3c00a7ca2ae34cb65c8d3394d9a012f20c69ee77 (patch) | |
tree | 54257f7655152fab7fbe97a75ce24faf15485d49 /libs | |
parent | c9d433d9b3f166e761bfc1b4765cc51b0a521e7d (diff) |
Move ARDOUR::Change into PBD so that Stateful can be aware of
what Change a State reflects. Hence allow Stateful to do some
of the work of set/get_state in Region.
git-svn-id: svn://localhost/ardour2/branches/3.0@6671 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r-- | libs/ardour/ardour/ardour.h | 13 | ||||
-rw-r--r-- | libs/ardour/ardour/audioplaylist.h | 4 | ||||
-rw-r--r-- | libs/ardour/ardour/audioregion.h | 16 | ||||
-rw-r--r-- | libs/ardour/ardour/crossfade.h | 6 | ||||
-rw-r--r-- | libs/ardour/ardour/diskstream.h | 2 | ||||
-rw-r--r-- | libs/ardour/ardour/location.h | 2 | ||||
-rw-r--r-- | libs/ardour/ardour/midi_playlist.h | 2 | ||||
-rw-r--r-- | libs/ardour/ardour/midi_region.h | 2 | ||||
-rw-r--r-- | libs/ardour/ardour/playlist.h | 8 | ||||
-rw-r--r-- | libs/ardour/ardour/region.h | 24 | ||||
-rw-r--r-- | libs/ardour/ardour/session.h | 4 | ||||
-rw-r--r-- | libs/ardour/ardour/tempo.h | 2 | ||||
-rw-r--r-- | libs/ardour/ardour/types.h | 5 | ||||
-rw-r--r-- | libs/ardour/audioregion.cc | 14 | ||||
-rw-r--r-- | libs/ardour/globals.cc | 31 | ||||
-rw-r--r-- | libs/ardour/midi_playlist.cc | 4 | ||||
-rw-r--r-- | libs/ardour/region.cc | 96 | ||||
-rw-r--r-- | libs/pbd/pbd/stateful.h | 61 | ||||
-rw-r--r-- | libs/pbd/stateful.cc | 48 |
19 files changed, 188 insertions, 156 deletions
diff --git a/libs/ardour/ardour/ardour.h b/libs/ardour/ardour/ardour.h index e98d85c433..a7b3bcafd0 100644 --- a/libs/ardour/ardour/ardour.h +++ b/libs/ardour/ardour/ardour.h @@ -31,6 +31,7 @@ #include "pbd/error.h" #include "pbd/failed_constructor.h" #include "pbd/locale_guard.h" +#include "pbd/stateful.h" #include "ardour/types.h" @@ -64,13 +65,11 @@ namespace ARDOUR { return (microseconds_t) jack_get_time(); } - Change new_change (); - - extern Change StartChanged; - extern Change LengthChanged; - extern Change PositionChanged; - extern Change NameChanged; - extern Change BoundsChanged; + extern PBD::Change StartChanged; + extern PBD::Change LengthChanged; + extern PBD::Change PositionChanged; + extern PBD::Change NameChanged; + extern PBD::Change BoundsChanged; static const double SHUTTLE_FRACT_SPEED1=0.48412291827; /* derived from A1,A2 */ diff --git a/libs/ardour/ardour/audioplaylist.h b/libs/ardour/ardour/audioplaylist.h index 9dd133cbc0..ce7c8aa335 100644 --- a/libs/ardour/ardour/audioplaylist.h +++ b/libs/ardour/ardour/audioplaylist.h @@ -79,8 +79,8 @@ class AudioPlaylist : public ARDOUR::Playlist XMLNode& state (bool full_state); void dump () const; - bool region_changed (Change, boost::shared_ptr<Region>); - void crossfade_changed (Change); + bool region_changed (PBD::Change, boost::shared_ptr<Region>); + void crossfade_changed (PBD::Change); void add_crossfade (boost::shared_ptr<Crossfade>); void source_offset_changed (boost::shared_ptr<AudioRegion> region); diff --git a/libs/ardour/ardour/audioregion.h b/libs/ardour/ardour/audioregion.h index 8b95881dc2..3f1e4cf9e3 100644 --- a/libs/ardour/ardour/audioregion.h +++ b/libs/ardour/ardour/audioregion.h @@ -45,13 +45,13 @@ class AudioSource; class AudioRegion : public Region { public: - static Change FadeInChanged; - static Change FadeOutChanged; - static Change FadeInActiveChanged; - static Change FadeOutActiveChanged; - static Change EnvelopeActiveChanged; - static Change ScaleAmplitudeChanged; - static Change EnvelopeChanged; + static PBD::Change FadeInChanged; + static PBD::Change FadeOutChanged; + static PBD::Change FadeInActiveChanged; + static PBD::Change FadeOutActiveChanged; + static PBD::Change EnvelopeActiveChanged; + static PBD::Change ScaleAmplitudeChanged; + static PBD::Change EnvelopeChanged; ~AudioRegion(); @@ -219,7 +219,7 @@ class AudioRegion : public Region AudioRegion (Session& s, nframes_t, nframes_t, std::string name); - int set_live_state (const XMLNode&, int version, Change&, bool send); + int set_live_state (const XMLNode&, int version, PBD::Change&, bool send); }; } /* namespace ARDOUR */ diff --git a/libs/ardour/ardour/crossfade.h b/libs/ardour/ardour/crossfade.h index 5e25bbe00d..148b501e51 100644 --- a/libs/ardour/ardour/crossfade.h +++ b/libs/ardour/ardour/crossfade.h @@ -106,7 +106,7 @@ class Crossfade : public ARDOUR::AudioRegion nframes_t overlap_length() const; PBD::Signal1<void,boost::shared_ptr<Region> > Invalidated; - PBD::Signal1<void,Change> StateChanged; + PBD::Signal1<void,PBD::Change> StateChanged; bool covers (nframes_t frame) const { return _position <= frame && frame < _position + _length; @@ -136,8 +136,8 @@ class Crossfade : public ARDOUR::AudioRegion static nframes_t short_xfade_length() { return _short_xfade_length; } static void set_short_xfade_length (nframes_t n); - static Change ActiveChanged; - static Change FollowOverlapChanged; + static PBD::Change ActiveChanged; + static PBD::Change FollowOverlapChanged; private: friend struct CrossfadeComparePtr; diff --git a/libs/ardour/ardour/diskstream.h b/libs/ardour/ardour/diskstream.h index 85e3071021..0c1bbd54d8 100644 --- a/libs/ardour/ardour/diskstream.h +++ b/libs/ardour/ardour/diskstream.h @@ -206,7 +206,7 @@ class Diskstream : public SessionObject /* XXX fix this redundancy ... */ - virtual void playlist_changed (Change); + virtual void playlist_changed (PBD::Change); virtual void playlist_deleted (boost::weak_ptr<Playlist>); virtual void playlist_ranges_moved (std::list< Evoral::RangeMove<nframes_t> > const &); diff --git a/libs/ardour/ardour/location.h b/libs/ardour/ardour/location.h index 1f2b80c831..6cec906d28 100644 --- a/libs/ardour/ardour/location.h +++ b/libs/ardour/ardour/location.h @@ -179,7 +179,7 @@ class Locations : public PBD::StatefulDestructible PBD::Signal0<void> changed; PBD::Signal1<void,Location*> added; PBD::Signal1<void,Location*> removed; - PBD::Signal1<void,Change> StateChanged; + PBD::Signal1<void,PBD::Change> StateChanged; template<class T> void apply (T& obj, void (T::*method)(LocationList&)) { Glib::Mutex::Lock lm (lock); diff --git a/libs/ardour/ardour/midi_playlist.h b/libs/ardour/ardour/midi_playlist.h index 16e66188fe..32196206e2 100644 --- a/libs/ardour/ardour/midi_playlist.h +++ b/libs/ardour/ardour/midi_playlist.h @@ -74,7 +74,7 @@ protected: private: void dump () const; - bool region_changed (Change, boost::shared_ptr<Region>); + bool region_changed (PBD::Change, boost::shared_ptr<Region>); NoteMode _note_mode; diff --git a/libs/ardour/ardour/midi_region.h b/libs/ardour/ardour/midi_region.h index 1c83c838a7..7309058b8e 100644 --- a/libs/ardour/ardour/midi_region.h +++ b/libs/ardour/ardour/midi_region.h @@ -121,7 +121,7 @@ class MidiRegion : public Region protected: - int set_live_state (const XMLNode&, int version, Change&, bool send); + int set_live_state (const XMLNode&, int version, PBD::Change&, bool send); }; } /* namespace ARDOUR */ diff --git a/libs/ardour/ardour/playlist.h b/libs/ardour/ardour/playlist.h index fb734458d5..404fc61d2d 100644 --- a/libs/ardour/ardour/playlist.h +++ b/libs/ardour/ardour/playlist.h @@ -249,15 +249,15 @@ class Playlist : public SessionObject void notify_length_changed (); void notify_layering_changed (); void notify_contents_changed (); - void notify_state_changed (Change); + void notify_state_changed (PBD::Change); void notify_region_moved (boost::shared_ptr<Region>); void mark_session_dirty(); - void region_changed_proxy (Change, boost::weak_ptr<Region>); - virtual bool region_changed (Change, boost::shared_ptr<Region>); + void region_changed_proxy (PBD::Change, boost::weak_ptr<Region>); + virtual bool region_changed (PBD::Change, boost::shared_ptr<Region>); - void region_bounds_changed (Change, boost::shared_ptr<Region>); + void region_bounds_changed (PBD::Change, boost::shared_ptr<Region>); void region_deleted (boost::shared_ptr<Region>); void sort_regions (); diff --git a/libs/ardour/ardour/region.h b/libs/ardour/ardour/region.h index 7060607a8d..414a1723f9 100644 --- a/libs/ardour/ardour/region.h +++ b/libs/ardour/ardour/region.h @@ -87,15 +87,15 @@ class Region static const Flag DefaultFlags = Flag (Opaque|DefaultFadeIn|DefaultFadeOut|FadeIn|FadeOut); - static Change FadeChanged; - static Change SyncOffsetChanged; - static Change MuteChanged; - static Change OpacityChanged; - static Change LockChanged; - static Change LayerChanged; - static Change HiddenChanged; - - PBD::Signal1<void,Change> StateChanged; + static PBD::Change FadeChanged; + static PBD::Change SyncOffsetChanged; + static PBD::Change MuteChanged; + static PBD::Change OpacityChanged; + static PBD::Change LockChanged; + static PBD::Change LayerChanged; + static PBD::Change HiddenChanged; + + PBD::Signal1<void,PBD::Change> StateChanged; static PBD::Signal1<void,boost::shared_ptr<ARDOUR::Region> > RegionPropertyChanged; void unlock_property_changes () { _flags = Flag (_flags & ~DoNotSendPropertyChanges); } void block_property_changes () { _flags = Flag (_flags | DoNotSendPropertyChanges); } @@ -242,7 +242,7 @@ class Region XMLNode& get_state (); virtual XMLNode& state (bool); virtual int set_state (const XMLNode&, int version); - virtual int set_live_state (const XMLNode&, int version, Change&, bool send); + virtual int set_live_state (const XMLNode&, int version, PBD::Change&, bool send); virtual boost::shared_ptr<Region> get_parent() const; @@ -296,7 +296,7 @@ class Region XMLNode& get_short_state (); /* used only by Session */ - void send_change (Change); + void send_change (PBD::Change); void trim_to_internal (nframes_t position, nframes_t length, void *src); virtual void set_position_internal (nframes_t pos, bool allow_bbt_recompute); @@ -333,7 +333,7 @@ class Region AnalysisFeatureList _transients; bool _valid_transients; mutable uint32_t _read_data_count; ///< modified in read() - Change _pending_changed; + PBD::Change _pending_changed; uint64_t _last_layer_op; ///< timestamp Glib::Mutex _lock; SourceList _sources; diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index f0b71d8019..06d5337b86 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -1210,7 +1210,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi void xrun_recovery (); TempoMap *_tempo_map; - void tempo_map_changed (Change); + void tempo_map_changed (PBD::Change); /* edit/mix groups */ @@ -1257,7 +1257,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi RegionList regions; void add_region (boost::shared_ptr<Region>); - void region_changed (Change, boost::weak_ptr<Region>); + void region_changed (PBD::Change, boost::weak_ptr<Region>); void remove_region (boost::weak_ptr<Region>); int load_regions (const XMLNode& node); diff --git a/libs/ardour/ardour/tempo.h b/libs/ardour/ardour/tempo.h index 9fe6f1fee5..d85247bec4 100644 --- a/libs/ardour/ardour/tempo.h +++ b/libs/ardour/ardour/tempo.h @@ -258,7 +258,7 @@ class TempoMap : public PBD::StatefulDestructible nframes_t frame_rate () const { return _frame_rate; } - PBD::Signal1<void,ARDOUR::Change> StateChanged; + PBD::Signal1<void,PBD::Change> StateChanged; private: static Tempo _default_tempo; diff --git a/libs/ardour/ardour/types.h b/libs/ardour/ardour/types.h index 92c26a9448..e8a8120591 100644 --- a/libs/ardour/ardour/types.h +++ b/libs/ardour/ardour/types.h @@ -261,11 +261,6 @@ namespace ARDOUR { SyncPoint }; - enum Change { - range_guarantee = ~0 - }; - - enum Placement { PreFader, PostFader diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc index e1aeffb4b3..7485ac6913 100644 --- a/libs/ardour/audioregion.cc +++ b/libs/ardour/audioregion.cc @@ -54,13 +54,13 @@ using namespace PBD; /* a Session will reset these to its chosen defaults by calling AudioRegion::set_default_fade() */ -Change AudioRegion::FadeInChanged = ARDOUR::new_change(); -Change AudioRegion::FadeOutChanged = ARDOUR::new_change(); -Change AudioRegion::FadeInActiveChanged = ARDOUR::new_change(); -Change AudioRegion::FadeOutActiveChanged = ARDOUR::new_change(); -Change AudioRegion::EnvelopeActiveChanged = ARDOUR::new_change(); -Change AudioRegion::ScaleAmplitudeChanged = ARDOUR::new_change(); -Change AudioRegion::EnvelopeChanged = ARDOUR::new_change(); +Change AudioRegion::FadeInChanged = PBD::new_change(); +Change AudioRegion::FadeOutChanged = PBD::new_change(); +Change AudioRegion::FadeInActiveChanged = PBD::new_change(); +Change AudioRegion::FadeOutActiveChanged = PBD::new_change(); +Change AudioRegion::EnvelopeActiveChanged = PBD::new_change(); +Change AudioRegion::ScaleAmplitudeChanged = PBD::new_change(); +Change AudioRegion::EnvelopeChanged = PBD::new_change(); void AudioRegion::init () diff --git a/libs/ardour/globals.cc b/libs/ardour/globals.cc index 125c0a8322..7536ee5932 100644 --- a/libs/ardour/globals.cc +++ b/libs/ardour/globals.cc @@ -99,11 +99,11 @@ MIDI::Port *ARDOUR::default_mtc_port = 0; MIDI::Port *ARDOUR::default_midi_port = 0; MIDI::Port *ARDOUR::default_midi_clock_port = 0; -Change ARDOUR::StartChanged = ARDOUR::new_change (); -Change ARDOUR::LengthChanged = ARDOUR::new_change (); -Change ARDOUR::PositionChanged = ARDOUR::new_change (); -Change ARDOUR::NameChanged = ARDOUR::new_change (); -Change ARDOUR::BoundsChanged = Change (0); // see init(), below +PBD::Change ARDOUR::StartChanged = PBD::new_change (); +PBD::Change ARDOUR::LengthChanged = PBD::new_change (); +PBD::Change ARDOUR::PositionChanged = PBD::new_change (); +PBD::Change ARDOUR::NameChanged = PBD::new_change (); +PBD::Change ARDOUR::BoundsChanged = Change (0); // see init(), below compute_peak_t ARDOUR::compute_peak = 0; find_peaks_t ARDOUR::find_peaks = 0; @@ -388,27 +388,6 @@ ARDOUR::cleanup () return 0; } -ARDOUR::Change -ARDOUR::new_change () -{ - Change c; - static uint32_t change_bit = 1; - - /* catch out-of-range */ - if (!change_bit) - { - fatal << _("programming error: ") - << "change_bit out of range in ARDOUR::new_change()" - << endmsg; - /*NOTREACHED*/ - } - - c = Change (change_bit); - change_bit <<= 1; // if it shifts too far, change_bit == 0 - - return c; -} - string ARDOUR::get_ardour_revision () { diff --git a/libs/ardour/midi_playlist.cc b/libs/ardour/midi_playlist.cc index 1721647c7c..e5c2e996f8 100644 --- a/libs/ardour/midi_playlist.cc +++ b/libs/ardour/midi_playlist.cc @@ -415,7 +415,7 @@ MidiPlaylist::contained_automation() bool -MidiPlaylist::region_changed (Change what_changed, boost::shared_ptr<Region> region) +MidiPlaylist::region_changed (PBD::Change what_changed, boost::shared_ptr<Region> region) { if (in_flush || in_set_state) { return false; @@ -423,7 +423,7 @@ MidiPlaylist::region_changed (Change what_changed, boost::shared_ptr<Region> reg // Feeling rather uninterested today, but thanks for the heads up anyway! - Change our_interests = Change (/*MidiRegion::FadeInChanged| + PBD::Change our_interests = PBD::Change (/*MidiRegion::FadeInChanged| MidiRegion::FadeOutChanged| MidiRegion::FadeInActiveChanged| MidiRegion::FadeOutActiveChanged| diff --git a/libs/ardour/region.cc b/libs/ardour/region.cc index e9b896f26e..52137f9af2 100644 --- a/libs/ardour/region.cc +++ b/libs/ardour/region.cc @@ -46,13 +46,13 @@ using namespace std; using namespace ARDOUR; using namespace PBD; -Change Region::FadeChanged = ARDOUR::new_change (); -Change Region::SyncOffsetChanged = ARDOUR::new_change (); -Change Region::MuteChanged = ARDOUR::new_change (); -Change Region::OpacityChanged = ARDOUR::new_change (); -Change Region::LockChanged = ARDOUR::new_change (); -Change Region::LayerChanged = ARDOUR::new_change (); -Change Region::HiddenChanged = ARDOUR::new_change (); +Change Region::FadeChanged = PBD::new_change (); +Change Region::SyncOffsetChanged = PBD::new_change (); +Change Region::MuteChanged = PBD::new_change (); +Change Region::OpacityChanged = PBD::new_change (); +Change Region::LockChanged = PBD::new_change (); +Change Region::LayerChanged = PBD::new_change (); +Change Region::HiddenChanged = PBD::new_change (); PBD::Signal1<void,boost::shared_ptr<ARDOUR::Region> > Region::RegionPropertyChanged; @@ -70,13 +70,13 @@ Region::Region (Session& s, nframes_t start, nframes_t length, const string& nam : SessionObject(s, name) , _type(type) , _flags(Flag (flags|DoNotSendPropertyChanges)) - , _start (X_("start"), start) + , _start (X_("start"), StartChanged, start) , _length(length) - , _position (X_("position"), 0) + , _position (X_("position"), PositionChanged, 0) , _last_position(0) , _positional_lock_style(AudioTime) , _sync_position(_start) - , _layer (X_("layer"), layer) + , _layer (X_("layer"), LayerChanged, layer) , _first_edit(EditChangesNothing) , _frozen(0) , _ancestral_start (0) @@ -98,13 +98,13 @@ Region::Region (boost::shared_ptr<Source> src, nframes_t start, nframes_t length : SessionObject(src->session(), name) , _type(type) , _flags(Flag (flags|DoNotSendPropertyChanges)) - , _start (X_("start"), start) + , _start (X_("start"), StartChanged, start) , _length(length) - , _position (X_("position"), 0) + , _position (X_("position"), PositionChanged, 0) , _last_position(0) , _positional_lock_style(AudioTime) , _sync_position(_start) - , _layer (X_("layer"), layer) + , _layer (X_("layer"), LayerChanged, layer) , _first_edit(EditChangesNothing) , _frozen(0) , _ancestral_start (0) @@ -133,13 +133,13 @@ Region::Region (const SourceList& srcs, nframes_t start, nframes_t length, const : SessionObject(srcs.front()->session(), name) , _type(type) , _flags(Flag (flags|DoNotSendPropertyChanges)) - , _start (X_("start"), start) + , _start (X_("start"), StartChanged, start) , _length(length) - , _position (X_("position"), 0) + , _position (X_("position"), PositionChanged, 0) , _last_position(0) , _positional_lock_style(AudioTime) , _sync_position(_start) - , _layer (X_("layer"), layer) + , _layer (X_("layer"), LayerChanged, layer) , _first_edit(EditChangesNothing) , _frozen(0) , _ancestral_start (0) @@ -161,9 +161,9 @@ Region::Region (const SourceList& srcs, nframes_t start, nframes_t length, const Region::Region (boost::shared_ptr<const Region> other, nframes_t offset, nframes_t length, const string& name, layer_t layer, Flag flags) : SessionObject(other->session(), name) , _type (other->data_type()) - , _start (X_("start"), 0) - , _position (X_("position"), 0) - , _layer (X_("layer"), 0) + , _start (X_("start"), StartChanged, 0) + , _position (X_("position"), PositionChanged, 0) + , _layer (X_("layer"), LayerChanged, 0) , _pending_explicit_relayer (false) { @@ -206,9 +206,9 @@ Region::Region (boost::shared_ptr<const Region> other, nframes_t offset, nframes Region::Region (boost::shared_ptr<const Region> other, nframes_t length, const string& name, layer_t layer, Flag flags) : SessionObject(other->session(), name) , _type (other->data_type()) - , _start (X_("start"), 0) - , _position (X_("position"), 0) - , _layer (X_("layer"), 0) + , _start (X_("start"), StartChanged, 0) + , _position (X_("position"), PositionChanged, 0) + , _layer (X_("layer"), LayerChanged, 0) , _pending_explicit_relayer (false) { register_states (); @@ -306,13 +306,13 @@ Region::Region (const SourceList& srcs, const XMLNode& node) : SessionObject(srcs.front()->session(), X_("error: XML did not reset this")) , _type(DataType::NIL) // to be loaded from XML , _flags(DoNotSendPropertyChanges) - , _start (X_("start"), 0) + , _start (X_("start"), StartChanged, 0) , _length(0) - , _position (X_("position"), 0) + , _position (X_("position"), PositionChanged, 0) , _last_position(0) , _positional_lock_style(AudioTime) , _sync_position(_start) - , _layer (X_("layer"), 0) + , _layer (X_("layer"), LayerChanged, 0) , _first_edit(EditChangesNothing) , _frozen(0) , _stretch(1.0) @@ -338,13 +338,13 @@ Region::Region (boost::shared_ptr<Source> src, const XMLNode& node) : SessionObject(src->session(), X_("error: XML did not reset this")) , _type(DataType::NIL) , _flags(DoNotSendPropertyChanges) - , _start (X_("start"), 0) + , _start (X_("start"), StartChanged, 0) , _length(0) - , _position (X_("position"), 0) + , _position (X_("position"), PositionChanged, 0) , _last_position(0) , _positional_lock_style(AudioTime) , _sync_position(_start) - , _layer (X_("layer"), 0) + , _layer (X_("layer"), LayerChanged, 0) , _first_edit(EditChangesNothing) , _frozen(0) , _stretch(1.0) @@ -1092,16 +1092,14 @@ Region::state (bool /*full_state*/) char buf[64]; const char* fe = NULL; + add_states (*node); + _id.print (buf, sizeof (buf)); node->add_property ("id", buf); node->add_property ("name", _name); node->add_property ("type", _type.to_string()); - snprintf (buf, sizeof (buf), "%u", _start.get ()); - node->add_property ("start", buf); snprintf (buf, sizeof (buf), "%u", _length); node->add_property ("length", buf); - snprintf (buf, sizeof (buf), "%u", _position.get ()); - node->add_property ("position", buf); snprintf (buf, sizeof (buf), "%" PRIi64, _ancestral_start); node->add_property ("ancestral-start", buf); snprintf (buf, sizeof (buf), "%" PRIi64, _ancestral_length); @@ -1130,8 +1128,6 @@ Region::state (bool /*full_state*/) /* note: flags are stored by derived classes */ - snprintf (buf, sizeof (buf), "%d", (int) _layer.get()); - node->add_property ("layer", buf); snprintf (buf, sizeof (buf), "%" PRIu32, _sync_position); node->add_property ("sync-position", buf); @@ -1172,15 +1168,6 @@ Region::set_live_state (const XMLNode& node, int /*version*/, Change& what_chang _type = DataType(prop->value()); } - if ((prop = node.property ("start")) != 0) { - sscanf (prop->value().c_str(), "%" PRIu32, &val); - if (val != _start) { - what_changed = Change (what_changed|StartChanged); - cerr << _name << " start changed\n"; - _start = val; - } - } - if ((prop = node.property ("length")) != 0) { sscanf (prop->value().c_str(), "%" PRIu32, &val); if (val != _length) { @@ -1191,26 +1178,6 @@ Region::set_live_state (const XMLNode& node, int /*version*/, Change& what_chang } } - if ((prop = node.property ("position")) != 0) { - sscanf (prop->value().c_str(), "%" PRIu32, &val); - if (val != _position) { - what_changed = Change (what_changed|PositionChanged); - cerr << _name << " position changed\n"; - _last_position = _position; - _position = val; - } - } - - if ((prop = node.property ("layer")) != 0) { - layer_t x; - x = (layer_t) atoi (prop->value().c_str()); - if (x != _layer) { - what_changed = Change (what_changed|LayerChanged); - cerr << _name << " layer changed\n"; - _layer = x; - } - } - if ((prop = node.property ("sync-position")) != 0) { sscanf (prop->value().c_str(), "%" PRIu32, &val); if (val != _sync_position) { @@ -1309,7 +1276,6 @@ int Region::set_state (const XMLNode& node, int version) { const XMLProperty *prop; - Change what_changed = Change (0); /* ID is not allowed to change, ever */ @@ -1319,6 +1285,8 @@ Region::set_state (const XMLNode& node, int version) _first_edit = EditChangesNothing; + Change what_changed = set_state_using_states (node); + set_live_state (node, version, what_changed, true); return 0; diff --git a/libs/pbd/pbd/stateful.h b/libs/pbd/pbd/stateful.h index 60c1c6b23c..80d7aa796a 100644 --- a/libs/pbd/pbd/stateful.h +++ b/libs/pbd/pbd/stateful.h @@ -33,13 +33,20 @@ namespace sys { class path; } +enum Change { + range_guarantee = ~0 +}; + +Change new_change (); + /** Base (non template) part of State */ class StateBase { public: - StateBase (std::string const & p) + StateBase (std::string const & p, Change c) : _have_old (false) , _xml_property_name (p) + , _change (c) { } @@ -47,6 +54,7 @@ public: StateBase (StateBase const & s) : _have_old (s._have_old) , _xml_property_name (s._xml_property_name) + , _change (s._change) { } @@ -57,10 +65,13 @@ public: } virtual void diff (XMLNode *, XMLNode *) const = 0; + virtual Change set_state (XMLNode const &) = 0; + virtual void add_state (XMLNode &) const = 0; protected: bool _have_old; std::string _xml_property_name; + Change _change; }; /** Class to represent a single piece of state in a Stateful object */ @@ -68,8 +79,8 @@ template <class T> class State : public StateBase { public: - State (std::string const & p, T const & v) - : StateBase (p) + State (std::string const & p, Change c, T const & v) + : StateBase (p, c) , _current (v) { @@ -86,6 +97,7 @@ public: /* XXX: isn't there a nicer place to do this? */ _have_old = s._have_old; _xml_property_name = s._xml_property_name; + _change = s._change; _current = s._current; _old = s._old; @@ -112,13 +124,36 @@ public: void diff (XMLNode* old, XMLNode* current) const { if (_have_old) { - std::stringstream o; - o << _old; - old->add_property (_xml_property_name.c_str(), o.str().c_str()); - std::stringstream c; - c << _current; - current->add_property (_xml_property_name.c_str(), c.str().c_str()); + old->add_property (_xml_property_name.c_str(), to_string (_old)); + current->add_property (_xml_property_name.c_str(), to_string (_current)); + } + } + + /** Try to set state from the property of an XML node. + * @param node XML node. + * @return Change effected, or 0. + */ + Change set_state (XMLNode const & node) { + XMLProperty const * p = node.property (_xml_property_name.c_str()); + + if (p) { + std::stringstream s (p->value ()); + T v; + s >> v; + + if (v == _current) { + return Change (0); + } + + set (v); + return _change; } + + return Change (0); + } + + void add_state (XMLNode & node) const { + node.add_property (_xml_property_name.c_str(), to_string (_current)); } private: @@ -127,6 +162,12 @@ private: _have_old = true; _current = v; } + + std::string to_string (T const & v) const { + std::stringstream s; + s << v; + return s.str (); + } T _current; T _old; @@ -163,6 +204,8 @@ class Stateful { void add_instant_xml (XMLNode&, const sys::path& directory_path); XMLNode *instant_xml (const std::string& str, const sys::path& directory_path); + Change set_state_using_states (XMLNode const &); + void add_states (XMLNode &); XMLNode *_extra_xml; XMLNode *_instant_xml; diff --git a/libs/pbd/stateful.cc b/libs/pbd/stateful.cc index 52b80c95ae..a50c54d7f5 100644 --- a/libs/pbd/stateful.cc +++ b/libs/pbd/stateful.cc @@ -35,6 +35,27 @@ namespace PBD { int Stateful::current_state_version = 0; int Stateful::loading_state_version = 0; +PBD::Change +new_change () +{ + Change c; + static uint32_t change_bit = 1; + + /* catch out-of-range */ + if (!change_bit) + { + fatal << _("programming error: ") + << "change_bit out of range in ARDOUR::new_change()" + << endmsg; + /*NOTREACHED*/ + } + + c = Change (change_bit); + change_bit <<= 1; // if it shifts too far, change_bit == 0 + + return c; +} + Stateful::Stateful () { _extra_xml = 0; @@ -175,5 +196,32 @@ Stateful::diff () return make_pair (old, current); } + +/** Set state of _states from an XML node. + * @param node Node. + * @return Changes made. + */ +Change +Stateful::set_state_using_states (XMLNode const & node) +{ + Change c = Change (0); + + for (list<StateBase*>::iterator i = _states.begin(); i != _states.end(); ++i) { + c = Change (c | (*i)->set_state (node)); + } + + return c; +} + +/** Add state of _states to an XML node. + * @param node Node. + */ +void +Stateful::add_states (XMLNode & node) +{ + for (list<StateBase*>::iterator i = _states.begin(); i != _states.end(); ++i) { + (*i)->add_state (node); + } +} } // namespace PBD |