summaryrefslogtreecommitdiff
path: root/libs/ardour/tempo.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2017-03-18 21:31:34 +0100
committerRobin Gareus <robin@gareus.org>2017-03-18 21:33:40 +0100
commita9ca7f649a1ff84409ef7e86166b1161e8848efb (patch)
tree9daa2f167b14c9ca69e14605392b163502df1ed2 /libs/ardour/tempo.cc
parent448bc635e528f068d88a34de03622fba0e3ea180 (diff)
Resolve copy-c'tor and assignment issue with TempoMap
There are various issues with copy-construction: no readlock is taken, Tempo/Metric Sections were static-cast to non-const pointers and passed as references... This remove the [now] unused copy-c'tor, and fixes various const issues.
Diffstat (limited to 'libs/ardour/tempo.cc')
-rw-r--r--libs/ardour/tempo.cc46
1 files changed, 12 insertions, 34 deletions
diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc
index cc40ef5532..45ae54f479 100644
--- a/libs/ardour/tempo.cc
+++ b/libs/ardour/tempo.cc
@@ -784,27 +784,12 @@ TempoMap::TempoMap (framecnt_t fr)
}
-TempoMap::TempoMap (TempoMap const & other)
-{
- _frame_rate = other._frame_rate;
- for (Metrics::const_iterator m = other._metrics.begin(); m != other._metrics.end(); ++m) {
- TempoSection* ts = dynamic_cast<TempoSection*> (*m);
- MeterSection* ms = dynamic_cast<MeterSection*> (*m);
-
- if (ts) {
- TempoSection* new_section = new TempoSection (*ts);
- _metrics.push_back (new_section);
- } else {
- MeterSection* new_section = new MeterSection (*ms);
- _metrics.push_back (new_section);
- }
- }
-}
-
TempoMap&
TempoMap::operator= (TempoMap const & other)
{
if (&other != this) {
+ Glib::Threads::RWLock::ReaderLock lr (other.lock);
+ Glib::Threads::RWLock::WriterLock lm (lock);
_frame_rate = other._frame_rate;
Metrics::const_iterator d = _metrics.begin();
@@ -815,8 +800,8 @@ TempoMap::operator= (TempoMap const & other)
_metrics.clear();
for (Metrics::const_iterator m = other._metrics.begin(); m != other._metrics.end(); ++m) {
- TempoSection* ts = dynamic_cast<TempoSection*> (*m);
- MeterSection* ms = dynamic_cast<MeterSection*> (*m);
+ TempoSection const * const ts = dynamic_cast<TempoSection const * const> (*m);
+ MeterSection const * const ms = dynamic_cast<MeterSection const * const> (*m);
if (ts) {
TempoSection* new_section = new TempoSection (*ts);
@@ -3140,15 +3125,13 @@ TempoMap::solve_map_bbt (Metrics& imaginary, MeterSection* section, const BBT_Ti
* to section's equivalent in copy.
*/
TempoSection*
-TempoMap::copy_metrics_and_point (const Metrics& metrics, Metrics& copy, TempoSection* section)
+TempoMap::copy_metrics_and_point (const Metrics& metrics, Metrics& copy, TempoSection* section) const
{
TempoSection* ret = 0;
for (Metrics::const_iterator i = metrics.begin(); i != metrics.end(); ++i) {
- TempoSection* t;
- MeterSection* m;
if ((*i)->is_tempo()) {
- t = static_cast<TempoSection*> (*i);
+ TempoSection const * const t = dynamic_cast<TempoSection const * const> (*i);
if (t == section) {
ret = new TempoSection (*t);
copy.push_back (ret);
@@ -3157,9 +3140,8 @@ TempoMap::copy_metrics_and_point (const Metrics& metrics, Metrics& copy, TempoSe
TempoSection* cp = new TempoSection (*t);
copy.push_back (cp);
- }
- if (!(*i)->is_tempo()) {
- m = static_cast<MeterSection *> (*i);
+ } else {
+ MeterSection const * const m = dynamic_cast<MeterSection const * const> (*i);
MeterSection* cp = new MeterSection (*m);
copy.push_back (cp);
}
@@ -3169,21 +3151,17 @@ TempoMap::copy_metrics_and_point (const Metrics& metrics, Metrics& copy, TempoSe
}
MeterSection*
-TempoMap::copy_metrics_and_point (const Metrics& metrics, Metrics& copy, MeterSection* section)
+TempoMap::copy_metrics_and_point (const Metrics& metrics, Metrics& copy, MeterSection* section) const
{
MeterSection* ret = 0;
for (Metrics::const_iterator i = metrics.begin(); i != metrics.end(); ++i) {
- TempoSection* t;
- MeterSection* m;
if ((*i)->is_tempo()) {
- t = static_cast<TempoSection*> (*i);
+ TempoSection const * const t = dynamic_cast<TempoSection const * const> (*i);
TempoSection* cp = new TempoSection (*t);
copy.push_back (cp);
- }
-
- if (!(*i)->is_tempo()) {
- m = static_cast<MeterSection *> (*i);
+ } else {
+ MeterSection const * const m = dynamic_cast<MeterSection const * const> (*i);
if (m == section) {
ret = new MeterSection (*m);
copy.push_back (ret);