~ubuntu-branches/ubuntu/utopic/ardour3/utopic

« back to all changes in this revision

Viewing changes to gtk2_ardour/stereo_panner_editor.cc

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler
  • Date: 2013-09-21 19:05:02 UTC
  • Revision ID: package-import@ubuntu.com-20130921190502-8gsftrku6jnzhd7v
Tags: upstream-3.4~dfsg
ImportĀ upstreamĀ versionĀ 3.4~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "ardour/panner.h"
 
25
#include "pbd/controllable.h"
 
26
#include "stereo_panner_editor.h"
 
27
#include "stereo_panner.h"
 
28
#include "i18n.h"
 
29
 
 
30
using namespace std;
 
31
using namespace Gtk;
 
32
using namespace Gtkmm2ext;
 
33
 
 
34
StereoPannerEditor::StereoPannerEditor (StereoPanner* p)
 
35
        : PannerEditor (_("Stereo 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 (_("Position"))), 0, 1, n, n + 1);
 
45
        t->attach (_position, 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 (_("Width"))), 0, 1, n, n + 1);
 
50
        t->attach (_width, 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
        _position.set_increments (1, 10);
 
58
        _width.set_increments (1, 10);
 
59
        set_position_range ();
 
60
        set_width_range ();
 
61
 
 
62
        _panner->get_position_controllable()->Changed.connect (
 
63
                _connections, invalidator (*this), boost::bind (&StereoPannerEditor::update_editor, this), gui_context ()
 
64
                );
 
65
 
 
66
        _panner->get_width_controllable()->Changed.connect (
 
67
                _connections, invalidator (*this), boost::bind (&StereoPannerEditor::update_editor, this), gui_context ()
 
68
                );
 
69
        
 
70
        _panner->DropReferences.connect (_connections, invalidator (*this), boost::bind (&StereoPannerEditor::panner_going_away, this), gui_context ());
 
71
        _position.signal_value_changed().connect (sigc::mem_fun (*this, &StereoPannerEditor::position_changed));
 
72
        _width.signal_value_changed().connect (sigc::mem_fun (*this, &StereoPannerEditor::width_changed));
 
73
 
 
74
        show_all ();
 
75
        update_editor ();
 
76
}
 
77
 
 
78
void
 
79
StereoPannerEditor::panner_going_away ()
 
80
{
 
81
        _panner = 0;
 
82
}
 
83
 
 
84
void
 
85
StereoPannerEditor::update_editor ()
 
86
{
 
87
        if (!_panner) {
 
88
                return;
 
89
        }
 
90
        
 
91
        _ignore_changes = true;
 
92
        _position.set_value (100 * _panner->get_position_controllable()->get_value ());
 
93
        _width.set_value (100 * _panner->get_width_controllable()->get_value ());
 
94
        _ignore_changes = false;
 
95
}
 
96
 
 
97
void
 
98
StereoPannerEditor::position_changed ()
 
99
{
 
100
        if (_ignore_changes || !_panner) {
 
101
                return;
 
102
        }
 
103
 
 
104
        _ignore_changes = true;
 
105
        double const v = _position.get_value() / 100;
 
106
        _panner->get_position_controllable()->set_value (v);
 
107
        set_width_range ();
 
108
        _ignore_changes = false;
 
109
}
 
110
 
 
111
void
 
112
StereoPannerEditor::width_changed ()
 
113
{
 
114
        if (_ignore_changes || !_panner) {
 
115
                return;
 
116
        }
 
117
 
 
118
        _ignore_changes = true;
 
119
        double const v = _width.get_value() / 100;
 
120
        _panner->get_width_controllable()->set_value (v);
 
121
        set_position_range ();
 
122
        _ignore_changes = false;
 
123
}
 
124
 
 
125
void
 
126
StereoPannerEditor::set_position_range ()
 
127
{
 
128
        pair<double, double> const pr = _panner->panner()->position_range ();
 
129
        _position.set_range (pr.first * 100, pr.second * 100);
 
130
}
 
131
 
 
132
void
 
133
StereoPannerEditor::set_width_range ()
 
134
{
 
135
        pair<double, double> const wr = _panner->panner()->width_range ();
 
136
        _width.set_range (wr.first * 100, wr.second * 100);
 
137
}
 
138