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