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