+
+void
+RouteUI::setup_invert_buttons ()
+{
+ /* remove old invert buttons */
+ for (list<BindableToggleButton*>::iterator i = _invert_buttons.begin(); i != _invert_buttons.end(); ++i) {
+ _invert_button_box.remove (**i);
+ }
+
+ _invert_buttons.clear ();
+
+ if (!_route || !_route->input()) {
+ return;
+ }
+
+ uint32_t const N = _route->input()->n_ports().n_audio ();
+
+ uint32_t const to_add = (N <= _max_invert_buttons) ? N : 1;
+
+ for (uint32_t i = 0; i < to_add; ++i) {
+ BindableToggleButton* b = manage (new BindableToggleButton);
+ b->signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &RouteUI::invert_toggled), i, b));
+ b->signal_button_press_event().connect (sigc::mem_fun (*this, &RouteUI::invert_press));
+
+ b->set_name (X_("MixerInvertButton"));
+ if (to_add == 1) {
+ b->add (*manage (new Label (X_("Ø"))));
+ } else {
+ b->add (*manage (new Label (string_compose (X_("Ø%1"), i + 1))));
+ }
+
+ if (N <= 4) {
+ UI::instance()->set_tip (*b, string_compose (_("Left-click to invert (phase reverse) channel %1 of this track. Right-click to show menu."), i + 1));
+ } else {
+ UI::instance()->set_tip (*b, string_compose (_("Left-click to invert (phase reverse) all channels of this track. Right-click to show menu."), i + 1));
+ }
+
+ _invert_buttons.push_back (b);
+ _invert_button_box.pack_start (*b);
+ }
+
+ _invert_button_box.show_all ();
+}
+
+void
+RouteUI::set_invert_button_state ()
+{
+ ++_i_am_the_modifier;
+
+ uint32_t const N = _route->input()->n_ports().n_audio();
+ if (N > _max_invert_buttons) {
+ _invert_buttons.front()->set_active (_route->phase_invert().any());
+ --_i_am_the_modifier;
+ return;
+ }
+
+ int j = 0;
+ for (list<BindableToggleButton*>::iterator i = _invert_buttons.begin(); i != _invert_buttons.end(); ++i, ++j) {
+ (*i)->set_active (_route->phase_invert (j));
+ }
+
+ --_i_am_the_modifier;
+}
+
+void
+RouteUI::invert_toggled (uint32_t i, BindableToggleButton* b)
+{
+ if (_i_am_the_modifier) {
+ return;
+ }
+
+ uint32_t const N = _route->input()->n_ports().n_audio();
+ if (N <= _max_invert_buttons) {
+ _route->set_phase_invert (i, b->get_active ());
+ } else {
+ boost::dynamic_bitset<> p (N);
+ if (b->get_active ()) {
+ p.set ();
+ }
+ _route->set_phase_invert (p);
+ }
+}
+
+bool
+RouteUI::invert_press (GdkEventButton* ev)
+{
+ using namespace Menu_Helpers;
+
+ if (ev->button != 3) {
+ return true;
+ }
+
+ delete _invert_menu;
+ _invert_menu = new Menu;
+ _invert_menu->set_name ("ArdourContextMenu");
+ MenuList& items = _invert_menu->items ();
+
+ uint32_t const N = _route->input()->n_ports().n_audio();
+ for (uint32_t i = 0; i < N; ++i) {
+ items.push_back (CheckMenuElem (string_compose (X_("Ø%1"), i + 1), sigc::bind (sigc::mem_fun (*this, &RouteUI::invert_menu_toggled), i)));
+ CheckMenuItem* e = dynamic_cast<CheckMenuItem*> (&items.back ());
+ ++_i_am_the_modifier;
+ e->set_active (_route->phase_invert (i));
+ --_i_am_the_modifier;
+ }
+
+ _invert_menu->popup (0, ev->time);
+
+ return false;
+}
+
+void
+RouteUI::invert_menu_toggled (uint32_t c)
+{
+ if (_i_am_the_modifier) {
+ return;
+ }
+
+ _route->set_phase_invert (c, !_route->phase_invert (c));
+}