extend strict-i/o to include route outputs.
[ardour.git] / gtk2_ardour / processor_box.cc
index 9d5fbaf8d378e84bccb824de6648699ceddeefdb..03492d7c84f48536f37fcc5fb081f9a4d096f72b 100644 (file)
@@ -147,6 +147,8 @@ ProcessorEntry::ProcessorEntry (ProcessorBox* parent, boost::shared_ptr<Processo
        , _width (w)
        , input_icon(true)
        , output_icon(false)
+       , routing_icon(true)
+       , output_routing_icon(false)
        , _plugin_display(0)
 {
        _vbox.show ();
@@ -192,17 +194,21 @@ ProcessorEntry::ProcessorEntry (ProcessorBox* parent, boost::shared_ptr<Processo
                                _plugin_display->show ();
                        }
                }
+               _vbox.pack_end (output_routing_icon);
                _vbox.pack_end (output_icon);
 
                _button.set_active (_processor->active());
 
-               routing_icon.set_no_show_all(true);
                input_icon.set_no_show_all(true);
+               routing_icon.set_no_show_all(true);
+               output_icon.set_no_show_all(true);
+               output_routing_icon.set_no_show_all(true);
 
                _button.show ();
-               routing_icon.hide();
                input_icon.hide();
                output_icon.show();
+               routing_icon.hide();
+               output_routing_icon.hide();
 
                _processor->ActiveChanged.connect (active_connection, invalidator (*this), boost::bind (&ProcessorEntry::processor_active_changed, this), gui_context());
                _processor->PropertyChanged.connect (name_connection, invalidator (*this), boost::bind (&ProcessorEntry::processor_property_changed, this, _1), gui_context());
@@ -472,6 +478,7 @@ ProcessorEntry::processor_configuration_changed (const ChanCount in, const ChanC
        input_icon.queue_draw();
        output_icon.queue_draw();
        routing_icon.queue_draw();
+       output_routing_icon.queue_draw();
 }
 
 void
@@ -949,6 +956,7 @@ PluginInsertProcessorEntry::iomap_changed ()
 {
        _parent->setup_routing_feeds ();
        routing_icon.queue_draw();
+       output_routing_icon.queue_draw();
 }
 
 void
@@ -1001,10 +1009,15 @@ ProcessorEntry::PortIcon::on_expose_event (GdkEventExpose* ev)
        return true;
 }
 
-ProcessorEntry::RoutingIcon::RoutingIcon ()
+ProcessorEntry::RoutingIcon::RoutingIcon (bool input)
        : _feed (false)
+       , _input (input)
 {
-       set_size_request (-1, std::max (7.f, rintf(8.f * UIConfiguration::instance().get_ui_scale())));
+       if (input) {
+               set_size_request (-1, std::max (7.f, rintf(8.f * UIConfiguration::instance().get_ui_scale())));
+       } else {
+               set_size_request (-1, std::max (10.f, rintf(12.f * UIConfiguration::instance().get_ui_scale())));
+       }
 }
 
 void
@@ -1014,46 +1027,63 @@ ProcessorEntry::RoutingIcon::set (
                const ARDOUR::ChanCount& sinks,
                const ARDOUR::ChanCount& sources,
                const ARDOUR::ChanMapping& in_map,
-               const ARDOUR::ChanMapping& out_map)
+               const ARDOUR::ChanMapping& out_map,
+               const ARDOUR::ChanMapping& thru_map)
 {
-       _in = in; _out = out;
-       _sources = sources; _sinks = sinks;
-       _in_map = in_map; _out_map = out_map;
-
+       _in       = in;
+       _out      = out;
+       _sources  = sources;
+       _sinks    = sinks;
+       _in_map   = in_map;
+       _out_map  = out_map;
+       _thru_map = thru_map;
 }
 
 bool
 ProcessorEntry::RoutingIcon::identity () const {
-       if (!_in_map.is_monotonic () || !_in_map.is_monotonic ()) {
+       if (!_in_map.is_monotonic () || !_in_map.is_identity ()) {
                return false;
        }
-       if (_in_map.count () != _sinks.n_total ()) {
+       if (_in_map.n_total () != _sinks.n_total () || _in.n_total () != _sinks.n_total ()) {
                return false;
        }
        if (_feed) {
-               if (!_f_out_map.is_monotonic () || _sinks != _f_sources) {
-                       return false;
-               }
-               if (!_f_out_map.is_identity ()) {
+               if (!_f_out_map.is_monotonic () || !_f_out_map.is_identity ()) {
                        return false;
                }
-               if (_f_out_map.count () != _f_sources.n_total ()) {
+               if (_f_out_map.n_total () != _f_sources.n_total () || _sinks != _f_sources) {
                        return false;
                }
        }
        return true;
 }
 
+bool
+ProcessorEntry::RoutingIcon::out_identity () const {
+       if (!_out_map.is_monotonic () || !_out_map.is_identity ()) {
+               return false;
+       }
+       if (_out_map.n_total () != _sources.n_total () || _out.n_total () != _sources.n_total ()) {
+               return false;
+       }
+       if (_thru_map.n_total () > 0) {
+               return false;
+       }
+       return true;
+}
+
 void
 ProcessorEntry::RoutingIcon::set_feed (
                                const ARDOUR::ChanCount& out,
                                const ARDOUR::ChanCount& sources,
-                               const ARDOUR::ChanMapping& out_map)
+                               const ARDOUR::ChanMapping& out_map,
+                               const ARDOUR::ChanMapping& thru_map)
 {
-       _f_out     = out;
-       _f_sources = sources;
-       _f_out_map = out_map;
-       _feed      = true;
+       _f_out      = out;
+       _f_sources  = sources;
+       _f_out_map  = out_map;
+       _f_thru_map = thru_map;
+       _feed       = true;
 }
 
 double
@@ -1067,11 +1097,31 @@ ProcessorEntry::RoutingIcon::pin_x_pos (uint32_t i, double width, uint32_t n_tot
        return rint (width * (.2 + .6 * i / (n_total - 1))) + .5;
 }
 
+void
+ProcessorEntry::RoutingIcon::draw_X (cairo_t* cr, double x0, double height, bool midi)
+{
+       const double y0 = rint (height * .4) + .5;
+       const double dx = min (y0 - .5, 1. + rint (max(2., 2. * UIConfiguration::instance().get_ui_scale())));
+
+       cairo_move_to (cr, x0, 0);
+       cairo_line_to (cr, x0, y0);
+       cairo_move_to (cr, x0 - dx, y0 - dx);
+       cairo_line_to (cr, x0 + dx, y0 + dx);
+       cairo_move_to (cr, x0 - dx, y0 + dx);
+       cairo_line_to (cr, x0 + dx, y0 - dx);
+
+       set_routing_color (cr, midi);
+       cairo_set_line_width  (cr, 1.0);
+       cairo_stroke_preserve (cr);
+       cairo_set_source_rgba (cr, 0, 0, 0, .4); // darken
+       cairo_stroke (cr);
+}
+
 void
 ProcessorEntry::RoutingIcon::draw_gnd (cairo_t* cr, double x0, double height, bool midi)
 {
        const double dx = 1 + rint (max(2., 2. * UIConfiguration::instance().get_ui_scale()));
-       const double y0 = rint (height * .66) - .5;
+       const double y0 = rint (height * .66) + .5;
 
        cairo_move_to (cr, x0, height);
        cairo_line_to (cr, x0, y0);
@@ -1083,6 +1133,41 @@ ProcessorEntry::RoutingIcon::draw_gnd (cairo_t* cr, double x0, double height, bo
        cairo_stroke (cr);
 }
 
+void
+ProcessorEntry::RoutingIcon::draw_sidechain (cairo_t* cr, double x0, double height, bool midi)
+{
+       const double dx = 1 + rint (max(2., 2. * UIConfiguration::instance().get_ui_scale()));
+       const double y0 = rint (height * .6) + .5;
+
+       cairo_move_to (cr, x0 - dx, height);
+       cairo_line_to (cr, x0, y0);
+       cairo_line_to (cr, x0 + dx, height);
+       cairo_close_path (cr);
+
+       set_routing_color (cr, midi);
+       cairo_fill (cr);
+}
+
+void
+ProcessorEntry::RoutingIcon::draw_thru (cairo_t* cr, double x0, double height, bool midi)
+{
+       const double dx = 1 + rint (max(2., 2. * UIConfiguration::instance().get_ui_scale()));
+       const double y0 = rint (height * .5) + .5;
+
+       cairo_move_to (cr, x0 - dx - .5, y0);
+       cairo_line_to (cr, x0 + dx + .5, y0 - 2);
+
+       cairo_move_to (cr, x0 - dx - .5, y0 + 2);
+       cairo_line_to (cr, x0 + dx + .5, y0);
+
+       cairo_move_to (cr, x0, y0 + 1);
+       cairo_line_to (cr, x0, height);
+
+       set_routing_color (cr, midi);
+       cairo_set_line_width  (cr, 1.0);
+       cairo_stroke (cr);
+}
+
 void
 ProcessorEntry::RoutingIcon::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi, bool dashed)
 {
@@ -1125,43 +1210,60 @@ ProcessorEntry::RoutingIcon::on_expose_event (GdkEventExpose* ev)
        cairo_rectangle (cr, 0, 0, width, height);
        cairo_fill (cr);
 
-       expose_map (cr, width, height);
+       if (_input) {
+               expose_input_map (cr, width, height);
+       } else {
+               expose_output_map (cr, width, height);
+       }
 
        cairo_destroy(cr);
        return true;
 }
 
 void
-ProcessorEntry::RoutingIcon::expose_map (cairo_t* cr, const double width, const double height)
+ProcessorEntry::RoutingIcon::expose_input_map (cairo_t* cr, const double width, const double height)
 {
        const uint32_t pc_in = _sinks.n_total();
        const uint32_t pc_in_midi = _sinks.n_midi();
 
        // TODO indicate midi-bypass ??
-       // show "X" for
+       // TODO indicate side-chain
 
        for (uint32_t i = 0; i < pc_in; ++i) {
                const bool is_midi = i < pc_in_midi;
                bool valid_in;
                uint32_t pn = is_midi ? i : i - pc_in_midi;
-               uint32_t idx = _in_map.get (is_midi ? DataType::MIDI : DataType::AUDIO, pn, &valid_in);
+               DataType dt = is_midi ? DataType::MIDI : DataType::AUDIO;
+               uint32_t idx = _in_map.get (dt, pn, &valid_in);
                if (!valid_in) {
-                       double x = pin_x_pos (i, width, pc_in, pc_in_midi, is_midi);
+                       double x = pin_x_pos (i, width, pc_in, 0, is_midi);
                        draw_gnd (cr, x, height, is_midi);
                        continue;
                }
+               if (idx >= _in.get (dt)) {
+                       // side-chain, probably
+                       double x = pin_x_pos (i, width, pc_in, 0, is_midi);
+                       draw_sidechain (cr, x, height, is_midi);
+                       continue;
+               }
                double c_x0;
                double c_x1 = pin_x_pos (i, width, pc_in, 0, false);
 
                if (_feed) {
                        bool valid_src;
-                       uint32_t src = _f_out_map.get_src (is_midi ? DataType::MIDI : DataType::AUDIO, idx, &valid_src);
+                       uint32_t src = _f_out_map.get_src (dt, idx, &valid_src);
                        if (!valid_src) {
-                               double x = pin_x_pos (i, width, pc_in, pc_in_midi, is_midi);
-                               draw_gnd (cr, x, height, is_midi);
+                               double x = pin_x_pos (i, width, pc_in, 0, false);
+                               bool valid_thru;
+                               _f_thru_map.get (dt, idx, &valid_thru);
+                               if (valid_thru) {
+                                       draw_thru (cr, x, height, is_midi);
+                               } else {
+                                       draw_gnd (cr, x, height, is_midi);
+                               }
                                continue;
                        }
-                       c_x0 = pin_x_pos (src, width, _f_out.n_total(), _f_out.n_midi(), is_midi);
+                       c_x0 = pin_x_pos (src, width, _f_sources.n_total(), _f_sources.n_midi(), is_midi);
                } else {
                        c_x0 = pin_x_pos (idx, width, _in.n_total(), _in.n_midi(), is_midi);
                }
@@ -1169,6 +1271,54 @@ ProcessorEntry::RoutingIcon::expose_map (cairo_t* cr, const double width, const
        }
 }
 
+void
+ProcessorEntry::RoutingIcon::expose_output_map (cairo_t* cr, const double width, const double height)
+{
+       const uint32_t pc_out = _sources.n_total();
+       const uint32_t pc_out_midi = _sources.n_midi();
+
+       const uint32_t n_out = _out.n_total();
+       const uint32_t n_out_midi = _out.n_midi();
+
+       for (uint32_t i = 0; i < pc_out; ++i) {
+               const bool is_midi = i < pc_out_midi;
+               bool valid_out;
+               uint32_t pn = is_midi ? i : i - pc_out_midi;
+               DataType dt = is_midi ? DataType::MIDI : DataType::AUDIO;
+               uint32_t idx = _out_map.get (dt, pn, &valid_out);
+               if (!valid_out) {
+                       continue;
+               }
+               double c_x0 = pin_x_pos (i, width, pc_out, 0, false);
+               double c_x1 = pin_x_pos (idx, width, n_out, n_out_midi, is_midi);
+               draw_connection (cr, c_x0, c_x1, 0, height - 3, is_midi);
+       }
+
+       // output arrows
+       for (uint32_t i = 0; i < n_out; ++i) {
+               const bool is_midi = i < n_out_midi;
+               double x = pin_x_pos (i, width, n_out, 0, is_midi);
+               uint32_t pn = is_midi ? i : i - n_out_midi;
+               DataType dt = is_midi ? DataType::MIDI : DataType::AUDIO;
+               bool valid_src;
+               _out_map.get_src (dt, pn, &valid_src);
+               if (!valid_src) {
+                       bool valid_thru;
+                       _thru_map.get (dt, pn, &valid_thru);
+                       if (valid_thru) {
+                               draw_thru (cr, x, height, is_midi);
+                       } else {
+                               draw_gnd (cr, x, height, is_midi);
+                       }
+               }
+               set_routing_color (cr, is_midi);
+               cairo_move_to (cr, x    , height);
+               cairo_line_to (cr, x - 3, height - 3);
+               cairo_line_to (cr, x + 3, height - 3);
+               cairo_close_path (cr);
+               cairo_fill (cr);
+       }
+}
 
 ProcessorEntry::PluginDisplay::PluginDisplay (boost::shared_ptr<ARDOUR::Plugin> p, uint32_t max_height)
        : _plug (p)
@@ -2361,6 +2511,7 @@ ProcessorBox::maybe_add_processor_pin_mgr (boost::weak_ptr<Processor> w)
 
        PluginPinWindowProxy* wp = new PluginPinWindowProxy (
                        string_compose ("PM-%2-%3", _route->id(), p->id()), w);
+       wp->set_session (_session);
 
        const XMLNode* ui_xml = _session->extra_xml (X_("UI"));
        if (ui_xml) {
@@ -2489,23 +2640,30 @@ ProcessorBox::setup_routing_feeds ()
                        ChanCount in, out;
                        pi->configured_io (in, out);
 
+                       ChanCount midi_thru;
                        ChanCount midi_bypass;
+                       ChanMapping input_map (pi->input_map ());
+                       if (pi->has_midi_thru ()) {
+                                midi_thru.set(DataType::MIDI, 1);
+                                input_map.set (DataType::MIDI, 0, 0);
+                       }
                        if (pi->has_midi_bypass ()) {
                                 midi_bypass.set(DataType::MIDI, 1);
                        }
 
-                       (*i)->input_icon.set_ports (sinks * count);
+                       (*i)->input_icon.set_ports (sinks * count + midi_thru);
                        (*i)->output_icon.set_ports (sources * count + midi_bypass);
 
                        (*i)->routing_icon.set (
                                        in, out,
-                                       sinks * count,
+                                       sinks * count + midi_thru,
                                        sources * count + midi_bypass,
-                                       pi->input_map (),
-                                       pi->output_map ());
+                                       input_map,
+                                       pi->output_map (),
+                                       pi->thru_map ());
 
                        if (next != children.end()) {
-                               (*next)->routing_icon.set_feed (out, sources * count + midi_bypass, pi->output_map ());
+                               (*next)->routing_icon.set_feed (out, sources * count + midi_bypass, pi->output_map (), pi->thru_map ());
                        }
 
                } else {
@@ -2513,15 +2671,16 @@ ProcessorBox::setup_routing_feeds ()
                        (*i)->output_icon.set_ports (p->output_streams());
                        ChanMapping inmap (p->input_streams ());
                        ChanMapping outmap (p->input_streams ());
+                       ChanMapping thrumap;
                        (*i)->routing_icon.set (
                                        p->input_streams(),
                                        p->output_streams(),
                                        p->input_streams(),
                                        p->output_streams(),
-                                       inmap, outmap);
+                                       inmap, outmap, thrumap);
 
                        if (next != children.end()) {
-                               (*next)->routing_icon.set_feed (p->output_streams(),  p->output_streams(), outmap);
+                               (*next)->routing_icon.set_feed (p->output_streams(),  p->output_streams(), outmap, thrumap);
                        }
                }
 
@@ -2543,8 +2702,20 @@ ProcessorBox::setup_routing_feeds ()
                        (*i)->routing_icon.queue_draw();
                        (*i)->input_icon.show();
                }
+
+               list<ProcessorEntry*>::iterator next = i;
+               if (++next == children.end()) {
+                       // show additional wires if outputs of last processor are not an identity map.
+                       if ((*i)->routing_icon.out_identity ()) {
+                               (*i)->output_routing_icon.hide();
+                       } else {
+                               (*i)->output_routing_icon.copy_state ((*i)->routing_icon);
+                               (*i)->output_routing_icon.show();
+                       }
+               } else {
+                       (*i)->output_routing_icon.hide();
+               }
        }
-       // TODO show additional wires if outputs of last processor are not an identity map.
 }
 
 void
@@ -3298,7 +3469,7 @@ ProcessorBox::register_actions ()
                        sigc::ptr_fun (ProcessorBox::rb_ab_plugins));
 
        manage_pins_action = myactions.register_action (
-               processor_box_actions, X_("manage-pins"), _("Pin Management..."),
+               processor_box_actions, X_("manage-pins"), _("Pin Connections..."),
                sigc::ptr_fun (ProcessorBox::rb_manage_pins));
 
        /* show editors */
@@ -3882,6 +4053,13 @@ PluginPinWindowProxy::~PluginPinWindowProxy()
        _window = 0;
 }
 
+ARDOUR::SessionHandlePtr*
+PluginPinWindowProxy::session_handle ()
+{
+       ArdourWindow* aw = dynamic_cast<ArdourWindow*> (_window);
+       if (aw) { return aw; }
+       return 0;
+}
 
 Gtk::Window*
 PluginPinWindowProxy::get (bool create)
@@ -3897,6 +4075,10 @@ PluginPinWindowProxy::get (bool create)
                        return 0;
                }
                _window = new PluginPinDialog (pi);
+               ArdourWindow* aw = dynamic_cast<ArdourWindow*> (_window);
+               if (aw) {
+                       aw->set_session (_session);
+               }
        }
 
        _window->show_all ();