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