Make normalize cancel button work.

git-svn-id: svn://localhost/ardour2/branches/3.0@7935 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Carl Hetherington 2010-10-28 17:09:32 +00:00
parent d731e4dba1
commit 6f9e9ad23e
6 changed files with 45 additions and 3 deletions

View 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) {

View 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 ();
}
}

View file

@ -37,6 +37,7 @@ public:
private:
void update_progress_gui (float);
void button_clicked (int);
Gtk::RadioButton* _normalize_individually;
Gtk::SpinButton* _spin;

View 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;
};
}

View 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;

View 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;
}