220673c294bd70587226710c54777ef32826e7f2
[ardour.git] / gtk2_ardour / vca_master_strip.cc
1 /*
2     Copyright (C) 2016 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 #include "pbd/convert.h"
20
21 #include "ardour/rc_configuration.h"
22 #include "ardour/vca.h"
23
24 #include "tooltips.h"
25 #include "vca_master_strip.h"
26 #include "gui_thread.h"
27
28 #include "i18n.h"
29
30 using namespace ARDOUR;
31 using namespace ARDOUR_UI_UTILS;
32 using namespace Gtkmm2ext;
33 using std::string;
34
35 VCAMasterStrip::VCAMasterStrip (Session* s, boost::shared_ptr<VCA> v)
36         : AxisView (s)
37         , _vca (v)
38         , gain_meter (s, 250)
39         , wide (true)
40 {
41         gain_meter.set_controls (boost::shared_ptr<Route>(),
42                                  boost::shared_ptr<PeakMeter>(),
43                                  boost::shared_ptr<Amp>(),
44                                  _vca->control());
45
46         solo_button.set_name ("solo button");
47         set_tooltip (solo_button, _("Solo slaves"));
48         solo_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::solo_release), false);
49
50         mute_button.set_name ("mute button");
51         set_tooltip (mute_button, _("Mute slaves"));
52         mute_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::mute_release), false);
53
54         hide_button.set_icon (ArdourIcon::CloseCross);
55         set_tooltip (&hide_button, _("Hide this VCA strip"));
56
57         width_button.set_icon (ArdourIcon::StripWidth);
58         set_tooltip (width_button, _("Click to toggle the width of this VCA strip."));
59
60         assign_button.set_text (_("-vca-"));
61         set_tooltip (assign_button, _("Click to assign a VCA Master to this VCA"));
62
63         width_button.signal_button_press_event().connect (sigc::mem_fun(*this, &VCAMasterStrip::width_button_pressed), false);
64         hide_button.signal_clicked.connect (sigc::mem_fun(*this, &VCAMasterStrip::hide_clicked));
65
66         width_hide_box.set_spacing (2);
67         width_hide_box.pack_start (width_button, false, true);
68         width_hide_box.pack_start (number_label, true, true);
69         width_hide_box.pack_end (hide_button, false, true);
70
71         solo_mute_box.set_spacing (2);
72         solo_mute_box.pack_start (mute_button, true, true);
73         solo_mute_box.pack_start (solo_button, true, true);
74
75         number_label.set_text (PBD::to_string (v->number(), std::dec));
76         number_label.set_elements((ArdourButton::Element)(ArdourButton::Edge|ArdourButton::Body|ArdourButton::Text|ArdourButton::Inactive));
77         number_label.set_no_show_all ();
78         number_label.set_name ("tracknumber label");
79         number_label.set_fixed_colors (0x80808080, 0x80808080);
80         number_label.set_alignment (.5, .5);
81         number_label.set_fallthrough_to_parent (true);
82
83         name_button.set_text (_vca->name());
84         active_button.set_text ("active");
85
86         top_padding.set_size_request (-1, 16); /* must match height in GroupTabs::set_size_request() */
87         bottom_padding.set_size_request (-1, 50); /* this one is a hack. there's no trivial way to compute it */
88
89         global_vpacker.set_border_width (1);
90         global_vpacker.set_spacing (0);
91
92         global_vpacker.pack_start (top_padding, false, false);
93         global_vpacker.pack_start (width_hide_box, false, false);
94         global_vpacker.pack_start (active_button, false, false);
95         global_vpacker.pack_start (name_button, false, false);
96         global_vpacker.pack_start (vertical_padding, true, true);
97         global_vpacker.pack_start (solo_mute_box, false, false);
98         global_vpacker.pack_start (gain_meter, false, false);
99         global_vpacker.pack_start (assign_button, false, false);
100         global_vpacker.pack_start (bottom_padding, false, false);
101
102         global_frame.add (global_vpacker);
103         global_frame.set_shadow_type (Gtk::SHADOW_IN);
104         global_frame.set_name ("BaseFrame");
105
106         add (global_frame);
107
108         global_vpacker.show ();
109         global_frame.show ();
110         top_padding.show ();
111         bottom_padding.show ();
112         vertical_padding.show ();
113         width_hide_box.show_all ();
114         active_button.show_all ();
115         name_button.show_all ();
116         gain_meter.show_all ();
117         solo_mute_box.show_all ();
118         assign_button.show ();
119
120         /* force setting of visible selected status */
121
122         _selected = true;
123         set_selected (false);
124         set_width (true);
125
126         _vca->SoloChange.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::solo_changed, this), gui_context());
127         _vca->MuteChange.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::mute_changed, this), gui_context());
128 }
129
130 string
131 VCAMasterStrip::name() const
132 {
133         return _vca->name();
134 }
135
136 void
137 VCAMasterStrip::hide_clicked ()
138 {
139 }
140
141 bool
142 VCAMasterStrip::width_button_pressed (GdkEventButton* ev)
143 {
144         return false;
145 }
146
147 void
148 VCAMasterStrip::set_selected (bool yn)
149 {
150         AxisView::set_selected (yn);
151
152         if (_selected) {
153                 global_frame.set_shadow_type (Gtk::SHADOW_ETCHED_OUT);
154                 global_frame.set_name ("MixerStripSelectedFrame");
155         } else {
156                 global_frame.set_shadow_type (Gtk::SHADOW_IN);
157                 global_frame.set_name ("MixerStripFrame");
158         }
159
160         global_frame.queue_draw ();
161 }
162
163 bool
164 VCAMasterStrip::solo_release (GdkEventButton*)
165 {
166         _vca->set_solo (!_vca->soloed());
167         return true;
168 }
169
170 bool
171 VCAMasterStrip::mute_release (GdkEventButton*)
172 {
173         _vca->set_mute (!_vca->muted());
174         return true;
175 }
176
177 void
178 VCAMasterStrip::set_solo_text ()
179 {
180         if (wide) {
181                 if (Config->get_solo_control_is_listen_control ()) {
182                         switch (Config->get_listen_position()) {
183                         case AfterFaderListen:
184                                 solo_button.set_text (_("AFL"));
185                                 break;
186                         case PreFaderListen:
187                                 solo_button.set_text (_("PFL"));
188                                 break;
189                         }
190                 } else {
191                         solo_button.set_text (_("Solo"));
192                 }
193         } else {
194                 if (Config->get_solo_control_is_listen_control ()) {
195                         switch (Config->get_listen_position()) {
196                         case AfterFaderListen:
197                                 solo_button.set_text (_("A"));
198                                 break;
199                         case PreFaderListen:
200                                 solo_button.set_text (_("P"));
201                                 break;
202                         }
203                 } else {
204                         solo_button.set_text (_("S"));
205                 }
206         }
207 }
208
209 void
210 VCAMasterStrip::set_width (bool w)
211 {
212         wide = w;
213
214         if (wide) {
215                 mute_button.set_text (_("Mute"));
216         } else {
217                 mute_button.set_text (_("m"));
218         }
219
220         set_solo_text ();
221 }
222
223 void
224 VCAMasterStrip::mute_changed ()
225 {
226         if (_vca->muted()) {
227                 mute_button.set_active_state (ExplicitActive);
228         } else {
229                 mute_button.set_active_state (Gtkmm2ext::Off);
230         }
231 }
232
233 void
234 VCAMasterStrip::solo_changed ()
235 {
236         if (_vca->soloed()) {
237                 solo_button.set_active_state (ExplicitActive);
238         } else {
239                 solo_button.set_active_state (Gtkmm2ext::Off);
240         }
241 }