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) {
75 Text* t = new Text (this);
76 upper_text.push_back (t);
77 t->set_font_description (fd2);
78 t->set_color (p2.get_color (Push2::ParameterName));
89 txt = _("Pan Widths");
110 lower_text.push_back (t);
111 t->set_font_description (fd2);
112 t->set_color (p2.get_color (Push2::ParameterName));
114 Rectangle* r = new Rectangle (this);
115 r->set (Rect (10 + (n*Push2Canvas::inter_button_spacing()) - 5, 2, Push2Canvas::inter_button_spacing(), 21));
116 backgrounds.push_back (r);
118 knobs[n] = new Push2Knob (p2, this);
119 knobs[n]->set_position (Duple (60 + (n*Push2Canvas::inter_button_spacing()), 95));
120 knobs[n]->set_radius (25);
123 mode_button = p2.button_by_id (Push2::Upper1);
125 session.RouteAdded.connect (session_connections, invalidator(*this), boost::bind (&MixLayout::stripables_added, this), &p2);
126 session.vca_manager().VCAAdded.connect (session_connections, invalidator (*this), boost::bind (&MixLayout::stripables_added, this), &p2);
129 MixLayout::~MixLayout ()
131 // Item destructor deletes all children
139 mode_button->set_color (Push2::LED::White);
140 mode_button->set_state (Push2::LED::OneShot24th);
141 p2.write (mode_button->state_msg());
143 switch_bank (bank_start);
147 MixLayout::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
149 set_source_rgb (context, p2.get_color (Push2::DarkBackground));
150 context->rectangle (0, 0, display_width(), display_height());
153 context->move_to (0, 22.5);
154 context->line_to (display_width(), 22.5);
155 context->set_line_width (1.0);
158 render_children (area, context);
162 MixLayout::button_upper (uint32_t n)
168 b = p2.button_by_id (Push2::Upper1);
171 vpot_mode = PanAzimuth;
172 b = p2.button_by_id (Push2::Upper2);
175 vpot_mode = PanWidth;
176 b = p2.button_by_id (Push2::Upper3);
180 b = p2.button_by_id (Push2::Upper4);
184 b = p2.button_by_id (Push2::Upper5);
188 b = p2.button_by_id (Push2::Upper6);
192 b = p2.button_by_id (Push2::Upper7);
196 b = p2.button_by_id (Push2::Upper8);
200 if (b != mode_button) {
201 mode_button->set_color (Push2::LED::Black);
202 mode_button->set_state (Push2::LED::OneShot24th);
203 p2.write (mode_button->state_msg());
212 MixLayout::show_vpot_mode ()
214 mode_button->set_color (Push2::LED::White);
215 mode_button->set_state (Push2::LED::OneShot24th);
216 p2.write (mode_button->state_msg());
218 boost::shared_ptr<AutomationControl> ac;
221 for (int s = 0; s < 8; ++s) {
223 knobs[s]->set_controllable (stripable[s]->gain_control());
225 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
227 knobs[s]->remove_flag (Push2Knob::ArcToZero);
231 for (int s = 0; s < 8; ++s) {
233 knobs[s]->set_controllable (stripable[s]->pan_azimuth_control());
234 knobs[s]->add_flag (Push2Knob::ArcToZero);
236 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
242 for (int s = 0; s < 8; ++s) {
244 knobs[s]->set_controllable (stripable[s]->pan_width_control());
246 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
249 knobs[s]->remove_flag (Push2Knob::ArcToZero);
253 for (int s = 0; s < 8; ++s) {
255 knobs[s]->set_controllable (stripable[s]->send_level_controllable (0));
257 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
260 knobs[s]->remove_flag (Push2Knob::ArcToZero);
264 for (int s = 0; s < 8; ++s) {
266 knobs[s]->set_controllable (stripable[s]->send_level_controllable (1));
268 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
271 knobs[s]->remove_flag (Push2Knob::ArcToZero);
275 for (int s = 0; s < 8; ++s) {
277 knobs[s]->set_controllable (stripable[s]->send_level_controllable (2));
279 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
282 knobs[s]->remove_flag (Push2Knob::ArcToZero);
286 for (int s = 0; s < 8; ++s) {
288 knobs[s]->set_controllable (stripable[s]->send_level_controllable (3));
290 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
293 knobs[s]->remove_flag (Push2Knob::ArcToZero);
297 for (int s = 0; s < 8; ++s) {
299 knobs[s]->set_controllable (stripable[s]->send_level_controllable (4));
301 knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
304 knobs[s]->remove_flag (Push2Knob::ArcToZero);
315 MixLayout::button_mute ()
317 boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
319 boost::shared_ptr<AutomationControl> ac = s->mute_control();
321 ac->set_value (!ac->get_value(), PBD::Controllable::UseGroup);
327 MixLayout::button_solo ()
329 boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
331 boost::shared_ptr<AutomationControl> ac = s->solo_control();
333 ac->set_value (!ac->get_value(), PBD::Controllable::UseGroup);
339 MixLayout::button_lower (uint32_t n)
345 ControlProtocol::SetStripableSelection (stripable[n]);
349 MixLayout::strip_vpot (int n, int delta)
351 boost::shared_ptr<Controllable> ac = knobs[n]->controllable();
354 ac->set_value (ac->get_value() + ((2.0/64.0) * delta), PBD::Controllable::UseGroup);
359 MixLayout::strip_vpot_touch (int n, bool touching)
362 boost::shared_ptr<AutomationControl> ac = stripable[n]->gain_control();
365 ac->start_touch (session.audible_frame());
367 ac->stop_touch (true, session.audible_frame());
374 MixLayout::stripable_property_change (PropertyChange const& what_changed, int which)
376 if (what_changed.contains (Properties::selected)) {
377 if (!stripable[which]) {
381 if (stripable[which]->presentation_info().selected()) {
382 selection_bg->show ();
383 selection_bg->set_fill_color (stripable[which]->presentation_info().color());
384 selection_bg->set (Rect (10 + (which*Push2Canvas::inter_button_spacing()) - 5, 137,
385 10 + (which*Push2Canvas::inter_button_spacing()) - 5 + Push2Canvas::inter_button_spacing(),
387 lower_text[which]->set_color (ArdourCanvas::contrasting_text_color (selection_bg->fill_color()));
389 selection_bg->hide ();
390 lower_text[which]->set_color (stripable[which]->presentation_info().color());
396 MixLayout::solo_changed (uint32_t n)
398 solo_mute_changed (n);
402 MixLayout::mute_changed (uint32_t n)
404 solo_mute_changed (n);
408 MixLayout::solo_mute_changed (uint32_t n)
410 string shortname = short_version (stripable[n]->name(), 10);
412 boost::shared_ptr<AutomationControl> ac;
413 ac = stripable[n]->solo_control();
414 if (ac && ac->get_value()) {
417 boost::shared_ptr<MuteControl> mc;
418 mc = stripable[n]->mute_control ();
420 if (mc->muted_by_self_or_masters()) {
422 } else if (mc->muted_by_others_soloing()) {
423 text += "- "; // it would be nice to use Unicode mute"\uD83D\uDD07 ";
427 lower_text[n]->set (text);
431 MixLayout::switch_bank (uint32_t base)
433 stripable_connections.drop_connections ();
435 /* work backwards so we can tell if we should actually switch banks */
437 boost::shared_ptr<Stripable> s[8];
438 uint32_t old_empty = 0;
439 uint32_t new_empty = 0;
441 for (int n = 0; n < 8; ++n) {
445 s[n] = session.get_remote_nth_stripable (base+n, PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::VCA));
451 if ((new_empty != 0) && (new_empty >= old_empty)) {
452 /* some missing strips; new bank the same or more empty stripables than the old one, do
453 nothing since we had already reached the end.
455 for (int n = 0; n < 8; ++n) {
456 upper_text[n]->hide ();
457 lower_text[n]->hide ();
458 backgrounds[n]->hide ();
463 for (int n = 0; n < 8; ++n) {
467 /* at least one stripable in this bank */
471 for (int n = 0; n < 8; ++n) {
473 upper_text[n]->hide ();
474 lower_text[n]->hide ();
475 backgrounds[n]->hide ();
479 upper_text[n]->show ();
480 lower_text[n]->show ();
481 backgrounds[n]->show ();
482 backgrounds[n]->set_fill_color (stripable[n]->presentation_info().color());
484 /* stripable goes away? refill the bank, starting at the same point */
486 stripable[n]->DropReferences.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::switch_bank, this, bank_start), &p2);
487 stripable[n]->presentation_info().PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::stripable_property_change, this, _1, n), &p2);
488 stripable[n]->solo_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::solo_changed, this, n), &p2);
489 stripable[n]->mute_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::mute_changed, this, n), &p2);
491 solo_mute_changed (n);
497 b = p2.button_by_id (Push2::Lower1);
500 b = p2.button_by_id (Push2::Lower2);
503 b = p2.button_by_id (Push2::Lower3);
506 b = p2.button_by_id (Push2::Lower4);
509 b = p2.button_by_id (Push2::Lower5);
512 b = p2.button_by_id (Push2::Lower6);
515 b = p2.button_by_id (Push2::Lower7);
518 b = p2.button_by_id (Push2::Lower8);
522 b->set_color (p2.get_color_index (stripable[n]->presentation_info().color()));
523 b->set_state (Push2::LED::OneShot24th);
524 p2.write (b->state_msg());
526 knobs[n]->set_text_color (stripable[n]->presentation_info().color());
527 knobs[n]->set_arc_start_color (stripable[n]->presentation_info().color());
528 knobs[n]->set_arc_end_color (stripable[n]->presentation_info().color());
535 MixLayout::button_right ()
537 switch_bank (max (0, bank_start + 8));
541 MixLayout::button_left ()
543 switch_bank (max (0, bank_start - 8));
548 MixLayout::button_select_press ()
553 MixLayout::button_select_release ()
555 if (!(p2.modifier_state() & Push2::ModSelect)) {
556 /* somebody else used us as a modifier */
562 for (int n = 0; n < 8; ++n) {
564 if (stripable[n]->presentation_info().selected()) {
573 /* no visible track selected, select first (if any) */
576 ControlProtocol::SetStripableSelection (stripable[0]);
581 if (p2.modifier_state() & Push2::ModShift) {
582 std::cerr << "select prev\n";
586 /* current selected is leftmost ... cancel selection,
587 switch banks by one, and select leftmost
589 if (bank_start != 0) {
590 ControlProtocol::ClearStripableSelection ();
591 switch_bank (bank_start-1);
593 ControlProtocol::SetStripableSelection (stripable[0]);
597 /* select prev, if any */
598 int n = selected - 1;
599 while (n >= 0 && !stripable[n]) {
603 ControlProtocol::SetStripableSelection (stripable[n]);
609 std::cerr << "select next\n";
613 /* current selected is rightmost ... cancel selection,
614 switch banks by one, and select righmost
616 ControlProtocol::ToggleStripableSelection (stripable[selected]);
617 switch_bank (bank_start+1);
619 ControlProtocol::SetStripableSelection (stripable[7]);
622 /* select next, if any */
623 int n = selected + 1;
624 while (n < 8 && !stripable[n]) {
629 ControlProtocol::SetStripableSelection (stripable[n]);
637 MixLayout::stripables_added ()
639 /* reload current bank */
640 switch_bank (bank_start);