From 3a27410dcbaaca10480ffc14770b41c11e9ca1da Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 11 Feb 2010 17:08:34 +0000 Subject: More tinkering with State<>. Use some StateDiffCommands instead of MementoCommand. More use of State<> for Region members. git-svn-id: svn://localhost/ardour2/branches/3.0@6675 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/ardour.h | 1 + libs/ardour/ardour/region.h | 14 +-- libs/ardour/ardour/session_object.h | 14 ++- libs/ardour/audio_diskstream.cc | 6 +- libs/ardour/audio_region_importer.cc | 2 +- libs/ardour/audioregion.cc | 3 - libs/ardour/crossfade.cc | 4 +- libs/ardour/diskstream.cc | 2 +- libs/ardour/globals.cc | 1 + libs/ardour/io.cc | 10 +- libs/ardour/io_processor.cc | 4 +- libs/ardour/midi_diskstream.cc | 2 +- libs/ardour/midi_region.cc | 14 +-- libs/ardour/midi_source.cc | 2 +- libs/ardour/midi_track.cc | 1 + libs/ardour/region.cc | 174 +++++++++++++---------------------- libs/ardour/route.cc | 1 + libs/ardour/session.cc | 1 + libs/ardour/session_state.cc | 1 + libs/ardour/sndfilesource.cc | 4 +- libs/pbd/i18n.h | 1 + libs/pbd/pbd/stateful.h | 110 ++++++++++++++++------ 22 files changed, 195 insertions(+), 177 deletions(-) (limited to 'libs') diff --git a/libs/ardour/ardour/ardour.h b/libs/ardour/ardour/ardour.h index a7b3bcafd0..403cf21007 100644 --- a/libs/ardour/ardour/ardour.h +++ b/libs/ardour/ardour/ardour.h @@ -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 */ diff --git a/libs/ardour/ardour/region.h b/libs/ardour/ardour/region.h index 414a1723f9..9c78285a09 100644 --- a/libs/ardour/ardour/region.h +++ b/libs/ardour/ardour/region.h @@ -314,21 +314,21 @@ class Region virtual void recompute_at_end () = 0; DataType _type; - Flag _flags; + PBD::EnumState _flags; PBD::State _start; - nframes_t _length; + PBD::State _length; nframes_t _last_length; PBD::State _position; nframes_t _last_position; PositionLockStyle _positional_lock_style; - nframes_t _sync_position; + PBD::State _sync_position; PBD::State _layer; mutable RegionEditState _first_edit; int _frozen; - nframes64_t _ancestral_start; - nframes64_t _ancestral_length; - float _stretch; - float _shift; + PBD::State _ancestral_start; + PBD::State _ancestral_length; + PBD::State _stretch; + PBD::State _shift; BBT_Time _bbt_time; AnalysisFeatureList _transients; bool _valid_transients; diff --git a/libs/ardour/ardour/session_object.h b/libs/ardour/ardour/session_object.h index 47caab5475..cf9ccbb3a7 100644 --- a/libs/ardour/ardour/session_object.h +++ b/libs/ardour/ardour/session_object.h @@ -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 NameChanged; protected: - std::string _name; + PBD::State _name; }; } // namespace ARDOUR diff --git a/libs/ardour/audio_diskstream.cc b/libs/ardour/audio_diskstream.cc index db1a343d17..ef209fad3a 100644 --- a/libs/ardour/audio_diskstream.cc +++ b/libs/ardour/audio_diskstream.cc @@ -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()); } } diff --git a/libs/ardour/audio_region_importer.cc b/libs/ardour/audio_region_importer.cc index c9203435d5..289af0b4d8 100644 --- a/libs/ardour/audio_region_importer.cc +++ b/libs/ardour/audio_region_importer.cc @@ -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; diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc index 7485ac6913..c96f7119b8 100644 --- a/libs/ardour/audioregion.cc +++ b/libs/ardour/audioregion.cc @@ -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); diff --git a/libs/ardour/crossfade.cc b/libs/ardour/crossfade.cc index fd59982f62..a79dae5f07 100644 --- a/libs/ardour/crossfade.cc +++ b/libs/ardour/crossfade.cc @@ -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); diff --git a/libs/ardour/diskstream.cc b/libs/ardour/diskstream.cc index a4f8c22e28..264dd3e79f 100644 --- a/libs/ardour/diskstream.cc +++ b/libs/ardour/diskstream.cc @@ -396,7 +396,7 @@ Diskstream::playlist_deleted (boost::weak_ptr wpl) bool Diskstream::set_name (const string& str) { - if (str != _name) { + if (_name != str) { assert(playlist()); playlist()->set_name (str); diff --git a/libs/ardour/globals.cc b/libs/ardour/globals.cc index 7536ee5932..3f3c35f739 100644 --- a/libs/ardour/globals.cc +++ b/libs/ardour/globals.cc @@ -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; diff --git a/libs/ardour/io.cc b/libs/ardour/io.cc index c9d3f6be08..34f624f2d2 100644 --- a/libs/ardour/io.cc +++ b/libs/ardour/io.cc @@ -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(); diff --git a/libs/ardour/io_processor.cc b/libs/ardour/io_processor.cc index 91247d5082..d1b7e9c232 100644 --- a/libs/ardour/io_processor.cc +++ b/libs/ardour/io_processor.cc @@ -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); diff --git a/libs/ardour/midi_diskstream.cc b/libs/ardour/midi_diskstream.cc index 18d3bc5ce3..790891a72d 100644 --- a/libs/ardour/midi_diskstream.cc +++ b/libs/ardour/midi_diskstream.cc @@ -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; diff --git a/libs/ardour/midi_region.cc b/libs/ardour/midi_region.cc index 7bb995337f..fb7a7e082f 100644 --- a/libs/ardour/midi_region.cc +++ b/libs/ardour/midi_region.cc @@ -51,7 +51,7 @@ using namespace PBD; MidiRegion::MidiRegion (boost::shared_ptr 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 src, nframes_t start, nfra MidiRegion::MidiRegion (boost::shared_ptr 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 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 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 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 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); } diff --git a/libs/ardour/midi_source.cc b/libs/ardour/midi_source.cc index 1e890170c4..ce58d4f585 100644 --- a/libs/ardour/midi_source.cc +++ b/libs/ardour/midi_source.cc @@ -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"; diff --git a/libs/ardour/midi_track.cc b/libs/ardour/midi_track.cc index 2fe0616973..aab7431cc1 100644 --- a/libs/ardour/midi_track.cc +++ b/libs/ardour/midi_track.cc @@ -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" diff --git a/libs/ardour/region.cc b/libs/ardour/region.cc index 52137f9af2..03d90bcf09 100644 --- a/libs/ardour/region.cc +++ b/libs/ardour/region.cc @@ -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 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 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 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 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 other, nframes_t offset, nframes Region::Region (boost::shared_ptr 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 other, nframes_t length, const s Region::Region (boost::shared_ptr 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 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 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 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) { diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index eb0707044a..02005fc269 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -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" diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index c7270e6ce9..8034f74033 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -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" diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 45e35c91fd..93cf6b3791 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -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" diff --git a/libs/ardour/sndfilesource.cc b/libs/ardour/sndfilesource.cc index d9d428a4cb..8f454d31ce 100644 --- a/libs/ardour/sndfilesource.cc +++ b/libs/ardour/sndfilesource.cc @@ -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; } diff --git a/libs/pbd/i18n.h b/libs/pbd/i18n.h index af1ac9d162..35516fab53 100644 --- a/libs/pbd/i18n.h +++ b/libs/pbd/i18n.h @@ -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__ diff --git a/libs/pbd/pbd/stateful.h b/libs/pbd/pbd/stateful.h index 80d7aa796a..5d3c98439c 100644 --- a/libs/pbd/pbd/stateful.h +++ b/libs/pbd/pbd/stateful.h @@ -24,6 +24,7 @@ #include #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 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 const & s) - : StateBase (s) - { - _current = s._current; - _old = s._old; - } - - State & operator= (State const & s) { + StateTemplate & operator= (StateTemplate 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 +std::ostream& operator<< (std::ostream& os, StateTemplate 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 State : public StateTemplate +{ +public: + State (std::string const & p, Change c, T const & v) + : StateTemplate (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 EnumState : public StateTemplate +{ +public: + EnumState (std::string const & p, Change c, T const & v) + : StateTemplate (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 */ -- cgit v1.2.3