additional i18n.h changes for push2 branch
[ardour.git] / libs / surfaces / push2 / track_mix.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 <pangomm/layout.h>
20
21 #include "pbd/compose.h"
22 #include "pbd/convert.h"
23 #include "pbd/debug.h"
24 #include "pbd/failed_constructor.h"
25 #include "pbd/file_utils.h"
26 #include "pbd/search_path.h"
27 #include "pbd/enumwriter.h"
28
29 #include "midi++/parser.h"
30 #include "timecode/time.h"
31 #include "timecode/bbt_time.h"
32
33 #include "ardour/async_midi_port.h"
34 #include "ardour/audioengine.h"
35 #include "ardour/debug.h"
36 #include "ardour/filesystem_paths.h"
37 #include "ardour/midiport_manager.h"
38 #include "ardour/midi_track.h"
39 #include "ardour/midi_port.h"
40 #include "ardour/session.h"
41 #include "ardour/tempo.h"
42
43 #include "gtkmm2ext/gui_thread.h"
44 #include "gtkmm2ext/rgb_macros.h"
45
46 #include "knob.h"
47 #include "menu.h"
48 #include "push2.h"
49 #include "track_mix.h"
50 #include "utils.h"
51
52 #include "pbd/i18n.h"
53
54 using namespace ARDOUR;
55 using namespace std;
56 using namespace PBD;
57 using namespace Glib;
58 using namespace ArdourSurface;
59
60 TrackMixLayout::TrackMixLayout (Push2& p, Session& s, Cairo::RefPtr<Cairo::Context> context)
61         : Push2Layout (p, s)
62         , _dirty (true)
63 {
64         Pango::FontDescription fd2 ("Sans 10");
65
66         for (int n = 0; n < 8; ++n) {
67                 upper_layout[n] = Pango::Layout::create (context);
68                 upper_layout[n]->set_font_description (fd2);
69
70                 lower_layout[n] = Pango::Layout::create (context);
71                 lower_layout[n]->set_font_description (fd2);
72
73                 switch (n) {
74                 case 0:
75                         upper_layout[n]->set_text (_("TRACK VOLUME"));
76                         lower_layout[n]->set_text (_("MUTE"));
77                         break;
78                 case 1:
79                         upper_layout[n]->set_text (_("TRACK PAN"));
80                         lower_layout[n]->set_text (_("SOLO"));
81                         break;
82                 case 2:
83                         upper_layout[n]->set_text (_("TRACK WIDTH"));
84                         lower_layout[n]->set_text (_("REC-ENABLE"));
85                         break;
86                 case 3:
87                         upper_layout[n]->set_text (_("TRACK TRIM"));
88                         lower_layout[n]->set_text (_("IN"));
89                         break;
90                 case 4:
91                         upper_layout[n]->set_text (_(""));
92                         lower_layout[n]->set_text (_("DISK"));
93                         break;
94                 case 5:
95                         upper_layout[n]->set_text (_(""));
96                         lower_layout[n]->set_text (_("SOLO ISO"));
97                         break;
98                 case 6:
99                         upper_layout[n]->set_text (_(""));
100                         lower_layout[n]->set_text (_("SOLO LOCK"));
101                         break;
102                 case 7:
103                         upper_layout[n]->set_text (_(""));
104                         lower_layout[n]->set_text (_(""));
105                         break;
106                 }
107
108                 knobs[n] = new Push2Knob (p2, context);
109                 knobs[n]->set_position (60 + (120*n), 95);
110                 knobs[n]->set_radius (25);
111         }
112
113         ControlProtocol::StripableSelectionChanged.connect (selection_connection, invalidator (*this), boost::bind (&TrackMixLayout::selection_changed, this), &p2);
114 }
115
116 TrackMixLayout::~TrackMixLayout ()
117 {
118         for (int n = 0; n < 8; ++n) {
119                 delete knobs[n];
120         }
121 }
122
123 void
124 TrackMixLayout::selection_changed ()
125 {
126         boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
127         if (s) {
128                 set_stripable (s);
129         }
130 }
131 void
132 TrackMixLayout::on_show ()
133 {
134         selection_changed ();
135 }
136
137 bool
138 TrackMixLayout::redraw (Cairo::RefPtr<Cairo::Context> context, bool force) const
139 {
140         bool children_dirty = false;
141
142         for (int n = 0; n < 8; ++n) {
143                 if (knobs[n]->dirty()) {
144                         children_dirty = true;
145                         break;
146                 }
147         }
148
149         if (!children_dirty) {
150                 return false;
151         }
152
153         set_source_rgb (context, p2.get_color (Push2::DarkBackground));
154         context->rectangle (0, 0, p2.cols, p2.rows);
155         context->fill ();
156
157         for (int n = 0; n < 8; ++n) {
158
159                 if (!upper_layout[n]->get_text().empty()) {
160
161                         /* Draw highlight box */
162
163                         uint32_t color = p2.get_color (Push2::ParameterName);
164                         set_source_rgb (context, color);
165
166                         context->move_to (10 + (n*120), 2);
167                         upper_layout[n]->update_from_cairo_context (context);
168                         upper_layout[n]->show_in_cairo_context (context);
169                 }
170
171                 if (!lower_layout[n]->get_text().empty()) {
172                         context->move_to (10 + (n*120), 140);
173                         lower_layout[n]->update_from_cairo_context (context);
174                         lower_layout[n]->show_in_cairo_context (context);
175                 }
176         }
177
178         context->move_to (0, 22.5);
179         context->line_to (p2.cols, 22.5);
180         context->set_line_width (1.0);
181         context->stroke ();
182
183         for (int n = 0; n < 8; ++n) {
184                 knobs[n]->redraw (context, force);
185         }
186
187         return true;
188 }
189
190 void
191 TrackMixLayout::button_upper (uint32_t n)
192 {
193 }
194
195 void
196 TrackMixLayout::button_lower (uint32_t n)
197 {
198 }
199
200 void
201 TrackMixLayout::set_stripable (boost::shared_ptr<Stripable> s)
202 {
203         stripable_connections.drop_connections ();
204
205         stripable = s;
206
207         if (stripable) {
208
209                 stripable->DropReferences.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::drop_stripable, this), &p2);
210
211                 stripable->PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::stripable_property_change, this, _1), &p2);
212                 stripable->presentation_info().PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::stripable_property_change, this, _1), &p2);
213
214                 knobs[0]->set_controllable (stripable->gain_control());
215                 knobs[1]->set_controllable (stripable->pan_azimuth_control());
216                 knobs[1]->add_flag (Push2Knob::ArcToZero);
217                 knobs[2]->set_controllable (stripable->pan_width_control());
218                 knobs[3]->set_controllable (stripable->trim_control());
219                 knobs[3]->add_flag (Push2Knob::ArcToZero);
220                 knobs[4]->set_controllable (boost::shared_ptr<AutomationControl>());
221                 knobs[5]->set_controllable (boost::shared_ptr<AutomationControl>());
222                 knobs[6]->set_controllable (boost::shared_ptr<AutomationControl>());
223                 knobs[7]->set_controllable (boost::shared_ptr<AutomationControl>());
224
225                 name_changed ();
226                 color_changed ();
227         }
228
229         _dirty = true;
230 }
231
232 void
233 TrackMixLayout::drop_stripable ()
234 {
235         stripable_connections.drop_connections ();
236         stripable.reset ();
237         _dirty = true;
238 }
239
240 void
241 TrackMixLayout::name_changed ()
242 {
243         _dirty = true;
244 }
245
246 void
247 TrackMixLayout::color_changed ()
248 {
249         uint32_t rgb = stripable->presentation_info().color();
250
251         for (int n = 0; n < 8; ++n) {
252                 knobs[n]->set_text_color (rgb);
253                 knobs[n]->set_arc_start_color (rgb);
254                 knobs[n]->set_arc_end_color (rgb);
255         }
256 }
257
258 void
259 TrackMixLayout::stripable_property_change (PropertyChange const& what_changed)
260 {
261         if (what_changed.contains (Properties::color)) {
262                 color_changed ();
263         }
264         if (what_changed.contains (Properties::name)) {
265                 name_changed ();
266         }
267 }
268
269 void
270 TrackMixLayout::strip_vpot (int n, int delta)
271 {
272         boost::shared_ptr<Controllable> ac = knobs[n]->controllable();
273
274         if (ac) {
275                 ac->set_value (ac->get_value() + ((2.0/64.0) * delta), PBD::Controllable::UseGroup);
276         }
277 }
278
279 void
280 TrackMixLayout::strip_vpot_touch (int n, bool touching)
281 {
282         boost::shared_ptr<AutomationControl> ac = knobs[n]->controllable();
283         if (ac) {
284                 if (touching) {
285                         ac->start_touch (session.audible_frame());
286                 } else {
287                         ac->stop_touch (true, session.audible_frame());
288                 }
289         }
290 }