fix from 2.X for automation line clear command using the wrong object in the memento...
[ardour.git] / gtk2_ardour / audio_region_view.cc
index b8f08456d49f782993601726e7504fa75c9a3f9a..d490ede63b4e7380064078ba33b322fb4e531099 100644 (file)
@@ -27,7 +27,6 @@
 #include "ardour/playlist.h"
 #include "ardour/audioregion.h"
 #include "ardour/audiosource.h"
-#include "ardour/audio_diskstream.h"
 #include "ardour/profile.h"
 #include "ardour/session.h"
 
@@ -111,7 +110,6 @@ AudioRegionView::AudioRegionView (const AudioRegionView& other)
        , _amplitude_above_axis(1.0)
        , _flags(0)
        , fade_color(0)
-
 {
        Gdk::Color c;
        int r,g,b,a;
@@ -133,7 +131,6 @@ AudioRegionView::AudioRegionView (const AudioRegionView& other, boost::shared_pt
        , _amplitude_above_axis(1.0)
        , _flags(0)
        , fade_color(0)
-
 {
        Gdk::Color c;
        int r,g,b,a;
@@ -165,7 +162,8 @@ AudioRegionView::init (Gdk::Color const & basic_color, bool wfd)
                store_flags ();
        }
 
-       if (trackview.editor().new_regionviews_display_gain()) {
+       /* make envelope visible if it has anything interesting in it */
+       if (audio_region()->envelope()->size() > 2) {
                _flags |= EnvelopeVisible;
        }
 
@@ -222,7 +220,8 @@ AudioRegionView::init (Gdk::Color const & basic_color, bool wfd)
 
        region_muted ();
        region_sync_changed ();
-       region_resized (BoundsChanged);
+
+       region_resized (ARDOUR::bounds_change);
        set_waveview_data_src();
        region_locked ();
        envelope_active_changed ();
@@ -251,6 +250,10 @@ AudioRegionView::~AudioRegionView ()
                gnome_canvas_waveview_cache_destroy (*cache);
        }
 
+       for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
+               delete *i;
+       }
+
        /* all waveviews etc will be destroyed when the group is destroyed */
 
        delete gain_line;
@@ -264,29 +267,29 @@ AudioRegionView::audio_region() const
 }
 
 void
-AudioRegionView::region_changed (Change what_changed)
+AudioRegionView::region_changed (const PropertyChange& what_changed)
 {
-       ENSURE_GUI_THREAD (*this, &AudioRegionView::region_changed, what_changed)
-       //cerr << "AudioRegionView::region_changed() called" << endl;
+       ENSURE_GUI_THREAD (*this, &AudioRegionView::region_changed, what_changed);
+        // cerr << "AudioRegionView::region_changed() called" << endl;
 
-       RegionView::region_changed(what_changed);
+       RegionView::region_changed (what_changed);
 
-       if (what_changed & AudioRegion::ScaleAmplitudeChanged) {
+       if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
                region_scale_amplitude_changed ();
        }
-       if (what_changed & AudioRegion::FadeInChanged) {
-               fade_in_changed ();
+       if (what_changed.contains (ARDOUR::Properties::fade_in)) {
+                fade_in_changed ();
        }
-       if (what_changed & AudioRegion::FadeOutChanged) {
+       if (what_changed.contains (ARDOUR::Properties::fade_out)) {
                fade_out_changed ();
        }
-       if (what_changed & AudioRegion::FadeInActiveChanged) {
+       if (what_changed.contains (ARDOUR::Properties::fade_in_active)) {
                fade_in_active_changed ();
        }
-       if (what_changed & AudioRegion::FadeOutActiveChanged) {
+       if (what_changed.contains (ARDOUR::Properties::fade_out_active)) {
                fade_out_active_changed ();
        }
-       if (what_changed & AudioRegion::EnvelopeActiveChanged) {
+       if (what_changed.contains (ARDOUR::Properties::envelope_active)) {
                envelope_active_changed ();
        }
 }
@@ -372,13 +375,17 @@ AudioRegionView::region_renamed ()
 }
 
 void
-AudioRegionView::region_resized (Change what_changed)
+AudioRegionView::region_resized (const PropertyChange& what_changed)
 {
        AudioGhostRegion* agr;
 
        RegionView::region_resized(what_changed);
+       PropertyChange interesting_stuff;
 
-       if (what_changed & Change (StartChanged|LengthChanged)) {
+       interesting_stuff.add (ARDOUR::Properties::start);
+       interesting_stuff.add (ARDOUR::Properties::length);
+
+       if (what_changed.contains (interesting_stuff)) {
 
                for (uint32_t n = 0; n < waves.size(); ++n) {
                        waves[n]->property_region_start() = _region->start();
@@ -468,24 +475,23 @@ AudioRegionView::set_height (gdouble height)
        // FIXME: ick
        height -= 2;
 
-       _height = height;
-
-       for (uint32_t n=0; n < wcnt; ++n) {
+       for (uint32_t n = 0; n < wcnt; ++n) {
                gdouble ht;
 
                if ((height) < NAME_HIGHLIGHT_THRESH) {
-                       ht = ((height-2*wcnt) / (double) wcnt);
+                       ht = ((height - 2 * wcnt) / (double) wcnt);
                } else {
-                       ht = (((height-2*wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
+                       ht = (((height - 2 * wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
                }
 
-               gdouble yoff = n * (ht+1);
+               gdouble yoff = n * (ht + 1);
 
                waves[n]->property_height() = ht;
                waves[n]->property_y() = yoff + 2;
        }
 
        if (gain_line) {
+
                if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
                        gain_line->hide ();
                } else {
@@ -493,7 +499,8 @@ AudioRegionView::set_height (gdouble height)
                                gain_line->show ();
                        }
                }
-               gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE - 2));
+
+               gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE) - 2);
        }
 
        manage_zero_line ();
@@ -502,7 +509,6 @@ AudioRegionView::set_height (gdouble height)
        if (name_pixbuf) {
                name_pixbuf->raise_to_top();
        }
-
 }
 
 void
@@ -843,11 +849,11 @@ AudioRegionView::create_waves ()
        // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
        RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
 
-       if (!atv.get_diskstream()) {
+       if (!atv.track()) {
                return;
        }
 
-       ChanCount nchans = atv.get_diskstream()->n_channels();
+       ChanCount nchans = atv.track()->n_channels();
 
        // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
        //              << " and channels = " << nchans.n_audio() << endl;
@@ -857,6 +863,16 @@ AudioRegionView::create_waves ()
                tmp_waves.push_back (0);
        }
 
+       for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
+               delete *i;
+       }
+
+       _data_ready_connections.clear ();
+
+       for (uint32_t i = 0; i < nchans.n_audio(); ++i) {
+               _data_ready_connections.push_back (0);
+       }
+
        for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
 
                if (n >= audio_region()->n_channels()) {
@@ -868,7 +884,7 @@ AudioRegionView::create_waves ()
                // cerr << "\tchannel " << n << endl;
 
                if (wait_for_data) {
-                       if (audio_region()->audio_source(n)->peaks_ready (boost::bind (&AudioRegionView::peaks_ready_handler, this, n), data_ready_connection, gui_context())) {
+                       if (audio_region()->audio_source(n)->peaks_ready (boost::bind (&AudioRegionView::peaks_ready_handler, this, n), &_data_ready_connections[n], gui_context())) {
                                // cerr << "\tData is ready\n";
                                create_one_wave (n, true);
                        } else {
@@ -890,7 +906,7 @@ AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
 {
        //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
        RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
-       uint32_t nchans = atv.get_diskstream()->n_channels().n_audio();
+       uint32_t nchans = atv.track()->n_channels().n_audio();
        uint32_t n;
        uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
        gdouble ht;
@@ -964,7 +980,8 @@ AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
                tmp_waves.clear ();
 
                /* all waves created, don't hook into peaks ready anymore */
-               data_ready_connection.disconnect ();
+               delete _data_ready_connections[which];
+               _data_ready_connections[which] = 0;
 
 #if 0
                if (!zero_line) {
@@ -981,7 +998,7 @@ AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
 void
 AudioRegionView::peaks_ready_handler (uint32_t which)
 {
-       Gtkmm2ext::UI::instance()->call_slot (boost::bind (&AudioRegionView::create_one_wave, this, which, false));
+       Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AudioRegionView::create_one_wave, this, which, false));
        // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
 }
 
@@ -1017,6 +1034,10 @@ AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
 
        gain_line->view_to_model_coord (x, y);
 
+        /* XXX STATEFUL: can't convert to stateful diff until we 
+           can represent automation data with it.
+        */
+
        trackview.session()->begin_reversible_command (_("add gain control point"));
        XMLNode &before = audio_region()->envelope()->get_state();
 
@@ -1155,7 +1176,7 @@ AudioRegionView::add_ghost (TimeAxisView& tv)
        AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
        uint32_t nchans;
 
-       nchans = rtv->get_diskstream()->n_channels().n_audio();
+       nchans = rtv->track()->n_channels().n_audio();
 
        for (uint32_t n = 0; n < nchans; ++n) {
 
@@ -1186,8 +1207,6 @@ AudioRegionView::add_ghost (TimeAxisView& tv)
        ghost->set_colors();
        ghosts.push_back (ghost);
 
-       ghost->GoingAway.connect (*this, ui_bind (&RegionView::remove_ghost, this, _1), gui_context());
-
        return ghost;
 }