2 Copyright (C) 2010 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <gtkmm/table.h>
21 #include <gtkmm/label.h>
22 #include <gtkmm/spinbutton.h>
23 #include <gtkmm/radiobutton.h>
24 #include <gtkmm/stock.h>
25 #include <gtkmm/progressbar.h>
26 #include "normalize_dialog.h"
31 double NormalizeDialog::_last_normalization_value = 0;
32 double NormalizeDialog::_last_rms_target_value = -9;
33 bool NormalizeDialog::_last_normalize_individually = true;
34 bool NormalizeDialog::_last_constrain_rms = false;
36 NormalizeDialog::NormalizeDialog (bool more_than_one)
37 : ArdourDialog (more_than_one ? _("Normalize regions") : _("Normalize region"))
38 , _normalize_individually (0)
40 get_vbox()->set_spacing (12);
42 Table* tbl = manage (new Table);
43 tbl->set_spacings (6);
44 tbl->set_border_width (6);
46 _spin_peak = manage (new SpinButton (0.2, 2));
47 _spin_peak->set_range (-112, 0);
48 _spin_peak->set_increments (0.1, 1);
49 _spin_peak->set_value (_last_normalization_value);
50 _spin_peak->set_activates_default ();
52 _constrain_rms = manage (new CheckButton (_("Constrain RMS to:")));
53 _constrain_rms->set_active (_last_constrain_rms);
54 _spin_rms = manage (new SpinButton (0.2, 2));
55 _spin_rms->set_range (-112, 0);
56 _spin_rms->set_increments (0.1, 1);
57 _spin_rms->set_value (_last_rms_target_value);
59 tbl->attach (*manage (new Label (_("Normalize to:"), ALIGN_END)), 0, 1, 0, 1, FILL, SHRINK);
60 tbl->attach (*_spin_peak, 1, 2, 0, 1, SHRINK, SHRINK);
61 tbl->attach (*manage (new Label (_("dBFS"))), 2, 3, 0, 1, SHRINK, SHRINK);
63 tbl->attach (*_constrain_rms, 0, 1, 1, 2, SHRINK, SHRINK);
64 tbl->attach (*_spin_rms, 1, 2, 1, 2, SHRINK, SHRINK);
65 tbl->attach (*manage (new Label (_("dBFS"))), 2, 3, 1, 2, SHRINK, SHRINK);
67 get_vbox()->pack_start (*tbl);
70 RadioButtonGroup group;
71 VBox* vbox = manage (new VBox);
73 _normalize_individually = manage (new RadioButton (group, _("Normalize each region using its own peak value")));
74 vbox->pack_start (*_normalize_individually);
75 RadioButton* b = manage (new RadioButton (group, _("Normalize each region using the peak value of all regions")));
76 vbox->pack_start (*b);
78 _normalize_individually->set_active (_last_normalize_individually);
79 b->set_active (!_last_normalize_individually);
81 get_vbox()->pack_start (*vbox);
84 _progress_bar = manage (new ProgressBar);
85 get_vbox()->pack_start (*_progress_bar);
87 update_sensitivity ();
89 _progress_bar->hide ();
91 add_button (Stock::CANCEL, RESPONSE_CANCEL);
92 add_button (_("Normalize"), RESPONSE_ACCEPT);
93 set_default_response (RESPONSE_ACCEPT);
95 _constrain_rms->signal_toggled ().connect (sigc::mem_fun (*this, &NormalizeDialog::update_sensitivity));
96 signal_response().connect (sigc::mem_fun (*this, &NormalizeDialog::button_clicked));
100 NormalizeDialog::update_sensitivity ()
102 _spin_rms->set_sensitive (constrain_rms ());
106 NormalizeDialog::normalize_individually () const
108 if (_normalize_individually == 0) {
112 return _normalize_individually->get_active ();
116 NormalizeDialog::constrain_rms () const
118 return _constrain_rms->get_active ();
122 NormalizeDialog::target_peak () const
124 return _spin_peak->get_value ();
128 NormalizeDialog::target_rms () const
130 return _spin_rms->get_value ();
134 NormalizeDialog::update_progress_gui (float p)
136 /* Normalization is run inside the GUI thread, so we can directly
137 * update the progress bar when notified about progress.
139 _progress_bar->show ();
140 _progress_bar->set_fraction (p);
144 NormalizeDialog::run ()
146 int const r = ArdourDialog::run ();
147 _last_normalization_value = target_peak ();
148 _last_rms_target_value = target_rms ();
149 _last_constrain_rms = constrain_rms ();
150 if (_normalize_individually) {
151 _last_normalize_individually = _normalize_individually->get_active ();
157 NormalizeDialog::button_clicked (int r)
159 if (r == RESPONSE_CANCEL) {