Merged with trunk R1311.
authorDavid Robillard <d@drobilla.net>
Thu, 11 Jan 2007 20:36:35 +0000 (20:36 +0000)
committerDavid Robillard <d@drobilla.net>
Thu, 11 Jan 2007 20:36:35 +0000 (20:36 +0000)
git-svn-id: svn://localhost/ardour2/branches/midi@1312 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/ardour_ui.cc
gtk2_ardour/editor.cc
gtk2_ardour/editor.h
gtk2_ardour/editor_canvas.cc
gtk2_ardour/editor_imageframe.cc
gtk2_ardour/editor_ops.cc
gtk2_ardour/public_editor.h

index 07d322a1fb70f5a335c1c077c6726f200dca57ca..3ecc618eba0b4d325ed082c70a4dfa7c5bc0042c 100644 (file)
@@ -994,7 +994,7 @@ ARDOUR_UI::transport_goto_start ()
                */
                
                if (editor) {
-                       editor->reposition_x_origin (session->current_start_frame());
+                       editor->reset_x_origin (session->current_start_frame());
                }
        }
 }
@@ -1011,7 +1011,7 @@ ARDOUR_UI::transport_goto_zero ()
                */
                
                if (editor) {
-                       editor->reposition_x_origin (0);
+                       editor->reset_x_origin (0);
                }
        }
 }
@@ -1028,7 +1028,7 @@ ARDOUR_UI::transport_goto_end ()
                */
                
                if (editor) {
-                       editor->reposition_x_origin (frame);
+                       editor->reset_x_origin (frame);
                }
        }
 }
index 621b76a1e19b43b16a9925040f0921c81a8bb9e7..77c731178c2089f62eccaa129bb4ed409cb143fd 100644 (file)
@@ -292,7 +292,6 @@ Editor::Editor (AudioEngine& eng)
        new_transport_marker_menu = 0;
        editor_mixer_strip_width = Wide;
        show_editor_mixer_when_tracks_arrive = false;
-       repos_zoom_queued = false;
        region_edit_menu_split_item = 0;
        temp_location = 0;
        region_edit_menu_split_multichannel_item = 0;
@@ -323,7 +322,7 @@ Editor::Editor (AudioEngine& eng)
        
        set_mouse_mode (MouseObject, true);
 
-       frames_per_unit = 2048; /* too early to use set_frames_per_unit */
+       frames_per_unit = 2048; /* too early to use reset_zoom () */
        reset_hscrollbar_stepping ();
        
        zoom_focus = ZoomFocusLeft;
@@ -825,65 +824,6 @@ Editor::tie_vertical_scrolling ()
        edit_cursor->set_y_axis(y1);
 }
 
-void
-Editor::set_frames_per_unit (double fpu)
-{
-       nframes_t frames;
-
-       if (fpu == frames_per_unit) {
-               return;
-       }
-
-       if (fpu < 2.0) {
-               fpu = 2.0;
-       }
-
-       // convert fpu to frame count
-
-       frames = (nframes_t) floor (fpu * canvas_width);
-       
-       /* don't allow zooms that fit more than the maximum number
-          of frames into an 800 pixel wide space.
-       */
-
-       if (max_frames / fpu < 800.0) {
-               return;
-       }
-
-       if (fpu == frames_per_unit) {
-               return;
-       }
-
-       frames_per_unit = fpu;
-
-       if (frames != zoom_range_clock.current_duration()) {
-               zoom_range_clock.set (frames);
-       }
-
-       if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
-               if (!selection->tracks.empty()) {
-                       for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
-                               (*i)->reshow_selection (selection->time);
-                       }
-               } else {
-                       for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
-                               (*i)->reshow_selection (selection->time);
-                       }
-               }
-       }
-
-       ZoomChanged (); /* EMIT_SIGNAL */
-
-       reset_hscrollbar_stepping ();
-       reset_scrolling_region ();
-       
-       if (edit_cursor) edit_cursor->set_position (edit_cursor->current_frame);
-       if (playhead_cursor) playhead_cursor->set_position (playhead_cursor->current_frame);
-
-       instant_save ();
-
-}
-
 void
 Editor::instant_save ()
 {
@@ -898,28 +838,6 @@ Editor::instant_save ()
        }
 }
 
-void
-Editor::reposition_x_origin (nframes_t frame)
-{
-       cerr << "repsosition to " << frame << endl;
-
-       if (frame != leftmost_frame) {
-               leftmost_frame = frame;
-               
-               nframes_t rightmost_frame = leftmost_frame + current_page_frames ();
-
-               if (rightmost_frame > last_canvas_frame) {
-                       last_canvas_frame = rightmost_frame;
-                       reset_scrolling_region ();
-               }
-
-               horizontal_adjustment.set_value (frame/frames_per_unit);
-       } else {
-               update_fixed_rulers();
-               tempo_map_changed (Change (0));
-       }
-}
-
 void
 Editor::edit_cursor_clock_changed()
 {
@@ -975,9 +893,9 @@ Editor::control_scroll (float fraction)
 
        if (target > (current_page_frames() / 2)) {
                /* try to center PH in window */
-               reposition_x_origin (target - (current_page_frames()/2));
+               reset_x_origin (target - (current_page_frames()/2));
        } else {
-               reposition_x_origin (0);
+               reset_x_origin (0);
        }
 
        /* cancel the existing */
@@ -996,36 +914,6 @@ Editor::deferred_control_scroll (nframes_t target)
        return false;
 }
 
-void 
-Editor::canvas_horizontally_scrolled ()
-{
-
-       leftmost_frame = (nframes_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
-       update_fixed_rulers ();
-       tempo_map_changed (Change (0));
-
-}
-
-void
-Editor::reposition_and_zoom (nframes_t frame, double nfpu)
-{
-       if (!repos_zoom_queued) {
-               repos_zoom_queued = true;
-               Glib::signal_idle().connect (bind (mem_fun(*this, &Editor::deferred_reposition_and_zoom), frame, nfpu));
-       }
-}
-
-gint
-Editor::deferred_reposition_and_zoom (nframes_t frame, double nfpu)
-{
-
-       set_frames_per_unit (nfpu);
-       reposition_x_origin  (frame);
-       repos_zoom_queued = false;
-       
-       return FALSE;
-}
-
 void
 Editor::on_realize ()
 {
@@ -1083,7 +971,7 @@ Editor::center_screen_internal (nframes_t frame, float page)
                frame = 0;
        }
 
-    reposition_x_origin (frame);
+       reset_x_origin (frame);
 }
 
 void
@@ -2115,7 +2003,7 @@ Editor::set_state (const XMLNode& node)
        } else {
                playhead_cursor->set_position (0);
 
-               /* ::reposition_x_origin() doesn't work right here, since the old
+               /* reset_x_origin() doesn't work right here, since the old
                   position may be zero already, and it does nothing in such
                   circumstances.
                */
@@ -2136,7 +2024,7 @@ Editor::set_state (const XMLNode& node)
        }
 
        if ((prop = node.property ("zoom"))) {
-               set_frames_per_unit (PBD::atof (prop->value()));
+               reset_zoom (PBD::atof (prop->value()));
        }
 
        if ((prop = node.property ("snap-to"))) {
@@ -4251,3 +4139,156 @@ Editor::on_key_press_event (GdkEventKey* ev)
        return key_press_focus_accelerator_handler (*this, ev);
 }
 
+void
+Editor::reset_x_origin (nframes_t frame)
+{
+       queue_visual_change (frame);
+}
+
+void
+Editor::reset_zoom (double fpu)
+{
+       queue_visual_change (fpu);
+}
+
+void
+Editor::reposition_and_zoom (nframes_t frame, double fpu)
+{
+       reset_x_origin (frame);
+       reset_zoom (fpu);
+}
+
+void
+Editor::set_frames_per_unit (double fpu)
+{
+       nframes_t frames;
+
+       /* this is the core function that controls the zoom level of the canvas. it is called
+          whenever one or more calls are made to reset_zoom(). it executes in an idle handler.
+       */
+
+       if (fpu == frames_per_unit) {
+               return;
+       }
+
+       if (fpu < 2.0) {
+               fpu = 2.0;
+       }
+
+       // convert fpu to frame count
+
+       frames = (nframes_t) floor (fpu * canvas_width);
+       
+       /* don't allow zooms that fit more than the maximum number
+          of frames into an 800 pixel wide space.
+       */
+
+       if (max_frames / fpu < 800.0) {
+               return;
+       }
+
+       if (fpu == frames_per_unit) {
+               return;
+       }
+
+       frames_per_unit = fpu;
+
+       if (frames != zoom_range_clock.current_duration()) {
+               zoom_range_clock.set (frames);
+       }
+
+       if (mouse_mode == MouseRange && selection->time.start () != selection->time.end_frame ()) {
+               if (!selection->tracks.empty()) {
+                       for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+                               (*i)->reshow_selection (selection->time);
+                       }
+               } else {
+                       for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
+                               (*i)->reshow_selection (selection->time);
+                       }
+               }
+       }
+
+       ZoomChanged (); /* EMIT_SIGNAL */
+
+       reset_hscrollbar_stepping ();
+       reset_scrolling_region ();
+       
+       if (edit_cursor) edit_cursor->set_position (edit_cursor->current_frame);
+       if (playhead_cursor) playhead_cursor->set_position (playhead_cursor->current_frame);
+
+       instant_save ();
+}
+
+void 
+Editor::canvas_horizontally_scrolled ()
+{
+       /* this is the core function that controls horizontal scrolling of the canvas. it is called
+          whenever the horizontal_adjustment emits its "value_changed" signal. it executes in an
+          idle handler.
+       */
+
+       leftmost_frame = (nframes_t) floor (horizontal_adjustment.get_value() * frames_per_unit);
+       nframes_t rightmost_frame = leftmost_frame + current_page_frames ();
+       
+       if (rightmost_frame > last_canvas_frame) {
+               last_canvas_frame = rightmost_frame;
+               reset_scrolling_region ();
+       }
+       
+       update_fixed_rulers ();
+       tempo_map_changed (Change (0));
+}
+
+void
+Editor::queue_visual_change (nframes_t where)
+{
+       pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::TimeOrigin);
+       pending_visual_change.time_origin = where;
+
+       if (pending_visual_change.idle_handler_id < 0) {
+               pending_visual_change.idle_handler_id = g_idle_add (_idle_visual_changer, this);
+       }
+}
+
+void
+Editor::queue_visual_change (double fpu)
+{
+       pending_visual_change.pending = VisualChange::Type (pending_visual_change.pending | VisualChange::ZoomLevel);
+       pending_visual_change.frames_per_unit = fpu;
+
+       if (pending_visual_change.idle_handler_id < 0) {
+               pending_visual_change.idle_handler_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE, _idle_visual_changer, this, 0);
+       }
+}
+
+int
+Editor::_idle_visual_changer (void* arg)
+{
+       return static_cast<Editor*>(arg)->idle_visual_changer ();
+}
+
+int
+Editor::idle_visual_changer ()
+{
+       VisualChange::Type p = pending_visual_change.pending;
+
+       pending_visual_change.pending = (VisualChange::Type) 0;
+       pending_visual_change.idle_handler_id = -1;
+       
+       if (p & VisualChange::ZoomLevel) {
+               set_frames_per_unit (pending_visual_change.frames_per_unit);
+       }
+
+       if (p & VisualChange::TimeOrigin) {
+               if (pending_visual_change.time_origin != leftmost_frame) {
+                       horizontal_adjustment.set_value (pending_visual_change.time_origin/frames_per_unit);
+                       /* the signal handler will do the rest */
+               } else {
+                       update_fixed_rulers();
+                       tempo_map_changed (Change (0));
+               }
+       }
+
+       return 0;
+}
index 55866a608cb69e3a77b8daf0504a84b56818a846..c3c77c553bdb4a44116a64b1feedc120126da58c 100644 (file)
@@ -332,11 +332,13 @@ class Editor : public PublicEditor
        bool new_regionviews_display_gain () { return _new_regionviews_show_envelope; }
        void prepare_for_cleanup ();
 
-       void reposition_x_origin (nframes_t sample);
-
        void maximise_editing_space();
        void restore_editing_space();
 
+       void reset_x_origin (nframes_t);
+       void reset_zoom (double);
+       void reposition_and_zoom (nframes_t, double);
+
   protected:
        void map_transport_state ();
        void map_position_change (nframes_t);
@@ -678,10 +680,31 @@ class Editor : public PublicEditor
        void tie_vertical_scrolling ();
        void canvas_horizontally_scrolled ();
 
-       void reposition_and_zoom (nframes_t sample, double fpu);
-       gint deferred_reposition_and_zoom (nframes_t sample, double fpu);
+       struct VisualChange {
+           enum Type { 
+                   TimeOrigin = 0x1,
+                   ZoomLevel = 0x2
+           };
+
+           Type pending;
+           nframes_t time_origin;
+           double frames_per_unit;
+
+           int idle_handler_id;
+
+           VisualChange() : pending ((VisualChange::Type) 0), time_origin (0), frames_per_unit (0), idle_handler_id (-1) {}
+       };
+
+
+       VisualChange pending_visual_change;
+
+       static int _idle_visual_changer (void *arg);
+       int idle_visual_changer ();
+
+       void queue_visual_change (nframes_t);
+       void queue_visual_change (double);
+
        void end_location_changed (ARDOUR::Location*);
-       bool repos_zoom_queued;
 
        struct RegionListDisplayModelColumns : public Gtk::TreeModel::ColumnRecord {
            RegionListDisplayModelColumns() {
@@ -1799,7 +1822,6 @@ class Editor : public PublicEditor
        Glib::RefPtr<Gtk::Action>              redo_action;
 
        void history_changed ();
-
 };
 
 #endif /* __ardour_editor_h__ */
index 973598561ac183ba288ea099cf488a028459b9cc..417d4ab0c4cbdfc5d3facf0ff54f973ce4a46bc5 100644 (file)
@@ -635,7 +635,7 @@ Editor::autoscroll_canvas ()
        } 
 
        if (new_frame != leftmost_frame) {
-               reposition_x_origin (new_frame);
+               reset_x_origin (new_frame);
        }
 
        if (autoscroll_cnt == 50) { /* 0.5 seconds */
index a2606175dfb7b0e76a196e0ee6773830890fbc2b..84419dbe7ffc615fa380a647548788deef340d35 100644 (file)
@@ -107,7 +107,7 @@ Editor::scroll_timeaxis_to_imageframe_item(const TimeAxisViewItem* item)
                x_pos = item->get_position() - offset + (item->get_duration() / 2);
        }
        
-       reposition_x_origin (x_pos);
+       reset_x_origin (x_pos);
 }
 
 void
index d8889c1af7d58c2b3d7244b873f6a8638bdac9ae..aff997a1252b637ef8a9dd88e434a583892e3623 100644 (file)
@@ -926,7 +926,7 @@ Editor::scroll_backward (float pages)
                frame = leftmost_frame - cnt;
        }
 
-       reposition_x_origin (frame);
+       reset_x_origin (frame);
 }
 
 void
@@ -954,7 +954,7 @@ Editor::scroll_forward (float pages)
                frame = leftmost_frame + cnt;
        }
 
-       reposition_x_origin (frame);
+       reset_x_origin (frame);
 }
 
 void
index 8f307f61f2a4513d646fcb0a6040fc2e6489ac4f..a47ac606e80df65a6a73a1e9bfe0a34bd8cd2c74 100644 (file)
@@ -130,7 +130,7 @@ class PublicEditor : public Gtk::Window, public PBD::StatefulThingWithGoingAway
        virtual void scroll_tracks_up_line () = 0;
        virtual bool new_regionviews_display_gain () = 0;
        virtual void prepare_for_cleanup () = 0;
-       virtual void reposition_x_origin (nframes_t frame) = 0;
+       virtual void reset_x_origin (nframes_t frame) = 0;
        virtual void remove_last_capture () = 0;
        virtual void maximise_editing_space() = 0;
        virtual void restore_editing_space() = 0;