2 Copyright (C) 2012 Paul Davis
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.
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.
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.
20 #include <gtkmm/table.h>
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"
31 using namespace Gtkmm2ext;
33 using PBD::Controllable;
35 MonoPannerEditor::MonoPannerEditor (MonoPanner* p)
36 : PannerEditor (_("Mono Panner"))
38 , _ignore_changes (false)
40 Table* t = manage (new Table (2, 3));
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);
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);
55 get_vbox()->pack_start (*manage (t));
56 get_vbox()->set_spacing (6);
58 _left.set_increments (1, 10);
59 _left.set_range (0, 100);
60 _right.set_increments (1, 10);
61 _right.set_range (0, 100);
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));
73 MonoPannerEditor::panner_going_away ()
79 MonoPannerEditor::update_editor ()
85 float const v = _panner->get_controllable()->get_value();
87 _ignore_changes = true;
88 _left.set_value (100 * (1 - v));
89 _right.set_value (100 * v);
90 _ignore_changes = false;
94 MonoPannerEditor::left_changed ()
96 if (_ignore_changes || !_panner) {
100 float const v = 1 - _left.get_value () / 100;
102 _ignore_changes = true;
103 _right.set_value (100 * v);
104 _panner->get_controllable()->set_value (v, Controllable::NoGroup);
105 _ignore_changes = false;
109 MonoPannerEditor::right_changed ()
111 if (_ignore_changes || !_panner) {
115 float const v = _right.get_value () / 100;
117 _ignore_changes = true;
118 _left.set_value (100 * (1 - v));
119 _panner->get_controllable()->set_value (v, Controllable::NoGroup);
120 _ignore_changes = false;