+ 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;