cleanup leftover problems from my commit yesterday; return of the windows
[ardour.git] / gtk2_ardour / option_editor.cc
1 /*
2     Copyright (C) 2001 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     $Id$
19 */
20
21 #include <ardour/session.h>
22 #include <ardour/audioengine.h>
23 #include <ardour/configuration.h>
24 #include <ardour/auditioner.h>
25 #include <ardour/crossfade.h>
26 #include <midi++/manager.h>
27 #include <gtkmm2ext/stop_signal.h>
28 #include <gtkmm2ext/utils.h>
29
30 #include "public_editor.h"
31 #include "mixer_ui.h"
32 #include "ardour_ui.h"
33 #include "io_selector.h"
34 #include "gain_meter.h"
35 #include "sfdb_ui.h"
36 #include "utils.h"
37 #include "editing.h"
38 #include "option_editor.h"
39
40 #include "i18n.h"
41
42 using namespace ARDOUR;
43 using namespace Gtk;
44 using namespace Editing;
45 using namespace Gtkmm2ext;
46 using namespace std;
47
48 static const gchar *psync_strings[] = {
49         N_("Internal"),
50         N_("Slave to MTC"),
51         N_("Sync with JACK"),
52         N_("never used but stops crashes"),
53         0
54 };
55
56 static const gchar *lmode_strings[] = {
57         N_("Later regions are higher"),
58         N_("Most recently added/moved/trimmed regions are higher"),
59         N_("Most recently added regions are higher"),
60         0
61 };
62
63 static const gchar *xfl_strings[] = {
64         N_("Span entire region overlap"),
65         N_("Short fades at the start of the overlap"),
66         0
67 };
68
69 static vector<string> positional_sync_strings;
70 static vector<string> layer_mode_strings;
71 static vector<string> xfade_model_strings;
72
73 OptionEditor::OptionEditor (ARDOUR_UI& uip, PublicEditor& ed, Mixer_UI& mixui)
74         : Dialog ("option editor"),
75           ui (uip),
76           editor (ed),
77           mixer (mixui),
78
79           path_table (9, 2),
80
81           /* Fades */
82
83           auto_xfade_button (_("Automatically create crossfades")),
84           xfade_active_button (_("New full-overlap crossfades are unmuted")),
85           layer_mode_label (_("Region layering mode")),
86           xfade_model_label (_("Crossfade model")),
87           short_xfade_adjustment (0, 1.0, 500.0, 5.0, 100.0),
88           short_xfade_slider (short_xfade_adjustment),
89
90           /* solo */
91           solo_latched_button (_("Latched solo")),
92           solo_via_bus_button (_("Solo via bus")),
93
94           /* display */
95
96           show_waveforms_button (_("Show waveforms")),
97           show_waveforms_recording_button (_("Show waveforms while recording")),
98           mixer_strip_width_button (_("Narrow mixer strips")),
99           show_measures_button (_("Show measure lines")),
100           follow_playhead_button (_("Follow playhead")),
101           
102           /* Sync */
103
104           send_mtc_button (_("Send MTC")),
105           send_mmc_button (_("Send MMC")),
106           jack_time_master_button (_("JACK time master")),
107           smpte_offset_clock (X_("SMPTEOffsetClock"), true, true),
108           smpte_offset_negative_button (_("SMPTE offset is negative")),
109
110           /* MIDI */
111
112           midi_feedback_button (_("Send MIDI parameter feedback")),
113           midi_control_button (_("MIDI parameter control")),
114           mmc_control_button (_("MMC control")),
115           
116           /* Click */
117
118           click_table (2, 3),
119           click_browse_button (_("Browse")),
120           click_emphasis_browse_button (_("Browse")),
121
122           /* kbd/mouse */
123
124           keyboard_mouse_table (3, 4),
125           delete_button_adjustment (3, 1, 5),
126           delete_button_spin (delete_button_adjustment),
127           edit_button_adjustment (3, 1, 5),
128           edit_button_spin (edit_button_adjustment),
129
130           /* Misc */
131
132           auto_connect_inputs_button (_("Auto-connect new track inputs to hardware")),
133           auto_connect_output_physical_button (_("Auto-connect new track outputs to hardware")),
134           auto_connect_output_master_button (_("Auto-connect new track outputs to master bus")),
135           auto_connect_output_manual_button (_("Manually connect new track outputs")),
136           hw_monitor_button(_("Use Hardware Monitoring")),
137           sw_monitor_button(_("Use Software Monitoring")),
138           plugins_stop_button (_("Stop plugins with transport")),
139           plugins_on_rec_button (_("Run plugins while recording")),
140           verify_remove_last_capture_button (_("Verify remove last capture")),
141           stop_rec_on_xrun_button (_("Stop recording on xrun")),
142           stop_at_end_button (_("Stop transport at end of session")),
143           debug_keyboard_button (_("Debug keyboard events")),
144           speed_quieten_button (_("-12dB gain reduction for ffwd/rew"))
145           
146 {
147         using namespace Notebook_Helpers;
148
149         click_io_selector = 0;
150         auditioner_io_selector = 0;
151
152         set_default_size (300, 300);
153         set_title (_("ardour: options editor"));
154         set_wmclass (_("ardour_option_editor"), "Ardour");
155
156         set_name ("OptionsWindow");
157         add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
158         
159         layer_mode_label.set_name ("OptionsLabel");
160         xfade_model_label.set_name ("OptionsLabel");
161         
162         VBox *vbox = get_vbox();
163         set_border_width (3);
164
165         vbox->set_spacing (4);
166         vbox->pack_start(notebook);
167
168         signal_delete_event().connect (mem_fun(*this, &OptionEditor::wm_close));
169
170         notebook.set_show_tabs (true);
171         notebook.set_show_border (true);
172         notebook.set_name ("OptionsNotebook");
173
174         setup_sync_options();
175         setup_path_options();
176         setup_fade_options ();
177         setup_solo_options ();
178         setup_display_options ();
179         setup_misc_options ();
180         setup_keyboard_options ();
181         setup_auditioner_editor ();
182
183         notebook.pages().push_back (TabElem (misc_packer, _("Misc")));
184         notebook.pages().push_back (TabElem (sync_packer, _("Sync")));
185         notebook.pages().push_back (TabElem (path_table, _("Paths/Files")));
186         notebook.pages().push_back (TabElem (display_packer, _("Display")));
187         notebook.pages().push_back (TabElem (keyboard_mouse_table, _("Kbd/Mouse")));
188         notebook.pages().push_back (TabElem (click_packer, _("Click")));
189         notebook.pages().push_back (TabElem (audition_packer, _("Audition")));
190         notebook.pages().push_back (TabElem (fade_packer, _("Layers & Fades")));
191         notebook.pages().push_back (TabElem (solo_packer, _("Solo")));
192
193         if (!MIDI::Manager::instance()->get_midi_ports().empty()) {
194                 setup_midi_options ();
195                 notebook.pages().push_back (TabElem (midi_packer, _("MIDI")));
196         }
197
198         set_session (0);
199         show_all_children();
200 }
201
202 void
203 OptionEditor::set_session (Session *s)
204 {
205         clear_click_editor ();
206         clear_auditioner_editor ();
207
208         click_path_entry.set_text ("");
209         click_emphasis_path_entry.set_text ("");
210         session_raid_entry.set_text ("");
211
212         send_mtc_button.set_sensitive (false);
213         send_mmc_button.set_sensitive (false);
214         midi_feedback_button.set_sensitive (false);
215         midi_control_button.set_sensitive (false);
216         mmc_control_button.set_sensitive (false);
217         click_path_entry.set_sensitive (false);
218         click_emphasis_path_entry.set_sensitive (false);
219         session_raid_entry.set_sensitive (false);
220         plugins_on_rec_button.set_sensitive (false);
221         verify_remove_last_capture_button.set_sensitive (false);
222         slave_type_combo.set_sensitive (false);
223         solo_latched_button.set_sensitive (false);
224         solo_via_bus_button.set_sensitive (false);
225         smpte_fps_combo.set_sensitive (false);
226         meter_hold_combo.set_sensitive (false);
227         meter_falloff_combo.set_sensitive (false);
228         auto_connect_inputs_button.set_sensitive (false);
229         auto_connect_output_physical_button.set_sensitive (false);
230         auto_connect_output_master_button.set_sensitive (false);
231         auto_connect_output_manual_button.set_sensitive (false);
232         layer_mode_combo.set_sensitive (false);
233         short_xfade_slider.set_sensitive (false);
234         smpte_offset_negative_button.set_sensitive (false);
235
236         smpte_offset_clock.set_session (s);
237
238         if ((session = s) == 0) {
239                 return;
240         }
241
242         send_mtc_button.set_sensitive (true);
243         send_mmc_button.set_sensitive (true);
244         midi_feedback_button.set_sensitive (true);
245         midi_control_button.set_sensitive (true);
246         mmc_control_button.set_sensitive (true);
247         click_path_entry.set_sensitive (true);
248         click_emphasis_path_entry.set_sensitive (true);
249         session_raid_entry.set_sensitive (true);
250         plugins_on_rec_button.set_sensitive (true);
251         verify_remove_last_capture_button.set_sensitive (true);
252         slave_type_combo.set_sensitive (true);
253         solo_latched_button.set_sensitive (true);
254         solo_via_bus_button.set_sensitive (true);
255         smpte_fps_combo.set_sensitive (true);
256         meter_hold_combo.set_sensitive (true);
257         meter_falloff_combo.set_sensitive (true);
258         auto_connect_inputs_button.set_sensitive (true);
259         auto_connect_output_physical_button.set_sensitive (true);
260         auto_connect_output_master_button.set_sensitive (true);
261         auto_connect_output_manual_button.set_sensitive (true);
262         layer_mode_combo.set_sensitive (true);
263         short_xfade_slider.set_sensitive (true);
264         smpte_offset_negative_button.set_sensitive (true);
265
266         if (!s->smpte_drop_frames) {
267                 // non-drop frames
268                 if (s->smpte_frames_per_second == 24.0)
269                         smpte_fps_combo.set_active_text (_("24 FPS"));
270                 else if (s->smpte_frames_per_second == 25.0)
271                         smpte_fps_combo.set_active_text (_("25 FPS"));
272                 else if (s->smpte_frames_per_second == 30.0)
273                         smpte_fps_combo.set_active_text (_("30 FPS"));
274                 else
275                         smpte_fps_combo.set_active_text (_("???"));
276         } else {
277                 // drop frames
278                 if (floor(s->smpte_frames_per_second) == 29.0)
279                         smpte_fps_combo.set_active_text (_("30 FPS drop"));
280                 else
281                         smpte_fps_combo.set_active_text (_("???"));
282         }
283         
284         smpte_offset_clock.set_session (s);
285         smpte_offset_clock.set (s->smpte_offset (), true);
286
287         smpte_offset_negative_button.set_active (session->smpte_offset_negative());
288         send_mtc_button.set_active (session->get_send_mtc());
289
290         /* MIDI I/O */
291
292         send_mmc_button.set_active (session->get_send_mmc());
293         midi_control_button.set_active (session->get_midi_control());
294         midi_feedback_button.set_active (session->get_midi_feedback());
295         mmc_control_button.set_active (session->get_mmc_control());
296
297         /* set up port assignments */
298
299         std::map<MIDI::Port*,vector<RadioButton*> >::iterator res;
300
301         if (session->mtc_port()) {
302                 if ((res = port_toggle_buttons.find (session->mtc_port())) != port_toggle_buttons.end()) {
303                         (*res).second[MtcIndex]->set_active (true);
304                 }
305         } 
306
307         if (session->mmc_port ()) {
308                 if ((res = port_toggle_buttons.find (session->mmc_port())) != port_toggle_buttons.end()) {
309                         (*res).second[MmcIndex]->set_active (true);
310                 } 
311         }
312
313         if (session->midi_port()) {
314                 if ((res = port_toggle_buttons.find (session->midi_port())) != port_toggle_buttons.end()) {
315                         (*res).second[MidiIndex]->set_active (true);
316                 }
317         }
318
319         auto_connect_inputs_button.set_active (session->get_input_auto_connect());
320
321         Session::AutoConnectOption oac = session->get_output_auto_connect();
322         if (oac & Session::AutoConnectPhysical) {
323                 auto_connect_output_physical_button.set_active (true);
324         } else if (oac & Session::AutoConnectMaster) {
325                 auto_connect_output_master_button.set_active (true);
326         } else {
327                 auto_connect_output_manual_button.set_active (true);
328         }
329
330         setup_click_editor ();
331         connect_audition_editor ();
332
333         plugins_on_rec_button.set_active (session->get_recording_plugins ());
334         verify_remove_last_capture_button.set_active (Config->get_verify_remove_last_capture());
335
336         layer_mode_combo.set_active_text (layer_mode_strings[session->get_layer_model()]);
337         xfade_model_combo.set_active_text (xfade_model_strings[session->get_xfade_model()]);
338
339         short_xfade_adjustment.set_value ((Crossfade::short_xfade_length() / (float) session->frame_rate()) * 1000.0);
340
341         xfade_active_button.set_active (session->get_crossfades_active());
342         solo_latched_button.set_active (session->solo_latched());
343         solo_via_bus_button.set_active (session->solo_model() == Session::SoloBus);
344         
345         add_session_paths ();
346
347         vector<string> dumb;
348         dumb.push_back (positional_sync_strings[Session::None]);
349         dumb.push_back (positional_sync_strings[Session::JACK]);
350         if (session->mtc_port()) {
351                 dumb.push_back (positional_sync_strings[Session::MTC]);
352         } 
353         set_popdown_strings (slave_type_combo, dumb);
354
355         // meter stuff
356         if (session->meter_falloff() == 0.0f) {
357                 meter_falloff_combo.set_active_text (_("Off"));
358         } else if (session->meter_falloff() <= 0.3f) {
359                 meter_falloff_combo.set_active_text (_("Slowest"));
360         } else if (session->meter_falloff() <= 0.4f) {
361                 meter_falloff_combo.set_active_text (_("Slow"));
362         } else if (session->meter_falloff() <= 0.8f) {
363                 meter_falloff_combo.set_active_text (_("Medium"));
364         } else if (session->meter_falloff() <= 1.4f) {
365                 meter_falloff_combo.set_active_text (_("Fast"));
366         } else if (session->meter_falloff() <= 2.0f) {
367                 meter_falloff_combo.set_active_text (_("Faster"));
368         } else {
369                 meter_falloff_combo.set_active_text (_("Fastest"));
370         }
371
372         switch ((int) floor (session->meter_hold())) {
373         case 0:
374                 meter_hold_combo.set_active_text (_("Off"));
375                 break;
376         case 40:
377                 meter_hold_combo.set_active_text (_("Short"));
378                 break;
379         case 100:
380                 meter_hold_combo.set_active_text (_("Medium"));
381                 break;
382         case 200:
383                 meter_hold_combo.set_active_text (_("Long"));
384                 break;
385         }
386         
387         session_control_changed (Session::SlaveType);
388         session_control_changed (Session::AlignChoice);
389         session->ControlChanged.connect (mem_fun(*this, &OptionEditor::queue_session_control_changed));
390 }
391
392 OptionEditor::~OptionEditor ()
393 {
394 }
395
396 static const gchar *native_format_strings[] = {
397         N_("Broadcast WAVE/floating point"),
398         N_("WAVE/floating point"),
399         0
400 };
401
402 void
403 OptionEditor::setup_path_options()
404 {
405         Gtk::Label* label;
406
407         path_table.set_homogeneous (true);
408         path_table.set_border_width (12);
409         path_table.set_row_spacings (5);
410
411         session_raid_entry.set_name ("OptionsEntry");
412
413         session_raid_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::raid_path_changed));
414
415         label = manage(new Label(_("session RAID path")));
416         label->set_name ("OptionsLabel");
417         path_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL);
418         path_table.attach (session_raid_entry, 1, 3, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
419
420         label = manage(new Label(_("Native Format")));
421         label->set_name ("OptionsLabel");
422         path_table.attach (*label, 0, 1, 1, 2, FILL|EXPAND, FILL);
423         path_table.attach (native_format_combo, 1, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
424
425         vector<string> nfstrings = internationalize (native_format_strings);
426
427         set_popdown_strings (native_format_combo, nfstrings);
428         native_format_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::native_format_chosen));
429
430         fixup_combo_size (native_format_combo, nfstrings);
431
432         if (Config->get_native_format_is_bwf()) {
433                 native_format_combo.set_active_text (native_format_strings[0]);
434         } else {
435                 native_format_combo.set_active_text (native_format_strings[1]);
436         }
437         
438         path_table.show_all();
439 }
440
441 void
442 OptionEditor::add_session_paths ()
443 {
444         click_path_entry.set_sensitive (true);
445         click_emphasis_path_entry.set_sensitive (true);
446         session_raid_entry.set_sensitive (true);
447
448         if (session->click_sound.length() == 0) {
449                 click_path_entry.set_text (_("internal"));
450         } else {
451                 click_path_entry.set_text (session->click_sound);
452         }
453
454         if (session->click_emphasis_sound.length() == 0) {
455                 click_emphasis_path_entry.set_text (_("internal"));
456         } else {
457                 click_emphasis_path_entry.set_text (session->click_emphasis_sound);
458         }
459
460         session_raid_entry.set_text(session->raid_path());
461 }
462
463 void
464 OptionEditor::setup_fade_options ()
465 {
466         Gtk::HBox* hbox;
467         vector<string> dumb;
468         
469         auto_xfade_button.set_name ("OptionEditorToggleButton");
470         xfade_active_button.set_name ("OptionEditorToggleButton");
471
472         hbox = manage (new HBox);
473         hbox->set_border_width (12);
474         hbox->pack_start (auto_xfade_button, false, false);
475         fade_packer.pack_start (*hbox, false, false);
476
477         hbox = manage (new HBox);
478         hbox->set_border_width (12);
479         hbox->pack_start (xfade_active_button, false, false);
480         fade_packer.pack_start (*hbox, false, false);
481
482         layer_mode_strings = internationalize (lmode_strings);
483
484         dumb.push_back (lmode_strings[Session::LaterHigher]);
485         dumb.push_back (lmode_strings[Session::MoveAddHigher]);
486         dumb.push_back (lmode_strings[Session::AddHigher]);
487         set_popdown_strings (layer_mode_combo, dumb);
488
489         layer_mode_combo.signal_changed ().connect (mem_fun(*this, &OptionEditor::layer_mode_chosen));
490
491         fixup_combo_size (layer_mode_combo, layer_mode_strings);
492
493         hbox = manage (new HBox);
494         hbox->set_border_width (5);
495         hbox->set_spacing (10);
496         hbox->pack_start (layer_mode_label, false, false);
497         hbox->pack_start (layer_mode_combo, false, false);
498         fade_packer.pack_start (*hbox, false, false);
499
500         xfade_model_strings = internationalize (xfl_strings);
501
502         dumb.clear ();
503         dumb.push_back (xfade_model_strings[FullCrossfade]);
504         dumb.push_back (xfade_model_strings[ShortCrossfade]);
505         set_popdown_strings (xfade_model_combo, dumb);
506
507         xfade_model_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::xfade_model_chosen));
508
509         fixup_combo_size (xfade_model_combo, xfade_model_strings);
510
511         hbox = manage (new HBox);
512         hbox->set_border_width (5);
513         hbox->set_spacing (10);
514         hbox->pack_start (xfade_model_label, false, false);
515         hbox->pack_start (xfade_model_combo, false, false);
516         fade_packer.pack_start (*hbox, false, false);
517
518         auto_xfade_button.set_active (Config->get_auto_xfade());
519         /* xfade and layer mode active requires session */
520
521         auto_xfade_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::auto_xfade_clicked));
522         xfade_active_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::xfade_active_clicked));
523         
524         Label* short_xfade_label = manage (new Label (_("Short crossfade length (msecs)")));
525         short_xfade_label->set_name ("OptionsLabel");
526         
527         hbox = manage (new HBox);
528         hbox->set_border_width (5);
529         hbox->set_spacing (10);
530         hbox->pack_start (*short_xfade_label, false, false);
531         hbox->pack_start (short_xfade_slider, true, true);
532         fade_packer.pack_start (*hbox, false, false);
533
534         short_xfade_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::short_xfade_adjustment_changed));
535
536         fade_packer.show_all ();
537 }
538
539 void
540 OptionEditor::short_xfade_adjustment_changed ()
541 {
542         if (session) {
543                 float val = short_xfade_adjustment.get_value();
544                 
545                 /* val is in msecs */
546                 
547                 Crossfade::set_short_xfade_length ((jack_nframes_t) floor (session->frame_rate() * (val / 1000.0)));
548         }
549 }
550
551 void
552 OptionEditor::layer_mode_chosen ()
553 {
554         if (!session) {
555                 return;
556         }
557
558         string which = layer_mode_combo.get_active_text ();
559
560         if (which == layer_mode_strings[Session::LaterHigher]) {
561                 session->set_layer_model (Session::LaterHigher);
562         } else if (which == layer_mode_strings[Session::MoveAddHigher]) {
563                 session->set_layer_model (Session::MoveAddHigher);
564         } else if (which == layer_mode_strings[Session::AddHigher]) {
565                 session->set_layer_model (Session::AddHigher);
566         }
567 }
568
569 void
570 OptionEditor::xfade_model_chosen ()
571 {
572         if (!session) {
573                 return;
574         }
575
576         string which = xfade_model_combo.get_active_text ();
577
578         if (which == xfade_model_strings[FullCrossfade]) {
579                 session->set_xfade_model (FullCrossfade);
580         } else if (which == xfade_model_strings[ShortCrossfade]) {
581                 session->set_xfade_model (ShortCrossfade);
582         }
583 }
584
585 void
586 OptionEditor::auto_xfade_clicked ()
587 {
588         Config->set_auto_xfade (auto_xfade_button.get_active());
589 }
590
591 void
592 OptionEditor::xfade_active_clicked ()
593 {
594         if (session) {
595                 session->set_crossfades_active (xfade_active_button.get_active());
596         }
597 }
598
599 void
600 OptionEditor::setup_solo_options ()
601 {
602         Gtk::HBox* hbox;
603
604         solo_via_bus_button.set_name ("OptionEditorToggleButton");
605         solo_latched_button.set_name ("OptionEditorToggleButton");
606
607         hbox = manage (new HBox);
608         hbox->set_border_width (12);
609         hbox->pack_start (solo_via_bus_button, false, false);
610         solo_packer.pack_start (*hbox, false, false);
611
612         hbox = manage (new HBox);
613         hbox->set_border_width (12);
614         hbox->pack_start (solo_latched_button, false, false);
615         solo_packer.pack_start (*hbox, false, false);
616
617         solo_via_bus_button.signal_clicked().connect 
618                 (mem_fun(*this, &OptionEditor::solo_via_bus_clicked));
619         solo_latched_button.signal_clicked().connect 
620                 (mem_fun(*this, &OptionEditor::solo_latched_clicked));
621
622         solo_packer.show_all ();
623 }
624
625 void
626 OptionEditor::solo_via_bus_clicked ()
627 {
628         if (!session) {
629                 return;
630         }
631
632         if (solo_via_bus_button.get_active()) {
633                 session->set_solo_model (Session::SoloBus);
634         } else {
635                 session->set_solo_model (Session::InverseMute);
636         }
637 }
638
639 void
640 OptionEditor::solo_latched_clicked ()
641 {
642         if (!session) {
643                 return;
644         }
645
646         bool x = solo_latched_button.get_active();
647
648         if (x != session->solo_latched()) {
649                 session->set_solo_latched (x);
650         }
651 }
652
653 void
654 OptionEditor::setup_display_options ()
655 {
656         HBox* hbox;
657         vector<string> dumb;
658
659         display_packer.set_border_width (12);
660         display_packer.set_spacing (5);
661
662         show_waveforms_button.set_name ("OptionEditorToggleButton");
663         show_waveforms_recording_button.set_name ("OptionEditorToggleButton");
664         show_measures_button.set_name ("OptionEditorToggleButton");
665         follow_playhead_button.set_name ("OptionEditorToggleButton");
666         mixer_strip_width_button.set_name ("OptionEditorToggleButton");
667
668         mixer_strip_width_button.set_active (mixer.get_strip_width() == Narrow);
669
670         hbox = manage (new HBox);
671         hbox->set_border_width (8);
672         hbox->pack_start (show_waveforms_button, false, false);
673         display_packer.pack_start (*hbox, false, false);
674
675         hbox = manage (new HBox);
676         hbox->set_border_width (8);
677         hbox->pack_start (show_waveforms_recording_button, false, false);
678         display_packer.pack_start (*hbox, false, false);
679         
680         hbox = manage (new HBox);
681         hbox->set_border_width (8);
682         hbox->pack_start (show_measures_button, false, false);
683         display_packer.pack_start (*hbox, false, false);
684
685         hbox = manage (new HBox);
686         hbox->set_border_width (8);
687         hbox->pack_start (mixer_strip_width_button, false, false);
688         display_packer.pack_start (*hbox, false, false);
689
690         hbox = manage (new HBox);
691         hbox->set_border_width (8);
692         hbox->pack_start (follow_playhead_button, false, false);
693         display_packer.pack_start (*hbox, false, false);
694
695         Label *meter_hold_label = manage (new Label (_("Meter Peak Hold")));
696         meter_hold_label->set_name ("OptionsLabel");
697         dumb.clear ();
698         dumb.push_back (_("Off"));
699         dumb.push_back (_("Short"));
700         dumb.push_back (_("Medium"));
701         dumb.push_back (_("Long"));
702         set_popdown_strings (meter_hold_combo, dumb);
703         meter_hold_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::meter_hold_chosen));
704         hbox = manage (new HBox);
705         hbox->set_border_width (8);
706         hbox->set_spacing (8);
707         hbox->pack_start (*meter_hold_label, false, false);
708         hbox->pack_start (meter_hold_combo, false, false);
709         display_packer.pack_start (*hbox, false, false);
710
711         Label *meter_falloff_label = manage (new Label (_("Meter Falloff")));
712         meter_falloff_label->set_name ("OptionsLabel");
713         dumb.clear ();
714         dumb.push_back (_("Off"));
715         dumb.push_back (_("Slowest"));
716         dumb.push_back (_("Slow"));
717         dumb.push_back (_("Medium"));
718         dumb.push_back (_("Fast"));
719         dumb.push_back (_("Faster"));
720         dumb.push_back (_("Fastest"));
721         set_popdown_strings (meter_falloff_combo, dumb);
722         meter_falloff_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::meter_falloff_chosen));
723         hbox = manage (new HBox);
724         hbox->set_border_width (8);
725         hbox->set_spacing (8);
726         hbox->pack_start (*meter_falloff_label, false, false);
727         hbox->pack_start (meter_falloff_combo, false, false);
728         display_packer.pack_start (*hbox, false, false);
729         
730         
731         show_waveforms_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::show_waveforms_clicked));
732         show_waveforms_recording_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::show_waveforms_recording_clicked));
733         show_measures_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::show_measures_clicked));
734         mixer_strip_width_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::strip_width_clicked));
735         follow_playhead_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::follow_playhead_clicked));
736
737         editor.DisplayControlChanged.connect (mem_fun(*this, &OptionEditor::display_control_changed));
738
739         show_measures_button.set_active (editor.show_measures());
740         show_waveforms_button.set_active (editor.show_waveforms());
741         show_waveforms_recording_button.set_active (editor.show_waveforms_recording());
742         follow_playhead_button.set_active (editor.follow_playhead());
743 }
744
745 void
746 OptionEditor::meter_hold_chosen ()
747 {
748         if (session) {
749                 string str = meter_hold_combo.get_active_text();
750                 
751                 if (str == _("Off")) {
752                         session->set_meter_hold (0);
753                 } else if (str == _("Short")) {
754                         session->set_meter_hold (40);
755                 } else if (str == _("Medium")) {
756                         session->set_meter_hold (100);
757                 } else if (str == _("Long")) {
758                         session->set_meter_hold (200);
759                 }
760         }
761 }
762
763 void
764 OptionEditor::meter_falloff_chosen ()
765 {
766         if (session) {
767                 string str = meter_falloff_combo.get_active_text();
768                 
769                 if (str == _("Off")) {
770                         session->set_meter_falloff (0.0f);
771                 } else if (str == _("Slowest")) {
772                         session->set_meter_falloff (0.266f); // 6.6 dB/sec falloff at update rate of 40 ms
773                 } else if (str == _("Slow")) {
774                         session->set_meter_falloff (0.342f); // 8.6 dB/sec falloff at update rate of 40 ms
775                 } else if (str == _("Medium")) {
776                         session->set_meter_falloff  (0.7f);
777                 } else if (str == _("Fast")) {
778                         session->set_meter_falloff (1.1f);
779                 } else if (str == _("Faster")) {
780                         session->set_meter_falloff (1.5f);
781                 } else if (str == _("Fastest")) {
782                         session->set_meter_falloff (2.5f);
783                 }
784         }
785 }
786
787 void
788 OptionEditor::display_control_changed (Editing::DisplayControl dc)
789 {
790         ToggleButton* button = 0;
791         bool val = true;
792
793         switch (dc) {
794         case ShowMeasures:
795                 val = editor.show_measures ();
796                 button = &show_measures_button;
797                 break;
798         case ShowWaveforms:
799                 val = editor.show_waveforms ();
800                 button = &show_waveforms_button;
801                 break;
802         case ShowWaveformsRecording:
803                 val = editor.show_waveforms_recording ();
804                 button = &show_waveforms_recording_button;
805                 break;
806         case FollowPlayhead:
807                 val = editor.follow_playhead ();
808                 button = &follow_playhead_button;
809                 break;
810         }
811
812         if (button->get_active() != val) {
813                 button->set_active (val);
814         }
815 }
816
817 void
818 OptionEditor::setup_sync_options ()
819 {
820         Label *slave_type_label = manage (new Label (_("Positional Sync")));
821         HBox* hbox;
822         vector<string> dumb;
823
824         slave_type_label->set_name("OptionsLabel");
825         positional_sync_strings = internationalize (psync_strings);
826
827         slave_type_combo.set_name ("OptionsEntry");
828         slave_type_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::slave_type_chosen));
829
830         dumb.clear ();
831         dumb.push_back (X_("24 FPS"));
832         dumb.push_back (X_("25 FPS"));
833         dumb.push_back (X_("30 FPS drop"));
834         dumb.push_back (X_("30 FPS non-drop"));
835         
836         set_popdown_strings (smpte_fps_combo, dumb);
837         smpte_fps_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::smpte_fps_chosen));
838         
839         smpte_offset_clock.set_mode (AudioClock::SMPTE);
840         smpte_offset_clock.ValueChanged.connect (mem_fun(*this, &OptionEditor::smpte_offset_chosen));
841         
842         send_mtc_button.set_name ("OptionEditorToggleButton");
843         jack_time_master_button.set_name ("OptionEditorToggleButton");
844         smpte_offset_negative_button.set_name ("OptionEditorToggleButton");
845
846         send_mtc_button.unset_flags (Gtk::CAN_FOCUS);
847         jack_time_master_button.unset_flags (Gtk::CAN_FOCUS);
848         smpte_offset_negative_button.unset_flags (Gtk::CAN_FOCUS);
849
850         hbox = manage (new HBox);
851         hbox->set_border_width (5);
852         hbox->set_spacing (10);
853         hbox->pack_start (*slave_type_label, false, false);
854         hbox->pack_start (slave_type_combo, false, false);
855
856         sync_packer.pack_start (*hbox, false, false);
857         
858         hbox = manage (new HBox);
859         hbox->set_border_width (5);
860         hbox->pack_start (send_mtc_button, false, false);
861         sync_packer.pack_start (*hbox, false, false);
862
863         hbox = manage (new HBox);
864         hbox->set_border_width (5);
865         hbox->pack_start (jack_time_master_button, false, false);
866         sync_packer.pack_start (*hbox, false, false);
867
868         Label *smpte_fps_label = manage (new Label (_("SMPTE Frames/second")));
869         Label *smpte_offset_label = manage (new Label (_("SMPTE Offset")));
870         smpte_fps_label->set_name("OptionsLabel");
871         smpte_offset_label->set_name("OptionsLabel");
872         
873         hbox = manage (new HBox);
874         hbox->set_border_width (5);
875         hbox->set_spacing (10);
876         hbox->pack_start (*smpte_fps_label, false, false);
877         hbox->pack_start (smpte_fps_combo, false, false);
878
879         sync_packer.pack_start (*hbox, false, false);
880
881         hbox = manage (new HBox);
882         hbox->set_border_width (5);
883         hbox->set_spacing (10);
884         hbox->pack_start (*smpte_offset_label, false, false);
885         hbox->pack_start (smpte_offset_clock, false, false);
886         hbox->pack_start (smpte_offset_negative_button, false, false);
887
888         sync_packer.pack_start (*hbox, false, false);
889
890         jack_time_master_button.set_active (Config->get_jack_time_master());
891
892         send_mtc_button.signal_button_press_event().connect (bind (mem_fun(*this, &OptionEditor::send_mtc_toggled), &send_mtc_button));
893         jack_time_master_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::jack_time_master_clicked));
894         smpte_offset_negative_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::smpte_offset_negative_clicked));
895 }
896
897 void
898 OptionEditor::smpte_offset_negative_clicked ()
899 {
900         if (session) {
901                 session->set_smpte_offset_negative (smpte_offset_negative_button.get_active());
902         }
903 }
904
905 void
906 OptionEditor::smpte_fps_chosen ()
907 {
908         if (session) {
909                 string str = smpte_fps_combo.get_active_text();
910                 
911                 if (str == X_("24 FPS")) {
912                         session->set_smpte_type (24.0, false);
913                 } else if (str == X_("25 FPS")) {
914                         session->set_smpte_type (25.0, false);
915                 } else if (str == X_("30 FPS drop")) {
916                         session->set_smpte_type (29.97, true);
917                 } else if (str == X_("30 FPS non-drop")) {
918                         session->set_smpte_type (30.0, false);
919                 }
920         }
921 }
922
923 void
924 OptionEditor::smpte_offset_chosen()
925 {
926         if (session) {
927                 jack_nframes_t frames = smpte_offset_clock.current_duration();
928                 session->set_smpte_offset (frames);
929         }
930 }
931
932
933 void
934 OptionEditor::setup_midi_options ()
935 {
936         HBox* hbox;
937         MIDI::Manager::PortMap::const_iterator i;
938         const MIDI::Manager::PortMap& ports = MIDI::Manager::instance()->get_midi_ports();
939         int n;
940         ToggleButton* tb;
941         RadioButton* rb;
942
943         Gtk::Table* table = manage (new Table (ports.size() + 4, 9));
944
945         table->set_row_spacings (6);
946         table->set_col_spacings (10);
947
948         table->attach (*(manage (new Label (X_("Port")))), 0, 1, 0, 1);
949         table->attach (*(manage (new Label (X_("Offline")))), 1, 2, 0, 1);
950         table->attach (*(manage (new Label (X_("Trace\nInput")))), 2, 3, 0, 1);
951         table->attach (*(manage (new Label (X_("Trace\nOutput")))), 3, 4, 0, 1);
952         table->attach (*(manage (new Label (X_("MTC")))), 4, 5, 0, 1);
953         table->attach (*(manage (new Label (X_("MMC")))), 6, 7, 0, 1);
954         table->attach (*(manage (new Label (X_("MIDI Parameter\nControl")))), 8, 9, 0, 1);
955
956         table->attach (*(manage (new HSeparator())), 0, 9, 1, 2);
957         table->attach (*(manage (new VSeparator())), 5, 6, 0, 8);
958         table->attach (*(manage (new VSeparator())), 7, 8, 0, 8);
959         
960         for (n = 0, i = ports.begin(); i != ports.end(); ++n, ++i) {
961
962                 pair<MIDI::Port*,vector<RadioButton*> > newpair;
963
964                 newpair.first = i->second;
965
966                 table->attach (*(manage (new Label (i->first))), 0, 1, n+2, n+3,FILL|EXPAND, FILL );
967                 tb = manage (new ToggleButton (_("online")));
968                 tb->set_name ("OptionEditorToggleButton");
969
970                 /* remember, we have to handle the i18n case where the relative
971                    lengths of the strings in language N is different than in english.
972                 */
973
974                 if (strlen (_("offline")) > strlen (_("online"))) {
975                         set_size_request_to_display_given_text (*tb, _("offline"), 15, 12);
976                 } else {
977                         set_size_request_to_display_given_text (*tb, _("online"), 15, 12);
978                 }
979
980                 tb->set_active (!(*i).second->input()->offline());
981                 tb->signal_button_press_event().connect (bind (mem_fun(*this, &OptionEditor::port_online_toggled), (*i).second, tb));
982                 (*i).second->input()->OfflineStatusChanged.connect (bind (mem_fun(*this, &OptionEditor::map_port_online), (*i).second, tb));
983                 table->attach (*tb, 1, 2, n+2, n+3, FILL|EXPAND, FILL);
984
985                 tb = manage (new ToggleButton ());
986                 tb->set_name ("OptionEditorToggleButton");
987                 tb->signal_button_press_event().connect (bind (mem_fun(*this, &OptionEditor::port_trace_in_toggled), (*i).second, tb));
988                 tb->set_size_request (10, 10);
989                 table->attach (*tb, 2, 3, n+2, n+3, FILL|EXPAND, FILL);
990
991                 tb = manage (new ToggleButton ());
992                 tb->set_name ("OptionEditorToggleButton");
993                 tb->signal_button_press_event().connect (bind (mem_fun(*this, &OptionEditor::port_trace_out_toggled), (*i).second, tb));
994                 tb->set_size_request (10, 10);
995                 table->attach (*tb, 3, 4, n+2, n+3, FILL|EXPAND, FILL);
996
997                 rb = manage (new RadioButton ());
998                 newpair.second.push_back (rb);
999                 rb->set_name ("OptionEditorToggleButton");
1000                 if (n == 0) {
1001                         mtc_button_group = rb->get_group();
1002                 } else {
1003                         rb->set_group (mtc_button_group);
1004
1005                 }
1006                 table->attach (*rb, 4, 5, n+2, n+3, FILL|EXPAND, FILL);
1007                 rb->signal_button_press_event().connect (bind (mem_fun(*this, &OptionEditor::mtc_port_chosen), (*i).second, rb));
1008
1009                 if (Config->get_mtc_port_name() == i->first) {
1010                         rb->set_active (true);
1011                 }
1012                 
1013                 rb = manage (new RadioButton ());
1014                 newpair.second.push_back (rb);
1015                 rb->set_name ("OptionEditorToggleButton");
1016                 if (n == 0) {
1017                         mmc_button_group = rb->get_group();
1018                 } else {
1019                         rb->set_group (mmc_button_group);
1020                 }
1021                 table->attach (*rb, 6, 7, n+2, n+3, FILL|EXPAND, FILL);
1022                 rb->signal_button_press_event().connect (bind (mem_fun(*this, &OptionEditor::mmc_port_chosen), (*i).second, rb));
1023
1024                 if (Config->get_mmc_port_name() == i->first) {
1025                         rb->set_active (true);
1026                 }
1027
1028                 rb = manage (new RadioButton ());
1029                 newpair.second.push_back (rb);
1030                 rb->set_name ("OptionEditorToggleButton");
1031                 if (n == 0) {
1032                         midi_button_group = rb->get_group();
1033                 } else {
1034                         rb->set_group (midi_button_group);
1035                 }
1036                 table->attach (*rb, 8, 9, n+2, n+3, FILL|EXPAND, FILL);
1037                 rb->signal_button_press_event().connect (bind (mem_fun(*this, &OptionEditor::midi_port_chosen), (*i).second, rb));
1038
1039                 if (Config->get_midi_port_name() == i->first) {
1040                         rb->set_active (true);
1041                 }
1042                 
1043                 port_toggle_buttons.insert (newpair);
1044         }
1045
1046         table->show_all ();
1047
1048         hbox = manage (new HBox);
1049         hbox->set_border_width (6);
1050         hbox->pack_start (*table, true, false);
1051         midi_packer.pack_start (*hbox, false, false);
1052         
1053         VBox* mmcbuttonbox = manage (new VBox);
1054
1055         mmc_control_button.set_name ("OptionEditorToggleButton");
1056
1057         hbox = manage (new HBox);
1058         hbox->set_border_width (6);
1059         hbox->pack_start (mmc_control_button, false, false, 36);
1060         mmcbuttonbox->pack_start (*hbox, false, false);
1061
1062         midi_control_button.set_name ("OptionEditorToggleButton");
1063
1064         hbox = manage (new HBox);
1065         hbox->set_border_width (6);
1066         hbox->pack_start (midi_control_button, false, false, 36);
1067         mmcbuttonbox->pack_start (*hbox, false, false);
1068
1069         send_mmc_button.set_name ("OptionEditorToggleButton");
1070
1071         hbox = manage (new HBox);
1072         hbox->set_border_width (6);
1073         hbox->pack_start (send_mmc_button, false, false, 36);
1074         mmcbuttonbox->pack_start (*hbox, false, false);
1075         
1076         midi_feedback_button.set_name ("OptionEditorToggleButton");
1077
1078         hbox = manage (new HBox);
1079         hbox->set_border_width (6);
1080         hbox->pack_start (midi_feedback_button, false, false, 36);
1081         mmcbuttonbox->pack_start (*hbox, false, false);
1082
1083         midi_packer.pack_start (*mmcbuttonbox, false, false);
1084
1085         mmc_control_button.signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::mmc_control_toggled), &mmc_control_button));
1086         midi_control_button.signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::midi_control_toggled), &midi_control_button));
1087         send_mmc_button.signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::send_mmc_toggled), &send_mmc_button));
1088         midi_feedback_button.signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::midi_feedback_toggled), &midi_feedback_button));
1089 }
1090
1091 gint
1092 OptionEditor::mtc_port_chosen (GdkEventButton* ev, MIDI::Port *port, Gtk::RadioButton* rb) 
1093 {
1094         if (session) {
1095                 if (!rb->get_active()) {
1096                         if (port) {
1097                                 session->set_mtc_port (port->name());
1098                                 Config->set_mtc_port_name (port->name());
1099                         } else {
1100                                 session->set_mtc_port ("");
1101                         }
1102
1103                         /* update sync options to reflect MTC port availability */
1104
1105                         vector<string> dumb;
1106                         dumb.push_back (positional_sync_strings[Session::None]);
1107                         dumb.push_back (positional_sync_strings[Session::JACK]);
1108
1109                         if (session->mtc_port()) {
1110                                 dumb.push_back (positional_sync_strings[Session::MTC]);
1111                         }
1112                         set_popdown_strings (slave_type_combo, dumb);
1113
1114                         rb->set_active (true);
1115                 }
1116         }
1117
1118         return stop_signal (*rb, "button_press_event");
1119 }
1120
1121 gint
1122 OptionEditor::mmc_port_chosen (GdkEventButton* ev, MIDI::Port* port, Gtk::RadioButton* rb)
1123 {
1124         if (session) {
1125                 if (!rb->get_active()) {
1126                         if (port) {
1127                                 session->set_mmc_port (port->name());
1128                                 Config->set_mtc_port_name (port->name());
1129                         } else {
1130                                 session->set_mmc_port ("");
1131                         }
1132                         rb->set_active (true);
1133                 }
1134         }
1135         return stop_signal (*rb, "button_press_event");
1136 }
1137
1138 gint
1139 OptionEditor::midi_port_chosen (GdkEventButton* ev, MIDI::Port* port, Gtk::RadioButton* rb)
1140 {
1141         if (session) {
1142                 if (!rb->get_active()) {
1143                         if (port) {
1144                                 session->set_midi_port (port->name());
1145                                 Config->set_midi_port_name (port->name());
1146                         } else {
1147                                 session->set_midi_port ("");
1148                         }
1149                         rb->set_active (true);
1150                 }
1151         }
1152         return stop_signal (*rb, "button_press_event");
1153 }
1154
1155 gint
1156 OptionEditor::port_online_toggled (GdkEventButton* ev, MIDI::Port* port, ToggleButton* tb)
1157 {
1158         bool wanted = tb->get_active(); /* it hasn't changed at this point */
1159
1160         if (wanted != port->input()->offline()) {
1161                 port->input()->set_offline (wanted);
1162         } 
1163         return stop_signal (*tb, "button_press_event");
1164 }
1165
1166 void
1167 OptionEditor::map_port_online (MIDI::Port* port, ToggleButton* tb)
1168 {
1169         if (port->input()->offline()) {
1170                 static_cast<Label*>(tb->get_child())->set_text (_("offline"));
1171                 tb->set_active (false);
1172         } else {
1173                 static_cast<Label*>(tb->get_child())->set_text (_("online"));
1174                 tb->set_active (true);
1175         }
1176 }
1177
1178 gint
1179 OptionEditor::port_trace_in_toggled (GdkEventButton* ev, MIDI::Port* port, ToggleButton* tb)
1180 {
1181         /* XXX not very good MVC style here */
1182
1183         port->input()->trace (!tb->get_active(), &cerr, string (port->name()) + string (" input: "));
1184         tb->set_active (!tb->get_active());
1185         return stop_signal (*tb, "button_press_event");
1186 }
1187
1188 gint
1189 OptionEditor::port_trace_out_toggled (GdkEventButton* ev,MIDI::Port* port, ToggleButton* tb)
1190 {
1191         /* XXX not very good MVC style here */
1192
1193         port->output()->trace (!tb->get_active(), &cerr, string (port->name()) + string (" output: "));
1194         tb->set_active (!tb->get_active());
1195         return stop_signal (*tb, "button_press_event");
1196 }
1197
1198 gint
1199 OptionEditor::send_mtc_toggled (GdkEventButton *ev, CheckButton *button)
1200 {
1201         if (session) {
1202                 session->set_send_mtc (!button->get_active());
1203         }
1204         return stop_signal (*button, "button_press_event");
1205 }
1206
1207 void
1208 OptionEditor::send_mmc_toggled (CheckButton *button)
1209 {
1210         if (session) {
1211                 session->set_send_mmc (button->get_active());
1212         }
1213 }
1214
1215 void
1216 OptionEditor::mmc_control_toggled (CheckButton *button)
1217 {
1218         if (session) {
1219                 session->set_mmc_control (button->get_active());
1220         }
1221 }
1222
1223 void
1224 OptionEditor::midi_control_toggled (CheckButton *button)
1225 {
1226         if (session) {
1227                 session->set_midi_control (button->get_active());
1228         }
1229 }
1230
1231 void
1232 OptionEditor::midi_feedback_toggled (CheckButton *button)
1233 {
1234         if (session) {
1235                 session->set_midi_feedback (button->get_active());
1236         }
1237 }
1238
1239 void
1240 OptionEditor::save ()
1241 {
1242         /* XXX a bit odd that we save the entire session state here */
1243
1244         ui.save_state ("");
1245 }
1246
1247 gint
1248 OptionEditor::wm_close (GdkEventAny *ev)
1249 {
1250         save ();
1251         just_close_win();
1252         return TRUE;
1253 }
1254
1255 void
1256 OptionEditor::jack_time_master_clicked ()
1257 {
1258         bool yn = jack_time_master_button.get_active();
1259
1260         Config->set_jack_time_master (yn);
1261
1262         if (session) {
1263                 session->engine().reset_timebase ();
1264         }
1265 }
1266
1267 void
1268 OptionEditor::raid_path_changed ()
1269 {
1270         if (session) {
1271                 session->set_raid_path (session_raid_entry.get_text());
1272         }
1273 }
1274
1275 void
1276 OptionEditor::click_browse_clicked ()
1277 {
1278         SoundFileChooser sfdb (_("Choose Click"));
1279         
1280         int result = sfdb.run ();
1281
1282         if (result == Gtk::RESPONSE_OK) {
1283                 click_chosen(sfdb.get_filename());
1284         }
1285 }
1286
1287 void
1288 OptionEditor::click_chosen (string path)
1289 {
1290         click_path_entry.set_text (path);
1291         click_sound_changed ();
1292 }
1293
1294 void
1295 OptionEditor::click_emphasis_browse_clicked ()
1296 {
1297         SoundFileChooser sfdb (_("Choose Click Emphasis"));
1298
1299         int result = sfdb.run ();
1300
1301         if (result == Gtk::RESPONSE_OK) {
1302                 click_emphasis_chosen (sfdb.get_filename());
1303         }
1304 }
1305
1306 void
1307 OptionEditor::click_emphasis_chosen (std::string path)
1308 {       
1309         click_emphasis_path_entry.set_text (path);
1310         click_emphasis_sound_changed ();
1311 }
1312
1313 void
1314 OptionEditor::click_sound_changed ()
1315 {
1316         if (session) {
1317                 string path = click_path_entry.get_text();
1318
1319                 if (path == session->click_sound) {
1320                         return;
1321                 }
1322
1323                 if (path.length() == 0) {
1324
1325                         session->set_click_sound ("");
1326
1327                 } else {
1328
1329                         strip_whitespace_edges (path);
1330                         
1331                         if (path == _("internal")) {
1332                                 session->set_click_sound ("");
1333                         } else {
1334                                 session->set_click_sound (path);
1335                         }
1336                 }
1337         }
1338 }
1339
1340 void
1341 OptionEditor::click_emphasis_sound_changed ()
1342 {
1343         if (session) {
1344                 string path = click_emphasis_path_entry.get_text();
1345
1346                 if (path == session->click_emphasis_sound) {
1347                         return;
1348                 }
1349
1350                 if (path.length() == 0) {
1351
1352                         session->set_click_emphasis_sound ("");
1353
1354                 } else {
1355
1356                         strip_whitespace_edges (path);
1357
1358                         if (path == _("internal")) {
1359                                 session->set_click_emphasis_sound ("");
1360                         } else {
1361                                 session->set_click_emphasis_sound (path);
1362                         }
1363                 }
1364         }
1365 }
1366
1367 void
1368 OptionEditor::show_waveforms_clicked ()
1369 {
1370         editor.set_show_waveforms (show_waveforms_button.get_active());
1371 }
1372
1373 void
1374 OptionEditor::show_waveforms_recording_clicked ()
1375 {
1376         editor.set_show_waveforms_recording (show_waveforms_recording_button.get_active());
1377 }
1378
1379 void
1380 OptionEditor::show_measures_clicked ()
1381 {
1382         editor.set_show_measures (show_measures_button.get_active());
1383 }
1384
1385 void
1386 OptionEditor::follow_playhead_clicked ()
1387 {
1388         editor.set_follow_playhead (follow_playhead_button.get_active());
1389 }
1390
1391 void
1392 OptionEditor::strip_width_clicked ()
1393 {
1394         mixer.set_strip_width (mixer_strip_width_button.get_active() ? Narrow : Wide);
1395 }
1396
1397
1398 void
1399 OptionEditor::just_close_win()
1400 {
1401         hide();
1402 }
1403
1404 void
1405 OptionEditor::queue_session_control_changed (Session::ControlType t)
1406 {
1407         ui.call_slot (bind (mem_fun(*this, &OptionEditor::session_control_changed), t));
1408 }
1409
1410 void
1411 OptionEditor::session_control_changed (Session::ControlType t)
1412 {
1413         switch (t) {
1414         case Session::SlaveType:
1415                 switch (session->slave_source()) {
1416                 case Session::None:
1417                         slave_type_combo.set_active_text (positional_sync_strings[Session::None]);
1418                         break;
1419                 case Session::MTC:
1420                         slave_type_combo.set_active_text (positional_sync_strings[Session::MTC]);
1421                         break;
1422                 case Session::JACK:
1423                         slave_type_combo.set_active_text (positional_sync_strings[Session::JACK]);
1424                         break;
1425                 default:
1426                         slave_type_combo.set_active_text (_("--unknown--"));
1427                         break;
1428                 }
1429                 
1430                 break;
1431
1432         case Session::SendMTC:
1433                 map_some_session_state (send_mtc_button, &Session::get_send_mtc);
1434                 break;
1435
1436         case Session::SendMMC:
1437                 map_some_session_state (send_mmc_button, &Session::get_send_mmc);
1438                 break;
1439
1440         case Session::MMCControl:       
1441                 map_some_session_state (mmc_control_button, &Session::get_mmc_control);
1442                 break;
1443
1444         case Session::MidiFeedback:       
1445                 map_some_session_state (midi_feedback_button, &Session::get_midi_feedback);
1446                 break;
1447
1448         case Session::MidiControl:       
1449                  map_some_session_state (midi_control_button, &Session::get_midi_control);
1450                 break;
1451         
1452         default:
1453                 break;
1454         }
1455 }
1456
1457 void
1458 OptionEditor::native_format_chosen ()
1459 {
1460         string which;
1461
1462         if (session == 0) {
1463                 return;
1464         }
1465
1466         bool use_bwf = (native_format_combo.get_active_text() == native_format_strings[0]);
1467
1468         if (use_bwf != Config->get_native_format_is_bwf()) {
1469                 Config->set_native_format_is_bwf (use_bwf);
1470                 session->reset_native_file_format ();
1471         }
1472 }
1473
1474 void
1475 OptionEditor::slave_type_chosen ()
1476 {
1477         string which;
1478
1479         if (session == 0) {
1480                 return;
1481         }
1482
1483         which = slave_type_combo.get_active_text();
1484
1485         if (which == positional_sync_strings[Session::None]) {
1486                 session->request_slave_source (Session::None);
1487         } else if (which == positional_sync_strings[Session::MTC]) {
1488                 session->request_slave_source (Session::MTC);
1489         } else if (which == positional_sync_strings[Session::JACK]) {
1490                 session->request_slave_source (Session::JACK);
1491         } 
1492 }
1493
1494 void
1495 OptionEditor::clear_click_editor ()
1496 {
1497         if (click_io_selector) {
1498                 click_packer.remove (*click_io_selector);
1499                 click_packer.remove (*click_gpm);
1500                 delete click_io_selector;
1501                 delete click_gpm;
1502                 click_io_selector = 0;
1503                 click_gpm = 0;
1504         }
1505 }
1506
1507 void
1508 OptionEditor::setup_click_editor ()
1509 {
1510         Label* label;
1511         HBox* hpacker = manage (new HBox);
1512
1513         click_path_entry.set_sensitive (true);
1514         click_emphasis_path_entry.set_sensitive (true);
1515
1516         click_path_entry.set_name ("OptionsEntry");
1517         click_emphasis_path_entry.set_name ("OptionsEntry");
1518         
1519         click_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_sound_changed));
1520         click_emphasis_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_emphasis_sound_changed));
1521
1522         click_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_sound_changed));
1523         click_emphasis_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_emphasis_sound_changed));
1524
1525         click_browse_button.set_name ("EditorGTKButton");
1526         click_emphasis_browse_button.set_name ("EditorGTKButton");
1527         click_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_browse_clicked));
1528         click_emphasis_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_emphasis_browse_clicked));
1529
1530         click_packer.set_border_width (12);
1531         click_packer.set_spacing (5);
1532
1533         click_io_selector = new IOSelector (*session, session->click_io(), false);
1534         click_gpm = new GainMeter (session->click_io(), *session);
1535
1536         click_table.set_col_spacings (10);
1537         
1538         label = manage(new Label(_("Click audio file")));
1539         label->set_name ("OptionsLabel");
1540         click_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL);
1541         click_table.attach (click_path_entry, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1542         click_table.attach (click_browse_button, 2, 3, 0, 1, FILL|EXPAND, FILL);
1543         
1544         label = manage(new Label(_("Click emphasis audiofile")));
1545         label->set_name ("OptionsLabel");
1546         click_table.attach (*label, 0, 1, 1, 2, FILL|EXPAND, FILL);
1547         click_table.attach (click_emphasis_path_entry, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1548         click_table.attach (click_emphasis_browse_button, 2, 3, 1, 2, FILL|EXPAND, FILL);
1549
1550         hpacker->set_spacing (10);
1551         hpacker->pack_start (*click_io_selector, false, false);
1552         hpacker->pack_start (*click_gpm, false, false);
1553
1554         click_packer.pack_start (click_table, false, false);
1555         click_packer.pack_start (*hpacker, false, false);
1556
1557         click_packer.show_all ();
1558 }
1559
1560 void
1561 OptionEditor::clear_auditioner_editor ()
1562 {
1563         if (auditioner_io_selector) {
1564                 audition_hpacker.remove (*auditioner_io_selector);
1565                 audition_hpacker.remove (*auditioner_gpm);
1566                 delete auditioner_io_selector;
1567                 delete auditioner_gpm;
1568                 auditioner_io_selector = 0;
1569                 auditioner_gpm = 0;
1570         }
1571 }
1572
1573 void
1574 OptionEditor::setup_auditioner_editor ()
1575 {
1576         audition_packer.set_border_width (12);
1577         audition_packer.set_spacing (5);
1578         audition_hpacker.set_spacing (10);
1579
1580         audition_label.set_name ("OptionEditorAuditionerLabel");
1581         audition_label.set_text (_("The auditioner is a dedicated mixer strip used\n"
1582                                    "for listening to specific regions outside the context\n"
1583                                    "of the overall mix. It can be connected just like any\n"
1584                                    "other mixer strip."));
1585         
1586         audition_packer.pack_start (audition_label, false, false, 10);
1587         audition_packer.pack_start (audition_hpacker, false, false);
1588 }
1589
1590 void
1591 OptionEditor::connect_audition_editor ()
1592 {
1593         auditioner_io_selector = new IOSelector (*session, session->the_auditioner(), false);
1594         auditioner_gpm = new GainMeter (session->the_auditioner(), *session);
1595
1596         audition_hpacker.pack_start (*auditioner_io_selector, false, false);
1597         audition_hpacker.pack_start (*auditioner_gpm, false, false);
1598
1599         auditioner_io_selector->show_all ();
1600         auditioner_gpm->show_all ();
1601 }
1602
1603 bool
1604 OptionEditor::focus_out_event_handler (GdkEventFocus* ev, void (OptionEditor::*pmf)()) 
1605 {
1606         (this->*pmf)();
1607         return false;
1608 }
1609
1610 void
1611 OptionEditor::setup_misc_options()
1612 {
1613         Gtk::Table* table = manage (new Table (4, 2));  
1614         table->set_homogeneous (true);
1615
1616         misc_packer.set_border_width (8);
1617         misc_packer.set_spacing (3);
1618         misc_packer.pack_start (*table, true, true);
1619
1620         table->attach (hw_monitor_button, 0, 1, 0, 1, Gtk::FILL, FILL, 8, 0);
1621         table->attach (sw_monitor_button, 0, 1, 1, 2, Gtk::FILL, FILL, 8, 0);
1622         table->attach (plugins_stop_button, 0, 1, 2, 3, Gtk::FILL, FILL, 8, 0);
1623         table->attach (plugins_on_rec_button, 0, 1, 3, 4, Gtk::FILL, FILL, 8, 0);
1624         table->attach (verify_remove_last_capture_button, 0, 1, 4, 5, Gtk::FILL, FILL, 8, 0);
1625
1626         table->attach (stop_rec_on_xrun_button, 1, 2, 0, 1, Gtk::FILL, FILL, 8, 0);
1627         table->attach (stop_at_end_button, 1, 2, 1, 2, Gtk::FILL, FILL, 8, 0);
1628         table->attach (debug_keyboard_button, 1, 2, 2, 3, Gtk::FILL, FILL, 8, 0);
1629         table->attach (speed_quieten_button, 1, 2, 3, 4, Gtk::FILL, FILL, 8, 0);
1630
1631         Gtk::VBox* connect_box = manage (new VBox);
1632         connect_box->set_spacing (3);
1633         connect_box->set_border_width (8);
1634
1635         auto_connect_output_button_group = auto_connect_output_master_button.get_group();
1636         auto_connect_output_manual_button.set_group (auto_connect_output_button_group);
1637         auto_connect_output_physical_button.set_group (auto_connect_output_button_group);
1638
1639         Gtk::HBox* useless_box = manage (new HBox);
1640         useless_box->pack_start (auto_connect_inputs_button, false, false);
1641         connect_box->pack_start (*useless_box, false, false);
1642         connect_box->pack_start (auto_connect_output_master_button, false, false);
1643         connect_box->pack_start (auto_connect_output_physical_button, false, false);
1644         connect_box->pack_start (auto_connect_output_manual_button, false, false);
1645
1646         misc_packer.pack_start (*connect_box, false, false);
1647         
1648         hw_monitor_button.set_name ("OptionEditorToggleButton");
1649         sw_monitor_button.set_name ("OptionEditorToggleButton");
1650         plugins_stop_button.set_name ("OptionEditorToggleButton");
1651         plugins_on_rec_button.set_name ("OptionEditorToggleButton");
1652         verify_remove_last_capture_button.set_name ("OptionEditorToggleButton");
1653         auto_connect_inputs_button.set_name ("OptionEditorToggleButton");
1654         auto_connect_output_physical_button.set_name ("OptionEditorToggleButton");
1655         auto_connect_output_master_button.set_name ("OptionEditorToggleButton");
1656         auto_connect_output_manual_button.set_name ("OptionEditorToggleButton");
1657         stop_rec_on_xrun_button.set_name ("OptionEditorToggleButton");
1658         stop_at_end_button.set_name ("OptionEditorToggleButton");
1659         debug_keyboard_button.set_name ("OptionEditorToggleButton");
1660         speed_quieten_button.set_name ("OptionEditorToggleButton");
1661
1662         hw_monitor_button.set_active (Config->get_use_hardware_monitoring());
1663         sw_monitor_button.set_active (!Config->get_no_sw_monitoring());
1664         plugins_stop_button.set_active (Config->get_plugins_stop_with_transport());
1665         stop_rec_on_xrun_button.set_active (Config->get_stop_recording_on_xrun());
1666         stop_at_end_button.set_active (Config->get_stop_at_session_end());
1667         debug_keyboard_button.set_active (false);
1668         speed_quieten_button.set_active (Config->get_quieten_at_speed() != 1.0f);
1669
1670         hw_monitor_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::hw_monitor_clicked));
1671         sw_monitor_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::sw_monitor_clicked));
1672         plugins_stop_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::plugins_stop_with_transport_clicked));
1673         plugins_on_rec_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::plugins_on_while_recording_clicked));
1674         verify_remove_last_capture_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::verify_remove_last_capture_clicked));
1675         auto_connect_inputs_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::auto_connect_inputs_clicked));
1676         auto_connect_output_physical_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::auto_connect_output_physical_clicked));
1677         auto_connect_output_master_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::auto_connect_output_master_clicked));
1678         auto_connect_output_manual_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::auto_connect_output_manual_clicked));
1679         stop_rec_on_xrun_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::stop_rec_on_xrun_clicked));
1680         stop_at_end_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::stop_at_end_clicked));
1681         debug_keyboard_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::debug_keyboard_clicked));
1682         speed_quieten_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::speed_quieten_clicked));
1683 }
1684
1685 void
1686 OptionEditor::speed_quieten_clicked ()
1687 {
1688         if (speed_quieten_button.get_active()) {
1689                 Config->set_quieten_at_speed (0.251189); // -12dB reduction for ffwd or rewind
1690         } else {
1691                 Config->set_quieten_at_speed (1.0); /* no change */
1692         }
1693 }
1694
1695 void
1696 OptionEditor::debug_keyboard_clicked ()
1697 {
1698         extern bool debug_keyboard;
1699         debug_keyboard = debug_keyboard_button.get_active ();
1700 }
1701
1702 void
1703 OptionEditor::auto_connect_inputs_clicked ()
1704 {
1705         if (session) {
1706                 session->set_input_auto_connect (auto_connect_inputs_button.get_active());
1707         }
1708 }
1709
1710 void
1711 OptionEditor::auto_connect_output_master_clicked ()
1712 {
1713         if (session) {
1714                 if (auto_connect_output_master_button.get_active()) {
1715                         session->set_output_auto_connect (Session::AutoConnectMaster);
1716                 } 
1717         }
1718 }
1719
1720 void
1721 OptionEditor::auto_connect_output_physical_clicked ()
1722 {
1723         if (session) {
1724                 if (auto_connect_output_physical_button.get_active()) {
1725                         session->set_output_auto_connect (Session::AutoConnectPhysical);
1726                 } 
1727         }
1728 }
1729
1730 void
1731 OptionEditor::auto_connect_output_manual_clicked ()
1732 {
1733         if (session) {
1734                 if (auto_connect_output_manual_button.get_active()) {
1735                         session->set_output_auto_connect (Session::AutoConnectOption (0));
1736                 } 
1737         }
1738 }
1739
1740 void
1741 OptionEditor::hw_monitor_clicked ()
1742 {
1743         Config->set_use_hardware_monitoring (hw_monitor_button.get_active());
1744 }
1745
1746 void
1747 OptionEditor::sw_monitor_clicked ()
1748 {
1749         Config->set_no_sw_monitoring (!sw_monitor_button.get_active());
1750 }
1751
1752 void
1753 OptionEditor::plugins_stop_with_transport_clicked ()
1754 {
1755         Config->set_plugins_stop_with_transport (plugins_stop_button.get_active());
1756 }
1757
1758 void
1759 OptionEditor::plugins_on_while_recording_clicked ()
1760 {
1761         if (session) {
1762                 session->set_recording_plugins (plugins_on_rec_button.get_active());
1763         }
1764 }
1765
1766 void
1767 OptionEditor::verify_remove_last_capture_clicked ()
1768 {
1769         Config->set_verify_remove_last_capture(verify_remove_last_capture_button.get_active());
1770 }
1771
1772 void
1773 OptionEditor::stop_rec_on_xrun_clicked ()
1774 {
1775         Config->set_stop_recording_on_xrun (stop_rec_on_xrun_button.get_active());
1776 }
1777
1778 void
1779 OptionEditor::stop_at_end_clicked ()
1780 {
1781         Config->set_stop_at_session_end (stop_at_end_button.get_active());
1782 }
1783                                                   
1784 static const struct {
1785     const char *name;
1786     guint   modifier;
1787 } modifiers[] = {
1788         { "Shift", GDK_SHIFT_MASK },
1789         { "Control", GDK_CONTROL_MASK },
1790         { "Alt (Mod1)", GDK_MOD1_MASK },
1791         { "Control-Shift", GDK_CONTROL_MASK|GDK_SHIFT_MASK },
1792         { "Control-Alt", GDK_CONTROL_MASK|GDK_MOD1_MASK },
1793         { "Shift-Alt", GDK_SHIFT_MASK|GDK_MOD1_MASK },
1794         { "Control-Shift-Alt", GDK_CONTROL_MASK|GDK_SHIFT_MASK|GDK_MOD1_MASK },
1795         { "Mod2", GDK_MOD2_MASK },
1796         { "Mod3", GDK_MOD3_MASK },
1797         { "Mod4", GDK_MOD4_MASK },
1798         { "Mod5", GDK_MOD5_MASK },
1799         { 0, 0 }
1800 };
1801
1802 void
1803 OptionEditor::setup_keyboard_options ()
1804 {
1805         vector<string> dumb;
1806         Label* label;
1807
1808         keyboard_mouse_table.set_border_width (12);
1809         keyboard_mouse_table.set_row_spacings (5);
1810         keyboard_mouse_table.set_col_spacings (5);
1811
1812         /* internationalize and prepare for use with combos */
1813
1814         for (int i = 0; modifiers[i].name; ++i) {
1815                 dumb.push_back (_(modifiers[i].name));
1816         }
1817
1818         set_popdown_strings (edit_modifier_combo, dumb);
1819         edit_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::edit_modifier_chosen));
1820
1821         for (int x = 0; modifiers[x].name; ++x) {
1822                 if (modifiers[x].modifier == Keyboard::edit_modifier ()) {
1823                         edit_modifier_combo.set_active_text (_(modifiers[x].name));
1824                         break;
1825                 }
1826         }
1827
1828         label = manage (new Label (_("Edit using")));
1829         label->set_name ("OptionsLabel");
1830         label->set_alignment (1.0, 0.5);
1831                 
1832         keyboard_mouse_table.attach (*label, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1833         keyboard_mouse_table.attach (edit_modifier_combo, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1834
1835         label = manage (new Label (_("+ button")));
1836         label->set_name ("OptionsLabel");
1837         
1838         keyboard_mouse_table.attach (*label, 3, 4, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1839         keyboard_mouse_table.attach (edit_button_spin, 4, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1840
1841         edit_button_spin.set_name ("OptionsEntry");
1842         edit_button_adjustment.set_value (Keyboard::edit_button());
1843         edit_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::edit_button_changed));
1844
1845         set_popdown_strings (delete_modifier_combo, dumb);
1846         delete_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::delete_modifier_chosen));
1847
1848         for (int x = 0; modifiers[x].name; ++x) {
1849                 if (modifiers[x].modifier == Keyboard::delete_modifier ()) {
1850                         delete_modifier_combo.set_active_text (_(modifiers[x].name));
1851                         break;
1852                 }
1853         }
1854
1855         label = manage (new Label (_("Delete using")));
1856         label->set_name ("OptionsLabel");
1857         label->set_alignment (1.0, 0.5);
1858                 
1859         keyboard_mouse_table.attach (*label, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1860         keyboard_mouse_table.attach (delete_modifier_combo, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1861
1862         label = manage (new Label (_("+ button")));
1863         label->set_name ("OptionsLabel");
1864
1865         keyboard_mouse_table.attach (*label, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1866         keyboard_mouse_table.attach (delete_button_spin, 4, 5, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1867
1868         delete_button_spin.set_name ("OptionsEntry");
1869         delete_button_adjustment.set_value (Keyboard::delete_button());
1870         delete_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::delete_button_changed));
1871
1872         set_popdown_strings (snap_modifier_combo, dumb);
1873         snap_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::snap_modifier_chosen));
1874         
1875         for (int x = 0; modifiers[x].name; ++x) {
1876                 if (modifiers[x].modifier == (guint) Keyboard::snap_modifier ()) {
1877                         snap_modifier_combo.set_active_text (_(modifiers[x].name));
1878                         break;
1879                 }
1880         }
1881
1882         label = manage (new Label (_("Ignore snap using")));
1883         label->set_name ("OptionsLabel");
1884         label->set_alignment (1.0, 0.5);
1885         
1886         keyboard_mouse_table.attach (*label, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
1887         keyboard_mouse_table.attach (snap_modifier_combo, 1, 2, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
1888 }
1889
1890 void
1891 OptionEditor::edit_modifier_chosen ()
1892 {
1893         string txt;
1894         
1895         txt = edit_modifier_combo.get_active_text();
1896
1897         for (int i = 0; modifiers[i].name; ++i) {
1898                 if (txt == _(modifiers[i].name)) {
1899                         Keyboard::set_edit_modifier (modifiers[i].modifier);
1900                         break;
1901                 }
1902         }
1903 }
1904
1905 void
1906 OptionEditor::delete_modifier_chosen ()
1907 {
1908         string txt;
1909         
1910         txt = delete_modifier_combo.get_active_text();
1911
1912         for (int i = 0; modifiers[i].name; ++i) {
1913                 if (txt == _(modifiers[i].name)) {
1914                         Keyboard::set_delete_modifier (modifiers[i].modifier);
1915                         break;
1916                 }
1917         }
1918 }
1919
1920 void
1921 OptionEditor::snap_modifier_chosen ()
1922 {
1923         string txt;
1924         
1925         txt = snap_modifier_combo.get_active_text();
1926
1927         for (int i = 0; modifiers[i].name; ++i) {
1928                 if (txt == _(modifiers[i].name)) {
1929                         Keyboard::set_snap_modifier (modifiers[i].modifier);
1930                         break;
1931                 }
1932         }
1933 }
1934
1935 void
1936 OptionEditor::delete_button_changed ()
1937 {
1938         Keyboard::set_delete_button ((guint) delete_button_adjustment.get_value());
1939 }
1940
1941 void
1942 OptionEditor::edit_button_changed ()
1943 {
1944         Keyboard::set_edit_button ((guint) edit_button_adjustment.get_value());
1945 }
1946
1947 void
1948 OptionEditor::fixup_combo_size (Gtk::ComboBoxText& combo, vector<string>& strings)
1949 {
1950         /* find the widest string */
1951
1952         string::size_type maxlen = 0;
1953         string maxstring;
1954
1955         for (vector<string>::iterator i = strings.begin(); i != strings.end(); ++i) {
1956                 string::size_type l;
1957
1958                 if ((l = (*i).length()) > maxlen) {
1959                         maxlen = l;
1960                         maxstring = *i;
1961                 }
1962         }
1963
1964         /* try to include ascenders and descenders */
1965
1966         if (maxstring.length() > 2) {
1967                 maxstring[0] = 'g';
1968                 maxstring[1] = 'l';
1969         }
1970
1971         const guint32 FUDGE = 10; // Combo's are stupid - they steal space from the entry for the button
1972
1973         set_size_request_to_display_given_text (combo, maxstring.c_str(), 10 + FUDGE, 10);
1974 }
1975
1976 void
1977 OptionEditor::map_some_session_state (CheckButton& button, bool (Session::*get)() const)
1978 {
1979         if (session) {
1980                 button.set_active ((session->*get)());
1981         }
1982 }
1983