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