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"
21 #include "gtkmm2ext/rgb_macros.h"
23 #include "plugin_pin_dialog.h"
24 #include "gui_thread.h"
25 #include "ui_config.h"
29 using namespace ARDOUR;
33 using namespace Gtkmm2ext;
35 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert> pi)
36 : ArdourWindow (string_compose (_("Pin Configuration: %1"), pi->name ()))
40 assert (pi->owner ()); // Route
42 _pi->PluginIoReConfigure.connect (
43 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::plugin_reconfigured, this), gui_context()
46 _pi->PluginMapChanged.connect (
47 _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::plugin_reconfigured, this), gui_context()
50 darea.signal_expose_event().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_expose_event));
52 // TODO min. width depending on # of pins.
53 darea.set_size_request(600, 200);
55 HBox* hbox = manage (new HBox);
56 hbox->pack_start (darea, true, true);
58 // TODO add info/settings table
59 // * show _pi->strict_io() -- inherited from route
60 // * show _pi->custom_cfg()
61 // Add/Remove instances
62 // Add/Remove output ports
63 // Reset Button custom-config to "Automatic"
65 VBox* vbox = manage (new VBox);
66 vbox->pack_start (*hbox, true, true);
70 PluginPinDialog::~PluginPinDialog()
75 PluginPinDialog::plugin_reconfigured ()
81 PluginPinDialog::set_color (cairo_t* cr, bool midi)
83 // see also gtk2_ardour/processor_box.cc
84 static const uint32_t audio_port_color = 0x4A8A0EFF; // Green
85 static const uint32_t midi_port_color = 0x960909FF; //Red
88 cairo_set_source_rgb (cr,
89 UINT_RGBA_R_FLT(midi_port_color),
90 UINT_RGBA_G_FLT(midi_port_color),
91 UINT_RGBA_B_FLT(midi_port_color));
93 cairo_set_source_rgb (cr,
94 UINT_RGBA_R_FLT(audio_port_color),
95 UINT_RGBA_G_FLT(audio_port_color),
96 UINT_RGBA_B_FLT(audio_port_color));
101 PluginPinDialog::draw_io_pins (cairo_t* cr, double y0, double width, uint32_t n_total, uint32_t n_midi, bool input)
103 double dir = input ? 1. : -1.;
105 for (uint32_t i = 0; i < n_total; ++i) {
106 double x0 = rint ((i + 1) * width / (1. + n_total)) - .5;
107 cairo_move_to (cr, x0, y0);
108 cairo_rel_line_to (cr, -5., -5. * dir);
109 cairo_rel_line_to (cr, 0., -25. * dir);
110 cairo_rel_line_to (cr, 10., 0.);
111 cairo_rel_line_to (cr, 0., 25. * dir);
112 cairo_close_path (cr);
114 cairo_set_source_rgb (cr, 0, 0, 0);
115 cairo_stroke_preserve (cr);
117 set_color (cr, i < n_midi);
123 PluginPinDialog::is_valid_port (uint32_t i, uint32_t n_total, uint32_t n_midi, bool midi)
125 if (!midi) { i += n_midi; }
133 PluginPinDialog::pin_x_pos (uint32_t i, double x0, double width, uint32_t n_total, uint32_t n_midi, bool midi)
135 if (!midi) { i += n_midi; }
136 return rint (x0 + (i + 1) * width / (1. + n_total)) - .5;
140 PluginPinDialog::draw_plugin_pins (cairo_t* cr, double x0, double y0, double width, uint32_t n_total, uint32_t n_midi, bool input)
142 // see also ProcessorEntry::PortIcon::on_expose_event
143 const double dxy = _pin_box_size;
145 for (uint32_t i = 0; i < n_total; ++i) {
146 double x = rint (x0 + (i + 1) * width / (1. + n_total)) - .5;
147 cairo_rectangle (cr, x - dxy * .5, input ? y0 - dxy : y0, 1 + dxy, dxy);
149 set_color (cr, i < n_midi);
155 PluginPinDialog::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi, bool dashed)
157 double bz = 2 * _pin_box_size;
159 cairo_move_to (cr, x0, y0);
160 cairo_curve_to (cr, x0, y0 + bz, x1, y1 - bz, x1, y1);
161 cairo_set_line_width (cr, 3.0);
162 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
163 cairo_set_source_rgb (cr, 1, 0, 0);
165 const double dashes[] = { 5, 7 };
166 cairo_set_dash (cr, dashes, 2, 0);
168 set_color (cr, midi);
171 cairo_set_dash (cr, 0, 0, 0);
176 PluginPinDialog::darea_expose_event (GdkEventExpose* ev)
178 Gtk::Allocation a = darea.get_allocation();
179 double const width = a.get_width();
180 double const height = a.get_height();
182 _pin_box_size = rint (max (6., 8. * UIConfiguration::instance().get_ui_scale()));
184 cairo_t* cr = gdk_cairo_create (darea.get_window()->gobj());
186 cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
189 Gdk::Color const bg = get_style()->get_bg (STATE_NORMAL);
190 cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
191 cairo_rectangle (cr, 0, 0, width, height);
194 ChanCount in, out; // actual configured i/o
195 _pi->configured_io (in, out);
197 ChanCount sinks = _pi->natural_input_streams ();
198 ChanCount sources = _pi->natural_output_streams ();
199 uint32_t plugins = _pi->get_count ();
204 double y_out = height - 40;
207 double yc = rint (height * .5);
209 double bxw = rint ((width * .9) / ((plugins) + .2 * (plugins - 1)));
210 double bxw2 = rint (bxw * .5);
213 const uint32_t pc_in = in.n_total();
214 const uint32_t pc_in_midi = in.n_midi();
215 const uint32_t pc_out = out.n_total();
216 const uint32_t pc_out_midi = out.n_midi();
218 cairo_set_line_width (cr, 1.0);
219 draw_io_pins (cr, y_in, width, pc_in, pc_in_midi, true);
220 draw_io_pins (cr, y_out, width, pc_out, pc_out_midi, false);
222 // draw midi-bypass (behind)
223 if (_pi->has_midi_bypass ()) {
224 double x0 = rint (width / (1. + pc_in)) - .5;
225 double x1 = rint (width / (1. + pc_out)) - .5;
226 draw_connection (cr, x0, x1, y_in, y_out, true, true);
229 for (uint32_t i = 0; i < plugins; ++i) {
230 double x0 = rint ((i + .5) * width / (double)(plugins)) - .5;
232 draw_plugin_pins (cr, x0 - bxw2, yc - bxh2, bxw, sinks.n_total (), sinks.n_midi (), true);
233 draw_plugin_pins (cr, x0 - bxw2, yc + bxh2, bxw, sources.n_total (), sources.n_midi (), false);
235 cairo_set_source_rgb (cr, .3, .3, .3);
236 rounded_rectangle (cr, x0 - bxw2, yc - bxh2, bxw, 2 * bxh2, 7);
239 const ChanMapping::Mappings in_map = _pi->input_map (i).mappings();
240 const ChanMapping::Mappings out_map = _pi->output_map (i).mappings();
242 for (ChanMapping::Mappings::const_iterator t = in_map.begin (); t != in_map.end (); ++t) {
243 bool is_midi = t->first == DataType::MIDI;
244 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
245 uint32_t pn = (*c).first; // pin
246 uint32_t pb = (*c).second;
247 if (!is_valid_port (pb, pc_in, pc_in_midi, is_midi)) {
250 double c_x0 = pin_x_pos (pb, 0, width, pc_in, pc_in_midi, is_midi);
251 double c_x1 = pin_x_pos (pn, x0 - bxw2, bxw, sinks.n_total (), sinks.n_midi (), is_midi);
252 draw_connection (cr, c_x0, c_x1, y_in, yc - bxh2 - _pin_box_size, is_midi);
256 for (ChanMapping::Mappings::const_iterator t = out_map.begin (); t != out_map.end (); ++t) {
257 bool is_midi = t->first == DataType::MIDI;
258 for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
259 uint32_t pn = (*c).first; // pin
260 uint32_t pb = (*c).second;
261 if (!is_valid_port (pb, pc_out, pc_out_midi, is_midi)) {
264 double c_x0 = pin_x_pos (pn, x0 - bxw2, bxw, sources.n_total (), sources.n_midi (), is_midi);
265 double c_x1 = pin_x_pos (pb, 0, width, pc_out, pc_out_midi, is_midi);
266 draw_connection (cr, c_x0, c_x1, yc + bxh2 + _pin_box_size, y_out, is_midi);