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"
28 #include "pbd/search_path.h"
29 #include "pbd/enumwriter.h"
31 #include "midi++/parser.h"
32 #include "timecode/time.h"
33 #include "timecode/bbt_time.h"
35 #include "ardour/async_midi_port.h"
36 #include "ardour/audioengine.h"
37 #include "ardour/debug.h"
38 #include "ardour/dsp_filter.h"
39 #include "ardour/filesystem_paths.h"
40 #include "ardour/midiport_manager.h"
41 #include "ardour/midi_track.h"
42 #include "ardour/midi_port.h"
43 #include "ardour/monitor_control.h"
44 #include "ardour/meter.h"
45 #include "ardour/session.h"
46 #include "ardour/solo_isolate_control.h"
47 #include "ardour/solo_safe_control.h"
48 #include "ardour/tempo.h"
50 #include "gtkmm2ext/gui_thread.h"
51 #include "gtkmm2ext/rgb_macros.h"
53 #include "canvas/box.h"
54 #include "canvas/line.h"
55 #include "canvas/meter.h"
56 #include "canvas/rectangle.h"
57 #include "canvas/text.h"
61 #include "level_meter.h"
64 #include "track_mix.h"
67 using namespace ARDOUR;
71 using namespace ArdourSurface;
72 using namespace ArdourCanvas;
74 TrackMixLayout::TrackMixLayout (Push2& p, Session& s)
77 Pango::FontDescription fd ("Sans 10");
79 bg = new Rectangle (this);
80 bg->set (Rect (0, 0, display_width(), display_height()));
81 bg->set_fill_color (p2.get_color (Push2::DarkBackground));
83 upper_line = new Line (this);
84 upper_line->set (Duple (0, 22.5), Duple (display_width(), 22.5));
85 upper_line->set_outline_color (p2.get_color (Push2::LightBackground));
87 for (int n = 0; n < 8; ++n) {
92 t->set_font_description (fd);
93 t->set_color (p2.get_color (Push2::ParameterName));
94 t->set_position ( Duple (10 + (n*Push2Canvas::inter_button_spacing()), 2));
95 upper_text.push_back (t);
99 t->set_font_description (fd);
100 t->set_color (p2.get_color (Push2::ParameterName));
101 t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 140));
103 lower_text.push_back (t);
107 upper_text[n]->set (_("Track Volume"));
108 lower_text[n]->set (_("Mute"));
111 upper_text[n]->set (_("Track Pan"));
112 lower_text[n]->set (_("Solo"));
115 upper_text[n]->set (_("Track Width"));
116 lower_text[n]->set (_("Rec-enable"));
119 upper_text[n]->set (_("Track Trim"));
120 lower_text[n]->set (_("In"));
123 lower_text[n]->set (_("Disk"));
126 lower_text[n]->set (_("Solo Iso"));
129 lower_text[n]->set (_("Solo Lock"));
132 lower_text[n]->set (_(""));
136 knobs[n] = new Push2Knob (p2, this);
137 knobs[n]->set_position (Duple (60 + (Push2Canvas::inter_button_spacing()*n), 95));
138 knobs[n]->set_radius (25);
141 name_text = new Text (this);
142 name_text->set_font_description (fd);
143 name_text->set_position (Duple (10 + (4*Push2Canvas::inter_button_spacing()), 2));
145 meter = new LevelMeter (p2, this, 200, ArdourCanvas::Meter::Horizontal);
146 meter->set_position (Duple (10 + (4 * Push2Canvas::inter_button_spacing()), 50));
148 ControlProtocol::StripableSelectionChanged.connect (selection_connection, invalidator (*this), boost::bind (&TrackMixLayout::selection_changed, this), &p2);
151 TrackMixLayout::~TrackMixLayout ()
153 for (int n = 0; n < 8; ++n) {
159 TrackMixLayout::selection_changed ()
161 boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
168 TrackMixLayout::show ()
170 selection_changed ();
172 Push2::ButtonID lower_buttons[] = { Push2::Lower1, Push2::Lower2, Push2::Lower3, Push2::Lower4,
173 Push2::Lower5, Push2::Lower6, Push2::Lower7, Push2::Lower8 };
175 for (size_t n = 0; n < sizeof (lower_buttons) / sizeof (lower_buttons[0]); ++n) {
176 Push2::Button* b = p2.button_by_id (lower_buttons[n]);
177 b->set_color (Push2::LED::DarkGray);
178 b->set_state (Push2::LED::OneShot24th);
179 p2.write (b->state_msg());
186 TrackMixLayout::hide ()
188 set_stripable (boost::shared_ptr<Stripable>());
192 TrackMixLayout::render (ArdourCanvas::Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
194 Container::render (area, context);
198 TrackMixLayout::button_upper (uint32_t n)
203 TrackMixLayout::button_lower (uint32_t n)
213 stripable->mute_control()->set_value (!stripable->mute_control()->get_value(), PBD::Controllable::UseGroup);
216 stripable->solo_control()->set_value (!stripable->solo_control()->get_value(), PBD::Controllable::UseGroup);
219 stripable->rec_enable_control()->set_value (!stripable->rec_enable_control()->get_value(), PBD::Controllable::UseGroup);
222 mc = stripable->monitoring_control()->monitoring_choice();
225 stripable->monitoring_control()->set_value (MonitorAuto, PBD::Controllable::UseGroup);
228 stripable->monitoring_control()->set_value (MonitorInput, PBD::Controllable::UseGroup);
233 mc = stripable->monitoring_control()->monitoring_choice();
236 stripable->monitoring_control()->set_value (MonitorAuto, PBD::Controllable::UseGroup);
239 stripable->monitoring_control()->set_value (MonitorDisk, PBD::Controllable::UseGroup);
244 stripable->solo_isolate_control()->set_value (!stripable->solo_isolate_control()->get_value(), PBD::Controllable::UseGroup);
247 stripable->solo_safe_control()->set_value (!stripable->solo_safe_control()->get_value(), PBD::Controllable::UseGroup);
256 TrackMixLayout::button_left ()
258 p2.access_action ("Editor/select-prev-route");
262 TrackMixLayout::button_right ()
264 p2.access_action ("Editor/select-next-route");
268 TrackMixLayout::simple_control_change (boost::shared_ptr<AutomationControl> ac, Push2::ButtonID bid)
274 Push2::Button* b = p2.button_by_id (bid);
281 if (ac->get_value()) {
282 b->set_color (selection_color);
284 b->set_color (Push2::LED::DarkGray);
286 b->set_state (Push2::LED::OneShot24th);
287 p2.write (b->state_msg());
291 TrackMixLayout::solo_change ()
297 simple_control_change (stripable->solo_control(), Push2::Lower2);
301 TrackMixLayout::mute_change ()
307 simple_control_change (stripable->mute_control(), Push2::Lower1);
311 TrackMixLayout::rec_enable_change ()
317 simple_control_change (stripable->rec_enable_control(), Push2::Lower3);
321 TrackMixLayout::solo_iso_change ()
327 simple_control_change (stripable->solo_isolate_control(), Push2::Lower6);
330 TrackMixLayout::solo_safe_change ()
336 simple_control_change (stripable->solo_safe_control(), Push2::Lower7);
340 TrackMixLayout::monitoring_change ()
346 if (!stripable->monitoring_control()) {
350 Push2::Button* b1 = p2.button_by_id (Push2::Lower4);
351 Push2::Button* b2 = p2.button_by_id (Push2::Lower5);
355 MonitorChoice mc = stripable->monitoring_control()->monitoring_choice ();
359 b1_color = Push2::LED::DarkGray;
360 b2_color = Push2::LED::DarkGray;
363 b1_color = selection_color;
364 b2_color = Push2::LED::DarkGray;
367 b1_color = Push2::LED::DarkGray;
368 b2_color = selection_color;
371 b1_color = selection_color;
372 b2_color = selection_color;
376 b1->set_color (b1_color);
377 b1->set_state (Push2::LED::OneShot24th);
378 p2.write (b1->state_msg());
380 b2->set_color (b2_color);
381 b2->set_state (Push2::LED::OneShot24th);
382 p2.write (b2->state_msg());
386 TrackMixLayout::set_stripable (boost::shared_ptr<Stripable> s)
388 stripable_connections.drop_connections ();
394 stripable->DropReferences.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::drop_stripable, this), &p2);
396 stripable->PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::stripable_property_change, this, _1), &p2);
397 stripable->presentation_info().PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::stripable_property_change, this, _1), &p2);
399 stripable->solo_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::solo_change, this), &p2);
400 stripable->mute_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::mute_change, this), &p2);
401 stripable->solo_isolate_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::solo_iso_change, this), &p2);
402 stripable->solo_safe_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::solo_safe_change, this), &p2);
404 if (stripable->rec_enable_control()) {
405 stripable->rec_enable_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::rec_enable_change, this), &p2);
408 if (stripable->monitoring_control()) {
409 stripable->monitoring_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::monitoring_change, this), &p2);
412 knobs[0]->set_controllable (stripable->gain_control());
413 knobs[1]->set_controllable (stripable->pan_azimuth_control());
414 knobs[1]->add_flag (Push2Knob::ArcToZero);
415 knobs[2]->set_controllable (stripable->pan_width_control());
416 knobs[3]->set_controllable (stripable->trim_control());
417 knobs[3]->add_flag (Push2Knob::ArcToZero);
418 knobs[4]->set_controllable (boost::shared_ptr<AutomationControl>());
419 knobs[5]->set_controllable (boost::shared_ptr<AutomationControl>());
420 knobs[6]->set_controllable (boost::shared_ptr<AutomationControl>());
421 knobs[7]->set_controllable (boost::shared_ptr<AutomationControl>());
427 rec_enable_change ();
430 monitoring_change ();
432 meter->set_meter (stripable->peak_meter ().get());
434 meter->set_meter (0);
439 TrackMixLayout::drop_stripable ()
441 stripable_connections.drop_connections ();
446 TrackMixLayout::name_changed ()
449 /* poor-man's right justification */
451 snprintf (buf, sizeof (buf), "%*s", (int) sizeof (buf) - 1, stripable->name().c_str());
452 name_text->set (buf);
457 TrackMixLayout::color_changed ()
463 Color rgba = stripable->presentation_info().color();
464 selection_color = p2.get_color_index (rgba);
466 name_text->set_color (rgba);
468 for (int n = 0; n < 8; ++n) {
469 knobs[n]->set_text_color (rgba);
470 knobs[n]->set_arc_start_color (rgba);
471 knobs[n]->set_arc_end_color (rgba);
476 TrackMixLayout::stripable_property_change (PropertyChange const& what_changed)
478 if (what_changed.contains (Properties::color)) {
481 if (what_changed.contains (Properties::name)) {
487 TrackMixLayout::strip_vpot (int n, int delta)
489 boost::shared_ptr<Controllable> ac = knobs[n]->controllable();
492 ac->set_value (ac->get_value() + ((2.0/64.0) * delta), PBD::Controllable::UseGroup);
497 TrackMixLayout::strip_vpot_touch (int n, bool touching)
499 boost::shared_ptr<AutomationControl> ac = knobs[n]->controllable();
502 ac->start_touch (session.audible_frame());
504 ac->stop_touch (true, session.audible_frame());
510 TrackMixLayout::update_meters ()
516 meter->update_meters ();