summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorCarl Hetherington <carl@carlh.net>2010-05-02 23:14:43 +0000
committerCarl Hetherington <carl@carlh.net>2010-05-02 23:14:43 +0000
commitc2da4ec8f988f6f8b9e426b03222a2c687c72edb (patch)
tree0223f8268e4462f0f1494c2795adb6367cee975a /libs
parentceb1025c2c8ab1246a51c3967ee5a79773a4e008 (diff)
Prevent multiple tempo / meter changes being inserted at the same point
on the timeline; adding a new change at the same time as an existing one will replace the existing one. Should prevent #769 from happening. Some cleanups and tweaks to tempo / meter dialogues. Desensitize Remove menu option for those changes that can't be removed. git-svn-id: svn://localhost/ardour2/branches/3.0@7045 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r--libs/ardour/ardour/tempo.h6
-rw-r--r--libs/ardour/tempo.cc78
2 files changed, 72 insertions, 12 deletions
diff --git a/libs/ardour/ardour/tempo.h b/libs/ardour/ardour/tempo.h
index 596444173f..21a1185725 100644
--- a/libs/ardour/ardour/tempo.h
+++ b/libs/ardour/ardour/tempo.h
@@ -86,7 +86,7 @@ class MetricSection {
virtual ~MetricSection() {}
const BBT_Time& start() const { return _start; }
- nframes64_t frame() const { return _frame; }
+ nframes64_t frame() const { return _frame; }
void set_movable (bool yn) { _movable = yn; }
bool movable() const { return _movable; }
@@ -105,9 +105,11 @@ class MetricSection {
*/
virtual XMLNode& get_state() const = 0;
+ int compare (MetricSection *, bool) const;
+
private:
BBT_Time _start;
- nframes64_t _frame;
+ nframes64_t _frame;
bool _movable;
};
diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc
index 127c0a10e4..f2a5c5be40 100644
--- a/libs/ardour/tempo.cc
+++ b/libs/ardour/tempo.cc
@@ -370,16 +370,46 @@ TempoMap::do_insert (MetricSection* section, bool with_bbt)
{
Metrics::iterator i;
+ /* Look for any existing MetricSection that is of the same type and
+ at the same time as the new one, and remove it before adding
+ the new one.
+ */
+
+ Metrics::iterator to_remove = metrics->end ();
+
for (i = metrics->begin(); i != metrics->end(); ++i) {
- if (with_bbt) {
- if ((*i)->start() < section->start()) {
- continue;
- }
- } else {
- if ((*i)->frame() < section->frame()) {
- continue;
- }
+ int const c = (*i)->compare (section, with_bbt);
+
+ if (c < 0) {
+ /* this section is before the one to be added; go back round */
+ continue;
+ } else if (c > 0) {
+ /* this section is after the one to be added; there can't be any at the same time */
+ break;
+ }
+
+ /* hacky comparison of type */
+ bool const a = dynamic_cast<TempoSection*> (*i) != 0;
+ bool const b = dynamic_cast<TempoSection*> (section) != 0;
+
+ if (a == b) {
+ to_remove = i;
+ break;
+ }
+ }
+
+ if (to_remove != metrics->end()) {
+ /* remove the MetricSection at the same time as the one we are about to add */
+ metrics->erase (to_remove);
+ }
+
+ /* Add the given MetricSection */
+
+ for (i = metrics->begin(); i != metrics->end(); ++i) {
+
+ if ((*i)->compare (section, with_bbt) < 0) {
+ continue;
}
metrics->insert (i, section);
@@ -400,7 +430,6 @@ TempoMap::add_tempo (const Tempo& tempo, BBT_Time where)
Glib::RWLock::WriterLock lm (lock);
/* new tempos always start on a beat */
-
where.ticks = 0;
do_insert (new TempoSection (where, tempo.beats_per_minute(), tempo.note_type()), true);
@@ -468,7 +497,6 @@ TempoMap::add_meter (const Meter& meter, BBT_Time where)
}
/* new meters *always* start on a beat. */
-
where.ticks = 0;
do_insert (new MeterSection (where, meter.beats_per_bar(), meter.note_divisor()), true);
@@ -1892,3 +1920,33 @@ TempoMap::bbt_subtract (const BBT_Time& start, const BBT_Time& decrement) const
result.bars -= op.bars;
return result;
}
+
+/** Compare the time of this with that of another MetricSection.
+ * @param with_bbt True to compare using ::start(), false to use ::frame().
+ * @return -1 for less than, 0 for equal, 1 for greater than.
+ */
+
+int
+MetricSection::compare (MetricSection* other, bool with_bbt) const
+{
+ if (with_bbt) {
+ if (start() == other->start()) {
+ return 0;
+ } else if (start() < other->start()) {
+ return -1;
+ } else {
+ return 1;
+ }
+ } else {
+ if (frame() == other->frame()) {
+ return 0;
+ } else if (frame() < other->frame()) {
+ return -1;
+ } else {
+ return 1;
+ }
+ }
+
+ /* NOTREACHED */
+ return 0;
+}