Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <cairomm/region.h>
#include <pangomm/layout.h>
#include "pbd/compose.h"
#include "pbd/enumwriter.h"
#include "midi++/parser.h"
-#include "timecode/time.h"
-#include "timecode/bbt_time.h"
+#include "temporal/time.h"
+#include "temporal/bbt_time.h"
#include "ardour/async_midi_port.h"
#include "ardour/audioengine.h"
#include "ardour/midi_port.h"
#include "ardour/session.h"
#include "ardour/tempo.h"
+#include "ardour/utils.h"
#include "ardour/vca_manager.h"
-#include "canvas/colors.h"
+#include "gtkmm2ext/colors.h"
+#include "canvas/line.h"
+#include "canvas/rectangle.h"
+#include "canvas/text.h"
#include "gtkmm2ext/gui_thread.h"
-#include "mix.h"
+#include "canvas.h"
#include "knob.h"
+#include "level_meter.h"
+#include "mix.h"
#include "push2.h"
#include "utils.h"
#include "pbd/i18n.h"
+#ifdef __APPLE__
+#define Rect ArdourCanvas::Rect
+#endif
+
using namespace ARDOUR;
using namespace std;
using namespace PBD;
using namespace Glib;
using namespace ArdourSurface;
+using namespace Gtkmm2ext;
+using namespace ArdourCanvas;
-MixLayout::MixLayout (Push2& p, Session& s, Cairo::RefPtr<Cairo::Context> context)
- : Push2Layout (p, s)
- , _dirty (true)
+MixLayout::MixLayout (Push2& p, Session & s, std::string const & name)
+ : Push2Layout (p, s, name)
, bank_start (0)
, vpot_mode (Volume)
{
+ /* background */
+
+ bg = new ArdourCanvas::Rectangle (this);
+ bg->set (Rect (0, 0, display_width(), display_height()));
+ bg->set_fill_color (p2.get_color (Push2::DarkBackground));
+
+ /* upper line */
+
+ upper_line = new Line (this);
+ upper_line->set (Duple (0, 22.5), Duple (display_width(), 22.5));
+ upper_line->set_outline_color (p2.get_color (Push2::LightBackground));
+
Pango::FontDescription fd2 ("Sans 10");
+
for (int n = 0; n < 8; ++n) {
- upper_layout[n] = Pango::Layout::create (context);
- upper_layout[n]->set_font_description (fd2);
+
+ /* background for text labels for knob function */
+
+ ArdourCanvas::Rectangle* r = new ArdourCanvas::Rectangle (this);
+ Coord x0 = 10 + (n*Push2Canvas::inter_button_spacing()) - 5;
+ r->set (Rect (x0, 2, x0 + Push2Canvas::inter_button_spacing(), 2 + 21));
+ upper_backgrounds.push_back (r);
+
+ r = new ArdourCanvas::Rectangle (this);
+ r->set (Rect (x0, 137, x0 + Push2Canvas::inter_button_spacing(), 137 + 21));
+ lower_backgrounds.push_back (r);
+
+ /* text labels for knob function*/
+
+ Text* t = new Text (this);
+ t->set_font_description (fd2);
+ t->set_color (p2.get_color (Push2::ParameterName));
+ t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 5));
string txt;
switch (n) {
txt = _("E Sends");
break;
}
- upper_layout[n]->set_text (txt);
- }
+ t->set (txt);
+ upper_text.push_back (t);
- Pango::FontDescription fd3 ("Sans 10");
- for (int n = 0; n < 8; ++n) {
- lower_layout[n] = Pango::Layout::create (context);
- lower_layout[n]->set_font_description (fd3);
- }
+ /* GainMeters */
+
+ gain_meter[n] = new GainMeter (this, p2);
+ gain_meter[n]->set_position (Duple (40 + (n * Push2Canvas::inter_button_spacing()), 95));
+
+ /* stripable names */
+
+ t = new Text (this);
+ t->set_font_description (fd2);
+ t->set_color (p2.get_color (Push2::ParameterName));
+ t->set_position (Duple (10 + (n*Push2Canvas::inter_button_spacing()), 140));
+ lower_text.push_back (t);
- for (int n = 0; n < 8; ++n) {
- knobs[n] = new Push2Knob (p2, context);
- knobs[n]->set_position (60 + (n*120), 95);
- knobs[n]->set_radius (25);
}
mode_button = p2.button_by_id (Push2::Upper1);
MixLayout::~MixLayout ()
{
- for (int n = 0; n < 8; ++n) {
- delete knobs[n];
- }
+ // Item destructor deletes all children
}
void
-MixLayout::on_show ()
+MixLayout::show ()
{
- mode_button->set_color (Push2::LED::White);
- mode_button->set_state (Push2::LED::OneShot24th);
- p2.write (mode_button->state_msg());
+ Push2::ButtonID upper_buttons[] = { Push2::Upper1, Push2::Upper2, Push2::Upper3, Push2::Upper4,
+ Push2::Upper5, Push2::Upper6, Push2::Upper7, Push2::Upper8 };
- switch_bank (bank_start);
-}
-bool
-MixLayout::redraw (Cairo::RefPtr<Cairo::Context> context, bool force) const
-{
- bool children_dirty = false;
+ for (size_t n = 0; n < sizeof (upper_buttons) / sizeof (upper_buttons[0]); ++n) {
+ Push2::Button* b = p2.button_by_id (upper_buttons[n]);
- for (int n = 0; n < 8; ++n) {
- if (knobs[n]->dirty()) {
- children_dirty = true;
- break;
- }
- }
-
- for (int n = 0; n < 8; ++n) {
- if (stripable[n]) {
-
- string shortname = short_version (stripable[n]->name(), 10);
- string text;
- boost::shared_ptr<AutomationControl> ac;
- ac = stripable[n]->solo_control();
- if (ac && ac->get_value()) {
- text += "* ";
- }
- boost::shared_ptr<MuteControl> mc;
- mc = stripable[n]->mute_control ();
- if (mc) {
- if (mc->muted_by_self_or_masters()) {
- text += "! ";
- } else if (mc->muted_by_others_soloing()) {
- text += "- "; // it would be nice to use Unicode mute"\uD83D\uDD07 ";
- }
- }
- text += shortname;
-
- if (text != lower_layout[n]->get_text()) {
- lower_layout[n]->set_text (text);
- children_dirty = true;
- }
- }
- }
-
- if (!children_dirty && !_dirty && !force) {
- return false;
- }
-
- set_source_rgb (context, p2.get_color (Push2::DarkBackground));
- context->rectangle (0, 0, p2.cols, p2.rows);
- context->fill ();
-
- set_source_rgb (context, p2.get_color (Push2::ParameterName));
-
- for (int n = 0; n < 8; ++n) {
-
- if (upper_layout[n]->get_text().empty()) {
- continue;
- }
-
- /* Draw highlight box */
-
- uint32_t color = p2.get_color (Push2::ParameterName);
-
- if (n == (int) vpot_mode) {
- set_source_rgb (context, color);
- context->rectangle (10 + (n*120) - 5, 2, 120, 21);
- context->fill();
- set_source_rgb (context, ArdourCanvas::contrasting_text_color (color));
- } else {
- set_source_rgb (context, color);
+ if (b != mode_button) {
+ b->set_color (Push2::LED::DarkGray);
+ } else {
+ b->set_color (Push2::LED::White);
}
-
- context->move_to (10 + (n*120), 2);
- upper_layout[n]->update_from_cairo_context (context);
- upper_layout[n]->show_in_cairo_context (context);
- }
-
- context->move_to (0, 22.5);
- context->line_to (p2.cols, 22.5);
- context->set_line_width (1.0);
- context->stroke ();
-
- for (int n = 0; n < 8; ++n) {
- knobs[n]->redraw (context, force);
+ b->set_state (Push2::LED::OneShot24th);
+ p2.write (b->state_msg());
}
- for (int n = 0; n < 8; ++n) {
-
- if (lower_layout[n]->get_text().empty()) {
- continue;
- }
-
- if (stripable[n]) {
- uint32_t color = stripable[n]->presentation_info().color();
-
- if (stripable[n]->presentation_info().selected()) {
- set_source_rgb (context, color);
- context->rectangle (10 + (n*120) - 5, 137, 120, 21);
- context->fill();
- set_source_rgb (context, ArdourCanvas::contrasting_text_color (color));
- } else {
- set_source_rgb (context, color);
- }
-
- context->move_to (10 + (n*120), 140);
- lower_layout[n]->update_from_cairo_context (context);
- lower_layout[n]->show_in_cairo_context (context);
- }
- }
+ switch_bank (bank_start);
- _dirty = false;
+ Container::show ();
+}
- return true;
+void
+MixLayout::render (Rect const& area, Cairo::RefPtr<Cairo::Context> context) const
+{
+ Container::render (area, context);
}
void
mode_button->set_state (Push2::LED::OneShot24th);
p2.write (mode_button->state_msg());
+ for (int s = 0; s < 8; ++s) {
+ upper_backgrounds[s]->hide ();
+ upper_text[s]->set_color (p2.get_color (Push2::ParameterName));
+ }
+
+ uint32_t n = 0;
+
boost::shared_ptr<AutomationControl> ac;
switch (vpot_mode) {
case Volume:
for (int s = 0; s < 8; ++s) {
if (stripable[s]) {
- knobs[s]->set_controllable (stripable[s]->gain_control());
+ gain_meter[s]->knob->set_controllable (stripable[s]->gain_control());
+ boost::shared_ptr<PeakMeter> pm = stripable[s]->peak_meter();
+ if (pm) {
+ gain_meter[s]->meter->set_meter (pm.get());
+ } else {
+ gain_meter[s]->meter->set_meter (0);
+ }
} else {
- knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
+ gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
+ gain_meter[s]->meter->set_meter (0);
}
- knobs[s]->remove_flag (Push2Knob::ArcToZero);
+ gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
+ gain_meter[s]->meter->show ();
}
+ n = 0;
break;
case PanAzimuth:
for (int s = 0; s < 8; ++s) {
if (stripable[s]) {
- knobs[s]->set_controllable (stripable[s]->pan_azimuth_control());
- knobs[s]->add_flag (Push2Knob::ArcToZero);
+ gain_meter[s]->knob->set_controllable (stripable[s]->pan_azimuth_control());
+ gain_meter[s]->knob->add_flag (Push2Knob::ArcToZero);
} else {
- knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
+ gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
}
+ gain_meter[s]->meter->hide ();
}
+ n = 1;
break;
case PanWidth:
for (int s = 0; s < 8; ++s) {
if (stripable[s]) {
- knobs[s]->set_controllable (stripable[s]->pan_width_control());
+ gain_meter[s]->knob->set_controllable (stripable[s]->pan_width_control());
} else {
- knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
+ gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
}
- knobs[s]->remove_flag (Push2Knob::ArcToZero);
+ gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
+ gain_meter[s]->meter->hide ();
}
+ n = 2;
break;
case Send1:
for (int s = 0; s < 8; ++s) {
if (stripable[s]) {
- knobs[s]->set_controllable (stripable[s]->send_level_controllable (0));
+ gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (0));
} else {
- knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
+ gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
}
- knobs[s]->remove_flag (Push2Knob::ArcToZero);
+ gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
+ gain_meter[s]->meter->hide ();
}
+ n = 3;
break;
case Send2:
for (int s = 0; s < 8; ++s) {
if (stripable[s]) {
- knobs[s]->set_controllable (stripable[s]->send_level_controllable (1));
+ gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (1));
} else {
- knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
+ gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
}
- knobs[s]->remove_flag (Push2Knob::ArcToZero);
+ gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
+ gain_meter[s]->meter->hide ();
}
+ n = 4;
break;
case Send3:
for (int s = 0; s < 8; ++s) {
if (stripable[s]) {
- knobs[s]->set_controllable (stripable[s]->send_level_controllable (2));
+ gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (2));
} else {
- knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
+ gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
}
- knobs[s]->remove_flag (Push2Knob::ArcToZero);
+ gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
+ gain_meter[s]->meter->hide ();
}
+ n = 5;
break;
case Send4:
for (int s = 0; s < 8; ++s) {
if (stripable[s]) {
- knobs[s]->set_controllable (stripable[s]->send_level_controllable (3));
+ gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (3));
} else {
- knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
+ gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
}
- knobs[s]->remove_flag (Push2Knob::ArcToZero);
+ gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
+ gain_meter[s]->meter->hide ();
}
+ n = 6;
break;
case Send5:
for (int s = 0; s < 8; ++s) {
if (stripable[s]) {
- knobs[s]->set_controllable (stripable[s]->send_level_controllable (4));
+ gain_meter[s]->knob->set_controllable (stripable[s]->send_level_controllable (4));
} else {
- knobs[s]->set_controllable (boost::shared_ptr<AutomationControl>());
+ gain_meter[s]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
}
- knobs[s]->remove_flag (Push2Knob::ArcToZero);
+ gain_meter[s]->knob->remove_flag (Push2Knob::ArcToZero);
+ gain_meter[s]->meter->hide ();
}
+ n = 7;
break;
default:
break;
}
- _dirty = true;
+ upper_backgrounds[n]->set_fill_color (p2.get_color (Push2::ParameterName));
+ upper_backgrounds[n]->set_outline_color (p2.get_color (Push2::ParameterName));
+ upper_backgrounds[n]->show ();
+ upper_text[n]->set_color (contrasting_text_color (p2.get_color (Push2::ParameterName)));
}
void
if (s) {
boost::shared_ptr<AutomationControl> ac = s->solo_control();
if (ac) {
- ac->set_value (!ac->get_value(), PBD::Controllable::UseGroup);
+ session.set_control (ac, !ac->get_value(), PBD::Controllable::UseGroup);
}
}
}
void
MixLayout::strip_vpot (int n, int delta)
{
- boost::shared_ptr<Controllable> ac = knobs[n]->controllable();
+ boost::shared_ptr<Controllable> ac = gain_meter[n]->knob->controllable();
if (ac) {
- ac->set_value (ac->get_value() + ((2.0/64.0) * delta), PBD::Controllable::UseGroup);
+ ac->set_value (ac->interface_to_internal (
+ min (ac->upper(), max (ac->lower(), ac->internal_to_interface (ac->get_value()) + (delta/256.0)))),
+ PBD::Controllable::UseGroup);
}
}
boost::shared_ptr<AutomationControl> ac = stripable[n]->gain_control();
if (ac) {
if (touching) {
- ac->start_touch (session.audible_frame());
+ ac->start_touch (session.audible_sample());
} else {
- ac->stop_touch (true, session.audible_frame());
+ ac->stop_touch (session.audible_sample());
}
}
}
}
void
-MixLayout::stripable_property_change (PropertyChange const& what_changed, int which)
+MixLayout::stripable_property_change (PropertyChange const& what_changed, uint32_t which)
{
+ if (what_changed.contains (Properties::color)) {
+ lower_backgrounds[which]->set_fill_color (stripable[which]->presentation_info().color());
+
+ if (stripable[which]->is_selected()) {
+ lower_text[which]->set_fill_color (contrasting_text_color (stripable[which]->presentation_info().color()));
+ /* might not be a MIDI track, in which case this will
+ do nothing
+ */
+ p2.update_selection_color ();
+ }
+ }
+
+ if (what_changed.contains (Properties::hidden)) {
+ switch_bank (bank_start);
+ }
+
if (what_changed.contains (Properties::selected)) {
+
if (!stripable[which]) {
return;
}
- /* cancel string, which will cause a redraw on the next update
- * cycle. The redraw will reflect selected status
- */
+ if (stripable[which]->is_selected()) {
+ show_selection (which);
+ } else {
+ hide_selection (which);
+ }
+ }
+
+}
+
+void
+MixLayout::show_selection (uint32_t n)
+{
+ lower_backgrounds[n]->show ();
+ lower_backgrounds[n]->set_fill_color (stripable[n]->presentation_info().color());
+ lower_text[n]->set_color (contrasting_text_color (lower_backgrounds[n]->fill_color()));
+}
- lower_layout[which]->set_text (string());
+void
+MixLayout::hide_selection (uint32_t n)
+{
+ lower_backgrounds[n]->hide ();
+ if (stripable[n]) {
+ lower_text[n]->set_color (stripable[n]->presentation_info().color());
}
}
+void
+MixLayout::solo_changed (uint32_t n)
+{
+ solo_mute_changed (n);
+}
+
+void
+MixLayout::mute_changed (uint32_t n)
+{
+ solo_mute_changed (n);
+}
+
+void
+MixLayout::solo_mute_changed (uint32_t n)
+{
+ string shortname = short_version (stripable[n]->name(), 10);
+ string text;
+ boost::shared_ptr<AutomationControl> ac;
+ ac = stripable[n]->solo_control();
+ if (ac && ac->get_value()) {
+ text += "* ";
+ }
+ boost::shared_ptr<MuteControl> mc;
+ mc = stripable[n]->mute_control ();
+ if (mc) {
+ if (mc->muted_by_self_or_masters()) {
+ text += "! ";
+ } else if (mc->muted_by_others_soloing()) {
+ text += "- "; // it would be nice to use Unicode mute"\uD83D\uDD07 ";
+ }
+ }
+ text += shortname;
+ lower_text[n]->set (text);
+}
+
void
MixLayout::switch_bank (uint32_t base)
{
/* work backwards so we can tell if we should actually switch banks */
boost::shared_ptr<Stripable> s[8];
- uint32_t old_empty = 0;
- uint32_t new_empty = 0;
+ uint32_t different = 0;
for (int n = 0; n < 8; ++n) {
- if (!stripable[n]) {
- old_empty++;
- }
s[n] = session.get_remote_nth_stripable (base+n, PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::VCA));
- if (!s[n]) {
- new_empty++;
+ if (s[n] != stripable[n]) {
+ different++;
}
}
- if ((new_empty != 0) && (new_empty >= old_empty)) {
- /* some missing strips; new bank the same or more empty stripables than the old one, do
- nothing since we had already reached the end.
- */
+ if (!s[0]) {
+ /* not even the first stripable exists, do nothing */
+ for (int n = 0; n < 8; ++n) {
+ stripable[n].reset ();
+ gain_meter[n]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
+ gain_meter[n]->meter->set_meter (0);
+ }
return;
}
bank_start = base;
for (int n = 0; n < 8; ++n) {
+
if (!stripable[n]) {
- continue;
- }
+ lower_text[n]->hide ();
+ hide_selection (n);
+ gain_meter[n]->knob->set_controllable (boost::shared_ptr<AutomationControl>());
+ gain_meter[n]->meter->set_meter (0);
+ } else {
+
+ lower_text[n]->show ();
+
+ /* stripable goes away? refill the bank, starting at the same point */
+
+ stripable[n]->DropReferences.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::switch_bank, this, bank_start), &p2);
+ stripable[n]->presentation_info().PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::stripable_property_change, this, _1, n), &p2);
+ stripable[n]->solo_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::solo_changed, this, n), &p2);
+ stripable[n]->mute_control()->Changed.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::mute_changed, this, n), &p2);
+
+ if (stripable[n]->is_selected()) {
+ show_selection (n);
+ } else {
+ hide_selection (n);
+ }
- /* stripable goes away? refill the bank, starting at the same point */
+ /* this will set lower text to the correct value (basically
+ the stripable name)
+ */
+
+ solo_mute_changed (n);
+
+ gain_meter[n]->knob->set_text_color (stripable[n]->presentation_info().color());
+ gain_meter[n]->knob->set_arc_start_color (stripable[n]->presentation_info().color());
+ gain_meter[n]->knob->set_arc_end_color (stripable[n]->presentation_info().color());
+ }
- stripable[n]->DropReferences.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::switch_bank, this, bank_start), &p2);
- stripable[n]->presentation_info().PropertyChanged.connect (stripable_connections, invalidator (*this), boost::bind (&MixLayout::stripable_property_change, this, _1, n), &p2);
Push2::Button* b;
break;
}
- b->set_color (p2.get_color_index (stripable[n]->presentation_info().color()));
+ if (stripable[n]) {
+ b->set_color (p2.get_color_index (stripable[n]->presentation_info().color()));
+ } else {
+ b->set_color (Push2::LED::Black);
+ }
+
b->set_state (Push2::LED::OneShot24th);
p2.write (b->state_msg());
-
- knobs[n]->set_text_color (stripable[n]->presentation_info().color());
- knobs[n]->set_arc_start_color (stripable[n]->presentation_info().color());
- knobs[n]->set_arc_end_color (stripable[n]->presentation_info().color());
}
show_vpot_mode ();
for (int n = 0; n < 8; ++n) {
if (stripable[n]) {
- if (stripable[n]->presentation_info().selected()) {
+ if (stripable[n]->is_selected()) {
selected = n;
break;
}
} else {
if (p2.modifier_state() & Push2::ModShift) {
- std::cerr << "select prev\n";
/* select prev */
if (selected == 0) {
} else {
- std::cerr << "select next\n";
/* select next */
if (selected == 7) {
/* reload current bank */
switch_bank (bank_start);
}
+
+void
+MixLayout::button_down ()
+{
+ p2.scroll_dn_1_track ();
+}
+
+void
+MixLayout::button_up ()
+{
+ p2.scroll_up_1_track ();
+}
+
+void
+MixLayout::update_meters ()
+{
+ if (vpot_mode != Volume) {
+ return;
+ }
+
+ for (uint32_t n = 0; n < 8; ++n) {
+ gain_meter[n]->meter->update_meters ();
+ }
+}
+
+MixLayout::GainMeter::GainMeter (Item* parent, Push2& p2)
+ : Container (parent)
+{
+ knob = new Push2Knob (p2, this);
+ knob->set_radius (25);
+ /* leave position at (0,0) */
+
+ meter = new LevelMeter (p2, this, 90, ArdourCanvas::Meter::Vertical);
+ meter->set_position (Duple (40, -60));
+}