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