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