2 * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3 * Copyright (C) 2011 Paul Davis
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "gtkmm2ext/utils.h"
22 #include "plugin_pin_dialog.h"
23 #include "gui_thread.h"
24 #include "ui_config.h"
28 using namespace ARDOUR;
32 using namespace Gtkmm2ext;
35 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert> pi)
36 : ArdourWindow (string_compose (_("Pin Configuration: %1"), pi->name ()))
39 assert (pi->owner ()); // Route
41 _pi->PluginIoReConfigure.connect (
42 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::plugin_reconfigured, this), gui_context()
45 _pi->PluginMapChanged.connect (
46 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::plugin_reconfigured, this), gui_context()
49 darea.signal_expose_event().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_expose_event));
51 // TODO min. width depending on # of pins.
52 darea.set_size_request(600, 200);
54 VBox* vbox = manage (new VBox);
55 vbox->pack_start (darea, true, true);
59 PluginPinDialog::~PluginPinDialog()
64 PluginPinDialog::plugin_reconfigured ()
70 PluginPinDialog::draw_io_pins (cairo_t* cr, double y0, double width, uint32_t n_total, uint32_t n_midi, bool input)
72 double dir = input ? 1. : -1.;
74 for (uint32_t i = 0; i < n_total; ++i) {
75 double x0 = rint ((i + 1) * width / (1. + n_total)) - .5;
76 cairo_move_to (cr, x0, y0);
77 cairo_rel_line_to (cr, -5., -5. * dir);
78 cairo_rel_line_to (cr, 0., -25. * dir);
79 cairo_rel_line_to (cr, 10., 0.);
80 cairo_rel_line_to (cr, 0., 25. * dir);
81 cairo_close_path (cr);
83 cairo_set_source_rgb (cr, 0, 0, 0);
84 cairo_stroke_preserve (cr);
87 cairo_set_source_rgb (cr, 1, 0, 0);
89 cairo_set_source_rgb (cr, 0, 1, 0);
96 PluginPinDialog::pin_x_pos (uint32_t i, double x0, double width, uint32_t n_total, uint32_t n_midi, bool midi)
98 if (!midi) { i += n_midi; }
99 return rint (x0 + (i + 1) * width / (1. + n_total)) - .5;
103 PluginPinDialog::draw_plugin_pins (cairo_t* cr, double x0, double y0, double width, uint32_t n_total, uint32_t n_midi, bool input)
105 // see also ProcessorEntry::PortIcon::on_expose_event
106 const double dxy = rint (max (6., 8. * UIConfiguration::instance().get_ui_scale()));
108 for (uint32_t i = 0; i < n_total; ++i) {
109 double x = rint (x0 + (i + 1) * width / (1. + n_total)) - .5;
110 cairo_rectangle (cr, x - dxy * .5, input ? y0 - dxy : y0, 1 + dxy, dxy);
113 cairo_set_source_rgb (cr, 1, 0, 0);
115 cairo_set_source_rgb (cr, 0, 1, 0);
123 PluginPinDialog::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi)
125 cairo_move_to (cr, x0, y0);
126 cairo_curve_to (cr, x0, y0 + 10, x1, y1 - 10, x1, y1);
127 cairo_set_line_width (cr, 3.0);
128 cairo_set_source_rgb (cr, 1, 0, 0);
130 cairo_set_source_rgb (cr, 1, 0, 0);
132 cairo_set_source_rgb (cr, 0, 1, 0);
138 PluginPinDialog::darea_expose_event (GdkEventExpose* ev)
140 Gtk::Allocation a = darea.get_allocation();
141 double const width = a.get_width();
142 double const height = a.get_height();
144 cairo_t* cr = gdk_cairo_create (darea.get_window()->gobj());
146 cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
149 Gdk::Color const bg = get_style()->get_bg (STATE_NORMAL);
150 cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
151 cairo_rectangle (cr, 0, 0, width, height);
154 ChanCount in, out; // actual configured i/o
155 _pi->configured_io (in, out);
157 ChanCount sinks = _pi->natural_input_streams ();
158 ChanCount sources = _pi->natural_output_streams ();
159 uint32_t plugins = _pi->get_count ();
164 double y_out = height - 40;
167 double yc = rint (height * .5);
169 double bxw = rint ((width * .9) / ((plugins) + .2 * (plugins - 1)));
170 double bxw2 = rint (bxw * .5);
173 const uint32_t pc_in = in.n_total();
174 const uint32_t pc_in_midi = in.n_midi();
175 const uint32_t pc_out = out.n_total();
176 const uint32_t pc_out_midi = out.n_midi();
178 cairo_set_line_width (cr, 1.0);
179 draw_io_pins (cr, y_in, width, pc_in, pc_in_midi, true);
180 draw_io_pins (cr, y_out, width, pc_out, pc_out_midi, false);
182 // draw midi-bypass (behind)
183 if (sources.n_midi() == 0 && pc_in_midi > 0 && pc_out_midi > 0) {
184 double x0 = rint (width / (1. + pc_in)) - .5;
185 double x1 = rint (width / (1. + pc_out)) - .5;
186 draw_connection (cr, x0, x1, y_in, y_out, true);
189 for (uint32_t i = 0; i < plugins; ++i) {
190 double x0 = rint ((i + .5) * width / (double)(plugins)) - .5;
192 draw_plugin_pins (cr, x0 - bxw2, yc - bxh2, bxw, sinks.n_total (), sinks.n_midi (), true);
193 draw_plugin_pins (cr, x0 - bxw2, yc + bxh2, bxw, sources.n_total (), sources.n_midi (), false);
195 cairo_set_source_rgb (cr, .3, .3, .3);
196 rounded_rectangle (cr, x0 - bxw2, yc - bxh2, bxw, 2 * bxh2, 7);
199 const ChanMapping::Mappings in_map = _pi->input_map (i).mappings();
200 const ChanMapping::Mappings out_map = _pi->output_map (i).mappings();
202 for (ChanMapping::Mappings::const_iterator t = in_map.begin (); t != in_map.end (); ++t) {
203 bool is_midi = t->first == DataType::MIDI;
204 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
205 uint32_t pn = (*c).first; // pin
206 uint32_t pb = (*c).second;
207 double c_x0 = pin_x_pos (pb, 0, width, pc_in, pc_in_midi, is_midi);
208 double c_x1 = pin_x_pos (pn, x0 - bxw2, bxw, sinks.n_total (), sinks.n_midi (), is_midi);
209 draw_connection (cr, c_x0, c_x1, y_in, yc - bxh2, is_midi);
213 for (ChanMapping::Mappings::const_iterator t = out_map.begin (); t != out_map.end (); ++t) {
214 bool is_midi = t->first == DataType::MIDI;
215 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
216 uint32_t pn = (*c).first; // pin
217 uint32_t pb = (*c).second;
218 double c_x0 = pin_x_pos (pn, x0 - bxw2, bxw, sources.n_total (), sources.n_midi (), is_midi);
219 double c_x1 = pin_x_pos (pb, 0, width, pc_out, pc_out_midi, is_midi);
220 draw_connection (cr, c_x0, c_x1, yc + bxh2, y_out, is_midi);