prevent dup output connections across instances
[ardour.git] / gtk2_ardour / plugin_pin_dialog.cc
1 /*
2  * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3  * Copyright (C) 2011 Paul Davis
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 #include <gtkmm/table.h>
21 #include <gtkmm/box.h>
22 #include <gtkmm/label.h>
23
24 #include "gtkmm2ext/utils.h"
25 #include "gtkmm2ext/rgb_macros.h"
26
27 #include "plugin_pin_dialog.h"
28 #include "gui_thread.h"
29 #include "ui_config.h"
30
31 #include "i18n.h"
32
33 using namespace ARDOUR;
34 using namespace PBD;
35 using namespace std;
36 using namespace Gtk;
37 using namespace Gtkmm2ext;
38
39 PluginPinDialog::PluginPinDialog (boost::shared_ptr<ARDOUR::PluginInsert> pi)
40         : ArdourWindow (string_compose (_("Pin Configuration: %1"), pi->name ()))
41         , _strict_io (_("Strict I/O"))
42         , _automatic (_("Automatic"))
43         , _add_plugin (_("+"))
44         , _del_plugin (_("-"))
45         , _add_output_audio (_("+"))
46         , _del_output_audio (_("-"))
47         , _add_output_midi (_("+"))
48         , _del_output_midi (_("-"))
49         , _pi (pi)
50         , _pin_box_size (4)
51         , _position_valid (false)
52         , _ignore_updates (false)
53 {
54         assert (pi->owner ()); // Route
55
56         _pi->PluginIoReConfigure.connect (
57                         _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::plugin_reconfigured, this), gui_context()
58                         );
59
60         _pi->PluginMapChanged.connect (
61                         _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::plugin_reconfigured, this), gui_context()
62                         );
63
64         _pi->PluginConfigChanged.connect (
65                         _plugin_connections, invalidator (*this), boost::bind (&PluginPinDialog::plugin_reconfigured, this), gui_context()
66                         );
67
68         // TODO min. width depending on # of pins.
69         darea.set_size_request(600, 200);
70         _strict_io.set_sensitive (false);
71
72         Label* l;
73         int r = 0;
74         Table* t = manage (new Table (4, 3));
75         t->set_border_width (0);
76         t->set_spacings (4);
77
78         l = manage (new Label (_("Track/Bus:"), ALIGN_END));
79         t->attach (*l, 0, 1, r, r + 1);
80         l = manage (new Label ());
81         l->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
82         l->set_width_chars (24);
83         l->set_max_width_chars (24);
84         l->set_text (_route()->name ());
85         t->attach (*l, 1, 3, r, r + 1);
86         ++r;
87
88         l = manage (new Label (_("Plugin:"), ALIGN_END));
89         t->attach (*l, 0, 1, r, r + 1);
90         l = manage (new Label ());
91         l->set_ellipsize (Pango::ELLIPSIZE_MIDDLE);
92         l->set_width_chars (24);
93         l->set_max_width_chars (24);
94         l->set_text (pi->name ());
95         t->attach (*l, 1, 3, r, r + 1);
96         ++r;
97
98         l = manage (new Label (_("Settings:"), ALIGN_END));
99         t->attach (*l, 0, 1, r, r + 1);
100         t->attach (_strict_io, 1, 2, r, r + 1, FILL, SHRINK);
101         t->attach (_automatic, 2, 3, r, r + 1, FILL, SHRINK);
102         ++r;
103
104         l = manage (new Label (_("Instances:"), ALIGN_END));
105         t->attach (*l, 0, 1, r, r + 1);
106         t->attach (_add_plugin, 1, 2, r, r + 1, SHRINK, SHRINK);
107         t->attach (_del_plugin, 2, 3, r, r + 1, SHRINK, SHRINK);
108         ++r;
109
110         l = manage (new Label (_("Audio Out:"), ALIGN_END));
111         t->attach (*l, 0, 1, r, r + 1);
112         t->attach (_add_output_audio, 1, 2, r, r + 1, SHRINK, SHRINK);
113         t->attach (_del_output_audio, 2, 3, r, r + 1, SHRINK, SHRINK);
114         ++r;
115
116         l = manage (new Label (_("Midi Out:"), ALIGN_END));
117         t->attach (*l, 0, 1, r, r + 1);
118         t->attach (_add_output_midi, 1, 2, r, r + 1, SHRINK, SHRINK);
119         t->attach (_del_output_midi, 2, 3, r, r + 1, SHRINK, SHRINK);
120         ++r;
121
122         HBox* hbox = manage (new HBox);
123         hbox->pack_start (darea, true, true);
124         hbox->pack_start (*t, false, true);
125
126         VBox* vbox = manage (new VBox);
127         vbox->pack_start (*hbox, true, true);
128         add (*vbox);
129         vbox->show_all();
130
131         plugin_reconfigured ();
132
133         darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
134         darea.signal_size_allocate().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_size_allocate));
135         darea.signal_expose_event().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_expose_event));
136         darea.signal_button_press_event().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_button_press_event));
137         darea.signal_button_release_event().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_button_release_event));
138         darea.signal_motion_notify_event().connect (sigc::mem_fun (*this, &PluginPinDialog::darea_motion_notify_event));
139
140         _automatic.signal_clicked.connect (sigc::mem_fun(*this, &PluginPinDialog::automatic_clicked));
141          _add_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun(*this, &PluginPinDialog::add_remove_plugin_clicked), true));
142          _del_plugin.signal_clicked.connect (sigc::bind (sigc::mem_fun(*this, &PluginPinDialog::add_remove_plugin_clicked), false));
143
144          _add_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun(*this, &PluginPinDialog::add_remove_port_clicked), true, DataType::AUDIO));
145          _del_output_audio.signal_clicked.connect (sigc::bind (sigc::mem_fun(*this, &PluginPinDialog::add_remove_port_clicked), false, DataType::AUDIO));
146          _add_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun(*this, &PluginPinDialog::add_remove_port_clicked), true, DataType::MIDI));
147          _del_output_midi.signal_clicked.connect (sigc::bind (sigc::mem_fun(*this, &PluginPinDialog::add_remove_port_clicked), false, DataType::MIDI));
148 }
149
150 PluginPinDialog::~PluginPinDialog()
151 {
152 }
153
154 void
155 PluginPinDialog::plugin_reconfigured ()
156 {
157         if (_ignore_updates) {
158                 return;
159         }
160         _n_plugins = _pi->get_count ();
161         _pi->configured_io (_in, _out);
162         _sinks = _pi->natural_input_streams ();
163         _sources = _pi->natural_output_streams ();
164
165         _del_plugin.set_sensitive (_n_plugins > 1);
166         _del_output_audio.set_sensitive (_out.n_audio () > 0 && _out.n_total () > 1);
167         _del_output_midi.set_sensitive (_out.n_midi () > 0 && _out.n_total () > 1);
168         _strict_io.set_active (_pi->strict_io());
169
170         update_elements ();
171 }
172
173 void
174 PluginPinDialog::update_elements ()
175 {
176         _elements.clear ();
177         _hover.reset();
178         _actor.reset();
179         _selection.reset();
180
181         for (uint32_t i = 0; i < _in.n_total (); ++i) {
182                 _elements.push_back (CtrlWidget (Input, (i < _in.n_midi () ? DataType::MIDI : DataType::AUDIO), i));
183         }
184
185         for (uint32_t i = 0; i < _out.n_total (); ++i) {
186                 _elements.push_back (CtrlWidget (Output, (i < _out.n_midi () ? DataType::MIDI : DataType::AUDIO), i));
187         }
188
189         for (uint32_t n = 0; n < _n_plugins; ++n) {
190                 for (uint32_t i = 0; i < _sinks.n_total(); ++i) {
191                         _elements.push_back (CtrlWidget (Sink, (i < _sinks.n_midi () ? DataType::MIDI : DataType::AUDIO), i, n));
192                 }
193                 for (uint32_t i = 0; i < _sources.n_total(); ++i) {
194                         _elements.push_back (CtrlWidget (Source, (i < _sources.n_midi () ? DataType::MIDI : DataType::AUDIO), i, n));
195                 }
196         }
197         _position_valid = false;
198         darea.queue_draw ();
199 }
200
201 void
202 PluginPinDialog::update_element_pos ()
203 {
204         /* layout sizes */
205         const double yc   = rint (_height * .5);
206         const double bxh2 = 18;
207         const double bxw  = rint ((_width * .9) / ((_n_plugins) + .2 * (_n_plugins - 1)));
208         const double bxw2 = rint (bxw * .5);
209         const double y_in = 40;
210         const double y_out = _height - 40;
211
212         _pin_box_size = rint (max (6., 8. * UIConfiguration::instance().get_ui_scale()));
213
214         for (CtrlElemList::iterator i = _elements.begin(); i != _elements.end(); ++i) {
215                 switch (i->e->ct) {
216                         case Input:
217                                 i->x = rint ((i->e->id + 1) * _width / (1. + _in.n_total ())) - 5.5;
218                                 i->y = y_in - 25;
219                                 i->w = 10;
220                                 i->h = 25;
221                                 break;
222                         case Output:
223                                 i->x = rint ((i->e->id + 1) * _width / (1. + _out.n_total ())) - 5.5;
224                                 i->y = y_out;
225                                 i->w = 10;
226                                 i->h = 25;
227                                 break;
228                         case Sink:
229                                 {
230                                         const double x0 = rint ((i->e->ip + .5) * _width / (double)(_n_plugins)) - .5 - bxw2;
231                                         i->x = rint (x0 + (i->e->id + 1) * bxw / (1. + _sinks.n_total ())) - .5 - _pin_box_size * .5;
232                                         i->y = yc - bxh2 - _pin_box_size;
233                                         i->w = _pin_box_size + 1;
234                                         i->h = _pin_box_size;
235                                 }
236                                 break;
237                         case Source:
238                                 {
239                                         const double x0 = rint ((i->e->ip + .5) * _width / (double)(_n_plugins)) - .5 - bxw2;
240                                         i->x = rint (x0 + (i->e->id + 1) * bxw / (1. + _sources.n_total ())) - .5 - _pin_box_size * .5;
241                                         i->y = yc + bxh2;
242                                         i->w = _pin_box_size + 1;
243                                         i->h = _pin_box_size;
244                                 }
245                                 break;
246                 }
247         }
248
249 }
250
251 void
252 PluginPinDialog::set_color (cairo_t* cr, bool midi)
253 {
254         // see also gtk2_ardour/processor_box.cc
255         static const uint32_t audio_port_color = 0x4A8A0EFF; // Green
256         static const uint32_t midi_port_color = 0x960909FF; //Red
257
258         if (midi) {
259                 cairo_set_source_rgb (cr,
260                                 UINT_RGBA_R_FLT(midi_port_color),
261                                 UINT_RGBA_G_FLT(midi_port_color),
262                                 UINT_RGBA_B_FLT(midi_port_color));
263         } else {
264                 cairo_set_source_rgb (cr,
265                                 UINT_RGBA_R_FLT(audio_port_color),
266                                 UINT_RGBA_G_FLT(audio_port_color),
267                                 UINT_RGBA_B_FLT(audio_port_color));
268         }
269 }
270
271 void
272 PluginPinDialog::draw_io_pin (cairo_t* cr, const CtrlWidget& w)
273 {
274         const double dir = (w.e->ct == Input) ? 1 : -1;
275
276         cairo_move_to (cr, w.x + 5.0, w.y + ((w.e->ct == Input) ? 25 : 0));
277         cairo_rel_line_to (cr, -5.,  -5. * dir);
278         cairo_rel_line_to (cr,  0., -25. * dir);
279         cairo_rel_line_to (cr, 10.,   0.);
280         cairo_rel_line_to (cr,  0.,  25. * dir);
281         cairo_close_path  (cr);
282
283         cairo_set_line_width (cr, 1.0);
284         cairo_set_source_rgb (cr, 0, 0, 0);
285         cairo_stroke_preserve (cr);
286
287         set_color (cr, w.e->dt == DataType::MIDI);
288         if (w.e == _selection || w.e == _actor) {
289                 cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
290         } else if (w.prelight) {
291                 cairo_fill_preserve (cr);
292                 cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.5);
293         }
294         cairo_fill (cr);
295 }
296
297 void
298 PluginPinDialog::draw_plugin_pin (cairo_t* cr, const CtrlWidget& w)
299 {
300         cairo_rectangle (cr, w.x, w.y, w.w, w.h);
301         set_color (cr, w.e->dt == DataType::MIDI);
302         if (w.e == _selection || w.e == _actor) {
303                 cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
304         } else if (w.prelight) {
305                 cairo_fill_preserve (cr);
306                 cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.5);
307         }
308         cairo_fill (cr);
309 }
310
311 bool
312 PluginPinDialog::is_valid_port (uint32_t i, uint32_t n_total, uint32_t n_midi, bool midi)
313 {
314         if (!midi) { i += n_midi; }
315         if (i >= n_total) {
316                 return false;
317         }
318         return true;
319 }
320
321 double
322 PluginPinDialog::pin_x_pos (uint32_t i, double x0, double width, uint32_t n_total, uint32_t n_midi, bool midi)
323 {
324         if (!midi) { i += n_midi; }
325         return rint (x0 + (i + 1) * width / (1. + n_total)) - .5;
326 }
327
328 void
329 PluginPinDialog::draw_connection (cairo_t* cr, double x0, double x1, double y0, double y1, bool midi, bool dashed)
330 {
331         const double bz = 2 * _pin_box_size;
332
333         cairo_move_to (cr, x0, y0);
334         cairo_curve_to (cr, x0, y0 + bz, x1, y1 - bz, x1, y1);
335         cairo_set_line_width (cr, 3.0);
336         cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
337         cairo_set_source_rgb (cr, 1, 0, 0);
338         if (dashed) {
339                 const double dashes[] = { 5, 7 };
340                 cairo_set_dash (cr, dashes, 2, 0);
341         }
342         set_color (cr, midi);
343         cairo_stroke (cr);
344         if (dashed) {
345                 cairo_set_dash (cr, 0, 0, 0);
346         }
347 }
348
349 bool
350 PluginPinDialog::darea_expose_event (GdkEventExpose* ev)
351 {
352         Gtk::Allocation a = darea.get_allocation();
353         double const width = a.get_width();
354         double const height = a.get_height();
355
356         if (!_position_valid) {
357                 _width = width;
358                 _height = height;
359                 update_element_pos ();
360                 _position_valid = true;
361         }
362
363         cairo_t* cr = gdk_cairo_create (darea.get_window()->gobj());
364         cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
365         cairo_clip (cr);
366
367         Gdk::Color const bg = get_style()->get_bg (STATE_NORMAL);
368         cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
369         cairo_rectangle (cr, 0, 0, width, height);
370         cairo_fill (cr);
371
372         /* layout sizes  -- TODO consolidate w/ update_element_pos() */
373         // i/o pins
374         const double y_in = 40;
375         const double y_out = height - 40;
376
377         // plugin box(es)
378         const double yc   = rint (height * .5);
379         const double bxh2 = 18;
380         const double bxw  = rint ((width * .9) / ((_n_plugins) + .2 * (_n_plugins - 1)));
381         const double bxw2 = rint (bxw * .5);
382
383         const uint32_t pc_in = _in.n_total();
384         const uint32_t pc_in_midi = _in.n_midi();
385         const uint32_t pc_out = _out.n_total();
386         const uint32_t pc_out_midi = _out.n_midi();
387
388         /* draw midi-bypass (behind) */
389         if (_pi->has_midi_bypass ()) {
390                 double x0 = rint (width / (1. + pc_in)) - .5;
391                 double x1 = rint (width / (1. + pc_out)) - .5;
392                 draw_connection (cr, x0, x1, y_in, y_out, true, true);
393         }
394
395         /* plugins & connection wires */
396         for (uint32_t i = 0; i < _n_plugins; ++i) {
397                 double x0 = rint ((i + .5) * width / (double)(_n_plugins)) - .5;
398
399                 /* plugin box */
400                 cairo_set_source_rgb (cr, .3, .3, .3);
401                 rounded_rectangle (cr, x0 - bxw2, yc - bxh2, bxw, 2 * bxh2, 7);
402                 cairo_fill (cr);
403
404                 const ChanMapping::Mappings in_map = _pi->input_map (i).mappings();
405                 const ChanMapping::Mappings out_map = _pi->output_map (i).mappings();
406
407                 for (ChanMapping::Mappings::const_iterator t = in_map.begin (); t != in_map.end (); ++t) {
408                         bool is_midi = t->first == DataType::MIDI;
409                         for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
410                                 uint32_t pn = (*c).first; // pin
411                                 uint32_t pb = (*c).second;
412                                 if (!is_valid_port (pb, pc_in, pc_in_midi, is_midi)) {
413                                         continue;
414                                 }
415                                 double c_x0 = pin_x_pos (pb, 0, width, pc_in, pc_in_midi, is_midi);
416                                 double c_x1 = pin_x_pos (pn, x0 - bxw2, bxw, _sinks.n_total (), _sinks.n_midi (), is_midi);
417                                 draw_connection (cr, c_x0, c_x1, y_in, yc - bxh2 - _pin_box_size, is_midi);
418                         }
419                 }
420
421                 for (ChanMapping::Mappings::const_iterator t = out_map.begin (); t != out_map.end (); ++t) {
422                         bool is_midi = t->first == DataType::MIDI;
423                         for (ChanMapping::TypeMapping::const_iterator c = (*t).second.begin (); c != (*t).second.end () ; ++c) {
424                                 uint32_t pn = (*c).first; // pin
425                                 uint32_t pb = (*c).second;
426                                 if (!is_valid_port (pb, pc_out, pc_out_midi, is_midi)) {
427                                         continue;
428                                 }
429                                 double c_x0 = pin_x_pos (pn, x0 - bxw2, bxw, _sources.n_total (), _sources.n_midi (), is_midi);
430                                 double c_x1 = pin_x_pos (pb, 0, width, pc_out, pc_out_midi, is_midi);
431                                 draw_connection (cr, c_x0, c_x1, yc + bxh2 + _pin_box_size, y_out, is_midi);
432                         }
433                 }
434         }
435
436         /* pins and ports */
437         for (CtrlElemList::const_iterator i = _elements.begin(); i != _elements.end(); ++i) {
438                 switch (i->e->ct) {
439                         case Input:
440                         case Output:
441                                 draw_io_pin (cr, *i);
442                                 break;
443                         case Sink:
444                         case Source:
445                                 draw_plugin_pin (cr, *i);
446                                 break;
447                 }
448         }
449
450         cairo_destroy (cr);
451         return true;
452 }
453
454 void
455 PluginPinDialog::darea_size_allocate (Gtk::Allocation&)
456 {
457         _position_valid = false;
458 }
459
460 bool
461 PluginPinDialog::darea_motion_notify_event (GdkEventMotion* ev)
462 {
463         bool changed = false;
464         _hover.reset ();
465         for (CtrlElemList::iterator i = _elements.begin(); i != _elements.end(); ++i) {
466                 if (ev->x >= i->x && ev->x <= i->x + i->w
467                                 && ev->y >= i->y && ev->y <= i->y + i->h)
468                 {
469                         if (!i->prelight) changed = true;
470                         i->prelight = true;
471                         _hover = i->e;
472                 } else {
473                         if (i->prelight) changed = true;
474                         i->prelight = false;
475                 }
476         }
477         if (changed) {
478                 darea.queue_draw ();
479         }
480         return true;
481 }
482
483 bool
484 PluginPinDialog::darea_button_press_event (GdkEventButton* ev)
485 {
486         if (ev->type != GDK_BUTTON_PRESS) {
487                 return false;
488         }
489
490         switch (ev->button) {
491                 case 1:
492                         if (!_selection || (_selection && !_hover)) {
493                                 _selection = _hover;
494                                 _actor.reset ();
495                                 darea.queue_draw ();
496                         } else if (_selection && _hover && _selection != _hover) {
497                                 if (_selection->dt != _hover->dt) { _actor.reset (); }
498                                 else if (_selection->ct == Input && _hover->ct == Sink) { _actor = _hover; }
499                                 else if (_selection->ct == Sink && _hover->ct == Input) { _actor = _hover; }
500                                 else if (_selection->ct == Output && _hover->ct == Source) { _actor = _hover; }
501                                 else if (_selection->ct == Source && _hover->ct == Output) { _actor = _hover; }
502                                 if (!_actor) {
503                                 _selection = _hover;
504                                 }
505                                 darea.queue_draw ();
506                         }
507                 case 3:
508                         if (_hover) {
509                         }
510                         break;
511                 default:
512                         break;
513         }
514
515         return true;
516 }
517
518 bool
519 PluginPinDialog::darea_button_release_event (GdkEventButton* ev)
520 {
521         if (_hover == _actor && _actor) {
522                 assert (_selection);
523                 assert (_selection->dt == _actor->dt);
524                 if      (_selection->ct == Input && _actor->ct == Sink) {
525                         handle_input_action (_actor, _selection);
526                 }
527                 else if (_selection->ct == Sink && _actor->ct == Input) {
528                         handle_input_action (_selection, _actor);
529                 }
530                 else if (_selection->ct == Output && _actor->ct == Source) {
531                         handle_output_action (_actor, _selection);
532                 }
533                 else if (_selection->ct == Source && _actor->ct == Output) {
534                         handle_output_action (_selection, _actor);
535                 }
536                 _selection.reset ();
537         }
538         _actor.reset ();
539         darea.queue_draw ();
540         return true;
541 }
542
543 void
544 PluginPinDialog::handle_input_action (const CtrlElem &s, const CtrlElem &i)
545 {
546         const int pc = s->ip;
547         bool valid;
548         ChanMapping in_map (_pi->input_map (pc));
549         uint32_t idx = in_map.get (s->dt, s->id, &valid);
550
551         if (valid && idx == i->id) {
552                 // disconnect
553                 in_map.unset (s->dt, s->id);
554                 _pi->set_input_map (pc, in_map);
555         }
556         else if (!valid) {
557                 // connect
558                 in_map.set (s->dt, s->id, i->id);
559                 _pi->set_input_map (pc, in_map);
560         }
561         else {
562                 // reconnect
563                 in_map.unset (s->dt, s->id);
564                 in_map.set (s->dt, s->id, i->id);
565                 _pi->set_input_map (pc, in_map);
566         }
567 }
568
569 void
570 PluginPinDialog::handle_output_action (const CtrlElem &s, const CtrlElem &o)
571 {
572         const int pc = s->ip;
573         bool valid;
574         ChanMapping out_map (_pi->output_map (pc));
575         uint32_t idx = out_map.get (s->dt, s->id, &valid);
576
577         if (valid && idx == o->id) {
578                 // disconnect
579                 out_map.unset (s->dt, s->id);
580                 _pi->set_output_map (pc, out_map);
581         }
582         else {
583                 // disconnect source
584                 if (valid) {
585                         out_map.unset (s->dt, s->id);
586                 }
587                 // disconnect other outputs
588                 _ignore_updates = true;
589                 for (uint32_t n = 0; n < _n_plugins; ++n) {
590                         if (n == pc) {
591                                 continue;
592                         }
593                         ChanMapping n_out_map (_pi->output_map (n));
594                         idx = n_out_map.get_src (s->dt, o->id, &valid);
595                         if (valid) {
596                                 n_out_map.unset (s->dt, idx);
597                                 _pi->set_output_map (n, n_out_map);
598                         }
599                 }
600                 _ignore_updates = false;
601                 idx = out_map.get_src (s->dt, o->id, &valid);
602                 if (valid) {
603                         out_map.unset (s->dt, idx);
604                 }
605                 // connect
606                 out_map.set (s->dt, s->id, o->id);
607                 _pi->set_output_map (pc, out_map);
608         }
609 }
610
611 void
612 PluginPinDialog::automatic_clicked ()
613 {
614         _route()->reset_plugin_insert (_pi);
615 }
616
617 void
618 PluginPinDialog::add_remove_plugin_clicked (bool add)
619 {
620         ChanCount out = _out;
621         assert (add || _n_plugins > 0);
622         _route()->customize_plugin_insert (_pi, _n_plugins + (add ? 1 : -1),  out);
623 }
624
625 void
626 PluginPinDialog::add_remove_port_clicked (bool add, ARDOUR::DataType dt)
627 {
628         ChanCount out = _out;
629         assert (add || out.get (dt) > 0);
630         out.set (dt, out.get (dt) + (add ? 1 : -1));
631         _route()->customize_plugin_insert (_pi, _n_plugins, out);
632 }