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