From d75239caea44ea47b06a74efdfe197d4e8fd1500 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 27 Oct 2010 21:21:50 +0000 Subject: Improve efficiency of normalization using multiple regions in some cases. git-svn-id: svn://localhost/ardour2/branches/3.0@7929 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/editor_ops.cc | 50 +++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 30 deletions(-) (limited to 'gtk2_ardour/editor_ops.cc') diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index a07f1dccec..93cdbf2254 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -4509,51 +4509,41 @@ Editor::normalize_region () set_canvas_cursor (wait_cursor); gdk_flush (); - /* XXX: this should really count only audio regions */ + /* XXX: should really only count audio regions here */ + int const regions = rs.size (); - int tasks = rs.size (); - if (!dialog.normalize_individually()) { - tasks *= 2; - } - - int n = 1; - - double maxamp = 0; - if (!dialog.normalize_individually()) { - for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) { - AudioRegionView* const arv = dynamic_cast (*r); - if (!arv) { - continue; - } - - dialog.descend (1.0 / tasks); - maxamp = max (maxamp, arv->audio_region()->maximum_amplitude (&dialog)); + /* Make a list of the selected audio regions' maximum amplitudes, and also + obtain the maximum amplitude of them all. + */ + list max_amps; + double max_amp = 0; + for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) { + AudioRegionView const * arv = dynamic_cast (*i); + if (arv) { + dialog.descend (1.0 / regions); + double const a = arv->audio_region()->maximum_amplitude (&dialog); + max_amps.push_back (a); + max_amp = max (max_amp, a); dialog.ascend (); - - dialog.set_progress (float (n) / tasks); - ++n; } } + + list::const_iterator a = max_amps.begin (); for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) { AudioRegionView* const arv = dynamic_cast (*r); if (!arv) { continue; } - arv->region()->clear_changes (); - double amp = maxamp; - if (dialog.normalize_individually()) { - dialog.descend (1.0 / tasks); - amp = arv->audio_region()->maximum_amplitude (&dialog); - dialog.ascend (); - } + arv->region()->clear_changes (); + double const amp = dialog.normalize_individually() ? *a : max_amp; + arv->audio_region()->normalize (amp, dialog.target ()); _session->add_command (new StatefulDiffCommand (arv->region())); - dialog.set_progress (float (n) / tasks); - ++n; + ++a; } commit_reversible_command (); -- cgit v1.2.3