Gnime::Canvas::Points init fix
[ardour.git] / gtk2_ardour / io_selector.cc
1 /*
2     Copyright (C) 2002-2003 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id$
19 */
20
21 #include <map>
22 #include <vector>
23
24 #include <pbd/lockmonitor.h>
25
26 #include <ardour/io.h>
27 #include <ardour/route.h>
28 #include <ardour/audioengine.h>
29 #include <ardour/port.h>
30 #include <ardour/insert.h>
31 #include <ardour/session.h>
32 #include <ardour/diskstream.h>
33
34 #include <gtkmm2ext/doi.h>
35 #include <gtkmm2ext/gtk_ui.h>
36
37 #include "utils.h"
38 #include "ardour_message.h"
39 #include "io_selector.h"
40 #include "keyboard.h"
41 #include "gui_thread.h"
42
43 #include "i18n.h"
44
45 using namespace std;
46 using namespace Gtk;
47 using namespace sigc;
48 using namespace ARDOUR;
49
50 IOSelectorWindow::IOSelectorWindow (Session& sess, IO& ior, bool input, bool can_cancel)
51         : ArdourDialog ("i/o selector"),
52           _selector (sess, ior, input),
53           ok_button (can_cancel ? _("OK"): _("Close")),
54           cancel_button (_("Cancel")),
55           rescan_button (_("Rescan"))
56
57 {
58         add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
59         set_name ("IOSelectorWindow");
60
61         string title;
62         if (input) {
63                 title = string_compose(_("%1 input"), ior.name());
64         } else {
65                 title = string_compose(_("%1 output"), ior.name());
66         }
67
68         ok_button.set_name ("IOSelectorButton");
69         cancel_button.set_name ("IOSelectorButton");
70         rescan_button.set_name ("IOSelectorButton");
71
72         button_box.set_spacing (5);
73         button_box.set_border_width (5);
74         button_box.set_homogeneous (true);
75         button_box.pack_start (rescan_button);
76
77         if (can_cancel) {
78                 button_box.pack_start (cancel_button);
79         }
80         else {
81                 cancel_button.hide();
82         }
83                 
84         button_box.pack_start (ok_button);
85
86         vbox.pack_start (_selector);
87         vbox.pack_start (button_box, false, false);
88
89         ok_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::accept));
90         cancel_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::cancel));
91         rescan_button.signal_clicked().connect (mem_fun(*this, &IOSelectorWindow::rescan));
92
93         set_title (title);
94         set_position (Gtk::WIN_POS_MOUSE);
95         add (vbox);
96
97         signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window *> (this)));
98 }
99
100 IOSelectorWindow::~IOSelectorWindow()
101 {
102 }
103
104 void
105 IOSelectorWindow::rescan ()
106 {
107         _selector.redisplay ();
108 }
109
110 void
111 IOSelectorWindow::cancel ()
112 {
113         _selector.Finished(IOSelector::Cancelled);
114         hide ();
115 }
116
117 void
118 IOSelectorWindow::accept ()
119 {
120         _selector.Finished(IOSelector::Accepted);
121         hide ();
122 }
123
124
125 bool
126 IOSelectorWindow::on_map (GdkEventAny *ev)
127 {
128         _selector.redisplay ();
129         return Window::on_map (ev);
130 }
131
132 /*************************
133   The IO Selector "widget"
134  *************************/  
135
136 IOSelector::IOSelector (Session& sess, IO& ior, bool input)
137         : session (sess),
138           io (ior),
139           for_input (input),
140           port_frame (for_input? _("Inputs") : _("Outputs")),
141           add_port_button (for_input? _("Add Input") : _("Add Output")),
142           remove_port_button (for_input? _("Remove Input") : _("Remove Output")),
143           clear_connections_button (_("Disconnect All"))
144 {
145         selected_port = 0;
146
147         notebook.set_name ("IOSelectorNotebook");
148         notebook.set_size_request (-1, 125);
149
150         clear_connections_button.set_name ("IOSelectorButton");
151         add_port_button.set_name ("IOSelectorButton");
152         remove_port_button.set_name ("IOSelectorButton");
153
154         selector_frame.set_name ("IOSelectorFrame");
155         port_frame.set_name ("IOSelectorFrame");
156
157         selector_frame.set_label (_("Available connections"));
158         
159         selector_button_box.set_spacing (5);
160         selector_button_box.set_border_width (5);
161
162         selector_box.set_spacing (5);
163         selector_box.set_border_width (5);
164         selector_box.pack_start (notebook);
165         selector_box.pack_start (selector_button_box, false, false);
166
167         selector_frame.add (selector_box);
168
169         port_box.set_spacing (5);
170         port_box.set_border_width (5);
171
172         port_display_scroller.set_name ("IOSelectorNotebook");
173         port_display_scroller.set_border_width (0);
174         port_display_scroller.set_size_request (-1, 170);
175         port_display_scroller.add (port_box);
176         port_display_scroller.set_policy (Gtk::POLICY_NEVER,
177                                           Gtk::POLICY_AUTOMATIC);
178
179         port_button_box.set_spacing (5);
180         port_button_box.set_border_width (5);
181
182         port_button_box.pack_start (add_port_button, false, false);
183
184         if (for_input) {
185                 if (io.input_maximum() < 0 || io.input_maximum() > (int) io.n_inputs()) {
186                         add_port_button.set_sensitive (true);
187                 } else {
188                         add_port_button.set_sensitive (false);
189                 }
190
191         } else {
192                 if (io.output_maximum() < 0 || io.output_maximum() > (int) io.n_outputs()) {
193                         add_port_button.set_sensitive (true);
194                 } else {
195                         add_port_button.set_sensitive (false);
196                 }
197                         
198         }
199
200         port_button_box.pack_start (remove_port_button, false, false);
201
202         if (for_input) {
203                 if (io.input_minimum() < 0 || io.input_minimum() < (int) io.n_inputs()) {
204                         remove_port_button.set_sensitive (true);
205                 } else {
206                         remove_port_button.set_sensitive (false);
207                 }
208                         
209         } else {
210                 if (io.output_minimum() < 0 || io.output_minimum() < (int) io.n_outputs()) {
211                         remove_port_button.set_sensitive (true);
212                 } else {
213                         remove_port_button.set_sensitive (false);
214                 }
215         }
216
217         port_button_box.pack_start (clear_connections_button, false, false);
218
219         port_and_button_box.set_border_width (5);
220         port_and_button_box.pack_start (port_button_box, false, false);
221         port_and_button_box.pack_start (port_display_scroller);
222
223         port_frame.add (port_and_button_box);
224
225         port_and_selector_box.set_spacing (5);
226         port_and_selector_box.pack_start (port_frame);
227         port_and_selector_box.pack_start (selector_frame);
228
229         set_spacing (5);
230         set_border_width (5);
231         pack_start (port_and_selector_box);
232
233         rescan();
234         display_ports ();
235
236         clear_connections_button.signal_clicked().connect (mem_fun(*this, &IOSelector::clear_connections));
237
238         add_port_button.signal_clicked().connect (mem_fun(*this, &IOSelector::add_port));
239         remove_port_button.signal_clicked().connect (mem_fun(*this, &IOSelector::remove_port));
240
241         if (for_input) {
242                 io.input_changed.connect (mem_fun(*this, &IOSelector::ports_changed));
243         } else {
244                 io.output_changed.connect (mem_fun(*this, &IOSelector::ports_changed));
245         }
246
247         io.name_changed.connect (mem_fun(*this, &IOSelector::name_changed));
248 }
249
250 IOSelector::~IOSelector ()
251 {
252 }
253
254 void
255 IOSelector::name_changed (void* src)
256 {
257         ENSURE_GUI_THREAD(bind (mem_fun(*this, &IOSelector::name_changed), src));
258         
259         display_ports ();
260 }
261
262 void
263 IOSelector::clear_connections ()
264 {
265         if (for_input) {
266                 io.disconnect_inputs (this);
267         } else {
268                 io.disconnect_outputs (this);
269         }
270 }
271
272 void
273 IOSelector::rescan ()
274 {
275         using namespace Notebook_Helpers;
276         using namespace CList_Helpers;
277
278         typedef std::map<string,vector<pair<string,string> > > PortMap;
279         PortMap portmap;
280         const char **ports;
281         PageList& pages = notebook.pages();
282         gint current_page;
283         vector<string> rowdata;
284
285         current_page = notebook.get_current_page_num ();
286         pages.clear ();
287
288         /* get relevant current JACK ports */
289
290         ports = session.engine().get_ports ("", JACK_DEFAULT_AUDIO_TYPE, for_input?JackPortIsOutput:JackPortIsInput);
291
292         if (ports == 0) {
293                 return;
294         }
295
296         /* find all the client names and group their ports into a list-by-client */
297         
298         for (int n = 0; ports[n]; ++n) {
299
300                 pair<string,vector<pair<string,string> > > newpair;
301                 pair<string,string> strpair;
302                 std::pair<PortMap::iterator,bool> result;
303
304                 string str = ports[n];
305                 string::size_type pos;
306                 string portname;
307
308                 pos = str.find (':');
309
310                 newpair.first = str.substr (0, pos); 
311                 portname = str.substr (pos+1);
312
313                 /* this may or may not succeed at actually inserting. 
314                    we don't care, however: we just want an iterator
315                    that gives us either the inserted element or
316                    the existing one with the same name.
317                 */
318
319                 result = portmap.insert (newpair);
320
321                 strpair.first = portname;
322                 strpair.second = str;
323
324                 result.first->second.push_back (strpair);
325         }
326
327         PortMap::iterator i;
328
329         for (i = portmap.begin(); i != portmap.end(); ++i) {
330                 
331                 Box *client_box = manage (new VBox);
332                 Gtk::CList *client_port_display = manage (new Gtk::CList (1));
333                 ScrolledWindow *scroller = manage (new ScrolledWindow);
334
335                 scroller->add (*client_port_display);
336                 scroller->set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
337
338                 client_box->pack_start (*scroller);
339
340                 client_port_display->set_selection_mode (Gtk::SELECTION_BROWSE);
341                 client_port_display->set_name ("IOSelectorList");
342
343                 for (vector<pair<string,string> >::iterator s = i->second.begin(); s != i->second.end(); ++s) {
344                         
345                         rowdata.clear ();
346                         rowdata.push_back (s->first);
347                         client_port_display->rows().push_back (rowdata);
348                         client_port_display->rows().back().set_data (g_strdup (s->second.c_str()), free);
349                 }
350
351                 client_port_display->columns_autosize ();
352                 client_port_display->select_row.connect (bind (mem_fun(*this, &IOSelector::port_selection_handler), client_port_display));
353
354                 Label *tab_label = manage (new Label);
355
356                 tab_label->set_name ("IOSelectorNotebookTab");
357                 tab_label->set_text ((*i).first);
358
359                 pages.push_back (TabElem (*client_box, *tab_label));
360         }
361
362         notebook.set_page (current_page);
363         notebook.signal_show().connect (bind (mem_fun (notebook, &Notebook::set_current_page), current_page));
364         selector_box.show_all ();
365 }       
366
367 void
368 IOSelector::display_ports ()
369 {
370         CList *clist = 0;
371         CList *firstclist = 0;
372         CList *selected_port_list = 0;
373
374         {
375                 LockMonitor lm (port_display_lock, __LINE__, __FILE__);
376                 Port *port;
377                 uint32_t limit;
378
379                 if (for_input) {
380                         limit = io.n_inputs();
381                 } else {
382                         limit = io.n_outputs();
383                 }
384
385                 for (slist<CList *>::iterator i = port_displays.begin(); i != port_displays.end(); ) {
386                 
387                         slist<CList *>::iterator tmp;
388
389                         tmp = i;
390                         ++tmp;
391
392                         port_box.remove (**i);
393                         delete *i;
394                         port_displays.erase (i);
395
396                         i = tmp;
397                 } 
398
399                 for (uint32_t n = 0; n < limit; ++n) {
400                         const gchar *title[1];
401                         string really_short_name;
402
403                         if (for_input) {
404                                 port = io.input (n);
405                         } else {
406                                 port = io.output (n);
407                         }
408
409                         /* we know there is '/' because we put it there */
410
411                         really_short_name = port->short_name();
412                         really_short_name = really_short_name.substr (really_short_name.find ('/') + 1);
413
414                         title[0] = really_short_name.c_str();
415                         clist = new CList (1, title);
416                         if (!firstclist) {
417                                 firstclist = clist;
418                         }
419                         
420                         port_displays.insert (port_displays.end(), clist);
421                         port_box.pack_start (*clist);
422
423                         clist->set_data (_("port"), port);
424
425                         /* XXX THIS IS A DIGUSTING AND DIRTY HACK, FORCED UPON US BECAUSE
426                            GtkCList DOESN'T PROVIDE ANY WAY TO CONNECT TO BUTTON_PRESS_EVENTS
427                            FOR THE COLUMN TITLE BUTTON.
428                          */
429
430                         clist->column(0).get_widget();  // force the column title button to be created
431                         GtkButton *b = GTK_BUTTON(clist->gobj()->column[0].button); // no API to access this
432                         Gtk::Button *B = Glib::wrap (b); // make C++ signal handling easier.
433
434                         clist->column_titles_show ();
435                         clist->column_titles_active ();
436
437                         if (for_input) {
438
439                                 if (io.input_maximum() == 1) {
440                                         selected_port = port;
441                                         selected_port_list = clist;
442                                 } else {
443                                         if (port == selected_port) {
444                                                 selected_port_list = clist;
445                                         }
446                                 }
447                                 
448                                 B->signal_button_release_event().connect 
449                                         (bind (mem_fun(*this, &IOSelector::port_column_button_release), clist));
450                         
451                         } else {
452
453                                 if (io.output_maximum() == 1) {
454                                         selected_port = port;
455                                         selected_port_list = clist;
456                                 } else {
457                                         if (port == selected_port) {
458                                                 selected_port_list = clist;
459                                         }
460                                 }
461
462                                 B->signal_button_release_event().connect 
463                                         (bind (mem_fun(*this, &IOSelector::port_column_button_release), clist));
464                         }
465
466                         clist->set_name ("IOSelectorPortList");
467                         clist->set_selection_mode (Gtk::SELECTION_SINGLE);
468                         clist->set_shadow_type (Gtk::SHADOW_IN);
469                         clist->set_size_request (-1, 75);
470
471                         /* now fill the clist with the current connections */
472
473                         const char **connections = port->get_connections ();
474
475                         if (connections) {
476
477                                 for (uint32_t c = 0; connections[c]; ++c) {
478                                         
479                                         const gchar *txt[1];
480                                 
481                                         txt[0] = connections[c];
482
483                                         clist->rows().push_back (txt);
484                                 }
485
486                                 free (connections);
487                         }
488
489                         clist->columns_autosize ();
490                         clist->signal_button_release_event().connect (bind (mem_fun(*this, &IOSelector::connection_click), clist));
491                 }
492
493                 port_box.show_all ();
494
495                 if (selected_port_list) {
496                         selected_port_list->click_column(0);
497                         selected_port_list->set_name ("IOSelectorPortListSelected");
498                         for (slist<CList *>::iterator i = port_displays.begin(); i != port_displays.end(); ++i) {
499                                 if (*i != selected_port_list) {
500                                         (*i)->set_name ("IOSelectorPortList");
501                                         (*i)->queue_draw ();
502                                 }
503                         }
504                 } else {
505                         selected_port = 0;
506                         selector_box.hide_all ();
507                 }
508         }
509         
510         if (selected_port_list) {
511                 select_clist (selected_port_list);
512         } else if (firstclist) {
513                 // select first
514                 select_clist (firstclist);
515         }
516 }
517
518 void
519 IOSelector::port_selection_handler (gint row, gint col, GdkEvent *ev, Gtk::CList *clist)
520 {
521         using namespace CList_Helpers;
522         int status;
523
524         if (selected_port == 0) {
525                 return;
526         }
527
528         string other_port_name = (char *) clist->rows()[row].get_data();
529
530         if (for_input) {
531                 if ((status = io.connect_input (selected_port, other_port_name, this)) == 0) {
532                         Port *p = session.engine().get_port_by_name (other_port_name);
533                         p->enable_metering();
534                 }
535         } else {
536                 status = io.connect_output (selected_port, other_port_name, this);
537         }
538
539         if (status == 0) {
540                 select_next_clist ();
541         }
542 }
543
544 void
545 IOSelector::ports_changed (IOChange change, void *src)
546 {
547         ENSURE_GUI_THREAD(bind (mem_fun(*this, &IOSelector::ports_changed), change, src));
548         
549         display_ports ();
550 }
551
552 void
553 IOSelector::add_port ()
554 {
555         /* add a new port, then hide the button if we're up to the maximum allowed */
556
557         if (for_input) {
558
559
560                 try {
561
562                         io.add_input_port ("", this);
563                 }
564
565                 catch (AudioEngine::PortRegistrationFailure& err) {
566                         ArdourMessage msg (0,  X_("noport dialog"),
567                                            _("There are no more JACK ports available."));
568                 }
569
570                 if (io.input_maximum() >= 0 && io.input_maximum() <= (int) io.n_inputs()) {
571                         add_port_button.set_sensitive (false);
572                 }
573                 
574                 if (io.input_minimum() < (int) io.n_inputs()) {
575                         remove_port_button.set_sensitive (true);
576                 }
577
578         } else {
579
580                 try {
581                         io.add_output_port ("", this);
582                 }
583
584                 catch (AudioEngine::PortRegistrationFailure& err) {
585                         ArdourMessage msg (0, X_("noport dialog"),
586                                            _("There are no more JACK ports available."));
587                 }
588
589                 if (io.output_maximum() >= 0 && io.output_maximum() <= (int) io.n_outputs()) {
590                         add_port_button.set_sensitive (false);
591                 }
592         }
593 }
594
595 void
596 IOSelector::remove_port ()
597 {
598         // always remove last port
599         uint32_t nports;
600         
601         if (for_input) {
602                 if ((nports = io.n_inputs()) > 0) {
603                         io.remove_input_port (io.input(nports-1), this);
604                 }
605                 if (io.input_minimum() == (int) io.n_inputs()) {
606                         remove_port_button.set_sensitive (false);
607                 }
608         } else {
609                 if ((nports = io.n_outputs()) > 0) {
610                         io.remove_output_port (io.output(nports-1), this);
611                 }
612         }
613 }
614
615 gint
616 IOSelector::remove_port_when_idle (Port *port)
617 {
618         if (for_input) {
619                 io.remove_input_port (port, this);
620         } else {
621                 io.remove_output_port (port, this);
622         }
623
624         return FALSE;
625 }
626
627 gint
628 IOSelector::port_column_button_release (GdkEventButton *event, CList *clist)
629 {
630         if (Keyboard::is_delete_event (event)) {
631                 Port* port;
632                 {
633                         LockMonitor lm (port_display_lock, __LINE__, __FILE__);
634                         
635                         port = reinterpret_cast<Port *> (clist->get_data (_("port")));
636                         
637                         if (port == selected_port) {
638                                 selected_port = 0;
639                                 clist->set_name ("IOSelectorPortList");
640                                 clist->queue_draw();
641                         }
642                 }
643
644                 /* remove the port when idle - if we do it here, we will destroy the widget
645                    for whom we are handling an event. not good.
646                 */
647
648                 Glib::signal_idle().connect (bind (mem_fun(*this, &IOSelector::remove_port_when_idle), port));
649
650         } else {
651                 select_clist(clist);
652         }
653
654         return TRUE;
655 }
656
657 void
658 IOSelector::select_next_clist ()
659 {
660         slist<CList*>::iterator next;
661
662         for (slist<CList *>::iterator i = port_displays.begin(); i != port_displays.end(); ++i) {
663
664                 if ((*i)->get_name() == "IOSelectorPortListSelected") {
665
666                         ++i;
667
668                         if (i == port_displays.end()) {
669                                 select_clist (port_displays.front());
670                         } else {
671                                 select_clist (*i);
672                         }
673                         
674                         break;
675                 }
676         }
677 }
678
679 void
680 IOSelector::select_clist(Gtk::CList* clist)
681 {
682         /* Gack. CList's don't respond visually to a change
683            in their state, so rename them to force a style
684            switch.
685         */
686         LockMonitor lm (port_display_lock, __LINE__, __FILE__);
687         Port* port = reinterpret_cast<Port *> (clist->get_data (_("port")));
688         
689         if (port != selected_port) {
690                 selected_port = port;
691                 
692                 clist->set_name ("IOSelectorPortListSelected");
693                 
694                 for (slist<CList *>::iterator i = port_displays.begin(); i != port_displays.end(); ++i) {
695                         if (*i != clist) {
696                                 (*i)->set_name ("IOSelectorPortList");
697                                 (*i)->queue_draw ();
698                         }
699                 }
700                 selector_box.show_all ();
701         }
702 }
703
704 gint
705 IOSelector::connection_click (GdkEventButton *ev, CList *clist)
706 {
707         gint row, col;
708
709         /* only handle button1 events here */
710
711         if (ev->button != 1) {
712                 return FALSE;
713         }
714
715         if (clist->get_selection_info ((int)ev->x, (int)ev->y, &row, &col) == 0) {
716                 return FALSE;
717         }
718
719         if (row < 0 || col < 0) {
720                 return FALSE;
721         }
722
723         Port *port = reinterpret_cast<Port *> (clist->get_data (_("port")));
724         string connected_port_name = clist->cell(row,col).get_text ();
725
726         if (for_input) {
727                 Port *p = session.engine().get_port_by_name (connected_port_name);
728                 p->disable_metering();
729                 io.disconnect_input (port, connected_port_name, this);
730         } else {
731                 io.disconnect_output (port, connected_port_name, this);
732         }
733
734         return TRUE;
735 }
736
737 void
738 IOSelector::redisplay ()
739 {
740         display_ports ();
741
742         if (for_input) {
743                 if (io.input_maximum() != 0) {
744                         rescan ();
745                 }
746         } else {
747                 if (io.output_maximum() != 0) {
748                         rescan();
749                 }
750         }
751 }
752
753 PortInsertUI::PortInsertUI (Session& sess, PortInsert& pi)
754         : input_selector (sess, pi, true),
755           output_selector (sess, pi, false)
756 {
757         hbox.pack_start (output_selector, true, true);
758         hbox.pack_start (input_selector, true, true);
759
760
761         pack_start (hbox);
762 }
763
764 void
765 PortInsertUI::redisplay()
766 {
767
768         input_selector.redisplay();
769         output_selector.redisplay();
770 }
771
772 void
773 PortInsertUI::finished(IOSelector::Result r)
774 {
775         input_selector.Finished (r);
776         output_selector.Finished (r);
777 }
778
779
780 PortInsertWindow::PortInsertWindow (Session& sess, PortInsert& pi, bool can_cancel)
781         : ArdourDialog ("port insert dialog"),
782           _portinsertui(sess, pi),
783           ok_button (can_cancel ? _("OK"): _("Close")),
784           cancel_button (_("Cancel")),
785           rescan_button (_("Rescan"))
786 {
787
788         set_name ("IOSelectorWindow");
789         string title = _("ardour: ");
790         title += pi.name();
791         set_title (title);
792         
793         ok_button.set_name ("IOSelectorButton");
794         cancel_button.set_name ("IOSelectorButton");
795         rescan_button.set_name ("IOSelectorButton");
796
797         button_box.set_spacing (5);
798         button_box.set_border_width (5);
799         button_box.set_homogeneous (true);
800         button_box.pack_start (rescan_button);
801         if (can_cancel) {
802                 button_box.pack_start (cancel_button);
803         }
804         else {
805                 cancel_button.hide();
806         }
807         button_box.pack_start (ok_button);
808
809         vbox.pack_start (_portinsertui);
810         vbox.pack_start (button_box, false, false);
811
812         add (vbox);
813
814         ok_button.signal_clicked().connect (mem_fun(*this, &PortInsertWindow::accept));
815         cancel_button.signal_clicked().connect (mem_fun(*this, &PortInsertWindow::cancel));
816         rescan_button.signal_clicked().connect (mem_fun(*this, &PortInsertWindow::rescan));
817
818         signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window *> (this))); 
819         pi.GoingAway.connect (mem_fun(*this, &PortInsertWindow::plugin_going_away));
820 }
821
822 void
823 PortInsertWindow::plugin_going_away (ARDOUR::Redirect* ignored)
824 {
825         ENSURE_GUI_THREAD(bind (mem_fun(*this, &PortInsertWindow::plugin_going_away), ignored));
826         
827         delete_when_idle (this);
828 }
829
830 gint
831 PortInsertWindow::on_map (GdkEventAny *ev)
832 {
833         _portinsertui.redisplay ();
834         return Window::on_map (ev);
835 }
836
837
838 void
839 PortInsertWindow::rescan ()
840 {
841         _portinsertui.redisplay();
842 }
843
844 void
845 PortInsertWindow::cancel ()
846 {
847         _portinsertui.finished(IOSelector::Cancelled);
848         hide ();
849 }
850
851 void
852 PortInsertWindow::accept ()
853 {
854         _portinsertui.finished(IOSelector::Accepted);
855         hide ();
856 }