From 4085309cdb07f011756a9ab90047037ef9ad8f20 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 18 Oct 2011 13:18:47 +0000 Subject: [PATCH] make Stateful::_id private and provide appropriate methods to set it, and use them throughout ardour git-svn-id: svn://localhost/ardour2/branches/3.0@10222 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/ardour_ui.cc | 6 ------ gtk2_ardour/ardour_ui.h | 2 -- gtk2_ardour/editor.cc | 8 +++----- gtk2_ardour/shuttle_control.cc | 6 ------ gtk2_ardour/shuttle_control.h | 2 -- gtk2_ardour/time_axis_view_item.cc | 3 ++- libs/ardour/audio_diskstream.cc | 10 +++++----- libs/ardour/automation_list.cc | 5 ++--- libs/ardour/crossfade.cc | 4 +--- libs/ardour/diskstream.cc | 8 ++------ libs/ardour/io.cc | 8 ++------ libs/ardour/location.cc | 4 +--- libs/ardour/lxvst_plugin.cc | 2 -- libs/ardour/midi_diskstream.cc | 4 ++-- libs/ardour/playlist.cc | 4 ++-- libs/ardour/playlist_source.cc | 8 ++++++-- libs/ardour/plugin_insert.cc | 7 +------ libs/ardour/processor.cc | 9 ++------- libs/ardour/region.cc | 6 ++---- libs/ardour/route.cc | 8 ++------ libs/ardour/route_group.cc | 5 +---- libs/ardour/source.cc | 8 +++----- libs/pbd/controllable.cc | 6 ++---- libs/pbd/id.cc | 10 ++++++++-- libs/pbd/pbd/id.h | 2 ++ libs/pbd/pbd/stateful.h | 9 +++++++-- libs/pbd/stateful.cc | 24 ++++++++++++++++++++++++ 27 files changed, 82 insertions(+), 96 deletions(-) diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 5161a6626d..a1bbce29ee 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -3701,12 +3701,6 @@ ARDOUR_UI::TransportControllable::get_value (void) const return val; } -void -ARDOUR_UI::TransportControllable::set_id (const string& str) -{ - _id = str; -} - void ARDOUR_UI::setup_profile () { diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index 08e0d42ab0..5c2a99290d 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -401,8 +401,6 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr void set_value (double); double get_value (void) const; - void set_id (const std::string&); - ARDOUR_UI& ui; ToggleType type; }; diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 78c6911116..08099c2972 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -1244,7 +1244,7 @@ Editor::set_session (Session *t) } /* register for undo history */ - _session->register_with_memento_command_factory(_id, this); + _session->register_with_memento_command_factory(id(), this); ActionManager::ui_manager->signal_pre_activate().connect (sigc::mem_fun (*this, &Editor::action_pre_activated)); @@ -2160,9 +2160,7 @@ Editor::set_state (const XMLNode& node, int /*version*/) int x, y; Gdk::Geometry g; - if ((prop = node.property ("id")) != 0) { - _id = prop->value (); - } + set_id (node); g.base_width = default_width; g.base_height = default_height; @@ -2374,7 +2372,7 @@ Editor::get_state () XMLNode* node = new XMLNode ("Editor"); char buf[32]; - _id.print (buf, sizeof (buf)); + id().print (buf, sizeof (buf)); node->add_property ("id", buf); if (is_realized()) { diff --git a/gtk2_ardour/shuttle_control.cc b/gtk2_ardour/shuttle_control.cc index a496ddc0b2..2fb2a3357e 100644 --- a/gtk2_ardour/shuttle_control.cc +++ b/gtk2_ardour/shuttle_control.cc @@ -611,12 +611,6 @@ ShuttleControl::ShuttleControllable::ShuttleControllable (ShuttleControl& s) { } -void -ShuttleControl::ShuttleControllable::set_id (const std::string& str) -{ - _id = str; -} - void ShuttleControl::ShuttleControllable::set_value (double val) { diff --git a/gtk2_ardour/shuttle_control.h b/gtk2_ardour/shuttle_control.h index 03ec005958..ab58969743 100644 --- a/gtk2_ardour/shuttle_control.h +++ b/gtk2_ardour/shuttle_control.h @@ -49,8 +49,6 @@ class ShuttleControl : public Gtk::DrawingArea, public ARDOUR::SessionHandlePtr void set_value (double); double get_value (void) const; - void set_id (const std::string&); - ShuttleControl& sc; }; diff --git a/gtk2_ardour/time_axis_view_item.cc b/gtk2_ardour/time_axis_view_item.cc index d9b0bfa2cf..9df586bf7f 100644 --- a/gtk2_ardour/time_axis_view_item.cc +++ b/gtk2_ardour/time_axis_view_item.cc @@ -109,7 +109,8 @@ TimeAxisViewItem::TimeAxisViewItem( } TimeAxisViewItem::TimeAxisViewItem (const TimeAxisViewItem& other) - : Selectable (other) + : trackable (other) + , Selectable (other) , PBD::ScopedConnectionList() , trackview (other.trackview) , _recregion (other._recregion) diff --git a/libs/ardour/audio_diskstream.cc b/libs/ardour/audio_diskstream.cc index 243ccdb9d1..436506c857 100644 --- a/libs/ardour/audio_diskstream.cc +++ b/libs/ardour/audio_diskstream.cc @@ -773,7 +773,7 @@ AudioDiskstream::overwrite_existing_buffers () if (read ((*chan)->playback_buf->buffer() + overwrite_offset, mixdown_buffer, gain_buffer, start, to_read, *chan, n, reversed)) { error << string_compose(_("AudioDiskstream %1: when refilling, cannot read %2 from playlist at frame %3"), - _id, size, playback_sample) << endmsg; + id(), size, playback_sample) << endmsg; goto out; } @@ -784,7 +784,7 @@ AudioDiskstream::overwrite_existing_buffers () if (read ((*chan)->playback_buf->buffer(), mixdown_buffer, gain_buffer, start, cnt, *chan, n, reversed)) { error << string_compose(_("AudioDiskstream %1: when refilling, cannot read %2 from playlist at frame %3"), - _id, size, playback_sample) << endmsg; + id(), size, playback_sample) << endmsg; goto out; } } @@ -933,7 +933,7 @@ AudioDiskstream::read (Sample* buf, Sample* mixdown_buffer, float* gain_buffer, this_read = min(cnt,this_read); if (audio_playlist()->read (buf+offset, mixdown_buffer, gain_buffer, start, this_read, channel) != this_read) { - error << string_compose(_("AudioDiskstream %1: cannot read %2 from playlist at frame %3"), _id, this_read, + error << string_compose(_("AudioDiskstream %1: cannot read %2 from playlist at frame %3"), id(), this_read, start) << endmsg; return -1; } @@ -1302,7 +1302,7 @@ AudioDiskstream::do_flush (RunContext /*context*/, bool force_flush) } if ((!(*chan)->write_source) || (*chan)->write_source->write (vector.buf[0], to_write) != to_write) { - error << string_compose(_("AudioDiskstream %1: cannot write to disk"), _id) << endmsg; + error << string_compose(_("AudioDiskstream %1: cannot write to disk"), id()) << endmsg; return -1; } @@ -1319,7 +1319,7 @@ AudioDiskstream::do_flush (RunContext /*context*/, bool force_flush) to_write = min ((framecnt_t)(disk_io_chunk_frames - to_write), (framecnt_t) vector.len[1]); if ((*chan)->write_source->write (vector.buf[1], to_write) != to_write) { - error << string_compose(_("AudioDiskstream %1: cannot write to disk"), _id) << endmsg; + error << string_compose(_("AudioDiskstream %1: cannot write to disk"), id()) << endmsg; return -1; } diff --git a/libs/ardour/automation_list.cc b/libs/ardour/automation_list.cc index b2bda4a203..2e28bb8bb1 100644 --- a/libs/ardour/automation_list.cc +++ b/libs/ardour/automation_list.cc @@ -270,7 +270,7 @@ AutomationList::state (bool full) root->add_property ("automation-id", EventTypeMap::instance().to_symbol(_parameter)); - root->add_property ("id", _id.to_s()); + root->add_property ("id", id().to_s()); snprintf (buf, sizeof (buf), "%.12g", _default_value); root->add_property ("default", buf); @@ -437,8 +437,7 @@ AutomationList::set_state (const XMLNode& node, int version) return -1; } - if ((prop = node.property ("id")) != 0) { - _id = prop->value (); + if (set_id (node)) { /* update session AL list */ AutomationListCreated(this); } diff --git a/libs/ardour/crossfade.cc b/libs/ardour/crossfade.cc index dc8d3e3c52..f06fcfb280 100644 --- a/libs/ardour/crossfade.cc +++ b/libs/ardour/crossfade.cc @@ -778,9 +778,7 @@ Crossfade::set_state (const XMLNode& node, int /*version*/) PropertyChange what_changed; framepos_t val; - if ((prop = node.property (X_("id")))) { - _id = prop->value(); - } + set_id (node); if ((prop = node.property ("position")) != 0) { sscanf (prop->value().c_str(), "%" PRId64, &val); diff --git a/libs/ardour/diskstream.cc b/libs/ardour/diskstream.cc index 6501998171..21bbbbd849 100644 --- a/libs/ardour/diskstream.cc +++ b/libs/ardour/diskstream.cc @@ -495,13 +495,9 @@ Diskstream::set_state (const XMLNode& node, int /*version*/) } if (deprecated_io_node) { - if ((prop = deprecated_io_node->property ("id")) != 0) { - _id = prop->value (); - } + set_id (*deprecated_io_node); } else { - if ((prop = node.property ("id")) != 0) { - _id = prop->value (); - } + set_id (node); } if ((prop = node.property ("flags")) != 0) { diff --git a/libs/ardour/io.cc b/libs/ardour/io.cc index 6aaca08c90..ca34b7db61 100644 --- a/libs/ardour/io.cc +++ b/libs/ardour/io.cc @@ -575,9 +575,7 @@ IO::set_state (const XMLNode& node, int version) assert(_default_type != DataType::NIL); } - if ((prop = node.property ("id")) != 0) { - _id = prop->value (); - } + set_id (node); if ((prop = node.property ("direction")) != 0) { _direction = (Direction) string_2_enum (prop->value(), _direction); @@ -633,9 +631,7 @@ IO::set_state_2X (const XMLNode& node, int version, bool in) assert(_default_type != DataType::NIL); } - if ((prop = node.property ("id")) != 0) { - _id = prop->value (); - } + set_id (node); _direction = in ? Input : Output; diff --git a/libs/ardour/location.cc b/libs/ardour/location.cc index b6a09d863a..ed9f34ff8b 100644 --- a/libs/ardour/location.cc +++ b/libs/ardour/location.cc @@ -419,10 +419,8 @@ Location::set_state (const XMLNode& node, int /*version*/) return -1; } - if ((prop = node.property ("id")) == 0) { + if (!set_id (node)) { warning << _("XML node for Location has no ID information") << endmsg; - } else { - _id = prop->value (); } if ((prop = node.property ("name")) == 0) { diff --git a/libs/ardour/lxvst_plugin.cc b/libs/ardour/lxvst_plugin.cc index 26136b4589..21bfdb42f5 100755 --- a/libs/ardour/lxvst_plugin.cc +++ b/libs/ardour/lxvst_plugin.cc @@ -366,10 +366,8 @@ LXVSTPlugin::load_user_preset (PresetRecord r) XMLNode* root = t->root (); for (XMLNodeList::const_iterator i = root->children().begin(); i != root->children().end(); ++i) { - XMLProperty* uri = (*i)->property (X_("uri")); XMLProperty* label = (*i)->property (X_("label")); - assert (uri); assert (label); if (label->value() != r.label) { diff --git a/libs/ardour/midi_diskstream.cc b/libs/ardour/midi_diskstream.cc index 28ee12cc5a..3dc54fe862 100644 --- a/libs/ardour/midi_diskstream.cc +++ b/libs/ardour/midi_diskstream.cc @@ -761,7 +761,7 @@ MidiDiskstream::read (framepos_t& start, framecnt_t dur, bool reversed) if (midi_playlist()->read (*_playback_buf, start, this_read) != this_read) { error << string_compose( _("MidiDiskstream %1: cannot read %2 from playlist at frame %3"), - _id, this_read, start) << endmsg; + id(), this_read, start) << endmsg; return -1; } @@ -905,7 +905,7 @@ MidiDiskstream::do_flush (RunContext /*context*/, bool force_flush) if (record_enabled() && ((total > disk_io_chunk_frames) || force_flush)) { if (_write_source->midi_write (*_capture_buf, get_capture_start_frame (0), to_write) != to_write) { - error << string_compose(_("MidiDiskstream %1: cannot write to disk"), _id) << endmsg; + error << string_compose(_("MidiDiskstream %1: cannot write to disk"), id()) << endmsg; return -1; } } diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc index 6fad2084e4..0e86d72bb1 100644 --- a/libs/ardour/playlist.cc +++ b/libs/ardour/playlist.cc @@ -2213,6 +2213,8 @@ Playlist::flush_notifications (bool from_undo) plist = node.properties(); + set_id (node); + for (piter = plist.begin(); piter != plist.end(); ++piter) { prop = *piter; @@ -2220,8 +2222,6 @@ Playlist::flush_notifications (bool from_undo) if (prop->name() == X_("name")) { _name = prop->value(); _set_sort_id (); - } else if (prop->name() == X_("id")) { - _id = prop->value(); } else if (prop->name() == X_("orig-diskstream-id")) { _orig_diskstream_id = prop->value (); } else if (prop->name() == X_("frozen")) { diff --git a/libs/ardour/playlist_source.cc b/libs/ardour/playlist_source.cc index 4c01831b02..7583a4e6ea 100644 --- a/libs/ardour/playlist_source.cc +++ b/libs/ardour/playlist_source.cc @@ -86,7 +86,7 @@ PlaylistSource::add_state (XMLNode& node) node.add_property ("offset", buf); snprintf (buf, sizeof (buf), "%" PRIu64, _playlist_length); node.add_property ("length", buf); - node.add_property ("original", _id.to_s()); + node.add_property ("original", id().to_s()); node.add_child_nocopy (_playlist->get_state()); } @@ -141,11 +141,15 @@ PlaylistSource::set_state (const XMLNode& node, int /*version*/) sscanf (prop->value().c_str(), "%" PRIu64, &_playlist_length); + /* XXX not quite sure why we set our ID back to the "original" one + here. october 2011, paul + */ + if ((prop = node.property (X_("original"))) == 0) { throw failed_constructor (); } - _id = prop->value(); + set_id (prop->value()); _level = _playlist->max_source_level () + 1; diff --git a/libs/ardour/plugin_insert.cc b/libs/ardour/plugin_insert.cc index b44f1d01fc..ea95ed09e5 100644 --- a/libs/ardour/plugin_insert.cc +++ b/libs/ardour/plugin_insert.cc @@ -75,9 +75,6 @@ PluginInsert::PluginInsert (Session& s, boost::shared_ptr plug) if (plug) { add_plugin (plug); create_automatable_parameters (); - - Glib::Mutex::Lock em (_session.engine().process_lock()); - IO::PortCountChanged (max(input_streams(), output_streams())); } } @@ -950,9 +947,7 @@ PluginInsert::set_state(const XMLNode& node, int version) // state. We can't call Processor::set_state() until // the plugins themselves are created and added. - if ((prop = node.property ("id")) != 0) { - _id = prop->value(); - } + set_id (node); if (_plugins.empty()) { /* if we are adding the first plugin, we will need to set diff --git a/libs/ardour/processor.cc b/libs/ardour/processor.cc index 8b54bd4f55..cf641fd7cf 100644 --- a/libs/ardour/processor.cc +++ b/libs/ardour/processor.cc @@ -150,9 +150,7 @@ Processor::set_state_2X (const XMLNode & node, int /*version*/) set_name (prop->value ()); } - if ((prop = (*i)->property ("id")) != 0) { - _id = prop->value (); - } + set_id (**i); if ((prop = (*i)->property ("active")) != 0) { bool const a = string_is_affirmative (prop->value ()); @@ -188,10 +186,7 @@ Processor::set_state (const XMLNode& node, int version) Processor::set_name (prop->value()); } - // may not exist for legacy 3.0 sessions - if ((prop = node.property ("id")) != 0) { - _id = prop->value(); - } + set_id (node); XMLNodeList nlist = node.children(); XMLNodeIterator niter; diff --git a/libs/ardour/region.cc b/libs/ardour/region.cc index 2ce823777b..c0156903b3 100644 --- a/libs/ardour/region.cc +++ b/libs/ardour/region.cc @@ -1167,7 +1167,7 @@ Region::state () add_properties (*node); - _id.print (buf, sizeof (buf)); + id().print (buf, sizeof (buf)); node->add_property ("id", buf); node->add_property ("type", _type.to_string()); @@ -1259,9 +1259,7 @@ Region::_set_state (const XMLNode& node, int /*version*/, PropertyChange& what_c what_changed = set_values (node); - if ((prop = node.property (X_("id")))) { - _id = prop->value(); - } + set_id (node); if (_position_lock_style == MusicTime) { if ((prop = node.property ("bbt-position")) == 0) { diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index cee897b119..a051cdb3d3 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -1886,9 +1886,7 @@ Route::_set_state (const XMLNode& node, int version, bool /*call_base*/) Route::set_name (prop->value()); } - if ((prop = node.property ("id")) != 0) { - _id = prop->value (); - } + set_id (node); if ((prop = node.property (X_("flags"))) != 0) { _flags = Flag (string_2_enum (prop->value(), _flags)); @@ -2216,9 +2214,7 @@ Route::_set_state_2X (const XMLNode& node, int version) Route::set_name (prop->value ()); } - if ((prop = child->property (X_("id"))) != 0) { - _id = prop->value (); - } + set_id (*child); if ((prop = child->property (X_("active"))) != 0) { bool yn = string_is_affirmative (prop->value()); diff --git a/libs/ardour/route_group.cc b/libs/ardour/route_group.cc index 42aa30c0f1..fadd436169 100644 --- a/libs/ardour/route_group.cc +++ b/libs/ardour/route_group.cc @@ -251,10 +251,7 @@ RouteGroup::set_state (const XMLNode& node, int version) const XMLProperty *prop; - if ((prop = node.property ("id")) != 0) { - _id = prop->value(); - } - + set_id (node); set_values (node); if ((prop = node.property ("routes")) != 0) { diff --git a/libs/ardour/source.cc b/libs/ardour/source.cc index 35e1417fb4..4c582f3ad7 100644 --- a/libs/ardour/source.cc +++ b/libs/ardour/source.cc @@ -100,7 +100,7 @@ Source::get_state () node->add_property ("name", name()); node->add_property ("type", _type.to_string()); node->add_property (X_("flags"), enum_2_string (_flags)); - _id.print (buf, sizeof (buf)); + id().print (buf, sizeof (buf)); node->add_property ("id", buf); if (_timestamp != 0) { @@ -122,9 +122,7 @@ Source::set_state (const XMLNode& node, int version) return -1; } - if ((prop = node.property ("id")) != 0) { - _id = prop->value (); - } else { + if (!set_id (node)) { return -1; } @@ -221,7 +219,7 @@ Source::get_transients_path () const s = _session.analysis_dir (); parts.push_back (s); - s = _id.to_s(); + s = id().to_s(); s += '.'; s += TransientDetector::operational_identifier(); parts.push_back (s); diff --git a/libs/pbd/controllable.cc b/libs/pbd/controllable.cc index 959abe443d..51877ee206 100644 --- a/libs/pbd/controllable.cc +++ b/libs/pbd/controllable.cc @@ -107,7 +107,7 @@ Controllable::get_state () char buf[64]; node->add_property (X_("name"), _name); // not reloaded from XML state, just there to look at - _id.print (buf, sizeof (buf)); + id().print (buf, sizeof (buf)); node->add_property (X_("id"), buf); node->add_property (X_("flags"), enum_2_string (_flags)); snprintf (buf, sizeof (buf), "%2.12f", get_value()); @@ -129,9 +129,7 @@ Controllable::set_state (const XMLNode& node, int /*version*/) Stateful::save_extra_xml (node); - if ((prop = node.property (X_("id"))) != 0) { - _id = prop->value(); - } else { + if (!set_id (node)) { error << _("Controllable state node has no ID property") << endmsg; return -1; } diff --git a/libs/pbd/id.cc b/libs/pbd/id.cc index b96863b0fa..d7ac1560a1 100644 --- a/libs/pbd/id.cc +++ b/libs/pbd/id.cc @@ -44,8 +44,7 @@ ID::init () ID::ID () { - Glib::Mutex::Lock lm (*counter_lock); - _id = _counter++; + reset (); } ID::ID (const ID& other) @@ -58,6 +57,13 @@ ID::ID (string str) string_assign (str); } +void +ID::reset () +{ + Glib::Mutex::Lock lm (*counter_lock); + _id = _counter++; +} + int ID::string_assign (string str) { diff --git a/libs/pbd/pbd/id.h b/libs/pbd/pbd/id.h index 7a32a29002..6296fc2981 100644 --- a/libs/pbd/pbd/id.h +++ b/libs/pbd/pbd/id.h @@ -33,6 +33,8 @@ class ID { ID (std::string); ID (const ID&); + void reset (); + bool operator== (const ID& other) const { return _id == other._id; } diff --git a/libs/pbd/pbd/stateful.h b/libs/pbd/pbd/stateful.h index dd1659db55..2d5b2a0990 100644 --- a/libs/pbd/pbd/stateful.h +++ b/libs/pbd/pbd/stateful.h @@ -65,7 +65,10 @@ class Stateful { void save_extra_xml (const XMLNode&); const PBD::ID& id() const { return _id; } - + bool set_id (const XMLNode&); + void set_id (const std::string&); + void reset_id (); + /* history management */ void clear_changes (); @@ -106,7 +109,6 @@ class Stateful { XMLNode *_extra_xml; XMLNode *_instant_xml; - PBD::ID _id; int32_t _frozen; PBD::PropertyChange _pending_changed; Glib::Mutex _lock; @@ -120,6 +122,9 @@ class Stateful { */ virtual void mid_thaw (const PropertyChange&) { } bool property_changes_suspended() const { return g_atomic_int_get (&_frozen) > 0; } + + private: + PBD::ID _id; }; } // namespace PBD diff --git a/libs/pbd/stateful.cc b/libs/pbd/stateful.cc index 47d1e66ef4..b2c76f452f 100644 --- a/libs/pbd/stateful.cc +++ b/libs/pbd/stateful.cc @@ -369,5 +369,29 @@ Stateful::clear_owned_changes () } } +bool +Stateful::set_id (const XMLNode& node) +{ + const XMLProperty* prop; + + if ((prop = node.property ("id")) != 0) { + _id = prop->value (); + return true; + } + + return false; +} + +void +Stateful::reset_id () +{ + _id = ID (); +} + +void +Stateful::set_id (const string& str) +{ + _id = str; +} } // namespace PBD -- 2.30.2