2 Copyright (C) 2016 Paul Davis
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
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include <cairomm/region.h>
20 #include <pangomm/layout.h>
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"
28 #include "pbd/search_path.h"
29 #include "pbd/enumwriter.h"
31 #include "midi++/parser.h"
32 #include "timecode/time.h"
33 #include "timecode/bbt_time.h"
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/monitor_control.h"
43 #include "ardour/session.h"
44 #include "ardour/solo_isolate_control.h"
45 #include "ardour/solo_safe_control.h"
46 #include "ardour/tempo.h"
48 #include "gtkmm2ext/gui_thread.h"
49 #include "gtkmm2ext/rgb_macros.h"
51 #include "canvas/rectangle.h"
52 #include "canvas/line.h"
58 #include "track_mix.h"
61 using namespace ARDOUR;
65 using namespace ArdourSurface;
66 using namespace ArdourCanvas;
68 TrackMixLayout::TrackMixLayout (Push2& p, Session& s)
71 Pango::FontDescription fd ("Sans 10");
73 bg = new Rectangle (this);
74 bg->set (Rect (0, 0, display_width(), display_height()));
75 bg->set_fill_color (p2.get_color (Push2::DarkBackground));
77 upper_line = new Line (this);
78 upper_line->set (Duple (0, 22.5), Duple (display_width(), 22.5));
79 upper_line->set_outline_color (p2.get_color (Push2::LightBackground));
81 for (int n = 0; n < 8; ++n) {
86 t->set_font_description (fd);
87 t->set_color (p2.get_color (Push2::ParameterName));
88 t->set_position ( Duple (10 + (n*Push2Canvas::inter_button_spacing()), 2));
89 upper_text.push_back (t);
93 t->set_font_description (fd);
94 t->set_color (p2.get_color (Push2::ParameterName));
95 t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 140));
97 lower_text.push_back (t);
101 upper_text[n]->set (_("Track Volume"));
102 lower_text[n]->set (_("Mute"));
105 upper_text[n]->set (_("Track Pan"));
106 lower_text[n]->set (_("Solo"));
109 upper_text[n]->set (_("Track Width"));
110 lower_text[n]->set (_("Rec-enable"));
113 upper_text[n]->set (_("Track Trim"));
114 lower_text[n]->set (_("In"));
117 lower_text[n]->set (_("Disk"));
120 lower_text[n]->set (_("Solo Iso"));
123 lower_text[n]->set (_("Solo Lock"));
126 lower_text[n]->set (_(""));
130 knobs[n] = new Push2Knob (p2, this);
131 knobs[n]->set_position (Duple (60 + (Push2Canvas::inter_button_spacing()*n), 95));
132 knobs[n]->set_radius (25);
135 name_text = new Text (this);
136 name_text->set_font_description (fd);
137 name_text->set_position (Duple (10 + (4*Push2Canvas::inter_button_spacing()), 2));
139 ControlProtocol::StripableSelectionChanged.connect (selection_connection, invalidator (*this), boost::bind (&TrackMixLayout::selection_changed, this), &p2);
142 TrackMixLayout::~TrackMixLayout ()
144 for (int n = 0; n < 8; ++n) {
150 TrackMixLayout::selection_changed ()
152 boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
158 TrackMixLayout::show ()
160 selection_changed ();
162 Push2::ButtonID lower_buttons[] = { Push2::Lower1, Push2::Lower2, Push2::Lower3, Push2::Lower4,
163 Push2::Lower5, Push2::Lower6, Push2::Lower7, Push2::Lower8 };
165 for (size_t n = 0; n < sizeof (lower_buttons) / sizeof (lower_buttons[0]); ++n) {
166 Push2::Button* b = p2.button_by_id (lower_buttons[n]);
167 b->set_color (Push2::LED::DarkGray);
168 b->set_state (Push2::LED::OneShot24th);
169 p2.write (b->state_msg());
176 TrackMixLayout::hide ()
178 set_stripable (boost::shared_ptr<Stripable>());
182 TrackMixLayout::render (ArdourCanvas::Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
184 Container::render (area, context);
188 TrackMixLayout::button_upper (uint32_t n)
193 TrackMixLayout::button_lower (uint32_t n)
203 stripable->mute_control()->set_value (!stripable->mute_control()->get_value(), PBD::Controllable::UseGroup);
206 stripable->solo_control()->set_value (!stripable->solo_control()->get_value(), PBD::Controllable::UseGroup);
209 stripable->rec_enable_control()->set_value (!stripable->rec_enable_control()->get_value(), PBD::Controllable::UseGroup);
212 mc = stripable->monitoring_control()->monitoring_choice();
215 stripable->monitoring_control()->set_value (MonitorAuto, PBD::Controllable::UseGroup);
218 stripable->monitoring_control()->set_value (MonitorInput, PBD::Controllable::UseGroup);
223 mc = stripable->monitoring_control()->monitoring_choice();
226 stripable->monitoring_control()->set_value (MonitorAuto, PBD::Controllable::UseGroup);
229 stripable->monitoring_control()->set_value (MonitorDisk, PBD::Controllable::UseGroup);
234 stripable->solo_isolate_control()->set_value (!stripable->solo_isolate_control()->get_value(), PBD::Controllable::UseGroup);
237 stripable->solo_safe_control()->set_value (!stripable->solo_safe_control()->get_value(), PBD::Controllable::UseGroup);
246 TrackMixLayout::button_left ()
248 p2.access_action ("Editor/select-prev-route");
252 TrackMixLayout::button_right ()
254 p2.access_action ("Editor/select-next-route");
258 TrackMixLayout::simple_control_change (boost::shared_ptr<AutomationControl> ac, Push2::ButtonID bid)
264 Push2::Button* b = p2.button_by_id (bid);
271 if (ac->get_value()) {
272 b->set_color (selection_color);
274 b->set_color (Push2::LED::DarkGray);
276 b->set_state (Push2::LED::OneShot24th);
277 p2.write (b->state_msg());
281 TrackMixLayout::solo_change ()
287 simple_control_change (stripable->solo_control(), Push2::Lower2);
291 TrackMixLayout::mute_change ()
297 simple_control_change (stripable->mute_control(), Push2::Lower1);
301 TrackMixLayout::rec_enable_change ()
307 simple_control_change (stripable->rec_enable_control(), Push2::Lower3);
311 TrackMixLayout::solo_iso_change ()
317 simple_control_change (stripable->solo_isolate_control(), Push2::Lower6);
320 TrackMixLayout::solo_safe_change ()
326 simple_control_change (stripable->solo_safe_control(), Push2::Lower7);
330 TrackMixLayout::monitoring_change ()
336 if (!stripable->monitoring_control()) {
340 Push2::Button* b1 = p2.button_by_id (Push2::Lower4);
341 Push2::Button* b2 = p2.button_by_id (Push2::Lower5);
345 MonitorChoice mc = stripable->monitoring_control()->monitoring_choice ();
349 b1_color = Push2::LED::DarkGray;
350 b2_color = Push2::LED::DarkGray;
353 b1_color = selection_color;
354 b2_color = Push2::LED::DarkGray;
357 b1_color = Push2::LED::DarkGray;
358 b2_color = selection_color;
361 b1_color = selection_color;
362 b2_color = selection_color;
366 b1->set_color (b1_color);
367 b1->set_state (Push2::LED::OneShot24th);
368 p2.write (b1->state_msg());
370 b2->set_color (b2_color);
371 b2->set_state (Push2::LED::OneShot24th);
372 p2.write (b2->state_msg());
376 TrackMixLayout::set_stripable (boost::shared_ptr<Stripable> s)
378 stripable_connections.drop_connections ();
384 stripable->DropReferences.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::drop_stripable, this), &p2);
386 stripable->PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::stripable_property_change, this, _1), &p2);
387 stripable->presentation_info().PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::stripable_property_change, this, _1), &p2);
389 stripable->solo_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::solo_change, this), &p2);
390 stripable->mute_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::mute_change, this), &p2);
391 stripable->solo_isolate_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::solo_iso_change, this), &p2);
392 stripable->solo_safe_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::solo_safe_change, this), &p2);
394 if (stripable->rec_enable_control()) {
395 stripable->rec_enable_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::rec_enable_change, this), &p2);
398 if (stripable->monitoring_control()) {
399 stripable->monitoring_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::monitoring_change, this), &p2);
402 knobs[0]->set_controllable (stripable->gain_control());
403 knobs[1]->set_controllable (stripable->pan_azimuth_control());
404 knobs[1]->add_flag (Push2Knob::ArcToZero);
405 knobs[2]->set_controllable (stripable->pan_width_control());
406 knobs[3]->set_controllable (stripable->trim_control());
407 knobs[3]->add_flag (Push2Knob::ArcToZero);
408 knobs[4]->set_controllable (boost::shared_ptr<AutomationControl>());
409 knobs[5]->set_controllable (boost::shared_ptr<AutomationControl>());
410 knobs[6]->set_controllable (boost::shared_ptr<AutomationControl>());
411 knobs[7]->set_controllable (boost::shared_ptr<AutomationControl>());
417 rec_enable_change ();
420 monitoring_change ();
425 TrackMixLayout::drop_stripable ()
427 stripable_connections.drop_connections ();
432 TrackMixLayout::name_changed ()
435 /* poor-man's right justification */
437 snprintf (buf, sizeof (buf), "%*s", (int) sizeof (buf) - 1, stripable->name().c_str());
438 name_text->set (buf);
443 TrackMixLayout::color_changed ()
449 Color rgba = stripable->presentation_info().color();
450 selection_color = p2.get_color_index (rgba);
452 name_text->set_color (rgba);
454 for (int n = 0; n < 8; ++n) {
455 knobs[n]->set_text_color (rgba);
456 knobs[n]->set_arc_start_color (rgba);
457 knobs[n]->set_arc_end_color (rgba);
462 TrackMixLayout::stripable_property_change (PropertyChange const& what_changed)
464 if (what_changed.contains (Properties::color)) {
467 if (what_changed.contains (Properties::name)) {
473 TrackMixLayout::strip_vpot (int n, int delta)
475 boost::shared_ptr<Controllable> ac = knobs[n]->controllable();
478 ac->set_value (ac->get_value() + ((2.0/64.0) * delta), PBD::Controllable::UseGroup);
483 TrackMixLayout::strip_vpot_touch (int n, bool touching)
485 boost::shared_ptr<AutomationControl> ac = knobs[n]->controllable();
488 ac->start_touch (session.audible_frame());
490 ac->stop_touch (true, session.audible_frame());