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"
27 #include "pbd/search_path.h"
28 #include "pbd/enumwriter.h"
30 #include "midi++/parser.h"
31 #include "timecode/time.h"
32 #include "timecode/bbt_time.h"
34 #include "ardour/async_midi_port.h"
35 #include "ardour/audioengine.h"
36 #include "ardour/debug.h"
37 #include "ardour/filesystem_paths.h"
38 #include "ardour/midiport_manager.h"
39 #include "ardour/midi_track.h"
40 #include "ardour/midi_port.h"
41 #include "ardour/session.h"
42 #include "ardour/tempo.h"
43 #include "ardour/utils.h"
44 #include "ardour/vca_manager.h"
46 #include "canvas/colors.h"
47 #include "canvas/line.h"
48 #include "canvas/rectangle.h"
49 #include "canvas/text.h"
51 #include "gtkmm2ext/gui_thread.h"
55 #include "level_meter.h"
62 using namespace ARDOUR;
66 using namespace ArdourSurface;
67 using namespace ArdourCanvas;
69 MixLayout::MixLayout (Push2& p, Session & s, std::string const & name)
70 : Push2Layout (p, s, name)
76 bg = new Rectangle (this);
77 bg->set (Rect (0, 0, display_width(), display_height()));
78 bg->set_fill_color (p2.get_color (Push2::DarkBackground));
82 upper_line = new Line (this);
83 upper_line->set (Duple (0, 22.5), Duple (display_width(), 22.5));
84 upper_line->set_outline_color (p2.get_color (Push2::LightBackground));
86 Pango::FontDescription fd2 ("Sans 10");
88 for (int n = 0; n < 8; ++n) {
90 /* background for text labels for knob function */
92 Rectangle* r = new Rectangle (this);
93 Coord x0 = 10 + (n*Push2Canvas::inter_button_spacing()) - 5;
94 r->set (Rect (x0, 2, x0 + Push2Canvas::inter_button_spacing(), 2 + 21));
95 upper_backgrounds.push_back (r);
97 r = new Rectangle (this);
98 r->set (Rect (x0, 137, x0 + Push2Canvas::inter_button_spacing(), 137 + 21));
99 lower_backgrounds.push_back (r);
101 /* text labels for knob function*/
103 Text* t = new Text (this);
104 t->set_font_description (fd2);
105 t->set_color (p2.get_color (Push2::ParameterName));
106 t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 5));
117 txt = _("Pan Widths");
136 upper_text.push_back (t);
140 gain_meter[n] = new GainMeter (this, p2);
141 gain_meter[n]->set_position (Duple (40 + (n * Push2Canvas::inter_button_spacing()), 95));
143 /* stripable names */
146 t->set_font_description (fd2);
147 t->set_color (p2.get_color (Push2::ParameterName));
148 t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 140));
149 lower_text.push_back (t);
153 mode_button = p2.button_by_id (Push2::Upper1);
155 session.RouteAdded.connect (session_connections, invalidator(*this), boost::bind (&MixLayout::stripables_added, this), &p2);
156 session.vca_manager().VCAAdded.connect (session_connections, invalidator (*this), boost::bind (&MixLayout::stripables_added, this), &p2);
159 MixLayout::~MixLayout ()
161 // Item destructor deletes all children
167 Push2::ButtonID upper_buttons[] = { Push2::Upper1, Push2::Upper2, Push2::Upper3, Push2::Upper4,
168 Push2::Upper5, Push2::Upper6, Push2::Upper7, Push2::Upper8 };
171 for (size_t n = 0; n < sizeof (upper_buttons) / sizeof (upper_buttons[0]); ++n) {
172 Push2::Button* b = p2.button_by_id (upper_buttons[n]);
174 if (b != mode_button) {
175 b->set_color (Push2::LED::DarkGray);
177 b->set_color (Push2::LED::White);
179 b->set_state (Push2::LED::OneShot24th);
180 p2.write (b->state_msg());
183 switch_bank (bank_start);
189 MixLayout::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
191 Container::render (area, context);
195 MixLayout::button_upper (uint32_t n)
201 b = p2.button_by_id (Push2::Upper1);
204 vpot_mode = PanAzimuth;
205 b = p2.button_by_id (Push2::Upper2);
208 vpot_mode = PanWidth;
209 b = p2.button_by_id (Push2::Upper3);
213 b = p2.button_by_id (Push2::Upper4);
217 b = p2.button_by_id (Push2::Upper5);
221 b = p2.button_by_id (Push2::Upper6);
225 b = p2.button_by_id (Push2::Upper7);
229 b = p2.button_by_id (Push2::Upper8);
233 if (b != mode_button) {
234 mode_button->set_color (Push2::LED::Black);
235 mode_button->set_state (Push2::LED::OneShot24th);
236 p2.write (mode_button->state_msg());
245 MixLayout::show_vpot_mode ()
247 mode_button->set_color (Push2::LED::White);
248 mode_button->set_state (Push2::LED::OneShot24th);
249 p2.write (mode_button->state_msg());
251 for (int s = 0; s < 8; ++s) {
252 upper_backgrounds[s]->hide ();
253 upper_text[s]->set_color (p2.get_color (Push2::ParameterName));
258 boost::shared_ptr<AutomationControl> ac;
261 for (int s = 0; s < 8; ++s) {
263 gain_meter[s]->knob->set_controllable (stripable[s]->gain_control());
264 boost::shared_ptr<PeakMeter> pm = stripable[s]->peak_meter();
266 gain_meter[s]->meter->set_meter (pm.get());
268 gain_meter[s]->meter->set_meter (0);
271 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
272 gain_meter[s]->meter->set_meter (0);
274 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
275 gain_meter[s]->meter->show ();
280 for (int s = 0; s < 8; ++s) {
282 gain_meter[s]->knob->set_controllable (stripable[s]->pan_azimuth_control());
283 gain_meter[s]->knob->add_flag (Push2Knob::ArcToZero);
285 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
288 gain_meter[s]->meter->hide ();
293 for (int s = 0; s < 8; ++s) {
295 gain_meter[s]->knob->set_controllable (stripable[s]->pan_width_control());
297 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
300 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
301 gain_meter[s]->meter->hide ();
306 for (int s = 0; s < 8; ++s) {
308 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (0));
310 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
313 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
314 gain_meter[s]->meter->hide ();
319 for (int s = 0; s < 8; ++s) {
321 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (1));
323 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
326 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
327 gain_meter[s]->meter->hide ();
332 for (int s = 0; s < 8; ++s) {
334 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (2));
336 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
339 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
340 gain_meter[s]->meter->hide ();
345 for (int s = 0; s < 8; ++s) {
347 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (3));
349 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
352 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
353 gain_meter[s]->meter->hide ();
358 for (int s = 0; s < 8; ++s) {
360 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (4));
362 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
365 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
366 gain_meter[s]->meter->hide ();
374 upper_backgrounds[n]->set_fill_color (p2.get_color (Push2::ParameterName));
375 upper_backgrounds[n]->set_outline_color (p2.get_color (Push2::ParameterName));
376 upper_backgrounds[n]->show ();
377 upper_text[n]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
381 MixLayout::button_mute ()
383 boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
385 boost::shared_ptr<AutomationControl> ac = s->mute_control();
387 ac->set_value (!ac->get_value(), PBD::Controllable::UseGroup);
393 MixLayout::button_solo ()
395 boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
397 boost::shared_ptr<AutomationControl> ac = s->solo_control();
399 ac->set_value (!ac->get_value(), PBD::Controllable::UseGroup);
405 MixLayout::button_lower (uint32_t n)
411 ControlProtocol::SetStripableSelection (stripable[n]);
415 MixLayout::strip_vpot (int n, int delta)
417 boost::shared_ptr<Controllable> ac = gain_meter[n]->knob->controllable();
420 ac->set_value (ac->interface_to_internal (
421 min (ac->upper(), max (ac->lower(), ac->internal_to_interface (ac->get_value()) + (delta/256.0)))),
422 PBD::Controllable::UseGroup);
427 MixLayout::strip_vpot_touch (int n, bool touching)
430 boost::shared_ptr<AutomationControl> ac = stripable[n]->gain_control();
433 ac->start_touch (session.audible_frame());
435 ac->stop_touch (true, session.audible_frame());
442 MixLayout::stripable_property_change (PropertyChange const& what_changed, uint32_t which)
444 if (what_changed.contains (Properties::color)) {
445 lower_backgrounds[which]->set_fill_color (stripable[which]->presentation_info().color());
447 if (stripable[which]->presentation_info().selected()) {
448 lower_text[which]->set_fill_color (contrasting_text_color (stripable[which]->presentation_info().color()));
449 /* might not be a MIDI track, in which case this will
452 p2.update_selection_color ();
456 if (what_changed.contains (Properties::hidden)) {
457 switch_bank (bank_start);
460 if (what_changed.contains (Properties::selected)) {
462 if (!stripable[which]) {
466 if (stripable[which]->presentation_info().selected()) {
467 show_selection (which);
469 hide_selection (which);
476 MixLayout::show_selection (uint32_t n)
478 lower_backgrounds[n]->show ();
479 lower_backgrounds[n]->set_fill_color (stripable[n]->presentation_info().color());
480 lower_text[n]->set_color (ArdourCanvas::contrasting_text_color (lower_backgrounds[n]->fill_color()));
484 MixLayout::hide_selection (uint32_t n)
486 lower_backgrounds[n]->hide ();
488 lower_text[n]->set_color (stripable[n]->presentation_info().color());
493 MixLayout::solo_changed (uint32_t n)
495 solo_mute_changed (n);
499 MixLayout::mute_changed (uint32_t n)
501 solo_mute_changed (n);
505 MixLayout::solo_mute_changed (uint32_t n)
507 string shortname = short_version (stripable[n]->name(), 10);
509 boost::shared_ptr<AutomationControl> ac;
510 ac = stripable[n]->solo_control();
511 if (ac && ac->get_value()) {
514 boost::shared_ptr<MuteControl> mc;
515 mc = stripable[n]->mute_control ();
517 if (mc->muted_by_self_or_masters()) {
519 } else if (mc->muted_by_others_soloing()) {
520 text += "- "; // it would be nice to use Unicode mute"\uD83D\uDD07 ";
524 lower_text[n]->set (text);
528 MixLayout::switch_bank (uint32_t base)
530 stripable_connections.drop_connections ();
532 /* work backwards so we can tell if we should actually switch banks */
534 boost::shared_ptr<Stripable> s[8];
535 uint32_t different = 0;
537 for (int n = 0; n < 8; ++n) {
538 s[n] = session.get_remote_nth_stripable (base+n, PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::VCA));
539 if (s[n] != stripable[n]) {
545 /* not even the first stripable exists, do nothing */
549 for (int n = 0; n < 8; ++n) {
553 /* at least one stripable in this bank */
557 for (int n = 0; n < 8; ++n) {
560 lower_text[n]->hide ();
564 lower_text[n]->show ();
566 /* stripable goes away? refill the bank, starting at the same point */
568 stripable[n]->DropReferences.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::switch_bank, this, bank_start), &p2);
569 stripable[n]->presentation_info().PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::stripable_property_change, this, _1, n), &p2);
570 stripable[n]->solo_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::solo_changed, this, n), &p2);
571 stripable[n]->mute_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::mute_changed, this, n), &p2);
573 if (stripable[n]->presentation_info().selected()) {
579 /* this will set lower text to the correct value (basically
583 solo_mute_changed (n);
585 gain_meter[n]->knob->set_text_color (stripable[n]->presentation_info().color());
586 gain_meter[n]->knob->set_arc_start_color (stripable[n]->presentation_info().color());
587 gain_meter[n]->knob->set_arc_end_color (stripable[n]->presentation_info().color());
595 b = p2.button_by_id (Push2::Lower1);
598 b = p2.button_by_id (Push2::Lower2);
601 b = p2.button_by_id (Push2::Lower3);
604 b = p2.button_by_id (Push2::Lower4);
607 b = p2.button_by_id (Push2::Lower5);
610 b = p2.button_by_id (Push2::Lower6);
613 b = p2.button_by_id (Push2::Lower7);
616 b = p2.button_by_id (Push2::Lower8);
621 b->set_color (p2.get_color_index (stripable[n]->presentation_info().color()));
623 b->set_color (Push2::LED::Black);
626 b->set_state (Push2::LED::OneShot24th);
627 p2.write (b->state_msg());
634 MixLayout::button_right ()
636 switch_bank (max (0, bank_start + 8));
640 MixLayout::button_left ()
642 switch_bank (max (0, bank_start - 8));
647 MixLayout::button_select_press ()
652 MixLayout::button_select_release ()
654 if (!(p2.modifier_state() & Push2::ModSelect)) {
655 /* somebody else used us as a modifier */
661 for (int n = 0; n < 8; ++n) {
663 if (stripable[n]->presentation_info().selected()) {
672 /* no visible track selected, select first (if any) */
675 ControlProtocol::SetStripableSelection (stripable[0]);
680 if (p2.modifier_state() & Push2::ModShift) {
684 /* current selected is leftmost ... cancel selection,
685 switch banks by one, and select leftmost
687 if (bank_start != 0) {
688 ControlProtocol::ClearStripableSelection ();
689 switch_bank (bank_start-1);
691 ControlProtocol::SetStripableSelection (stripable[0]);
695 /* select prev, if any */
696 int n = selected - 1;
697 while (n >= 0 && !stripable[n]) {
701 ControlProtocol::SetStripableSelection (stripable[n]);
710 /* current selected is rightmost ... cancel selection,
711 switch banks by one, and select righmost
713 ControlProtocol::ToggleStripableSelection (stripable[selected]);
714 switch_bank (bank_start+1);
716 ControlProtocol::SetStripableSelection (stripable[7]);
719 /* select next, if any */
720 int n = selected + 1;
721 while (n < 8 && !stripable[n]) {
726 ControlProtocol::SetStripableSelection (stripable[n]);
734 MixLayout::stripables_added ()
736 /* reload current bank */
737 switch_bank (bank_start);
741 MixLayout::button_down ()
743 p2.scroll_dn_1_track ();
747 MixLayout::button_up ()
749 p2.scroll_up_1_track ();
753 MixLayout::update_meters ()
755 if (vpot_mode != Volume) {
759 for (uint32_t n = 0; n < 8; ++n) {
760 gain_meter[n]->meter->update_meters ();
764 MixLayout::GainMeter::GainMeter (Item* parent, Push2& p2)
767 knob = new Push2Knob (p2, this);
768 knob->set_radius (25);
769 /* leave position at (0,0) */
771 meter = new LevelMeter (p2, this, 90, ArdourCanvas::Meter::Vertical);
772 meter->set_position (Duple (40, -60));