Fix ExportFormatSpecification copy-c'tor
[ardour.git] / gtk2_ardour / normalize_dialog.cc
1 /*
2     Copyright (C) 2010 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
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"
27 #include "pbd/i18n.h"
28
29 using namespace Gtk;
30
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;
35
36 NormalizeDialog::NormalizeDialog (bool more_than_one)
37         : ArdourDialog (more_than_one ? _("Normalize regions") : _("Normalize region"))
38         , _normalize_individually (0)
39 {
40         get_vbox()->set_spacing (12);
41
42         Table* tbl = manage (new Table);
43         tbl->set_spacings (6);
44         tbl->set_border_width (6);
45
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 ();
51
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);
58
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);
62
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);
66
67         get_vbox()->pack_start (*tbl);
68
69         if (more_than_one) {
70                 RadioButtonGroup group;
71                 VBox* vbox = manage (new VBox);
72
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);
77
78                 _normalize_individually->set_active (_last_normalize_individually);
79                 b->set_active (!_last_normalize_individually);
80
81                 get_vbox()->pack_start (*vbox);
82         }
83
84         _progress_bar = manage (new ProgressBar);
85         get_vbox()->pack_start (*_progress_bar);
86
87         update_sensitivity ();
88         show_all ();
89         _progress_bar->hide ();
90
91         add_button (Stock::CANCEL, RESPONSE_CANCEL);
92         add_button (_("Normalize"), RESPONSE_ACCEPT);
93         set_default_response (RESPONSE_ACCEPT);
94
95         _constrain_rms->signal_toggled ().connect (sigc::mem_fun (*this, &NormalizeDialog::update_sensitivity));
96         signal_response().connect (sigc::mem_fun (*this, &NormalizeDialog::button_clicked));
97 }
98
99 void
100 NormalizeDialog::update_sensitivity ()
101 {
102         _spin_rms->set_sensitive (constrain_rms ());
103 }
104
105 bool
106 NormalizeDialog::normalize_individually () const
107 {
108         if (_normalize_individually == 0) {
109                 return true;
110         }
111
112         return _normalize_individually->get_active ();
113 }
114
115 bool
116 NormalizeDialog::constrain_rms () const
117 {
118         return _constrain_rms->get_active ();
119 }
120
121 double
122 NormalizeDialog::target_peak () const
123 {
124         return _spin_peak->get_value ();
125 }
126
127 double
128 NormalizeDialog::target_rms () const
129 {
130         return _spin_rms->get_value ();
131 }
132
133 void
134 NormalizeDialog::update_progress_gui (float p)
135 {
136         /* Normalization is run inside the GUI thread, so we can directly
137          * update the progress bar when notified about progress.
138          */
139         _progress_bar->show ();
140         _progress_bar->set_fraction (p);
141 }
142
143 int
144 NormalizeDialog::run ()
145 {
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 ();
152         }
153         return r;
154 }
155
156 void
157 NormalizeDialog::button_clicked (int r)
158 {
159         if (r == RESPONSE_CANCEL) {
160                 cancel ();
161         }
162 }