Numerical sort patch from mantis #2654
[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, 11),
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         midi_packer.pack_start (add_midi_port_button, false, false);
514
515         hbox = manage (new HBox);
516         hbox->set_border_width (6);
517         hbox->set_spacing (6);
518         label = (manage (new Label (_("Inbound MMC Device ID")))); 
519         hbox->pack_start (mmc_receive_device_id_spinner, false, false);
520         hbox->pack_start (*label, false, false);
521         midi_packer.pack_start (*hbox, false, false); 
522
523         mmc_receive_device_id_spinner.set_value(Config->get_mmc_receive_device_id ());
524
525         hbox = manage (new HBox);
526         hbox->set_border_width (6);
527         hbox->set_spacing (6);
528         label = (manage (new Label (_("Outbound MMC Device ID")))); 
529         hbox->pack_start (mmc_send_device_id_spinner, false, false);
530         hbox->pack_start (*label, false, false);
531         midi_packer.pack_start (*hbox, false, false);
532
533         mmc_send_device_id_spinner.set_value(Config->get_mmc_send_device_id ());
534
535         hbox = manage (new HBox);
536         hbox->set_border_width (6);
537         hbox->set_spacing (6);
538         label = (manage (new Label (_("Startup program change")))); 
539         hbox->pack_start (initial_program_change_spinner, false, false);
540         hbox->pack_start (*label, false, false);
541         midi_packer.pack_start (*hbox, false, false);
542
543         initial_program_change_spinner.set_value (Config->get_initial_program_change());
544         initial_program_change_adjustment.signal_value_changed().connect (mem_fun (*this, &OptionEditor::initial_program_change_adjusted));
545
546         add_midi_port_button.signal_clicked().connect (mem_fun (*this, &OptionEditor::add_midi_port));
547 }
548
549 void
550 OptionEditor::initial_program_change_adjusted ()
551 {
552         Config->set_initial_program_change (((int32_t) floor (initial_program_change_adjustment.get_value())) & 0x7f);
553 }
554
555 void
556 OptionEditor::redisplay_midi_ports ()
557 {
558         MIDI::Manager::PortMap::const_iterator i;
559         const MIDI::Manager::PortMap& ports = MIDI::Manager::instance()->get_midi_ports();
560         int n;
561
562         /* remove all existing widgets */
563
564         // XXX broken in gtkmm 2.10
565         // midi_port_table.clear ();
566
567         for (vector<Widget*>::iterator w = midi_port_table_widgets.begin(); w != midi_port_table_widgets.end(); ++w) {
568                 midi_port_table.remove (**w);
569         }
570
571         midi_port_table_widgets.clear ();
572
573         midi_port_table.resize (ports.size() + 4, 11);
574
575         Gtk::Label* label;
576
577         label = (manage (new Label (_("Port")))); 
578         label->show ();
579         midi_port_table_widgets.push_back (label);
580         midi_port_table.attach (*label, 0, 1, 0, 1);
581         label = (manage (new Label (_("Offline")))); 
582         label->show ();
583         midi_port_table_widgets.push_back (label);
584         midi_port_table.attach (*label, 1, 2, 0, 1);
585         label = (manage (new Label (_("Trace\nInput")))); 
586         label->show ();
587         midi_port_table_widgets.push_back (label);
588         midi_port_table.attach (*label, 2, 3, 0, 1);
589         label = (manage (new Label (_("Trace\nOutput")))); 
590         label->show ();
591         midi_port_table_widgets.push_back (label);
592         midi_port_table.attach (*label, 3, 4, 0, 1);
593         label = (manage (new Label (_("MTC")))); 
594         label->show ();
595         midi_port_table_widgets.push_back (label);
596         midi_port_table.attach (*label, 4, 5, 0, 1);
597         label = (manage (new Label (_("MMC")))); 
598         label->show ();
599         midi_port_table_widgets.push_back (label);
600         midi_port_table.attach (*label, 6, 7, 0, 1);
601         label = (manage (new Label (_("MIDI Parameter\nControl")))); 
602         label->show ();
603         midi_port_table_widgets.push_back (label);
604         midi_port_table.attach (*label, 8, 9, 0, 1);
605
606         Gtk::HSeparator* hsep = (manage (new HSeparator())); 
607         hsep->show ();
608         midi_port_table_widgets.push_back (hsep);
609         midi_port_table.attach (*hsep, 0, 9, 1, 2);
610         Gtk::VSeparator* vsep = (manage (new VSeparator())); 
611         vsep->show ();
612         midi_port_table_widgets.push_back (vsep);
613         midi_port_table.attach (*vsep, 5, 6, 0, 8);
614         vsep = (manage (new VSeparator())); 
615         vsep->show ();
616         midi_port_table_widgets.push_back (vsep);
617         midi_port_table.attach (*vsep, 7, 8, 0, 8);
618         
619         for (n = 0, i = ports.begin(); i != ports.end(); ++n, ++i) {
620
621                 ToggleButton* tb;
622                 RadioButton* rb;
623                 Button* bb;
624
625                 /* the remove button. create early so we can pass it to various callbacks */
626                 
627                 bb = manage (new Button (Stock::REMOVE));
628                 bb->set_name ("OptionEditorToggleButton");
629                 bb->show ();
630                 midi_port_table_widgets.push_back (bb);
631                 midi_port_table.attach (*bb, 9, 10, n+2, n+3, FILL|EXPAND, FILL);
632                 bb->signal_clicked().connect (bind (mem_fun(*this, &OptionEditor::remove_midi_port), i->second));
633                 bb->set_sensitive (port_removable (i->second));
634
635                 label = (manage (new Label (i->first))); 
636                 label->show ();
637                 midi_port_table_widgets.push_back (label);
638                 midi_port_table.attach (*label, 0, 1, n+2, n+3,FILL|EXPAND, FILL );
639                 
640                 tb = manage (new ToggleButton (_("online")));
641                 tb->set_name ("OptionEditorToggleButton");
642
643                 /* remember, we have to handle the i18n case where the relative
644                    lengths of the strings in language N is different than in english.
645                 */
646
647                 if (strlen (_("offline")) > strlen (_("online"))) {
648                         set_size_request_to_display_given_text (*tb, _("offline"), 15, 12);
649                 } else {
650                         set_size_request_to_display_given_text (*tb, _("online"), 15, 12);
651                 }
652
653                 if (i->second->input()) {
654                         tb->set_active (!i->second->input()->offline());
655                         tb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::port_online_toggled), i->second, tb));
656                         i->second->input()->OfflineStatusChanged.connect (bind (mem_fun(*this, &OptionEditor::map_port_online), (*i).second, tb));
657                 }
658                 tb->show ();
659                 midi_port_table_widgets.push_back (tb);
660                 midi_port_table.attach (*tb, 1, 2, n+2, n+3, FILL|EXPAND, FILL);
661
662                 tb = manage (new ToggleButton ());
663                 tb->set_name ("OptionEditorToggleButton");
664                 tb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::port_trace_in_toggled), (*i).second, tb));
665                 tb->set_size_request (10, 10);
666                 tb->show ();
667                 midi_port_table_widgets.push_back (tb);
668                 midi_port_table.attach (*tb, 2, 3, n+2, n+3, FILL|EXPAND, FILL);
669
670                 tb = manage (new ToggleButton ());
671                 tb->set_name ("OptionEditorToggleButton");
672                 tb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::port_trace_out_toggled), (*i).second, tb));
673                 tb->set_size_request (10, 10);
674                 tb->show ();
675                 midi_port_table_widgets.push_back (tb);
676                 midi_port_table.attach (*tb, 3, 4, n+2, n+3, FILL|EXPAND, FILL);
677
678                 rb = manage (new RadioButton ());
679                 rb->set_name ("OptionEditorToggleButton");
680                 if (n == 0) {
681                         mtc_button_group = rb->get_group();
682                 } else {
683                         rb->set_group (mtc_button_group);
684
685                 }
686                 rb->show ();
687                 midi_port_table_widgets.push_back (rb);
688                 midi_port_table.attach (*rb, 4, 5, n+2, n+3, FILL|EXPAND, FILL);
689                 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::mtc_port_chosen), (*i).second, rb, bb));
690
691                 if (session && i->second == session->mtc_port()) {
692                         rb->set_active (true);
693                 }
694                 
695                 rb = manage (new RadioButton ());
696                 rb->set_name ("OptionEditorToggleButton");
697                 if (n == 0) {
698                         mmc_button_group = rb->get_group();
699                 } else {
700                         rb->set_group (mmc_button_group);
701                 }
702                 rb->show ();
703                 midi_port_table_widgets.push_back (rb);
704                 midi_port_table.attach (*rb, 6, 7, n+2, n+3, FILL|EXPAND, FILL);
705                 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::mmc_port_chosen), (*i).second, rb, bb));
706
707                 if (session && i->second == session->mmc_port()) {
708                         rb->set_active (true);
709                 }
710
711                 rb = manage (new RadioButton ());
712                 rb->set_name ("OptionEditorToggleButton");
713                 if (n == 0) {
714                         midi_button_group = rb->get_group();
715                 } else {
716                         rb->set_group (midi_button_group);
717                 }
718                 rb->show ();
719                 midi_port_table_widgets.push_back (rb);
720                 midi_port_table.attach (*rb, 8, 9, n+2, n+3, FILL|EXPAND, FILL);
721                 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::midi_port_chosen), (*i).second, rb, bb));
722
723                 if (session && i->second == session->midi_port()) {
724                         rb->set_active (true);
725                 }
726
727         }
728
729         midi_port_table.show();
730 }
731
732 void
733 OptionEditor::remove_midi_port (MIDI::Port* port)
734 {
735         MIDI::Manager::instance()->remove_port (port);
736         redisplay_midi_ports ();
737 }
738
739 void
740 OptionEditor::add_midi_port ()
741 {
742         MidiPortDialog dialog;
743
744         dialog.set_position (WIN_POS_MOUSE);
745         dialog.set_transient_for (*this);
746
747         dialog.show ();
748
749         int ret = dialog.run ();
750
751         switch (ret) {
752         case RESPONSE_ACCEPT:
753                 break;
754         default:
755                 return;
756                 break;
757         }
758
759         Glib::ustring mode = dialog.port_mode_combo.get_active_text();
760         std::string smod;
761
762         if (mode == _("input")) {
763                 smod = X_("input");
764         } else if (mode == (_("output"))) {
765                 smod = X_("output");
766         } else {
767                 smod = "duplex";
768         }
769
770
771         XMLNode node (X_("MIDI-port"));
772
773         node.add_property ("tag", dialog.port_name.get_text());
774         node.add_property ("device", X_("ardour")); // XXX this can't be right for all types
775         node.add_property ("type", MIDI::PortFactory::default_port_type());
776         node.add_property ("mode", smod);
777
778         if (MIDI::Manager::instance()->add_port (node) != 0) {
779                 redisplay_midi_ports ();
780         }
781 }
782
783 bool
784 OptionEditor::port_removable (MIDI::Port *port)
785 {
786         if (!session) {
787                 return true;
788         }
789
790         if (port == session->mtc_port() ||
791             port == session->mmc_port() ||
792             port == session->midi_port()) {
793                 return false;
794         }
795         return true;
796 }
797
798 void
799 OptionEditor::mtc_port_chosen (MIDI::Port *port, Gtk::RadioButton* rb, Gtk::Button* bb) 
800 {
801         if (session) {
802                 if (rb->get_active()) {
803                         session->set_mtc_port (port->name());
804                         Config->set_mtc_port_name (port->name());
805                 } else {
806                         session->set_mtc_port ("");
807                 }
808                 bb->set_sensitive (port_removable (port));
809         }
810 }
811
812 void
813 OptionEditor::mmc_port_chosen (MIDI::Port* port, Gtk::RadioButton* rb, Gtk::Button* bb)
814 {
815         if (session) {
816                 if (rb->get_active()) {
817                         session->set_mmc_port (port->name());
818                         Config->set_mtc_port_name (port->name());
819                 } else {
820                         session->set_mmc_port ("");
821                 }
822                 bb->set_sensitive (port_removable (port));
823         }
824 }
825
826 void
827 OptionEditor::midi_port_chosen (MIDI::Port* port, Gtk::RadioButton* rb, Gtk::Button* bb)
828 {
829         if (session) {
830                 if (rb->get_active()) {
831                         session->set_midi_port (port->name());
832                         Config->set_midi_port_name (port->name());
833                 } else {
834                         session->set_midi_port ("");
835                 }
836                 bb->set_sensitive (port_removable (port));
837         }
838 }
839
840 void
841 OptionEditor::port_online_toggled (MIDI::Port* port, ToggleButton* tb)
842 {
843         bool wanted = tb->get_active();
844
845         if (port->input()) {
846                 if (wanted != port->input()->offline()) {
847                         port->input()->set_offline (wanted);
848                 } 
849         }
850 }
851
852 void
853 OptionEditor::map_port_online (MIDI::Port* port, ToggleButton* tb)
854 {
855         bool bstate = tb->get_active ();
856         
857         if (port->input()) {
858                 if (bstate != port->input()->offline()) {
859                         if (port->input()->offline()) {
860                                 tb->set_label (_("offline"));
861                                 tb->set_active (false);
862                         } else {
863                                 tb->set_label (_("online"));
864                                 tb->set_active (true);
865                         }
866                 }
867         }
868 }
869
870 void
871 OptionEditor::mmc_receive_device_id_adjusted ()
872 {
873         uint8_t id = (uint8_t) mmc_receive_device_id_spinner.get_value();
874         Config->set_mmc_receive_device_id (id);
875 }
876
877 void
878 OptionEditor::mmc_send_device_id_adjusted ()
879 {
880         uint8_t id = (uint8_t) mmc_send_device_id_spinner.get_value();
881         Config->set_mmc_send_device_id (id);
882 }
883
884 void
885 OptionEditor::port_trace_in_toggled (MIDI::Port* port, ToggleButton* tb)
886 {
887         bool trace = tb->get_active();
888
889         if (port->input()) {
890                 if (port->input()->tracing() != trace) {
891                         port->input()->trace (trace, &cerr, string (port->name()) + string (" input: "));
892                 }
893         }
894 }
895
896 void
897 OptionEditor::port_trace_out_toggled (MIDI::Port* port, ToggleButton* tb)
898 {
899         bool trace = tb->get_active();
900
901         if (port->output()) {
902                 if (port->output()->tracing() != trace) {
903                         port->output()->trace (trace, &cerr, string (port->name()) + string (" output: "));
904                 }
905         }
906 }
907
908 void
909 OptionEditor::save ()
910 {
911         /* XXX a bit odd that we save the entire session state here */
912
913         ui.save_state ("");
914 }
915
916 gint
917 OptionEditor::wm_close (GdkEventAny *ev)
918 {
919         save ();
920         hide ();
921         return TRUE;
922 }
923
924 void
925 OptionEditor::raid_path_changed ()
926 {
927         if (session) {
928                 Config->set_raid_path (session_raid_entry.get_text());
929         }
930 }
931
932 void
933 OptionEditor::click_browse_clicked ()
934 {
935         SoundFileChooser sfdb (*this, _("Choose Click"), session);
936         
937         sfdb.show_all ();
938         sfdb.present ();
939
940         int result = sfdb.run ();
941  
942         if (result == Gtk::RESPONSE_OK) {
943                 click_chosen(sfdb.get_filename());
944         }
945 }
946
947 void
948 OptionEditor::click_chosen (const string & path)
949 {
950         click_path_entry.set_text (path);
951         click_sound_changed ();
952 }
953
954 void
955 OptionEditor::click_emphasis_browse_clicked ()
956 {
957         SoundFileChooser sfdb (*this, _("Choose Click Emphasis"), session);
958
959         sfdb.show_all ();
960         sfdb.present ();
961
962         int result = sfdb.run ();
963
964         if (result == Gtk::RESPONSE_OK) {
965                 click_emphasis_chosen (sfdb.get_filename());
966         }
967 }
968
969 void
970 OptionEditor::click_emphasis_chosen (const string & path)
971 {       
972         click_emphasis_path_entry.set_text (path);
973         click_emphasis_sound_changed ();
974 }
975
976 void
977 OptionEditor::click_sound_changed ()
978 {
979         if (session) {
980                 string path = click_path_entry.get_text();
981
982                 if (path == Config->get_click_sound()) {
983                         return;
984                 }
985
986                 strip_whitespace_edges (path);
987
988                 if (path == _("internal")) {
989                         Config->set_click_sound ("");
990                 } else {
991                         Config->set_click_sound (path);
992                 }
993         }
994 }
995
996 void
997 OptionEditor::click_emphasis_sound_changed ()
998 {
999         if (session) {
1000                 string path = click_emphasis_path_entry.get_text();
1001
1002                 if (path == Config->get_click_emphasis_sound()) {
1003                         return;
1004                 }
1005
1006                 strip_whitespace_edges (path);
1007
1008                 if (path == _("internal")) {
1009                         Config->set_click_emphasis_sound ("");
1010                 } else {
1011                         Config->set_click_emphasis_sound (path);
1012                 }
1013         }
1014 }
1015
1016 void
1017 OptionEditor::clear_click_editor ()
1018 {
1019         if (click_io_selector) {
1020                 click_hpacker.remove (*click_io_selector);
1021                 click_hpacker.remove (*click_gpm);
1022                 delete click_io_selector;
1023                 delete click_gpm;
1024                 click_io_selector = 0;
1025                 click_gpm = 0;
1026         }
1027 }
1028
1029 void
1030 OptionEditor::setup_click_editor ()
1031 {
1032         Label* label;
1033
1034         if (first_click_setup) {
1035                 
1036                 click_path_entry.set_name ("OptionsEntry");
1037                 click_emphasis_path_entry.set_name ("OptionsEntry");
1038                 
1039                 click_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_sound_changed));
1040                 click_emphasis_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_emphasis_sound_changed));
1041                 
1042                 click_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_sound_changed));
1043                 click_emphasis_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_emphasis_sound_changed));
1044                 
1045                 click_browse_button.set_name ("EditorGTKButton");
1046                 click_emphasis_browse_button.set_name ("EditorGTKButton");
1047
1048                 click_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_browse_clicked));
1049                 click_emphasis_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_emphasis_browse_clicked));
1050
1051                 click_packer.set_border_width (12);
1052                 click_packer.set_spacing (5);
1053
1054                 click_table.set_col_spacings (10);
1055                 
1056                 label = manage(new Label(_("Click audio file")));
1057                 label->set_name ("OptionsLabel");
1058                 click_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL);
1059                 click_table.attach (click_path_entry, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1060                 click_table.attach (click_browse_button, 2, 3, 0, 1, FILL|EXPAND, FILL);
1061                 
1062                 label = manage(new Label(_("Click emphasis audiofile")));
1063                 label->set_name ("OptionsLabel");
1064                 click_table.attach (*label, 0, 1, 1, 2, FILL|EXPAND, FILL);
1065                 click_table.attach (click_emphasis_path_entry, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1066                 click_table.attach (click_emphasis_browse_button, 2, 3, 1, 2, FILL|EXPAND, FILL);
1067
1068                 click_packer.pack_start (click_table, false, false);
1069                 click_packer.pack_start (click_hpacker, false, false);
1070         
1071
1072                 click_hpacker.set_spacing (10);
1073
1074                 first_click_setup = false;
1075         }
1076
1077         click_path_entry.set_sensitive (true);
1078         click_emphasis_path_entry.set_sensitive (true);
1079
1080         click_io_selector = new IOSelector (*session, session->click_io(), false);
1081         click_gpm = new GainMeter (*session);
1082         click_gpm->set_io (session->click_io());
1083
1084         click_hpacker.pack_start (*click_io_selector, false, false);
1085         click_hpacker.pack_start (*click_gpm, false, false);
1086
1087         click_packer.show_all ();
1088 }
1089
1090 void
1091 OptionEditor::clear_auditioner_editor ()
1092 {
1093         if (auditioner_io_selector) {
1094                 audition_hpacker.remove (*auditioner_io_selector);
1095                 audition_hpacker.remove (*auditioner_gpm);
1096                 delete auditioner_io_selector;
1097                 delete auditioner_gpm;
1098                 auditioner_io_selector = 0;
1099                 auditioner_gpm = 0;
1100         }
1101 }
1102
1103 void
1104 OptionEditor::setup_auditioner_editor ()
1105 {
1106         audition_packer.set_border_width (12);
1107         audition_packer.set_spacing (5);
1108         audition_hpacker.set_spacing (10);
1109
1110         audition_label.set_name ("OptionEditorAuditionerLabel");
1111         audition_label.set_text (_("The auditioner is a dedicated mixer strip used\n"
1112                                    "for listening to specific regions outside the context\n"
1113                                    "of the overall mix. It can be connected just like any\n"
1114                                    "other mixer strip."));
1115         
1116         audition_packer.pack_start (audition_label, false, false, 10);
1117         audition_packer.pack_start (audition_hpacker, false, false);
1118 }
1119
1120 void
1121 OptionEditor::connect_audition_editor ()
1122 {
1123         auditioner_io_selector = new IOSelector (*session, session->the_auditioner(), false);
1124         auditioner_gpm = new GainMeter (*session);
1125         auditioner_gpm->set_io (session->the_auditioner());
1126
1127         audition_hpacker.pack_start (*auditioner_io_selector, false, false);
1128         audition_hpacker.pack_start (*auditioner_gpm, false, false);
1129
1130         auditioner_io_selector->show_all ();
1131         auditioner_gpm->show_all ();
1132 }
1133
1134 bool
1135 OptionEditor::focus_out_event_handler (GdkEventFocus* ev, void (OptionEditor::*pmf)()) 
1136 {
1137         (this->*pmf)();
1138         return false;
1139 }
1140
1141 static const struct {
1142     const char *name;
1143     guint   modifier;
1144 } modifiers[] = {
1145
1146 #ifdef GTKOSX 
1147
1148         /* Command = Meta
1149            Option/Alt = Mod1
1150         */
1151
1152         { "Shift", GDK_SHIFT_MASK },
1153         { "Command", GDK_META_MASK },
1154         { "Control", GDK_CONTROL_MASK },
1155         { "Option", GDK_MOD1_MASK },
1156         { "Command-Shift", GDK_MOD1_MASK|GDK_SHIFT_MASK },
1157         { "Command-Option", GDK_MOD1_MASK|GDK_MOD5_MASK },
1158         { "Shift-Option", GDK_SHIFT_MASK|GDK_MOD5_MASK },
1159         { "Shift-Command-Option", GDK_MOD5_MASK|GDK_SHIFT_MASK|GDK_MOD1_MASK },
1160
1161 #else
1162         { "Shift", GDK_SHIFT_MASK },
1163         { "Control", GDK_CONTROL_MASK },
1164         { "Alt (Mod1)", GDK_MOD1_MASK },
1165         { "Control-Shift", GDK_CONTROL_MASK|GDK_SHIFT_MASK },
1166         { "Control-Alt", GDK_CONTROL_MASK|GDK_MOD1_MASK },
1167         { "Shift-Alt", GDK_SHIFT_MASK|GDK_MOD1_MASK },
1168         { "Control-Shift-Alt", GDK_CONTROL_MASK|GDK_SHIFT_MASK|GDK_MOD1_MASK },
1169         { "Mod2", GDK_MOD2_MASK },
1170         { "Mod3", GDK_MOD3_MASK },
1171         { "Mod4", GDK_MOD4_MASK },
1172         { "Mod5", GDK_MOD5_MASK },
1173 #endif
1174         { 0, 0 }
1175 };
1176
1177 void
1178 OptionEditor::setup_keyboard_options ()
1179 {
1180         vector<string> dumb;
1181         Label* label;
1182
1183         keyboard_mouse_table.set_border_width (12);
1184         keyboard_mouse_table.set_row_spacings (5);
1185         keyboard_mouse_table.set_col_spacings (5);
1186
1187         /* internationalize and prepare for use with combos */
1188
1189         for (int i = 0; modifiers[i].name; ++i) {
1190                 dumb.push_back (_(modifiers[i].name));
1191         }
1192
1193         set_popdown_strings (edit_modifier_combo, dumb);
1194         edit_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::edit_modifier_chosen));
1195
1196         for (int x = 0; modifiers[x].name; ++x) {
1197                 if (modifiers[x].modifier == Keyboard::edit_modifier ()) {
1198                         edit_modifier_combo.set_active_text (_(modifiers[x].name));
1199                         break;
1200                 }
1201         }
1202
1203         label = manage (new Label (_("Edit using")));
1204         label->set_name ("OptionsLabel");
1205         label->set_alignment (1.0, 0.5);
1206                 
1207         keyboard_mouse_table.attach (*label, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1208         keyboard_mouse_table.attach (edit_modifier_combo, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1209
1210         label = manage (new Label (_("+ button")));
1211         label->set_name ("OptionsLabel");
1212         
1213         keyboard_mouse_table.attach (*label, 3, 4, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1214         keyboard_mouse_table.attach (edit_button_spin, 4, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1215
1216         edit_button_spin.set_name ("OptionsEntry");
1217         edit_button_adjustment.set_value (Keyboard::edit_button());
1218         edit_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::edit_button_changed));
1219
1220         set_popdown_strings (delete_modifier_combo, dumb);
1221         delete_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::delete_modifier_chosen));
1222
1223         for (int x = 0; modifiers[x].name; ++x) {
1224                 if (modifiers[x].modifier == Keyboard::delete_modifier ()) {
1225                         delete_modifier_combo.set_active_text (_(modifiers[x].name));
1226                         break;
1227                 }
1228         }
1229
1230         label = manage (new Label (_("Delete using")));
1231         label->set_name ("OptionsLabel");
1232         label->set_alignment (1.0, 0.5);
1233                 
1234         keyboard_mouse_table.attach (*label, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1235         keyboard_mouse_table.attach (delete_modifier_combo, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1236
1237         label = manage (new Label (_("+ button")));
1238         label->set_name ("OptionsLabel");
1239
1240         keyboard_mouse_table.attach (*label, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1241         keyboard_mouse_table.attach (delete_button_spin, 4, 5, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1242
1243         delete_button_spin.set_name ("OptionsEntry");
1244         delete_button_adjustment.set_value (Keyboard::delete_button());
1245         delete_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::delete_button_changed));
1246
1247         set_popdown_strings (snap_modifier_combo, dumb);
1248         snap_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::snap_modifier_chosen));
1249         
1250         for (int x = 0; modifiers[x].name; ++x) {
1251                 if (modifiers[x].modifier == (guint) Keyboard::snap_modifier ()) {
1252                         snap_modifier_combo.set_active_text (_(modifiers[x].name));
1253                         break;
1254                 }
1255         }
1256
1257         label = manage (new Label (_("Ignore snap using")));
1258         label->set_name ("OptionsLabel");
1259         label->set_alignment (1.0, 0.5);
1260         
1261         keyboard_mouse_table.attach (*label, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
1262         keyboard_mouse_table.attach (snap_modifier_combo, 1, 2, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
1263
1264         vector<string> strs;
1265         
1266         for (std::map<std::string,std::string>::iterator bf = Keyboard::binding_files.begin(); bf != Keyboard::binding_files.end(); ++bf) {
1267                 strs.push_back (bf->first);
1268         }
1269         
1270         set_popdown_strings (keyboard_layout_selector, strs);
1271         keyboard_layout_selector.set_active_text (Keyboard::current_binding_name());
1272         keyboard_layout_selector.signal_changed().connect (mem_fun (*this, &OptionEditor::bindings_changed));
1273
1274         label = manage (new Label (_("Keyboard layout")));
1275         label->set_name ("OptionsLabel");
1276         label->set_alignment (1.0, 0.5);
1277
1278         keyboard_mouse_table.attach (*label, 0, 1, 3, 4, Gtk::FILL|Gtk::EXPAND, FILL);
1279         keyboard_mouse_table.attach (keyboard_layout_selector, 1, 2, 3, 4, Gtk::FILL|Gtk::EXPAND, FILL);
1280 }
1281
1282 void
1283 OptionEditor::bindings_changed ()
1284 {
1285         string txt;
1286         
1287         txt = keyboard_layout_selector.get_active_text();
1288
1289         for (std::map<string,string>::iterator i = Keyboard::binding_files.begin(); i != Keyboard::binding_files.end(); ++i) {
1290                 if (txt == i->first) {
1291                         if (Keyboard::load_keybindings (i->second)) {
1292                                 Keyboard::save_keybindings ();
1293                         }
1294                 }
1295         }
1296 }
1297
1298 void
1299 OptionEditor::edit_modifier_chosen ()
1300 {
1301         string txt;
1302         
1303         txt = edit_modifier_combo.get_active_text();
1304
1305         for (int i = 0; modifiers[i].name; ++i) {
1306                 if (txt == _(modifiers[i].name)) {
1307                         Keyboard::set_edit_modifier (modifiers[i].modifier);
1308                         break;
1309                 }
1310         }
1311 }
1312
1313 void
1314 OptionEditor::delete_modifier_chosen ()
1315 {
1316         string txt;
1317         
1318         txt = delete_modifier_combo.get_active_text();
1319
1320         for (int i = 0; modifiers[i].name; ++i) {
1321                 if (txt == _(modifiers[i].name)) {
1322                         Keyboard::set_delete_modifier (modifiers[i].modifier);
1323                         break;
1324                 }
1325         }
1326 }
1327
1328 void
1329 OptionEditor::snap_modifier_chosen ()
1330 {
1331         string txt;
1332         
1333         txt = snap_modifier_combo.get_active_text();
1334
1335         for (int i = 0; modifiers[i].name; ++i) {
1336                 if (txt == _(modifiers[i].name)) {
1337                         Keyboard::set_snap_modifier (modifiers[i].modifier);
1338                         break;
1339                 }
1340         }
1341 }
1342
1343 void
1344 OptionEditor::delete_button_changed ()
1345 {
1346         Keyboard::set_delete_button ((guint) delete_button_adjustment.get_value());
1347 }
1348
1349 void
1350 OptionEditor::edit_button_changed ()
1351 {
1352         Keyboard::set_edit_button ((guint) edit_button_adjustment.get_value());
1353 }
1354
1355 void
1356 OptionEditor::parameter_changed (const char* parameter_name)
1357 {
1358         ENSURE_GUI_THREAD (bind (mem_fun (*this, &OptionEditor::parameter_changed), parameter_name));
1359
1360 #define PARAM_IS(x) (!strcmp (parameter_name, (x)))
1361         
1362         if (PARAM_IS ("timecode-source-is-synced")) {
1363                 synced_timecode_button.set_active (Config->get_timecode_source_is_synced());
1364         } else if (PARAM_IS ("history-depth")) {
1365                 int32_t depth = Config->get_history_depth();
1366                 
1367                 history_depth.set_value (depth);
1368                 history_depth_spinner.set_sensitive (depth != 0);
1369                 limit_history_button.set_active (depth != 0);
1370
1371         } else if (PARAM_IS ("saved-history-depth")) {
1372
1373                 saved_history_depth.set_value (Config->get_saved_history_depth());
1374
1375         } else if (PARAM_IS ("save-history")) {
1376
1377                 bool x = Config->get_save_history();
1378
1379                 save_history_button.set_active (x);
1380                 saved_history_depth_spinner.set_sensitive (x);
1381         } else if (PARAM_IS ("font-scale")) {
1382                 reset_dpi();
1383         }
1384 }