mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-09 16:24:57 +01:00
remove race condition when editing tempo/meter information.
Lock was not held across a replace_{tempo,meter}() operation because of re-use
of {remove,add}_{tempo,meter}. Moved functional code into _locked variants so
that replace operation can hold lock across its entire active lifetime.
This commit is contained in:
parent
73f967c330
commit
9a4827374c
2 changed files with 149 additions and 106 deletions
|
|
@ -364,6 +364,13 @@ class LIBARDOUR_API TempoMap : public PBD::StatefulDestructible
|
||||||
TempoSection& first_tempo();
|
TempoSection& first_tempo();
|
||||||
|
|
||||||
void do_insert (MetricSection* section);
|
void do_insert (MetricSection* section);
|
||||||
|
|
||||||
|
void add_tempo_locked (const Tempo&, Timecode::BBT_Time where, bool recompute);
|
||||||
|
void add_meter_locked (const Meter&, Timecode::BBT_Time where, bool recompute);
|
||||||
|
|
||||||
|
bool remove_tempo_locked (const TempoSection&);
|
||||||
|
bool remove_meter_locked (const MeterSection&);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}; /* namespace ARDOUR */
|
}; /* namespace ARDOUR */
|
||||||
|
|
|
||||||
|
|
@ -307,23 +307,11 @@ TempoMap::remove_tempo (const TempoSection& tempo, bool complete_operation)
|
||||||
|
|
||||||
{
|
{
|
||||||
Glib::Threads::RWLock::WriterLock lm (lock);
|
Glib::Threads::RWLock::WriterLock lm (lock);
|
||||||
Metrics::iterator i;
|
if ((removed = remove_tempo_locked (tempo))) {
|
||||||
|
if (complete_operation) {
|
||||||
for (i = metrics.begin(); i != metrics.end(); ++i) {
|
recompute_map (true);
|
||||||
if (dynamic_cast<TempoSection*> (*i) != 0) {
|
|
||||||
if (tempo.frame() == (*i)->frame()) {
|
|
||||||
if ((*i)->movable()) {
|
|
||||||
metrics.erase (i);
|
|
||||||
removed = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (removed && complete_operation) {
|
|
||||||
recompute_map (false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (removed && complete_operation) {
|
if (removed && complete_operation) {
|
||||||
|
|
@ -331,6 +319,25 @@ TempoMap::remove_tempo (const TempoSection& tempo, bool complete_operation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
TempoMap::remove_tempo_locked (const TempoSection& tempo)
|
||||||
|
{
|
||||||
|
Metrics::iterator i;
|
||||||
|
|
||||||
|
for (i = metrics.begin(); i != metrics.end(); ++i) {
|
||||||
|
if (dynamic_cast<TempoSection*> (*i) != 0) {
|
||||||
|
if (tempo.frame() == (*i)->frame()) {
|
||||||
|
if ((*i)->movable()) {
|
||||||
|
metrics.erase (i);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TempoMap::remove_meter (const MeterSection& tempo, bool complete_operation)
|
TempoMap::remove_meter (const MeterSection& tempo, bool complete_operation)
|
||||||
{
|
{
|
||||||
|
|
@ -338,23 +345,11 @@ TempoMap::remove_meter (const MeterSection& tempo, bool complete_operation)
|
||||||
|
|
||||||
{
|
{
|
||||||
Glib::Threads::RWLock::WriterLock lm (lock);
|
Glib::Threads::RWLock::WriterLock lm (lock);
|
||||||
Metrics::iterator i;
|
if ((removed = remove_meter_locked (tempo))) {
|
||||||
|
if (complete_operation) {
|
||||||
for (i = metrics.begin(); i != metrics.end(); ++i) {
|
recompute_map (true);
|
||||||
if (dynamic_cast<MeterSection*> (*i) != 0) {
|
|
||||||
if (tempo.frame() == (*i)->frame()) {
|
|
||||||
if ((*i)->movable()) {
|
|
||||||
metrics.erase (i);
|
|
||||||
removed = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (removed && complete_operation) {
|
|
||||||
recompute_map (true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (removed && complete_operation) {
|
if (removed && complete_operation) {
|
||||||
|
|
@ -362,6 +357,25 @@ TempoMap::remove_meter (const MeterSection& tempo, bool complete_operation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
TempoMap::remove_meter_locked (const MeterSection& tempo)
|
||||||
|
{
|
||||||
|
Metrics::iterator i;
|
||||||
|
|
||||||
|
for (i = metrics.begin(); i != metrics.end(); ++i) {
|
||||||
|
if (dynamic_cast<MeterSection*> (*i) != 0) {
|
||||||
|
if (tempo.frame() == (*i)->frame()) {
|
||||||
|
if ((*i)->movable()) {
|
||||||
|
metrics.erase (i);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TempoMap::do_insert (MetricSection* section)
|
TempoMap::do_insert (MetricSection* section)
|
||||||
{
|
{
|
||||||
|
|
@ -476,17 +490,19 @@ TempoMap::do_insert (MetricSection* section)
|
||||||
void
|
void
|
||||||
TempoMap::replace_tempo (const TempoSection& ts, const Tempo& tempo, const BBT_Time& where)
|
TempoMap::replace_tempo (const TempoSection& ts, const Tempo& tempo, const BBT_Time& where)
|
||||||
{
|
{
|
||||||
TempoSection& first (first_tempo());
|
{
|
||||||
|
Glib::Threads::RWLock::WriterLock lm (lock);
|
||||||
if (ts.start() != first.start()) {
|
TempoSection& first (first_tempo());
|
||||||
remove_tempo (ts, false);
|
|
||||||
add_tempo (tempo, where);
|
if (ts.start() != first.start()) {
|
||||||
} else {
|
remove_tempo_locked (ts);
|
||||||
{
|
add_tempo_locked (tempo, where, true);
|
||||||
Glib::Threads::RWLock::WriterLock lm (lock);
|
} else {
|
||||||
/* cannot move the first tempo section */
|
{
|
||||||
*static_cast<Tempo*>(&first) = tempo;
|
/* cannot move the first tempo section */
|
||||||
recompute_map (false);
|
*static_cast<Tempo*>(&first) = tempo;
|
||||||
|
recompute_map (false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -498,62 +514,69 @@ TempoMap::add_tempo (const Tempo& tempo, BBT_Time where)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
Glib::Threads::RWLock::WriterLock lm (lock);
|
Glib::Threads::RWLock::WriterLock lm (lock);
|
||||||
|
add_tempo_locked (tempo, where, true);
|
||||||
/* new tempos always start on a beat */
|
|
||||||
where.ticks = 0;
|
|
||||||
|
|
||||||
TempoSection* ts = new TempoSection (where, tempo.beats_per_minute(), tempo.note_type());
|
|
||||||
|
|
||||||
/* find the meter to use to set the bar offset of this
|
|
||||||
* tempo section.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const Meter* meter = &first_meter();
|
|
||||||
|
|
||||||
/* as we start, we are *guaranteed* to have m.meter and m.tempo pointing
|
|
||||||
at something, because we insert the default tempo and meter during
|
|
||||||
TempoMap construction.
|
|
||||||
|
|
||||||
now see if we can find better candidates.
|
|
||||||
*/
|
|
||||||
|
|
||||||
for (Metrics::const_iterator i = metrics.begin(); i != metrics.end(); ++i) {
|
|
||||||
|
|
||||||
const MeterSection* m;
|
|
||||||
|
|
||||||
if (where < (*i)->start()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) {
|
|
||||||
meter = m;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ts->update_bar_offset_from_bbt (*meter);
|
|
||||||
|
|
||||||
/* and insert it */
|
|
||||||
|
|
||||||
do_insert (ts);
|
|
||||||
|
|
||||||
recompute_map (false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PropertyChanged (PropertyChange ());
|
PropertyChanged (PropertyChange ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TempoMap::add_tempo_locked (const Tempo& tempo, BBT_Time where, bool recompute)
|
||||||
|
{
|
||||||
|
/* new tempos always start on a beat */
|
||||||
|
where.ticks = 0;
|
||||||
|
|
||||||
|
TempoSection* ts = new TempoSection (where, tempo.beats_per_minute(), tempo.note_type());
|
||||||
|
|
||||||
|
/* find the meter to use to set the bar offset of this
|
||||||
|
* tempo section.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const Meter* meter = &first_meter();
|
||||||
|
|
||||||
|
/* as we start, we are *guaranteed* to have m.meter and m.tempo pointing
|
||||||
|
at something, because we insert the default tempo and meter during
|
||||||
|
TempoMap construction.
|
||||||
|
|
||||||
|
now see if we can find better candidates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (Metrics::const_iterator i = metrics.begin(); i != metrics.end(); ++i) {
|
||||||
|
|
||||||
|
const MeterSection* m;
|
||||||
|
|
||||||
|
if (where < (*i)->start()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) {
|
||||||
|
meter = m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ts->update_bar_offset_from_bbt (*meter);
|
||||||
|
|
||||||
|
/* and insert it */
|
||||||
|
|
||||||
|
do_insert (ts);
|
||||||
|
|
||||||
|
if (recompute) {
|
||||||
|
recompute_map (false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TempoMap::replace_meter (const MeterSection& ms, const Meter& meter, const BBT_Time& where)
|
TempoMap::replace_meter (const MeterSection& ms, const Meter& meter, const BBT_Time& where)
|
||||||
{
|
{
|
||||||
MeterSection& first (first_meter());
|
{
|
||||||
|
Glib::Threads::RWLock::WriterLock lm (lock);
|
||||||
if (ms.start() != first.start()) {
|
MeterSection& first (first_meter());
|
||||||
remove_meter (ms, false);
|
|
||||||
add_meter (meter, where);
|
if (ms.start() != first.start()) {
|
||||||
} else {
|
remove_meter_locked (ms);
|
||||||
{
|
add_meter_locked (meter, where, true);
|
||||||
Glib::Threads::RWLock::WriterLock lm (lock);
|
} else {
|
||||||
/* cannot move the first meter section */
|
/* cannot move the first meter section */
|
||||||
*static_cast<Meter*>(&first) = meter;
|
*static_cast<Meter*>(&first) = meter;
|
||||||
recompute_map (true);
|
recompute_map (true);
|
||||||
|
|
@ -568,24 +591,7 @@ TempoMap::add_meter (const Meter& meter, BBT_Time where)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
Glib::Threads::RWLock::WriterLock lm (lock);
|
Glib::Threads::RWLock::WriterLock lm (lock);
|
||||||
|
add_meter_locked (meter, where, true);
|
||||||
/* a new meter always starts a new bar on the first beat. so
|
|
||||||
round the start time appropriately. remember that
|
|
||||||
`where' is based on the existing tempo map, not
|
|
||||||
the result after we insert the new meter.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (where.beats != 1) {
|
|
||||||
where.beats = 1;
|
|
||||||
where.bars++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* new meters *always* start on a beat. */
|
|
||||||
where.ticks = 0;
|
|
||||||
|
|
||||||
do_insert (new MeterSection (where, meter.divisions_per_bar(), meter.note_divisor()));
|
|
||||||
recompute_map (true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -598,6 +604,32 @@ TempoMap::add_meter (const Meter& meter, BBT_Time where)
|
||||||
PropertyChanged (PropertyChange ());
|
PropertyChanged (PropertyChange ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TempoMap::add_meter_locked (const Meter& meter, BBT_Time where, bool recompute)
|
||||||
|
{
|
||||||
|
/* a new meter always starts a new bar on the first beat. so
|
||||||
|
round the start time appropriately. remember that
|
||||||
|
`where' is based on the existing tempo map, not
|
||||||
|
the result after we insert the new meter.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (where.beats != 1) {
|
||||||
|
where.beats = 1;
|
||||||
|
where.bars++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* new meters *always* start on a beat. */
|
||||||
|
where.ticks = 0;
|
||||||
|
|
||||||
|
do_insert (new MeterSection (where, meter.divisions_per_bar(), meter.note_divisor()));
|
||||||
|
|
||||||
|
if (recompute) {
|
||||||
|
recompute_map (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TempoMap::change_initial_tempo (double beats_per_minute, double note_type)
|
TempoMap::change_initial_tempo (double beats_per_minute, double note_type)
|
||||||
{
|
{
|
||||||
|
|
@ -687,6 +719,8 @@ TempoMap::first_meter ()
|
||||||
{
|
{
|
||||||
MeterSection *m = 0;
|
MeterSection *m = 0;
|
||||||
|
|
||||||
|
/* CALLER MUST HOLD LOCK */
|
||||||
|
|
||||||
for (Metrics::iterator i = metrics.begin(); i != metrics.end(); ++i) {
|
for (Metrics::iterator i = metrics.begin(); i != metrics.end(); ++i) {
|
||||||
if ((m = dynamic_cast<MeterSection *> (*i)) != 0) {
|
if ((m = dynamic_cast<MeterSection *> (*i)) != 0) {
|
||||||
return *m;
|
return *m;
|
||||||
|
|
@ -703,6 +737,8 @@ TempoMap::first_tempo () const
|
||||||
{
|
{
|
||||||
const TempoSection *t = 0;
|
const TempoSection *t = 0;
|
||||||
|
|
||||||
|
/* CALLER MUST HOLD LOCK */
|
||||||
|
|
||||||
for (Metrics::const_iterator i = metrics.begin(); i != metrics.end(); ++i) {
|
for (Metrics::const_iterator i = metrics.begin(); i != metrics.end(); ++i) {
|
||||||
if ((t = dynamic_cast<const TempoSection *> (*i)) != 0) {
|
if ((t = dynamic_cast<const TempoSection *> (*i)) != 0) {
|
||||||
return *t;
|
return *t;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue