enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / stereo_panner_editor.cc
1 /*
2     Copyright (C) 2012 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.h>
21 #include "gtkmm2ext/utils.h"
22 #include "gtkmm2ext/gtk_ui.h"
23 #include "gtkmm2ext/gui_thread.h"
24 #include "ardour/panner.h"
25 #include "pbd/controllable.h"
26 #include "stereo_panner_editor.h"
27 #include "stereo_panner.h"
28 #include "pbd/i18n.h"
29
30 using namespace std;
31 using namespace Gtk;
32 using namespace Gtkmm2ext;
33
34 using PBD::Controllable;
35
36 StereoPannerEditor::StereoPannerEditor (StereoPanner* p)
37         : PannerEditor (_("Stereo Panner"))
38         , _panner (p)
39         , _ignore_changes (false)
40 {
41         Table* t = manage (new Table (2, 3));
42         t->set_spacings (6);
43
44         int n = 0;
45
46         t->attach (*manage (left_aligned_label (_("Position"))), 0, 1, n, n + 1);
47         t->attach (_position, 1, 2, n, n + 1);
48         t->attach (*manage (left_aligned_label (_("%"))), 2, 3, n, n + 1);
49         ++n;
50
51         t->attach (*manage (left_aligned_label (_("Width"))), 0, 1, n, n + 1);
52         t->attach (_width, 1, 2, n, n + 1);
53         t->attach (*manage (left_aligned_label (_("%"))), 2, 3, n, n + 1);
54         ++n;
55
56         get_vbox()->pack_start (*manage (t));
57         get_vbox()->set_spacing (6);
58
59         _position.set_increments (1, 10);
60         _width.set_increments (1, 10);
61         set_position_range ();
62         set_width_range ();
63
64         _panner->get_position_controllable()->Changed.connect (
65                 _connections, invalidator (*this), boost::bind (&StereoPannerEditor::update_editor, this), gui_context ()
66                 );
67
68         _panner->get_width_controllable()->Changed.connect (
69                 _connections, invalidator (*this), boost::bind (&StereoPannerEditor::update_editor, this), gui_context ()
70                 );
71
72         _panner->DropReferences.connect (_connections, invalidator (*this), boost::bind (&StereoPannerEditor::panner_going_away, this), gui_context ());
73         _position.signal_value_changed().connect (sigc::mem_fun (*this, &StereoPannerEditor::position_changed));
74         _width.signal_value_changed().connect (sigc::mem_fun (*this, &StereoPannerEditor::width_changed));
75
76         show_all ();
77         update_editor ();
78 }
79
80 void
81 StereoPannerEditor::panner_going_away ()
82 {
83         _panner = 0;
84 }
85
86 void
87 StereoPannerEditor::update_editor ()
88 {
89         if (!_panner) {
90                 return;
91         }
92
93         _ignore_changes = true;
94         _position.set_value (100 * _panner->get_position_controllable()->get_value ());
95         _width.set_value (100 * _panner->get_width_controllable()->get_value ());
96         _ignore_changes = false;
97 }
98
99 void
100 StereoPannerEditor::position_changed ()
101 {
102         if (_ignore_changes || !_panner) {
103                 return;
104         }
105
106         _ignore_changes = true;
107         double const v = _position.get_value() / 100;
108         _panner->get_position_controllable()->set_value (v, Controllable::NoGroup);
109         set_width_range ();
110         _ignore_changes = false;
111 }
112
113 void
114 StereoPannerEditor::width_changed ()
115 {
116         if (_ignore_changes || !_panner) {
117                 return;
118         }
119
120         _ignore_changes = true;
121         double const v = _width.get_value() / 100;
122         _panner->get_width_controllable()->set_value (v, Controllable::NoGroup);
123         set_position_range ();
124         _ignore_changes = false;
125 }
126
127 void
128 StereoPannerEditor::set_position_range ()
129 {
130         pair<double, double> const pr = _panner->panner()->position_range ();
131         _position.set_range (pr.first * 100, pr.second * 100);
132 }
133
134 void
135 StereoPannerEditor::set_width_range ()
136 {
137         pair<double, double> const wr = _panner->panner()->width_range ();
138         _width.set_range (wr.first * 100, wr.second * 100);
139 }
140