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/vca_manager.h"
45 #include "canvas/colors.h"
46 #include "canvas/rectangle.h"
48 #include "gtkmm2ext/gui_thread.h"
58 using namespace ARDOUR;
62 using namespace ArdourSurface;
63 using namespace ArdourCanvas;
65 MixLayout::MixLayout (Push2& p, Session& s)
70 selection_bg = new Rectangle (this);
71 selection_bg->hide ();
73 Pango::FontDescription fd2 ("Sans 10");
74 for (int n = 0; n < 8; ++n) {
76 /* background for text labels for knob function */
78 Rectangle* r = new Rectangle (this);
79 Coord x0 = 10 + (n*Push2Canvas::inter_button_spacing()) - 5;
80 r->set (Rect (x0, 2, x0 + Push2Canvas::inter_button_spacing(), 2 + 21));
81 backgrounds.push_back (r);
83 /* text labels for knob function*/
85 Text* t = new Text (this);
86 t->set_font_description (fd2);
87 t->set_color (p2.get_color (Push2::ParameterName));
88 t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 5));
99 txt = _("Pan Widths");
118 upper_text.push_back (t);
122 knobs[n] = new Push2Knob (p2, this);
123 knobs[n]->set_position (Duple (60 + (n*Push2Canvas::inter_button_spacing()), 95));
124 knobs[n]->set_radius (25);
126 /* stripable names */
129 t->set_font_description (fd2);
130 t->set_color (p2.get_color (Push2::ParameterName));
131 t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 140));
132 lower_text.push_back (t);
136 mode_button = p2.button_by_id (Push2::Upper1);
138 session.RouteAdded.connect (session_connections, invalidator(*this), boost::bind (&MixLayout::stripables_added, this), &p2);
139 session.vca_manager().VCAAdded.connect (session_connections, invalidator (*this), boost::bind (&MixLayout::stripables_added, this), &p2);
142 MixLayout::~MixLayout ()
144 // Item destructor deletes all children
152 mode_button->set_color (Push2::LED::White);
153 mode_button->set_state (Push2::LED::OneShot24th);
154 p2.write (mode_button->state_msg());
156 switch_bank (bank_start);
160 MixLayout::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
162 DEBUG_TRACE (DEBUG::Push2, string_compose ("mix render %1\n", area));
164 /* draw background */
166 set_source_rgb (context, p2.get_color (Push2::DarkBackground));
167 context->rectangle (0, 0, display_width(), display_height());
170 /* draw line across top (below labels) */
172 context->move_to (0, 22.5);
173 context->line_to (display_width(), 22.5);
174 context->set_line_width (1.0);
177 /* show the kids ... */
179 render_children (area, context);
183 MixLayout::button_upper (uint32_t n)
189 b = p2.button_by_id (Push2::Upper1);
192 vpot_mode = PanAzimuth;
193 b = p2.button_by_id (Push2::Upper2);
196 vpot_mode = PanWidth;
197 b = p2.button_by_id (Push2::Upper3);
201 b = p2.button_by_id (Push2::Upper4);
205 b = p2.button_by_id (Push2::Upper5);
209 b = p2.button_by_id (Push2::Upper6);
213 b = p2.button_by_id (Push2::Upper7);
217 b = p2.button_by_id (Push2::Upper8);
221 if (b != mode_button) {
222 mode_button->set_color (Push2::LED::Black);
223 mode_button->set_state (Push2::LED::OneShot24th);
224 p2.write (mode_button->state_msg());
233 MixLayout::show_vpot_mode ()
235 mode_button->set_color (Push2::LED::White);
236 mode_button->set_state (Push2::LED::OneShot24th);
237 p2.write (mode_button->state_msg());
239 for (int s = 0; s < 8; ++s) {
240 backgrounds[s]->hide ();
241 upper_text[s]->set_color (p2.get_color (Push2::ParameterName));
244 boost::shared_ptr<AutomationControl> ac;
247 for (int s = 0; s < 8; ++s) {
249 knobs[s]->set_controllable (stripable[s]->gain_control());
251 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
253 knobs[s]->remove_flag (Push2Knob::ArcToZero);
255 backgrounds[0]->set_fill_color (p2.get_color (Push2::ParameterName));
256 backgrounds[0]->show ();
257 upper_text[0]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
260 for (int s = 0; s < 8; ++s) {
262 knobs[s]->set_controllable (stripable[s]->pan_azimuth_control());
263 knobs[s]->add_flag (Push2Knob::ArcToZero);
265 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
269 backgrounds[1]->set_fill_color (p2.get_color (Push2::ParameterName));
270 backgrounds[1]->show ();
271 upper_text[1]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
274 for (int s = 0; s < 8; ++s) {
276 knobs[s]->set_controllable (stripable[s]->pan_width_control());
278 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
281 knobs[s]->remove_flag (Push2Knob::ArcToZero);
283 backgrounds[2]->set_fill_color (p2.get_color (Push2::ParameterName));
284 backgrounds[2]->show ();
285 upper_text[2]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
288 for (int s = 0; s < 8; ++s) {
290 knobs[s]->set_controllable (stripable[s]->send_level_controllable (0));
292 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
295 knobs[s]->remove_flag (Push2Knob::ArcToZero);
297 backgrounds[3]->set_fill_color (p2.get_color (Push2::ParameterName));
298 backgrounds[3]->show ();
299 upper_text[3]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
302 for (int s = 0; s < 8; ++s) {
304 knobs[s]->set_controllable (stripable[s]->send_level_controllable (1));
306 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
309 knobs[s]->remove_flag (Push2Knob::ArcToZero);
311 backgrounds[4]->set_fill_color (p2.get_color (Push2::ParameterName));
312 backgrounds[4]->show ();
313 upper_text[4]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
316 for (int s = 0; s < 8; ++s) {
318 knobs[s]->set_controllable (stripable[s]->send_level_controllable (2));
320 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
323 knobs[s]->remove_flag (Push2Knob::ArcToZero);
325 backgrounds[5]->set_fill_color (p2.get_color (Push2::ParameterName));
326 backgrounds[5]->show ();
327 upper_text[5]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
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);
339 backgrounds[6]->set_fill_color (p2.get_color (Push2::ParameterName));
340 backgrounds[6]->show ();
341 upper_text[6]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
344 for (int s = 0; s < 8; ++s) {
346 knobs[s]->set_controllable (stripable[s]->send_level_controllable (4));
348 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
351 knobs[s]->remove_flag (Push2Knob::ArcToZero);
353 backgrounds[7]->set_fill_color (p2.get_color (Push2::ParameterName));
354 backgrounds[7]->show ();
355 upper_text[7]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
363 MixLayout::button_mute ()
365 boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
367 boost::shared_ptr<AutomationControl> ac = s->mute_control();
369 ac->set_value (!ac->get_value(), PBD::Controllable::UseGroup);
375 MixLayout::button_solo ()
377 boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
379 boost::shared_ptr<AutomationControl> ac = s->solo_control();
381 ac->set_value (!ac->get_value(), PBD::Controllable::UseGroup);
387 MixLayout::button_lower (uint32_t n)
393 ControlProtocol::SetStripableSelection (stripable[n]);
397 MixLayout::strip_vpot (int n, int delta)
399 boost::shared_ptr<Controllable> ac = knobs[n]->controllable();
402 ac->set_value (ac->get_value() + ((2.0/64.0) * delta), PBD::Controllable::UseGroup);
407 MixLayout::strip_vpot_touch (int n, bool touching)
410 boost::shared_ptr<AutomationControl> ac = stripable[n]->gain_control();
413 ac->start_touch (session.audible_frame());
415 ac->stop_touch (true, session.audible_frame());
422 MixLayout::stripable_property_change (PropertyChange const& what_changed, uint32_t which)
424 if (what_changed.contains (Properties::hidden)) {
425 switch_bank (bank_start);
428 if (what_changed.contains (Properties::selected)) {
430 if (!stripable[which]) {
434 if (stripable[which]->presentation_info().selected()) {
435 show_selection (which);
437 hide_selection (which);
444 MixLayout::show_selection (uint32_t n)
446 selection_bg->show ();
447 selection_bg->set_fill_color (stripable[n]->presentation_info().color());
448 const Coord x0 = 10 + (n * Push2Canvas::inter_button_spacing()) - 5;
449 selection_bg->set (Rect (x0, 137, x0 + Push2Canvas::inter_button_spacing(), 137 + 21));
450 lower_text[n]->set_color (ArdourCanvas::contrasting_text_color (selection_bg->fill_color()));
454 MixLayout::hide_selection (uint32_t n)
456 selection_bg->hide ();
458 lower_text[n]->set_color (stripable[n]->presentation_info().color());
463 MixLayout::solo_changed (uint32_t n)
465 solo_mute_changed (n);
469 MixLayout::mute_changed (uint32_t n)
471 solo_mute_changed (n);
475 MixLayout::solo_mute_changed (uint32_t n)
477 string shortname = short_version (stripable[n]->name(), 10);
479 boost::shared_ptr<AutomationControl> ac;
480 ac = stripable[n]->solo_control();
481 if (ac && ac->get_value()) {
484 boost::shared_ptr<MuteControl> mc;
485 mc = stripable[n]->mute_control ();
487 if (mc->muted_by_self_or_masters()) {
489 } else if (mc->muted_by_others_soloing()) {
490 text += "- "; // it would be nice to use Unicode mute"\uD83D\uDD07 ";
494 lower_text[n]->set (text);
498 MixLayout::switch_bank (uint32_t base)
500 stripable_connections.drop_connections ();
502 /* work backwards so we can tell if we should actually switch banks */
504 boost::shared_ptr<Stripable> s[8];
505 uint32_t different = 0;
507 for (int n = 0; n < 8; ++n) {
508 s[n] = session.get_remote_nth_stripable (base+n, PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::VCA));
509 if (s[n] != stripable[n]) {
515 /* some missing strips; new bank the same or more empty stripables than the old one, do
516 nothing since we had already reached the end.
522 /* not even the first stripable exists, do nothing */
526 for (int n = 0; n < 8; ++n) {
530 /* at least one stripable in this bank */
534 for (int n = 0; n < 8; ++n) {
536 lower_text[n]->hide ();
541 lower_text[n]->show ();
543 /* stripable goes away? refill the bank, starting at the same point */
545 stripable[n]->DropReferences.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::switch_bank, this, bank_start), &p2);
546 stripable[n]->presentation_info().PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::stripable_property_change, this, _1, n), &p2);
547 stripable[n]->solo_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::solo_changed, this, n), &p2);
548 stripable[n]->mute_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::mute_changed, this, n), &p2);
550 if (stripable[n]->presentation_info().selected()) {
556 /* this will set lower text to the correct value (basically
560 solo_mute_changed (n);
566 b = p2.button_by_id (Push2::Lower1);
569 b = p2.button_by_id (Push2::Lower2);
572 b = p2.button_by_id (Push2::Lower3);
575 b = p2.button_by_id (Push2::Lower4);
578 b = p2.button_by_id (Push2::Lower5);
581 b = p2.button_by_id (Push2::Lower6);
584 b = p2.button_by_id (Push2::Lower7);
587 b = p2.button_by_id (Push2::Lower8);
591 b->set_color (p2.get_color_index (stripable[n]->presentation_info().color()));
592 b->set_state (Push2::LED::OneShot24th);
593 p2.write (b->state_msg());
595 knobs[n]->set_text_color (stripable[n]->presentation_info().color());
596 knobs[n]->set_arc_start_color (stripable[n]->presentation_info().color());
597 knobs[n]->set_arc_end_color (stripable[n]->presentation_info().color());
604 MixLayout::button_right ()
606 switch_bank (max (0, bank_start + 8));
610 MixLayout::button_left ()
612 switch_bank (max (0, bank_start - 8));
617 MixLayout::button_select_press ()
622 MixLayout::button_select_release ()
624 if (!(p2.modifier_state() & Push2::ModSelect)) {
625 /* somebody else used us as a modifier */
631 for (int n = 0; n < 8; ++n) {
633 if (stripable[n]->presentation_info().selected()) {
642 /* no visible track selected, select first (if any) */
645 ControlProtocol::SetStripableSelection (stripable[0]);
650 if (p2.modifier_state() & Push2::ModShift) {
651 std::cerr << "select prev\n";
655 /* current selected is leftmost ... cancel selection,
656 switch banks by one, and select leftmost
658 if (bank_start != 0) {
659 ControlProtocol::ClearStripableSelection ();
660 switch_bank (bank_start-1);
662 ControlProtocol::SetStripableSelection (stripable[0]);
666 /* select prev, if any */
667 int n = selected - 1;
668 while (n >= 0 && !stripable[n]) {
672 ControlProtocol::SetStripableSelection (stripable[n]);
678 std::cerr << "select next\n";
682 /* current selected is rightmost ... cancel selection,
683 switch banks by one, and select righmost
685 ControlProtocol::ToggleStripableSelection (stripable[selected]);
686 switch_bank (bank_start+1);
688 ControlProtocol::SetStripableSelection (stripable[7]);
691 /* select next, if any */
692 int n = selected + 1;
693 while (n < 8 && !stripable[n]) {
698 ControlProtocol::SetStripableSelection (stripable[n]);
706 MixLayout::stripables_added ()
708 /* reload current bank */
709 switch_bank (bank_start);