audun's tempo redraw fix; sort-of cache time axis view item name widths and avoid...
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 3 Apr 2007 02:05:34 +0000 (02:05 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 3 Apr 2007 02:05:34 +0000 (02:05 +0000)
git-svn-id: svn://localhost/ardour2/trunk@1657 d708f5d6-7413-0410-9779-e7cbd77b26cf

15 files changed:
gtk2_ardour/automation_line.cc
gtk2_ardour/automation_line.h
gtk2_ardour/automation_time_axis.cc
gtk2_ardour/automation_time_axis.h
gtk2_ardour/editor.cc
gtk2_ardour/editor.h
gtk2_ardour/editor_canvas.cc
gtk2_ardour/editor_rulers.cc
gtk2_ardour/editor_tempodisplay.cc
gtk2_ardour/ghostregion.cc
gtk2_ardour/ghostregion.h
gtk2_ardour/time_axis_view_item.cc
gtk2_ardour/time_axis_view_item.h
gtk2_ardour/utils.cc
gtk2_ardour/utils.h

index 4978a1ef68e14cde3752b87268450eb98c7cbad3..67f91e1ed474b0f0a00adce1e8b25f034fffb795 100644 (file)
@@ -1136,6 +1136,13 @@ AutomationLine::set_selected_points (PointSelection& points)
 
 }
 
+void AutomationLine::set_colors() {
+       set_line_color( color_map[cAutomationLine] );
+       for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
+               (*i)->show_color (false, !points_visible);
+       }
+}
+
 void
 AutomationLine::show_selection ()
 {
index 4942643b65d8bf2461572965ea4aacdec80a17ec..76afff5097a43cf62ce7359ac4bd0d29de5637be 100644 (file)
@@ -159,6 +159,7 @@ class AutomationLine : public sigc::trackable, public PBD::StatefulThingWithGoin
 
        XMLNode& get_state (void);
        int set_state (const XMLNode&);
+       void set_colors();
 
   protected:
 
index 69653c9c99c7ab26d98abb97022d815a1962ea66..0da3a38fdc64ffbb9790e750ba38d50239ddfbdb 100644 (file)
@@ -163,6 +163,7 @@ AutomationTimeAxisView::AutomationTimeAxisView (Session& s, boost::shared_ptr<Ro
        /* make sure labels etc. are correct */
 
        automation_state_changed ();
+       ColorChanged.connect (mem_fun (*this, &AutomationTimeAxisView::color_handler));
 }
 
 AutomationTimeAxisView::~AutomationTimeAxisView ()
@@ -787,6 +788,42 @@ AutomationTimeAxisView::exited ()
        hide_all_but_selected_control_points ();
 }
 
+void
+AutomationTimeAxisView::set_colors () {
+
+    for( list<GhostRegion *>::iterator i=ghosts.begin(); i != ghosts.end(); i++ ) {
+       (*i)->set_colors();
+    }
+    
+    for( vector<AutomationLine *>::iterator i=lines.begin(); i != lines.end(); i++ ) {
+       (*i)->set_colors();
+    }
+
+}
+
+void
+AutomationTimeAxisView::color_handler (ColorID id, uint32_t val) {
+    
+       switch (id) {
+       case cGhostTrackWave:
+       case cGhostTrackWaveClip:
+       case cGhostTrackZeroLine:
+
+       case cControlPoint:
+       case cControlPointFill:
+       case cControlPointOutline:
+       case cAutomationLine:
+               set_colors ();
+
+               break;
+
+       default: 
+               break;
+       }
+}
+
+
+
 void
 AutomationTimeAxisView::set_state (const XMLNode& node)
 {
index 0eb525f6c1805c2d083e8b100b19687b016779aa..f7c61942df0cd46f117f0179171e47be48e48414 100644 (file)
@@ -122,6 +122,9 @@ class AutomationTimeAxisView : public TimeAxisView {
        void entered ();
        void exited ();
 
+       void set_colors ();
+       void color_handler (ColorID, uint32_t);
+
        static Pango::FontDescription name_font;
        static bool have_name_font;
 };
index a62e193a628c5787484afae363948d8f135090ff..885b3027c455d06a3dd18ccd13ca9bfbfa45d00e 100644 (file)
@@ -1075,7 +1075,7 @@ Editor::connect_to_session (Session *t)
 
        session_connections.push_back (session->SMPTEOffsetChanged.connect (mem_fun(*this, &Editor::update_just_smpte)));
 
-       session_connections.push_back (session->tempo_map().StateChanged.connect (bind (mem_fun(*this, &Editor::tempo_map_changed), false)));
+       session_connections.push_back (session->tempo_map().StateChanged.connect (mem_fun(*this, &Editor::tempo_map_changed)));
 
        edit_groups_changed ();
 
@@ -3665,7 +3665,7 @@ Editor::idle_visual_changer ()
                        /* the signal handler will do the rest */
                } else {
                        update_fixed_rulers();
-                       tempo_map_changed (Change (0), true);
+                       redisplay_tempo (true);
                }
        }
 
index 20e6429aaec685c4e47d42f29ff36f2df63e8812..fd3ecee508fc593849ee34ebe788bd4d8dfb9a28 100644 (file)
@@ -1275,8 +1275,8 @@ class Editor : public PublicEditor
        void remove_metric_marks ();
        void draw_metric_marks (const ARDOUR::Metrics& metrics);
 
-       void tempo_map_changed (ARDOUR::Change, bool immediate_redraw);
-       void redisplay_tempo ();
+       void tempo_map_changed (ARDOUR::Change);
+       void redisplay_tempo (bool immediate_redraw);
        
        void snap_to (nframes_t& first, int32_t direction = 0, bool for_mark = false);
        uint32_t bbt_beat_subdivision;
index d9fe6f529fd2186cc1ac1d1c6a31f089c8d876c4..049f6f48b251e1969afeb44df6a080966b9a8dfc 100644 (file)
@@ -368,7 +368,7 @@ Editor::track_canvas_size_allocated ()
        }
                
        update_fixed_rulers();
-       tempo_map_changed (Change (0), true);
+       redisplay_tempo (true);
        
        Resized (); /* EMIT_SIGNAL */
 
@@ -723,6 +723,6 @@ Editor::canvas_horizontally_scrolled ()
        
        update_fixed_rulers ();
 
-       tempo_map_changed (Change (0), !_dragging_hscrollbar);
+       redisplay_tempo (!_dragging_hscrollbar);
 }
 
index 9dac8bc4c09ff2c42c4e099cb785cb9ae31b33ee..1a928002a8bafcd1944ef8b676a709204f789e74 100644 (file)
@@ -709,7 +709,7 @@ Editor::update_ruler_visibility ()
        
        update_fixed_rulers();
        //update_tempo_based_rulers();
-       tempo_map_changed(Change (0), false);
+       redisplay_tempo (false);
 
        time_canvas_event_box.show_all();
        time_button_frame.show_all();
index fc5117fcf5a94b5265d8dc92d9b77de00ac50a97..339c335fa3c8613712be6bf2dc175b68b08a1dbe 100644 (file)
@@ -93,13 +93,28 @@ Editor::draw_metric_marks (const Metrics& metrics)
 }
 
 void
-Editor::tempo_map_changed (Change ignored, bool immediate_redraw)
+Editor::tempo_map_changed (Change ignored)
 {
        if (!session) {
                return;
        }
 
-        ENSURE_GUI_THREAD(bind (mem_fun (*this, &Editor::tempo_map_changed), ignored, immediate_redraw));
+       ENSURE_GUI_THREAD(bind (mem_fun (*this, &Editor::tempo_map_changed), ignored));
+       
+       redisplay_tempo (false); // redraw rulers and measures
+       session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks); // redraw metric markers
+}
+
+/**
+ * This code was originally in tempo_map_changed, but this is called every time the canvas scrolls horizontally. 
+ * That's why this is moved in here. The new tempo_map_changed is called when the ARDOUR::TempoMap actually changed.
+ */
+void
+Editor::redisplay_tempo (bool immediate_redraw)
+{
+       if (!session) {
+               return;
+       }
 
        BBT_Time previous_beat, next_beat; // the beats previous to the leftmost frame and after the rightmost frame
 
@@ -152,11 +167,6 @@ Editor::tempo_map_changed (Change ignored, bool immediate_redraw)
        }
 }
 
-void
-Editor::redisplay_tempo ()
-{      
-}
-
 void
 Editor::hide_measures ()
 {
@@ -307,8 +317,6 @@ Editor::mouse_add_new_tempo_event (nframes_t frame)
        commit_reversible_command ();
        
        map.dump (cerr);
-
-       session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
 }
 
 void
@@ -349,8 +357,6 @@ Editor::mouse_add_new_meter_event (nframes_t frame)
        commit_reversible_command ();
        
        map.dump (cerr);
-
-       session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
 }
 
 void
@@ -401,8 +407,6 @@ Editor::edit_meter_section (MeterSection* section)
         XMLNode &after = session->tempo_map().get_state();
        session->add_command(new MementoCommand<TempoMap>(session->tempo_map(), &before, &after));
        commit_reversible_command ();
-
-       session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
 }
 
 void
@@ -433,8 +437,6 @@ Editor::edit_tempo_section (TempoSection* section)
         XMLNode &after = session->tempo_map().get_state();
        session->add_command (new MementoCommand<TempoMap>(session->tempo_map(), &before, &after));
        commit_reversible_command ();
-
-       session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
 }
 
 void
@@ -485,8 +487,6 @@ Editor::real_remove_tempo_marker (TempoSection *section)
        session->add_command(new MementoCommand<TempoMap>(session->tempo_map(), &before, &after));
        commit_reversible_command ();
 
-       session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
-
        return FALSE;
 }
 
@@ -521,7 +521,5 @@ Editor::real_remove_meter_marker (MeterSection *section)
        session->add_command(new MementoCommand<TempoMap>(session->tempo_map(), &before, &after));
        commit_reversible_command ();
 
-       session->tempo_map().apply_with_metrics (*this, &Editor::draw_metric_marks);
-
        return FALSE;
 }
index 2cd26014061273df3b7ecae0f3b85d602db6847a..7f7d11c0bec458acb6c0eda85405d3ea7247a5a3 100644 (file)
@@ -69,3 +69,13 @@ GhostRegion::set_height ()
        }
 }
 
+void
+GhostRegion::set_colors ()
+{
+    for (uint32_t n=0; n < waves.size(); ++n) {
+       waves[n]->property_wave_color() = color_map[cGhostTrackWave];
+
+       waves[n]->property_clip_color() = color_map[cGhostTrackWaveClip];
+       waves[n]->property_zero_color() = color_map[cGhostTrackZeroLine];
+    }
+}
index 77b22f942c6d3cdd7382a9a87868f2cb131df13c..1e32add7944199592d83b1221dcca2fbaad4f159 100644 (file)
@@ -41,6 +41,7 @@ struct GhostRegion : public sigc::trackable
     void set_samples_per_unit (double spu);
     void set_duration (double units);
     void set_height ();
+    void set_colors ();
 
     sigc::signal<void,GhostRegion*> GoingAway;
 };
index 09d959358dd0d79a3a5474bd19c376c99d3d89d8..cf29fae9bd8b62a207e81918b6cb915a835af6f6 100644 (file)
@@ -125,6 +125,8 @@ void
 TimeAxisViewItem::init (const string& it_name, double spu, Gdk::Color& base_color, nframes_t start, nframes_t duration, Visibility vis)
 {
        item_name = it_name ;
+       name_text_width = ::pixel_width (it_name, NAME_FONT);
+       last_name_text_width = 0;
        samples_per_unit = spu ;
        should_show_selection = true;
        frame_position = start ;
@@ -488,6 +490,7 @@ TimeAxisViewItem::set_item_name(std::string new_name, void* src)
        if (new_name != item_name) {
                std::string temp_name = item_name ;
                item_name = new_name ;
+               name_text_width = ::pixel_width (new_name, NAME_FONT);
                NameChanged (item_name, temp_name, src) ; /* EMIT_SIGNAL */
        }
 }
@@ -553,10 +556,11 @@ TimeAxisViewItem::get_time_axis_view()
  * @param new_name the new name text to display
  */
 void
-TimeAxisViewItem::set_name_text(std::string new_name)
+TimeAxisViewItem::set_name_text(const ustring& new_name)
 {
        if (name_text) {
                name_text->property_text() = new_name.c_str();
+               name_text_width = pixel_width (new_name, NAME_FONT);
        }
 }
 
@@ -913,6 +917,13 @@ TimeAxisViewItem::reset_name_width (double pixel_width)
        if (name_text == 0) {
                return;
        }
+
+       if ((last_name_text_width &&                                      // we did this once
+            (name_text_width <= pixel_width - NAME_X_OFFSET) &&          // fits the new size
+            (name_text_width <= last_name_text_width - NAME_X_OFFSET))) { // fit into the old size too
+               last_name_text_width = pixel_width;
+               return;
+       }
                        
        int width;
        
@@ -941,6 +952,8 @@ TimeAxisViewItem::reset_name_width (double pixel_width)
                name_text->property_text() = ustr;
                name_text->show();
        }
+
+       last_name_text_width = pixel_width;
 }
 
 
index e0331a2de29546c7baa6d886817dc3fce4d59b97..960d9402687df6f73a46c072af37d38648524f48 100644 (file)
@@ -199,7 +199,7 @@ class TimeAxisViewItem : public Selectable
      *
      * @param new_name the new name text to display
      */
-    void set_name_text(std::string new_name) ;
+    void set_name_text(const Glib::ustring& new_name) ;
     
     /**
      * Set the height of this item
@@ -461,6 +461,9 @@ class TimeAxisViewItem : public Selectable
     ArdourCanvas::SimpleRect* frame_handle_start;
     ArdourCanvas::SimpleRect* frame_handle_end;
 
+    int name_text_width;
+    double last_name_text_width;
+
     Visibility visibility;
 
 }; /* class TimeAxisViewItem */
index fbebf0d51afc0a1a888a192ca4292bf8dbb811dc..9c1ef22a88c579ebcd38e08a3f24d270eeb0d538 100644 (file)
@@ -44,6 +44,20 @@ using namespace sigc;
 using namespace Glib;
 using namespace PBD;
 
+int
+pixel_width (const ustring& str, Pango::FontDescription& font)
+{
+       Label foo;
+       Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout ("");
+
+       layout->set_font_description (font);
+       layout->set_text (str);
+
+       int width, height;
+       Gtkmm2ext::get_ink_pixel_size (layout, width, height);
+       return width;
+}
+
 ustring
 fit_to_pixels (const ustring& str, int pixel_width, Pango::FontDescription& font, int& actual_width, bool with_ellipses)
 {
index 2d2f879073f7badaeeeb2410c956536ade341093..b95f09d24336c5021371e73e5d1d1e6c0e94d781 100644 (file)
@@ -53,6 +53,7 @@ slider_position_to_gain (double pos)
 }
 
 Glib::ustring fit_to_pixels (const Glib::ustring&, int pixel_width, Pango::FontDescription& font, int& actual_width, bool with_ellipses = false);
+int pixel_width (const Glib::ustring& str, Pango::FontDescription& font);
 
 gint   just_hide_it (GdkEventAny*, Gtk::Window*);
 void   allow_keyboard_focus (bool);