summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gtk2_ardour/editor_ops.cc11
-rw-r--r--gtk2_ardour/normalize_dialog.cc10
-rw-r--r--gtk2_ardour/normalize_dialog.h1
-rw-r--r--libs/ardour/ardour/progress.h6
-rw-r--r--libs/ardour/audioregion.cc7
-rw-r--r--libs/ardour/progress.cc13
6 files changed, 45 insertions, 3 deletions
diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc
index b03df00cec..bce0e5c475 100644
--- a/gtk2_ardour/editor_ops.cc
+++ b/gtk2_ardour/editor_ops.cc
@@ -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) {
diff --git a/gtk2_ardour/normalize_dialog.cc b/gtk2_ardour/normalize_dialog.cc
index 9a34c3a4bb..716bfa7c39 100644
--- a/gtk2_ardour/normalize_dialog.cc
+++ b/gtk2_ardour/normalize_dialog.cc
@@ -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 ();
+ }
+}
diff --git a/gtk2_ardour/normalize_dialog.h b/gtk2_ardour/normalize_dialog.h
index fec46dbd08..1cb1ae1cb5 100644
--- a/gtk2_ardour/normalize_dialog.h
+++ b/gtk2_ardour/normalize_dialog.h
@@ -37,6 +37,7 @@ public:
private:
void update_progress_gui (float);
+ void button_clicked (int);
Gtk::RadioButton* _normalize_individually;
Gtk::SpinButton* _spin;
diff --git a/libs/ardour/ardour/progress.h b/libs/ardour/ardour/progress.h
index e252c63bd8..6cd66bdcbe 100644
--- a/libs/ardour/ardour/progress.h
+++ b/libs/ardour/ardour/progress.h
@@ -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;
};
}
diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc
index 1461e1a3a4..be3b80de87 100644
--- a/libs/ardour/audioregion.cc
+++ b/libs/ardour/audioregion.cc
@@ -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;
diff --git a/libs/ardour/progress.cc b/libs/ardour/progress.cc
index d09309f793..0822b8e616 100644
--- a/libs/ardour/progress.cc
+++ b/libs/ardour/progress.cc
@@ -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;
+}