Make Enter give RESPONSE_ACCEPT in the normalize dialogue (#3937).
[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/label.h>
21 #include <gtkmm/spinbutton.h>
22 #include <gtkmm/radiobutton.h>
23 #include <gtkmm/stock.h>
24 #include <gtkmm/progressbar.h>
25 #include "normalize_dialog.h"
26
27 using namespace Gtk;
28
29 double NormalizeDialog::_last_normalization_value = 0;
30 bool NormalizeDialog::_last_normalize_individually = true;
31
32 NormalizeDialog::NormalizeDialog (bool more_than_one)
33         : ArdourDialog (more_than_one ? _("Normalize regions") : _("Normalize region"))
34         , _normalize_individually (0)
35 {
36         get_vbox()->set_spacing (12);
37         
38         HBox* hbox = manage (new HBox);
39         hbox->set_spacing (6);
40         hbox->set_border_width (6);
41         hbox->pack_start (*manage (new Label (_("Normalize to:"))), false, false);
42         _spin = manage (new SpinButton (0.2, 2));
43         _spin->set_range (-112, 0);
44         _spin->set_increments (0.1, 1);
45         _spin->set_value (_last_normalization_value);
46         _spin->set_activates_default ();
47         hbox->pack_start (*_spin, false, false);
48         hbox->pack_start (*manage (new Label (_("dbFS"))), false, false);
49         get_vbox()->pack_start (*hbox);
50
51         if (more_than_one) {
52                 RadioButtonGroup group;
53                 VBox* vbox = manage (new VBox);
54
55                 _normalize_individually = manage (new RadioButton (group, _("Normalize each region using its own peak value")));
56                 vbox->pack_start (*_normalize_individually);
57                 RadioButton* b = manage (new RadioButton (group, _("Normalize each region using the peak value of all regions")));
58                 vbox->pack_start (*b);
59
60                 _normalize_individually->set_active (_last_normalize_individually);
61                 b->set_active (!_last_normalize_individually);
62
63                 get_vbox()->pack_start (*vbox);
64         }
65
66         _progress_bar = manage (new ProgressBar);
67         get_vbox()->pack_start (*_progress_bar);
68
69         show_all ();
70         
71         add_button (Stock::CANCEL, RESPONSE_CANCEL);
72         add_button (_("Normalize"), RESPONSE_ACCEPT);
73         set_default_response (RESPONSE_ACCEPT);
74
75         signal_response().connect (sigc::mem_fun (*this, &NormalizeDialog::button_clicked));
76 }
77
78 bool
79 NormalizeDialog::normalize_individually () const
80 {
81         if (_normalize_individually == 0) {
82                 return true;
83         }
84
85         return _normalize_individually->get_active ();
86 }
87
88 double
89 NormalizeDialog::target () const
90 {
91         return _spin->get_value ();
92 }
93
94 void
95 NormalizeDialog::update_progress_gui (float p)
96 {
97         _progress_bar->set_fraction (p);
98 }
99
100 int
101 NormalizeDialog::run ()
102 {
103         int const r = ArdourDialog::run ();
104         _last_normalization_value = target ();
105         if (_normalize_individually) {
106                 _last_normalize_individually = _normalize_individually->get_active ();
107         }
108         return r;
109 }
110
111 void
112 NormalizeDialog::button_clicked (int r)
113 {
114         if (r == RESPONSE_CANCEL) {
115                 cancel ();
116         }
117 }