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