Make normalize cancel button work.
authorCarl Hetherington <carl@carlh.net>
Thu, 28 Oct 2010 17:09:32 +0000 (17:09 +0000)
committerCarl Hetherington <carl@carlh.net>
Thu, 28 Oct 2010 17:09:32 +0000 (17:09 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7935 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor_ops.cc
gtk2_ardour/normalize_dialog.cc
gtk2_ardour/normalize_dialog.h
libs/ardour/ardour/progress.h
libs/ardour/audioregion.cc
libs/ardour/progress.cc

index b03df00cec0b6b4d699c1d70ebd2325f986f37b6..bce0e5c475347161eda1dd60198ed2469875b289 100644 (file)
@@ -4504,8 +4504,6 @@ Editor::normalize_region ()
                return;
        }
 
-       begin_reversible_command (_("normalize"));
-
        set_canvas_cursor (wait_cursor);
        gdk_flush ();
 
@@ -4522,12 +4520,21 @@ Editor::normalize_region ()
                if (arv) {
                        dialog.descend (1.0 / regions);
                        double const a = arv->audio_region()->maximum_amplitude (&dialog);
+
+                       if (a == -1) {
+                               /* the user cancelled the operation */
+                               set_canvas_cursor (current_canvas_cursor);
+                               return;
+                       }
+                       
                        max_amps.push_back (a);
                        max_amp = max (max_amp, a);
                        dialog.ascend ();
                }
        }
 
+       begin_reversible_command (_("normalize"));
+
        list<double>::const_iterator a = max_amps.begin ();
        
        for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
index 9a34c3a4bbe3df75920ac5824bcb4aa0904074e2..716bfa7c3962b8fd34ca583f665fa06b0149663c 100644 (file)
@@ -65,6 +65,8 @@ NormalizeDialog::NormalizeDialog (bool more_than_one)
        
        add_button (Stock::CANCEL, RESPONSE_CANCEL);
        add_button (_("Normalize"), RESPONSE_ACCEPT);
+
+       signal_response().connect (sigc::mem_fun (*this, &NormalizeDialog::button_clicked));
 }
 
 bool
@@ -96,3 +98,11 @@ NormalizeDialog::run ()
        _last_normalization_value = target ();
        return r;
 }
+
+void
+NormalizeDialog::button_clicked (int r)
+{
+       if (r == RESPONSE_CANCEL) {
+               cancel ();
+       }
+}
index fec46dbd08aa6761da5d39e270c5230d608cc8af..1cb1ae1cb516f476c3ddd17eb8ac8a39fccc03f9 100644 (file)
@@ -37,6 +37,7 @@ public:
 
 private:
        void update_progress_gui (float);
+       void button_clicked (int);
        
        Gtk::RadioButton* _normalize_individually;
        Gtk::SpinButton* _spin;
index e252c63bd86efddf6be178ed95d3e30aee6e0b9d..6cd66bdcbe4606ff5c257d147bb8305178b4e38c 100644 (file)
@@ -35,6 +35,11 @@ public:
        void ascend ();
        void descend (float);
 
+       bool cancelled () const;
+       
+protected:
+       void cancel ();
+
 private:
        /** Report overall progress.
         *  @param p Current progress (from 0 to 1)
@@ -49,6 +54,7 @@ private:
        };
 
        std::list<Level> _stack;
+       bool _cancelled;
 };
 
 }
index 1461e1a3a4e3888377dfbaf9e9bdf347a8707b18..be3b80de8717ddbc9aac5b92ddab09cdd0e4a263 100644 (file)
@@ -1143,7 +1143,9 @@ AudioRegion::set_scale_amplitude (gain_t g)
        send_change (PropertyChange (Properties::scale_amplitude));
 }
 
-/** @return the maximum (linear) amplitude of the region */
+/** @return the maximum (linear) amplitude of the region, or a -ve
+ *  number if the Progress object reports that the process was cancelled.
+ */
 double
 AudioRegion::maximum_amplitude (Progress* p) const
 {
@@ -1173,6 +1175,9 @@ AudioRegion::maximum_amplitude (Progress* p) const
 
                fpos += to_read;
                p->set_progress (float (fpos - _start) / _length);
+               if (p->cancelled ()) {
+                       return -1;
+               }
        }
 
        return maxamp;
index d09309f7934313171e87ca617f1772db3b705d06..0822b8e616c56130441f555f5dbfc860cc66db34 100644 (file)
@@ -24,6 +24,7 @@
 using namespace std;
 
 ARDOUR::Progress::Progress ()
+       : _cancelled (false)
 {
        descend (1);
 }
@@ -70,3 +71,15 @@ ARDOUR::Progress::set_progress (float p)
 
        set_overall_progress (overall);
 }
+
+void
+ARDOUR::Progress::cancel ()
+{
+       _cancelled = true;
+}
+
+bool
+ARDOUR::Progress::cancelled () const
+{
+       return _cancelled;
+}