Tidy a couple of minor things up.
[ardour.git] / gtk2_ardour / crossfade_edit.cc
index 382f6afd09b114b5ad0392a39f64811d03ae3751..da833b8ea452f6eb40d87705c91f4a03f7b8fb3e 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <libgnomecanvasmm/line.h>
 
+#include "pbd/memento_command.h"
 #include "ardour/automation_list.h"
 #include "evoral/Curve.hpp"
 #include "ardour/crossfade.h"
@@ -36,6 +37,7 @@
 #include "ardour/audiosource.h"
 #include "ardour/region_factory.h"
 #include "ardour/profile.h"
+#include "ardour/crossfade_binder.h"
 
 #include <gtkmm2ext/gtk_ui.h>
 
@@ -96,11 +98,11 @@ CrossfadeEditor::CrossfadeEditor (Session* s, boost::shared_ptr<Crossfade> xf, d
          select_out_button (_("Fade Out")),
 
          _peaks_ready_connection (0)
-         
+
 {
        set_session (s);
 
-       set_wmclass (X_("ardour_automationedit"), "Ardour");
+       set_wmclass (X_("ardour_automationedit"), PROGRAM_NAME);
        set_name ("CrossfadeEditWindow");
        set_position (Gtk::WIN_POS_MOUSE);
 
@@ -418,15 +420,16 @@ CrossfadeEditor::point_event (GdkEvent* event, Point* point)
                if (point_grabbed) {
                        double new_x, new_y;
 
-                       /* can't drag first or last points horizontally */
+                       /* can't drag first or last points horizontally or vertically */
 
                        if (point == fade[current].points.front() || point == fade[current].points.back()) {
                                new_x = point->x;
+                               new_y = point->y;
                        } else {
                                new_x = (event->motion.x - canvas_border)/effective_width();
+                               new_y = 1.0 - ((event->motion.y - canvas_border)/effective_height());
                        }
 
-                       new_y = 1.0 - ((event->motion.y - canvas_border)/effective_height());
                        point->move_to (x_coordinate (new_x), y_coordinate (new_y),
                                        new_x, new_y);
                        redraw ();
@@ -502,17 +505,17 @@ CrossfadeEditor::add_control_point (double x, double y)
 void
 CrossfadeEditor::Point::move_to (double nx, double ny, double xfract, double yfract)
 {
-        if ( xfract < 0.0 ) {
-                xfract = 0.0;
-        } else if ( xfract > 1.0 ) {
-                xfract = 1.0;
-        }
-        
-        if ( yfract < 0.0 ) {
-                yfract = 0.0;
-        } else if ( yfract > 1.0 ) {
-                yfract = 1.0;
-        }
+       if ( xfract < 0.0 ) {
+               xfract = 0.0;
+       } else if ( xfract > 1.0 ) {
+               xfract = 1.0;
+       }
+
+       if ( yfract < 0.0 ) {
+               yfract = 0.0;
+       } else if ( yfract > 1.0 ) {
+               yfract = 1.0;
+       }
 
        const double half_size = rint(size/2.0);
        double x1 = nx - half_size;
@@ -654,7 +657,7 @@ CrossfadeEditor::redraw ()
                return;
        }
 
-       nframes_t len = xfade->length ();
+       framecnt_t len = xfade->length ();
 
        fade[current].normative_curve.clear ();
        fade[current].gain_curve.clear ();
@@ -783,7 +786,20 @@ CrossfadeEditor::apply_preset (Preset *preset)
 void
 CrossfadeEditor::apply ()
 {
+       _session->begin_reversible_command (_("Edit crossfade"));
+
+       XMLNode& before = xfade->get_state ();
+
        _apply_to (xfade);
+
+       _session->add_command (
+               new MementoCommand<Crossfade> (
+                       new ARDOUR::CrossfadeBinder (_session->playlists, xfade->id ()),
+                       &before, &xfade->get_state ()
+                       )
+               );
+
+       _session->commit_reversible_command ();
 }
 
 void
@@ -800,8 +816,6 @@ CrossfadeEditor::_apply_to (boost::shared_ptr<Crossfade> xf)
 
        double firstx = (*in.begin())->when;
        double endx = (*the_end)->when;
-       double miny = in.get_min_y ();
-       double maxy = in.get_max_y ();
 
        in.freeze ();
        in.clear ();
@@ -809,7 +823,7 @@ CrossfadeEditor::_apply_to (boost::shared_ptr<Crossfade> xf)
        for (list<Point*>::iterator i = fade[In].points.begin(); i != fade[In].points.end(); ++i) {
 
                double when = firstx + ((*i)->x * (endx - firstx));
-               double value = (*i)->y; // miny + ((*i)->y * (maxy - miny));
+               double value = (*i)->y;
                in.add (when, value);
        }
 
@@ -820,8 +834,6 @@ CrossfadeEditor::_apply_to (boost::shared_ptr<Crossfade> xf)
 
        firstx = (*out.begin())->when;
        endx = (*the_end)->when;
-       miny = out.get_min_y ();
-       maxy = out.get_max_y ();
 
        out.freeze ();
        out.clear ();
@@ -829,7 +841,7 @@ CrossfadeEditor::_apply_to (boost::shared_ptr<Crossfade> xf)
        for (list<Point*>::iterator i = fade[Out].points.begin(); i != fade[Out].points.end(); ++i) {
 
                double when = firstx + ((*i)->x * (endx - firstx));
-               double value = (*i)->y; // miny + ((*i)->y * (maxy - miny));
+               double value = (*i)->y;
                out.add (when, value);
        }
 
@@ -864,7 +876,7 @@ CrossfadeEditor::reset ()
        set (xfade->fade_in(),  In);
        set (xfade->fade_out(), Out);
 
-        curve_select_clicked (current);
+       curve_select_clicked (current);
 }
 
 void
@@ -1145,7 +1157,7 @@ CrossfadeEditor::make_waves (boost::shared_ptr<AudioRegion> region, WhichFade wh
 
        delete _peaks_ready_connection;
        _peaks_ready_connection = 0;
-       
+
        for (uint32_t n = 0; n < nchans; ++n) {
 
                gdouble yoff = n * ht;
@@ -1198,7 +1210,7 @@ CrossfadeEditor::peaks_ready (boost::weak_ptr<AudioRegion> wr, WhichFade which)
        */
        delete _peaks_ready_connection;
        _peaks_ready_connection = 0;
-       
+
        make_waves (r, which);
 }
 
@@ -1206,11 +1218,11 @@ void
 CrossfadeEditor::audition (Audition which)
 {
        AudioPlaylist& pl (_session->the_auditioner()->prepare_playlist());
-       nframes_t preroll;
-       nframes_t postroll;
-       nframes_t left_start_offset;
-       nframes_t right_length;
-       nframes_t left_length;
+       framecnt_t preroll;
+       framecnt_t postroll;
+       framecnt_t left_start_offset;
+       framecnt_t right_length;
+       framecnt_t left_length;
 
        if (which != Right && preroll_button.get_active()) {
                preroll = _session->frame_rate() * 2;  //2 second hardcoded preroll for now
@@ -1242,16 +1254,16 @@ CrossfadeEditor::audition (Audition which)
                right_length = xfade->in()->length();
        }
 
-       PropertyList left_plist; 
-       PropertyList right_plist; 
+       PropertyList left_plist;
+       PropertyList right_plist;
+
 
-       
        left_plist.add (ARDOUR::Properties::start, left_start_offset);
        left_plist.add (ARDOUR::Properties::length, left_length);
        left_plist.add (ARDOUR::Properties::name, string ("xfade out"));
        left_plist.add (ARDOUR::Properties::layer, 0);
        left_plist.add (ARDOUR::Properties::fade_in_active, true);
-       
+
        right_plist.add (ARDOUR::Properties::start, 0);
        right_plist.add (ARDOUR::Properties::length, right_length);
        right_plist.add (ARDOUR::Properties::name, string("xfade in"));
@@ -1264,9 +1276,9 @@ CrossfadeEditor::audition (Audition which)
                left_plist.add (ARDOUR::Properties::scale_amplitude, 0.0f);
        }
 
-       boost::shared_ptr<AudioRegion> left (boost::dynamic_pointer_cast<AudioRegion> 
+       boost::shared_ptr<AudioRegion> left (boost::dynamic_pointer_cast<AudioRegion>
                                                     (RegionFactory::create (xfade->out(), left_plist, false)));
-       boost::shared_ptr<AudioRegion> right (boost::dynamic_pointer_cast<AudioRegion> 
+       boost::shared_ptr<AudioRegion> right (boost::dynamic_pointer_cast<AudioRegion>
                                              (RegionFactory::create (xfade->in(), right_plist, false)));
 
        // apply a 20ms declicking fade at the start and end of auditioning
@@ -1293,14 +1305,14 @@ CrossfadeEditor::audition_both ()
 void
 CrossfadeEditor::audition_left_dry ()
 {
-       PropertyList plist; 
+       PropertyList plist;
 
        plist.add (ARDOUR::Properties::start, xfade->out()->length() - xfade->length());
        plist.add (ARDOUR::Properties::length, xfade->length());
        plist.add (ARDOUR::Properties::name, string("xfade left"));
        plist.add (ARDOUR::Properties::layer, 0);
-       
-       boost::shared_ptr<AudioRegion> left (boost::dynamic_pointer_cast<AudioRegion> 
+
+       boost::shared_ptr<AudioRegion> left (boost::dynamic_pointer_cast<AudioRegion>
                                             (RegionFactory::create (xfade->out(), plist, false)));
 
        _session->audition_region (left);
@@ -1315,14 +1327,14 @@ CrossfadeEditor::audition_left ()
 void
 CrossfadeEditor::audition_right_dry ()
 {
-       PropertyList plist; 
+       PropertyList plist;
 
        plist.add (ARDOUR::Properties::start, 0);
        plist.add (ARDOUR::Properties::length, xfade->length());
        plist.add (ARDOUR::Properties::name, string ("xfade right"));
        plist.add (ARDOUR::Properties::layer, 0);
 
-       boost::shared_ptr<AudioRegion> right (boost::dynamic_pointer_cast<AudioRegion> 
+       boost::shared_ptr<AudioRegion> right (boost::dynamic_pointer_cast<AudioRegion>
                                              (RegionFactory::create (xfade->in(), plist, false)));
 
        _session->audition_region (right);