Patch from Lincoln (#3319) to make the range selection box not display trim handles...
[ardour.git] / gtk2_ardour / automation_streamview.cc
index c8dc0ae3c4bd11972e451cb61e39ae7662ab937b..146cdc7b8918077f672e772b115533b00ff84fdb 100644 (file)
@@ -54,14 +54,14 @@ using namespace Editing;
 
 AutomationStreamView::AutomationStreamView (AutomationTimeAxisView& tv)
        : StreamView (*dynamic_cast<RouteTimeAxisView*>(tv.get_parent()),
+                     new ArdourCanvas::Group(*tv.canvas_background()),
                      new ArdourCanvas::Group(*tv.canvas_display()))
        , _controller(tv.controller())
        , _automation_view(tv)
+       , _pending_automation_state (Off)
 {
        //canvas_rect->property_fill_color_rgba() = stream_base_color;
        canvas_rect->property_outline_color_rgba() = RGBA_BLACK;
-
-       use_rec_regions = tv.editor().show_waveforms_recording ();
 }
 
 AutomationStreamView::~AutomationStreamView ()
@@ -83,9 +83,9 @@ AutomationStreamView::add_region_view_internal (boost::shared_ptr<Region> region
                        mr->midi_source()->load_model();
        }
 
-       const boost::shared_ptr<AutomationControl> control
-               = boost::dynamic_pointer_cast<AutomationControl>(
-                               region->control(_controller->controllable()->parameter()));
+       const boost::shared_ptr<AutomationControl> control = boost::dynamic_pointer_cast<AutomationControl> (
+               region->control (_controller->controllable()->parameter(), true)
+               );
 
        boost::shared_ptr<AutomationList> list;
        if (control) {
@@ -112,7 +112,7 @@ AutomationStreamView::add_region_view_internal (boost::shared_ptr<Region> region
                }
        }
 
-       region_view = new AutomationRegionView (canvas_group, _automation_view, region,
+       region_view = new AutomationRegionView (_canvas_group, _automation_view, region,
                        _controller->controllable()->parameter(), list,
                        _samples_per_unit, region_color);
 
@@ -129,8 +129,14 @@ AutomationStreamView::add_region_view_internal (boost::shared_ptr<Region> region
        display_region(region_view);
 
        /* catch regionview going away */
-       region->GoingAway.connect (*this, boost::bind (&AutomationStreamView::remove_region_view, this, boost::weak_ptr<Region>(region)), gui_context());
+       region->DropReferences.connect (*this, invalidator (*this), boost::bind (&AutomationStreamView::remove_region_view, this, boost::weak_ptr<Region>(region)), gui_context());
 
+       /* setup automation state for this region */
+       boost::shared_ptr<AutomationLine> line = region_view->line ();
+       if (line && line->the_list()) {
+               line->the_list()->set_automation_state (automation_state ());
+       }
+       
        RegionViewAdded (region_view);
 
        return region_view;
@@ -145,16 +151,24 @@ AutomationStreamView::display_region(AutomationRegionView* region_view)
 void
 AutomationStreamView::set_automation_state (AutoState state)
 {
-       std::list<RegionView *>::iterator i;
-       for (i = region_views.begin(); i != region_views.end(); ++i) {
-               boost::shared_ptr<AutomationLine> line = ((AutomationRegionView*)(*i))->line();
-               if (line && line->the_list())
-                       line->the_list()->set_automation_state (state);
+       /* XXX: not sure if this is right, but for now the automation state is basically held by
+          the regions' AutomationLists.  Each region is always set to have the same AutoState.
+       */
+       
+       if (region_views.empty()) {
+               _pending_automation_state = state;
+       } else {
+               for (std::list<RegionView *>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
+                       boost::shared_ptr<AutomationLine> line = dynamic_cast<AutomationRegionView*>(*i)->line();
+                       if (line && line->the_list()) {
+                               line->the_list()->set_automation_state (state);
+                       }
+               }
        }
 }
 
 void
-AutomationStreamView::redisplay_diskstream ()
+AutomationStreamView::redisplay_track ()
 {
        list<RegionView *>::iterator i, tmp;
 
@@ -166,7 +180,7 @@ AutomationStreamView::redisplay_diskstream ()
 
        // Add and display region views, and flag them as valid
        if (_trackview.is_track()) {
-               _trackview.get_diskstream()->playlist()->foreach_region (
+               _trackview.track()->playlist()->foreach_region (
                        sigc::hide_return (sigc::mem_fun (*this, &StreamView::add_region_view))
                        );
        }
@@ -182,29 +196,69 @@ AutomationStreamView::setup_rec_box ()
 }
 
 void
-AutomationStreamView::update_rec_regions (nframes_t /*start*/, nframes_t /*dur*/)
+AutomationStreamView::color_handler ()
 {
+       /*if (_trackview.is_midi_track()) {
+               canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MidiTrackBase.get();
+       }
+
+       if (!_trackview.is_midi_track()) {
+               canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MidiBusBase.get();;
+       }*/
 }
 
-void
-AutomationStreamView::rec_data_range_ready (jack_nframes_t start, jack_nframes_t dur)
+AutoState
+AutomationStreamView::automation_state () const
 {
-       // this is called from the butler thread for now
+       if (region_views.empty()) {
+               return _pending_automation_state;
+       }
 
-       ENSURE_GUI_THREAD (*this, &AutomationStreamView::rec_data_range_ready, start, dur)
+       boost::shared_ptr<AutomationLine> line = ((AutomationRegionView*) region_views.front())->line ();
+       if (!line || !line->the_list()) {
+               return Off;
+       }
 
-       this->update_rec_regions (start, dur);
+       return line->the_list()->automation_state ();
 }
 
-void
-AutomationStreamView::color_handler ()
+bool
+AutomationStreamView::has_automation () const
 {
-       /*if (_trackview.is_midi_track()) {
-               canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MidiTrackBase.get();
+       list<RegionView*>::const_iterator i = region_views.begin ();
+       while (i != region_views.end()) {
+               AutomationRegionView* rv = static_cast<AutomationRegionView*> (*i);
+               if (rv->line() && rv->line()->npoints() > 0) {
+                       return true;
+               }
+               ++i;
        }
 
-       if (!_trackview.is_midi_track()) {
-               canvas_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_MidiBusBase.get();;
-       }*/
+       return false;
 }
 
+/** Our parent AutomationTimeAxisView calls this when the user requests a particular
+ *  InterpolationStyle; tell the AutomationLists in our regions.
+ */
+void
+AutomationStreamView::set_interpolation (AutomationList::InterpolationStyle s)
+{
+       for (list<RegionView*>::const_iterator i = region_views.begin(); i != region_views.end(); ++i) {
+               AutomationRegionView* arv = dynamic_cast<AutomationRegionView*> (*i);
+               assert (arv);
+               arv->line()->the_list()->set_interpolation (s);
+       }
+}
+
+AutomationList::InterpolationStyle
+AutomationStreamView::interpolation () const
+{
+       if (region_views.empty()) {
+               return AutomationList::Linear;
+       }
+
+       AutomationRegionView* v = dynamic_cast<AutomationRegionView*> (region_views.front());
+       assert (v);
+
+       return v->line()->the_list()->interpolation ();
+}