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"
32 #include "temporal/time.h"
33 #include "temporal/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"
58 #include "canvas/types.h"
62 #include "level_meter.h"
65 #include "track_mix.h"
71 #define Rect ArdourCanvas::Rect
74 using namespace ARDOUR;
78 using namespace ArdourSurface;
79 using namespace ArdourCanvas;
81 TrackMixLayout::TrackMixLayout (Push2& p, Session & s, std::string const & name)
82 : Push2Layout (p, s, name)
84 Pango::FontDescription fd ("Sans 10");
86 bg = new ArdourCanvas::Rectangle (this);
87 bg->set (Rect (0, 0, display_width(), display_height()));
88 bg->set_fill_color (p2.get_color (Push2::DarkBackground));
90 upper_line = new Line (this);
91 upper_line->set (Duple (0, 22.5), Duple (display_width(), 22.5));
92 upper_line->set_outline_color (p2.get_color (Push2::LightBackground));
94 for (int n = 0; n < 8; ++n) {
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()), 2));
102 upper_text.push_back (t);
106 t->set_font_description (fd);
107 t->set_color (p2.get_color (Push2::ParameterName));
108 t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 140));
110 lower_text.push_back (t);
114 upper_text[n]->set (_("Track Volume"));
115 lower_text[n]->set (_("Mute"));
118 upper_text[n]->set (_("Track Pan"));
119 lower_text[n]->set (_("Solo"));
122 upper_text[n]->set (_("Track Width"));
123 lower_text[n]->set (_("Rec-enable"));
126 upper_text[n]->set (_("Track Trim"));
127 lower_text[n]->set (_("In"));
130 lower_text[n]->set (_("Disk"));
133 lower_text[n]->set (_("Solo Iso"));
136 lower_text[n]->set (_("Solo Lock"));
139 lower_text[n]->set (_(""));
143 knobs[n] = new Push2Knob (p2, this);
144 knobs[n]->set_position (Duple (60 + (Push2Canvas::inter_button_spacing()*n), 95));
145 knobs[n]->set_radius (25);
148 name_text = new Text (this);
149 name_text->set_font_description (fd);
150 name_text->set_position (Duple (10 + (4*Push2Canvas::inter_button_spacing()), 2));
152 meter = new LevelMeter (p2, this, 300, ArdourCanvas::Meter::Horizontal);
153 meter->set_position (Duple (10 + (4 * Push2Canvas::inter_button_spacing()), 30));
155 Pango::FontDescription fd2 ("Sans 18");
156 bbt_text = new Text (this);
157 bbt_text->set_font_description (fd2);
158 bbt_text->set_color (p2.get_color (Push2::LightBackground));
159 bbt_text->set_position (Duple (10 + (4 * Push2Canvas::inter_button_spacing()), 60));
161 minsec_text = new Text (this);
162 minsec_text->set_font_description (fd2);
163 minsec_text->set_color (p2.get_color (Push2::LightBackground));
164 minsec_text->set_position (Duple (10 + (4 * Push2Canvas::inter_button_spacing()), 90));
167 TrackMixLayout::~TrackMixLayout ()
169 for (int n = 0; n < 8; ++n) {
175 TrackMixLayout::show ()
177 Push2::ButtonID lower_buttons[] = { Push2::Lower1, Push2::Lower2, Push2::Lower3, Push2::Lower4,
178 Push2::Lower5, Push2::Lower6, Push2::Lower7, Push2::Lower8 };
180 for (size_t n = 0; n < sizeof (lower_buttons) / sizeof (lower_buttons[0]); ++n) {
181 boost::shared_ptr<Push2::Button> b = p2.button_by_id (lower_buttons[n]);
182 b->set_color (Push2::LED::DarkGray);
183 b->set_state (Push2::LED::OneShot24th);
184 p2.write (b->state_msg());
193 TrackMixLayout::hide ()
199 TrackMixLayout::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
201 Container::render (area, context);
205 TrackMixLayout::button_upper (uint32_t n)
210 TrackMixLayout::button_lower (uint32_t n)
220 if (stripable->mute_control()) {
221 stripable->mute_control()->set_value (!stripable->mute_control()->get_value(), PBD::Controllable::UseGroup);
225 if (stripable->solo_control()) {
226 stripable->solo_control()->set_value (!stripable->solo_control()->get_value(), PBD::Controllable::UseGroup);
230 if (stripable->rec_enable_control()) {
231 stripable->rec_enable_control()->set_value (!stripable->rec_enable_control()->get_value(), PBD::Controllable::UseGroup);
235 if (stripable->monitor_control()) {
236 mc = stripable->monitoring_control()->monitoring_choice();
239 stripable->monitoring_control()->set_value (MonitorAuto, PBD::Controllable::UseGroup);
242 stripable->monitoring_control()->set_value (MonitorInput, PBD::Controllable::UseGroup);
248 mc = stripable->monitoring_control()->monitoring_choice();
251 stripable->monitoring_control()->set_value (MonitorAuto, PBD::Controllable::UseGroup);
254 stripable->monitoring_control()->set_value (MonitorDisk, PBD::Controllable::UseGroup);
259 if (stripable->solo_isolate_control()) {
260 stripable->solo_isolate_control()->set_value (!stripable->solo_isolate_control()->get_value(), PBD::Controllable::UseGroup);
264 if (stripable->solo_safe_control()) {
265 stripable->solo_safe_control()->set_value (!stripable->solo_safe_control()->get_value(), PBD::Controllable::UseGroup);
275 TrackMixLayout::button_left ()
277 p2.access_action ("Editor/select-prev-route");
281 TrackMixLayout::button_right ()
283 p2.access_action ("Editor/select-next-route");
287 TrackMixLayout::simple_control_change (boost::shared_ptr<AutomationControl> ac, Push2::ButtonID bid)
289 if (!ac || !parent()) {
293 boost::shared_ptr<Push2::Button> b = p2.button_by_id (bid);
299 if (ac->get_value()) {
300 b->set_color (selection_color);
302 b->set_color (Push2::LED::DarkGray);
304 b->set_state (Push2::LED::OneShot24th);
305 p2.write (b->state_msg());
309 TrackMixLayout::solo_mute_change ()
315 boost::shared_ptr<Push2::Button> b = p2.button_by_id (Push2::Lower2);
318 boost::shared_ptr<SoloControl> sc = stripable->solo_control();
321 if (sc->soloed_by_self_or_masters()) {
322 b->set_color (selection_color);
323 b->set_state (Push2::LED::OneShot24th);
324 } else if (sc->soloed_by_others_upstream() || sc->soloed_by_others_downstream()) {
325 b->set_color (selection_color);
326 b->set_state (Push2::LED::Blinking8th);
328 b->set_color (Push2::LED::DarkGray);
329 b->set_state (Push2::LED::OneShot24th);
332 b->set_color (Push2::LED::DarkGray);
333 b->set_state (Push2::LED::OneShot24th);
336 p2.write (b->state_msg());
339 b = p2.button_by_id (Push2::Lower1);
342 boost::shared_ptr<MuteControl> mc = stripable->mute_control();
345 if (mc->muted_by_self_or_masters()) {
346 b->set_color (selection_color);
347 b->set_state (Push2::LED::OneShot24th);
348 } else if (mc->muted_by_others_soloing()) {
349 b->set_color (selection_color);
350 b->set_state (Push2::LED::Blinking8th);
352 b->set_color (Push2::LED::DarkGray);
353 b->set_state (Push2::LED::OneShot24th);
357 b->set_color (Push2::LED::DarkGray);
358 b->set_state (Push2::LED::OneShot24th);
361 p2.write (b->state_msg());
367 TrackMixLayout::rec_enable_change ()
373 simple_control_change (stripable->rec_enable_control(), Push2::Lower3);
377 TrackMixLayout::solo_iso_change ()
383 simple_control_change (stripable->solo_isolate_control(), Push2::Lower6);
386 TrackMixLayout::solo_safe_change ()
392 simple_control_change (stripable->solo_safe_control(), Push2::Lower7);
396 TrackMixLayout::monitoring_change ()
402 if (!stripable->monitoring_control()) {
406 boost::shared_ptr<Push2::Button> b1 = p2.button_by_id (Push2::Lower4);
407 boost::shared_ptr<Push2::Button> b2 = p2.button_by_id (Push2::Lower5);
411 MonitorChoice mc = stripable->monitoring_control()->monitoring_choice ();
415 b1_color = Push2::LED::DarkGray;
416 b2_color = Push2::LED::DarkGray;
419 b1_color = selection_color;
420 b2_color = Push2::LED::DarkGray;
423 b1_color = Push2::LED::DarkGray;
424 b2_color = selection_color;
427 b1_color = selection_color;
428 b2_color = selection_color;
432 b1->set_color (b1_color);
433 b1->set_state (Push2::LED::OneShot24th);
434 p2.write (b1->state_msg());
436 b2->set_color (b2_color);
437 b2->set_state (Push2::LED::OneShot24th);
438 p2.write (b2->state_msg());
442 TrackMixLayout::show_state ()
452 rec_enable_change ();
455 monitoring_change ();
457 meter->set_meter (stripable->peak_meter ().get());
459 meter->set_meter (0);
464 TrackMixLayout::set_stripable (boost::shared_ptr<Stripable> s)
466 stripable_connections.drop_connections ();
472 stripable->DropReferences.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::drop_stripable, this), &p2);
474 stripable->PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::stripable_property_change, this, _1), &p2);
475 stripable->presentation_info().PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::stripable_property_change, this, _1), &p2);
477 stripable->solo_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::solo_mute_change, this), &p2);
478 stripable->mute_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::solo_mute_change, this), &p2);
479 stripable->solo_isolate_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::solo_iso_change, this), &p2);
480 stripable->solo_safe_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::solo_safe_change, this), &p2);
482 if (stripable->rec_enable_control()) {
483 stripable->rec_enable_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::rec_enable_change, this), &p2);
486 if (stripable->monitoring_control()) {
487 stripable->monitoring_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&TrackMixLayout::monitoring_change, this), &p2);
490 knobs[0]->set_controllable (stripable->gain_control());
491 knobs[1]->set_controllable (stripable->pan_azimuth_control());
492 knobs[1]->add_flag (Push2Knob::ArcToZero);
493 knobs[2]->set_controllable (stripable->pan_width_control());
494 knobs[3]->set_controllable (stripable->trim_control());
495 knobs[3]->add_flag (Push2Knob::ArcToZero);
496 knobs[4]->set_controllable (boost::shared_ptr<AutomationControl>());
497 knobs[5]->set_controllable (boost::shared_ptr<AutomationControl>());
498 knobs[6]->set_controllable (boost::shared_ptr<AutomationControl>());
499 knobs[7]->set_controllable (boost::shared_ptr<AutomationControl>());
506 TrackMixLayout::drop_stripable ()
508 stripable_connections.drop_connections ();
513 TrackMixLayout::name_changed ()
517 name_text->set (stripable->name());
522 pos.y = name_text->position().y;
523 pos.x = display_width() - 10 - name_text->width();
525 name_text->set_position (pos);
530 TrackMixLayout::color_changed ()
536 Gtkmm2ext::Color rgba = stripable->presentation_info().color();
537 selection_color = p2.get_color_index (rgba);
539 name_text->set_color (rgba);
541 for (int n = 0; n < 8; ++n) {
542 knobs[n]->set_text_color (rgba);
543 knobs[n]->set_arc_start_color (rgba);
544 knobs[n]->set_arc_end_color (rgba);
549 TrackMixLayout::stripable_property_change (PropertyChange const& what_changed)
551 if (what_changed.contains (Properties::color)) {
554 if (what_changed.contains (Properties::name)) {
560 TrackMixLayout::strip_vpot (int n, int delta)
562 boost::shared_ptr<Controllable> ac = knobs[n]->controllable();
565 ac->set_value (ac->get_value() + ((2.0/64.0) * delta), PBD::Controllable::UseGroup);
570 TrackMixLayout::strip_vpot_touch (int n, bool touching)
572 boost::shared_ptr<AutomationControl> ac = knobs[n]->controllable();
575 ac->start_touch (session.audible_sample());
577 ac->stop_touch (session.audible_sample());
583 TrackMixLayout::update_meters ()
589 meter->update_meters ();
593 TrackMixLayout::update_clocks ()
595 samplepos_t pos = session.audible_sample();
596 bool negative = false;
604 Timecode::BBT_Time BBT = session.tempo_map().bbt_at_sample (pos);
606 #define BBT_BAR_CHAR "|"
609 snprintf (buf, sizeof (buf), "-%03" PRIu32 BBT_BAR_CHAR "%02" PRIu32 BBT_BAR_CHAR "%04" PRIu32,
610 BBT.bars, BBT.beats, BBT.ticks);
612 snprintf (buf, sizeof (buf), " %03" PRIu32 BBT_BAR_CHAR "%02" PRIu32 BBT_BAR_CHAR "%04" PRIu32,
613 BBT.bars, BBT.beats, BBT.ticks);
624 const double sample_rate = session.sample_rate ();
627 hrs = (int) floor (left / (sample_rate * 60.0f * 60.0f));
628 left -= (samplecnt_t) floor (hrs * sample_rate * 60.0f * 60.0f);
629 mins = (int) floor (left / (sample_rate * 60.0f));
630 left -= (samplecnt_t) floor (mins * sample_rate * 60.0f);
631 secs = (int) floor (left / (float) sample_rate);
632 left -= (samplecnt_t) floor ((double)(secs * sample_rate));
633 millisecs = floor (left * 1000.0 / (float) sample_rate);
636 snprintf (buf, sizeof (buf), "-%02" PRId32 ":%02" PRId32 ":%02" PRId32 ".%03" PRId32, hrs, mins, secs, millisecs);
638 snprintf (buf, sizeof (buf), " %02" PRId32 ":%02" PRId32 ":%02" PRId32 ".%03" PRId32, hrs, mins, secs, millisecs);
641 minsec_text->set (buf);