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