Relent a bit and make adding a route to a group which already contains that group...
[ardour.git] / gtk2_ardour / automation_streamview.cc
index d3419e8bb84ade63922457cc344169c5258780e5..2591f6d8dd2a932e5a042e14aeb4e44012e12f9c 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2001-2007 Paul Davis 
+    Copyright (C) 2001-2007 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
 #include <gtkmm2ext/gtk_ui.h>
 
-#include <ardour/midi_playlist.h>
-#include <ardour/midi_region.h>
-#include <ardour/midi_source.h>
-#include <ardour/midi_diskstream.h>
-#include <ardour/midi_track.h>
-#include <ardour/smf_source.h>
-#include <ardour/region_factory.h>
+#include "ardour/midi_playlist.h"
+#include "ardour/midi_region.h"
+#include "ardour/midi_source.h"
+#include "ardour/midi_diskstream.h"
+#include "ardour/midi_track.h"
+#include "ardour/smf_source.h"
+#include "ardour/region_factory.h"
 
 #include "automation_streamview.h"
 #include "region_view.h"
@@ -54,14 +54,14 @@ using namespace Editing;
 
 AutomationStreamView::AutomationStreamView (AutomationTimeAxisView& tv)
        : StreamView (*dynamic_cast<RouteTimeAxisView*>(tv.get_parent()),
-                       new ArdourCanvas::Group(*tv.canvas_display))
+                     new ArdourCanvas::Group(*tv.canvas_display()))
        , _controller(tv.controller())
        , _automation_view(tv)
 {
        //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 ();
+       use_rec_regions = tv.editor().show_waveforms_recording ();
 }
 
 AutomationStreamView::~AutomationStreamView ()
@@ -70,7 +70,7 @@ AutomationStreamView::~AutomationStreamView ()
 
 
 RegionView*
-AutomationStreamView::add_region_view_internal (boost::shared_ptr<Region> region, bool wfd, bool recording)
+AutomationStreamView::add_region_view_internal (boost::shared_ptr<Region> region, bool wfd, bool /*recording*/)
 {
        if ( ! region) {
                cerr << "No region" << endl;
@@ -98,7 +98,7 @@ AutomationStreamView::add_region_view_internal (boost::shared_ptr<Region> region
 
        for (i = region_views.begin(); i != region_views.end(); ++i) {
                if ((*i)->region() == region) {
-                       
+
                        /* great. we already have an AutomationRegionView for this Region. use it again. */
                        AutomationRegionView* arv = dynamic_cast<AutomationRegionView*>(*i);;
 
@@ -111,14 +111,14 @@ AutomationStreamView::add_region_view_internal (boost::shared_ptr<Region> region
                        return NULL;
                }
        }
-       
+
        region_view = new AutomationRegionView (canvas_group, _automation_view, region,
                        _controller->controllable()->parameter(), list,
                        _samples_per_unit, region_color);
-               
+
        region_view->init (region_color, false);
        region_views.push_front (region_view);
-       
+
        /* follow global waveform setting */
 
        if (wfd) {
@@ -129,8 +129,8 @@ AutomationStreamView::add_region_view_internal (boost::shared_ptr<Region> region
        display_region(region_view);
 
        /* catch regionview going away */
-       region->GoingAway.connect (bind (mem_fun (*this, &AutomationStreamView::remove_region_view), region));
-       
+       region->DropReferences.connect (*this, boost::bind (&AutomationStreamView::remove_region_view, this, boost::weak_ptr<Region>(region)), gui_context());
+
        RegionViewAdded (region_view);
 
        return region_view;
@@ -158,33 +158,21 @@ AutomationStreamView::redisplay_diskstream ()
 {
        list<RegionView *>::iterator i, tmp;
 
-       for (i = region_views.begin(); i != region_views.end(); ++i)
+       // Flag region views as invalid and disable drawing
+       for (i = region_views.begin(); i != region_views.end(); ++i) {
                (*i)->set_valid (false);
-       
-       if (_trackview.is_track()) {
-               _trackview.get_diskstream()->playlist()->foreach_region (static_cast<StreamView*>(this), &StreamView::add_region_view);
+               (*i)->enable_display(false);
        }
 
-       for (i = region_views.begin(); i != region_views.end(); ) {
-               tmp = i;
-               tmp++;
-
-               if (!(*i)->is_valid()) {
-                       delete *i;
-                       region_views.erase (i);
-               } else {
-                       (*i)->enable_display(true);
-                       (*i)->set_height(height);
-               }
-
-               i = tmp;
+       // Add and display region views, and flag them as valid
+       if (_trackview.is_track()) {
+               _trackview.get_diskstream()->playlist()->foreach_region (
+                       sigc::hide_return (sigc::mem_fun (*this, &StreamView::add_region_view))
+                       );
        }
-       
-       /* now fix layering */
 
-       for (RegionViewList::iterator i = region_views.begin(); i != region_views.end(); ++i) {
-               region_layered (*i);
-       }
+       // Stack regions by layer, and remove invalid regions
+       layer_regions();
 }
 
 
@@ -194,7 +182,7 @@ AutomationStreamView::setup_rec_box ()
 }
 
 void
-AutomationStreamView::update_rec_regions (nframes_t start, nframes_t dur)
+AutomationStreamView::update_rec_regions (nframes_t /*start*/, nframes_t /*dur*/)
 {
 }
 
@@ -202,9 +190,9 @@ void
 AutomationStreamView::rec_data_range_ready (jack_nframes_t start, jack_nframes_t dur)
 {
        // this is called from the butler thread for now
-       
-       ENSURE_GUI_THREAD(bind (mem_fun (*this, &AutomationStreamView::rec_data_range_ready), start, dur));
-       
+
+       ENSURE_GUI_THREAD (*this, &AutomationStreamView::rec_data_range_ready, start, dur)
+
        this->update_rec_regions (start, dur);
 }
 
@@ -213,7 +201,7 @@ 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();;