From ebf60a31d8ad0e92109eb4b578de33a9d48cff87 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 14 Jun 2009 16:54:40 +0000 Subject: [PATCH] Fix up some problems with Region::_master_sources git-svn-id: svn://localhost/ardour2/branches/3.0@5189 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/audioregion.h | 3 +- libs/ardour/audioregion.cc | 70 ++++++++++++++++++-------------- libs/ardour/region.cc | 1 + libs/ardour/session_state.cc | 4 +- 4 files changed, 45 insertions(+), 33 deletions(-) diff --git a/libs/ardour/ardour/audioregion.h b/libs/ardour/ardour/audioregion.h index 36b3db0bed..cda9cab878 100644 --- a/libs/ardour/ardour/audioregion.h +++ b/libs/ardour/ardour/audioregion.h @@ -200,7 +200,8 @@ class AudioRegion : public Region void fade_out_changed (); void source_offset_changed (); void listen_to_my_curves (); - void listen_to_my_sources (); + void connect_to_analysis_changed (); + void connect_to_header_position_offset_changed (); AutomatableControls _automatable; diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc index 197af86d13..25948e595c 100644 --- a/libs/ardour/audioregion.cc +++ b/libs/ardour/audioregion.cc @@ -73,7 +73,7 @@ AudioRegion::init () set_default_envelope (); listen_to_my_curves (); - listen_to_my_sources (); + connect_to_analysis_changed (); } /** Constructor for use by derived types only */ @@ -85,6 +85,7 @@ AudioRegion::AudioRegion (Session& s, nframes_t start, nframes_t length, string , _envelope (new AutomationList(Evoral::Parameter(EnvelopeAutomation))) { init (); + assert (_sources.size() == _master_sources.size()); } /** Basic AudioRegion constructor (one channel) */ @@ -101,6 +102,7 @@ AudioRegion::AudioRegion (boost::shared_ptr src, nframes_t start, n } init (); + assert (_sources.size() == _master_sources.size()); } /* Basic AudioRegion constructor (one channel) */ @@ -117,6 +119,7 @@ AudioRegion::AudioRegion (boost::shared_ptr src, nframes_t start, n } init (); + assert (_sources.size() == _master_sources.size()); } /** Basic AudioRegion constructor (many channels) */ @@ -128,7 +131,8 @@ AudioRegion::AudioRegion (const SourceList& srcs, nframes_t start, nframes_t len , _envelope (new AutomationList(Evoral::Parameter(EnvelopeAutomation))) { init (); - listen_to_my_sources (); + connect_to_analysis_changed (); + assert (_sources.size() == _master_sources.size()); } /** Create a new AudioRegion, that is part of an existing one */ @@ -139,22 +143,7 @@ AudioRegion::AudioRegion (boost::shared_ptr other, nframes_t , _fade_out (new AutomationList(*other->_fade_out)) , _envelope (new AutomationList(*other->_envelope, offset, offset + length)) { - set > unique_srcs; - - for (SourceList::const_iterator i= other->_sources.begin(); i != other->_sources.end(); ++i) { - _sources.push_back (*i); - - pair >::iterator,bool> result; - - result = unique_srcs.insert (*i); - - if (result.second) { - boost::shared_ptr afs = boost::dynamic_pointer_cast (*i); - if (afs) { - afs->HeaderPositionOffsetChanged.connect (mem_fun (*this, &AudioRegion::source_offset_changed)); - } - } - } + connect_to_header_position_offset_changed (); /* return to default fades if the existing ones are too long */ @@ -183,7 +172,9 @@ AudioRegion::AudioRegion (boost::shared_ptr other, nframes_t assert(_type == DataType::AUDIO); listen_to_my_curves (); - listen_to_my_sources (); + connect_to_analysis_changed (); + + assert (_sources.size() == _master_sources.size()); } AudioRegion::AudioRegion (boost::shared_ptr other) @@ -199,7 +190,9 @@ AudioRegion::AudioRegion (boost::shared_ptr other) set_default_fades (); listen_to_my_curves (); - listen_to_my_sources (); + connect_to_analysis_changed (); + + assert (_sources.size() == _master_sources.size()); } AudioRegion::AudioRegion (boost::shared_ptr other, const SourceList& srcs, @@ -212,12 +205,7 @@ AudioRegion::AudioRegion (boost::shared_ptr other, const Sour { /* make-a-sort-of-copy-with-different-sources constructor (used by audio filter) */ - set > unique_srcs; - - for (SourceList::const_iterator i=srcs.begin(); i != srcs.end(); ++i) { - - _sources.push_back (*i); - _master_sources.push_back (*i); + for (SourceList::const_iterator i = _sources.begin(); i != _sources.end(); ++i) { boost::shared_ptr afs = boost::dynamic_pointer_cast ((*i)); if (afs) { @@ -231,7 +219,9 @@ AudioRegion::AudioRegion (boost::shared_ptr other, const Sour _fade_out_disabled = 0; listen_to_my_curves (); - listen_to_my_sources (); + connect_to_analysis_changed (); + + assert (_sources.size() == _master_sources.size()); } AudioRegion::AudioRegion (boost::shared_ptr src, const XMLNode& node) @@ -253,7 +243,9 @@ AudioRegion::AudioRegion (boost::shared_ptr src, const XMLNode& nod } assert(_type == DataType::AUDIO); - listen_to_my_sources (); + connect_to_analysis_changed (); + + assert (_sources.size() == _master_sources.size()); } AudioRegion::AudioRegion (SourceList& srcs, const XMLNode& node) @@ -270,7 +262,8 @@ AudioRegion::AudioRegion (SourceList& srcs, const XMLNode& node) } assert(_type == DataType::AUDIO); - listen_to_my_sources (); + connect_to_analysis_changed (); + assert (_sources.size() == _master_sources.size()); } AudioRegion::~AudioRegion () @@ -278,13 +271,30 @@ AudioRegion::~AudioRegion () } void -AudioRegion::listen_to_my_sources () +AudioRegion::connect_to_analysis_changed () { for (SourceList::const_iterator i = _sources.begin(); i != _sources.end(); ++i) { (*i)->AnalysisChanged.connect (mem_fun (*this, &AudioRegion::invalidate_transients)); } } +void +AudioRegion::connect_to_header_position_offset_changed () +{ + set > unique_srcs; + + for (SourceList::const_iterator i = _sources.begin(); i != _sources.end(); ++i) { + + if (unique_srcs.find (*i) == unique_srcs.end ()) { + unique_srcs.insert (*i); + boost::shared_ptr afs = boost::dynamic_pointer_cast (*i); + if (afs) { + afs->HeaderPositionOffsetChanged.connect (mem_fun (*this, &AudioRegion::source_offset_changed)); + } + } + } +} + void AudioRegion::listen_to_my_curves () { diff --git a/libs/ardour/region.cc b/libs/ardour/region.cc index 804a4104dc..fb662beca3 100644 --- a/libs/ardour/region.cc +++ b/libs/ardour/region.cc @@ -1473,6 +1473,7 @@ void Region::set_master_sources (const SourceList& srcs) { _master_sources = srcs; + assert (_sources.size() == _master_sources.size()); } bool diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 955da881d1..5d622f95a7 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -1506,7 +1506,7 @@ Session::XMLAudioRegionFactory (const XMLNode& node, bool full) } } - for (uint32_t n=1; n < nchans; ++n) { + for (uint32_t n = 0; n < nchans; ++n) { snprintf (buf, sizeof(buf), X_("master-source-%d"), n); if ((prop = node.property (buf)) != 0) { @@ -1541,7 +1541,7 @@ Session::XMLAudioRegionFactory (const XMLNode& node, bool full) } if (!master_sources.empty()) { - if (master_sources.size() == nchans) { + if (master_sources.size() != nchans) { error << _("Session: XMLNode describing an AudioRegion is missing some master sources; ignored") << endmsg; } else { region->set_master_sources (master_sources);