introduce GUIObjectState; massive, pervasive changes in visibility and height managem...
[ardour.git] / gtk2_ardour / editor.cc
index dcf97ffaa826f29dfd7bd546eedd2ae8307ba5f3..814ea66b3dd78dffc8e5c47328dcdc08a8382105 100644 (file)
 
 #include "control_protocol/control_protocol.h"
 
-#include "editor.h"
-#include "debug.h"
-#include "keyboard.h"
-#include "marker.h"
-#include "playlist_selector.h"
+#include "actions.h"
+#include "actions.h"
+#include "analysis_window.h"
+#include "audio_clock.h"
 #include "audio_region_view.h"
-#include "rgb_macros.h"
-#include "selection.h"
 #include "audio_streamview.h"
-#include "time_axis_view.h"
 #include "audio_time_axis.h"
-#include "utils.h"
-#include "crossfade_view.h"
+#include "automation_time_axis.h"
+#include "bundle_manager.h"
 #include "canvas-noevent-text.h"
-#include "editing.h"
-#include "public_editor.h"
-#include "crossfade_edit.h"
 #include "canvas_impl.h"
-#include "actions.h"
-#include "sfdb_ui.h"
-#include "gui_thread.h"
-#include "simpleline.h"
-#include "rhythm_ferret.h"
-#include "actions.h"
-#include "tempo_lines.h"
-#include "analysis_window.h"
-#include "bundle_manager.h"
-#include "global_port_matrix.h"
+#include "crossfade_edit.h"
+#include "crossfade_view.h"
+#include "debug.h"
+#include "editing.h"
+#include "editor.h"
+#include "editor_cursors.h"
 #include "editor_drag.h"
 #include "editor_group_tabs.h"
-#include "automation_time_axis.h"
-#include "editor_routes.h"
-#include "midi_time_axis.h"
-#include "mixer_strip.h"
-#include "editor_route_groups.h"
-#include "editor_regions.h"
 #include "editor_locations.h"
+#include "editor_regions.h"
+#include "editor_route_groups.h"
+#include "editor_routes.h"
 #include "editor_snapshots.h"
 #include "editor_summary.h"
-#include "region_layering_order_editor.h"
+#include "global_port_matrix.h"
+#include "gui_object.h"
+#include "gui_thread.h"
+#include "keyboard.h"
+#include "marker.h"
+#include "midi_time_axis.h"
+#include "mixer_strip.h"
 #include "mouse_cursors.h"
-#include "editor_cursors.h"
+#include "playlist_selector.h"
+#include "public_editor.h"
+#include "region_layering_order_editor.h"
+#include "rgb_macros.h"
+#include "rhythm_ferret.h"
+#include "selection.h"
+#include "sfdb_ui.h"
+#include "simpleline.h"
+#include "tempo_lines.h"
+#include "time_axis_view.h"
+#include "utils.h"
 
 #include "i18n.h"
 
@@ -260,7 +262,7 @@ Editor::Editor ()
 
          /* tool bar related */
 
-       , zoom_range_clock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, false, true)
+       , zoom_range_clock (new AudioClock (X_("zoomrange"), false, X_("ZoomRangeClock"), true, false, true))
 
        , toolbar_selection_clock_table (2,3)
 
@@ -276,7 +278,7 @@ Editor::Editor ()
 
          /* nudge */
 
-       , nudge_clock (X_("nudge"), false, X_("NudgeClock"), true, false, true)
+       , nudge_clock (new AudioClock (X_("nudge"), false, X_("NudgeClock"), true, false, true))
        , meters_running(false)
        , _pending_locate_request (false)
        , _pending_initial_locate (false)
@@ -387,7 +389,7 @@ Editor::Editor ()
 
        zoom_focus = ZoomFocusLeft;
        set_zoom_focus (ZoomFocusLeft);
-       zoom_range_clock.ValueChanged.connect (sigc::mem_fun(*this, &Editor::zoom_adjustment_changed));
+       zoom_range_clock->ValueChanged.connect (sigc::mem_fun(*this, &Editor::zoom_adjustment_changed));
 
        bbt_label.set_name ("EditorTimeButton");
        bbt_label.set_size_request (-1, (int)timebar_height);
@@ -896,14 +898,14 @@ Editor::zoom_adjustment_changed ()
                return;
        }
 
-       double fpu = zoom_range_clock.current_duration() / _canvas_width;
+       double fpu = zoom_range_clock->current_duration() / _canvas_width;
 
        if (fpu < 1.0) {
                fpu = 1.0;
-               zoom_range_clock.set ((framepos_t) floor (fpu * _canvas_width));
+               zoom_range_clock->set ((framepos_t) floor (fpu * _canvas_width));
        } else if (fpu > _session->current_end_frame() / _canvas_width) {
                fpu = _session->current_end_frame() / _canvas_width;
-               zoom_range_clock.set ((framepos_t) floor (fpu * _canvas_width));
+               zoom_range_clock->set ((framepos_t) floor (fpu * _canvas_width));
        }
 
        temporal_zoom (fpu);
@@ -1084,9 +1086,9 @@ Editor::set_session (Session *t)
                return;
        }
 
-       zoom_range_clock.set_session (_session);
+       zoom_range_clock->set_session (_session);
        _playlist_selector->set_session (_session);
-       nudge_clock.set_session (_session);
+       nudge_clock->set_session (_session);
        _summary->set_session (_session);
        _group_tabs->set_session (_session);
        _route_groups->set_session (_session);
@@ -1145,11 +1147,11 @@ Editor::set_session (Session *t)
                bbt.beats = 0;
                bbt.ticks = 120;
                framepos_t pos = _session->tempo_map().bbt_duration_at (0, bbt, 1);
-               nudge_clock.set_mode(AudioClock::BBT);
-               nudge_clock.set (pos, true, 0, AudioClock::BBT);
+               nudge_clock->set_mode(AudioClock::BBT);
+               nudge_clock->set (pos, true, 0, AudioClock::BBT);
 
        } else {
-               nudge_clock.set (_session->frame_rate() * 5, true, 0, AudioClock::Timecode); // default of 5 seconds
+               nudge_clock->set (_session->frame_rate() * 5, true, 0, AudioClock::Timecode); // default of 5 seconds
        }
 
        playhead_cursor->canvas_item.show ();
@@ -2129,7 +2131,7 @@ Editor::set_state (const XMLNode& node, int /*version*/)
 {
        const XMLProperty* prop;
        XMLNode* geometry;
-       int x, y, xoff, yoff;
+       int x, y;
        Gdk::Geometry g;
 
        if ((prop = node.property ("id")) != 0) {
@@ -2140,8 +2142,6 @@ Editor::set_state (const XMLNode& node, int /*version*/)
        g.base_height = default_height;
        x = 1;
        y = 1;
-       xoff = 0;
-       yoff = 21;
 
        if ((geometry = find_named_node (node, "geometry")) != 0) {
 
@@ -2173,19 +2173,6 @@ Editor::set_state (const XMLNode& node, int /*version*/)
                if (prop) {
                        y = atoi (prop->value());
                }
-
-               if ((prop = geometry->property ("x_off")) == 0) {
-                       prop = geometry->property ("x-off");
-               }
-               if (prop) {
-                       xoff = atoi (prop->value());
-               }
-               if ((prop = geometry->property ("y_off")) == 0) {
-                       prop = geometry->property ("y-off");
-               }
-               if (prop) {
-                       yoff = atoi (prop->value());
-               }
        }
 
        set_default_size (g.base_width, g.base_height);
@@ -2367,9 +2354,8 @@ Editor::get_state ()
        if (is_realized()) {
                Glib::RefPtr<Gdk::Window> win = get_window();
 
-               int x, y, xoff, yoff, width, height;
+               int x, y, width, height;
                win->get_root_origin(x, y);
-               win->get_position(xoff, yoff);
                win->get_size(width, height);
 
                XMLNode* geometry = new XMLNode ("geometry");
@@ -2382,10 +2368,6 @@ Editor::get_state ()
                geometry->add_property("x-pos", string(buf));
                snprintf(buf, sizeof(buf), "%d", y);
                geometry->add_property("y-pos", string(buf));
-               snprintf(buf, sizeof(buf), "%d", xoff);
-               geometry->add_property("x-off", string(buf));
-               snprintf(buf, sizeof(buf), "%d", yoff);
-               geometry->add_property("y-off", string(buf));
                snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&edit_pane)->gobj()));
                geometry->add_property("edit-horizontal-pane-pos", string(buf));
                geometry->add_property("notebook-shrunk", _notebook_shrunk ? "1" : "0");
@@ -2907,7 +2889,7 @@ Editor::setup_toolbar ()
 
        nudge_box->pack_start (nudge_backward_button, false, false);
        nudge_box->pack_start (nudge_forward_button, false, false);
-       nudge_box->pack_start (nudge_clock, false, false);
+       nudge_box->pack_start (*nudge_clock, false, false);
 
 
        /* Pack everything in... */
@@ -3526,7 +3508,6 @@ Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
        XMLProperty* prop;
        char buf[32];
        XMLNode* node = ARDOUR_UI::instance()->editor_settings();
-       int width, height;
 
        enum Pane {
                Horizontal = 0x1,
@@ -3535,22 +3516,7 @@ Editor::pane_allocation_handler (Allocation &alloc, Paned* which)
 
        static Pane done;
 
-       XMLNode* geometry;
-
-       width = default_width;
-       height = default_height;
-
-       if ((geometry = find_named_node (*node, "geometry")) != 0) {
-
-               prop = geometry->property ("x-size");
-               if (prop) {
-                       width = atoi (prop->value());
-               }
-               prop = geometry->property ("y-size");
-               if (prop) {
-                       height = atoi (prop->value());
-               }
-       }
+       XMLNode* geometry = find_named_node (*node, "geometry");
 
        if (which == static_cast<Paned*> (&edit_pane)) {
 
@@ -3821,7 +3787,7 @@ Editor::get_nudge_distance (framepos_t pos, framecnt_t& next)
 {
        framecnt_t ret;
 
-       ret = nudge_clock.current_duration (pos);
+       ret = nudge_clock->current_duration (pos);
        next = ret + 1; /* XXXX fix me */
 
        return ret;
@@ -4128,6 +4094,16 @@ Editor::reposition_and_zoom (framepos_t frame, double fpu)
        }
 }
 
+Editor::VisualState::VisualState ()
+       : gui_state (new GUIObjectState)
+{
+}
+
+Editor::VisualState::~VisualState ()
+{
+       delete gui_state;
+}
+
 Editor::VisualState*
 Editor::current_visual_state (bool with_tracks)
 {
@@ -4137,10 +4113,8 @@ Editor::current_visual_state (bool with_tracks)
        vs->leftmost_frame = leftmost_frame;
        vs->zoom_focus = zoom_focus;
 
-       if (with_tracks) {
-               for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
-                       vs->track_states.push_back (TAVState ((*i), &(*i)->get_state()));
-               }
+       if (with_tracks) {      
+               *(vs->gui_state) = *ARDOUR_UI::instance()->gui_object_state;
        }
 
        return vs;
@@ -4195,22 +4169,14 @@ Editor::use_visual_state (VisualState& vs)
 
        set_zoom_focus (vs.zoom_focus);
        reposition_and_zoom (vs.leftmost_frame, vs.frames_per_unit);
+       
+       *ARDOUR_UI::instance()->gui_object_state = *vs.gui_state;
 
-       for (list<TAVState>::iterator i = vs.track_states.begin(); i != vs.track_states.end(); ++i) {
-               TrackViewList::iterator t;
-
-               /* check if the track still exists - it could have been deleted */
-
-               if ((t = find (track_views.begin(), track_views.end(), i->first)) != track_views.end()) {
-                       (*t)->set_state (*(i->second), Stateful::loading_state_version);
-               }
-       }
-
-
-       if (!vs.track_states.empty()) {
-               _routes->update_visibility ();
+       for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {    
+               (*i)->reset_visual_state ();
        }
 
+       _routes->update_visibility ();
        _routes->resume_redisplay ();
 
        no_save_visual = false;
@@ -4254,8 +4220,8 @@ Editor::post_zoom ()
 
        framepos_t frames = (framepos_t) floor (frames_per_unit * _canvas_width);
 
-       if (frames_per_unit != zoom_range_clock.current_duration()) {
-               zoom_range_clock.set (frames);
+       if (frames_per_unit != zoom_range_clock->current_duration()) {
+               zoom_range_clock->set (frames);
        }
 
        if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
@@ -4875,9 +4841,11 @@ Editor::handle_new_route (RouteList& routes)
                DataType dt = route->input()->default_type();
 
                if (dt == ARDOUR::DataType::AUDIO) {
-                       rtv = new AudioTimeAxisView (*this, _session, route, *track_canvas);
+                       rtv = new AudioTimeAxisView (*this, _session, *track_canvas);
+                       rtv->set_route (route);
                } else if (dt == ARDOUR::DataType::MIDI) {
-                       rtv = new MidiTimeAxisView (*this, _session, route, *track_canvas);
+                       rtv = new MidiTimeAxisView (*this, _session, *track_canvas);
+                       rtv->set_route (route);
                } else {
                        throw unknown_type();
                }
@@ -5349,8 +5317,8 @@ Editor::session_going_away ()
        }
        track_views.clear ();
 
-       zoom_range_clock.set_session (0);
-       nudge_clock.set_session (0);
+       zoom_range_clock->set_session (0);
+       nudge_clock->set_session (0);
 
        editor_list_button.set_active(false);
        editor_list_button.set_sensitive(false);