fix feedback loop while track resizing
[ardour.git] / gtk2_ardour / automation_region_view.cc
index f0dc23e0433a6c9341ce5f09aa0a342abe67e9b1..c213b3feeb3137152871fc298f8171735ae82693 100644 (file)
 AutomationRegionView::AutomationRegionView(ArdourCanvas::Group*                      parent,
                                            AutomationTimeAxisView&                   time_axis,
                                            boost::shared_ptr<ARDOUR::Region>         region,
+                                           const ARDOUR::Parameter&                  param,
                                            boost::shared_ptr<ARDOUR::AutomationList> list,
                                            double                                    spu,
                                            Gdk::Color&                               basic_color)
        : RegionView(parent, time_axis, region, spu, basic_color)
+       , _parameter(param)
 { 
        if (list) {
-               _line = boost::shared_ptr<AutomationLine>(new AutomationLine(
-                                       list->parameter().to_string(), time_axis, *group, list));
-               _line->set_colors();
-               _line->show();
-               _line->show_all_control_points();
+               assert(list->parameter() == param);
+               create_line(list);
        }
        
        group->signal_event().connect (mem_fun (this, &AutomationRegionView::canvas_event), false);
@@ -53,7 +52,7 @@ AutomationRegionView::init (Gdk::Color& basic_color, bool wfd)
 
        reset_width_dependent_items ((double) _region->length() / samples_per_unit);
 
-       set_y_position_and_height (0, trackview.height);
+       set_height (trackview.current_height());
 
        _region->StateChanged.connect (mem_fun(*this, &AutomationRegionView::region_changed));
 
@@ -62,6 +61,17 @@ AutomationRegionView::init (Gdk::Color& basic_color, bool wfd)
        _enable_display = true;
 }
 
+void
+AutomationRegionView::create_line (boost::shared_ptr<ARDOUR::AutomationList> list)
+{
+       _line = boost::shared_ptr<AutomationLine>(new AutomationLine(
+                               list->parameter().symbol(), trackview, *get_canvas_group(), list));
+       _line->set_colors();
+       _line->show();
+       _line->show_all_control_points();
+       _line->set_height ((uint32_t)rint(trackview.current_height() - NAME_HIGHLIGHT_SIZE));
+}
+
 bool
 AutomationRegionView::canvas_event(GdkEvent* ev)
 {
@@ -79,9 +89,13 @@ void
 AutomationRegionView::add_automation_event (GdkEvent* event, nframes_t when, double y)
 {
        if (!_line) {
-               cerr << "ERROR: AutomationRegionView::add_automation_event called without line" << endl;
-               return;
+               boost::shared_ptr<Evoral::Control> c = _region->control(_parameter, true);
+               boost::shared_ptr<ARDOUR::AutomationControl> ac
+                               = boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(c);
+               assert(ac);
+               create_line(ac->alist());
        }
+       assert(_line);
 
        double x = 0;
        AutomationTimeAxisView* const view = automation_view();
@@ -90,8 +104,8 @@ AutomationRegionView::add_automation_event (GdkEvent* event, nframes_t when, dou
 
        /* compute vertical fractional position */
 
-       const double height = trackview.height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 2;
-       y = 1.0 - (y / height);
+       const double h = trackview.current_height() - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 2;
+       y = 1.0 - (y / h);
 
        /* map using line */
 
@@ -109,14 +123,13 @@ AutomationRegionView::add_automation_event (GdkEvent* event, nframes_t when, dou
        view->session().set_dirty ();
 }
 
-
 void
-AutomationRegionView::set_y_position_and_height (double y, double h)
+AutomationRegionView::set_height (double h)
 {
-       RegionView::set_y_position_and_height(y, h - 1);
+       RegionView::set_height(h);
 
        if (_line)
-               _line->set_y_position_and_height ((uint32_t)y, (uint32_t) rint (h - NAME_HIGHLIGHT_SIZE));
+               _line->set_height ((uint32_t)rint(h - NAME_HIGHLIGHT_SIZE));
 }
 
 bool