move all destructive functionality into SndFileSource as a mode, and drop Destructive...
[ardour.git] / gtk2_ardour / option_editor.cc
1 /*
2     Copyright (C) 2001-2006 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 <pbd/whitespace.h>
22
23 #include <ardour/audio_library.h>
24 #include <ardour/session.h>
25 #include <ardour/audioengine.h>
26 #include <ardour/configuration.h>
27 #include <ardour/auditioner.h>
28 #include <ardour/destructive_filesource.h>
29 #include <ardour/crossfade.h>
30 #include <midi++/manager.h>
31 #include <gtkmm2ext/stop_signal.h>
32 #include <gtkmm2ext/utils.h>
33
34 #include "public_editor.h"
35 #include "mixer_ui.h"
36 #include "ardour_ui.h"
37 #include "io_selector.h"
38 #include "gain_meter.h"
39 #include "sfdb_ui.h"
40 #include "utils.h"
41 #include "editing.h"
42 #include "option_editor.h"
43
44 #include "i18n.h"
45
46 using namespace ARDOUR;
47 using namespace PBD;
48 using namespace Gtk;
49 using namespace Editing;
50 using namespace Gtkmm2ext;
51 using namespace std;
52
53 static vector<string> positional_sync_strings;
54
55 OptionEditor::OptionEditor (ARDOUR_UI& uip, PublicEditor& ed, Mixer_UI& mixui)
56         : Dialog ("option editor"),
57           ui (uip),
58           editor (ed),
59           mixer (mixui),
60
61           /* Paths */
62           path_table (11, 2),
63           sfdb_path_view(),
64
65           /* Fades */
66
67           short_xfade_adjustment (0, 1.0, 500.0, 5.0, 100.0),
68           short_xfade_slider (short_xfade_adjustment),
69           destructo_xfade_adjustment (1.0, 1.0, 500.0, 1.0, 100.0),
70           destructo_xfade_slider (destructo_xfade_adjustment),
71
72           /* Sync */
73
74           smpte_offset_clock (X_("SMPTEOffsetClock"), true, true),
75           smpte_offset_negative_button (_("SMPTE offset is negative")),
76
77           /* MIDI */
78
79           /* Click */
80
81           click_table (2, 3),
82           click_browse_button (_("Browse")),
83           click_emphasis_browse_button (_("Browse")),
84
85           /* kbd/mouse */
86
87           keyboard_mouse_table (3, 4),
88           delete_button_adjustment (3, 1, 5),
89           delete_button_spin (delete_button_adjustment),
90           edit_button_adjustment (3, 1, 5),
91           edit_button_spin (edit_button_adjustment)
92           
93 {
94         using namespace Notebook_Helpers;
95
96         click_io_selector = 0;
97         auditioner_io_selector = 0;
98         session = 0;
99
100         set_default_size (300, 300);
101         set_title (_("ardour: options editor"));
102         set_wmclass (_("ardour_option_editor"), "Ardour");
103
104         set_name ("OptionsWindow");
105         add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
106         
107         VBox *vbox = get_vbox();
108         set_border_width (3);
109
110         vbox->set_spacing (4);
111         vbox->pack_start(notebook);
112
113         signal_delete_event().connect (mem_fun(*this, &OptionEditor::wm_close));
114
115         notebook.set_show_tabs (true);
116         notebook.set_show_border (true);
117         notebook.set_name ("OptionsNotebook");
118
119         setup_sync_options();
120         setup_path_options();
121         setup_fade_options ();
122         setup_keyboard_options ();
123         setup_auditioner_editor ();
124
125         notebook.pages().push_back (TabElem (sync_packer, _("Sync")));
126         notebook.pages().push_back (TabElem (path_table, _("Paths/Files")));
127         notebook.pages().push_back (TabElem (keyboard_mouse_table, _("Kbd/Mouse")));
128         notebook.pages().push_back (TabElem (click_packer, _("Click")));
129         notebook.pages().push_back (TabElem (audition_packer, _("Audition")));
130         notebook.pages().push_back (TabElem (fade_packer, _("Layers & Fades")));
131
132         if (!MIDI::Manager::instance()->get_midi_ports().empty()) {
133                 setup_midi_options ();
134                 notebook.pages().push_back (TabElem (midi_packer, _("MIDI")));
135         }
136
137         set_session (0);
138         show_all_children();
139 }
140
141 void
142 OptionEditor::set_session (Session *s)
143 {
144         clear_click_editor ();
145         clear_auditioner_editor ();
146
147         click_path_entry.set_text ("");
148         click_emphasis_path_entry.set_text ("");
149         session_raid_entry.set_text ("");
150
151         click_path_entry.set_sensitive (false);
152         click_emphasis_path_entry.set_sensitive (false);
153         session_raid_entry.set_sensitive (false);
154
155         short_xfade_slider.set_sensitive (false);
156         smpte_offset_negative_button.set_sensitive (false);
157
158         smpte_offset_clock.set_session (s);
159
160         if ((session = s) == 0) {
161                 return;
162         }
163
164         click_path_entry.set_sensitive (true);
165         click_emphasis_path_entry.set_sensitive (true);
166         session_raid_entry.set_sensitive (true);
167         short_xfade_slider.set_sensitive (true);
168         smpte_offset_negative_button.set_sensitive (true);
169
170         smpte_offset_clock.set_session (s);
171         smpte_offset_clock.set (s->smpte_offset (), true);
172
173         smpte_offset_negative_button.set_active (session->smpte_offset_negative());
174
175         /* set up port assignments */
176
177         std::map<MIDI::Port*,vector<RadioButton*> >::iterator res;
178
179         if (session->mtc_port()) {
180                 if ((res = port_toggle_buttons.find (session->mtc_port())) != port_toggle_buttons.end()) {
181                         (*res).second[MtcIndex]->set_active (true);
182                 }
183         } 
184
185         if (session->mmc_port ()) {
186                 if ((res = port_toggle_buttons.find (session->mmc_port())) != port_toggle_buttons.end()) {
187                         (*res).second[MmcIndex]->set_active (true);
188                 } 
189         }
190
191         if (session->midi_port()) {
192                 if ((res = port_toggle_buttons.find (session->midi_port())) != port_toggle_buttons.end()) {
193                         (*res).second[MidiIndex]->set_active (true);
194                 }
195         }
196
197         setup_click_editor ();
198         connect_audition_editor ();
199
200         short_xfade_adjustment.set_value ((Crossfade::short_xfade_length() / (float) session->frame_rate()) * 1000.0);
201
202         add_session_paths ();
203 }
204
205 OptionEditor::~OptionEditor ()
206 {
207 }
208
209 void
210 OptionEditor::setup_path_options()
211 {
212         Gtk::Label* label;
213
214         path_table.set_homogeneous (false);
215         path_table.set_border_width (12);
216         path_table.set_row_spacings (5);
217
218         session_raid_entry.set_name ("OptionsEntry");
219
220         session_raid_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::raid_path_changed));
221
222         label = manage(new Label(_("session RAID path")));
223         label->set_name ("OptionsLabel");
224         path_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL);
225         path_table.attach (session_raid_entry, 1, 3, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
226
227         label = manage(new Label(_("Soundfile Search Paths")));
228         label->set_name("OptionsLabel");
229         path_table.attach(*label, 0, 1, 2, 3, FILL|EXPAND, FILL);
230         path_table.attach(sfdb_path_view, 1, 3, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
231
232         sfdb_path_view.set_paths(Library->get_paths());
233         sfdb_path_view.PathsUpdated.connect (mem_fun(*this, &OptionEditor::sfdb_paths_changed));
234
235         path_table.show_all();
236 }
237
238 void
239 OptionEditor::sfdb_paths_changed ()
240 {
241         Library->set_paths (sfdb_path_view.get_paths());
242 }
243
244 void
245 OptionEditor::add_session_paths ()
246 {
247         click_path_entry.set_sensitive (true);
248         click_emphasis_path_entry.set_sensitive (true);
249         session_raid_entry.set_sensitive (true);
250
251         if (Config->get_click_sound().empty()) {
252                 click_path_entry.set_text (_("internal"));
253         } else {
254                 click_path_entry.set_text (Config->get_click_sound());
255         }
256
257         if (Config->get_click_emphasis_sound().empty()) {
258                 click_emphasis_path_entry.set_text (_("internal"));
259         } else {
260                 click_emphasis_path_entry.set_text (Config->get_click_emphasis_sound());
261         }
262
263         session_raid_entry.set_text(session->raid_path());
264 }
265
266 void
267 OptionEditor::setup_fade_options ()
268 {
269         Gtk::HBox* hbox;
270         
271         Label* label = manage (new Label (_("Short crossfade length (msecs)")));
272         label->set_name ("OptionsLabel");
273         
274         hbox = manage (new HBox);
275         hbox->set_border_width (5);
276         hbox->set_spacing (10);
277         hbox->pack_start (*label, false, false);
278         hbox->pack_start (short_xfade_slider, true, true);
279         fade_packer.pack_start (*hbox, false, false);
280
281         short_xfade_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::short_xfade_adjustment_changed));
282
283         label = manage (new Label (_("Destructive crossfade length (msecs)")));
284         label->set_name ("OptionsLabel");
285         
286         hbox = manage (new HBox);
287         hbox->set_border_width (5);
288         hbox->set_spacing (10);
289         hbox->pack_start (*label, false, false);
290         hbox->pack_start (destructo_xfade_slider, true, true);
291         fade_packer.pack_start (*hbox, false, false);
292         
293         destructo_xfade_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::destructo_xfade_adjustment_changed));
294
295         short_xfade_slider.set_update_policy (UPDATE_DISCONTINUOUS);
296         destructo_xfade_slider.set_update_policy (UPDATE_DISCONTINUOUS);
297
298         destructo_xfade_adjustment.set_value (Config->get_destructive_xfade_msecs());
299
300         fade_packer.show_all ();
301 }
302
303 void
304 OptionEditor::short_xfade_adjustment_changed ()
305 {
306         if (session) {
307                 float val = short_xfade_adjustment.get_value();
308                 
309                 /* val is in msecs */
310                 
311                 Crossfade::set_short_xfade_length ((nframes_t) floor (session->frame_rate() * (val / 1000.0)));
312         }
313 }
314
315 void
316 OptionEditor::destructo_xfade_adjustment_changed ()
317 {
318         float val = destructo_xfade_adjustment.get_value();
319
320         /* val is in msecs */
321
322         
323         Config->set_destructive_xfade_msecs ((uint32_t) floor (val));
324
325         cerr << "set destructo fade to " << Config->get_destructive_xfade_msecs () << endl;
326
327         if (session) {
328                 SndFileSource::setup_standard_crossfades (session->frame_rate());
329         } 
330 }
331
332 void
333 OptionEditor::setup_sync_options ()
334 {
335         HBox* hbox;
336         vector<string> dumb;
337
338         smpte_offset_clock.set_mode (AudioClock::SMPTE);
339         smpte_offset_clock.ValueChanged.connect (mem_fun(*this, &OptionEditor::smpte_offset_chosen));
340         
341         smpte_offset_negative_button.set_name ("OptionEditorToggleButton");
342
343         smpte_offset_negative_button.unset_flags (Gtk::CAN_FOCUS);
344
345         Label *smpte_offset_label = manage (new Label (_("SMPTE Offset")));
346         smpte_offset_label->set_name("OptionsLabel");
347         
348         hbox = manage (new HBox);
349         hbox->set_border_width (5);
350         hbox->set_spacing (10);
351         hbox->pack_start (*smpte_offset_label, false, false);
352         hbox->pack_start (smpte_offset_clock, false, false);
353         hbox->pack_start (smpte_offset_negative_button, false, false);
354
355         sync_packer.pack_start (*hbox, false, false);
356
357         smpte_offset_negative_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::smpte_offset_negative_clicked));
358 }
359
360 void
361 OptionEditor::smpte_offset_negative_clicked ()
362 {
363         if (session) {
364                 session->set_smpte_offset_negative (smpte_offset_negative_button.get_active());
365         }
366 }
367
368 void
369 OptionEditor::smpte_offset_chosen()
370 {
371         if (session) {
372                 nframes_t frames = smpte_offset_clock.current_duration();
373                 session->set_smpte_offset (frames);
374         }
375 }
376
377
378 void
379 OptionEditor::setup_midi_options ()
380 {
381         HBox* hbox;
382         MIDI::Manager::PortMap::const_iterator i;
383         const MIDI::Manager::PortMap& ports = MIDI::Manager::instance()->get_midi_ports();
384         int n;
385         ToggleButton* tb;
386         RadioButton* rb;
387
388         Gtk::Table* table = manage (new Table (ports.size() + 4, 9));
389
390         table->set_row_spacings (6);
391         table->set_col_spacings (10);
392
393         table->attach (*(manage (new Label (X_("Port")))), 0, 1, 0, 1);
394         table->attach (*(manage (new Label (X_("Offline")))), 1, 2, 0, 1);
395         table->attach (*(manage (new Label (X_("Trace\nInput")))), 2, 3, 0, 1);
396         table->attach (*(manage (new Label (X_("Trace\nOutput")))), 3, 4, 0, 1);
397         table->attach (*(manage (new Label (X_("MTC")))), 4, 5, 0, 1);
398         table->attach (*(manage (new Label (X_("MMC")))), 6, 7, 0, 1);
399         table->attach (*(manage (new Label (X_("MIDI Parameter\nControl")))), 8, 9, 0, 1);
400
401         table->attach (*(manage (new HSeparator())), 0, 9, 1, 2);
402         table->attach (*(manage (new VSeparator())), 5, 6, 0, 8);
403         table->attach (*(manage (new VSeparator())), 7, 8, 0, 8);
404         
405         for (n = 0, i = ports.begin(); i != ports.end(); ++n, ++i) {
406
407                 pair<MIDI::Port*,vector<RadioButton*> > newpair;
408
409                 newpair.first = i->second;
410
411                 table->attach (*(manage (new Label (i->first))), 0, 1, n+2, n+3,FILL|EXPAND, FILL );
412                 tb = manage (new ToggleButton (_("online")));
413                 tb->set_name ("OptionEditorToggleButton");
414
415                 /* remember, we have to handle the i18n case where the relative
416                    lengths of the strings in language N is different than in english.
417                 */
418
419                 if (strlen (_("offline")) > strlen (_("online"))) {
420                         set_size_request_to_display_given_text (*tb, _("offline"), 15, 12);
421                 } else {
422                         set_size_request_to_display_given_text (*tb, _("online"), 15, 12);
423                 }
424
425                 tb->set_active (!(*i).second->input()->offline());
426                 tb->signal_button_press_event().connect (bind (mem_fun(*this, &OptionEditor::port_online_toggled), (*i).second, tb));
427                 (*i).second->input()->OfflineStatusChanged.connect (bind (mem_fun(*this, &OptionEditor::map_port_online), (*i).second, tb));
428                 table->attach (*tb, 1, 2, n+2, n+3, FILL|EXPAND, FILL);
429
430                 tb = manage (new ToggleButton ());
431                 tb->set_name ("OptionEditorToggleButton");
432                 tb->signal_button_press_event().connect (bind (mem_fun(*this, &OptionEditor::port_trace_in_toggled), (*i).second, tb));
433                 tb->set_size_request (10, 10);
434                 table->attach (*tb, 2, 3, n+2, n+3, FILL|EXPAND, FILL);
435
436                 tb = manage (new ToggleButton ());
437                 tb->set_name ("OptionEditorToggleButton");
438                 tb->signal_button_press_event().connect (bind (mem_fun(*this, &OptionEditor::port_trace_out_toggled), (*i).second, tb));
439                 tb->set_size_request (10, 10);
440                 table->attach (*tb, 3, 4, n+2, n+3, FILL|EXPAND, FILL);
441
442                 rb = manage (new RadioButton ());
443                 newpair.second.push_back (rb);
444                 rb->set_name ("OptionEditorToggleButton");
445                 if (n == 0) {
446                         mtc_button_group = rb->get_group();
447                 } else {
448                         rb->set_group (mtc_button_group);
449
450                 }
451                 table->attach (*rb, 4, 5, n+2, n+3, FILL|EXPAND, FILL);
452                 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::mtc_port_chosen), (*i).second, rb));
453
454                 if (Config->get_mtc_port_name() == i->first) {
455                         rb->set_active (true);
456                 }
457                 
458                 rb = manage (new RadioButton ());
459                 newpair.second.push_back (rb);
460                 rb->set_name ("OptionEditorToggleButton");
461                 if (n == 0) {
462                         mmc_button_group = rb->get_group();
463                 } else {
464                         rb->set_group (mmc_button_group);
465                 }
466                 table->attach (*rb, 6, 7, n+2, n+3, FILL|EXPAND, FILL);
467                 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::mmc_port_chosen), (*i).second, rb));
468
469                 if (Config->get_mmc_port_name() == i->first) {
470                         rb->set_active (true);
471                 }
472
473                 rb = manage (new RadioButton ());
474                 newpair.second.push_back (rb);
475                 rb->set_name ("OptionEditorToggleButton");
476                 if (n == 0) {
477                         midi_button_group = rb->get_group();
478                 } else {
479                         rb->set_group (midi_button_group);
480                 }
481                 table->attach (*rb, 8, 9, n+2, n+3, FILL|EXPAND, FILL);
482                 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::midi_port_chosen), (*i).second, rb));
483
484                 if (Config->get_midi_port_name() == i->first) {
485                         rb->set_active (true);
486                 }
487                 
488                 port_toggle_buttons.insert (newpair);
489         }
490
491         table->show_all ();
492
493         hbox = manage (new HBox);
494         hbox->set_border_width (6);
495         hbox->pack_start (*table, true, false);
496         midi_packer.pack_start (*hbox, false, false);
497 }
498
499 void
500 OptionEditor::mtc_port_chosen (MIDI::Port *port, Gtk::RadioButton* rb) 
501 {
502         if (session) {
503                 if (rb->get_active()) {
504                         cerr << "Activating MTC port " << port->name() << endl;
505                         if (port) {
506                                 session->set_mtc_port (port->name());
507                                 Config->set_mtc_port_name (port->name());
508                         } else {
509                                 session->set_mtc_port ("");
510                         }
511                         rb->set_active (true);
512                 }
513         }
514 }
515
516 void
517 OptionEditor::mmc_port_chosen (MIDI::Port* port, Gtk::RadioButton* rb)
518 {
519         if (session) {
520                 if (rb->get_active()) {
521                         cerr << "Activating MMC port " << port->name() << endl;
522                         if (port) {
523                                 session->set_mmc_port (port->name());
524                                 Config->set_mtc_port_name (port->name());
525                         } else {
526                                 session->set_mmc_port ("");
527                         }
528                         rb->set_active (true);
529                 }
530         }
531 }
532
533 void
534 OptionEditor::midi_port_chosen (MIDI::Port* port, Gtk::RadioButton* rb)
535 {
536         if (session) {
537                 if (rb->get_active()) {
538                         cerr << "Activating MIDI port " << port->name() << endl;
539                         if (port) {
540                                 session->set_midi_port (port->name());
541                                 Config->set_midi_port_name (port->name());
542                         } else {
543                                 session->set_midi_port ("");
544                         }
545                         rb->set_active (true);
546                 }
547         }
548 }
549
550 gint
551 OptionEditor::port_online_toggled (GdkEventButton* ev, MIDI::Port* port, ToggleButton* tb)
552 {
553         bool wanted = tb->get_active(); /* it hasn't changed at this point */
554
555         if (wanted != port->input()->offline()) {
556                 port->input()->set_offline (wanted);
557         } 
558         return stop_signal (*tb, "button_press_event");
559 }
560
561 void
562 OptionEditor::map_port_online (MIDI::Port* port, ToggleButton* tb)
563 {
564         if (port->input()->offline()) {
565                 tb->set_label (_("offline"));
566                 tb->set_active (false);
567         } else {
568                 tb->set_label (_("online"));
569                 tb->set_active (true);
570         }
571 }
572
573 gint
574 OptionEditor::port_trace_in_toggled (GdkEventButton* ev, MIDI::Port* port, ToggleButton* tb)
575 {
576         /* XXX not very good MVC style here */
577
578         port->input()->trace (!tb->get_active(), &cerr, string (port->name()) + string (" input: "));
579         tb->set_active (!tb->get_active());
580         return stop_signal (*tb, "button_press_event");
581 }
582
583 gint
584 OptionEditor::port_trace_out_toggled (GdkEventButton* ev,MIDI::Port* port, ToggleButton* tb)
585 {
586         /* XXX not very good MVC style here */
587
588         port->output()->trace (!tb->get_active(), &cerr, string (port->name()) + string (" output: "));
589         tb->set_active (!tb->get_active());
590         return stop_signal (*tb, "button_press_event");
591 }
592
593 void
594 OptionEditor::save ()
595 {
596         /* XXX a bit odd that we save the entire session state here */
597
598         ui.save_state ("");
599 }
600
601 gint
602 OptionEditor::wm_close (GdkEventAny *ev)
603 {
604         save ();
605         hide ();
606         return TRUE;
607 }
608
609 void
610 OptionEditor::raid_path_changed ()
611 {
612         if (session) {
613                 Config->set_raid_path (session_raid_entry.get_text());
614         }
615 }
616
617 void
618 OptionEditor::click_browse_clicked ()
619 {
620         SoundFileChooser sfdb (_("Choose Click"), session);
621         
622         int result = sfdb.run ();
623
624         if (result == Gtk::RESPONSE_OK) {
625                 click_chosen(sfdb.get_filename());
626         }
627 }
628
629 void
630 OptionEditor::click_chosen (const string & path)
631 {
632         click_path_entry.set_text (path);
633         click_sound_changed ();
634 }
635
636 void
637 OptionEditor::click_emphasis_browse_clicked ()
638 {
639         SoundFileChooser sfdb (_("Choose Click Emphasis"), session);
640
641         int result = sfdb.run ();
642
643         if (result == Gtk::RESPONSE_OK) {
644                 click_emphasis_chosen (sfdb.get_filename());
645         }
646 }
647
648 void
649 OptionEditor::click_emphasis_chosen (const string & path)
650 {       
651         click_emphasis_path_entry.set_text (path);
652         click_emphasis_sound_changed ();
653 }
654
655 void
656 OptionEditor::click_sound_changed ()
657 {
658         if (session) {
659                 string path = click_path_entry.get_text();
660
661                 if (path == Config->get_click_sound()) {
662                         return;
663                 }
664
665                 if (path.empty()) {
666
667                         Config->set_click_sound ("");
668
669                 } else {
670
671                         strip_whitespace_edges (path);
672                         
673                         if (path == _("internal")) {
674                                 Config->set_click_sound ("");
675                         } else {
676                                 Config->set_click_sound (path);
677                         }
678                 }
679         }
680 }
681
682 void
683 OptionEditor::click_emphasis_sound_changed ()
684 {
685         if (session) {
686                 string path = click_emphasis_path_entry.get_text();
687
688                 if (path == Config->get_click_emphasis_sound()) {
689                         return;
690                 }
691
692                 if (path.empty()) {
693
694                         Config->set_click_emphasis_sound ("");
695
696                 } else {
697
698                         strip_whitespace_edges (path);
699
700                         if (path == _("internal")) {
701                                 Config->set_click_emphasis_sound ("");
702                         } else {
703                                 Config->set_click_emphasis_sound (path);
704                         }
705                 }
706         }
707 }
708
709 void
710 OptionEditor::clear_click_editor ()
711 {
712         if (click_io_selector) {
713                 click_packer.remove (*click_io_selector);
714                 click_packer.remove (*click_gpm);
715                 delete click_io_selector;
716                 delete click_gpm;
717                 click_io_selector = 0;
718                 click_gpm = 0;
719         }
720 }
721
722 void
723 OptionEditor::setup_click_editor ()
724 {
725         Label* label;
726         HBox* hpacker = manage (new HBox);
727
728         click_path_entry.set_sensitive (true);
729         click_emphasis_path_entry.set_sensitive (true);
730
731         click_path_entry.set_name ("OptionsEntry");
732         click_emphasis_path_entry.set_name ("OptionsEntry");
733         
734         click_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_sound_changed));
735         click_emphasis_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_emphasis_sound_changed));
736
737         click_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_sound_changed));
738         click_emphasis_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_emphasis_sound_changed));
739
740         click_browse_button.set_name ("EditorGTKButton");
741         click_emphasis_browse_button.set_name ("EditorGTKButton");
742         click_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_browse_clicked));
743         click_emphasis_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_emphasis_browse_clicked));
744
745         click_packer.set_border_width (12);
746         click_packer.set_spacing (5);
747
748         click_io_selector = new IOSelector (*session, session->click_io(), false);
749         click_gpm = new GainMeter (session->click_io(), *session);
750
751         click_table.set_col_spacings (10);
752         
753         label = manage(new Label(_("Click audio file")));
754         label->set_name ("OptionsLabel");
755         click_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL);
756         click_table.attach (click_path_entry, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
757         click_table.attach (click_browse_button, 2, 3, 0, 1, FILL|EXPAND, FILL);
758         
759         label = manage(new Label(_("Click emphasis audiofile")));
760         label->set_name ("OptionsLabel");
761         click_table.attach (*label, 0, 1, 1, 2, FILL|EXPAND, FILL);
762         click_table.attach (click_emphasis_path_entry, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
763         click_table.attach (click_emphasis_browse_button, 2, 3, 1, 2, FILL|EXPAND, FILL);
764
765         hpacker->set_spacing (10);
766         hpacker->pack_start (*click_io_selector, false, false);
767         hpacker->pack_start (*click_gpm, false, false);
768
769         click_packer.pack_start (click_table, false, false);
770         click_packer.pack_start (*hpacker, false, false);
771
772         click_packer.show_all ();
773 }
774
775 void
776 OptionEditor::clear_auditioner_editor ()
777 {
778         if (auditioner_io_selector) {
779                 audition_hpacker.remove (*auditioner_io_selector);
780                 audition_hpacker.remove (*auditioner_gpm);
781                 delete auditioner_io_selector;
782                 delete auditioner_gpm;
783                 auditioner_io_selector = 0;
784                 auditioner_gpm = 0;
785         }
786 }
787
788 void
789 OptionEditor::setup_auditioner_editor ()
790 {
791         audition_packer.set_border_width (12);
792         audition_packer.set_spacing (5);
793         audition_hpacker.set_spacing (10);
794
795         audition_label.set_name ("OptionEditorAuditionerLabel");
796         audition_label.set_text (_("The auditioner is a dedicated mixer strip used\n"
797                                    "for listening to specific regions outside the context\n"
798                                    "of the overall mix. It can be connected just like any\n"
799                                    "other mixer strip."));
800         
801         audition_packer.pack_start (audition_label, false, false, 10);
802         audition_packer.pack_start (audition_hpacker, false, false);
803 }
804
805 void
806 OptionEditor::connect_audition_editor ()
807 {
808         auditioner_io_selector = new IOSelector (*session, session->the_auditioner(), false);
809         auditioner_gpm = new GainMeter (session->the_auditioner(), *session);
810
811         audition_hpacker.pack_start (*auditioner_io_selector, false, false);
812         audition_hpacker.pack_start (*auditioner_gpm, false, false);
813
814         auditioner_io_selector->show_all ();
815         auditioner_gpm->show_all ();
816 }
817
818 bool
819 OptionEditor::focus_out_event_handler (GdkEventFocus* ev, void (OptionEditor::*pmf)()) 
820 {
821         (this->*pmf)();
822         return false;
823 }
824
825 static const struct {
826     const char *name;
827     guint   modifier;
828 } modifiers[] = {
829         { "Shift", GDK_SHIFT_MASK },
830         { "Control", GDK_CONTROL_MASK },
831         { "Alt (Mod1)", GDK_MOD1_MASK },
832         { "Control-Shift", GDK_CONTROL_MASK|GDK_SHIFT_MASK },
833         { "Control-Alt", GDK_CONTROL_MASK|GDK_MOD1_MASK },
834         { "Shift-Alt", GDK_SHIFT_MASK|GDK_MOD1_MASK },
835         { "Control-Shift-Alt", GDK_CONTROL_MASK|GDK_SHIFT_MASK|GDK_MOD1_MASK },
836         { "Mod2", GDK_MOD2_MASK },
837         { "Mod3", GDK_MOD3_MASK },
838         { "Mod4", GDK_MOD4_MASK },
839         { "Mod5", GDK_MOD5_MASK },
840         { 0, 0 }
841 };
842
843 void
844 OptionEditor::setup_keyboard_options ()
845 {
846         vector<string> dumb;
847         Label* label;
848
849         keyboard_mouse_table.set_border_width (12);
850         keyboard_mouse_table.set_row_spacings (5);
851         keyboard_mouse_table.set_col_spacings (5);
852
853         /* internationalize and prepare for use with combos */
854
855         for (int i = 0; modifiers[i].name; ++i) {
856                 dumb.push_back (_(modifiers[i].name));
857         }
858
859         set_popdown_strings (edit_modifier_combo, dumb);
860         edit_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::edit_modifier_chosen));
861
862         for (int x = 0; modifiers[x].name; ++x) {
863                 if (modifiers[x].modifier == Keyboard::edit_modifier ()) {
864                         edit_modifier_combo.set_active_text (_(modifiers[x].name));
865                         break;
866                 }
867         }
868
869         label = manage (new Label (_("Edit using")));
870         label->set_name ("OptionsLabel");
871         label->set_alignment (1.0, 0.5);
872                 
873         keyboard_mouse_table.attach (*label, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
874         keyboard_mouse_table.attach (edit_modifier_combo, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
875
876         label = manage (new Label (_("+ button")));
877         label->set_name ("OptionsLabel");
878         
879         keyboard_mouse_table.attach (*label, 3, 4, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
880         keyboard_mouse_table.attach (edit_button_spin, 4, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
881
882         edit_button_spin.set_name ("OptionsEntry");
883         edit_button_adjustment.set_value (Keyboard::edit_button());
884         edit_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::edit_button_changed));
885
886         set_popdown_strings (delete_modifier_combo, dumb);
887         delete_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::delete_modifier_chosen));
888
889         for (int x = 0; modifiers[x].name; ++x) {
890                 if (modifiers[x].modifier == Keyboard::delete_modifier ()) {
891                         delete_modifier_combo.set_active_text (_(modifiers[x].name));
892                         break;
893                 }
894         }
895
896         label = manage (new Label (_("Delete using")));
897         label->set_name ("OptionsLabel");
898         label->set_alignment (1.0, 0.5);
899                 
900         keyboard_mouse_table.attach (*label, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
901         keyboard_mouse_table.attach (delete_modifier_combo, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
902
903         label = manage (new Label (_("+ button")));
904         label->set_name ("OptionsLabel");
905
906         keyboard_mouse_table.attach (*label, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
907         keyboard_mouse_table.attach (delete_button_spin, 4, 5, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
908
909         delete_button_spin.set_name ("OptionsEntry");
910         delete_button_adjustment.set_value (Keyboard::delete_button());
911         delete_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::delete_button_changed));
912
913         set_popdown_strings (snap_modifier_combo, dumb);
914         snap_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::snap_modifier_chosen));
915         
916         for (int x = 0; modifiers[x].name; ++x) {
917                 if (modifiers[x].modifier == (guint) Keyboard::snap_modifier ()) {
918                         snap_modifier_combo.set_active_text (_(modifiers[x].name));
919                         break;
920                 }
921         }
922
923         label = manage (new Label (_("Ignore snap using")));
924         label->set_name ("OptionsLabel");
925         label->set_alignment (1.0, 0.5);
926         
927         keyboard_mouse_table.attach (*label, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
928         keyboard_mouse_table.attach (snap_modifier_combo, 1, 2, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
929 }
930
931 void
932 OptionEditor::edit_modifier_chosen ()
933 {
934         string txt;
935         
936         txt = edit_modifier_combo.get_active_text();
937
938         for (int i = 0; modifiers[i].name; ++i) {
939                 if (txt == _(modifiers[i].name)) {
940                         Keyboard::set_edit_modifier (modifiers[i].modifier);
941                         break;
942                 }
943         }
944 }
945
946 void
947 OptionEditor::delete_modifier_chosen ()
948 {
949         string txt;
950         
951         txt = delete_modifier_combo.get_active_text();
952
953         for (int i = 0; modifiers[i].name; ++i) {
954                 if (txt == _(modifiers[i].name)) {
955                         Keyboard::set_delete_modifier (modifiers[i].modifier);
956                         break;
957                 }
958         }
959 }
960
961 void
962 OptionEditor::snap_modifier_chosen ()
963 {
964         string txt;
965         
966         txt = snap_modifier_combo.get_active_text();
967
968         for (int i = 0; modifiers[i].name; ++i) {
969                 if (txt == _(modifiers[i].name)) {
970                         Keyboard::set_snap_modifier (modifiers[i].modifier);
971                         break;
972                 }
973         }
974 }
975
976 void
977 OptionEditor::delete_button_changed ()
978 {
979         Keyboard::set_delete_button ((guint) delete_button_adjustment.get_value());
980 }
981
982 void
983 OptionEditor::edit_button_changed ()
984 {
985         Keyboard::set_edit_button ((guint) edit_button_adjustment.get_value());
986 }
987
988 void
989 OptionEditor::fixup_combo_size (Gtk::ComboBoxText& combo, vector<string>& strings)
990 {
991         /* find the widest string */
992
993         string::size_type maxlen = 0;
994         string maxstring;
995
996         for (vector<string>::iterator i = strings.begin(); i != strings.end(); ++i) {
997                 string::size_type l;
998
999                 if ((l = (*i).length()) > maxlen) {
1000                         maxlen = l;
1001                         maxstring = *i;
1002                 }
1003         }
1004
1005         /* try to include ascenders and descenders */
1006
1007         if (maxstring.length() > 2) {
1008                 maxstring[0] = 'g';
1009                 maxstring[1] = 'l';
1010         }
1011
1012         const guint32 FUDGE = 10; // Combo's are stupid - they steal space from the entry for the button
1013
1014         set_size_request_to_display_given_text (combo, maxstring.c_str(), 10 + FUDGE, 10);
1015 }
1016