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