+
+bool
+EditorSummary::on_scroll_event (GdkEventScroll* ev)
+{
+ /* mouse wheel */
+
+ pair<double, double> xr;
+ pair<double, double> yr;
+ get_editor (&xr, &yr);
+ double x = xr.first;
+ double y = yr.first;
+
+ double amount = 8;
+
+ if (Keyboard::modifier_state_contains (ev->state, Keyboard::SecondaryModifier)) {
+ amount = 64;
+ } else if (Keyboard::modifier_state_contains (ev->state, Keyboard::TertiaryModifier)) {
+ amount = 1;
+ }
+
+ if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
+
+ /* primary-wheel == left-right scrolling */
+
+ if (ev->direction == GDK_SCROLL_UP) {
+ x += amount;
+ } else if (ev->direction == GDK_SCROLL_DOWN) {
+ x -= amount;
+ }
+
+ } else {
+
+ if (ev->direction == GDK_SCROLL_DOWN) {
+ y += amount;
+ } else if (ev->direction == GDK_SCROLL_UP) {
+ y -= amount;
+ } else if (ev->direction == GDK_SCROLL_LEFT) {
+ x -= amount;
+ } else if (ev->direction == GDK_SCROLL_RIGHT) {
+ x += amount;
+ }
+ }
+
+ set_editor (x, y);
+ return true;
+}
+
+/** Set the editor to display a x range with the left at a given position
+ * and a y range with the top at a given position.
+ * x and y parameters are specified in summary coordinates.
+ * Zoom is not changed in either direction.
+ */
+void
+EditorSummary::set_editor (double const x, double const y)
+{
+ if (_editor->pending_visual_change.idle_handler_id >= 0) {
+
+ /* As a side-effect, the Editor's visual change idle handler processes
+ pending GTK events. Hence this motion notify handler can be called
+ in the middle of a visual change idle handler, and if this happens,
+ the queue_visual_change calls below modify the variables that the
+ idle handler is working with. This causes problems. Hence this
+ check. It ensures that we won't modify the pending visual change
+ while a visual change idle handler is in progress. It's not perfect,
+ as it also means that we won't change these variables if an idle handler
+ is merely pending but not executing. But c'est la vie.
+ */
+
+ return;
+ }
+
+ set_editor_x (x);
+ set_editor_y (y);
+}
+
+/** Set the editor to display a given x range and a y range with the top at a given position.
+ * The editor's x zoom is adjusted if necessary, but the y zoom is not changed.
+ * x and y parameters are specified in summary coordinates.
+ */
+void
+EditorSummary::set_editor (pair<double,double> const & x, double const y)
+{
+ if (_editor->pending_visual_change.idle_handler_id >= 0) {
+ /* see comment in other set_editor () */
+ return;
+ }
+
+ set_editor_x (x);
+ set_editor_y (y);
+}
+
+/** Set the editor to display given x and y ranges. x zoom and track heights are
+ * adjusted if necessary.
+ * x and y parameters are specified in summary coordinates.
+ */
+void
+EditorSummary::set_editor (pair<double,double> const & x, pair<double, double> const & y)
+{
+ if (_editor->pending_visual_change.idle_handler_id >= 0) {
+ /* see comment in other set_editor () */
+ return;
+ }
+
+ set_editor_x (x);
+ set_editor_y (y);
+}
+
+/** Set the left of the x range visible in the editor.
+ * Caller should have checked that Editor::pending_visual_change.idle_handler_id is < 0
+ * @param x new x left position in summary coordinates.
+ */
+void
+EditorSummary::set_editor_x (double const x)
+{
+ _editor->reset_x_origin (x / _x_scale + _start);
+}
+
+/** Set the x range visible in the editor.
+ * Caller should have checked that Editor::pending_visual_change.idle_handler_id is < 0
+ * @param x new x range in summary coordinates.
+ */
+void
+EditorSummary::set_editor_x (pair<double, double> const & x)
+{
+ _editor->reset_x_origin (x.first / _x_scale + _start);
+
+ double const nx = (
+ ((x.second - x.first) / _x_scale) /
+ _editor->frame_to_unit (_editor->current_page_frames())
+ );
+
+ if (nx != _editor->get_current_zoom ()) {
+ _editor->reset_zoom (nx);
+ }
+}
+
+/** Set the top of the y range visible in the editor.
+ * Caller should have checked that Editor::pending_visual_change.idle_handler_id is < 0
+ * @param y new editor top in summary coodinates.
+ */
+void
+EditorSummary::set_editor_y (double const y)
+{
+ double y1 = summary_y_to_editor (y);
+ double const eh = _editor->canvas_height() - _editor->get_canvas_timebars_vsize ();
+ double y2 = y1 + eh;
+
+ double const full_editor_height = _editor->full_canvas_height - _editor->get_canvas_timebars_vsize();
+
+ if (y2 > full_editor_height) {
+ y1 -= y2 - full_editor_height;
+ }
+
+ if (y1 < 0) {
+ y1 = 0;
+ }
+
+ _editor->reset_y_origin (y1);
+}
+
+/** Set the y range visible in the editor. This is achieved by scaling track heights,
+ * if necessary.
+ * Caller should have checked that Editor::pending_visual_change.idle_handler_id is < 0
+ * @param y new editor range in summary coodinates.
+ */
+void
+EditorSummary::set_editor_y (pair<double, double> const & y)
+{
+ /* Compute current height of tracks between y.first and y.second. We add up
+ the total height into `total_height' and the height of complete tracks into
+ `scale height'.
+ */
+
+ /* Copy of target range for use below */
+ pair<double, double> yc = y;
+ /* Total height of all tracks */
+ double total_height = 0;
+ /* Height of any parts of tracks that aren't fully in the desired range */
+ double partial_height = 0;
+ /* Height of any tracks that are fully in the desired range */
+ double scale_height = 0;
+
+ _editor->_routes->suspend_redisplay ();
+
+ for (TrackViewList::const_iterator i = _editor->track_views.begin(); i != _editor->track_views.end(); ++i) {
+
+ if ((*i)->hidden()) {
+ continue;
+ }
+
+ double const h = (*i)->effective_height ();
+ total_height += h;
+
+ if (yc.first > 0 && yc.first < _track_height) {
+ partial_height += (_track_height - yc.first) * h / _track_height;
+ } else if (yc.first <= 0 && yc.second >= _track_height) {
+ scale_height += h;
+ } else if (yc.second > 0 && yc.second < _track_height) {
+ partial_height += yc.second * h / _track_height;
+ break;
+ }
+
+ yc.first -= _track_height;
+ yc.second -= _track_height;
+ }
+
+ /* Height that we will use for scaling; use the whole editor height unless there are not
+ enough tracks to fill it.
+ */
+ double const ch = min (total_height, _editor->canvas_height() - _editor->get_canvas_timebars_vsize());
+
+ /* hence required scale factor of the complete tracks to fit the required y range;
+ the amount of space they should take up divided by the amount they currently take up.
+ */
+ double const scale = (ch - partial_height) / scale_height;
+
+ yc = y;
+
+ /* Scale complete tracks within the range to make it fit */
+
+ for (TrackViewList::const_iterator i = _editor->track_views.begin(); i != _editor->track_views.end(); ++i) {
+
+ if ((*i)->hidden()) {
+ continue;
+ }
+
+ if (yc.first <= 0 && yc.second >= _track_height) {
+ (*i)->set_height (max (TimeAxisView::preset_height (HeightSmall), (uint32_t) ((*i)->effective_height() * scale)));
+ }
+
+ yc.first -= _track_height;
+ yc.second -= _track_height;
+ }
+
+ _editor->_routes->resume_redisplay ();
+
+ set_editor_y (y.first);
+}
+
+void
+EditorSummary::playhead_position_changed (framepos_t p)
+{
+ if (_session && int (p * _x_scale) != int (_last_playhead)) {
+ set_overlays_dirty ();
+ }
+}
+
+double
+EditorSummary::summary_y_to_editor (double y) const
+{
+ double ey = 0;
+ for (TrackViewList::const_iterator i = _editor->track_views.begin (); i != _editor->track_views.end(); ++i) {
+
+ if ((*i)->hidden()) {
+ continue;
+ }
+
+ double const h = (*i)->effective_height ();
+ if (y < _track_height) {
+ /* in this track */
+ return ey + y * h / _track_height;
+ }
+
+ ey += h;
+ y -= _track_height;
+ }
+
+ return ey;
+}
+
+double
+EditorSummary::editor_y_to_summary (double y) const
+{
+ double sy = 0;
+ for (TrackViewList::const_iterator i = _editor->track_views.begin (); i != _editor->track_views.end(); ++i) {
+
+ if ((*i)->hidden()) {
+ continue;
+ }
+
+ double const h = (*i)->effective_height ();
+ if (y < h) {
+ /* in this track */
+ return sy + y * _track_height / h;
+ }
+
+ sy += _track_height;
+ y -= h;
+ }
+
+ return sy;
+}
+
+void
+EditorSummary::routes_added (list<RouteTimeAxisView*> const & r)
+{
+ /* Connect to gui_changed() on the routes so that we know when their colour has changed */
+ for (list<RouteTimeAxisView*>::const_iterator i = r.begin(); i != r.end(); ++i) {
+ (*i)->route()->gui_changed.connect (*this, invalidator (*this), ui_bind (&EditorSummary::route_gui_changed, this, _1), gui_context ());
+ }
+
+ set_dirty ();
+}
+
+void
+EditorSummary::route_gui_changed (string c)
+{
+ if (c == "color") {
+ set_dirty ();
+ }
+}