2 * Copyright (C) 2016 Paul Davis <paul@linuxaudiosystems.com>
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 along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "gtkmm2ext/utils.h"
21 #include "gtkmm2ext/gtk_ui.h"
22 #include "gtkmm2ext/gui_thread.h"
23 #include "ardour/panner.h"
24 #include "pbd/controllable.h"
25 #include "stereo_panner_editor.h"
26 #include "stereo_panner.h"
31 using namespace Gtkmm2ext;
33 using PBD::Controllable;
35 StereoPannerEditor::StereoPannerEditor (StereoPanner* p)
36 : PannerEditor (_("Stereo Panner"))
38 , _ignore_changes (false)
40 Table* t = manage (new Table (2, 3));
45 t->attach (*manage (left_aligned_label (_("Position"))), 0, 1, n, n + 1);
46 t->attach (_position, 1, 2, n, n + 1);
47 t->attach (*manage (left_aligned_label (_("%"))), 2, 3, n, n + 1);
50 t->attach (*manage (left_aligned_label (_("Width"))), 0, 1, n, n + 1);
51 t->attach (_width, 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 _position.set_increments (1, 10);
59 _width.set_increments (1, 10);
60 set_position_range ();
63 _panner->get_position_controllable()->Changed.connect (
64 _connections, invalidator (*this), boost::bind (&StereoPannerEditor::update_editor, this), gui_context ()
67 _panner->get_width_controllable()->Changed.connect (
68 _connections, invalidator (*this), boost::bind (&StereoPannerEditor::update_editor, this), gui_context ()
71 _panner->DropReferences.connect (_connections, invalidator (*this), boost::bind (&StereoPannerEditor::panner_going_away, this), gui_context ());
72 _position.signal_value_changed().connect (sigc::mem_fun (*this, &StereoPannerEditor::position_changed));
73 _width.signal_value_changed().connect (sigc::mem_fun (*this, &StereoPannerEditor::width_changed));
80 StereoPannerEditor::panner_going_away ()
86 StereoPannerEditor::update_editor ()
92 _ignore_changes = true;
93 _position.set_value (100 * _panner->get_position_controllable()->get_value ());
94 _width.set_value (100 * _panner->get_width_controllable()->get_value ());
95 _ignore_changes = false;
99 StereoPannerEditor::position_changed ()
101 if (_ignore_changes || !_panner) {
105 _ignore_changes = true;
106 double const v = _position.get_value() / 100;
107 _panner->get_position_controllable()->set_value (v, Controllable::NoGroup);
109 _ignore_changes = false;
113 StereoPannerEditor::width_changed ()
115 if (_ignore_changes || !_panner) {
119 _ignore_changes = true;
120 double const v = _width.get_value() / 100;
121 _panner->get_width_controllable()->set_value (v, Controllable::NoGroup);
122 set_position_range ();
123 _ignore_changes = false;
127 StereoPannerEditor::set_position_range ()
129 pair<double, double> const pr = _panner->panner()->position_range ();
130 _position.set_range (pr.first * 100, pr.second * 100);
134 StereoPannerEditor::set_width_range ()
136 pair<double, double> const wr = _panner->panner()->width_range ();
137 _width.set_range (wr.first * 100, wr.second * 100);