add a persistent folder variable so that every time the sfdb_ui is created, it shows...
[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                         if (port) {
487                                 session->set_mtc_port (port->name());
488                                 Config->set_mtc_port_name (port->name());
489                         } else {
490                                 session->set_mtc_port ("");
491                         }
492                         rb->set_active (true);
493                 }
494         }
495 }
496
497 void
498 OptionEditor::mmc_port_chosen (MIDI::Port* port, Gtk::RadioButton* rb)
499 {
500         if (session) {
501                 if (rb->get_active()) {
502                         if (port) {
503                                 session->set_mmc_port (port->name());
504                                 Config->set_mtc_port_name (port->name());
505                         } else {
506                                 session->set_mmc_port ("");
507                         }
508                         rb->set_active (true);
509                 }
510         }
511 }
512
513 void
514 OptionEditor::midi_port_chosen (MIDI::Port* port, Gtk::RadioButton* rb)
515 {
516         if (session) {
517                 if (rb->get_active()) {
518                         if (port) {
519                                 session->set_midi_port (port->name());
520                                 Config->set_midi_port_name (port->name());
521                         } else {
522                                 session->set_midi_port ("");
523                         }
524                         rb->set_active (true);
525                 }
526         }
527 }
528
529 void
530 OptionEditor::port_online_toggled (MIDI::Port* port, ToggleButton* tb)
531 {
532         bool wanted = tb->get_active();
533
534         if (wanted != port->input()->offline()) {
535                 port->input()->set_offline (wanted);
536         } 
537 }
538
539 void
540 OptionEditor::map_port_online (MIDI::Port* port, ToggleButton* tb)
541 {
542         bool bstate = tb->get_active ();
543
544         if (bstate != port->input()->offline()) {
545                 if (port->input()->offline()) {
546                         tb->set_label (_("offline"));
547                         tb->set_active (false);
548                 } else {
549                         tb->set_label (_("online"));
550                         tb->set_active (true);
551                 }
552         }
553 }
554
555 void
556 OptionEditor::port_trace_in_toggled (MIDI::Port* port, ToggleButton* tb)
557 {
558         bool trace = tb->get_active();
559
560         if (port->input()->tracing() != trace) {
561                 port->output()->trace (trace, &cerr, string (port->name()) + string (" input: "));
562         }
563 }
564
565 void
566 OptionEditor::port_trace_out_toggled (MIDI::Port* port, ToggleButton* tb)
567 {
568         bool trace = tb->get_active();
569
570         if (port->output()->tracing() != trace) {
571                 port->output()->trace (trace, &cerr, string (port->name()) + string (" output: "));
572         }
573 }
574
575 void
576 OptionEditor::save ()
577 {
578         /* XXX a bit odd that we save the entire session state here */
579
580         ui.save_state ("");
581 }
582
583 gint
584 OptionEditor::wm_close (GdkEventAny *ev)
585 {
586         save ();
587         hide ();
588         return TRUE;
589 }
590
591 void
592 OptionEditor::raid_path_changed ()
593 {
594         if (session) {
595                 Config->set_raid_path (session_raid_entry.get_text());
596         }
597 }
598
599 void
600 OptionEditor::click_browse_clicked ()
601 {
602         SoundFileChooser sfdb (_("Choose Click"), session);
603         
604         int result = sfdb.run ();
605
606         if (result == Gtk::RESPONSE_OK) {
607                 click_chosen(sfdb.get_filename());
608         }
609 }
610
611 void
612 OptionEditor::click_chosen (const string & path)
613 {
614         click_path_entry.set_text (path);
615         click_sound_changed ();
616 }
617
618 void
619 OptionEditor::click_emphasis_browse_clicked ()
620 {
621         SoundFileChooser sfdb (_("Choose Click Emphasis"), session);
622
623         int result = sfdb.run ();
624
625         if (result == Gtk::RESPONSE_OK) {
626                 click_emphasis_chosen (sfdb.get_filename());
627         }
628 }
629
630 void
631 OptionEditor::click_emphasis_chosen (const string & path)
632 {       
633         click_emphasis_path_entry.set_text (path);
634         click_emphasis_sound_changed ();
635 }
636
637 void
638 OptionEditor::click_sound_changed ()
639 {
640         if (session) {
641                 string path = click_path_entry.get_text();
642
643                 if (path == Config->get_click_sound()) {
644                         return;
645                 }
646
647                 strip_whitespace_edges (path);
648
649                 if (path == _("internal")) {
650                         Config->set_click_sound ("");
651                 } else {
652                         Config->set_click_sound (path);
653                 }
654         }
655 }
656
657 void
658 OptionEditor::click_emphasis_sound_changed ()
659 {
660         if (session) {
661                 string path = click_emphasis_path_entry.get_text();
662
663                 if (path == Config->get_click_emphasis_sound()) {
664                         return;
665                 }
666
667                 strip_whitespace_edges (path);
668
669                 if (path == _("internal")) {
670                         Config->set_click_emphasis_sound ("");
671                 } else {
672                         Config->set_click_emphasis_sound (path);
673                 }
674         }
675 }
676
677 void
678 OptionEditor::clear_click_editor ()
679 {
680         if (click_io_selector) {
681                 click_packer.remove (*click_io_selector);
682                 click_packer.remove (*click_gpm);
683                 delete click_io_selector;
684                 delete click_gpm;
685                 click_io_selector = 0;
686                 click_gpm = 0;
687         }
688 }
689
690 void
691 OptionEditor::setup_click_editor ()
692 {
693         Label* label;
694         HBox* hpacker = manage (new HBox);
695
696         click_path_entry.set_sensitive (true);
697         click_emphasis_path_entry.set_sensitive (true);
698
699         click_path_entry.set_name ("OptionsEntry");
700         click_emphasis_path_entry.set_name ("OptionsEntry");
701         
702         click_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_sound_changed));
703         click_emphasis_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_emphasis_sound_changed));
704
705         click_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_sound_changed));
706         click_emphasis_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_emphasis_sound_changed));
707
708         click_browse_button.set_name ("EditorGTKButton");
709         click_emphasis_browse_button.set_name ("EditorGTKButton");
710         click_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_browse_clicked));
711         click_emphasis_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_emphasis_browse_clicked));
712
713         click_packer.set_border_width (12);
714         click_packer.set_spacing (5);
715
716         click_io_selector = new IOSelector (*session, session->click_io(), false);
717         click_gpm = new GainMeter (session->click_io(), *session);
718
719         click_table.set_col_spacings (10);
720         
721         label = manage(new Label(_("Click audio file")));
722         label->set_name ("OptionsLabel");
723         click_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL);
724         click_table.attach (click_path_entry, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
725         click_table.attach (click_browse_button, 2, 3, 0, 1, FILL|EXPAND, FILL);
726         
727         label = manage(new Label(_("Click emphasis audiofile")));
728         label->set_name ("OptionsLabel");
729         click_table.attach (*label, 0, 1, 1, 2, FILL|EXPAND, FILL);
730         click_table.attach (click_emphasis_path_entry, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
731         click_table.attach (click_emphasis_browse_button, 2, 3, 1, 2, FILL|EXPAND, FILL);
732
733         hpacker->set_spacing (10);
734         hpacker->pack_start (*click_io_selector, false, false);
735         hpacker->pack_start (*click_gpm, false, false);
736
737         click_packer.pack_start (click_table, false, false);
738         click_packer.pack_start (*hpacker, false, false);
739
740         click_packer.show_all ();
741 }
742
743 void
744 OptionEditor::clear_auditioner_editor ()
745 {
746         if (auditioner_io_selector) {
747                 audition_hpacker.remove (*auditioner_io_selector);
748                 audition_hpacker.remove (*auditioner_gpm);
749                 delete auditioner_io_selector;
750                 delete auditioner_gpm;
751                 auditioner_io_selector = 0;
752                 auditioner_gpm = 0;
753         }
754 }
755
756 void
757 OptionEditor::setup_auditioner_editor ()
758 {
759         audition_packer.set_border_width (12);
760         audition_packer.set_spacing (5);
761         audition_hpacker.set_spacing (10);
762
763         audition_label.set_name ("OptionEditorAuditionerLabel");
764         audition_label.set_text (_("The auditioner is a dedicated mixer strip used\n"
765                                    "for listening to specific regions outside the context\n"
766                                    "of the overall mix. It can be connected just like any\n"
767                                    "other mixer strip."));
768         
769         audition_packer.pack_start (audition_label, false, false, 10);
770         audition_packer.pack_start (audition_hpacker, false, false);
771 }
772
773 void
774 OptionEditor::connect_audition_editor ()
775 {
776         auditioner_io_selector = new IOSelector (*session, session->the_auditioner(), false);
777         auditioner_gpm = new GainMeter (session->the_auditioner(), *session);
778
779         audition_hpacker.pack_start (*auditioner_io_selector, false, false);
780         audition_hpacker.pack_start (*auditioner_gpm, false, false);
781
782         auditioner_io_selector->show_all ();
783         auditioner_gpm->show_all ();
784 }
785
786 bool
787 OptionEditor::focus_out_event_handler (GdkEventFocus* ev, void (OptionEditor::*pmf)()) 
788 {
789         (this->*pmf)();
790         return false;
791 }
792
793 static const struct {
794     const char *name;
795     guint   modifier;
796 } modifiers[] = {
797         { "Shift", GDK_SHIFT_MASK },
798         { "Control", GDK_CONTROL_MASK },
799         { "Alt (Mod1)", GDK_MOD1_MASK },
800         { "Control-Shift", GDK_CONTROL_MASK|GDK_SHIFT_MASK },
801         { "Control-Alt", GDK_CONTROL_MASK|GDK_MOD1_MASK },
802         { "Shift-Alt", GDK_SHIFT_MASK|GDK_MOD1_MASK },
803         { "Control-Shift-Alt", GDK_CONTROL_MASK|GDK_SHIFT_MASK|GDK_MOD1_MASK },
804         { "Mod2", GDK_MOD2_MASK },
805         { "Mod3", GDK_MOD3_MASK },
806         { "Mod4", GDK_MOD4_MASK },
807         { "Mod5", GDK_MOD5_MASK },
808         { 0, 0 }
809 };
810
811 void
812 OptionEditor::setup_keyboard_options ()
813 {
814         vector<string> dumb;
815         Label* label;
816
817         keyboard_mouse_table.set_border_width (12);
818         keyboard_mouse_table.set_row_spacings (5);
819         keyboard_mouse_table.set_col_spacings (5);
820
821         /* internationalize and prepare for use with combos */
822
823         for (int i = 0; modifiers[i].name; ++i) {
824                 dumb.push_back (_(modifiers[i].name));
825         }
826
827         set_popdown_strings (edit_modifier_combo, dumb);
828         edit_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::edit_modifier_chosen));
829
830         for (int x = 0; modifiers[x].name; ++x) {
831                 if (modifiers[x].modifier == Keyboard::edit_modifier ()) {
832                         edit_modifier_combo.set_active_text (_(modifiers[x].name));
833                         break;
834                 }
835         }
836
837         label = manage (new Label (_("Edit using")));
838         label->set_name ("OptionsLabel");
839         label->set_alignment (1.0, 0.5);
840                 
841         keyboard_mouse_table.attach (*label, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
842         keyboard_mouse_table.attach (edit_modifier_combo, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
843
844         label = manage (new Label (_("+ button")));
845         label->set_name ("OptionsLabel");
846         
847         keyboard_mouse_table.attach (*label, 3, 4, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
848         keyboard_mouse_table.attach (edit_button_spin, 4, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
849
850         edit_button_spin.set_name ("OptionsEntry");
851         edit_button_adjustment.set_value (Keyboard::edit_button());
852         edit_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::edit_button_changed));
853
854         set_popdown_strings (delete_modifier_combo, dumb);
855         delete_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::delete_modifier_chosen));
856
857         for (int x = 0; modifiers[x].name; ++x) {
858                 if (modifiers[x].modifier == Keyboard::delete_modifier ()) {
859                         delete_modifier_combo.set_active_text (_(modifiers[x].name));
860                         break;
861                 }
862         }
863
864         label = manage (new Label (_("Delete using")));
865         label->set_name ("OptionsLabel");
866         label->set_alignment (1.0, 0.5);
867                 
868         keyboard_mouse_table.attach (*label, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
869         keyboard_mouse_table.attach (delete_modifier_combo, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
870
871         label = manage (new Label (_("+ button")));
872         label->set_name ("OptionsLabel");
873
874         keyboard_mouse_table.attach (*label, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
875         keyboard_mouse_table.attach (delete_button_spin, 4, 5, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
876
877         delete_button_spin.set_name ("OptionsEntry");
878         delete_button_adjustment.set_value (Keyboard::delete_button());
879         delete_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::delete_button_changed));
880
881         set_popdown_strings (snap_modifier_combo, dumb);
882         snap_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::snap_modifier_chosen));
883         
884         for (int x = 0; modifiers[x].name; ++x) {
885                 if (modifiers[x].modifier == (guint) Keyboard::snap_modifier ()) {
886                         snap_modifier_combo.set_active_text (_(modifiers[x].name));
887                         break;
888                 }
889         }
890
891         label = manage (new Label (_("Ignore snap using")));
892         label->set_name ("OptionsLabel");
893         label->set_alignment (1.0, 0.5);
894         
895         keyboard_mouse_table.attach (*label, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
896         keyboard_mouse_table.attach (snap_modifier_combo, 1, 2, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
897 }
898
899 void
900 OptionEditor::edit_modifier_chosen ()
901 {
902         string txt;
903         
904         txt = edit_modifier_combo.get_active_text();
905
906         for (int i = 0; modifiers[i].name; ++i) {
907                 if (txt == _(modifiers[i].name)) {
908                         Keyboard::set_edit_modifier (modifiers[i].modifier);
909                         break;
910                 }
911         }
912 }
913
914 void
915 OptionEditor::delete_modifier_chosen ()
916 {
917         string txt;
918         
919         txt = delete_modifier_combo.get_active_text();
920
921         for (int i = 0; modifiers[i].name; ++i) {
922                 if (txt == _(modifiers[i].name)) {
923                         Keyboard::set_delete_modifier (modifiers[i].modifier);
924                         break;
925                 }
926         }
927 }
928
929 void
930 OptionEditor::snap_modifier_chosen ()
931 {
932         string txt;
933         
934         txt = snap_modifier_combo.get_active_text();
935
936         for (int i = 0; modifiers[i].name; ++i) {
937                 if (txt == _(modifiers[i].name)) {
938                         Keyboard::set_snap_modifier (modifiers[i].modifier);
939                         break;
940                 }
941         }
942 }
943
944 void
945 OptionEditor::delete_button_changed ()
946 {
947         Keyboard::set_delete_button ((guint) delete_button_adjustment.get_value());
948 }
949
950 void
951 OptionEditor::edit_button_changed ()
952 {
953         Keyboard::set_edit_button ((guint) edit_button_adjustment.get_value());
954 }
955
956 void
957 OptionEditor::fixup_combo_size (Gtk::ComboBoxText& combo, vector<string>& strings)
958 {
959         /* find the widest string */
960
961         string::size_type maxlen = 0;
962         string maxstring;
963
964         for (vector<string>::iterator i = strings.begin(); i != strings.end(); ++i) {
965                 string::size_type l;
966
967                 if ((l = (*i).length()) > maxlen) {
968                         maxlen = l;
969                         maxstring = *i;
970                 }
971         }
972
973         /* try to include ascenders and descenders */
974
975         if (maxstring.length() > 2) {
976                 maxstring[0] = 'g';
977                 maxstring[1] = 'l';
978         }
979
980         const guint32 FUDGE = 10; // Combo's are stupid - they steal space from the entry for the button
981
982         set_size_request_to_display_given_text (combo, maxstring.c_str(), 10 + FUDGE, 10);
983 }
984