From 935aeb55dd5fbce9fb9b1dd7770834b3b684a6d1 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 27 Oct 2010 14:22:24 +0000 Subject: [PATCH] Use ProgressReporter class for normalization. Report progress for individual regions. Fix crash on normalising a single region (#3510). git-svn-id: svn://localhost/ardour2/branches/3.0@7924 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/editor_ops.cc | 23 +++++++++++++++++------ gtk2_ardour/normalize_dialog.cc | 14 +++++--------- gtk2_ardour/normalize_dialog.h | 6 ++++-- gtk2_ardour/progress_reporter.h | 5 +++++ libs/ardour/ardour/audioregion.h | 2 +- libs/ardour/ardour/progress.h | 5 +++++ libs/ardour/audioregion.cc | 4 +++- 7 files changed, 40 insertions(+), 19 deletions(-) diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index f84f8f5d34..a07f1dccec 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -4509,12 +4509,14 @@ Editor::normalize_region () set_canvas_cursor (wait_cursor); gdk_flush (); + /* XXX: this should really count only audio regions */ + int tasks = rs.size (); if (!dialog.normalize_individually()) { tasks *= 2; } - int n = 0; + int n = 1; double maxamp = 0; if (!dialog.normalize_individually()) { @@ -4523,8 +4525,12 @@ Editor::normalize_region () if (!arv) { continue; } - maxamp = max (maxamp, arv->audio_region()->maximum_amplitude ()); - dialog.set_progress (double (n) / tasks); + + dialog.descend (1.0 / tasks); + maxamp = max (maxamp, arv->audio_region()->maximum_amplitude (&dialog)); + dialog.ascend (); + + dialog.set_progress (float (n) / tasks); ++n; } } @@ -4536,12 +4542,17 @@ Editor::normalize_region () } arv->region()->clear_changes (); - double const amp = dialog.normalize_individually () ? arv->audio_region()->maximum_amplitude () : maxamp; - + double amp = maxamp; + if (dialog.normalize_individually()) { + dialog.descend (1.0 / tasks); + amp = arv->audio_region()->maximum_amplitude (&dialog); + dialog.ascend (); + } + arv->audio_region()->normalize (amp, dialog.target ()); _session->add_command (new StatefulDiffCommand (arv->region())); - dialog.set_progress (double (n) / tasks); + dialog.set_progress (float (n) / tasks); ++n; } diff --git a/gtk2_ardour/normalize_dialog.cc b/gtk2_ardour/normalize_dialog.cc index 088c123433..2c2077a085 100644 --- a/gtk2_ardour/normalize_dialog.cc +++ b/gtk2_ardour/normalize_dialog.cc @@ -56,11 +56,11 @@ NormalizeDialog::NormalizeDialog (bool more_than_one) vbox->pack_start (*b); get_vbox()->pack_start (*vbox); - - _progress_bar = manage (new ProgressBar); - get_vbox()->pack_start (*_progress_bar); } + _progress_bar = manage (new ProgressBar); + get_vbox()->pack_start (*_progress_bar); + show_all (); add_button (Stock::CANCEL, RESPONSE_CANCEL); @@ -71,7 +71,7 @@ bool NormalizeDialog::normalize_individually () const { if (_normalize_individually == 0) { - return false; + return true; } return _normalize_individually->get_active (); @@ -84,11 +84,7 @@ NormalizeDialog::target () const } void -NormalizeDialog::set_progress (double p) +NormalizeDialog::update_progress_gui (float p) { _progress_bar->set_fraction (p); - - while (gtk_events_pending()) { - gtk_main_iteration (); - } } diff --git a/gtk2_ardour/normalize_dialog.h b/gtk2_ardour/normalize_dialog.h index 38ad6d0bf3..26bac98003 100644 --- a/gtk2_ardour/normalize_dialog.h +++ b/gtk2_ardour/normalize_dialog.h @@ -18,6 +18,7 @@ */ #include "ardour_dialog.h" +#include "progress_reporter.h" namespace Gtk { class RadioButton; @@ -25,16 +26,17 @@ namespace Gtk { class ProgressBar; } -class NormalizeDialog : public ArdourDialog +class NormalizeDialog : public ArdourDialog, public ProgressReporter { public: NormalizeDialog (bool); bool normalize_individually () const; double target () const; - void set_progress (double); private: + void update_progress_gui (float); + Gtk::RadioButton* _normalize_individually; Gtk::SpinButton* _spin; Gtk::ProgressBar* _progress_bar; diff --git a/gtk2_ardour/progress_reporter.h b/gtk2_ardour/progress_reporter.h index 6426f8f1aa..0fbabf5d23 100644 --- a/gtk2_ardour/progress_reporter.h +++ b/gtk2_ardour/progress_reporter.h @@ -17,6 +17,9 @@ */ +#ifndef __ardour_progress_reporter_h__ +#define __ardour_progress_reporter_h__ + #include "ardour/progress.h" /** A parent class for classes which can report progress on something */ @@ -34,3 +37,5 @@ private: */ virtual void update_progress_gui (float p) = 0; }; + +#endif diff --git a/libs/ardour/ardour/audioregion.h b/libs/ardour/ardour/audioregion.h index b919b6572c..302d1d1698 100644 --- a/libs/ardour/ardour/audioregion.h +++ b/libs/ardour/ardour/audioregion.h @@ -83,7 +83,7 @@ class AudioRegion : public Region gain_t scale_amplitude() const { return _scale_amplitude; } void normalize (float, float target_in_dB = 0.0f); - double maximum_amplitude () const; + double maximum_amplitude (Progress *) const; bool envelope_active () const { return _envelope_active; } bool fade_in_active () const { return _fade_in_active; } diff --git a/libs/ardour/ardour/progress.h b/libs/ardour/ardour/progress.h index 891af22059..e252c63bd8 100644 --- a/libs/ardour/ardour/progress.h +++ b/libs/ardour/ardour/progress.h @@ -17,6 +17,9 @@ */ +#ifndef __ardour_progress_h__ +#define __ardour_progress_h__ + #include namespace ARDOUR { @@ -49,3 +52,5 @@ private: }; } + +#endif diff --git a/libs/ardour/audioregion.cc b/libs/ardour/audioregion.cc index e4c4b55a54..1461e1a3a4 100644 --- a/libs/ardour/audioregion.cc +++ b/libs/ardour/audioregion.cc @@ -45,6 +45,7 @@ #include "ardour/region_factory.h" #include "ardour/runtime_functions.h" #include "ardour/transient_detector.h" +#include "ardour/progress.h" #include "i18n.h" #include @@ -1144,7 +1145,7 @@ AudioRegion::set_scale_amplitude (gain_t g) /** @return the maximum (linear) amplitude of the region */ double -AudioRegion::maximum_amplitude () const +AudioRegion::maximum_amplitude (Progress* p) const { framepos_t fpos = _start; framepos_t const fend = _start + _length; @@ -1171,6 +1172,7 @@ AudioRegion::maximum_amplitude () const } fpos += to_read; + p->set_progress (float (fpos - _start) / _length); } return maxamp;