summaryrefslogtreecommitdiff
path: root/gtk2_ardour/editor_ops.cc
diff options
context:
space:
mode:
authorCarl Hetherington <carl@carlh.net>2010-10-27 21:21:50 +0000
committerCarl Hetherington <carl@carlh.net>2010-10-27 21:21:50 +0000
commitd75239caea44ea47b06a74efdfe197d4e8fd1500 (patch)
treed355fb0e8c80f9fe13fcb1488bdbef46299ff36f /gtk2_ardour/editor_ops.cc
parent67b4433b0c8b83ca03dbc517c71e85b9ab619a0f (diff)
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
Diffstat (limited to 'gtk2_ardour/editor_ops.cc')
-rw-r--r--gtk2_ardour/editor_ops.cc50
1 files changed, 20 insertions, 30 deletions
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<AudioRegionView*> (*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<double> max_amps;
+ double max_amp = 0;
+ for (RegionSelection::const_iterator i = rs.begin(); i != rs.end(); ++i) {
+ AudioRegionView const * arv = dynamic_cast<AudioRegionView const *> (*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<double>::const_iterator a = max_amps.begin ();
for (RegionSelection::iterator r = rs.begin(); r != rs.end(); ++r) {
AudioRegionView* const arv = dynamic_cast<AudioRegionView*> (*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 ();