More tinkering with State<>. Use some StateDiffCommands instead of
authorCarl Hetherington <carl@carlh.net>
Thu, 11 Feb 2010 17:08:34 +0000 (17:08 +0000)
committerCarl Hetherington <carl@carlh.net>
Thu, 11 Feb 2010 17:08:34 +0000 (17:08 +0000)
MementoCommand<Region>.  More use of State<> for Region members.

git-svn-id: svn://localhost/ardour2/branches/3.0@6675 d708f5d6-7413-0410-9779-e7cbd77b26cf

25 files changed:
gtk2_ardour/editor_ops.cc
gtk2_ardour/rhythm_ferret.cc
gtk2_ardour/time_axis_view.cc
libs/ardour/ardour/ardour.h
libs/ardour/ardour/region.h
libs/ardour/ardour/session_object.h
libs/ardour/audio_diskstream.cc
libs/ardour/audio_region_importer.cc
libs/ardour/audioregion.cc
libs/ardour/crossfade.cc
libs/ardour/diskstream.cc
libs/ardour/globals.cc
libs/ardour/io.cc
libs/ardour/io_processor.cc
libs/ardour/midi_diskstream.cc
libs/ardour/midi_region.cc
libs/ardour/midi_source.cc
libs/ardour/midi_track.cc
libs/ardour/region.cc
libs/ardour/route.cc
libs/ardour/session.cc
libs/ardour/session_state.cc
libs/ardour/sndfilesource.cc
libs/pbd/i18n.h
libs/pbd/pbd/stateful.h

index 1ca4c1d2455d71c3ae1927fd04aafcb21b21954b..6ed670509e31fcdf8c4ee9cb9bb3d101a85d6966 100644 (file)
@@ -32,6 +32,7 @@
 #include "pbd/pthread_utils.h"
 #include "pbd/memento_command.h"
 #include "pbd/whitespace.h"
+#include "pbd/stateful_diff_command.h"
 
 #include <gtkmm2ext/utils.h>
 #include <gtkmm2ext/choice.h>
@@ -3177,10 +3178,9 @@ Editor::naturalize ()
 
        begin_reversible_command (_("naturalize"));
        for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
-                XMLNode &before = (*i)->region()->get_state();
+               (*i)->region()->clear_history ();
                (*i)->region()->move_to_natural_position (this);
-                XMLNode &after = (*i)->region()->get_state();
-               _session->add_command (new MementoCommand<Region>(*((*i)->region().get()), &before, &after));
+               _session->add_command (new StatefulDiffCommand ((*i)->region().get()));
        }
        commit_reversible_command ();
 }
@@ -4930,10 +4930,9 @@ Editor::toggle_gain_envelope_active ()
        for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
                AudioRegionView* const arv = dynamic_cast<AudioRegionView*>(*i);
                if (arv) {
-                       XMLNode &before = arv->region()->get_state ();
+                       arv->region()->clear_history ();
                        arv->audio_region()->set_envelope_active (!arv->audio_region()->envelope_active());
-                       XMLNode &after = arv->region()->get_state ();
-                       _session->add_command (new MementoCommand<Region> (*(arv->region().get()), &before, &after));
+                       _session->add_command (new StatefulDiffCommand (arv->region().get()));
                }
        }
 
@@ -4952,10 +4951,9 @@ Editor::toggle_region_lock ()
        _session->begin_reversible_command (_("region lock"));
 
        for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
-               XMLNode &before = (*i)->region()->get_state ();
+               (*i)->region()->clear_history ();
                (*i)->region()->set_locked (!(*i)->region()->locked());
-               XMLNode &after = (*i)->region()->get_state ();
-               _session->add_command (new MementoCommand<Region> (*((*i)->region().get()), &before, &after));
+               _session->add_command (new StatefulDiffCommand ((*i)->region().get()));
        }
 
        _session->commit_reversible_command ();
@@ -4995,10 +4993,9 @@ Editor::toggle_region_mute ()
        _session->begin_reversible_command (_("region mute"));
 
        for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
-               XMLNode &before = (*i)->region()->get_state ();
+               (*i)->region()->clear_history ();
                (*i)->region()->set_muted (!(*i)->region()->muted());
-               XMLNode &after = (*i)->region()->get_state ();
-               _session->add_command (new MementoCommand<Region> (*((*i)->region().get()), &before, &after));
+               _session->add_command (new StatefulDiffCommand ((*i)->region().get()));
        }
 
        _session->commit_reversible_command ();
@@ -5016,10 +5013,9 @@ Editor::toggle_region_opaque ()
        _session->begin_reversible_command (_("region opacity"));
 
        for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
-               XMLNode &before = (*i)->region()->get_state ();
+               (*i)->region()->clear_history ();
                (*i)->region()->set_opaque (!(*i)->region()->opaque());
-               XMLNode &after = (*i)->region()->get_state ();
-               _session->add_command (new MementoCommand<Region> (*((*i)->region().get()), &before, &after));
+               _session->add_command (new StatefulDiffCommand ((*i)->region().get()));
        }
 
        _session->commit_reversible_command ();
index f6619fcb8bce55a052bfef288ab8aab23a3a3080..de18fe7b5d907d3c75e67d3c8c0ce8c45209bfda 100644 (file)
@@ -2,6 +2,7 @@
 #include <gtkmm2ext/utils.h>
 
 #include "pbd/memento_command.h"
+#include "pbd/convert.h"
 
 #include "ardour/transient_detector.h"
 #include "ardour/onset_detector.h"
index 983bd8c33bc008d76f48b3cfce5424cdb4a0bdf4..4ab870c9cd1b68745dbb78d3abbfea2efd2c6d60 100644 (file)
@@ -28,6 +28,7 @@
 #include <libgnomecanvasmm/item.h>
 
 #include "pbd/error.h"
+#include "pbd/convert.h"
 
 #include <gtkmm2ext/utils.h>
 #include <gtkmm2ext/selector.h>
index a7b3bcafd080f0e61f44a07b321aad14d901f14a..403cf21007f9b810517738d5edabac1079eb5df4 100644 (file)
@@ -70,6 +70,7 @@ namespace ARDOUR {
        extern PBD::Change PositionChanged;
        extern PBD::Change NameChanged;
        extern PBD::Change BoundsChanged;
+       extern PBD::Change FlagsChanged;
 
        static const double SHUTTLE_FRACT_SPEED1=0.48412291827; /* derived from A1,A2 */
 
index 414a1723f9707290a2923e66aad30b0a70016f6d..9c78285a09fd3043aa28b3d6bb83d13ada30c01a 100644 (file)
@@ -314,21 +314,21 @@ class Region
        virtual void recompute_at_end () = 0;
 
        DataType                _type;
-       Flag                    _flags;
+       PBD::EnumState<Flag>    _flags;
        PBD::State<nframes_t>   _start;
-       nframes_t               _length;
+       PBD::State<nframes_t>   _length;
        nframes_t               _last_length;
        PBD::State<nframes_t>   _position;
        nframes_t               _last_position;
        PositionLockStyle       _positional_lock_style;
-       nframes_t               _sync_position;
+       PBD::State<nframes_t>   _sync_position;
        PBD::State<layer_t>     _layer;
        mutable RegionEditState _first_edit;
        int                     _frozen;
-       nframes64_t             _ancestral_start;
-       nframes64_t             _ancestral_length;
-       float                   _stretch;
-       float                   _shift;
+       PBD::State<nframes64_t> _ancestral_start;
+       PBD::State<nframes64_t> _ancestral_length;
+       PBD::State<float>       _stretch;
+       PBD::State<float>       _shift;
        BBT_Time                _bbt_time;
        AnalysisFeatureList     _transients;
        bool                    _valid_transients;
index 47caab54758ca438594bb8fe352baf162de51177..cf9ccbb3a7172476b6347c540765f95032da3e85 100644 (file)
@@ -26,6 +26,8 @@
 
 #include "ardour/session_handle.h"
 
+#include "i18n.h"
+
 namespace ARDOUR {
 
 class Session;
@@ -39,11 +41,13 @@ class SessionObject : public SessionHandleRef, public PBD::StatefulDestructible
   public:
        SessionObject (Session& session, const std::string& name)
                : SessionHandleRef (session)
-               , _name(name)
-       {}
+               , _name (X_("name"), PBD::Change (0), "")
+       {
+               add_state (_name);
+       }
        
-       Session&           session() const { return _session; }
-       const std::string& name()    const { return _name; }
+       Session&    session() const { return _session; }
+       std::string name()    const { return _name; }
 
        virtual bool set_name (const std::string& str) {
                if (_name != str) {
@@ -56,7 +60,7 @@ class SessionObject : public SessionHandleRef, public PBD::StatefulDestructible
        PBD::Signal0<void> NameChanged;
 
   protected:
-       std::string _name;
+       PBD::State<std::string> _name;
 };
 
 } // namespace ARDOUR
index db1a343d175eac33d2074ec832df0eba59e8a913..ef209fad3a897228425e90b088c04cd52227c28d 100644 (file)
@@ -1433,7 +1433,7 @@ AudioDiskstream::transport_stopped (struct tm& when, time_t twhen, bool abort_ca
                if (s) {
                        srcs.push_back (s);
                        s->update_header (capture_info.front()->start, when, twhen);
-                       s->set_captured_for (_name);
+                       s->set_captured_for (_name.get());
                        s->mark_immutable ();
                        if (Config->get_auto_analyse_audio()) {
                                Analyser::queue_source_for_analysis (s, true);
@@ -1970,7 +1970,7 @@ AudioDiskstream::rename_write_sources ()
 
        for (chan = c->begin(), n = 0; chan != c->end(); ++chan, ++n) {
                if ((*chan)->write_source != 0) {
-                       (*chan)->write_source->set_source_name (_name, destructive());
+                       (*chan)->write_source->set_source_name (_name.get(), destructive());
                        /* XXX what to do if one of them fails ? */
                }
        }
@@ -2178,7 +2178,7 @@ AudioDiskstream::use_pending_capture_data (XMLNode& node)
                                first_fs = fs;
                        }
 
-                       fs->set_captured_for (_name);
+                       fs->set_captured_for (_name.get());
                }
        }
 
index c9203435d539dc0266acfca7934c84205ea78ca5..289af0b4d8f6e91dd2baacea1e96cb43a7b2ea18 100644 (file)
@@ -252,7 +252,7 @@ AudioRegionImporter::parse_source_xml ()
                return false;
        }
 
-       channels = atoi (prop->value());
+       channels = atoi (prop->value().c_str());
        for (uint32_t i = 0; i < channels; ++i) {
                bool source_found = false;
 
index 7485ac69131f8b8ea30af11ff513230d1ce21d7b..c96f7119b8ee42972a02ac2d8b4e22661c593f5e 100644 (file)
@@ -305,12 +305,9 @@ void
 AudioRegion::set_envelope_active (bool yn)
 {
        if (envelope_active() != yn) {
-               char buf[64];
                if (yn) {
-                       snprintf (buf, sizeof (buf), "envelope active");
                        _flags = Flag (_flags|EnvelopeActive);
                } else {
-                       snprintf (buf, sizeof (buf), "envelope off");
                        _flags = Flag (_flags & ~EnvelopeActive);
                }
                send_change (EnvelopeActiveChanged);
index fd59982f6200fb17745a625c50a9883c54f62e2b..a79dae5f07584058b2942e1303335a7b672cbe74 100644 (file)
@@ -314,7 +314,7 @@ Crossfade::read_at (Sample *buf, Sample *mixdown_buffer,
 
                start = _position;
                buf += offset;
-               to_write = min (_length, cnt);
+               to_write = min (_length.get(), cnt);
 
        } else {
 
@@ -679,7 +679,7 @@ Crossfade::get_state ()
        node->add_property ("active", (_active ? "yes" : "no"));
        node->add_property ("follow-overlap", (_follow_overlap ? "yes" : "no"));
        node->add_property ("fixed", (_fixed ? "yes" : "no"));
-       snprintf (buf, sizeof(buf), "%" PRIu32, _length);
+       snprintf (buf, sizeof(buf), "%" PRIu32, _length.get());
        node->add_property ("length", buf);
        snprintf (buf, sizeof(buf), "%" PRIu32, (uint32_t) _anchor_point);
        node->add_property ("anchor-point", buf);
index a4f8c22e285d8f0558cfbcced4bd0155bf53f800..264dd3e79f044479243397ae559d1e0e8c48f0d9 100644 (file)
@@ -396,7 +396,7 @@ Diskstream::playlist_deleted (boost::weak_ptr<Playlist> wpl)
 bool
 Diskstream::set_name (const string& str)
 {
-       if (str != _name) {
+       if (_name != str) {
                assert(playlist());
                playlist()->set_name (str);
 
index 7536ee59328550e5a859446540aec1c76730bbab..3f3c35f7390d74011e2bfd4bb3e42a45adc40810 100644 (file)
@@ -104,6 +104,7 @@ 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
+PBD::Change ARDOUR::FlagsChanged = PBD::new_change ();
 
 compute_peak_t          ARDOUR::compute_peak = 0;
 find_peaks_t            ARDOUR::find_peaks = 0;
index c9d3f6be08ffee9049c8be343564f7a723a9c174..34f624f2d25cde13048cc2de9d2f74d4e40357b1 100644 (file)
@@ -1086,7 +1086,7 @@ IO::set_name (const string& requested_name)
 {
        string name = requested_name;
 
-       if (name == _name) {
+       if (_name == name) {
                return true;
        }
 
@@ -1098,7 +1098,7 @@ IO::set_name (const string& requested_name)
 
        for (PortSet::iterator i = _ports.begin(); i != _ports.end(); ++i) {
                string current_name = i->name();
-               current_name.replace (current_name.find (_name), _name.length(), name);
+               current_name.replace (current_name.find (_name), _name.get().length(), name);
                i->set_name (current_name);
        }
 
@@ -1267,7 +1267,7 @@ IO::build_legal_port_name (DataType type)
        char buf1[name_size+1];
        char buf2[name_size+1];
 
-       snprintf (buf1, name_size+1, ("%.*s/%s"), limit, _name.c_str(), suffix.c_str());
+       snprintf (buf1, name_size+1, ("%.*s/%s"), limit, _name.get().c_str(), suffix.c_str());
 
        int port_number = find_port_hole (buf1);
        snprintf (buf2, name_size+1, "%s %d", buf1, port_number);
@@ -1342,9 +1342,9 @@ IO::setup_bundle ()
        _bundle->remove_channels ();
 
        if (_direction == Input) {
-               snprintf(buf, sizeof (buf), _("%s in"), _name.c_str());
+               snprintf(buf, sizeof (buf), _("%s in"), _name.get().c_str());
        } else {
-               snprintf(buf, sizeof (buf), _("%s out"), _name.c_str());
+               snprintf(buf, sizeof (buf), _("%s out"), _name.get().c_str());
        }
         _bundle->set_name (buf);
        uint32_t const ni = _ports.num_ports();
index 91247d5082dd62c6c993f524e4b2945817075813..d1b7e9c232103d6c63e7adcb90438ea9efc66142 100644 (file)
@@ -170,7 +170,7 @@ IOProcessor::set_state (const XMLNode& node, int version)
                for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
                        const XMLProperty* prop;
                        if ((prop = (*niter)->property ("name")) != 0) {
-                               if (prop->value() == _name) {
+                               if (_name == prop->value()) {
                                        if ((prop = (*niter)->property ("direction")) != 0) {
                                                if (prop->value() == instr) {
                                                        io_node = (*niter);
@@ -200,7 +200,7 @@ IOProcessor::set_state (const XMLNode& node, int version)
                        if ((*niter)->name() == "IO") {
                                const XMLProperty* prop;
                                if ((prop = (*niter)->property ("name")) != 0) {
-                                       if (prop->value() == _name) {
+                                       if (_name == prop->value()) {
                                                if ((prop = (*niter)->property ("direction")) != 0) {
                                                        if (prop->value() == outstr) {
                                                                io_node = (*niter);
index 18d3bc5ce30681fe5d7df762a970b7247f3d2601..790891a72d1e5cef2afba778e0be13d9e5241352 100644 (file)
@@ -1388,7 +1388,7 @@ int
 MidiDiskstream::rename_write_sources ()
 {
        if (_write_source != 0) {
-               _write_source->set_source_name (_name, destructive());
+               _write_source->set_source_name (_name.get(), destructive());
                /* XXX what to do if this fails ? */
        }
        return 0;
index 7bb995337f64bbf7225773e28bd1350b9c8a144f..fb7a7e082fbd025a69107ed52bfbae23beb182a0 100644 (file)
@@ -51,7 +51,7 @@ using namespace PBD;
 MidiRegion::MidiRegion (boost::shared_ptr<MidiSource> src, nframes_t start, nframes_t length)
        : Region (src, start, length, PBD::basename_nosuffix(src->name()), DataType::MIDI, 0,  Region::Flag(Region::DefaultFlags|Region::External))
 {
-       assert(_name.find("/") == string::npos);
+       assert(_name.get().find("/") == string::npos);
        midi_source(0)->Switched.connect_same_thread (*this, boost::bind (&MidiRegion::switch_source, this, _1));
 }
 
@@ -59,7 +59,7 @@ MidiRegion::MidiRegion (boost::shared_ptr<MidiSource> src, nframes_t start, nfra
 MidiRegion::MidiRegion (boost::shared_ptr<MidiSource> src, nframes_t start, nframes_t length, const string& name, layer_t layer, Flag flags)
        : Region (src, start, length, name, DataType::MIDI, layer, flags)
 {
-       assert(_name.find("/") == string::npos);
+       assert(_name.get().find("/") == string::npos);
        midi_source(0)->Switched.connect_same_thread (*this, boost::bind (&MidiRegion::switch_source, this, _1));
 }
 
@@ -67,7 +67,7 @@ MidiRegion::MidiRegion (boost::shared_ptr<MidiSource> src, nframes_t start, nfra
 MidiRegion::MidiRegion (const SourceList& srcs, nframes_t start, nframes_t length, const string& name, layer_t layer, Flag flags)
        : Region (srcs, start, length, name, DataType::MIDI, layer, flags)
 {
-       assert(_name.find("/") == string::npos);
+       assert(_name.get().find("/") == string::npos);
        midi_source(0)->Switched.connect_same_thread (*this, boost::bind (&MidiRegion::switch_source, this, _1));
 }
 
@@ -76,14 +76,14 @@ MidiRegion::MidiRegion (const SourceList& srcs, nframes_t start, nframes_t lengt
 MidiRegion::MidiRegion (boost::shared_ptr<const MidiRegion> other, nframes_t offset, nframes_t length, const string& name, layer_t layer, Flag flags)
        : Region (other, offset, length, name, layer, flags)
 {
-       assert(_name.find("/") == string::npos);
+       assert(_name.get().find("/") == string::npos);
        midi_source(0)->Switched.connect_same_thread (*this, boost::bind (&MidiRegion::switch_source, this, _1));
 }
 
 MidiRegion::MidiRegion (boost::shared_ptr<const MidiRegion> other)
        : Region (other)
 {
-       assert(_name.find("/") == string::npos);
+       assert(_name.get().find("/") == string::npos);
        midi_source(0)->Switched.connect_same_thread (*this, boost::bind (&MidiRegion::switch_source, this, _1));
 }
 
@@ -95,7 +95,7 @@ MidiRegion::MidiRegion (boost::shared_ptr<MidiSource> src, const XMLNode& node)
        }
 
        midi_source(0)->Switched.connect_same_thread (*this, boost::bind (&MidiRegion::switch_source, this, _1));
-       assert(_name.find("/") == string::npos);
+       assert(_name.get().find("/") == string::npos);
        assert(_type == DataType::MIDI);
 }
 
@@ -107,7 +107,7 @@ MidiRegion::MidiRegion (const SourceList& srcs, const XMLNode& node)
        }
 
        midi_source(0)->Switched.connect_same_thread (*this, boost::bind (&MidiRegion::switch_source, this, _1));
-       assert(_name.find("/") == string::npos);
+       assert(_name.get().find("/") == string::npos);
        assert(_type == DataType::MIDI);
 }
 
index 1e890170c46dc02aa8f3b6eebb0c34f112e3f21f..ce58d4f585a5319ab5402ce27a17f70f23ba8ef2 100644 (file)
@@ -230,7 +230,7 @@ MidiSource::session_saved()
 
        if (_model && _model->edited()) {
                string newname;
-               const string basename = PBD::basename_nosuffix(_name);
+               const string basename = PBD::basename_nosuffix(_name.get());
                string::size_type last_dash = basename.find_last_of("-");
                if (last_dash == string::npos || last_dash == basename.find_first_of("-")) {
                        newname = basename + "-1";
index 2fe0616973064941b233fbe13ed0984919aebe17..aab7431cc1962ad5517ebc79d7aae1d8e5c47a0a 100644 (file)
@@ -19,6 +19,7 @@
 #include "pbd/error.h"
 
 #include "pbd/enumwriter.h"
+#include "pbd/convert.h"
 #include "midi++/events.h"
 #include "evoral/midi_util.h"
 
index 52137f9af2ce413773eec977e5ada229eebb18ea..03d90bcf095b76723f3402ce8df4b0664b7c37e2 100644 (file)
@@ -60,29 +60,36 @@ void
 Region::register_states ()
 {
        _xml_node_name = X_("Region");
+       add_state (_flags);
        add_state (_start);
+       add_state (_length);
        add_state (_position);
+       add_state (_sync_position);
        add_state (_layer);
+       add_state (_ancestral_start);
+       add_state (_ancestral_length);
+       add_state (_stretch);
+       add_state (_shift);
 }
 
 /* derived-from-derived constructor (no sources in constructor) */
 Region::Region (Session& s, nframes_t start, nframes_t length, const string& name, DataType type, layer_t layer, Region::Flag flags)
        : SessionObject(s, name)
        , _type(type)
-       , _flags(Flag (flags|DoNotSendPropertyChanges))
+       , _flags (X_("flags"), FlagsChanged, Flag (flags|DoNotSendPropertyChanges))
        , _start (X_("start"), StartChanged, start)
-       , _length(length)
+       , _length (X_("length"), LengthChanged, length)
        , _position (X_("position"), PositionChanged, 0)
-       , _last_position(0)
+       , _last_position (0)
        , _positional_lock_style(AudioTime)
-       , _sync_position(_start)
+       , _sync_position (X_("sync-position"), SyncOffsetChanged, _start)
        , _layer (X_("layer"), LayerChanged, layer)
        , _first_edit(EditChangesNothing)
        , _frozen(0)
-       , _ancestral_start (0)
-       , _ancestral_length (0)
-       , _stretch(1.0)
-       , _shift(1.0)
+       , _ancestral_start (X_("ancestral-start"), Change (0), 0)
+       , _ancestral_length (X_("ancestral-length"), Change (0), 0)
+       , _stretch (X_("stretch"), Change (0), 1.0)
+       , _shift (X_("shift"), Change (0), 1.0)
        , _read_data_count(0)
        , _pending_changed(Change (0))
        , _last_layer_op(0)
@@ -97,20 +104,20 @@ Region::Region (Session& s, nframes_t start, nframes_t length, const string& nam
 Region::Region (boost::shared_ptr<Source> src, nframes_t start, nframes_t length, const string& name, DataType type, layer_t layer, Region::Flag flags)
        : SessionObject(src->session(), name)
        , _type(type)
-       , _flags(Flag (flags|DoNotSendPropertyChanges))
+       , _flags (X_("flags"), FlagsChanged, Flag (flags|DoNotSendPropertyChanges))
        , _start (X_("start"), StartChanged, start)
-       , _length(length)
+       , _length (X_("length"), LengthChanged, length)
        , _position (X_("position"), PositionChanged, 0)
        , _last_position(0)
        , _positional_lock_style(AudioTime)
-       , _sync_position(_start)
+       , _sync_position (X_("sync-position"), SyncOffsetChanged, _start)
        , _layer (X_("layer"), LayerChanged, layer)
        , _first_edit(EditChangesNothing)
        , _frozen(0)
-       , _ancestral_start (0)
-       , _ancestral_length (0)
-       , _stretch (1.0)
-       , _shift (1.0)
+       , _ancestral_start (X_("ancestral-start"), Change (0), 0)
+       , _ancestral_length (X_("ancestral-length"), Change (0), 0)
+       , _stretch (X_("stretch"), Change (0), 1.0)
+       , _shift (X_("shift"), Change (0), 1.0)
        , _valid_transients(false)
        , _read_data_count(0)
        , _pending_changed(Change (0))
@@ -132,20 +139,20 @@ Region::Region (boost::shared_ptr<Source> src, nframes_t start, nframes_t length
 Region::Region (const SourceList& srcs, nframes_t start, nframes_t length, const string& name, DataType type, layer_t layer, Region::Flag flags)
        : SessionObject(srcs.front()->session(), name)
        , _type(type)
-       , _flags(Flag (flags|DoNotSendPropertyChanges))
+       , _flags (X_("flags"), FlagsChanged, Flag (flags|DoNotSendPropertyChanges))
        , _start (X_("start"), StartChanged, start)
-       , _length(length)
+       , _length (X_("length"), LengthChanged, length)
        , _position (X_("position"), PositionChanged, 0)
        , _last_position(0)
        , _positional_lock_style(AudioTime)
-       , _sync_position(_start)
+       , _sync_position (X_("sync-position"), SyncOffsetChanged, _start)
        , _layer (X_("layer"), LayerChanged, layer)
        , _first_edit(EditChangesNothing)
        , _frozen(0)
-       , _ancestral_start (0)
-       , _ancestral_length (0)
-       , _stretch(1.0)
-       , _shift(1.0)
+       , _ancestral_start (X_("ancestral-start"), Change (0), 0)
+       , _ancestral_length (X_("ancestral-length"), Change (0), 0)
+       , _stretch (X_("stretch"), Change (0), 1.0)
+       , _shift (X_("shift"), Change (0), 1.0)
        , _read_data_count(0)
        , _pending_changed(Change (0))
        , _last_layer_op(0)
@@ -161,9 +168,16 @@ 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())
+       , _flags (X_("flags"), FlagsChanged, Flag (flags | DoNotSendPropertyChanges))
        , _start (X_("start"), StartChanged, 0)
+       , _length (X_("length"), LengthChanged, 0)
        , _position (X_("position"), PositionChanged, 0)
+       , _sync_position (X_("sync-position"), SyncOffsetChanged, 0)
        , _layer (X_("layer"), LayerChanged, 0)
+       , _ancestral_start (X_("ancestral-start"), Change (0), 0)
+       , _ancestral_length (X_("ancestral-length"), Change (0), 0)
+       , _stretch (X_("stretch"), Change (0), 1.0)
+       , _shift (X_("shift"), Change (0), 1.0)
        , _pending_explicit_relayer (false)
 
 {
@@ -172,8 +186,6 @@ Region::Region (boost::shared_ptr<const Region> other, nframes_t offset, nframes
        _start = other->_start + offset;
        copy_stuff (other, offset, length, name, layer, flags);
 
-       _flags = Flag (_flags | DoNotSendPropertyChanges);
-
        /* if the other region had a distinct sync point
           set, then continue to use it as best we can.
           otherwise, reset sync point back to start.
@@ -206,9 +218,16 @@ 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())
+       , _flags (X_("flags"), FlagsChanged, Flag (flags|DoNotSendPropertyChanges))
        , _start (X_("start"), StartChanged, 0)
+       , _length (X_("length"), LengthChanged, 0)
        , _position (X_("position"), PositionChanged, 0)
+       , _sync_position (X_("sync-position"), SyncOffsetChanged, 0)
        , _layer (X_("layer"), LayerChanged, 0)
+       , _ancestral_start (X_("ancestral-start"), Change (0), 0)
+       , _ancestral_length (X_("ancestral-length"), Change (0), 0)
+       , _stretch (X_("stretch"), Change (0), 1.0)
+       , _shift (X_("shift"), Change (0), 1.0)
        , _pending_explicit_relayer (false)
 {
        register_states ();
@@ -266,7 +285,7 @@ Region::Region (boost::shared_ptr<const Region> other, nframes_t length, const s
 Region::Region (boost::shared_ptr<const Region> other)
        : SessionObject(other->session(), other->name())
        , _type(other->data_type())
-       , _flags(Flag(other->_flags & ~(Locked|PositionLocked)))
+       , _flags (other->_flags)
        , _start(other->_start)
        , _length(other->_length)
        , _position(other->_position)
@@ -288,6 +307,7 @@ Region::Region (boost::shared_ptr<const Region> other)
 {
        register_states ();
 
+       _flags = Flag (_flags & ~ (Locked | PositionLocked));
        _flags = Flag (_flags | DoNotSendPropertyChanges);
 
        other->_first_edit = EditChangesName;
@@ -305,18 +325,20 @@ Region::Region (boost::shared_ptr<const Region> other)
 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)
+       , _flags (X_("flags"), FlagsChanged, Flag (DoNotSendPropertyChanges))
        , _start (X_("start"), StartChanged, 0)
-       , _length(0)
+       , _length (X_("length"), LengthChanged, 0)
        , _position (X_("position"), PositionChanged, 0)
        , _last_position(0)
        , _positional_lock_style(AudioTime)
-       , _sync_position(_start)
+       , _sync_position (X_("sync-position"), SyncOffsetChanged, _start)
        , _layer (X_("layer"), LayerChanged, 0)
        , _first_edit(EditChangesNothing)
        , _frozen(0)
-       , _stretch(1.0)
-       , _shift(1.0)
+       , _ancestral_start (X_("ancestral-start"), Change (0), 0)
+       , _ancestral_length (X_("ancestral-length"), Change (0), 0)
+       , _stretch (X_("stretch"), Change (0), 1.0)
+       , _shift (X_("shift"), Change (0), 1.0)
        , _read_data_count(0)
        , _pending_changed(Change(0))
        , _last_layer_op(0)
@@ -337,18 +359,20 @@ Region::Region (const SourceList& srcs, const XMLNode& node)
 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)
+       , _flags (X_("flags"), FlagsChanged, Flag (DoNotSendPropertyChanges))
        , _start (X_("start"), StartChanged, 0)
-       , _length(0)
+       , _length (X_("length"), LengthChanged, 0)
        , _position (X_("position"), PositionChanged, 0)
        , _last_position(0)
        , _positional_lock_style(AudioTime)
-       , _sync_position(_start)
+       , _sync_position (X_("sync-position"), SyncOffsetChanged, _start)
        , _layer (X_("layer"), LayerChanged, 0)
        , _first_edit(EditChangesNothing)
        , _frozen(0)
-       , _stretch(1.0)
-       , _shift(1.0)
+       , _ancestral_start (X_("ancestral-start"), Change (0), 0)
+       , _ancestral_length (X_("ancestral-length"), Change (0), 0)
+       , _stretch (X_("stretch"), Change (0), 1.0)
+       , _shift (X_("shift"), Change (0), 1.0)
        , _read_data_count(0)
        , _pending_changed(Change(0))
        , _last_layer_op(0)
@@ -1096,18 +1120,7 @@ Region::state (bool /*full_state*/)
 
        _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", _length);
-       node->add_property ("length", buf);
-       snprintf (buf, sizeof (buf), "%" PRIi64, _ancestral_start);
-       node->add_property ("ancestral-start", buf);
-       snprintf (buf, sizeof (buf), "%" PRIi64, _ancestral_length);
-       node->add_property ("ancestral-length", buf);
-       snprintf (buf, sizeof (buf), "%.12g", _stretch);
-       node->add_property ("stretch", buf);
-       snprintf (buf, sizeof (buf), "%.12g", _shift);
-       node->add_property ("shift", buf);
 
        switch (_first_edit) {
        case EditChangesNothing:
@@ -1128,9 +1141,6 @@ Region::state (bool /*full_state*/)
 
        /* note: flags are stored by derived classes */
 
-       snprintf (buf, sizeof (buf), "%" PRIu32, _sync_position);
-       node->add_property ("sync-position", buf);
-
        if (_positional_lock_style != AudioTime) {
                node->add_property ("positional-lock-style", enum_2_string (_positional_lock_style));
                stringstream str;
@@ -1152,41 +1162,17 @@ Region::set_live_state (const XMLNode& node, int /*version*/, Change& what_chang
 {
        const XMLNodeList& nlist = node.children();
        const XMLProperty *prop;
-       nframes_t val;
 
        /* this is responsible for setting those aspects of Region state
           that are mutable after construction.
        */
 
-       if ((prop = node.property ("name"))) {
-               _name = prop->value();
-       }
-
        if ((prop = node.property ("type")) == 0) {
                _type = DataType::AUDIO;
        } else {
                _type = DataType(prop->value());
        }
 
-       if ((prop = node.property ("length")) != 0) {
-               sscanf (prop->value().c_str(), "%" PRIu32, &val);
-               if (val != _length) {
-                       what_changed = Change (what_changed|LengthChanged);
-                       cerr << _name << " length changed\n";
-                       _last_length = _length;
-                       _length = val;
-               }
-       }
-
-       if ((prop = node.property ("sync-position")) != 0) {
-               sscanf (prop->value().c_str(), "%" PRIu32, &val);
-               if (val != _sync_position) {
-                       what_changed = Change (what_changed|SyncOffsetChanged);
-                       cerr << _name << " sync changed\n";
-                       _sync_position = val;
-               }
-       }
-
        if ((prop = node.property ("positional-lock-style")) != 0) {
                _positional_lock_style = PositionLockStyle (string_2_enum (prop->value(), _positional_lock_style));
 
@@ -1208,47 +1194,17 @@ Region::set_live_state (const XMLNode& node, int /*version*/, Change& what_chang
 
        /* XXX FIRST EDIT !!! */
 
-       /* these 3 properties never change as a result of any editing */
-
-       if ((prop = node.property ("ancestral-start")) != 0) {
-               _ancestral_start = strtoll (prop->value().c_str(), 0, 10);
-       } else {
-               _ancestral_start = _start;
-       }
-
-       if ((prop = node.property ("ancestral-length")) != 0) {
-               _ancestral_length = strtoll (prop->value().c_str(), 0, 10);
-       } else {
-               _ancestral_length = _length;
-       }
-
-       if ((prop = node.property ("stretch")) != 0) {
-               _stretch = atof (prop->value());
-
-               /* fix problem with old sessions corrupted by an impossible
-                  value for _stretch
-               */
-               if (_stretch == 0.0) {
-                       _stretch = 1.0;
-               }
-       } else {
+       /* fix problems with old sessions corrupted by impossible
+          values for _stretch or _shift
+       */
+       if (_stretch == 0.0) {
                _stretch = 1.0;
        }
-
-       if ((prop = node.property ("shift")) != 0) {
-               _shift = atof (prop->value());
-
-               /* fix problem with old sessions corrupted by an impossible
-                  value for _shift
-               */
-               if (_shift == 0.0) {
-                       _shift = 1.0;
-               }
-       } else {
+       
+       if (_shift == 0.0) {
                _shift = 1.0;
        }
 
-
        /* note: derived classes set flags */
 
        for (XMLNodeConstIterator niter = nlist.begin(); niter != nlist.end(); ++niter) {
index eb0707044aa1191ddd0cc4b98cb97d6f01d8875f..02005fc269e4ab67aa572108af0e10cfc3302ba1 100644 (file)
@@ -26,6 +26,7 @@
 #include "pbd/enumwriter.h"
 #include "pbd/memento_command.h"
 #include "pbd/stacktrace.h"
+#include "pbd/convert.h"
 
 #include "evoral/Curve.hpp"
 
index c7270e6ce98239152414e7eef4db7f0ff1ff84e3..8034f7403369abac130854b48f7ab0cf53c699ba 100644 (file)
@@ -41,6 +41,7 @@
 #include "pbd/basename.h"
 #include "pbd/stacktrace.h"
 #include "pbd/file_utils.h"
+#include "pbd/convert.h"
 
 #include "ardour/amp.h"
 #include "ardour/analyser.h"
index 45e35c91fd75a041d8e64facd5ed2a966fd02787..93cf6b3791b82036355819c4b84f870e2d45bca4 100644 (file)
@@ -64,6 +64,7 @@
 #include "pbd/pthread_utils.h"
 #include "pbd/search_path.h"
 #include "pbd/stacktrace.h"
+#include "pbd/convert.h"
 
 #include "ardour/amp.h"
 #include "ardour/audio_diskstream.h"
index d9d428a4cb8ae098e6827d67e635904b037f6e73..8f454d31ce973313929cd8f2d5f7f9c761e2684b 100644 (file)
@@ -306,7 +306,7 @@ SndFileSource::read_unlocked (Sample *dst, sframes_t start, nframes_t cnt) const
                if (sf_seek (sf, (sf_count_t) start, SEEK_SET|SFM_READ) != (sf_count_t) start) {
                        char errbuf[256];
                        sf_error_str (0, errbuf, sizeof (errbuf) - 1);
-                       error << string_compose(_("SndFileSource: could not seek to frame %1 within %2 (%3)"), start, _name.substr (1), errbuf) << endmsg;
+                       error << string_compose(_("SndFileSource: could not seek to frame %1 within %2 (%3)"), start, _name.get().substr (1), errbuf) << endmsg;
                        return 0;
                }
 
@@ -316,7 +316,7 @@ SndFileSource::read_unlocked (Sample *dst, sframes_t start, nframes_t cnt) const
                        if (ret != file_cnt) {
                                char errbuf[256];
                                sf_error_str (0, errbuf, sizeof (errbuf) - 1);
-                               cerr << string_compose(_("SndFileSource: @ %1 could not read %2 within %3 (%4) (len = %5)"), start, file_cnt, _name.substr (1), errbuf, _length) << endl;
+                               cerr << string_compose(_("SndFileSource: @ %1 could not read %2 within %3 (%4) (len = %5)"), start, file_cnt, _name.get().substr (1), errbuf, _length) << endl;
                        }
                        return ret;
                }
index af1ac9d162b5e722ca32dcf74af6fdb328c4a130..35516fab53d36b4b882c34f715a8c6c47065e000 100644 (file)
@@ -7,5 +7,6 @@
 #define _(Text) dgettext (PACKAGE, Text)
 #define N_(Text) gettext_noop (Text)
 #define X_(Text) (Text)
+#define I18N(Array) PBD::internationalize (PACKAGE, Array)
 
 #endif // __i18n_h__
index 80d7aa796acda33063f33f0fc1e6672460a9e8bb..5d3c98439c6c6095e6a2bd72a4a895a099eb0980 100644 (file)
@@ -24,6 +24,7 @@
 #include <cassert>
 #include "pbd/id.h"
 #include "pbd/xml++.h"
+#include "pbd/enumwriter.h"
 
 class XMLNode;
 
@@ -51,14 +52,6 @@ public:
 
        }
 
-       StateBase (StateBase const & s)
-               : _have_old (s._have_old)
-               , _xml_property_name (s._xml_property_name)
-               , _change (s._change)
-       {
-
-       }
-
        /** Forget about any old value for this state */
        void clear_history () {
                _have_old = false;
@@ -74,26 +67,19 @@ protected:
        Change _change;
 };
 
-/** Class to represent a single piece of state in a Stateful object */
+/** Parent class for classes which represent a single piece of state in a Stateful object */
 template <class T>
-class State : public StateBase
+class StateTemplate : public StateBase
 {
 public:
-       State (std::string const & p, Change c, T const & v)
+       StateTemplate (std::string const & p, Change c, T const & v)
                : StateBase (p, c)
                , _current (v)
        {
 
        }
 
-       State (State<T> const & s)
-               : StateBase (s)
-       {
-               _current = s._current;
-               _old = s._old;
-       }               
-
-       State<T> & operator= (State<T> const & s) {
+       StateTemplate<T> & operator= (StateTemplate<T> const & s) {
                /* XXX: isn't there a nicer place to do this? */
                _have_old = s._have_old;
                _xml_property_name = s._xml_property_name;
@@ -114,10 +100,18 @@ public:
                return _current;
        }
 
-       operator T () const {
+       bool operator== (std::string const & o) const {
+               return o == to_string (_current);
+       }
+
+       bool operator!= (std::string const & o) const {
+               return o != to_string (_current);
+       }
+
+       operator T const & () const {
                return _current;
        }
-       
+
        T const & get () const {
                return _current;
        }
@@ -137,9 +131,7 @@ public:
                XMLProperty const * p = node.property (_xml_property_name.c_str());
 
                if (p) {
-                       std::stringstream s (p->value ());
-                       T v;
-                       s >> v;
+                       T const v = from_string (p->value ());
 
                        if (v == _current) {
                                return Change (0);
@@ -156,21 +148,83 @@ public:
                node.add_property (_xml_property_name.c_str(), to_string (_current));
        }
 
-private:
+protected:
        void set (T const & v) {
                _old = _current;
                _have_old = true;
                _current = v;
        }
 
+       virtual std::string to_string (T const & v) const = 0;
+       virtual T from_string (std::string const & s) const = 0;
+               
+       T _current;
+       T _old;
+};
+
+template<class T>      
+std::ostream& operator<< (std::ostream& os, StateTemplate<T> const & s)
+{
+       os << s.get();
+       return os;
+}
+
+/** Representation of a single piece of state in a Stateful; for use
+ *  with types that can be written to / read from stringstreams.
+ */
+template <class T>
+class State : public StateTemplate<T>
+{
+public:
+       State (std::string const & p, Change c, T const & v)
+               : StateTemplate<T> (p, c, v)
+       {
+
+       }
+       
+       T & operator= (T const & v) {
+               this->set (v);
+               return this->_current;
+       }
+       
+private:       
        std::string to_string (T const & v) const {
                std::stringstream s;
                s << v;
                return s.str ();
        }
-               
-       T _current;
-       T _old;
+
+       T from_string (std::string const & s) const {
+               std::stringstream t (s);
+               T v;
+               t >> v;
+               return v;
+       }
+};
+
+template <class T>
+class EnumState : public StateTemplate<T>
+{
+public:
+       EnumState (std::string const & p, Change c, T const & v)
+               : StateTemplate<T> (p, c, v)
+       {
+
+       }
+       
+       T & operator= (T const & v) {
+               this->set (v);
+               return this->_current;
+       }
+
+private:
+       std::string to_string (T const & v) const {
+               return enum_2_string (v);
+       }
+
+       T from_string (std::string const & v) const {
+               return T (string_2_enum (v, this->_current));
+       }
 };
 
 /** Base class for objects with saveable and undoable state */