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"
32 #include "temporal/time.h"
33 #include "temporal/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/session.h"
43 #include "ardour/tempo.h"
44 #include "ardour/utils.h"
45 #include "ardour/vca_manager.h"
47 #include "gtkmm2ext/colors.h"
48 #include "canvas/line.h"
49 #include "canvas/rectangle.h"
50 #include "canvas/text.h"
52 #include "gtkmm2ext/gui_thread.h"
56 #include "level_meter.h"
64 #define Rect ArdourCanvas::Rect
67 using namespace ARDOUR;
71 using namespace ArdourSurface;
72 using namespace Gtkmm2ext;
73 using namespace ArdourCanvas;
75 MixLayout::MixLayout (Push2& p, Session & s, std::string const & name)
76 : Push2Layout (p, s, name)
82 bg = new ArdourCanvas::Rectangle (this);
83 bg->set (Rect (0, 0, display_width(), display_height()));
84 bg->set_fill_color (p2.get_color (Push2::DarkBackground));
88 upper_line = new Line (this);
89 upper_line->set (Duple (0, 22.5), Duple (display_width(), 22.5));
90 upper_line->set_outline_color (p2.get_color (Push2::LightBackground));
92 Pango::FontDescription fd2 ("Sans 10");
94 for (int n = 0; n < 8; ++n) {
96 /* background for text labels for knob function */
98 ArdourCanvas::Rectangle* r = new ArdourCanvas::Rectangle (this);
99 Coord x0 = 10 + (n*Push2Canvas::inter_button_spacing()) - 5;
100 r->set (Rect (x0, 2, x0 + Push2Canvas::inter_button_spacing(), 2 + 21));
101 upper_backgrounds.push_back (r);
103 r = new ArdourCanvas::Rectangle (this);
104 r->set (Rect (x0, 137, x0 + Push2Canvas::inter_button_spacing(), 137 + 21));
105 lower_backgrounds.push_back (r);
107 /* text labels for knob function*/
109 Text* t = new Text (this);
110 t->set_font_description (fd2);
111 t->set_color (p2.get_color (Push2::ParameterName));
112 t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 5));
123 txt = _("Pan Widths");
142 upper_text.push_back (t);
146 gain_meter[n] = new GainMeter (this, p2);
147 gain_meter[n]->set_position (Duple (40 + (n * Push2Canvas::inter_button_spacing()), 95));
149 /* stripable names */
152 t->set_font_description (fd2);
153 t->set_color (p2.get_color (Push2::ParameterName));
154 t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 140));
155 lower_text.push_back (t);
159 mode_button = p2.button_by_id (Push2::Upper1);
161 session.RouteAdded.connect (session_connections, invalidator(*this), boost::bind (&MixLayout::stripables_added, this), &p2);
162 session.vca_manager().VCAAdded.connect (session_connections, invalidator (*this), boost::bind (&MixLayout::stripables_added, this), &p2);
165 MixLayout::~MixLayout ()
167 // Item destructor deletes all children
173 Push2::ButtonID upper_buttons[] = { Push2::Upper1, Push2::Upper2, Push2::Upper3, Push2::Upper4,
174 Push2::Upper5, Push2::Upper6, Push2::Upper7, Push2::Upper8 };
177 for (size_t n = 0; n < sizeof (upper_buttons) / sizeof (upper_buttons[0]); ++n) {
178 boost::shared_ptr<Push2::Button> b = p2.button_by_id (upper_buttons[n]);
180 if (b != mode_button) {
181 b->set_color (Push2::LED::DarkGray);
183 b->set_color (Push2::LED::White);
185 b->set_state (Push2::LED::OneShot24th);
186 p2.write (b->state_msg());
189 switch_bank (bank_start);
195 MixLayout::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
197 Container::render (area, context);
201 MixLayout::button_upper (uint32_t n)
203 boost::shared_ptr<Push2::Button> b;
207 b = p2.button_by_id (Push2::Upper1);
210 vpot_mode = PanAzimuth;
211 b = p2.button_by_id (Push2::Upper2);
214 vpot_mode = PanWidth;
215 b = p2.button_by_id (Push2::Upper3);
219 b = p2.button_by_id (Push2::Upper4);
223 b = p2.button_by_id (Push2::Upper5);
227 b = p2.button_by_id (Push2::Upper6);
231 b = p2.button_by_id (Push2::Upper7);
235 b = p2.button_by_id (Push2::Upper8);
239 if (b != mode_button) {
240 mode_button->set_color (Push2::LED::Black);
241 mode_button->set_state (Push2::LED::OneShot24th);
242 p2.write (mode_button->state_msg());
251 MixLayout::show_vpot_mode ()
253 mode_button->set_color (Push2::LED::White);
254 mode_button->set_state (Push2::LED::OneShot24th);
255 p2.write (mode_button->state_msg());
257 for (int s = 0; s < 8; ++s) {
258 upper_backgrounds[s]->hide ();
259 upper_text[s]->set_color (p2.get_color (Push2::ParameterName));
264 boost::shared_ptr<AutomationControl> ac;
267 for (int s = 0; s < 8; ++s) {
269 gain_meter[s]->knob->set_controllable (stripable[s]->gain_control());
270 boost::shared_ptr<PeakMeter> pm = stripable[s]->peak_meter();
272 gain_meter[s]->meter->set_meter (pm.get());
274 gain_meter[s]->meter->set_meter (0);
277 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
278 gain_meter[s]->meter->set_meter (0);
280 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
281 gain_meter[s]->meter->show ();
286 for (int s = 0; s < 8; ++s) {
288 gain_meter[s]->knob->set_controllable (stripable[s]->pan_azimuth_control());
289 gain_meter[s]->knob->add_flag (Push2Knob::ArcToZero);
291 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
294 gain_meter[s]->meter->hide ();
299 for (int s = 0; s < 8; ++s) {
301 gain_meter[s]->knob->set_controllable (stripable[s]->pan_width_control());
303 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
306 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
307 gain_meter[s]->meter->hide ();
312 for (int s = 0; s < 8; ++s) {
314 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (0));
316 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
319 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
320 gain_meter[s]->meter->hide ();
325 for (int s = 0; s < 8; ++s) {
327 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (1));
329 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
332 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
333 gain_meter[s]->meter->hide ();
338 for (int s = 0; s < 8; ++s) {
340 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (2));
342 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
345 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
346 gain_meter[s]->meter->hide ();
351 for (int s = 0; s < 8; ++s) {
353 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (3));
355 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
358 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
359 gain_meter[s]->meter->hide ();
364 for (int s = 0; s < 8; ++s) {
366 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (4));
368 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
371 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
372 gain_meter[s]->meter->hide ();
380 upper_backgrounds[n]->set_fill_color (p2.get_color (Push2::ParameterName));
381 upper_backgrounds[n]->set_outline_color (p2.get_color (Push2::ParameterName));
382 upper_backgrounds[n]->show ();
383 upper_text[n]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
387 MixLayout::button_mute ()
389 boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
391 boost::shared_ptr<AutomationControl> ac = s->mute_control();
393 ac->set_value (!ac->get_value(), PBD::Controllable::UseGroup);
399 MixLayout::button_solo ()
401 boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
403 boost::shared_ptr<AutomationControl> ac = s->solo_control();
405 session.set_control (ac, !ac->get_value(), PBD::Controllable::UseGroup);
411 MixLayout::button_lower (uint32_t n)
417 ControlProtocol::SetStripableSelection (stripable[n]);
421 MixLayout::strip_vpot (int n, int delta)
423 boost::shared_ptr<Controllable> ac = gain_meter[n]->knob->controllable();
426 ac->set_value (ac->interface_to_internal (
427 min (ac->upper(), max (ac->lower(), ac->internal_to_interface (ac->get_value()) + (delta/256.0)))),
428 PBD::Controllable::UseGroup);
433 MixLayout::strip_vpot_touch (int n, bool touching)
436 boost::shared_ptr<AutomationControl> ac = stripable[n]->gain_control();
439 ac->start_touch (session.audible_sample());
441 ac->stop_touch (session.audible_sample());
448 MixLayout::stripable_property_change (PropertyChange const& what_changed, uint32_t which)
450 if (what_changed.contains (Properties::color)) {
451 lower_backgrounds[which]->set_fill_color (stripable[which]->presentation_info().color());
453 if (stripable[which]->is_selected()) {
454 lower_text[which]->set_fill_color (contrasting_text_color (stripable[which]->presentation_info().color()));
455 /* might not be a MIDI track, in which case this will
458 p2.update_selection_color ();
462 if (what_changed.contains (Properties::hidden)) {
463 switch_bank (bank_start);
466 if (what_changed.contains (Properties::selected)) {
468 if (!stripable[which]) {
472 if (stripable[which]->is_selected()) {
473 show_selection (which);
475 hide_selection (which);
482 MixLayout::show_selection (uint32_t n)
484 lower_backgrounds[n]->show ();
485 lower_backgrounds[n]->set_fill_color (stripable[n]->presentation_info().color());
486 lower_text[n]->set_color (contrasting_text_color (lower_backgrounds[n]->fill_color()));
490 MixLayout::hide_selection (uint32_t n)
492 lower_backgrounds[n]->hide ();
494 lower_text[n]->set_color (stripable[n]->presentation_info().color());
499 MixLayout::solo_changed (uint32_t n)
501 solo_mute_changed (n);
505 MixLayout::mute_changed (uint32_t n)
507 solo_mute_changed (n);
511 MixLayout::solo_mute_changed (uint32_t n)
513 string shortname = short_version (stripable[n]->name(), 10);
515 boost::shared_ptr<AutomationControl> ac;
516 ac = stripable[n]->solo_control();
517 if (ac && ac->get_value()) {
520 boost::shared_ptr<MuteControl> mc;
521 mc = stripable[n]->mute_control ();
523 if (mc->muted_by_self_or_masters()) {
525 } else if (mc->muted_by_others_soloing()) {
526 text += "- "; // it would be nice to use Unicode mute"\uD83D\uDD07 ";
530 lower_text[n]->set (text);
534 MixLayout::switch_bank (uint32_t base)
536 stripable_connections.drop_connections ();
538 /* work backwards so we can tell if we should actually switch banks */
540 boost::shared_ptr<Stripable> s[8];
541 uint32_t different = 0;
543 for (int n = 0; n < 8; ++n) {
544 s[n] = session.get_remote_nth_stripable (base+n, PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::VCA));
545 if (s[n] != stripable[n]) {
551 /* not even the first stripable exists, do nothing */
552 for (int n = 0; n < 8; ++n) {
553 stripable[n].reset ();
554 gain_meter[n]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
555 gain_meter[n]->meter->set_meter (0);
560 for (int n = 0; n < 8; ++n) {
564 /* at least one stripable in this bank */
568 for (int n = 0; n < 8; ++n) {
571 lower_text[n]->hide ();
573 gain_meter[n]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
574 gain_meter[n]->meter->set_meter (0);
577 lower_text[n]->show ();
579 /* stripable goes away? refill the bank, starting at the same point */
581 stripable[n]->DropReferences.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::switch_bank, this, bank_start), &p2);
582 stripable[n]->presentation_info().PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::stripable_property_change, this, _1, n), &p2);
583 stripable[n]->solo_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::solo_changed, this, n), &p2);
584 stripable[n]->mute_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::mute_changed, this, n), &p2);
586 if (stripable[n]->is_selected()) {
592 /* this will set lower text to the correct value (basically
596 solo_mute_changed (n);
598 gain_meter[n]->knob->set_text_color (stripable[n]->presentation_info().color());
599 gain_meter[n]->knob->set_arc_start_color (stripable[n]->presentation_info().color());
600 gain_meter[n]->knob->set_arc_end_color (stripable[n]->presentation_info().color());
604 boost::shared_ptr<Push2::Button> b;
608 b = p2.button_by_id (Push2::Lower1);
611 b = p2.button_by_id (Push2::Lower2);
614 b = p2.button_by_id (Push2::Lower3);
617 b = p2.button_by_id (Push2::Lower4);
620 b = p2.button_by_id (Push2::Lower5);
623 b = p2.button_by_id (Push2::Lower6);
626 b = p2.button_by_id (Push2::Lower7);
629 b = p2.button_by_id (Push2::Lower8);
634 b->set_color (p2.get_color_index (stripable[n]->presentation_info().color()));
636 b->set_color (Push2::LED::Black);
639 b->set_state (Push2::LED::OneShot24th);
640 p2.write (b->state_msg());
647 MixLayout::button_right ()
649 switch_bank (max (0, bank_start + 8));
653 MixLayout::button_left ()
655 switch_bank (max (0, bank_start - 8));
660 MixLayout::button_select_press ()
665 MixLayout::button_select_release ()
667 if (!(p2.modifier_state() & Push2::ModSelect)) {
668 /* somebody else used us as a modifier */
674 for (int n = 0; n < 8; ++n) {
676 if (stripable[n]->is_selected()) {
685 /* no visible track selected, select first (if any) */
688 ControlProtocol::SetStripableSelection (stripable[0]);
693 if (p2.modifier_state() & Push2::ModShift) {
697 /* current selected is leftmost ... cancel selection,
698 switch banks by one, and select leftmost
700 if (bank_start != 0) {
701 ControlProtocol::ClearStripableSelection ();
702 switch_bank (bank_start-1);
704 ControlProtocol::SetStripableSelection (stripable[0]);
708 /* select prev, if any */
709 int n = selected - 1;
710 while (n >= 0 && !stripable[n]) {
714 ControlProtocol::SetStripableSelection (stripable[n]);
723 /* current selected is rightmost ... cancel selection,
724 switch banks by one, and select righmost
726 ControlProtocol::ToggleStripableSelection (stripable[selected]);
727 switch_bank (bank_start+1);
729 ControlProtocol::SetStripableSelection (stripable[7]);
732 /* select next, if any */
733 int n = selected + 1;
734 while (n < 8 && !stripable[n]) {
739 ControlProtocol::SetStripableSelection (stripable[n]);
747 MixLayout::stripables_added ()
749 /* reload current bank */
750 switch_bank (bank_start);
754 MixLayout::button_down ()
756 p2.scroll_dn_1_track ();
760 MixLayout::button_up ()
762 p2.scroll_up_1_track ();
766 MixLayout::update_meters ()
768 if (vpot_mode != Volume) {
772 for (uint32_t n = 0; n < 8; ++n) {
773 gain_meter[n]->meter->update_meters ();
777 MixLayout::GainMeter::GainMeter (Item* parent, Push2& p2)
780 /* knob and meter become owned by their parent on the canvas */
782 knob = new Push2Knob (p2, this);
783 knob->set_radius (25);
784 /* leave position at (0,0) */
786 meter = new LevelMeter (p2, this, 90, ArdourCanvas::Meter::Vertical);
787 meter->set_position (Duple (40, -60));