2 * Copyright (C) 2016-2018 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2016-2018 Robin Gareus <robin@gareus.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <cairomm/region.h>
21 #include <pangomm/layout.h>
23 #include "pbd/compose.h"
24 #include "pbd/convert.h"
25 #include "pbd/debug.h"
26 #include "pbd/failed_constructor.h"
27 #include "pbd/file_utils.h"
28 #include "pbd/search_path.h"
29 #include "pbd/enumwriter.h"
31 #include "midi++/parser.h"
33 #include "temporal/time.h"
34 #include "temporal/bbt_time.h"
36 #include "ardour/async_midi_port.h"
37 #include "ardour/audioengine.h"
38 #include "ardour/debug.h"
39 #include "ardour/dsp_filter.h"
40 #include "ardour/filesystem_paths.h"
41 #include "ardour/midiport_manager.h"
42 #include "ardour/midi_track.h"
43 #include "ardour/midi_port.h"
44 #include "ardour/monitor_control.h"
45 #include "ardour/meter.h"
46 #include "ardour/session.h"
47 #include "ardour/solo_isolate_control.h"
48 #include "ardour/solo_safe_control.h"
49 #include "ardour/tempo.h"
51 #include "gtkmm2ext/gui_thread.h"
52 #include "gtkmm2ext/rgb_macros.h"
54 #include "canvas/box.h"
55 #include "canvas/line.h"
56 #include "canvas/meter.h"
57 #include "canvas/rectangle.h"
58 #include "canvas/text.h"
59 #include "canvas/types.h"
63 #include "level_meter.h"
66 #include "track_mix.h"
72 #define Rect ArdourCanvas::Rect
75 using namespace ARDOUR;
79 using namespace ArdourSurface;
80 using namespace ArdourCanvas;
82 TrackMixLayout::TrackMixLayout (Push2& p, Session & s, std::string const & name)
83 : Push2Layout (p, s, name)
85 Pango::FontDescription fd ("Sans 10");
87 bg = new ArdourCanvas::Rectangle (this);
88 bg->set (Rect (0, 0, display_width(), display_height()));
89 bg->set_fill_color (p2.get_color (Push2::DarkBackground));
91 upper_line = new Line (this);
92 upper_line->set (Duple (0, 22.5), Duple (display_width(), 22.5));
93 upper_line->set_outline_color (p2.get_color (Push2::LightBackground));
95 for (int n = 0; n < 8; ++n) {
100 t->set_font_description (fd);
101 t->set_color (p2.get_color (Push2::ParameterName));
102 t->set_position ( Duple (10 + (n*Push2Canvas::inter_button_spacing()), 2));
103 upper_text.push_back (t);
107 t->set_font_description (fd);
108 t->set_color (p2.get_color (Push2::ParameterName));
109 t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 140));
111 lower_text.push_back (t);
115 upper_text[n]->set (_("Track Volume"));
116 lower_text[n]->set (_("Mute"));
119 upper_text[n]->set (_("Track Pan"));
120 lower_text[n]->set (_("Solo"));
123 upper_text[n]->set (_("Track Width"));
124 lower_text[n]->set (_("Rec-enable"));
127 upper_text[n]->set (_("Track Trim"));
128 lower_text[n]->set (_("In"));
131 lower_text[n]->set (_("Disk"));
134 lower_text[n]->set (_("Solo Iso"));
137 lower_text[n]->set (_("Solo Lock"));
140 lower_text[n]->set (_(""));
144 knobs[n] = new Push2Knob (p2, this);
145 knobs[n]->set_position (Duple (60 + (Push2Canvas::inter_button_spacing()*n), 95));
146 knobs[n]->set_radius (25);
149 name_text = new Text (this);
150 name_text->set_font_description (fd);
151 name_text->set_position (Duple (10 + (4*Push2Canvas::inter_button_spacing()), 2));
153 meter = new LevelMeter (p2, this, 300, ArdourCanvas::Meter::Horizontal);
154 meter->set_position (Duple (10 + (4 * Push2Canvas::inter_button_spacing()), 30));
156 Pango::FontDescription fd2 ("Sans 18");
157 bbt_text = new Text (this);
158 bbt_text->set_font_description (fd2);
159 bbt_text->set_color (p2.get_color (Push2::LightBackground));
160 bbt_text->set_position (Duple (10 + (4 * Push2Canvas::inter_button_spacing()), 60));
162 minsec_text = new Text (this);
163 minsec_text->set_font_description (fd2);
164 minsec_text->set_color (p2.get_color (Push2::LightBackground));
165 minsec_text->set_position (Duple (10 + (4 * Push2Canvas::inter_button_spacing()), 90));
168 TrackMixLayout::~TrackMixLayout ()
170 for (int n = 0; n < 8; ++n) {
176 TrackMixLayout::show ()
178 Push2::ButtonID lower_buttons[] = { Push2::Lower1, Push2::Lower2, Push2::Lower3, Push2::Lower4,
179 Push2::Lower5, Push2::Lower6, Push2::Lower7, Push2::Lower8 };
181 for (size_t n = 0; n < sizeof (lower_buttons) / sizeof (lower_buttons[0]); ++n) {
182 boost::shared_ptr<Push2::Button> b = p2.button_by_id (lower_buttons[n]);
183 b->set_color (Push2::LED::DarkGray);
184 b->set_state (Push2::LED::OneShot24th);
185 p2.write (b->state_msg());
194 TrackMixLayout::hide ()
200 TrackMixLayout::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
202 Container::render (area, context);
206 TrackMixLayout::button_upper (uint32_t n)
211 TrackMixLayout::button_lower (uint32_t n)
221 if (stripable->mute_control()) {
222 stripable->mute_control()->set_value (!stripable->mute_control()->get_value(), PBD::Controllable::UseGroup);
226 if (stripable->solo_control()) {
227 stripable->solo_control()->set_value (!stripable->solo_control()->get_value(), PBD::Controllable::UseGroup);
231 if (stripable->rec_enable_control()) {
232 stripable->rec_enable_control()->set_value (!stripable->rec_enable_control()->get_value(), PBD::Controllable::UseGroup);
236 if (stripable->monitor_control()) {
237 mc = stripable->monitoring_control()->monitoring_choice();
240 stripable->monitoring_control()->set_value (MonitorAuto, PBD::Controllable::UseGroup);
243 stripable->monitoring_control()->set_value (MonitorInput, PBD::Controllable::UseGroup);
249 mc = stripable->monitoring_control()->monitoring_choice();
252 stripable->monitoring_control()->set_value (MonitorAuto, PBD::Controllable::UseGroup);
255 stripable->monitoring_control()->set_value (MonitorDisk, PBD::Controllable::UseGroup);
260 if (stripable->solo_isolate_control()) {
261 stripable->solo_isolate_control()->set_value (!stripable->solo_isolate_control()->get_value(), PBD::Controllable::UseGroup);
265 if (stripable->solo_safe_control()) {
266 stripable->solo_safe_control()->set_value (!stripable->solo_safe_control()->get_value(), PBD::Controllable::UseGroup);
276 TrackMixLayout::button_left ()
278 p2.access_action ("Editor/select-prev-route");
282 TrackMixLayout::button_right ()
284 p2.access_action ("Editor/select-next-route");
288 TrackMixLayout::simple_control_change (boost::shared_ptr<AutomationControl> ac, Push2::ButtonID bid)
290 if (!ac || !parent()) {
294 boost::shared_ptr<Push2::Button> b = p2.button_by_id (bid);
300 if (ac->get_value()) {
301 b->set_color (selection_color);
303 b->set_color (Push2::LED::DarkGray);
305 b->set_state (Push2::LED::OneShot24th);
306 p2.write (b->state_msg());
310 TrackMixLayout::solo_mute_change ()
316 boost::shared_ptr<Push2::Button> b = p2.button_by_id (Push2::Lower2);
319 boost::shared_ptr<SoloControl> sc = stripable->solo_control();
322 if (sc->soloed_by_self_or_masters()) {
323 b->set_color (selection_color);
324 b->set_state (Push2::LED::OneShot24th);
325 } else if (sc->soloed_by_others_upstream() || sc->soloed_by_others_downstream()) {
326 b->set_color (selection_color);
327 b->set_state (Push2::LED::Blinking8th);
329 b->set_color (Push2::LED::DarkGray);
330 b->set_state (Push2::LED::OneShot24th);
333 b->set_color (Push2::LED::DarkGray);
334 b->set_state (Push2::LED::OneShot24th);
337 p2.write (b->state_msg());
340 b = p2.button_by_id (Push2::Lower1);
343 boost::shared_ptr<MuteControl> mc = stripable->mute_control();
346 if (mc->muted_by_self_or_masters()) {
347 b->set_color (selection_color);
348 b->set_state (Push2::LED::OneShot24th);
349 } else if (mc->muted_by_others_soloing()) {
350 b->set_color (selection_color);
351 b->set_state (Push2::LED::Blinking8th);
353 b->set_color (Push2::LED::DarkGray);
354 b->set_state (Push2::LED::OneShot24th);
358 b->set_color (Push2::LED::DarkGray);
359 b->set_state (Push2::LED::OneShot24th);
362 p2.write (b->state_msg());
368 TrackMixLayout::rec_enable_change ()
374 simple_control_change (stripable->rec_enable_control(), Push2::Lower3);
378 TrackMixLayout::solo_iso_change ()
384 simple_control_change (stripable->solo_isolate_control(), Push2::Lower6);
387 TrackMixLayout::solo_safe_change ()
393 simple_control_change (stripable->solo_safe_control(), Push2::Lower7);
397 TrackMixLayout::monitoring_change ()
403 if (!stripable->monitoring_control()) {
407 boost::shared_ptr<Push2::Button> b1 = p2.button_by_id (Push2::Lower4);
408 boost::shared_ptr<Push2::Button> b2 = p2.button_by_id (Push2::Lower5);
412 MonitorChoice mc = stripable->monitoring_control()->monitoring_choice ();
416 b1_color = Push2::LED::DarkGray;
417 b2_color = Push2::LED::DarkGray;
420 b1_color = selection_color;
421 b2_color = Push2::LED::DarkGray;
424 b1_color = Push2::LED::DarkGray;
425 b2_color = selection_color;
428 b1_color = selection_color;
429 b2_color = selection_color;
433 b1->set_color (b1_color);
434 b1->set_state (Push2::LED::OneShot24th);
435 p2.write (b1->state_msg());
437 b2->set_color (b2_color);
438 b2->set_state (Push2::LED::OneShot24th);
439 p2.write (b2->state_msg());
443 TrackMixLayout::show_state ()
453 rec_enable_change ();
456 monitoring_change ();
458 meter->set_meter (stripable->peak_meter ().get());
460 meter->set_meter (0);
465 TrackMixLayout::set_stripable (boost::shared_ptr<Stripable> s)
467 stripable_connections.drop_connections ();
473 stripable->DropReferences.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::drop_stripable, this), &p2);
475 stripable->PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::stripable_property_change, this, _1), &p2);
476 stripable->presentation_info().PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::stripable_property_change, this, _1), &p2);
478 stripable->solo_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::solo_mute_change, this), &p2);
479 stripable->mute_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::solo_mute_change, this), &p2);
480 stripable->solo_isolate_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::solo_iso_change, this), &p2);
481 stripable->solo_safe_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::solo_safe_change, this), &p2);
483 if (stripable->rec_enable_control()) {
484 stripable->rec_enable_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::rec_enable_change, this), &p2);
487 if (stripable->monitoring_control()) {
488 stripable->monitoring_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::monitoring_change, this), &p2);
491 knobs[0]->set_controllable (stripable->gain_control());
492 knobs[1]->set_controllable (stripable->pan_azimuth_control());
493 knobs[1]->add_flag (Push2Knob::ArcToZero);
494 knobs[2]->set_controllable (stripable->pan_width_control());
495 knobs[3]->set_controllable (stripable->trim_control());
496 knobs[3]->add_flag (Push2Knob::ArcToZero);
497 knobs[4]->set_controllable (boost::shared_ptr<AutomationControl>());
498 knobs[5]->set_controllable (boost::shared_ptr<AutomationControl>());
499 knobs[6]->set_controllable (boost::shared_ptr<AutomationControl>());
500 knobs[7]->set_controllable (boost::shared_ptr<AutomationControl>());
507 TrackMixLayout::drop_stripable ()
509 stripable_connections.drop_connections ();
514 TrackMixLayout::name_changed ()
518 name_text->set (stripable->name());
523 pos.y = name_text->position().y;
524 pos.x = display_width() - 10 - name_text->width();
526 name_text->set_position (pos);
531 TrackMixLayout::color_changed ()
537 Gtkmm2ext::Color rgba = stripable->presentation_info().color();
538 selection_color = p2.get_color_index (rgba);
540 name_text->set_color (rgba);
542 for (int n = 0; n < 8; ++n) {
543 knobs[n]->set_text_color (rgba);
544 knobs[n]->set_arc_start_color (rgba);
545 knobs[n]->set_arc_end_color (rgba);
550 TrackMixLayout::stripable_property_change (PropertyChange const& what_changed)
552 if (what_changed.contains (Properties::color)) {
555 if (what_changed.contains (Properties::name)) {
561 TrackMixLayout::strip_vpot (int n, int delta)
563 boost::shared_ptr<Controllable> ac = knobs[n]->controllable();
566 ac->set_value (ac->get_value() + ((2.0/64.0) * delta), PBD::Controllable::UseGroup);
571 TrackMixLayout::strip_vpot_touch (int n, bool touching)
573 boost::shared_ptr<AutomationControl> ac = knobs[n]->controllable();
576 ac->start_touch (session.audible_sample());
578 ac->stop_touch (session.audible_sample());
584 TrackMixLayout::update_meters ()
590 meter->update_meters ();
594 TrackMixLayout::update_clocks ()
596 samplepos_t pos = session.audible_sample();
597 bool negative = false;
605 Timecode::BBT_Time BBT = session.tempo_map().bbt_at_sample (pos);
607 #define BBT_BAR_CHAR "|"
610 snprintf (buf, sizeof (buf), "-%03" PRIu32 BBT_BAR_CHAR "%02" PRIu32 BBT_BAR_CHAR "%04" PRIu32,
611 BBT.bars, BBT.beats, BBT.ticks);
613 snprintf (buf, sizeof (buf), " %03" PRIu32 BBT_BAR_CHAR "%02" PRIu32 BBT_BAR_CHAR "%04" PRIu32,
614 BBT.bars, BBT.beats, BBT.ticks);
625 const double sample_rate = session.sample_rate ();
628 hrs = (int) floor (left / (sample_rate * 60.0f * 60.0f));
629 left -= (samplecnt_t) floor (hrs * sample_rate * 60.0f * 60.0f);
630 mins = (int) floor (left / (sample_rate * 60.0f));
631 left -= (samplecnt_t) floor (mins * sample_rate * 60.0f);
632 secs = (int) floor (left / (float) sample_rate);
633 left -= (samplecnt_t) floor ((double)(secs * sample_rate));
634 millisecs = floor (left * 1000.0 / (float) sample_rate);
637 snprintf (buf, sizeof (buf), "-%02" PRId32 ":%02" PRId32 ":%02" PRId32 ".%03" PRId32, hrs, mins, secs, millisecs);
639 snprintf (buf, sizeof (buf), " %02" PRId32 ":%02" PRId32 ":%02" PRId32 ".%03" PRId32, hrs, mins, secs, millisecs);
642 minsec_text->set (buf);