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