add set_* methods to Slice; remove property additions

Derived classes (currently only Region) just register the Slice properties
_start and _length.
This commit is contained in:
Paul Davis 2024-01-04 19:05:58 -07:00
parent e3be2c781f
commit a6e02d7a94
3 changed files with 22 additions and 8 deletions

View file

@ -18,7 +18,7 @@ namespace Properties {
LIBARDOUR_API extern PBD::PropertyDescriptor<timecnt_t> length; LIBARDOUR_API extern PBD::PropertyDescriptor<timecnt_t> length;
} }
class LIBARDOUR_API Slice : virtual public PBD::Stateful class LIBARDOUR_API Slice
{ {
public: public:
Slice (Temporal::timepos_t const &, Temporal::timecnt_t const &); Slice (Temporal::timepos_t const &, Temporal::timecnt_t const &);
@ -33,6 +33,10 @@ class LIBARDOUR_API Slice : virtual public PBD::Stateful
timepos_t end() const; timepos_t end() const;
timepos_t nt_last() const { return end().decrement(); } timepos_t nt_last() const { return end().decrement(); }
virtual void set_start (timepos_t const & s) { _start = s; }
virtual void set_position (timepos_t const & p);
virtual void set_length (timecnt_t const &);
/* these two are valid ONLY during a StateChanged signal handler */ /* these two are valid ONLY during a StateChanged signal handler */
timepos_t last_position () const { return _last_length.position(); } timepos_t last_position () const { return _last_length.position(); }
@ -112,9 +116,6 @@ class LIBARDOUR_API Slice : virtual public PBD::Stateful
virtual void set_length_internal (timecnt_t const &); virtual void set_length_internal (timecnt_t const &);
virtual void set_start_internal (timepos_t const &); virtual void set_start_internal (timepos_t const &);
virtual void set_position_internal (timepos_t const &); virtual void set_position_internal (timepos_t const &);
private:
void register_properties ();
}; };
} /* namespace */ } /* namespace */

View file

@ -200,6 +200,13 @@ Region::register_properties ()
{ {
_xml_node_name = X_("Region"); _xml_node_name = X_("Region");
/* anything derived from Slice must remember to add these properties to
* Stateful's list, since Slice does not do this itself.
*/
add_property (_start);
add_property (_length);
add_property (_muted); add_property (_muted);
add_property (_opaque); add_property (_opaque);
add_property (_locked); add_property (_locked);

View file

@ -8,7 +8,6 @@ Slice::Slice (timepos_t const & s, timecnt_t const & l)
, _length (Properties::length, l) , _length (Properties::length, l)
, _last_length (l) , _last_length (l)
{ {
register_properties ();
} }
Slice::Slice (Slice const & other) Slice::Slice (Slice const & other)
@ -19,10 +18,17 @@ Slice::Slice (Slice const & other)
} }
void void
Slice::register_properties () Slice::set_position (timepos_t const & pos)
{ {
add_property (_start); _length = timecnt_t (_length.val().distance(), pos);
add_property (_length); _last_length = _length;
}
void
Slice::set_length (timecnt_t const & len)
{
_last_length = _length;
_length = timecnt_t (len.distance(), _length.val().position());
} }
timepos_t timepos_t