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/rectangle.h"
48 #include "canvas/line.h"
50 #include "gtkmm2ext/gui_thread.h"
60 using namespace ARDOUR;
64 using namespace ArdourSurface;
65 using namespace ArdourCanvas;
67 MixLayout::MixLayout (Push2& p, Session& s)
74 bg = new Rectangle (this);
75 bg->set (Rect (0, 0, display_width(), display_height()));
76 bg->set_fill_color (p2.get_color (Push2::DarkBackground));
80 upper_line = new Line (this);
81 upper_line->set (Duple (0, 22.5), Duple (display_width(), 22.5));
82 upper_line->set_outline_color (p2.get_color (Push2::LightBackground));
84 Pango::FontDescription fd2 ("Sans 10");
85 for (int n = 0; n < 8; ++n) {
87 /* background for text labels for knob function */
89 Rectangle* r = new Rectangle (this);
90 Coord x0 = 10 + (n*Push2Canvas::inter_button_spacing()) - 5;
91 r->set (Rect (x0, 2, x0 + Push2Canvas::inter_button_spacing(), 2 + 21));
92 upper_backgrounds.push_back (r);
94 r = new Rectangle (this);
95 r->set (Rect (x0, 137, x0 + Push2Canvas::inter_button_spacing(), 137 + 21));
96 lower_backgrounds.push_back (r);
98 /* text labels for knob function*/
100 Text* t = new Text (this);
101 t->set_font_description (fd2);
102 t->set_color (p2.get_color (Push2::ParameterName));
103 t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 5));
114 txt = _("Pan Widths");
133 upper_text.push_back (t);
137 knobs[n] = new Push2Knob (p2, this);
138 knobs[n]->set_position (Duple (60 + (n*Push2Canvas::inter_button_spacing()), 95));
139 knobs[n]->set_radius (25);
141 /* stripable names */
144 t->set_font_description (fd2);
145 t->set_color (p2.get_color (Push2::ParameterName));
146 t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 140));
147 lower_text.push_back (t);
151 mode_button = p2.button_by_id (Push2::Upper1);
153 session.RouteAdded.connect (session_connections, invalidator(*this), boost::bind (&MixLayout::stripables_added, this), &p2);
154 session.vca_manager().VCAAdded.connect (session_connections, invalidator (*this), boost::bind (&MixLayout::stripables_added, this), &p2);
157 MixLayout::~MixLayout ()
159 // Item destructor deletes all children
165 Push2::ButtonID upper_buttons[] = { Push2::Upper1, Push2::Upper2, Push2::Upper3, Push2::Upper4,
166 Push2::Upper5, Push2::Upper6, Push2::Upper7, Push2::Upper8 };
169 for (size_t n = 0; n < sizeof (upper_buttons) / sizeof (upper_buttons[0]); ++n) {
170 Push2::Button* b = p2.button_by_id (upper_buttons[n]);
172 if (b != mode_button) {
173 b->set_color (Push2::LED::DarkGray);
175 b->set_color (Push2::LED::White);
177 b->set_state (Push2::LED::OneShot24th);
178 p2.write (b->state_msg());
181 switch_bank (bank_start);
187 MixLayout::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
189 Container::render (area, context);
193 MixLayout::button_upper (uint32_t n)
199 b = p2.button_by_id (Push2::Upper1);
202 vpot_mode = PanAzimuth;
203 b = p2.button_by_id (Push2::Upper2);
206 vpot_mode = PanWidth;
207 b = p2.button_by_id (Push2::Upper3);
211 b = p2.button_by_id (Push2::Upper4);
215 b = p2.button_by_id (Push2::Upper5);
219 b = p2.button_by_id (Push2::Upper6);
223 b = p2.button_by_id (Push2::Upper7);
227 b = p2.button_by_id (Push2::Upper8);
231 if (b != mode_button) {
232 mode_button->set_color (Push2::LED::Black);
233 mode_button->set_state (Push2::LED::OneShot24th);
234 p2.write (mode_button->state_msg());
243 MixLayout::show_vpot_mode ()
245 mode_button->set_color (Push2::LED::White);
246 mode_button->set_state (Push2::LED::OneShot24th);
247 p2.write (mode_button->state_msg());
249 for (int s = 0; s < 8; ++s) {
250 upper_backgrounds[s]->hide ();
251 upper_text[s]->set_color (p2.get_color (Push2::ParameterName));
256 boost::shared_ptr<AutomationControl> ac;
259 for (int s = 0; s < 8; ++s) {
261 knobs[s]->set_controllable (stripable[s]->gain_control());
263 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
265 knobs[s]->remove_flag (Push2Knob::ArcToZero);
270 for (int s = 0; s < 8; ++s) {
272 knobs[s]->set_controllable (stripable[s]->pan_azimuth_control());
273 knobs[s]->add_flag (Push2Knob::ArcToZero);
275 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
282 for (int s = 0; s < 8; ++s) {
284 knobs[s]->set_controllable (stripable[s]->pan_width_control());
286 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
289 knobs[s]->remove_flag (Push2Knob::ArcToZero);
294 for (int s = 0; s < 8; ++s) {
296 knobs[s]->set_controllable (stripable[s]->send_level_controllable (0));
298 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
301 knobs[s]->remove_flag (Push2Knob::ArcToZero);
306 for (int s = 0; s < 8; ++s) {
308 knobs[s]->set_controllable (stripable[s]->send_level_controllable (1));
310 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
313 knobs[s]->remove_flag (Push2Knob::ArcToZero);
318 for (int s = 0; s < 8; ++s) {
320 knobs[s]->set_controllable (stripable[s]->send_level_controllable (2));
322 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
325 knobs[s]->remove_flag (Push2Knob::ArcToZero);
330 for (int s = 0; s < 8; ++s) {
332 knobs[s]->set_controllable (stripable[s]->send_level_controllable (3));
334 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
337 knobs[s]->remove_flag (Push2Knob::ArcToZero);
342 for (int s = 0; s < 8; ++s) {
344 knobs[s]->set_controllable (stripable[s]->send_level_controllable (4));
346 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
349 knobs[s]->remove_flag (Push2Knob::ArcToZero);
357 upper_backgrounds[n]->set_fill_color (p2.get_color (Push2::ParameterName));
358 upper_backgrounds[n]->set_outline_color (p2.get_color (Push2::ParameterName));
359 upper_backgrounds[n]->show ();
360 upper_text[n]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
364 MixLayout::button_mute ()
366 boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
368 boost::shared_ptr<AutomationControl> ac = s->mute_control();
370 ac->set_value (!ac->get_value(), PBD::Controllable::UseGroup);
376 MixLayout::button_solo ()
378 boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
380 boost::shared_ptr<AutomationControl> ac = s->solo_control();
382 ac->set_value (!ac->get_value(), PBD::Controllable::UseGroup);
388 MixLayout::button_lower (uint32_t n)
394 ControlProtocol::SetStripableSelection (stripable[n]);
398 MixLayout::strip_vpot (int n, int delta)
400 boost::shared_ptr<Controllable> ac = knobs[n]->controllable();
403 if (ac->is_gain_like()) {
404 /* 128 steps from fader position 0 to 1.0 ..
406 const double new_fader_position = min (1.0, max (0.0, ac->internal_to_interface (ac->get_value()) + ((1.0 / 128.0) * delta)));
407 ac->set_value (ac->interface_to_internal (new_fader_position), PBD::Controllable::UseGroup);
409 /* 128 steps from min to max */
410 ac->set_value (ac->get_value() + (((ac->upper() - ac->lower()) / 128.0) * delta) , PBD::Controllable::UseGroup);
416 MixLayout::strip_vpot_touch (int n, bool touching)
419 boost::shared_ptr<AutomationControl> ac = stripable[n]->gain_control();
422 ac->start_touch (session.audible_frame());
424 ac->stop_touch (true, session.audible_frame());
431 MixLayout::stripable_property_change (PropertyChange const& what_changed, uint32_t which)
433 if (what_changed.contains (Properties::color)) {
434 lower_backgrounds[which]->set_fill_color (stripable[which]->presentation_info().color());
436 if (stripable[which]->presentation_info().selected()) {
437 lower_text[which]->set_fill_color (contrasting_text_color (stripable[which]->presentation_info().color()));
438 /* might not be a MIDI track, in which case this will
441 p2.update_selection_color ();
445 if (what_changed.contains (Properties::hidden)) {
446 switch_bank (bank_start);
449 if (what_changed.contains (Properties::selected)) {
451 if (!stripable[which]) {
455 if (stripable[which]->presentation_info().selected()) {
456 show_selection (which);
458 hide_selection (which);
465 MixLayout::show_selection (uint32_t n)
467 lower_backgrounds[n]->show ();
468 lower_backgrounds[n]->set_fill_color (stripable[n]->presentation_info().color());
469 lower_text[n]->set_color (ArdourCanvas::contrasting_text_color (lower_backgrounds[n]->fill_color()));
473 MixLayout::hide_selection (uint32_t n)
475 lower_backgrounds[n]->hide ();
477 lower_text[n]->set_color (stripable[n]->presentation_info().color());
482 MixLayout::solo_changed (uint32_t n)
484 solo_mute_changed (n);
488 MixLayout::mute_changed (uint32_t n)
490 solo_mute_changed (n);
494 MixLayout::solo_mute_changed (uint32_t n)
496 string shortname = short_version (stripable[n]->name(), 10);
498 boost::shared_ptr<AutomationControl> ac;
499 ac = stripable[n]->solo_control();
500 if (ac && ac->get_value()) {
503 boost::shared_ptr<MuteControl> mc;
504 mc = stripable[n]->mute_control ();
506 if (mc->muted_by_self_or_masters()) {
508 } else if (mc->muted_by_others_soloing()) {
509 text += "- "; // it would be nice to use Unicode mute"\uD83D\uDD07 ";
513 lower_text[n]->set (text);
517 MixLayout::switch_bank (uint32_t base)
519 stripable_connections.drop_connections ();
521 /* work backwards so we can tell if we should actually switch banks */
523 boost::shared_ptr<Stripable> s[8];
524 uint32_t different = 0;
526 for (int n = 0; n < 8; ++n) {
527 s[n] = session.get_remote_nth_stripable (base+n, PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::VCA));
528 if (s[n] != stripable[n]) {
534 /* not even the first stripable exists, do nothing */
538 for (int n = 0; n < 8; ++n) {
542 /* at least one stripable in this bank */
546 for (int n = 0; n < 8; ++n) {
549 lower_text[n]->hide ();
553 lower_text[n]->show ();
555 /* stripable goes away? refill the bank, starting at the same point */
557 stripable[n]->DropReferences.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::switch_bank, this, bank_start), &p2);
558 stripable[n]->presentation_info().PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::stripable_property_change, this, _1, n), &p2);
559 stripable[n]->solo_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::solo_changed, this, n), &p2);
560 stripable[n]->mute_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::mute_changed, this, n), &p2);
562 if (stripable[n]->presentation_info().selected()) {
568 /* this will set lower text to the correct value (basically
572 solo_mute_changed (n);
574 knobs[n]->set_text_color (stripable[n]->presentation_info().color());
575 knobs[n]->set_arc_start_color (stripable[n]->presentation_info().color());
576 knobs[n]->set_arc_end_color (stripable[n]->presentation_info().color());
584 b = p2.button_by_id (Push2::Lower1);
587 b = p2.button_by_id (Push2::Lower2);
590 b = p2.button_by_id (Push2::Lower3);
593 b = p2.button_by_id (Push2::Lower4);
596 b = p2.button_by_id (Push2::Lower5);
599 b = p2.button_by_id (Push2::Lower6);
602 b = p2.button_by_id (Push2::Lower7);
605 b = p2.button_by_id (Push2::Lower8);
610 b->set_color (p2.get_color_index (stripable[n]->presentation_info().color()));
612 b->set_color (Push2::LED::Black);
615 b->set_state (Push2::LED::OneShot24th);
616 p2.write (b->state_msg());
623 MixLayout::button_right ()
625 switch_bank (max (0, bank_start + 8));
629 MixLayout::button_left ()
631 switch_bank (max (0, bank_start - 8));
636 MixLayout::button_select_press ()
641 MixLayout::button_select_release ()
643 if (!(p2.modifier_state() & Push2::ModSelect)) {
644 /* somebody else used us as a modifier */
650 for (int n = 0; n < 8; ++n) {
652 if (stripable[n]->presentation_info().selected()) {
661 /* no visible track selected, select first (if any) */
664 ControlProtocol::SetStripableSelection (stripable[0]);
669 if (p2.modifier_state() & Push2::ModShift) {
673 /* current selected is leftmost ... cancel selection,
674 switch banks by one, and select leftmost
676 if (bank_start != 0) {
677 ControlProtocol::ClearStripableSelection ();
678 switch_bank (bank_start-1);
680 ControlProtocol::SetStripableSelection (stripable[0]);
684 /* select prev, if any */
685 int n = selected - 1;
686 while (n >= 0 && !stripable[n]) {
690 ControlProtocol::SetStripableSelection (stripable[n]);
699 /* current selected is rightmost ... cancel selection,
700 switch banks by one, and select righmost
702 ControlProtocol::ToggleStripableSelection (stripable[selected]);
703 switch_bank (bank_start+1);
705 ControlProtocol::SetStripableSelection (stripable[7]);
708 /* select next, if any */
709 int n = selected + 1;
710 while (n < 8 && !stripable[n]) {
715 ControlProtocol::SetStripableSelection (stripable[n]);
723 MixLayout::stripables_added ()
725 /* reload current bank */
726 switch_bank (bank_start);
730 MixLayout::button_down ()
732 p2.scroll_dn_1_track ();
736 MixLayout::button_up ()
738 p2.scroll_up_1_track ();