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