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 "temporal/time.h"
32 #include "temporal/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 "gtkmm2ext/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 Gtkmm2ext;
72 using namespace ArdourCanvas;
74 MixLayout::MixLayout (Push2& p, Session & s, std::string const & name)
75 : Push2Layout (p, s, name)
81 bg = new ArdourCanvas::Rectangle (this);
82 bg->set (Rect (0, 0, display_width(), display_height()));
83 bg->set_fill_color (p2.get_color (Push2::DarkBackground));
87 upper_line = new Line (this);
88 upper_line->set (Duple (0, 22.5), Duple (display_width(), 22.5));
89 upper_line->set_outline_color (p2.get_color (Push2::LightBackground));
91 Pango::FontDescription fd2 ("Sans 10");
93 for (int n = 0; n < 8; ++n) {
95 /* background for text labels for knob function */
97 ArdourCanvas::Rectangle* r = new ArdourCanvas::Rectangle (this);
98 Coord x0 = 10 + (n*Push2Canvas::inter_button_spacing()) - 5;
99 r->set (Rect (x0, 2, x0 + Push2Canvas::inter_button_spacing(), 2 + 21));
100 upper_backgrounds.push_back (r);
102 r = new ArdourCanvas::Rectangle (this);
103 r->set (Rect (x0, 137, x0 + Push2Canvas::inter_button_spacing(), 137 + 21));
104 lower_backgrounds.push_back (r);
106 /* text labels for knob function*/
108 Text* t = new Text (this);
109 t->set_font_description (fd2);
110 t->set_color (p2.get_color (Push2::ParameterName));
111 t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 5));
122 txt = _("Pan Widths");
141 upper_text.push_back (t);
145 gain_meter[n] = new GainMeter (this, p2);
146 gain_meter[n]->set_position (Duple (40 + (n * Push2Canvas::inter_button_spacing()), 95));
148 /* stripable names */
151 t->set_font_description (fd2);
152 t->set_color (p2.get_color (Push2::ParameterName));
153 t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 140));
154 lower_text.push_back (t);
158 mode_button = p2.button_by_id (Push2::Upper1);
160 session.RouteAdded.connect (session_connections, invalidator(*this), boost::bind (&MixLayout::stripables_added, this), &p2);
161 session.vca_manager().VCAAdded.connect (session_connections, invalidator (*this), boost::bind (&MixLayout::stripables_added, this), &p2);
164 MixLayout::~MixLayout ()
166 // Item destructor deletes all children
172 Push2::ButtonID upper_buttons[] = { Push2::Upper1, Push2::Upper2, Push2::Upper3, Push2::Upper4,
173 Push2::Upper5, Push2::Upper6, Push2::Upper7, Push2::Upper8 };
176 for (size_t n = 0; n < sizeof (upper_buttons) / sizeof (upper_buttons[0]); ++n) {
177 Push2::Button* b = p2.button_by_id (upper_buttons[n]);
179 if (b != mode_button) {
180 b->set_color (Push2::LED::DarkGray);
182 b->set_color (Push2::LED::White);
184 b->set_state (Push2::LED::OneShot24th);
185 p2.write (b->state_msg());
188 switch_bank (bank_start);
194 MixLayout::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
196 Container::render (area, context);
200 MixLayout::button_upper (uint32_t n)
206 b = p2.button_by_id (Push2::Upper1);
209 vpot_mode = PanAzimuth;
210 b = p2.button_by_id (Push2::Upper2);
213 vpot_mode = PanWidth;
214 b = p2.button_by_id (Push2::Upper3);
218 b = p2.button_by_id (Push2::Upper4);
222 b = p2.button_by_id (Push2::Upper5);
226 b = p2.button_by_id (Push2::Upper6);
230 b = p2.button_by_id (Push2::Upper7);
234 b = p2.button_by_id (Push2::Upper8);
238 if (b != mode_button) {
239 mode_button->set_color (Push2::LED::Black);
240 mode_button->set_state (Push2::LED::OneShot24th);
241 p2.write (mode_button->state_msg());
250 MixLayout::show_vpot_mode ()
252 mode_button->set_color (Push2::LED::White);
253 mode_button->set_state (Push2::LED::OneShot24th);
254 p2.write (mode_button->state_msg());
256 for (int s = 0; s < 8; ++s) {
257 upper_backgrounds[s]->hide ();
258 upper_text[s]->set_color (p2.get_color (Push2::ParameterName));
263 boost::shared_ptr<AutomationControl> ac;
266 for (int s = 0; s < 8; ++s) {
268 gain_meter[s]->knob->set_controllable (stripable[s]->gain_control());
269 boost::shared_ptr<PeakMeter> pm = stripable[s]->peak_meter();
271 gain_meter[s]->meter->set_meter (pm.get());
273 gain_meter[s]->meter->set_meter (0);
276 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
277 gain_meter[s]->meter->set_meter (0);
279 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
280 gain_meter[s]->meter->show ();
285 for (int s = 0; s < 8; ++s) {
287 gain_meter[s]->knob->set_controllable (stripable[s]->pan_azimuth_control());
288 gain_meter[s]->knob->add_flag (Push2Knob::ArcToZero);
290 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
293 gain_meter[s]->meter->hide ();
298 for (int s = 0; s < 8; ++s) {
300 gain_meter[s]->knob->set_controllable (stripable[s]->pan_width_control());
302 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
305 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
306 gain_meter[s]->meter->hide ();
311 for (int s = 0; s < 8; ++s) {
313 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (0));
315 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
318 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
319 gain_meter[s]->meter->hide ();
324 for (int s = 0; s < 8; ++s) {
326 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (1));
328 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
331 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
332 gain_meter[s]->meter->hide ();
337 for (int s = 0; s < 8; ++s) {
339 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (2));
341 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
344 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
345 gain_meter[s]->meter->hide ();
350 for (int s = 0; s < 8; ++s) {
352 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (3));
354 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
357 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
358 gain_meter[s]->meter->hide ();
363 for (int s = 0; s < 8; ++s) {
365 gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (4));
367 gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
370 gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
371 gain_meter[s]->meter->hide ();
379 upper_backgrounds[n]->set_fill_color (p2.get_color (Push2::ParameterName));
380 upper_backgrounds[n]->set_outline_color (p2.get_color (Push2::ParameterName));
381 upper_backgrounds[n]->show ();
382 upper_text[n]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
386 MixLayout::button_mute ()
388 boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
390 boost::shared_ptr<AutomationControl> ac = s->mute_control();
392 ac->set_value (!ac->get_value(), PBD::Controllable::UseGroup);
398 MixLayout::button_solo ()
400 boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
402 boost::shared_ptr<AutomationControl> ac = s->solo_control();
404 session.set_control (ac, !ac->get_value(), PBD::Controllable::UseGroup);
410 MixLayout::button_lower (uint32_t n)
416 ControlProtocol::SetStripableSelection (stripable[n]);
420 MixLayout::strip_vpot (int n, int delta)
422 boost::shared_ptr<Controllable> ac = gain_meter[n]->knob->controllable();
425 ac->set_value (ac->interface_to_internal (
426 min (ac->upper(), max (ac->lower(), ac->internal_to_interface (ac->get_value()) + (delta/256.0)))),
427 PBD::Controllable::UseGroup);
432 MixLayout::strip_vpot_touch (int n, bool touching)
435 boost::shared_ptr<AutomationControl> ac = stripable[n]->gain_control();
438 ac->start_touch (session.audible_sample());
440 ac->stop_touch (session.audible_sample());
447 MixLayout::stripable_property_change (PropertyChange const& what_changed, uint32_t which)
449 if (what_changed.contains (Properties::color)) {
450 lower_backgrounds[which]->set_fill_color (stripable[which]->presentation_info().color());
452 if (stripable[which]->is_selected()) {
453 lower_text[which]->set_fill_color (contrasting_text_color (stripable[which]->presentation_info().color()));
454 /* might not be a MIDI track, in which case this will
457 p2.update_selection_color ();
461 if (what_changed.contains (Properties::hidden)) {
462 switch_bank (bank_start);
465 if (what_changed.contains (Properties::selected)) {
467 if (!stripable[which]) {
471 if (stripable[which]->is_selected()) {
472 show_selection (which);
474 hide_selection (which);
481 MixLayout::show_selection (uint32_t n)
483 lower_backgrounds[n]->show ();
484 lower_backgrounds[n]->set_fill_color (stripable[n]->presentation_info().color());
485 lower_text[n]->set_color (contrasting_text_color (lower_backgrounds[n]->fill_color()));
489 MixLayout::hide_selection (uint32_t n)
491 lower_backgrounds[n]->hide ();
493 lower_text[n]->set_color (stripable[n]->presentation_info().color());
498 MixLayout::solo_changed (uint32_t n)
500 solo_mute_changed (n);
504 MixLayout::mute_changed (uint32_t n)
506 solo_mute_changed (n);
510 MixLayout::solo_mute_changed (uint32_t n)
512 string shortname = short_version (stripable[n]->name(), 10);
514 boost::shared_ptr<AutomationControl> ac;
515 ac = stripable[n]->solo_control();
516 if (ac && ac->get_value()) {
519 boost::shared_ptr<MuteControl> mc;
520 mc = stripable[n]->mute_control ();
522 if (mc->muted_by_self_or_masters()) {
524 } else if (mc->muted_by_others_soloing()) {
525 text += "- "; // it would be nice to use Unicode mute"\uD83D\uDD07 ";
529 lower_text[n]->set (text);
533 MixLayout::switch_bank (uint32_t base)
535 stripable_connections.drop_connections ();
537 /* work backwards so we can tell if we should actually switch banks */
539 boost::shared_ptr<Stripable> s[8];
540 uint32_t different = 0;
542 for (int n = 0; n < 8; ++n) {
543 s[n] = session.get_remote_nth_stripable (base+n, PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::VCA));
544 if (s[n] != stripable[n]) {
550 /* not even the first stripable exists, do nothing */
551 for (int n = 0; n < 8; ++n) {
552 stripable[n].reset ();
553 gain_meter[n]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
554 gain_meter[n]->meter->set_meter (0);
559 for (int n = 0; n < 8; ++n) {
563 /* at least one stripable in this bank */
567 for (int n = 0; n < 8; ++n) {
570 lower_text[n]->hide ();
572 gain_meter[n]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
573 gain_meter[n]->meter->set_meter (0);
576 lower_text[n]->show ();
578 /* stripable goes away? refill the bank, starting at the same point */
580 stripable[n]->DropReferences.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::switch_bank, this, bank_start), &p2);
581 stripable[n]->presentation_info().PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::stripable_property_change, this, _1, n), &p2);
582 stripable[n]->solo_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::solo_changed, this, n), &p2);
583 stripable[n]->mute_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::mute_changed, this, n), &p2);
585 if (stripable[n]->is_selected()) {
591 /* this will set lower text to the correct value (basically
595 solo_mute_changed (n);
597 gain_meter[n]->knob->set_text_color (stripable[n]->presentation_info().color());
598 gain_meter[n]->knob->set_arc_start_color (stripable[n]->presentation_info().color());
599 gain_meter[n]->knob->set_arc_end_color (stripable[n]->presentation_info().color());
607 b = p2.button_by_id (Push2::Lower1);
610 b = p2.button_by_id (Push2::Lower2);
613 b = p2.button_by_id (Push2::Lower3);
616 b = p2.button_by_id (Push2::Lower4);
619 b = p2.button_by_id (Push2::Lower5);
622 b = p2.button_by_id (Push2::Lower6);
625 b = p2.button_by_id (Push2::Lower7);
628 b = p2.button_by_id (Push2::Lower8);
633 b->set_color (p2.get_color_index (stripable[n]->presentation_info().color()));
635 b->set_color (Push2::LED::Black);
638 b->set_state (Push2::LED::OneShot24th);
639 p2.write (b->state_msg());
646 MixLayout::button_right ()
648 switch_bank (max (0, bank_start + 8));
652 MixLayout::button_left ()
654 switch_bank (max (0, bank_start - 8));
659 MixLayout::button_select_press ()
664 MixLayout::button_select_release ()
666 if (!(p2.modifier_state() & Push2::ModSelect)) {
667 /* somebody else used us as a modifier */
673 for (int n = 0; n < 8; ++n) {
675 if (stripable[n]->is_selected()) {
684 /* no visible track selected, select first (if any) */
687 ControlProtocol::SetStripableSelection (stripable[0]);
692 if (p2.modifier_state() & Push2::ModShift) {
696 /* current selected is leftmost ... cancel selection,
697 switch banks by one, and select leftmost
699 if (bank_start != 0) {
700 ControlProtocol::ClearStripableSelection ();
701 switch_bank (bank_start-1);
703 ControlProtocol::SetStripableSelection (stripable[0]);
707 /* select prev, if any */
708 int n = selected - 1;
709 while (n >= 0 && !stripable[n]) {
713 ControlProtocol::SetStripableSelection (stripable[n]);
722 /* current selected is rightmost ... cancel selection,
723 switch banks by one, and select righmost
725 ControlProtocol::ToggleStripableSelection (stripable[selected]);
726 switch_bank (bank_start+1);
728 ControlProtocol::SetStripableSelection (stripable[7]);
731 /* select next, if any */
732 int n = selected + 1;
733 while (n < 8 && !stripable[n]) {
738 ControlProtocol::SetStripableSelection (stripable[n]);
746 MixLayout::stripables_added ()
748 /* reload current bank */
749 switch_bank (bank_start);
753 MixLayout::button_down ()
755 p2.scroll_dn_1_track ();
759 MixLayout::button_up ()
761 p2.scroll_up_1_track ();
765 MixLayout::update_meters ()
767 if (vpot_mode != Volume) {
771 for (uint32_t n = 0; n < 8; ++n) {
772 gain_meter[n]->meter->update_meters ();
776 MixLayout::GainMeter::GainMeter (Item* parent, Push2& p2)
779 knob = new Push2Knob (p2, this);
780 knob->set_radius (25);
781 /* leave position at (0,0) */
783 meter = new LevelMeter (p2, this, 90, ArdourCanvas::Meter::Vertical);
784 meter->set_position (Duple (40, -60));