enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / mono_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 "pbd/controllable.h"
25 #include "mono_panner_editor.h"
26 #include "mono_panner.h"
27 #include "pbd/i18n.h"
28
29 using namespace Gtk;
30 using namespace Gtkmm2ext;
31
32 using PBD::Controllable;
33
34 MonoPannerEditor::MonoPannerEditor (MonoPanner* p)
35         : PannerEditor (_("Mono Panner"))
36         , _panner (p)
37         , _ignore_changes (false)
38 {
39         Table* t = manage (new Table (2, 3));
40         t->set_spacings (6);
41
42         int n = 0;
43
44         t->attach (*manage (left_aligned_label (_("Left"))), 0, 1, n, n + 1);
45         t->attach (_left, 1, 2, n, n + 1);
46         t->attach (*manage (left_aligned_label (_("%"))), 2, 3, n, n + 1);
47         ++n;
48
49         t->attach (*manage (left_aligned_label (_("Right"))), 0, 1, n, n + 1);
50         t->attach (_right, 1, 2, n, n + 1);
51         t->attach (*manage (left_aligned_label (_("%"))), 2, 3, n, n + 1);
52         ++n;
53
54         get_vbox()->pack_start (*manage (t));
55         get_vbox()->set_spacing (6);
56
57         _left.set_increments (1, 10);
58         _left.set_range (0, 100);
59         _right.set_increments (1, 10);
60         _right.set_range (0, 100);
61
62         _panner->get_controllable()->Changed.connect (_connections, invalidator (*this), boost::bind (&MonoPannerEditor::update_editor, this), gui_context ());
63         _panner->DropReferences.connect (_connections, invalidator (*this), boost::bind (&MonoPannerEditor::panner_going_away, this), gui_context ());
64         _left.signal_value_changed().connect (sigc::mem_fun (*this, &MonoPannerEditor::left_changed));
65         _right.signal_value_changed().connect (sigc::mem_fun (*this, &MonoPannerEditor::right_changed));
66
67         show_all ();
68         update_editor ();
69 }
70
71 void
72 MonoPannerEditor::panner_going_away ()
73 {
74         _panner = 0;
75 }
76
77 void
78 MonoPannerEditor::update_editor ()
79 {
80         if (!_panner) {
81                 return;
82         }
83
84         float const v = _panner->get_controllable()->get_value();
85
86         _ignore_changes = true;
87         _left.set_value (100 * (1 - v));
88         _right.set_value (100 * v);
89         _ignore_changes = false;
90 }
91
92 void
93 MonoPannerEditor::left_changed ()
94 {
95         if (_ignore_changes || !_panner) {
96                 return;
97         }
98
99         float const v = 1 - _left.get_value () / 100;
100
101         _ignore_changes = true;
102         _right.set_value (100 * v);
103         _panner->get_controllable()->set_value (v, Controllable::NoGroup);
104         _ignore_changes = false;
105 }
106
107 void
108 MonoPannerEditor::right_changed ()
109 {
110         if (_ignore_changes || !_panner) {
111                 return;
112         }
113
114         float const v = _right.get_value () / 100;
115
116         _ignore_changes = true;
117         _left.set_value (100 * (1 - v));
118         _panner->get_controllable()->set_value (v, Controllable::NoGroup);
119         _ignore_changes = false;
120 }
121