- xpos = rint(((framepos_t)(*i).frame) / (double)samples_per_pixel);
-
- li = _lines.lower_bound(xpos); // first line >= xpos
-
- line = (li != _lines.end()) ? li->second : 0;
- assert(!line || line->x0() == li->first);
-
- Lines::iterator next = li;
- if (next != _lines.end())
- ++next;
-
- exhausted = (next == _lines.end());
-
- // Hooray, line is perfect
- if (line && line->x0() == xpos) {
- if (li != _lines.end())
- ++li;
-
- line->set_outline_color (color);
-
- // Use existing line, moving if necessary
- } else if (!exhausted) {
- Lines::iterator steal = _lines.end();
- --steal;
-
- // Steal from the right
- if (left->first > needed_left && li != steal && steal->first > needed_right) {
- // cerr << "*** STEALING FROM RIGHT" << endl;
- double const x = steal->first;
- line = steal->second;
- _lines.erase(steal);
- line->set_x0 (xpos);
- line->set_x1 (xpos);
- line->set_outline_color (color);
- _lines.insert(make_pair(xpos, line));
- invalidated = true;
-
- // Shift clean range left
- _clean_left = min(_clean_left, xpos);
- _clean_right = min(_clean_right, x);
-
- // Move this line to where we need it
- } else {
- Lines::iterator existing = _lines.find(xpos);
- if (existing != _lines.end()) {
- //cout << "*** EXISTING LINE" << endl;
- li = existing;
- li->second->set_outline_color (color);
- } else {
- //cout << "*** MOVING LINE" << endl;
- const double x1 = line->x0();
- const bool was_clean = x1 >= _clean_left && x1 <= _clean_right;
- invalidated = invalidated || was_clean;
- // Invalidate clean portion (XXX: too harsh?)
- _clean_left = needed_left;
- _clean_right = needed_right;
- _lines.erase(li);
- line->set_outline_color (color);
- line->set_x0 (xpos);
- line->set_x1 (xpos);
- _lines.insert(make_pair(xpos, line));
- }
- }
-
- // Create a new line
- } else if (_lines.size() < needed || _lines.size() < MAX_CACHED_LINES) {
- // cerr << "*** CREATING LINE" << endl;
- /* if we already have a line there ... don't sweat it */
- if (_lines.find (xpos) == _lines.end()) {
- line = new ArdourCanvas::Line (_group);
- line->set_x0 (xpos);
- line->set_x1 (xpos);
- line->set_y0 (0.0);
- line->set_y1 (ArdourCanvas::COORD_MAX);
- line->set_outline_color (color);
- _lines.insert(make_pair(xpos, line));
- }
-
- // Steal from the left