merge from 2.0-ongoing @ 3581
[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 #include <pango/pangoft2.h> // for fontmap resolution control for GnomeCanvas
20 #include <pango/pangocairo.h> // for fontmap resolution control for GnomeCanvas
21
22 #include <pbd/whitespace.h>
23
24 #include <ardour/ardour.h>
25 #include <ardour/session.h>
26 #include <ardour/audioengine.h>
27 #include <ardour/configuration.h>
28 #include <ardour/auditioner.h>
29 #include <ardour/sndfilesource.h>
30 #include <ardour/crossfade.h>
31 #include <midi++/manager.h>
32 #include <midi++/factory.h>
33 #include <gtkmm2ext/stop_signal.h>
34 #include <gtkmm2ext/utils.h>
35 #include <gtkmm2ext/window_title.h>
36
37 #include "public_editor.h"
38 #include "keyboard.h"
39 #include "mixer_ui.h"
40 #include "ardour_ui.h"
41 #include "io_selector.h"
42 #include "gain_meter.h"
43 #include "sfdb_ui.h"
44 #include "utils.h"
45 #include "editing.h"
46 #include "option_editor.h"
47 #include "midi_port_dialog.h"
48 #include "gui_thread.h"
49 #include "utils.h"
50
51 #include "i18n.h"
52
53 using namespace ARDOUR;
54 using namespace PBD;
55 using namespace Gtk;
56 using namespace Editing;
57 using namespace Gtkmm2ext;
58 using namespace std;
59
60 static vector<string> positional_sync_strings;
61
62 OptionEditor::OptionEditor (ARDOUR_UI& uip, PublicEditor& ed, Mixer_UI& mixui)
63         : ArdourDialog ("options editor", false),
64           ui (uip),
65           editor (ed),
66           mixer (mixui),
67
68           /* Paths */
69           path_table (11, 2),
70
71           /* misc */
72
73           short_xfade_adjustment (0, 1.0, 500.0, 5.0, 100.0),
74           short_xfade_slider (short_xfade_adjustment),
75           destructo_xfade_adjustment (1.0, 1.0, 500.0, 1.0, 100.0),
76           destructo_xfade_slider (destructo_xfade_adjustment),
77           history_depth (20, -1, 100, 1.0, 10.0),
78           saved_history_depth (20, 0, 100, 1.0, 10.0),
79           history_depth_spinner (history_depth),
80           saved_history_depth_spinner (saved_history_depth),
81           limit_history_button (_("Limit undo history")),
82           save_history_button (_("Save undo history")),
83
84           /* Sync */
85
86           smpte_offset_clock (X_("smpteoffset"), false, X_("SMPTEOffsetClock"), true, true),
87           smpte_offset_negative_button (_("SMPTE offset is negative")),
88           synced_timecode_button (_("Timecode source is sample-clock synced")),
89
90           /* MIDI */
91
92           midi_port_table (4, 12),
93           mmc_receive_device_id_adjustment (0.0, 0.0, (double) 0x7f, 1.0, 16.0),
94           mmc_receive_device_id_spinner (mmc_receive_device_id_adjustment),
95           mmc_send_device_id_adjustment (0.0, 0.0, (double) 0x7f, 1.0, 16.0),
96           mmc_send_device_id_spinner (mmc_send_device_id_adjustment),
97           add_midi_port_button (_("Add new MIDI port")),
98
99           /* Click */
100
101           click_table (2, 3),
102           click_browse_button (_("Browse")),
103           click_emphasis_browse_button (_("Browse")),
104
105           /* kbd/mouse */
106
107           keyboard_mouse_table (4, 4),
108           delete_button_adjustment (3, 1, 5),
109           delete_button_spin (delete_button_adjustment),
110           edit_button_adjustment (3, 1, 5),
111           edit_button_spin (edit_button_adjustment)
112
113 {
114         using namespace Notebook_Helpers;
115
116         first_click_setup = true;
117         click_io_selector = 0;
118         auditioner_io_selector = 0;
119         session = 0;
120
121         WindowTitle title(Glib::get_application_name());
122         title += _("Preferences");
123         set_title(title.get_string());
124
125         set_default_size (300, 300);
126         set_wmclass (X_("ardour_preferences"), "Ardour");
127
128         set_name ("Preferences");
129         add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
130
131         VBox *vbox = get_vbox();
132         set_border_width (3);
133
134         vbox->set_spacing (4);
135         vbox->pack_start(notebook);
136
137         signal_delete_event().connect (mem_fun(*this, &OptionEditor::wm_close));
138
139         notebook.set_show_tabs (true);
140         notebook.set_show_border (true);
141         notebook.set_name ("OptionsNotebook");
142
143         setup_sync_options();
144         setup_path_options();
145         setup_misc_options ();
146         setup_keyboard_options ();
147         setup_auditioner_editor ();
148
149         notebook.pages().push_back (TabElem (sync_packer, _("Sync")));
150         notebook.pages().push_back (TabElem (path_table, _("Paths/Files")));
151         notebook.pages().push_back (TabElem (keyboard_mouse_table, _("Kbd/Mouse")));
152         notebook.pages().push_back (TabElem (click_packer, _("Click")));
153         notebook.pages().push_back (TabElem (audition_packer, _("Audition")));
154         notebook.pages().push_back (TabElem (misc_packer, _("Misc")));
155
156         setup_midi_options ();
157         notebook.pages().push_back (TabElem (midi_packer, _("MIDI")));
158
159         set_session (0);
160         show_all_children();
161
162         Config->map_parameters (mem_fun (*this, &OptionEditor::parameter_changed));
163         Config->ParameterChanged.connect (mem_fun (*this, &OptionEditor::parameter_changed));
164 }
165
166 void
167 OptionEditor::set_session (Session *s)
168 {
169         clear_click_editor ();
170         clear_auditioner_editor ();
171
172         click_path_entry.set_text ("");
173         click_emphasis_path_entry.set_text ("");
174         session_raid_entry.set_text ("");
175
176         click_path_entry.set_sensitive (false);
177         click_emphasis_path_entry.set_sensitive (false);
178         session_raid_entry.set_sensitive (false);
179
180         short_xfade_slider.set_sensitive (false);
181         smpte_offset_negative_button.set_sensitive (false);
182
183         smpte_offset_clock.set_session (s);
184
185         if ((session = s) == 0) {
186                 return;
187         }
188
189         click_path_entry.set_sensitive (true);
190         click_emphasis_path_entry.set_sensitive (true);
191         session_raid_entry.set_sensitive (true);
192         short_xfade_slider.set_sensitive (true);
193         smpte_offset_negative_button.set_sensitive (true);
194
195         smpte_offset_clock.set_session (s);
196         smpte_offset_clock.set (s->smpte_offset (), true);
197
198         smpte_offset_negative_button.set_active (session->smpte_offset_negative());
199
200         redisplay_midi_ports ();
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 static void
258 font_scale_changed (Gtk::Adjustment* adj)
259 {
260         Config->set_font_scale((long)floor (adj->get_value() * 1024));
261         reset_dpi();
262 }
263
264 void
265 OptionEditor::setup_misc_options ()
266 {
267         Gtk::HBox* hbox;
268         Label* label;
269
270 #ifndef GTKOSX
271         /* font scaling does nothing with GDK/Quartz */
272
273         Gtk::Adjustment* dpi_adj = new Gtk::Adjustment ((double)Config->get_font_scale() / 1024, 50, 250, 1, 10);
274         Gtk::HScale * dpi_range = new Gtk::HScale (*dpi_adj);
275
276         label = manage (new Label (_("Font Scaling")));
277         label->set_name ("OptionsLabel");
278
279         dpi_range->set_update_policy (Gtk::UPDATE_DISCONTINUOUS);
280         dpi_adj->signal_value_changed().connect (bind (sigc::ptr_fun (font_scale_changed), dpi_adj));
281
282         hbox = manage (new HBox);
283         hbox->set_border_width (5);
284         hbox->set_spacing (10);
285         hbox->pack_start (*label, false, false);
286         hbox->pack_start (*dpi_range, true, true);
287         misc_packer.pack_start (*hbox, false, false);
288 #endif
289
290         label = manage (new Label (_("Short crossfade length (msecs)")));
291         label->set_name ("OptionsLabel");
292
293         hbox = manage (new HBox);
294         hbox->set_border_width (5);
295         hbox->set_spacing (10);
296         hbox->pack_start (*label, false, false);
297         hbox->pack_start (short_xfade_slider, true, true);
298         misc_packer.pack_start (*hbox, false, false);
299
300         short_xfade_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::short_xfade_adjustment_changed));
301
302         label = manage (new Label (_("Destructive crossfade length (msecs)")));
303         label->set_name ("OptionsLabel");
304
305         hbox = manage (new HBox);
306         hbox->set_border_width (5);
307         hbox->set_spacing (10);
308         hbox->pack_start (*label, false, false);
309         hbox->pack_start (destructo_xfade_slider, true, true);
310         misc_packer.pack_start (*hbox, false, false);
311
312
313         destructo_xfade_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::destructo_xfade_adjustment_changed));
314
315         hbox = manage (new HBox);
316         hbox->set_border_width (5);
317         hbox->set_spacing (10);
318         hbox->pack_start (limit_history_button, false, false);
319         misc_packer.pack_start (*hbox, false, false);
320
321         label = manage (new Label (_("History depth (commands)")));
322         label->set_name ("OptionsLabel");
323
324         hbox = manage (new HBox);
325         hbox->set_border_width (5);
326         hbox->set_spacing (10);
327         hbox->pack_start (*label, false, false);
328         hbox->pack_start (history_depth_spinner, false, false);
329         misc_packer.pack_start (*hbox, false, false);
330
331         history_depth.signal_value_changed().connect (mem_fun (*this, &OptionEditor::history_depth_changed));
332         saved_history_depth.signal_value_changed().connect (mem_fun (*this, &OptionEditor::saved_history_depth_changed));
333         save_history_button.signal_toggled().connect (mem_fun (*this, &OptionEditor::save_history_toggled));
334         limit_history_button.signal_toggled().connect (mem_fun (*this, &OptionEditor::limit_history_toggled));
335
336         hbox = manage (new HBox);
337         hbox->set_border_width (5);
338         hbox->set_spacing (10);
339         hbox->pack_start (save_history_button, false, false);
340         misc_packer.pack_start (*hbox, false, false);
341
342         label = manage (new Label (_("Saved history depth (commands)")));
343         label->set_name ("OptionsLabel");
344
345         hbox = manage (new HBox);
346         hbox->set_border_width (5);
347         hbox->set_spacing (10);
348         hbox->pack_start (*label, false, false);
349         hbox->pack_start (saved_history_depth_spinner, false, false);
350         misc_packer.pack_start (*hbox, false, false);
351
352         short_xfade_slider.set_update_policy (UPDATE_DISCONTINUOUS);
353         destructo_xfade_slider.set_update_policy (UPDATE_DISCONTINUOUS);
354
355         destructo_xfade_adjustment.set_value (Config->get_destructive_xfade_msecs());
356
357         misc_packer.show_all ();
358 }
359
360 void
361 OptionEditor::limit_history_toggled ()
362 {
363         bool x = limit_history_button.get_active();
364
365         if (!x) {
366                 Config->set_history_depth (0);
367                 history_depth_spinner.set_sensitive (false);
368         } else {
369                 if (Config->get_history_depth() == 0) {
370                         /* get back to a sane default */
371                         Config->set_history_depth (20);
372                 }
373                 history_depth_spinner.set_sensitive (true);
374         }
375 }
376
377 void
378 OptionEditor::save_history_toggled ()
379 {
380         bool x = save_history_button.get_active();
381
382         if (x != Config->get_save_history()) {
383                 Config->set_save_history (x);
384                 saved_history_depth_spinner.set_sensitive (x);
385         }
386 }
387
388 void
389 OptionEditor::history_depth_changed()
390 {
391         Config->set_history_depth ((int32_t) floor (history_depth.get_value()));
392 }
393
394 void
395 OptionEditor::saved_history_depth_changed()
396 {
397         Config->set_saved_history_depth ((int32_t) floor (saved_history_depth.get_value()));
398 }
399
400 void
401 OptionEditor::short_xfade_adjustment_changed ()
402 {
403         if (session) {
404                 float val = short_xfade_adjustment.get_value();
405
406                 /* val is in msecs */
407
408                 Crossfade::set_short_xfade_length ((nframes_t) floor (session->frame_rate() * (val / 1000.0)));
409         }
410 }
411
412 void
413 OptionEditor::destructo_xfade_adjustment_changed ()
414 {
415         float val = destructo_xfade_adjustment.get_value();
416
417         /* val is in msecs */
418
419
420         Config->set_destructive_xfade_msecs ((uint32_t) floor (val));
421
422         if (session) {
423                 SndFileSource::setup_standard_crossfades (session->frame_rate());
424         }
425 }
426
427 void
428 OptionEditor::setup_sync_options ()
429 {
430         HBox* hbox;
431         vector<string> dumb;
432
433         smpte_offset_clock.set_mode (AudioClock::SMPTE);
434         smpte_offset_clock.ValueChanged.connect (mem_fun(*this, &OptionEditor::smpte_offset_chosen));
435
436         smpte_offset_negative_button.set_name ("OptionEditorToggleButton");
437
438         smpte_offset_negative_button.unset_flags (Gtk::CAN_FOCUS);
439
440         Label *smpte_offset_label = manage (new Label (_("SMPTE Offset")));
441         smpte_offset_label->set_name("OptionsLabel");
442
443         hbox = manage (new HBox);
444         hbox->set_border_width (5);
445         hbox->set_spacing (10);
446         hbox->pack_start (*smpte_offset_label, false, false);
447         hbox->pack_start (smpte_offset_clock, false, false);
448         hbox->pack_start (smpte_offset_negative_button, false, false);
449
450         sync_packer.pack_start (*hbox, false, false);
451         sync_packer.pack_start (synced_timecode_button, false, false);
452
453         smpte_offset_negative_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::smpte_offset_negative_clicked));
454         synced_timecode_button.signal_toggled().connect (mem_fun(*this, &OptionEditor::synced_timecode_toggled));
455 }
456
457 void
458 OptionEditor::smpte_offset_negative_clicked ()
459 {
460         if (session) {
461                 session->set_smpte_offset_negative (smpte_offset_negative_button.get_active());
462         }
463 }
464
465 void
466 OptionEditor::synced_timecode_toggled ()
467 {
468         bool x;
469
470         if ((x = synced_timecode_button.get_active()) != Config->get_timecode_source_is_synced()) {
471                 Config->set_timecode_source_is_synced (x);
472                 Config->save_state();
473         }
474 }
475
476 void
477 OptionEditor::smpte_offset_chosen()
478 {
479         if (session) {
480                 nframes_t frames = smpte_offset_clock.current_duration();
481                 session->set_smpte_offset (frames);
482         }
483 }
484
485
486 void
487 OptionEditor::setup_midi_options ()
488 {
489         HBox* hbox;
490         Label* label;
491
492         midi_port_table.set_row_spacings (6);
493         midi_port_table.set_col_spacings (10);
494
495         redisplay_midi_ports ();
496
497         mmc_receive_device_id_adjustment.set_value (Config->get_mmc_receive_device_id());
498         mmc_send_device_id_adjustment.set_value (Config->get_mmc_send_device_id());
499
500         mmc_receive_device_id_adjustment.signal_value_changed().connect (mem_fun (*this, &OptionEditor::mmc_receive_device_id_adjusted));
501         mmc_send_device_id_adjustment.signal_value_changed().connect (mem_fun (*this, &OptionEditor::mmc_send_device_id_adjusted));
502
503         hbox = manage (new HBox);
504         hbox->set_border_width (6);
505         hbox->pack_start (midi_port_table, true, false);
506
507         midi_packer.pack_start (*hbox, false, false);
508         add_midi_port_button.set_label ("Add MIDI port");
509         midi_packer.pack_start (add_midi_port_button, false, false);
510
511         hbox = manage (new HBox);
512         hbox->set_border_width (6);
513         hbox->set_spacing (6);
514         label = (manage (new Label (_("Inbound MMC Device ID"))));
515         hbox->pack_start (mmc_receive_device_id_spinner, false, false);
516         hbox->pack_start (*label, false, false);
517         midi_packer.pack_start (*hbox, false, false);
518
519         mmc_receive_device_id_spinner.set_value(Config->get_mmc_receive_device_id ());
520
521         hbox = manage (new HBox);
522         hbox->set_border_width (6);
523         hbox->set_spacing (6);
524         label = (manage (new Label (_("Outbound MMC Device ID"))));
525         hbox->pack_start (mmc_send_device_id_spinner, false, false);
526         hbox->pack_start (*label, false, false);
527         midi_packer.pack_start (*hbox, false, false);
528
529         mmc_send_device_id_spinner.set_value(Config->get_mmc_send_device_id ());
530
531         add_midi_port_button.signal_clicked().connect (mem_fun (*this, &OptionEditor::add_midi_port));
532 }
533
534 void
535 OptionEditor::redisplay_midi_ports ()
536 {
537         MIDI::Manager::PortMap::const_iterator i;
538         const MIDI::Manager::PortMap& ports = MIDI::Manager::instance()->get_midi_ports();
539         int n;
540
541         /* remove all existing widgets */
542
543         // XXX broken in gtkmm 2.10
544         // midi_port_table.clear ();
545
546         for (vector<Widget*>::iterator w = midi_port_table_widgets.begin(); w != midi_port_table_widgets.end(); ++w) {
547                 midi_port_table.remove (**w);
548         }
549
550         midi_port_table_widgets.clear ();
551
552         midi_port_table.resize (ports.size() + 4, 12);
553
554         Gtk::Label* label;
555
556         label = (manage (new Label (_("Port"))));
557         label->show ();
558         midi_port_table_widgets.push_back (label);
559         midi_port_table.attach (*label, 0, 1, 0, 1);
560         label = (manage (new Label (_("Offline"))));
561         label->show ();
562         midi_port_table_widgets.push_back (label);
563         midi_port_table.attach (*label, 1, 2, 0, 1);
564         label = (manage (new Label (_("Trace\nInput"))));
565         label->show ();
566         midi_port_table_widgets.push_back (label);
567         midi_port_table.attach (*label, 2, 3, 0, 1);
568         label = (manage (new Label (_("Trace\nOutput"))));
569         label->show ();
570         midi_port_table_widgets.push_back (label);
571         midi_port_table.attach (*label, 3, 4, 0, 1);
572         label = (manage (new Label (_("MTC"))));
573         label->show ();
574         midi_port_table_widgets.push_back (label);
575         midi_port_table.attach (*label, 4, 5, 0, 1);
576         label = (manage (new Label (_("MIDI\nClock"))));
577         label->show ();
578         midi_port_table_widgets.push_back (label);
579         midi_port_table.attach (*label, 6, 7, 0, 1);
580         label = (manage (new Label (_("MMC"))));
581         label->show ();
582         midi_port_table_widgets.push_back (label);
583         midi_port_table.attach (*label, 8, 9, 0, 1);
584         label = (manage (new Label (_("MIDI Parameter\nControl"))));
585         label->show ();
586         midi_port_table_widgets.push_back (label);
587         midi_port_table.attach (*label, 10, 11, 0, 1);
588
589         Gtk::HSeparator* hsep = (manage (new HSeparator()));
590         hsep->show ();
591         midi_port_table_widgets.push_back (hsep);
592         midi_port_table.attach (*hsep, 0, 11, 1, 2);
593         Gtk::VSeparator* vsep = (manage (new VSeparator()));
594         vsep->show ();
595         midi_port_table_widgets.push_back (vsep);
596         midi_port_table.attach (*vsep, 5, 6, 0, 8);
597         vsep = (manage (new VSeparator()));
598         vsep->show ();
599         midi_port_table_widgets.push_back (vsep);
600         midi_port_table.attach (*vsep, 7, 8, 0, 8);
601         vsep = (manage (new VSeparator()));
602         vsep->show ();
603         midi_port_table_widgets.push_back (vsep);
604         midi_port_table.attach (*vsep, 9, 10, 0, 8);
605
606         for (n = 0, i = ports.begin(); i != ports.end(); ++n, ++i) {
607
608                 ToggleButton* tb;
609                 RadioButton* rb;
610                 Button* bb;
611
612                 /* the remove button. create early so we can pass it to various callbacks */
613
614                 bb = manage (new Button (Stock::REMOVE));
615                 bb->set_name ("OptionEditorToggleButton");
616                 bb->show ();
617                 midi_port_table_widgets.push_back (bb);
618                 midi_port_table.attach (*bb, 11, 12, n+2, n+3, FILL|EXPAND, FILL);
619                 bb->signal_clicked().connect (bind (mem_fun(*this, &OptionEditor::remove_midi_port), i->second));
620                 bb->set_sensitive (port_removable (i->second));
621
622                 label = (manage (new Label (i->first)));
623                 label->show ();
624                 midi_port_table_widgets.push_back (label);
625                 midi_port_table.attach (*label, 0, 1, n+2, n+3,FILL|EXPAND, FILL );
626
627                 tb = manage (new ToggleButton (_("online")));
628                 tb->set_name ("OptionEditorToggleButton");
629
630                 /* remember, we have to handle the i18n case where the relative
631                    lengths of the strings in language N is different than in english.
632                 */
633
634                 if (strlen (_("offline")) > strlen (_("online"))) {
635                         set_size_request_to_display_given_text (*tb, _("offline"), 15, 12);
636                 } else {
637                         set_size_request_to_display_given_text (*tb, _("online"), 15, 12);
638                 }
639
640                 if (i->second->input()) {
641                         tb->set_active (!i->second->input()->offline());
642                         tb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::port_online_toggled), i->second, tb));
643                         i->second->input()->OfflineStatusChanged.connect (bind (mem_fun(*this, &OptionEditor::map_port_online), (*i).second, tb));
644                 }
645                 tb->show ();
646                 midi_port_table_widgets.push_back (tb);
647                 midi_port_table.attach (*tb, 1, 2, n+2, n+3, FILL|EXPAND, FILL);
648
649                 // Trace MIDI Input
650                 tb = manage (new ToggleButton ());
651                 tb->set_name ("OptionEditorToggleButton");
652                 tb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::port_trace_in_toggled), (*i).second, tb));
653                 tb->set_size_request (10, 10);
654                 tb->show ();
655                 midi_port_table_widgets.push_back (tb);
656                 midi_port_table.attach (*tb, 2, 3, n+2, n+3, FILL|EXPAND, FILL);
657
658                 // Trace MIDI Output
659                 tb = manage (new ToggleButton ());
660                 tb->set_name ("OptionEditorToggleButton");
661                 tb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::port_trace_out_toggled), (*i).second, tb));
662                 tb->set_size_request (10, 10);
663                 tb->show ();
664                 midi_port_table_widgets.push_back (tb);
665                 midi_port_table.attach (*tb, 3, 4, n+2, n+3, FILL|EXPAND, FILL);
666
667                 // MTC Radio Button
668                 rb = manage (new RadioButton ());
669                 rb->set_name ("OptionEditorToggleButton");
670                 if (n == 0) {
671                         mtc_button_group = rb->get_group();
672                 } else {
673                         rb->set_group (mtc_button_group);
674                 }
675                 rb->show ();
676                 midi_port_table_widgets.push_back (rb);
677                 midi_port_table.attach (*rb, 4, 5, n+2, n+3, FILL|EXPAND, FILL);
678                 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::mtc_port_chosen), (*i).second, rb, bb));
679
680                 if (session && i->second == session->mtc_port()) {
681                         rb->set_active (true);
682                 }
683
684                 // MIDI Clock Radio Button
685                 rb = manage (new RadioButton ());
686                 rb->set_name ("OptionEditorToggleButton");
687                 if (n == 0) {
688                         midi_clock_button_group = rb->get_group();
689                 } else {
690                         rb->set_group (midi_clock_button_group);
691                 }
692                 rb->show ();
693                 midi_port_table_widgets.push_back (rb);
694                 midi_port_table.attach (*rb, 6, 7, n+2, n+3, FILL|EXPAND, FILL);
695                 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::midi_clock_port_chosen), (*i).second, rb, bb));
696
697                 if (session && i->second == session->midi_clock_port()) {
698                         rb->set_active (true);
699                 }
700
701                 rb = manage (new RadioButton ());
702                 rb->set_name ("OptionEditorToggleButton");
703                 if (n == 0) {
704                         mmc_button_group = rb->get_group();
705                 } else {
706                         rb->set_group (mmc_button_group);
707                 }
708                 rb->show ();
709                 midi_port_table_widgets.push_back (rb);
710                 midi_port_table.attach (*rb, 8, 9, n+2, n+3, FILL|EXPAND, FILL);
711                 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::mmc_port_chosen), (*i).second, rb, bb));
712
713                 if (session && i->second == session->mmc_port()) {
714                         rb->set_active (true);
715                 }
716
717                 rb = manage (new RadioButton ());
718                 rb->set_name ("OptionEditorToggleButton");
719                 if (n == 0) {
720                         midi_button_group = rb->get_group();
721                 } else {
722                         rb->set_group (midi_button_group);
723                 }
724                 rb->show ();
725                 midi_port_table_widgets.push_back (rb);
726                 midi_port_table.attach (*rb, 10, 11, n+2, n+3, FILL|EXPAND, FILL);
727                 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::midi_port_chosen), (*i).second, rb, bb));
728
729                 if (session && i->second == session->midi_port()) {
730                         rb->set_active (true);
731                 }
732
733         }
734
735         midi_port_table.show();
736 }
737
738 void
739 OptionEditor::remove_midi_port (MIDI::Port* port)
740 {
741         MIDI::Manager::instance()->remove_port (port);
742         redisplay_midi_ports ();
743 }
744
745 void
746 OptionEditor::add_midi_port ()
747 {
748         MidiPortDialog dialog;
749
750         dialog.set_position (WIN_POS_MOUSE);
751         dialog.set_transient_for (*this);
752
753         dialog.show ();
754
755         int ret = dialog.run ();
756
757         switch (ret) {
758         case RESPONSE_ACCEPT:
759                 break;
760         default:
761                 return;
762                 break;
763         }
764
765         Glib::ustring mode = dialog.port_mode_combo.get_active_text();
766         std::string smod;
767
768         if (mode == _("input")) {
769                 smod = X_("input");
770         } else if (mode == (_("output"))) {
771                 smod = X_("output");
772         } else {
773                 smod = "duplex";
774         }
775
776
777         XMLNode node (X_("MIDI-port"));
778
779         node.add_property ("tag", dialog.port_name.get_text());
780         node.add_property ("device", X_("ardour")); // XXX this can't be right for all types
781         node.add_property ("type", MIDI::PortFactory::default_port_type());
782         node.add_property ("mode", smod);
783
784         if (MIDI::Manager::instance()->add_port (node) != 0) {
785                 redisplay_midi_ports ();
786         }
787 }
788
789 bool
790 OptionEditor::port_removable (MIDI::Port *port)
791 {
792         if (!session) {
793                 return true;
794         }
795
796         if (port == session->mtc_port() ||
797             port == session->mmc_port() ||
798             port == session->midi_port()) {
799                 return false;
800         }
801         return true;
802 }
803
804 void
805 OptionEditor::mtc_port_chosen (MIDI::Port *port, Gtk::RadioButton* rb, Gtk::Button* bb)
806 {
807         if (session) {
808                 if (rb->get_active()) {
809                         session->set_mtc_port (port->name());
810                         Config->set_mtc_port_name (port->name());
811                 } else {
812                         session->set_mtc_port ("");
813                 }
814                 bb->set_sensitive (port_removable (port));
815         }
816 }
817
818 void
819 OptionEditor::mmc_port_chosen (MIDI::Port* port, Gtk::RadioButton* rb, Gtk::Button* bb)
820 {
821         if (session) {
822                 if (rb->get_active()) {
823                         session->set_mmc_port (port->name());
824                         Config->set_mtc_port_name (port->name());
825                 } else {
826                         session->set_mmc_port ("");
827                 }
828                 bb->set_sensitive (port_removable (port));
829         }
830 }
831
832 void
833 OptionEditor::midi_port_chosen (MIDI::Port* port, Gtk::RadioButton* rb, Gtk::Button* bb)
834 {
835         if (session) {
836                 if (rb->get_active()) {
837                         session->set_midi_port (port->name());
838                         Config->set_midi_port_name (port->name());
839                 } else {
840                         session->set_midi_port ("");
841                 }
842                 bb->set_sensitive (port_removable (port));
843         }
844 }
845
846 void
847 OptionEditor::midi_clock_port_chosen (MIDI::Port *port, Gtk::RadioButton* rb, Gtk::Button* bb)
848 {
849         if (session) {
850                 if (rb->get_active()) {
851                         session->set_midi_clock_port (port->name());
852                         Config->set_midi_clock_port_name (port->name());
853                 } else {
854                         session->set_midi_clock_port ("");
855                 }
856                 bb->set_sensitive (port_removable (port));
857         }
858 }
859
860 void
861 OptionEditor::port_online_toggled (MIDI::Port* port, ToggleButton* tb)
862 {
863         bool wanted = tb->get_active();
864
865         if (port->input()) {
866                 if (wanted != port->input()->offline()) {
867                         port->input()->set_offline (wanted);
868                 }
869         }
870 }
871
872 void
873 OptionEditor::map_port_online (MIDI::Port* port, ToggleButton* tb)
874 {
875         bool bstate = tb->get_active ();
876
877         if (port->input()) {
878                 if (bstate != port->input()->offline()) {
879                         if (port->input()->offline()) {
880                                 tb->set_label (_("offline"));
881                                 tb->set_active (false);
882                         } else {
883                                 tb->set_label (_("online"));
884                                 tb->set_active (true);
885                         }
886                 }
887         }
888 }
889
890 void
891 OptionEditor::mmc_receive_device_id_adjusted ()
892 {
893         uint8_t id = (uint8_t) mmc_receive_device_id_spinner.get_value();
894         Config->set_mmc_receive_device_id (id);
895 }
896
897 void
898 OptionEditor::mmc_send_device_id_adjusted ()
899 {
900         uint8_t id = (uint8_t) mmc_send_device_id_spinner.get_value();
901         Config->set_mmc_send_device_id (id);
902 }
903
904 void
905 OptionEditor::port_trace_in_toggled (MIDI::Port* port, ToggleButton* tb)
906 {
907         bool trace = tb->get_active();
908
909         if (port->input()) {
910                 if (port->input()->tracing() != trace) {
911                         port->input()->trace (trace, &cerr, string (port->name()) + string (" input: "));
912                 }
913         }
914 }
915
916 void
917 OptionEditor::port_trace_out_toggled (MIDI::Port* port, ToggleButton* tb)
918 {
919         bool trace = tb->get_active();
920
921         if (port->output()) {
922                 if (port->output()->tracing() != trace) {
923                         port->output()->trace (trace, &cerr, string (port->name()) + string (" output: "));
924                 }
925         }
926 }
927
928 void
929 OptionEditor::save ()
930 {
931         /* XXX a bit odd that we save the entire session state here */
932
933         ui.save_state ("");
934 }
935
936 gint
937 OptionEditor::wm_close (GdkEventAny *ev)
938 {
939         save ();
940         hide ();
941         return TRUE;
942 }
943
944 void
945 OptionEditor::raid_path_changed ()
946 {
947         if (session) {
948                 Config->set_raid_path (session_raid_entry.get_text());
949         }
950 }
951
952 void
953 OptionEditor::click_browse_clicked ()
954 {
955         SoundFileChooser sfdb (*this, _("Choose Click"), session);
956
957         sfdb.show_all ();
958         sfdb.present ();
959
960         int result = sfdb.run ();
961
962         if (result == Gtk::RESPONSE_OK) {
963                 click_chosen(sfdb.get_filename());
964         }
965 }
966
967 void
968 OptionEditor::click_chosen (const string & path)
969 {
970         click_path_entry.set_text (path);
971         click_sound_changed ();
972 }
973
974 void
975 OptionEditor::click_emphasis_browse_clicked ()
976 {
977         SoundFileChooser sfdb (*this, _("Choose Click Emphasis"), session);
978
979         sfdb.show_all ();
980         sfdb.present ();
981
982         int result = sfdb.run ();
983
984         if (result == Gtk::RESPONSE_OK) {
985                 click_emphasis_chosen (sfdb.get_filename());
986         }
987 }
988
989 void
990 OptionEditor::click_emphasis_chosen (const string & path)
991 {
992         click_emphasis_path_entry.set_text (path);
993         click_emphasis_sound_changed ();
994 }
995
996 void
997 OptionEditor::click_sound_changed ()
998 {
999         if (session) {
1000                 string path = click_path_entry.get_text();
1001
1002                 if (path == Config->get_click_sound()) {
1003                         return;
1004                 }
1005
1006                 strip_whitespace_edges (path);
1007
1008                 if (path == _("internal")) {
1009                         Config->set_click_sound ("");
1010                 } else {
1011                         Config->set_click_sound (path);
1012                 }
1013         }
1014 }
1015
1016 void
1017 OptionEditor::click_emphasis_sound_changed ()
1018 {
1019         if (session) {
1020                 string path = click_emphasis_path_entry.get_text();
1021
1022                 if (path == Config->get_click_emphasis_sound()) {
1023                         return;
1024                 }
1025
1026                 strip_whitespace_edges (path);
1027
1028                 if (path == _("internal")) {
1029                         Config->set_click_emphasis_sound ("");
1030                 } else {
1031                         Config->set_click_emphasis_sound (path);
1032                 }
1033         }
1034 }
1035
1036 void
1037 OptionEditor::clear_click_editor ()
1038 {
1039         if (click_io_selector) {
1040                 click_hpacker.remove (*click_io_selector);
1041                 click_hpacker.remove (*click_gpm);
1042                 delete click_io_selector;
1043                 delete click_gpm;
1044                 click_io_selector = 0;
1045                 click_gpm = 0;
1046         }
1047 }
1048
1049 void
1050 OptionEditor::setup_click_editor ()
1051 {
1052         Label* label;
1053
1054         if (first_click_setup) {
1055                 
1056                 click_path_entry.set_name ("OptionsEntry");
1057                 click_emphasis_path_entry.set_name ("OptionsEntry");
1058                 
1059                 click_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_sound_changed));
1060                 click_emphasis_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_emphasis_sound_changed));
1061                 
1062                 click_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_sound_changed));
1063                 click_emphasis_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_emphasis_sound_changed));
1064                 
1065                 click_browse_button.set_name ("EditorGTKButton");
1066                 click_emphasis_browse_button.set_name ("EditorGTKButton");
1067
1068                 click_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_browse_clicked));
1069                 click_emphasis_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_emphasis_browse_clicked));
1070
1071                 click_packer.set_border_width (12);
1072                 click_packer.set_spacing (5);
1073
1074                 click_table.set_col_spacings (10);
1075                 
1076                 label = manage(new Label(_("Click audio file")));
1077                 label->set_name ("OptionsLabel");
1078                 click_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL);
1079                 click_table.attach (click_path_entry, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1080                 click_table.attach (click_browse_button, 2, 3, 0, 1, FILL|EXPAND, FILL);
1081                 
1082                 label = manage(new Label(_("Click emphasis audiofile")));
1083                 label->set_name ("OptionsLabel");
1084                 click_table.attach (*label, 0, 1, 1, 2, FILL|EXPAND, FILL);
1085                 click_table.attach (click_emphasis_path_entry, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1086                 click_table.attach (click_emphasis_browse_button, 2, 3, 1, 2, FILL|EXPAND, FILL);
1087
1088                 click_packer.pack_start (click_table, false, false);
1089                 click_packer.pack_start (click_hpacker, false, false);
1090
1091
1092                 click_hpacker.set_spacing (10);
1093
1094                 first_click_setup = false;
1095         }
1096
1097         click_path_entry.set_sensitive (true);
1098         click_emphasis_path_entry.set_sensitive (true);
1099
1100         click_io_selector = new IOSelector (*session, session->click_io(), false);
1101         click_gpm = new GainMeter (session->click_io(), *session);
1102
1103         click_hpacker.pack_start (*click_io_selector, false, false);
1104         click_hpacker.pack_start (*click_gpm, false, false);
1105
1106         click_table.set_col_spacings (10);
1107
1108         label = manage(new Label(_("Click audio file")));
1109         label->set_name ("OptionsLabel");
1110         click_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL);
1111         click_table.attach (click_path_entry, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1112         click_table.attach (click_browse_button, 2, 3, 0, 1, FILL|EXPAND, FILL);
1113
1114         label = manage(new Label(_("Click emphasis audiofile")));
1115         label->set_name ("OptionsLabel");
1116         click_table.attach (*label, 0, 1, 1, 2, FILL|EXPAND, FILL);
1117         click_table.attach (click_emphasis_path_entry, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1118         click_table.attach (click_emphasis_browse_button, 2, 3, 1, 2, FILL|EXPAND, FILL);
1119
1120         click_packer.show_all ();
1121 }
1122
1123 void
1124 OptionEditor::clear_auditioner_editor ()
1125 {
1126         if (auditioner_io_selector) {
1127                 audition_hpacker.remove (*auditioner_io_selector);
1128                 audition_hpacker.remove (*auditioner_gpm);
1129                 delete auditioner_io_selector;
1130                 delete auditioner_gpm;
1131                 auditioner_io_selector = 0;
1132                 auditioner_gpm = 0;
1133         }
1134 }
1135
1136 void
1137 OptionEditor::setup_auditioner_editor ()
1138 {
1139         audition_packer.set_border_width (12);
1140         audition_packer.set_spacing (5);
1141         audition_hpacker.set_spacing (10);
1142
1143         audition_label.set_name ("OptionEditorAuditionerLabel");
1144         audition_label.set_text (_("The auditioner is a dedicated mixer strip used\n"
1145                                    "for listening to specific regions outside the context\n"
1146                                    "of the overall mix. It can be connected just like any\n"
1147                                    "other mixer strip."));
1148
1149         audition_packer.pack_start (audition_label, false, false, 10);
1150         audition_packer.pack_start (audition_hpacker, false, false);
1151 }
1152
1153 void
1154 OptionEditor::connect_audition_editor ()
1155 {
1156         auditioner_io_selector = new IOSelector (*session, session->the_auditioner(), false);
1157         auditioner_gpm = new GainMeter (session->the_auditioner(), *session);
1158
1159         audition_hpacker.pack_start (*auditioner_io_selector, false, false);
1160         audition_hpacker.pack_start (*auditioner_gpm, false, false);
1161
1162         auditioner_io_selector->show_all ();
1163         auditioner_gpm->show_all ();
1164 }
1165
1166 bool
1167 OptionEditor::focus_out_event_handler (GdkEventFocus* ev, void (OptionEditor::*pmf)())
1168 {
1169         (this->*pmf)();
1170         return false;
1171 }
1172
1173 static const struct {
1174     const char *name;
1175     guint   modifier;
1176 } modifiers[] = {
1177
1178 #ifdef GTKOSX
1179
1180         /* Command = Meta
1181            Option/Alt = Mod1
1182         */
1183
1184         { "Shift", GDK_SHIFT_MASK },
1185         { "Command", GDK_META_MASK },
1186         { "Control", GDK_CONTROL_MASK },
1187         { "Option", GDK_MOD1_MASK },
1188         { "Command-Shift", GDK_MOD1_MASK|GDK_SHIFT_MASK },
1189         { "Command-Option", GDK_MOD1_MASK|GDK_MOD5_MASK },
1190         { "Shift-Option", GDK_SHIFT_MASK|GDK_MOD5_MASK },
1191         { "Shift-Command-Option", GDK_MOD5_MASK|GDK_SHIFT_MASK|GDK_MOD1_MASK },
1192
1193 #else
1194         { "Shift", GDK_SHIFT_MASK },
1195         { "Control", GDK_CONTROL_MASK },
1196         { "Alt (Mod1)", GDK_MOD1_MASK },
1197         { "Control-Shift", GDK_CONTROL_MASK|GDK_SHIFT_MASK },
1198         { "Control-Alt", GDK_CONTROL_MASK|GDK_MOD1_MASK },
1199         { "Shift-Alt", GDK_SHIFT_MASK|GDK_MOD1_MASK },
1200         { "Control-Shift-Alt", GDK_CONTROL_MASK|GDK_SHIFT_MASK|GDK_MOD1_MASK },
1201         { "Mod2", GDK_MOD2_MASK },
1202         { "Mod3", GDK_MOD3_MASK },
1203         { "Mod4", GDK_MOD4_MASK },
1204         { "Mod5", GDK_MOD5_MASK },
1205 #endif
1206         { 0, 0 }
1207 };
1208
1209 void
1210 OptionEditor::setup_keyboard_options ()
1211 {
1212         vector<string> dumb;
1213         Label* label;
1214
1215         keyboard_mouse_table.set_border_width (12);
1216         keyboard_mouse_table.set_row_spacings (5);
1217         keyboard_mouse_table.set_col_spacings (5);
1218
1219         /* internationalize and prepare for use with combos */
1220
1221         for (int i = 0; modifiers[i].name; ++i) {
1222                 dumb.push_back (_(modifiers[i].name));
1223         }
1224
1225         set_popdown_strings (edit_modifier_combo, dumb);
1226         edit_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::edit_modifier_chosen));
1227
1228         for (int x = 0; modifiers[x].name; ++x) {
1229                 if (modifiers[x].modifier == Keyboard::edit_modifier ()) {
1230                         edit_modifier_combo.set_active_text (_(modifiers[x].name));
1231                         break;
1232                 }
1233         }
1234
1235         label = manage (new Label (_("Edit using")));
1236         label->set_name ("OptionsLabel");
1237         label->set_alignment (1.0, 0.5);
1238
1239         keyboard_mouse_table.attach (*label, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1240         keyboard_mouse_table.attach (edit_modifier_combo, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1241
1242         label = manage (new Label (_("+ button")));
1243         label->set_name ("OptionsLabel");
1244
1245         keyboard_mouse_table.attach (*label, 3, 4, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1246         keyboard_mouse_table.attach (edit_button_spin, 4, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1247
1248         edit_button_spin.set_name ("OptionsEntry");
1249         edit_button_adjustment.set_value (Keyboard::edit_button());
1250         edit_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::edit_button_changed));
1251
1252         set_popdown_strings (delete_modifier_combo, dumb);
1253         delete_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::delete_modifier_chosen));
1254
1255         for (int x = 0; modifiers[x].name; ++x) {
1256                 if (modifiers[x].modifier == Keyboard::delete_modifier ()) {
1257                         delete_modifier_combo.set_active_text (_(modifiers[x].name));
1258                         break;
1259                 }
1260         }
1261
1262         label = manage (new Label (_("Delete using")));
1263         label->set_name ("OptionsLabel");
1264         label->set_alignment (1.0, 0.5);
1265
1266         keyboard_mouse_table.attach (*label, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1267         keyboard_mouse_table.attach (delete_modifier_combo, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1268
1269         label = manage (new Label (_("+ button")));
1270         label->set_name ("OptionsLabel");
1271
1272         keyboard_mouse_table.attach (*label, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1273         keyboard_mouse_table.attach (delete_button_spin, 4, 5, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1274
1275         delete_button_spin.set_name ("OptionsEntry");
1276         delete_button_adjustment.set_value (Keyboard::delete_button());
1277         delete_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::delete_button_changed));
1278
1279         set_popdown_strings (snap_modifier_combo, dumb);
1280         snap_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::snap_modifier_chosen));
1281
1282         for (int x = 0; modifiers[x].name; ++x) {
1283                 if (modifiers[x].modifier == (guint) Keyboard::snap_modifier ()) {
1284                         snap_modifier_combo.set_active_text (_(modifiers[x].name));
1285                         break;
1286                 }
1287         }
1288
1289         label = manage (new Label (_("Ignore snap using")));
1290         label->set_name ("OptionsLabel");
1291         label->set_alignment (1.0, 0.5);
1292
1293         keyboard_mouse_table.attach (*label, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
1294         keyboard_mouse_table.attach (snap_modifier_combo, 1, 2, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
1295
1296         vector<string> strs;
1297
1298         for (std::map<std::string,std::string>::iterator bf = Keyboard::binding_files.begin(); bf != Keyboard::binding_files.end(); ++bf) {
1299                 strs.push_back (bf->first);
1300         }
1301
1302         set_popdown_strings (keyboard_layout_selector, strs);
1303         keyboard_layout_selector.set_active_text (Keyboard::current_binding_name());
1304         keyboard_layout_selector.signal_changed().connect (mem_fun (*this, &OptionEditor::bindings_changed));
1305
1306         label = manage (new Label (_("Keyboard layout")));
1307         label->set_name ("OptionsLabel");
1308         label->set_alignment (1.0, 0.5);
1309
1310         keyboard_mouse_table.attach (*label, 0, 1, 3, 4, Gtk::FILL|Gtk::EXPAND, FILL);
1311         keyboard_mouse_table.attach (keyboard_layout_selector, 1, 2, 3, 4, Gtk::FILL|Gtk::EXPAND, FILL);
1312 }
1313
1314 void
1315 OptionEditor::bindings_changed ()
1316 {
1317         string txt;
1318
1319         txt = keyboard_layout_selector.get_active_text();
1320
1321         for (std::map<string,string>::iterator i = Keyboard::binding_files.begin(); i != Keyboard::binding_files.end(); ++i) {
1322                 if (txt == i->first) {
1323                         if (Keyboard::load_keybindings (i->second)) {
1324                                 Keyboard::save_keybindings ();
1325                         }
1326                 }
1327         }
1328 }
1329
1330 void
1331 OptionEditor::edit_modifier_chosen ()
1332 {
1333         string txt;
1334
1335         txt = edit_modifier_combo.get_active_text();
1336
1337         for (int i = 0; modifiers[i].name; ++i) {
1338                 if (txt == _(modifiers[i].name)) {
1339                         Keyboard::set_edit_modifier (modifiers[i].modifier);
1340                         break;
1341                 }
1342         }
1343 }
1344
1345 void
1346 OptionEditor::delete_modifier_chosen ()
1347 {
1348         string txt;
1349
1350         txt = delete_modifier_combo.get_active_text();
1351
1352         for (int i = 0; modifiers[i].name; ++i) {
1353                 if (txt == _(modifiers[i].name)) {
1354                         Keyboard::set_delete_modifier (modifiers[i].modifier);
1355                         break;
1356                 }
1357         }
1358 }
1359
1360 void
1361 OptionEditor::snap_modifier_chosen ()
1362 {
1363         string txt;
1364
1365         txt = snap_modifier_combo.get_active_text();
1366
1367         for (int i = 0; modifiers[i].name; ++i) {
1368                 if (txt == _(modifiers[i].name)) {
1369                         Keyboard::set_snap_modifier (modifiers[i].modifier);
1370                         break;
1371                 }
1372         }
1373 }
1374
1375 void
1376 OptionEditor::delete_button_changed ()
1377 {
1378         Keyboard::set_delete_button ((guint) delete_button_adjustment.get_value());
1379 }
1380
1381 void
1382 OptionEditor::edit_button_changed ()
1383 {
1384         Keyboard::set_edit_button ((guint) edit_button_adjustment.get_value());
1385 }
1386
1387 void
1388 OptionEditor::fixup_combo_size (Gtk::ComboBoxText& combo, vector<string>& strings)
1389 {
1390         /* find the widest string */
1391
1392         string::size_type maxlen = 0;
1393         string maxstring;
1394
1395         for (vector<string>::iterator i = strings.begin(); i != strings.end(); ++i) {
1396                 string::size_type l;
1397
1398                 if ((l = (*i).length()) > maxlen) {
1399                         maxlen = l;
1400                         maxstring = *i;
1401                 }
1402         }
1403
1404         /* try to include ascenders and descenders */
1405
1406         if (maxstring.length() > 2) {
1407                 maxstring[0] = 'g';
1408                 maxstring[1] = 'l';
1409         }
1410
1411         const guint32 FUDGE = 10; // Combo's are stupid - they steal space from the entry for the button
1412
1413         set_size_request_to_display_given_text (combo, maxstring.c_str(), 10 + FUDGE, 10);
1414 }
1415
1416 void
1417 OptionEditor::parameter_changed (const char* parameter_name)
1418 {
1419         ENSURE_GUI_THREAD (bind (mem_fun (*this, &OptionEditor::parameter_changed), parameter_name));
1420
1421 #define PARAM_IS(x) (!strcmp (parameter_name, (x)))
1422
1423         if (PARAM_IS ("timecode-source-is-synced")) {
1424                 synced_timecode_button.set_active (Config->get_timecode_source_is_synced());
1425         } else if (PARAM_IS ("history-depth")) {
1426                 int32_t depth = Config->get_history_depth();
1427
1428                 history_depth.set_value (depth);
1429                 history_depth_spinner.set_sensitive (depth != 0);
1430                 limit_history_button.set_active (depth != 0);
1431
1432         } else if (PARAM_IS ("saved-history-depth")) {
1433
1434                 saved_history_depth.set_value (Config->get_saved_history_depth());
1435
1436         } else if (PARAM_IS ("save-history")) {
1437
1438                 bool x = Config->get_save_history();
1439
1440                 save_history_button.set_active (x);
1441                 saved_history_depth_spinner.set_sensitive (x);
1442         } else if (PARAM_IS ("font-scale")) {
1443                 reset_dpi();
1444         }
1445 }