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"
63 #define Rect ArdourCanvas::Rect
66 using namespace ARDOUR;
70 using namespace ArdourSurface;
71 using namespace ArdourCanvas;
73 MixLayout::MixLayout (Push2& p, Session & s, std::string const & name)
74 : Push2Layout (p, s, name)
80 bg = new ArdourCanvas::Rectangle (this);
81 bg->set (Rect (0, 0, display_width(), display_height()));
82 bg->set_fill_color (p2.get_color (Push2::DarkBackground));
86 upper_line = new Line (this);
87 upper_line->set (Duple (0, 22.5), Duple (display_width(), 22.5));
88 upper_line->set_outline_color (p2.get_color (Push2::LightBackground));
90 Pango::FontDescription fd2 ("Sans 10");
92 for (int n = 0; n < 8; ++n) {
94 /* background for text labels for knob function */
96 ArdourCanvas::Rectangle* r = new ArdourCanvas::Rectangle (this);
97 Coord x0 = 10 + (n*Push2Canvas::inter_button_spacing()) - 5;
98 r->set (Rect (x0, 2, x0 + Push2Canvas::inter_button_spacing(), 2 + 21));
99 upper_backgrounds.push_back (r);
101 r = new ArdourCanvas::Rectangle (this);
102 r->set (Rect (x0, 137, x0 + Push2Canvas::inter_button_spacing(), 137 + 21));
103 lower_backgrounds.push_back (r);
105 /* text labels for knob function*/
107 Text* t = new Text (this);
108 t->set_font_description (fd2);
109 t->set_color (p2.get_color (Push2::ParameterName));
110 t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 5));
121 txt = _("Pan Widths");
140 upper_text.push_back (t);
144 gain_meter[n] = new GainMeter (this, p2);
145 gain_meter[n]->set_position (Duple (40 + (n * Push2Canvas::inter_button_spacing()), 95));
147 /* stripable names */
150 t->set_font_description (fd2);
151 t->set_color (p2.get_color (Push2::ParameterName));
152 t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 140));
153 lower_text.push_back (t);
157 mode_button = p2.button_by_id (Push2::Upper1);
159 session.RouteAdded.connect (session_connections, invalidator(*this), boost::bind (&MixLayout::stripables_added, this), &p2);
160 session.vca_manager().VCAAdded.connect (session_connections, invalidator (*this), boost::bind (&MixLayout::stripables_added, this), &p2);
163 MixLayout::~MixLayout ()
165 // Item destructor deletes all children
171 Push2::ButtonID upper_buttons[] = { Push2::Upper1, Push2::Upper2, Push2::Upper3, Push2::Upper4,
172 Push2::Upper5, Push2::Upper6, Push2::Upper7, Push2::Upper8 };
175 for (size_t n = 0; n < sizeof (upper_buttons) / sizeof (upper_buttons[0]); ++n) {
176 Push2::Button* b = p2.button_by_id (upper_buttons[n]);
178 if (b != mode_button) {
179 b->set_color (Push2::LED::DarkGray);
181 b->set_color (Push2::LED::White);
183 b->set_state (Push2::LED::OneShot24th);
184 p2.write (b->state_msg());
187 switch_bank (bank_start);
193 MixLayout::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
195 Container::render (area, context);
199 MixLayout::button_upper (uint32_t n)
205 b = p2.button_by_id (Push2::Upper1);
208 vpot_mode = PanAzimuth;
209 b = p2.button_by_id (Push2::Upper2);
212 vpot_mode = PanWidth;
213 b = p2.button_by_id (Push2::Upper3);
217 b = p2.button_by_id (Push2::Upper4);
221 b = p2.button_by_id (Push2::Upper5);
225 b = p2.button_by_id (Push2::Upper6);
229 b = p2.button_by_id (Push2::Upper7);
233 b = p2.button_by_id (Push2::Upper8);
237 if (b != mode_button) {
238 mode_button->set_color (Push2::LED::Black);
239 mode_button->set_state (Push2::LED::OneShot24th);
240 p2.write (mode_button->state_msg());
249 MixLayout::show_vpot_mode ()
251 mode_button->set_color (Push2::LED::White);
252 mode_button->set_state (Push2::LED::OneShot24th);
253 p2.write (mode_button->state_msg());
255 for (int s = 0; s < 8; ++s) {
256 upper_backgrounds[s]->hide ();
257 upper_text[s]->set_color (p2.get_color (Push2::ParameterName));
262 boost::shared_ptr<AutomationControl> ac;
265 for (int s = 0; s < 8; ++s) {
267 gain_meter[s]->knob->set_controllable (stripable[s]->gain_control());
268 boost::shared_ptr<PeakMeter> pm = stripable[s]->peak_meter();
270 gain_meter[s]->meter->set_meter (pm.get());
272 gain_meter[s]->meter->set_meter (0);
275 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
276 gain_meter[s]->meter->set_meter (0);
278 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
279 gain_meter[s]->meter->show ();
284 for (int s = 0; s < 8; ++s) {
286 gain_meter[s]->knob->set_controllable (stripable[s]->pan_azimuth_control());
287 gain_meter[s]->knob->add_flag (Push2Knob::ArcToZero);
289 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
292 gain_meter[s]->meter->hide ();
297 for (int s = 0; s < 8; ++s) {
299 gain_meter[s]->knob->set_controllable (stripable[s]->pan_width_control());
301 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
304 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
305 gain_meter[s]->meter->hide ();
310 for (int s = 0; s < 8; ++s) {
312 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (0));
314 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
317 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
318 gain_meter[s]->meter->hide ();
323 for (int s = 0; s < 8; ++s) {
325 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (1));
327 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
330 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
331 gain_meter[s]->meter->hide ();
336 for (int s = 0; s < 8; ++s) {
338 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (2));
340 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
343 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
344 gain_meter[s]->meter->hide ();
349 for (int s = 0; s < 8; ++s) {
351 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (3));
353 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
356 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
357 gain_meter[s]->meter->hide ();
362 for (int s = 0; s < 8; ++s) {
364 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (4));
366 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
369 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
370 gain_meter[s]->meter->hide ();
378 upper_backgrounds[n]->set_fill_color (p2.get_color (Push2::ParameterName));
379 upper_backgrounds[n]->set_outline_color (p2.get_color (Push2::ParameterName));
380 upper_backgrounds[n]->show ();
381 upper_text[n]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
385 MixLayout::button_mute ()
387 boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
389 boost::shared_ptr<AutomationControl> ac = s->mute_control();
391 ac->set_value (!ac->get_value(), PBD::Controllable::UseGroup);
397 MixLayout::button_solo ()
399 boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
401 boost::shared_ptr<AutomationControl> ac = s->solo_control();
403 session.set_control (ac, !ac->get_value(), PBD::Controllable::UseGroup);
409 MixLayout::button_lower (uint32_t n)
415 ControlProtocol::SetStripableSelection (stripable[n]);
419 MixLayout::strip_vpot (int n, int delta)
421 boost::shared_ptr<Controllable> ac = gain_meter[n]->knob->controllable();
424 ac->set_value (ac->interface_to_internal (
425 min (ac->upper(), max (ac->lower(), ac->internal_to_interface (ac->get_value()) + (delta/256.0)))),
426 PBD::Controllable::UseGroup);
431 MixLayout::strip_vpot_touch (int n, bool touching)
434 boost::shared_ptr<AutomationControl> ac = stripable[n]->gain_control();
437 ac->start_touch (session.audible_frame());
439 ac->stop_touch (true, session.audible_frame());
446 MixLayout::stripable_property_change (PropertyChange const& what_changed, uint32_t which)
448 if (what_changed.contains (Properties::color)) {
449 lower_backgrounds[which]->set_fill_color (stripable[which]->presentation_info().color());
451 if (stripable[which]->presentation_info().selected()) {
452 lower_text[which]->set_fill_color (contrasting_text_color (stripable[which]->presentation_info().color()));
453 /* might not be a MIDI track, in which case this will
456 p2.update_selection_color ();
460 if (what_changed.contains (Properties::hidden)) {
461 switch_bank (bank_start);
464 if (what_changed.contains (Properties::selected)) {
466 if (!stripable[which]) {
470 if (stripable[which]->presentation_info().selected()) {
471 show_selection (which);
473 hide_selection (which);
480 MixLayout::show_selection (uint32_t n)
482 lower_backgrounds[n]->show ();
483 lower_backgrounds[n]->set_fill_color (stripable[n]->presentation_info().color());
484 lower_text[n]->set_color (ArdourCanvas::contrasting_text_color (lower_backgrounds[n]->fill_color()));
488 MixLayout::hide_selection (uint32_t n)
490 lower_backgrounds[n]->hide ();
492 lower_text[n]->set_color (stripable[n]->presentation_info().color());
497 MixLayout::solo_changed (uint32_t n)
499 solo_mute_changed (n);
503 MixLayout::mute_changed (uint32_t n)
505 solo_mute_changed (n);
509 MixLayout::solo_mute_changed (uint32_t n)
511 string shortname = short_version (stripable[n]->name(), 10);
513 boost::shared_ptr<AutomationControl> ac;
514 ac = stripable[n]->solo_control();
515 if (ac && ac->get_value()) {
518 boost::shared_ptr<MuteControl> mc;
519 mc = stripable[n]->mute_control ();
521 if (mc->muted_by_self_or_masters()) {
523 } else if (mc->muted_by_others_soloing()) {
524 text += "- "; // it would be nice to use Unicode mute"\uD83D\uDD07 ";
528 lower_text[n]->set (text);
532 MixLayout::switch_bank (uint32_t base)
534 stripable_connections.drop_connections ();
536 /* work backwards so we can tell if we should actually switch banks */
538 boost::shared_ptr<Stripable> s[8];
539 uint32_t different = 0;
541 for (int n = 0; n < 8; ++n) {
542 s[n] = session.get_remote_nth_stripable (base+n, PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::VCA));
543 if (s[n] != stripable[n]) {
549 /* not even the first stripable exists, do nothing */
550 for (int n = 0; n < 8; ++n) {
551 stripable[n].reset ();
552 gain_meter[n]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
553 gain_meter[n]->meter->set_meter (0);
558 for (int n = 0; n < 8; ++n) {
562 /* at least one stripable in this bank */
566 for (int n = 0; n < 8; ++n) {
569 lower_text[n]->hide ();
571 gain_meter[n]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
572 gain_meter[n]->meter->set_meter (0);
575 lower_text[n]->show ();
577 /* stripable goes away? refill the bank, starting at the same point */
579 stripable[n]->DropReferences.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::switch_bank, this, bank_start), &p2);
580 stripable[n]->presentation_info().PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::stripable_property_change, this, _1, n), &p2);
581 stripable[n]->solo_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::solo_changed, this, n), &p2);
582 stripable[n]->mute_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::mute_changed, this, n), &p2);
584 if (stripable[n]->presentation_info().selected()) {
590 /* this will set lower text to the correct value (basically
594 solo_mute_changed (n);
596 gain_meter[n]->knob->set_text_color (stripable[n]->presentation_info().color());
597 gain_meter[n]->knob->set_arc_start_color (stripable[n]->presentation_info().color());
598 gain_meter[n]->knob->set_arc_end_color (stripable[n]->presentation_info().color());
606 b = p2.button_by_id (Push2::Lower1);
609 b = p2.button_by_id (Push2::Lower2);
612 b = p2.button_by_id (Push2::Lower3);
615 b = p2.button_by_id (Push2::Lower4);
618 b = p2.button_by_id (Push2::Lower5);
621 b = p2.button_by_id (Push2::Lower6);
624 b = p2.button_by_id (Push2::Lower7);
627 b = p2.button_by_id (Push2::Lower8);
632 b->set_color (p2.get_color_index (stripable[n]->presentation_info().color()));
634 b->set_color (Push2::LED::Black);
637 b->set_state (Push2::LED::OneShot24th);
638 p2.write (b->state_msg());
645 MixLayout::button_right ()
647 switch_bank (max (0, bank_start + 8));
651 MixLayout::button_left ()
653 switch_bank (max (0, bank_start - 8));
658 MixLayout::button_select_press ()
663 MixLayout::button_select_release ()
665 if (!(p2.modifier_state() & Push2::ModSelect)) {
666 /* somebody else used us as a modifier */
672 for (int n = 0; n < 8; ++n) {
674 if (stripable[n]->presentation_info().selected()) {
683 /* no visible track selected, select first (if any) */
686 ControlProtocol::SetStripableSelection (stripable[0]);
691 if (p2.modifier_state() & Push2::ModShift) {
695 /* current selected is leftmost ... cancel selection,
696 switch banks by one, and select leftmost
698 if (bank_start != 0) {
699 ControlProtocol::ClearStripableSelection ();
700 switch_bank (bank_start-1);
702 ControlProtocol::SetStripableSelection (stripable[0]);
706 /* select prev, if any */
707 int n = selected - 1;
708 while (n >= 0 && !stripable[n]) {
712 ControlProtocol::SetStripableSelection (stripable[n]);
721 /* current selected is rightmost ... cancel selection,
722 switch banks by one, and select righmost
724 ControlProtocol::ToggleStripableSelection (stripable[selected]);
725 switch_bank (bank_start+1);
727 ControlProtocol::SetStripableSelection (stripable[7]);
730 /* select next, if any */
731 int n = selected + 1;
732 while (n < 8 && !stripable[n]) {
737 ControlProtocol::SetStripableSelection (stripable[n]);
745 MixLayout::stripables_added ()
747 /* reload current bank */
748 switch_bank (bank_start);
752 MixLayout::button_down ()
754 p2.scroll_dn_1_track ();
758 MixLayout::button_up ()
760 p2.scroll_up_1_track ();
764 MixLayout::update_meters ()
766 if (vpot_mode != Volume) {
770 for (uint32_t n = 0; n < 8; ++n) {
771 gain_meter[n]->meter->update_meters ();
775 MixLayout::GainMeter::GainMeter (Item* parent, Push2& p2)
778 knob = new Push2Knob (p2, this);
779 knob->set_radius (25);
780 /* leave position at (0,0) */
782 meter = new LevelMeter (p2, this, 90, ArdourCanvas::Meter::Vertical);
783 meter->set_position (Duple (40, -60));