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