fix crash when zoom level leads to multiple tempo lines on the same pixel (may affect several mantis reports)

git-svn-id: svn://localhost/ardour2/branches/3.0@14015 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2013-01-27 22:42:36 +00:00
parent de4c4b5340
commit d04caca7ea

View file

@ -123,7 +123,7 @@ TempoLines::draw (const ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
// Tempo map hasn't changed and we're entirely within a clean // Tempo map hasn't changed and we're entirely within a clean
// range, don't need to do anything. Yay. // range, don't need to do anything. Yay.
if (needed_left >= _clean_left && needed_right <= _clean_right) { if (needed_left >= _clean_left && needed_right <= _clean_right) {
//cout << endl << "*** LINE CACHE PERFECT HIT" << endl; // cout << endl << "*** LINE CACHE PERFECT HIT" << endl;
return; return;
} }
@ -144,11 +144,9 @@ TempoLines::draw (const ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
} }
xpos = rint(((framepos_t)(*i).frame) / (double)frames_per_unit); xpos = rint(((framepos_t)(*i).frame) / (double)frames_per_unit);
if (inserted_last_time && !_lines.empty()) { li = _lines.lower_bound(xpos); // first line >= xpos
li = _lines.lower_bound(xpos); // first line >= xpos
}
line = (li != _lines.end()) ? li->second : NULL; line = (li != _lines.end()) ? li->second : NULL;
assert(!line || line->property_x1() == li->first); assert(!line || line->property_x1() == li->first);
@ -157,7 +155,7 @@ TempoLines::draw (const ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
++next; ++next;
exhausted = (next == _lines.end()); exhausted = (next == _lines.end());
// Hooray, line is perfect // Hooray, line is perfect
if (line && line->property_x1() == xpos) { if (line && line->property_x1() == xpos) {
if (li != _lines.end()) if (li != _lines.end())
@ -165,7 +163,6 @@ TempoLines::draw (const ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
line->property_color_rgba() = color; line->property_color_rgba() = color;
inserted_last_time = false; // don't search next time inserted_last_time = false; // don't search next time
// Use existing line, moving if necessary // Use existing line, moving if necessary
} else if (!exhausted) { } else if (!exhausted) {
Lines::iterator steal = _lines.end(); Lines::iterator steal = _lines.end();
@ -216,34 +213,37 @@ TempoLines::draw (const ARDOUR::TempoMap::BBTPointList::const_iterator& begin,
// Create a new line // Create a new line
} else if (_lines.size() < needed || _lines.size() < MAX_CACHED_LINES) { } else if (_lines.size() < needed || _lines.size() < MAX_CACHED_LINES) {
//cout << "*** CREATING LINE" << endl; //cout << "*** CREATING LINE" << endl;
assert(_lines.find(xpos) == _lines.end()); /* if we already have a line there ... don't sweat it */
line = new ArdourCanvas::SimpleLine (*_group); if (_lines.find (xpos) == _lines.end()) {
line->property_x1() = xpos; line = new ArdourCanvas::SimpleLine (*_group);
line->property_x2() = xpos; line->property_x1() = xpos;
line->property_y1() = 0.0; line->property_x2() = xpos;
line->property_y2() = _height; line->property_y1() = 0.0;
line->property_color_rgba() = color; line->property_y2() = _height;
_lines.insert(make_pair(xpos, line)); line->property_color_rgba() = color;
inserted_last_time = true; _lines.insert(make_pair(xpos, line));
inserted_last_time = true;
}
// Steal from the left // Steal from the left
} else { } else {
//cout << "*** STEALING FROM LEFT" << endl; //cout << "*** STEALING FROM LEFT" << endl;
assert(_lines.find(xpos) == _lines.end()); if (_lines.find (xpos) == _lines.end()) {
Lines::iterator steal = _lines.begin(); Lines::iterator steal = _lines.begin();
double const x = steal->first; double const x = steal->first;
line = steal->second; line = steal->second;
_lines.erase(steal); _lines.erase(steal);
line->property_color_rgba() = color; line->property_color_rgba() = color;
line->property_x1() = xpos; line->property_x1() = xpos;
line->property_x2() = xpos; line->property_x2() = xpos;
_lines.insert(make_pair(xpos, line)); _lines.insert(make_pair(xpos, line));
inserted_last_time = true; // search next time inserted_last_time = true; // search next time
invalidated = true; invalidated = true;
// Shift clean range right // Shift clean range right
_clean_left = max(_clean_left, x); _clean_left = max(_clean_left, x);
_clean_right = max(_clean_right, xpos); _clean_right = max(_clean_right, xpos);
}
} }
} }