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