+ if (_input) {
+ if (can_coalesce ()) {
+ expose_coalesced_input_map (cr, width, height);
+ } else {
+ expose_input_map (cr, width, height);
+ }
+ } else {
+ expose_output_map (cr, width, height);
+ }
+
+ cairo_destroy(cr);
+ return true;
+}
+
+void
+ProcessorEntry::RoutingIcon::expose_coalesced_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();
+
+ 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;
+ 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, 0, is_midi);
+ draw_gnd (cr, x, 0, 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, 0, height, is_midi);
+ continue;
+ }
+ double c_x0;
+ double c_x1 = pin_x_pos (i, width, pc_in, 0, false);
+
+ if (_fed_by) {
+ bool 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, 0, false);
+ bool valid_thru;
+ _f_thru_map.get (dt, idx, &valid_thru);
+ if (valid_thru) {
+ draw_thru_src (cr, x, 0, height, is_midi);
+ } else {
+ draw_gnd (cr, x, 0, height, is_midi);
+ }
+ continue;
+ }
+ 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);
+ }
+ draw_connection (cr, c_x0, c_x1, 0, height, is_midi);
+ }
+}
+
+void
+ProcessorEntry::RoutingIcon::expose_input_map (cairo_t* cr, const double width, const double height)
+{
+ const uint32_t n_in = _in.n_total();
+ const uint32_t n_in_midi = _in.n_midi();
+ const uint32_t pc_in = _sinks.n_total();
+ const uint32_t pc_in_midi = _sinks.n_midi();
+
+ // draw inputs to this
+ 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;
+ DataType dt = is_midi ? DataType::MIDI : DataType::AUDIO;
+ uint32_t idx = _in_map.get (dt, pn, &valid_in);
+ // check if it's fed
+ bool valid_src = true;
+ if (valid_in && idx < _in.get (dt) && _fed_by) {
+ bool valid_out;
+ bool valid_thru;
+ _f_out_map.get_src (dt, idx, &valid_out);
+ _f_thru_map.get (dt, idx, &valid_thru);
+ if (!valid_out && !valid_thru) {
+ valid_src = false;
+ }
+ }
+ if (!valid_in || !valid_src) {
+ double x = pin_x_pos (i, width, pc_in, 0, is_midi);
+ draw_gnd (cr, x, 0, 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, 0, height, is_midi);
+ continue;
+ }
+ double c_x1 = pin_x_pos (i, width, pc_in, 0, false);
+ double c_x0 = pin_x_pos (idx, width, n_in, n_in_midi, is_midi);
+ draw_connection (cr, c_x0, c_x1, 0, height, is_midi);
+ }
+
+ // draw reverse thru
+ for (uint32_t i = 0; i < n_in; ++i) {
+ const bool is_midi = i < n_in_midi;
+ bool valid_thru;
+ uint32_t pn = is_midi ? i : i - n_in_midi;
+ DataType dt = is_midi ? DataType::MIDI : DataType::AUDIO;
+ _thru_map.get_src (dt, pn, &valid_thru);
+ if (!valid_thru) {
+ continue;
+ }
+ double x = pin_x_pos (i, width, n_in, 0, is_midi);
+ draw_thru_sink (cr, x, 0, height, is_midi);
+ }
+}
+
+void
+ProcessorEntry::RoutingIcon::expose_output_map (cairo_t* cr, const double width, const double height)
+{
+ int dh = std::max (4.f, rintf(4.f * UIConfiguration::instance().get_ui_scale()));
+ double ht = _terminal ? height - dh : height;
+
+ // draw outputs of this
+ 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;
+ }
+ // skip connections that are not used in the next's input
+ if (_feeding) {
+ bool valid_thru, valid_sink;
+ _i_in_map.get_src (dt, idx, &valid_sink);
+ _i_thru_map.get_src (dt, idx, &valid_thru);
+ if (!valid_thru && !valid_sink) {
+ if (!is_midi || i != 0) { // special case midi-bypass
+ 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, ht, is_midi);
+ }
+
+ for (uint32_t i = 0; i < n_out; ++i) {
+ const bool is_midi = i < n_out_midi;
+ uint32_t pn = is_midi ? i : i - n_out_midi;
+ DataType dt = is_midi ? DataType::MIDI : DataType::AUDIO;
+ double x = pin_x_pos (i, width, n_out, 0, is_midi);
+
+ if (!_terminal) {
+ bool valid_thru_f = false;
+ // skip connections that are not used in the next's input
+ if (_feeding) {
+ bool valid_sink;
+ _i_in_map.get_src (dt, pn, &valid_sink);
+ _i_thru_map.get_src (dt, pn, &valid_thru_f);
+ if (!valid_thru_f && !valid_sink) {
+ if (!is_midi || i != 0) { // special case midi-bypass
+ continue;
+ }
+ }
+ }
+
+ bool valid_src;
+ _out_map.get_src (dt, pn, &valid_src);
+ if (!valid_src) {
+ bool valid_thru;
+ uint32_t idx = _thru_map.get (dt, pn, &valid_thru);
+ if (valid_thru) {
+ if (idx >= _in.get (dt)) {
+ draw_sidechain (cr, x, 0, height, is_midi);
+ } else {
+ draw_thru_src (cr, x, 0, height, is_midi);
+ }
+ } else if (valid_thru_f){
+ // gnd is part of input, unless it's a thru input
+ // (also only true if !coalesced into one small display)
+ draw_gnd (cr, x, 0, height, is_midi);
+ }
+ }
+ } else {
+ // terminal node, add arrows
+ bool valid_src;
+ _out_map.get_src (dt, pn, &valid_src);
+ if (!valid_src) {
+ bool valid_thru;
+ uint32_t idx = _thru_map.get (dt, pn, &valid_thru);
+ if (valid_thru) {
+ if (idx >= _in.get (dt)) {
+ draw_sidechain (cr, x, 0, height - dh, is_midi);
+ } else {
+ draw_thru_src (cr, x, 0, height - dh, is_midi);
+ }
+ } else {
+ draw_gnd (cr, x, 0, height - dh, is_midi);
+ }
+ }
+
+ set_routing_color (cr, is_midi);
+ cairo_set_line_width (cr, 1.0);
+ cairo_move_to (cr, x, height - dh);
+ cairo_line_to (cr, x, height - 2);
+ cairo_stroke (cr);
+
+ const double ar = dh - 1;
+ cairo_move_to (cr, x - ar, height - ar);
+ cairo_line_to (cr, x , height - .5);
+ cairo_line_to (cr, x + ar, height - ar);
+ cairo_line_to (cr, x , height - ar * .5);
+ cairo_close_path (cr);
+ cairo_fill_preserve (cr);
+ cairo_stroke (cr);
+ }
+ }
+}
+
+ProcessorEntry::PluginDisplay::PluginDisplay (boost::shared_ptr<ARDOUR::Plugin> p, uint32_t max_height)
+ : _plug (p)
+ , _surf (0)
+ , _max_height (max_height)
+ , _cur_height (1)
+ , _scroll (false)
+{
+ set_name ("processor prefader");
+ _plug->QueueDraw.connect (_qdraw_connection, invalidator (*this),
+ boost::bind (&Gtk::Widget::queue_draw, this), gui_context ());
+}
+
+ProcessorEntry::PluginDisplay::~PluginDisplay ()
+{
+ if (_surf) {
+ cairo_surface_destroy (_surf);
+ }
+}
+
+void
+ProcessorEntry::PluginDisplay::on_size_request (Gtk::Requisition* req)
+{
+ req->width = 56;
+ req->height = _cur_height;
+}
+
+
+void
+ProcessorEntry::PluginDisplay::update_height_alloc (uint32_t inline_height)
+{
+ /* work-around scroll-bar + aspect ratio
+ * show inline-view -> height changes -> scrollbar gets added
+ * -> width changes -> inline-view, fixed aspect ratio -> height changes
+ * -> scroll bar is removed [-> width changes ; repeat ]
+ */
+ uint32_t shm = std::min (_max_height, inline_height);
+ bool sc = false;
+ Gtk::Container* pr = get_parent();
+ for (uint32_t i = 0; i < 4 && pr; ++i) {
+ // VBox, EventBox, ViewPort, ScrolledWindow
+ pr = pr->get_parent();
+ }
+ Gtk::ScrolledWindow* sw = dynamic_cast<Gtk::ScrolledWindow*> (pr);
+ if (sw) {
+ const Gtk::VScrollbar* vsb = sw->get_vscrollbar();
+ sc = vsb && vsb->is_visible();
+ }
+
+ if (shm != _cur_height) {
+ if (_scroll == sc || _cur_height < shm) {
+ queue_resize ();
+ }
+ _cur_height = shm;
+ }
+ _scroll = sc;
+}
+
+uint32_t
+ProcessorEntry::PluginDisplay::render_inline (cairo_t* cr, uint32_t width)
+{
+ Plugin::Display_Image_Surface* dis = _plug->render_inline_display (width, _max_height);
+ if (!dis) {
+ return 0;
+ }
+
+ /* allocate a local image-surface,
+ * We cannot re-use the data via cairo_image_surface_create_for_data(),
+ * since pixman keeps a reference to it.
+ * we'd need to hand over the data and ha cairo_surface_destroy to free it.
+ * it might be possible to work around via cairo_surface_set_user_data().
+ */
+ if (!_surf
+ || dis->width != cairo_image_surface_get_width (_surf)
+ || dis->height != cairo_image_surface_get_height (_surf)
+ ) {
+ if (_surf) {
+ cairo_surface_destroy (_surf);
+ }
+ _surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, dis->width, dis->height);
+ }
+
+ if (cairo_image_surface_get_stride (_surf) == dis->stride) {
+ memcpy (cairo_image_surface_get_data (_surf), dis->data, dis->stride * dis->height);
+ } else {
+ unsigned char *src = dis->data;
+ unsigned char *dst = cairo_image_surface_get_data (_surf);
+ const int dst_stride = cairo_image_surface_get_stride (_surf);
+ for (int y = 0; y < dis->height; ++y) {
+ memcpy (dst, src, dis->width * 4 /*ARGB32*/);
+ src += dis->stride;
+ dst += dst_stride;
+ }
+ }
+
+ cairo_surface_flush(_surf);
+ cairo_surface_mark_dirty(_surf);
+ const double xc = floor ((width - dis->width) * .5);
+ cairo_set_source_surface(cr, _surf, xc, 0);
+ cairo_paint (cr);
+
+ return dis->height;
+}
+
+bool
+ProcessorEntry::PluginDisplay::on_expose_event (GdkEventExpose* ev)
+{
+ Gtk::Allocation a = get_allocation();
+ double const width = a.get_width();
+ double const height = a.get_height();
+
+ cairo_t* cr = gdk_cairo_create (get_window()->gobj());
+ cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
+ cairo_clip (cr);
+
+ Gdk::Color const bg = get_style()->get_bg (STATE_NORMAL);
+ cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
+ cairo_rectangle (cr, 0, 0, width, height);
+ cairo_fill (cr);
+
+ cairo_save (cr);
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ Gtkmm2ext::rounded_rectangle (cr, .5, -1.5, width - 1, height + 1, 7);
+ cairo_clip (cr);
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+
+ uint32_t ht = render_inline (cr, width);
+ cairo_restore (cr);
+
+ if (ht == 0) {
+ hide ();
+ if (_cur_height != 1) {
+ _cur_height = 1;
+ queue_resize ();
+ }
+ cairo_destroy (cr);
+ return true;
+ } else {
+ update_height_alloc (ht);
+ }
+
+ bool failed = false;
+ std::string name = get_name();
+ ArdourCanvas::Color fill_color = UIConfiguration::instance().color (string_compose ("%1: fill active", name), &failed);
+
+ Gtkmm2ext::rounded_rectangle (cr, .5, -1.5, width - 1, height + 1, 7);
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+ cairo_set_line_width(cr, 1.0);
+ ArdourCanvas::set_source_rgb_a (cr, fill_color, 1.0);
+ cairo_stroke (cr);
+
+ cairo_destroy(cr);
+ return true;
+}
+
+ProcessorEntry::LuaPluginDisplay::LuaPluginDisplay (boost::shared_ptr<ARDOUR::LuaProc> p, uint32_t max_height)
+ : PluginDisplay (p, max_height)
+ , _luaproc (p)
+ , _lua_render_inline (0)
+{
+ p->setup_lua_inline_gui (&lua_gui);
+
+ lua_State* LG = lua_gui.getState ();
+ LuaInstance::bind_cairo (LG);
+ luabridge::LuaRef lua_render = luabridge::getGlobal (LG, "render_inline");
+ assert (lua_render.isFunction ());
+ _lua_render_inline = new luabridge::LuaRef (lua_render);
+}
+
+ProcessorEntry::LuaPluginDisplay::~LuaPluginDisplay ()
+{
+ delete (_lua_render_inline);
+}
+
+uint32_t
+ProcessorEntry::LuaPluginDisplay::render_inline (cairo_t *cr, uint32_t width)
+{
+ Cairo::Context ctx (cr);
+ try {
+ luabridge::LuaRef rv = (*_lua_render_inline)((Cairo::Context *)&ctx, width, _max_height);
+ if (rv.isTable ()) {
+ uint32_t h = rv[2];
+ return h;