packaging tweaks for OS X
[ardour.git] / gtk2_ardour / rc_option_editor.cc
1 /*
2     Copyright (C) 2001-2011 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 */
19
20 #ifdef WAF_BUILD
21 #include "gtk2ardour-config.h"
22 #endif
23
24 #include <gtkmm/liststore.h>
25 #include <gtkmm/stock.h>
26 #include <gtkmm/scale.h>
27 #include <gtkmm2ext/utils.h>
28 #include <gtkmm2ext/slider_controller.h>
29
30 #include "pbd/fpu.h"
31 #include "pbd/cpus.h"
32
33 #include "midi++/manager.h"
34
35 #include "ardour/audioengine.h"
36 #include "ardour/dB.h"
37 #include "ardour/rc_configuration.h"
38 #include "ardour/control_protocol_manager.h"
39 #include "control_protocol/control_protocol.h"
40
41 #include "ardour_window.h"
42 #include "ardour_dialog.h"
43 #include "gui_thread.h"
44 #include "midi_tracer.h"
45 #include "rc_option_editor.h"
46 #include "utils.h"
47 #include "midi_port_dialog.h"
48 #include "sfdb_ui.h"
49 #include "keyboard.h"
50 #include "i18n.h"
51
52 using namespace std;
53 using namespace Gtk;
54 using namespace Gtkmm2ext;
55 using namespace PBD;
56 using namespace ARDOUR;
57
58 class ClickOptions : public OptionEditorBox
59 {
60 public:
61         ClickOptions (RCConfiguration* c, Gtk::Window* p)
62                 : _rc_config (c),
63                   _parent (p)
64         {
65                 Table* t = manage (new Table (2, 3));
66                 t->set_spacings (4);
67
68                 Label* l = manage (new Label (_("Click audio file:")));
69                 l->set_alignment (0, 0.5);
70                 t->attach (*l, 0, 1, 0, 1, FILL);
71                 t->attach (_click_path_entry, 1, 2, 0, 1, FILL);
72                 Button* b = manage (new Button (_("Browse...")));
73                 b->signal_clicked().connect (sigc::mem_fun (*this, &ClickOptions::click_browse_clicked));
74                 t->attach (*b, 2, 3, 0, 1, FILL);
75
76                 l = manage (new Label (_("Click emphasis audio file:")));
77                 l->set_alignment (0, 0.5);
78                 t->attach (*l, 0, 1, 1, 2, FILL);
79                 t->attach (_click_emphasis_path_entry, 1, 2, 1, 2, FILL);
80                 b = manage (new Button (_("Browse...")));
81                 b->signal_clicked().connect (sigc::mem_fun (*this, &ClickOptions::click_emphasis_browse_clicked));
82                 t->attach (*b, 2, 3, 1, 2, FILL);
83                 
84                 _box->pack_start (*t, false, false);
85
86                 _click_path_entry.signal_activate().connect (sigc::mem_fun (*this, &ClickOptions::click_changed));      
87                 _click_emphasis_path_entry.signal_activate().connect (sigc::mem_fun (*this, &ClickOptions::click_emphasis_changed));
88         }
89
90         void parameter_changed (string const & p)
91         {
92                 if (p == "click-sound") {
93                         _click_path_entry.set_text (_rc_config->get_click_sound());
94                 } else if (p == "click-emphasis-sound") {
95                         _click_emphasis_path_entry.set_text (_rc_config->get_click_emphasis_sound());
96                 }
97         }
98
99         void set_state_from_config ()
100         {
101                 parameter_changed ("click-sound");
102                 parameter_changed ("click-emphasis-sound");
103         }
104
105 private:
106
107         void click_browse_clicked ()
108         {
109                 SoundFileChooser sfdb (*_parent, _("Choose Click"));
110
111                 sfdb.show_all ();
112                 sfdb.present ();
113
114                 if (sfdb.run () == RESPONSE_OK) {
115                         click_chosen (sfdb.get_filename());
116                 }
117         }
118
119         void click_chosen (string const & path)
120         {
121                 _click_path_entry.set_text (path);
122                 _rc_config->set_click_sound (path);
123         }
124
125         void click_changed ()
126         {
127                 click_chosen (_click_path_entry.get_text ());
128         }
129         
130         void click_emphasis_browse_clicked ()
131         {
132                 SoundFileChooser sfdb (*_parent, _("Choose Click Emphasis"));
133
134                 sfdb.show_all ();
135                 sfdb.present ();
136
137                 if (sfdb.run () == RESPONSE_OK) {
138                         click_emphasis_chosen (sfdb.get_filename());
139                 }
140         }
141
142         void click_emphasis_chosen (string const & path)
143         {
144                 _click_emphasis_path_entry.set_text (path);
145                 _rc_config->set_click_emphasis_sound (path);
146         }
147
148         void click_emphasis_changed ()
149         {
150                 click_emphasis_chosen (_click_emphasis_path_entry.get_text ());
151         }
152
153         RCConfiguration* _rc_config;
154         Gtk::Window* _parent;
155         Entry _click_path_entry;
156         Entry _click_emphasis_path_entry;
157 };
158
159 class UndoOptions : public OptionEditorBox
160 {
161 public:
162         UndoOptions (RCConfiguration* c) :
163                 _rc_config (c),
164                 _limit_undo_button (_("Limit undo history to")),
165                 _save_undo_button (_("Save undo history of"))
166         {
167                 Table* t = new Table (2, 3);
168                 t->set_spacings (4);
169
170                 t->attach (_limit_undo_button, 0, 1, 0, 1, FILL);
171                 _limit_undo_spin.set_range (0, 512);
172                 _limit_undo_spin.set_increments (1, 10);
173                 t->attach (_limit_undo_spin, 1, 2, 0, 1, FILL | EXPAND);
174                 Label* l = manage (new Label (_("commands")));
175                 l->set_alignment (0, 0.5);
176                 t->attach (*l, 2, 3, 0, 1);
177
178                 t->attach (_save_undo_button, 0, 1, 1, 2, FILL);
179                 _save_undo_spin.set_range (0, 512);
180                 _save_undo_spin.set_increments (1, 10);
181                 t->attach (_save_undo_spin, 1, 2, 1, 2, FILL | EXPAND);
182                 l = manage (new Label (_("commands")));
183                 l->set_alignment (0, 0.5);
184                 t->attach (*l, 2, 3, 1, 2);
185
186                 _box->pack_start (*t);
187
188                 _limit_undo_button.signal_toggled().connect (sigc::mem_fun (*this, &UndoOptions::limit_undo_toggled));
189                 _limit_undo_spin.signal_value_changed().connect (sigc::mem_fun (*this, &UndoOptions::limit_undo_changed));
190                 _save_undo_button.signal_toggled().connect (sigc::mem_fun (*this, &UndoOptions::save_undo_toggled));
191                 _save_undo_spin.signal_value_changed().connect (sigc::mem_fun (*this, &UndoOptions::save_undo_changed));
192         }
193
194         void parameter_changed (string const & p)
195         {
196                 if (p == "history-depth") {
197                         int32_t const d = _rc_config->get_history_depth();
198                         _limit_undo_button.set_active (d != 0);
199                         _limit_undo_spin.set_sensitive (d != 0);
200                         _limit_undo_spin.set_value (d);
201                 } else if (p == "save-history") {
202                         bool const x = _rc_config->get_save_history ();
203                         _save_undo_button.set_active (x);
204                         _save_undo_spin.set_sensitive (x);
205                 } else if (p == "save-history-depth") {
206                         _save_undo_spin.set_value (_rc_config->get_saved_history_depth());
207                 }
208         }
209
210         void set_state_from_config ()
211         {
212                 parameter_changed ("save-history");
213                 parameter_changed ("history-depth");
214                 parameter_changed ("save-history-depth");
215         }
216
217         void limit_undo_toggled ()
218         {
219                 bool const x = _limit_undo_button.get_active ();
220                 _limit_undo_spin.set_sensitive (x);
221                 int32_t const n = x ? 16 : 0;
222                 _limit_undo_spin.set_value (n);
223                 _rc_config->set_history_depth (n);
224         }
225
226         void limit_undo_changed ()
227         {
228                 _rc_config->set_history_depth (_limit_undo_spin.get_value_as_int ());
229         }
230
231         void save_undo_toggled ()
232         {
233                 bool const x = _save_undo_button.get_active ();
234                 _rc_config->set_save_history (x);
235         }
236
237         void save_undo_changed ()
238         {
239                 _rc_config->set_saved_history_depth (_save_undo_spin.get_value_as_int ());
240         }
241
242 private:
243         RCConfiguration* _rc_config;
244         CheckButton _limit_undo_button;
245         SpinButton _limit_undo_spin;
246         CheckButton _save_undo_button;
247         SpinButton _save_undo_spin;
248 };
249
250
251
252 static const struct {
253     const char *name;
254     guint modifier;
255 } modifiers[] = {
256
257         { "Unmodified", 0 },
258
259 #ifdef GTKOSX
260
261         /* Command = Meta
262            Option/Alt = Mod1
263         */
264         { "Key|Shift", GDK_SHIFT_MASK },
265         { "Command", GDK_META_MASK },
266         { "Control", GDK_CONTROL_MASK },
267         { "Option", GDK_MOD1_MASK },
268         { "Command-Shift", GDK_META_MASK|GDK_SHIFT_MASK },
269         { "Command-Option", GDK_MOD1_MASK|GDK_META_MASK },
270         { "Shift-Option", GDK_SHIFT_MASK|GDK_MOD1_MASK },
271         { "Shift-Command-Option", GDK_MOD5_MASK|GDK_SHIFT_MASK|GDK_META_MASK },
272
273 #else
274         { "Key|Shift", GDK_SHIFT_MASK },
275         { "Control", GDK_CONTROL_MASK },
276         { "Alt (Mod1)", GDK_MOD1_MASK },
277         { "Control-Shift", GDK_CONTROL_MASK|GDK_SHIFT_MASK },
278         { "Control-Alt", GDK_CONTROL_MASK|GDK_MOD1_MASK },
279         { "Shift-Alt", GDK_SHIFT_MASK|GDK_MOD1_MASK },
280         { "Control-Shift-Alt", GDK_CONTROL_MASK|GDK_SHIFT_MASK|GDK_MOD1_MASK },
281         { "Mod2", GDK_MOD2_MASK },
282         { "Mod3", GDK_MOD3_MASK },
283         { "Mod4", GDK_MOD4_MASK },
284         { "Mod5", GDK_MOD5_MASK },
285 #endif
286         { 0, 0 }
287 };
288
289
290 class KeyboardOptions : public OptionEditorBox
291 {
292 public:
293         KeyboardOptions () :
294                   _delete_button_adjustment (3, 1, 12),
295                   _delete_button_spin (_delete_button_adjustment),
296                   _edit_button_adjustment (3, 1, 5),
297                   _edit_button_spin (_edit_button_adjustment),
298                   _insert_note_button_adjustment (3, 1, 5),
299                   _insert_note_button_spin (_insert_note_button_adjustment)
300         {
301                 /* internationalize and prepare for use with combos */
302
303                 vector<string> dumb;
304                 for (int i = 0; modifiers[i].name; ++i) {
305                         dumb.push_back (S_(modifiers[i].name));
306                 }
307
308                 set_popdown_strings (_edit_modifier_combo, dumb);
309                 _edit_modifier_combo.signal_changed().connect (sigc::mem_fun(*this, &KeyboardOptions::edit_modifier_chosen));
310
311                 for (int x = 0; modifiers[x].name; ++x) {
312                         if (modifiers[x].modifier == Keyboard::edit_modifier ()) {
313                                 _edit_modifier_combo.set_active_text (S_(modifiers[x].name));
314                                 break;
315                         }
316                 }
317
318                 Table* t = manage (new Table (4, 4));
319                 t->set_spacings (4);
320
321                 Label* l = manage (new Label (_("Edit using:")));
322                 l->set_name ("OptionsLabel");
323                 l->set_alignment (0, 0.5);
324
325                 t->attach (*l, 0, 1, 0, 1, FILL | EXPAND, FILL);
326                 t->attach (_edit_modifier_combo, 1, 2, 0, 1, FILL | EXPAND, FILL);
327
328                 l = manage (new Label (_("+ button")));
329                 l->set_name ("OptionsLabel");
330
331                 t->attach (*l, 3, 4, 0, 1, FILL | EXPAND, FILL);
332                 t->attach (_edit_button_spin, 4, 5, 0, 1, FILL | EXPAND, FILL);
333
334                 _edit_button_spin.set_name ("OptionsEntry");
335                 _edit_button_adjustment.set_value (Keyboard::edit_button());
336                 _edit_button_adjustment.signal_value_changed().connect (sigc::mem_fun(*this, &KeyboardOptions::edit_button_changed));
337
338                 set_popdown_strings (_delete_modifier_combo, dumb);
339                 _delete_modifier_combo.signal_changed().connect (sigc::mem_fun(*this, &KeyboardOptions::delete_modifier_chosen));
340
341                 for (int x = 0; modifiers[x].name; ++x) {
342                         if (modifiers[x].modifier == Keyboard::delete_modifier ()) {
343                                 _delete_modifier_combo.set_active_text (S_(modifiers[x].name));
344                                 break;
345                         }
346                 }
347
348                 l = manage (new Label (_("Delete using:")));
349                 l->set_name ("OptionsLabel");
350                 l->set_alignment (0, 0.5);
351
352                 t->attach (*l, 0, 1, 1, 2, FILL | EXPAND, FILL);
353                 t->attach (_delete_modifier_combo, 1, 2, 1, 2, FILL | EXPAND, FILL);
354
355                 l = manage (new Label (_("+ button")));
356                 l->set_name ("OptionsLabel");
357
358                 t->attach (*l, 3, 4, 1, 2, FILL | EXPAND, FILL);
359                 t->attach (_delete_button_spin, 4, 5, 1, 2, FILL | EXPAND, FILL);
360
361                 _delete_button_spin.set_name ("OptionsEntry");
362                 _delete_button_adjustment.set_value (Keyboard::delete_button());
363                 _delete_button_adjustment.signal_value_changed().connect (sigc::mem_fun(*this, &KeyboardOptions::delete_button_changed));
364
365
366                 set_popdown_strings (_insert_note_modifier_combo, dumb);
367                 _insert_note_modifier_combo.signal_changed().connect (sigc::mem_fun(*this, &KeyboardOptions::insert_note_modifier_chosen));
368
369                 for (int x = 0; modifiers[x].name; ++x) {
370                         if (modifiers[x].modifier == Keyboard::insert_note_modifier ()) {
371                                 _insert_note_modifier_combo.set_active_text (S_(modifiers[x].name));
372                                 break;
373                         }
374                 }
375
376                 l = manage (new Label (_("Insert note using:")));
377                 l->set_name ("OptionsLabel");
378                 l->set_alignment (0, 0.5);
379
380                 t->attach (*l, 0, 1, 2, 3, FILL | EXPAND, FILL);
381                 t->attach (_insert_note_modifier_combo, 1, 2, 2, 3, FILL | EXPAND, FILL);
382
383                 l = manage (new Label (_("+ button")));
384                 l->set_name ("OptionsLabel");
385
386                 t->attach (*l, 3, 4, 2, 3, FILL | EXPAND, FILL);
387                 t->attach (_insert_note_button_spin, 4, 5, 2, 3, FILL | EXPAND, FILL);
388
389                 _insert_note_button_spin.set_name ("OptionsEntry");
390                 _insert_note_button_adjustment.set_value (Keyboard::insert_note_button());
391                 _insert_note_button_adjustment.signal_value_changed().connect (sigc::mem_fun(*this, &KeyboardOptions::insert_note_button_changed));
392
393
394                 set_popdown_strings (_snap_modifier_combo, dumb);
395                 _snap_modifier_combo.signal_changed().connect (sigc::mem_fun(*this, &KeyboardOptions::snap_modifier_chosen));
396
397                 for (int x = 0; modifiers[x].name; ++x) {
398                         if (modifiers[x].modifier == (guint) Keyboard::snap_modifier ()) {
399                                 _snap_modifier_combo.set_active_text (S_(modifiers[x].name));
400                                 break;
401                         }
402                 }
403
404                 l = manage (new Label (_("Toggle snap using:")));
405                 l->set_name ("OptionsLabel");
406                 l->set_alignment (0, 0.5);
407
408                 t->attach (*l, 0, 1, 3, 4, FILL | EXPAND, FILL);
409                 t->attach (_snap_modifier_combo, 1, 2, 3, 4, FILL | EXPAND, FILL);
410
411                 vector<string> strs;
412
413                 for (map<string,string>::iterator bf = Keyboard::binding_files.begin(); bf != Keyboard::binding_files.end(); ++bf) {
414                         strs.push_back (bf->first);
415                 }
416
417                 set_popdown_strings (_keyboard_layout_selector, strs);
418                 _keyboard_layout_selector.set_active_text (Keyboard::current_binding_name());
419                 _keyboard_layout_selector.signal_changed().connect (sigc::mem_fun (*this, &KeyboardOptions::bindings_changed));
420
421                 l = manage (new Label (_("Keyboard layout:")));
422                 l->set_name ("OptionsLabel");
423                 l->set_alignment (0, 0.5);
424
425                 t->attach (*l, 0, 1, 4, 5, FILL | EXPAND, FILL);
426                 t->attach (_keyboard_layout_selector, 1, 2, 4, 5, FILL | EXPAND, FILL);
427
428                 _box->pack_start (*t, false, false);
429         }
430
431         void parameter_changed (string const &)
432         {
433                 /* XXX: these aren't really config options... */
434         }
435
436         void set_state_from_config ()
437         {
438                 /* XXX: these aren't really config options... */
439         }
440
441 private:
442
443         void bindings_changed ()
444         {
445                 string const txt = _keyboard_layout_selector.get_active_text();
446
447                 /* XXX: config...?  for all this keyboard stuff */
448
449                 for (map<string,string>::iterator i = Keyboard::binding_files.begin(); i != Keyboard::binding_files.end(); ++i) {
450                         if (txt == i->first) {
451                                 if (Keyboard::load_keybindings (i->second)) {
452                                         Keyboard::save_keybindings ();
453                                 }
454                         }
455                 }
456         }
457
458         void edit_modifier_chosen ()
459         {
460                 string const txt = _edit_modifier_combo.get_active_text();
461
462                 for (int i = 0; modifiers[i].name; ++i) {
463                         if (txt == _(modifiers[i].name)) {
464                                 Keyboard::set_edit_modifier (modifiers[i].modifier);
465                                 break;
466                         }
467                 }
468         }
469
470         void delete_modifier_chosen ()
471         {
472                 string const txt = _delete_modifier_combo.get_active_text();
473
474                 for (int i = 0; modifiers[i].name; ++i) {
475                         if (txt == _(modifiers[i].name)) {
476                                 Keyboard::set_delete_modifier (modifiers[i].modifier);
477                                 break;
478                         }
479                 }
480         }
481
482         void insert_note_modifier_chosen ()
483         {
484                 string const txt = _insert_note_modifier_combo.get_active_text();
485
486                 for (int i = 0; modifiers[i].name; ++i) {
487                         if (txt == _(modifiers[i].name)) {
488                                 Keyboard::set_insert_note_modifier (modifiers[i].modifier);
489                                 break;
490                         }
491                 }
492         }
493
494         void snap_modifier_chosen ()
495         {
496                 string const txt = _snap_modifier_combo.get_active_text();
497
498                 for (int i = 0; modifiers[i].name; ++i) {
499                         if (txt == _(modifiers[i].name)) {
500                                 Keyboard::set_snap_modifier (modifiers[i].modifier);
501                                 break;
502                         }
503                 }
504         }
505
506         void delete_button_changed ()
507         {
508                 Keyboard::set_delete_button (_delete_button_spin.get_value_as_int());
509         }
510
511         void edit_button_changed ()
512         {
513                 Keyboard::set_edit_button (_edit_button_spin.get_value_as_int());
514         }
515
516         void insert_note_button_changed ()
517         {
518                 Keyboard::set_insert_note_button (_insert_note_button_spin.get_value_as_int());
519         }
520
521         ComboBoxText _keyboard_layout_selector;
522         ComboBoxText _edit_modifier_combo;
523         ComboBoxText _delete_modifier_combo;
524         ComboBoxText _insert_note_modifier_combo;
525         ComboBoxText _snap_modifier_combo;
526         Adjustment _delete_button_adjustment;
527         SpinButton _delete_button_spin;
528         Adjustment _edit_button_adjustment;
529         SpinButton _edit_button_spin;
530         Adjustment _insert_note_button_adjustment;
531         SpinButton _insert_note_button_spin;
532
533 };
534
535 class FontScalingOptions : public OptionEditorBox
536 {
537 public:
538         FontScalingOptions (RCConfiguration* c) :
539                 _rc_config (c),
540                 _dpi_adjustment (50, 50, 250, 1, 10),
541                 _dpi_slider (_dpi_adjustment)
542         {
543                 _dpi_adjustment.set_value (_rc_config->get_font_scale () / 1024);
544
545                 Label* l = manage (new Label (_("Font scaling:")));
546                 l->set_name ("OptionsLabel");
547
548                 _dpi_slider.set_update_policy (UPDATE_DISCONTINUOUS);
549                 HBox* h = manage (new HBox);
550                 h->set_spacing (4);
551                 h->pack_start (*l, false, false);
552                 h->pack_start (_dpi_slider, true, true);
553
554                 _box->pack_start (*h, false, false);
555
556                 _dpi_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &FontScalingOptions::dpi_changed));
557         }
558
559         void parameter_changed (string const & p)
560         {
561                 if (p == "font-scale") {
562                         _dpi_adjustment.set_value (_rc_config->get_font_scale() / 1024);
563                 }
564         }
565
566         void set_state_from_config ()
567         {
568                 parameter_changed ("font-scale");
569         }
570
571 private:
572
573         void dpi_changed ()
574         {
575                 _rc_config->set_font_scale ((long) floor (_dpi_adjustment.get_value() * 1024));
576                 /* XXX: should be triggered from the parameter changed signal */
577                 reset_dpi ();
578         }
579
580         RCConfiguration* _rc_config;
581         Adjustment _dpi_adjustment;
582         HScale _dpi_slider;
583 };
584
585 class BufferingOptions : public OptionEditorBox
586 {
587 public:
588         BufferingOptions (RCConfiguration* c)
589                 : _rc_config (c)
590                 , _playback_adjustment (5, 1, 60, 1, 4)
591                 , _capture_adjustment (5, 1, 60, 1, 4)
592                 , _playback_slider (_playback_adjustment)
593                 , _capture_slider (_capture_adjustment)
594         {
595                 _playback_adjustment.set_value (_rc_config->get_audio_playback_buffer_seconds());
596
597                 Label* l = manage (new Label (_("Playback (seconds of buffering):")));
598                 l->set_name ("OptionsLabel");
599
600                 _playback_slider.set_update_policy (UPDATE_DISCONTINUOUS);
601                 HBox* h = manage (new HBox);
602                 h->set_spacing (4);
603                 h->pack_start (*l, false, false);
604                 h->pack_start (_playback_slider, true, true);
605
606                 _box->pack_start (*h, false, false);
607
608                 _capture_adjustment.set_value (_rc_config->get_audio_capture_buffer_seconds());
609
610                 l = manage (new Label (_("Recording (seconds of buffering):")));
611                 l->set_name ("OptionsLabel");
612
613                 _capture_slider.set_update_policy (UPDATE_DISCONTINUOUS);
614                 h = manage (new HBox);
615                 h->set_spacing (4);
616                 h->pack_start (*l, false, false);
617                 h->pack_start (_capture_slider, true, true);
618
619                 _box->pack_start (*h, false, false);
620
621                 _capture_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &BufferingOptions::capture_changed));
622                 _playback_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &BufferingOptions::playback_changed));
623         }
624
625         void parameter_changed (string const & p)
626         {
627                 if (p == "playback-buffer-seconds") {
628                         _playback_adjustment.set_value (_rc_config->get_audio_playback_buffer_seconds());
629                 } else if (p == "capture-buffer-seconds") {
630                         _capture_adjustment.set_value (_rc_config->get_audio_capture_buffer_seconds());
631                 }
632         }
633
634         void set_state_from_config ()
635         {
636                 parameter_changed ("playback-buffer-seconds");
637                 parameter_changed ("capture-buffer-seconds");
638         }
639
640 private:
641
642         void playback_changed ()
643         {
644                 _rc_config->set_audio_playback_buffer_seconds ((long) _playback_adjustment.get_value());
645         }
646
647         void capture_changed ()
648         {
649                 _rc_config->set_audio_capture_buffer_seconds ((long) _capture_adjustment.get_value());
650         }
651
652         RCConfiguration* _rc_config;
653         Adjustment _playback_adjustment;
654         Adjustment _capture_adjustment;
655         HScale _playback_slider;
656         HScale _capture_slider;
657 };
658
659 class ControlSurfacesOptions : public OptionEditorBox
660 {
661 public:
662         ControlSurfacesOptions (Gtk::Window& parent)
663                 : _parent (parent)
664         {
665                 _store = ListStore::create (_model);
666                 _view.set_model (_store);
667                 _view.append_column (_("Name"), _model.name);
668                 _view.get_column(0)->set_resizable (true);
669                 _view.get_column(0)->set_expand (true);
670                 _view.append_column_editable (_("Enabled"), _model.enabled);
671                 _view.append_column_editable (_("Feedback"), _model.feedback);
672
673                 _box->pack_start (_view, false, false);
674
675                 Label* label = manage (new Label);
676                 label->set_markup (string_compose (X_("<i>%1</i>"), _("Double-click on a name to edit settings for an enabled protocol")));
677
678                 _box->pack_start (*label, false, false);
679                 label->show ();
680
681                 _store->signal_row_changed().connect (sigc::mem_fun (*this, &ControlSurfacesOptions::model_changed));
682                 _view.signal_button_press_event().connect_notify (sigc::mem_fun(*this, &ControlSurfacesOptions::edit_clicked));
683         }
684
685         void parameter_changed (std::string const &)
686         {
687
688         }
689
690         void set_state_from_config ()
691         {
692                 _store->clear ();
693
694                 ControlProtocolManager& m = ControlProtocolManager::instance ();
695                 for (list<ControlProtocolInfo*>::iterator i = m.control_protocol_info.begin(); i != m.control_protocol_info.end(); ++i) {
696
697                         if (!(*i)->mandatory) {
698                                 TreeModel::Row r = *_store->append ();
699                                 r[_model.name] = (*i)->name;
700                                 r[_model.enabled] = ((*i)->protocol || (*i)->requested);
701                                 r[_model.feedback] = ((*i)->protocol && (*i)->protocol->get_feedback ());
702                                 r[_model.protocol_info] = *i;
703                         }
704                 }
705         }
706
707 private:
708
709         void model_changed (TreeModel::Path const &, TreeModel::iterator const & i)
710         {
711                 TreeModel::Row r = *i;
712
713                 ControlProtocolInfo* cpi = r[_model.protocol_info];
714                 if (!cpi) {
715                         return;
716                 }
717
718                 bool const was_enabled = (cpi->protocol != 0);
719                 bool const is_enabled = r[_model.enabled];
720
721                 if (was_enabled != is_enabled) {
722                         if (!was_enabled) {
723                                 ControlProtocolManager::instance().instantiate (*cpi);
724                         } else {
725                                 Gtk::Window* win = r[_model.editor];
726                                 if (win) {
727                                         win->hide ();
728                                 }
729
730                                 ControlProtocolManager::instance().teardown (*cpi);
731                                         
732                                 if (win) {
733                                         delete win;
734                                 }
735                                 r[_model.editor] = 0;
736                                 cpi->requested = false;
737                         }
738                 }
739
740                 bool const was_feedback = (cpi->protocol && cpi->protocol->get_feedback ());
741                 bool const is_feedback = r[_model.feedback];
742
743                 if (was_feedback != is_feedback && cpi->protocol) {
744                         cpi->protocol->set_feedback (is_feedback);
745                 }
746         }
747
748         void edit_clicked (GdkEventButton* ev)
749         {
750                 if (ev->type != GDK_2BUTTON_PRESS) {
751                         return;
752                 }
753
754                 std::string name;
755                 ControlProtocolInfo* cpi;
756                 TreeModel::Row row;
757
758                 row = *(_view.get_selection()->get_selected());
759
760                 Window* win = row[_model.editor];
761                 if (win && !win->is_visible()) {
762                         win->present ();
763                 } else {
764                         cpi = row[_model.protocol_info];
765
766                         if (cpi && cpi->protocol && cpi->protocol->has_editor ()) {
767                                 Box* box = (Box*) cpi->protocol->get_gui ();
768                                 if (box) {
769                                         string title = row[_model.name];
770                                         ArdourWindow* win = new ArdourWindow (_parent, title);
771                                         win->set_title ("Control Protocol Options");
772                                         win->add (*box);
773                                         box->show ();
774                                         win->present ();
775                                         row[_model.editor] = win;
776                                 }
777                         }
778                 }
779         }
780
781         class ControlSurfacesModelColumns : public TreeModelColumnRecord
782         {
783         public:
784
785                 ControlSurfacesModelColumns ()
786                 {
787                         add (name);
788                         add (enabled);
789                         add (feedback);
790                         add (protocol_info);
791                         add (editor);
792                 }
793
794                 TreeModelColumn<string> name;
795                 TreeModelColumn<bool> enabled;
796                 TreeModelColumn<bool> feedback;
797                 TreeModelColumn<ControlProtocolInfo*> protocol_info;
798                 TreeModelColumn<Gtk::Window*> editor;
799         };
800
801         Glib::RefPtr<ListStore> _store;
802         ControlSurfacesModelColumns _model;
803         TreeView _view;
804         Gtk::Window& _parent;
805 };
806
807 /** A class which allows control of visibility of some editor components usign
808  *  a VisibilityGroup.  The caller should pass in a `dummy' VisibilityGroup
809  *  which has the correct members, but with null widget pointers.  This
810  *  class allows the user to set visibility of the members, the details
811  *  of which are stored in a configuration variable which can be watched
812  *  by parts of the editor that actually contain the widgets whose visibility
813  *  is being controlled.
814  */
815
816 class VisibilityOption : public Option
817 {
818 public:
819         /** @param name User-visible name for this group.
820          *  @param g `Dummy' VisibilityGroup (as described above).
821          *  @param get Method to get the value of the appropriate configuration variable.
822          *  @param set Method to set the value of the appropriate configuration variable.
823          */
824         VisibilityOption (string name, VisibilityGroup* g, sigc::slot<string> get, sigc::slot<bool, string> set)
825                 : Option (g->get_state_name(), name)
826                 , _heading (name)
827                 , _visibility_group (g)
828                 , _get (get)
829                 , _set (set)
830         {
831                 /* Watch for changes made by the user to our members */
832                 _visibility_group->VisibilityChanged.connect_same_thread (
833                         _visibility_group_connection, sigc::bind (&VisibilityOption::changed, this)
834                         );
835         }
836
837         void set_state_from_config ()
838         {
839                 /* Set our state from the current configuration */
840                 _visibility_group->set_state (_get ());
841         }
842
843         void add_to_page (OptionEditorPage* p)
844         {
845                 _heading.add_to_page (p);
846                 add_widget_to_page (p, _visibility_group->list_view ());
847         }
848
849 private:
850         void changed ()
851         {
852                 /* The user has changed something, so reflect this change
853                    in the RCConfiguration.
854                 */
855                 _set (_visibility_group->get_state_value ());
856         }
857         
858         OptionEditorHeading _heading;
859         VisibilityGroup* _visibility_group;
860         sigc::slot<std::string> _get;
861         sigc::slot<bool, std::string> _set;
862         PBD::ScopedConnection _visibility_group_connection;
863 };
864
865
866 RCOptionEditor::RCOptionEditor ()
867         : OptionEditor (Config, string_compose (_("%1 Preferences"), PROGRAM_NAME))
868         , _rc_config (Config)
869         , _mixer_strip_visibility ("mixer-strip-visibility")
870 {
871         /* MISC */
872
873         uint32_t hwcpus = hardware_concurrency ();
874
875         if (hwcpus > 1) {
876                 add_option (_("Misc"), new OptionEditorHeading (_("DSP CPU Utilization")));
877
878                 ComboOption<int32_t>* procs = new ComboOption<int32_t> (
879                         "processor-usage",
880                         _("Signal processing uses"),
881                         sigc::mem_fun (*_rc_config, &RCConfiguration::get_processor_usage),
882                         sigc::mem_fun (*_rc_config, &RCConfiguration::set_processor_usage)
883                         );
884
885                 procs->add (-1, _("all but one processor"));
886                 procs->add (0, _("all available processors"));
887
888                 for (uint32_t i = 1; i <= hwcpus; ++i) {
889                         procs->add (i, string_compose (_("%1 processors"), i));
890                 }
891
892                 procs->set_note (string_compose (_("This setting will only take effect when %1 is restarted."), PROGRAM_NAME));
893
894                 add_option (_("Misc"), procs);
895         }
896
897         add_option (_("Misc"), new OptionEditorHeading (S_("Options|Undo")));
898
899         add_option (_("Misc"), new UndoOptions (_rc_config));
900
901         add_option (_("Misc"),
902              new BoolOption (
903                      "verify-remove-last-capture",
904                      _("Verify removal of last capture"),
905                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_verify_remove_last_capture),
906                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_verify_remove_last_capture)
907                      ));
908
909         add_option (_("Misc"),
910              new BoolOption (
911                      "periodic-safety-backups",
912                      _("Make periodic backups of the session file"),
913                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_periodic_safety_backups),
914                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_periodic_safety_backups)
915                      ));
916
917         add_option (_("Misc"), new OptionEditorHeading (_("Session Management")));
918
919         add_option (_("Misc"),
920              new BoolOption (
921                      "only-copy-imported-files",
922                      _("Always copy imported files"),
923                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_only_copy_imported_files),
924                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_only_copy_imported_files)
925                      ));
926
927         add_option (_("Misc"), new DirectoryOption (
928                             X_("default-session-parent-dir"),
929                             _("Default folder for new sessions:"),
930                             sigc::mem_fun (*_rc_config, &RCConfiguration::get_default_session_parent_dir),
931                             sigc::mem_fun (*_rc_config, &RCConfiguration::set_default_session_parent_dir)
932                             ));
933
934         add_option (_("Misc"),
935              new SpinOption<uint32_t> (
936                      "max-recent-sessions",
937                      _("Maximum number of recent sessions"),
938                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_max_recent_sessions),
939                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_max_recent_sessions),
940                      0, 1000, 1, 20
941                      ));
942
943         add_option (_("Misc"), new OptionEditorHeading (_("Click")));
944
945         add_option (_("Misc"), new ClickOptions (_rc_config, this));
946
947         add_option (_("Misc"),
948              new FaderOption (
949                      "click-gain",
950                      _("Click Gain Level"),
951                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_click_gain),
952                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_click_gain)
953                      ));
954
955         add_option (_("Misc"), new OptionEditorHeading (_("Automation")));
956
957         add_option (_("Misc"),
958              new SpinOption<double> (
959                      "automation-thinning-factor",
960                      _("Thinning factor (larger value => less data)"),
961                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_automation_thinning_factor),
962                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_automation_thinning_factor),
963                      0, 1000, 1, 20
964                      ));
965
966         /* TRANSPORT */
967
968         add_option (_("Transport"),
969              new BoolOption (
970                      "latched-record-enable",
971                      _("Keep record-enable engaged on stop"),
972                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_latched_record_enable),
973                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_latched_record_enable)
974                      ));
975
976         add_option (_("Transport"),
977              new BoolOption (
978                      "stop-recording-on-xrun",
979                      _("Stop recording when an xrun occurs"),
980                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_stop_recording_on_xrun),
981                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_stop_recording_on_xrun)
982                      ));
983
984         add_option (_("Transport"),
985              new BoolOption (
986                      "create-xrun-marker",
987                      _("Create markers where xruns occur"),
988                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_create_xrun_marker),
989                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_create_xrun_marker)
990                      ));
991
992         add_option (_("Transport"),
993              new BoolOption (
994                      "stop-at-session-end",
995                      _("Stop at the end of the session"),
996                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_stop_at_session_end),
997                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_stop_at_session_end)
998                      ));
999
1000         add_option (_("Transport"),
1001              new BoolOption (
1002                      "seamless-loop",
1003                      _("Do seamless looping (not possible when slaved to MTC, JACK etc)"),
1004                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_seamless_loop),
1005                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_seamless_loop)
1006                      ));
1007
1008         add_option (_("Transport"),
1009              new BoolOption (
1010                      "primary-clock-delta-edit-cursor",
1011                      _("Primary clock delta to edit cursor"),
1012                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_primary_clock_delta_edit_cursor),
1013                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_primary_clock_delta_edit_cursor)
1014                      ));
1015
1016         add_option (_("Transport"),
1017              new BoolOption (
1018                      "secondary-clock-delta-edit-cursor",
1019                      _("Secondary clock delta to edit cursor"),
1020                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_secondary_clock_delta_edit_cursor),
1021                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_secondary_clock_delta_edit_cursor)
1022                      ));
1023
1024         add_option (_("Transport"),
1025              new BoolOption (
1026                      "disable-disarm-during-roll",
1027                      _("Disable per-track record disarm while rolling"),
1028                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_disable_disarm_during_roll),
1029                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_disable_disarm_during_roll)
1030                      ));
1031
1032         add_option (_("Transport"),
1033              new BoolOption (
1034                      "quieten_at_speed",
1035                      _("12dB gain reduction during fast-forward and fast-rewind"),
1036                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_quieten_at_speed),
1037                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_quieten_at_speed)
1038                      ));
1039
1040         /* EDITOR */
1041
1042         add_option (_("Editor"),
1043              new BoolOption (
1044                      "link-region-and-track-selection",
1045                      _("Link selection of regions and tracks"),
1046                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_link_region_and_track_selection),
1047                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_link_region_and_track_selection)
1048                      ));
1049
1050         add_option (_("Editor"),
1051              new BoolOption (
1052                      "automation-follows-regions",
1053                      _("Move relevant automation when audio regions are moved"),
1054                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_automation_follows_regions),
1055                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_automation_follows_regions)
1056                      ));
1057
1058         add_option (_("Editor"),
1059              new BoolOption (
1060                      "show-track-meters",
1061                      _("Show meters on tracks in the editor"),
1062                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_show_track_meters),
1063                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_show_track_meters)
1064                      ));
1065
1066         add_option (_("Editor"),
1067              new BoolOption (
1068                      "use-overlap-equivalency",
1069                      _("Use overlap equivalency for regions"),
1070                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_use_overlap_equivalency),
1071                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_use_overlap_equivalency)
1072                      ));
1073
1074         add_option (_("Editor"),
1075              new BoolOption (
1076                      "rubberbanding-snaps-to-grid",
1077                      _("Make rubberband selection rectangle snap to the grid"),
1078                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_rubberbanding_snaps_to_grid),
1079                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_rubberbanding_snaps_to_grid)
1080                      ));
1081
1082         add_option (_("Editor"),
1083              new BoolOption (
1084                      "show-waveforms",
1085                      _("Show waveforms in regions"),
1086                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_show_waveforms),
1087                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_show_waveforms)
1088                      ));
1089
1090         add_option (_("Editor"),
1091              new BoolOption (
1092                      "show-region-gain-envelopes",
1093                      _("Show gain envelopes in audio regions"),
1094                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_show_region_gain),
1095                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_show_region_gain)
1096                      ));
1097
1098         ComboOption<WaveformScale>* wfs = new ComboOption<WaveformScale> (
1099                 "waveform-scale",
1100                 _("Waveform scale"),
1101                 sigc::mem_fun (*_rc_config, &RCConfiguration::get_waveform_scale),
1102                 sigc::mem_fun (*_rc_config, &RCConfiguration::set_waveform_scale)
1103                 );
1104
1105         wfs->add (Linear, _("linear"));
1106         wfs->add (Logarithmic, _("logarithmic"));
1107
1108         add_option (_("Editor"), wfs);
1109
1110         ComboOption<WaveformShape>* wfsh = new ComboOption<WaveformShape> (
1111                 "waveform-shape",
1112                 _("Waveform shape"),
1113                 sigc::mem_fun (*_rc_config, &RCConfiguration::get_waveform_shape),
1114                 sigc::mem_fun (*_rc_config, &RCConfiguration::set_waveform_shape)
1115                 );
1116
1117         wfsh->add (Traditional, _("traditional"));
1118         wfsh->add (Rectified, _("rectified"));
1119
1120         add_option (_("Editor"), wfsh);
1121
1122         add_option (_("Editor"),
1123              new BoolOption (
1124                      "show-waveforms-while-recording",
1125                      _("Show waveforms for audio while it is being recorded"),
1126                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_show_waveforms_while_recording),
1127                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_show_waveforms_while_recording)
1128                      ));
1129
1130         add_option (_("Editor"),
1131                     new BoolOption (
1132                             "show-zoom-tools",
1133                             _("Show zoom toolbar"),
1134                             sigc::mem_fun (*_rc_config, &RCConfiguration::get_show_zoom_tools),
1135                             sigc::mem_fun (*_rc_config, &RCConfiguration::set_show_zoom_tools)
1136                             ));
1137
1138         add_option (_("Editor"),
1139                     new BoolOption (
1140                             "color-regions-using-track-color",
1141                             _("Color regions using their track's color"),
1142                             sigc::mem_fun (*_rc_config, &RCConfiguration::get_color_regions_using_track_color),
1143                             sigc::mem_fun (*_rc_config, &RCConfiguration::set_color_regions_using_track_color)
1144                             ));
1145
1146         add_option (_("Editor"),
1147                     new BoolOption (
1148                             "update-editor-during-summary-drag",
1149                             _("Update editor window during drags of the summary"),
1150                             sigc::mem_fun (*_rc_config, &RCConfiguration::get_update_editor_during_summary_drag),
1151                             sigc::mem_fun (*_rc_config, &RCConfiguration::set_update_editor_during_summary_drag)
1152                             ));
1153
1154         add_option (_("Editor"),
1155              new BoolOption (
1156                      "sync-all-route-ordering",
1157                      _("Synchronise editor and mixer track order"),
1158                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_sync_all_route_ordering),
1159                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_sync_all_route_ordering)
1160                      ));
1161
1162         add_option (_("Editor"),
1163              new BoolOption (
1164                      "link-editor-and-mixer-selection",
1165                      _("Synchronise editor and mixer selection"),
1166                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_link_editor_and_mixer_selection),
1167                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_link_editor_and_mixer_selection)
1168                      ));
1169
1170         add_option (_("Editor"),
1171              new BoolOption (
1172                      "name-new-markers",
1173                      _("Name new markers"),
1174                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_name_new_markers),
1175                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_name_new_markers)
1176                      ));
1177
1178         /* AUDIO */
1179
1180         add_option (_("Audio"), new OptionEditorHeading (_("Buffering")));
1181
1182         add_option (_("Audio"), new BufferingOptions (_rc_config));
1183
1184         add_option (_("Audio"), new OptionEditorHeading (_("Monitoring")));
1185
1186         add_option (_("Audio"),
1187              new BoolOption (
1188                      "use-monitor-bus",
1189                      _("Use a monitor bus (allows AFL/PFL and more control)"),
1190                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_use_monitor_bus),
1191                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_use_monitor_bus)
1192                      ));
1193
1194         ComboOption<MonitorModel>* mm = new ComboOption<MonitorModel> (
1195                 "monitoring-model",
1196                 _("Record monitoring handled by"),
1197                 sigc::mem_fun (*_rc_config, &RCConfiguration::get_monitoring_model),
1198                 sigc::mem_fun (*_rc_config, &RCConfiguration::set_monitoring_model)
1199                 );
1200
1201 #ifndef __APPLE__
1202         /* no JACK monitoring on CoreAudio */
1203         if (AudioEngine::instance()->can_request_hardware_monitoring()) {
1204                 mm->add (HardwareMonitoring, _("JACK"));
1205         }
1206 #endif
1207         mm->add (SoftwareMonitoring, _("ardour"));
1208         mm->add (ExternalMonitoring, _("audio hardware"));
1209
1210         add_option (_("Audio"), mm);
1211
1212         add_option (_("Audio"),
1213              new BoolOption (
1214                      "tape-machine-mode",
1215                      _("Tape machine mode"),
1216                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_tape_machine_mode),
1217                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_tape_machine_mode)
1218                      ));
1219
1220         add_option (_("Audio"), new OptionEditorHeading (_("Connection of tracks and busses")));
1221
1222         add_option (_("Audio"),
1223                     new BoolOption (
1224                             "auto-connect-standard-busses",
1225                             _("Auto-connect master/monitor busses"),
1226                             sigc::mem_fun (*_rc_config, &RCConfiguration::get_auto_connect_standard_busses),
1227                             sigc::mem_fun (*_rc_config, &RCConfiguration::set_auto_connect_standard_busses)
1228                             ));
1229
1230         ComboOption<AutoConnectOption>* iac = new ComboOption<AutoConnectOption> (
1231                 "input-auto-connect",
1232                 _("Connect track inputs"),
1233                 sigc::mem_fun (*_rc_config, &RCConfiguration::get_input_auto_connect),
1234                 sigc::mem_fun (*_rc_config, &RCConfiguration::set_input_auto_connect)
1235                 );
1236
1237         iac->add (AutoConnectPhysical, _("automatically to physical inputs"));
1238         iac->add (ManualConnect, _("manually"));
1239
1240         add_option (_("Audio"), iac);
1241
1242         ComboOption<AutoConnectOption>* oac = new ComboOption<AutoConnectOption> (
1243                 "output-auto-connect",
1244                 _("Connect track and bus outputs"),
1245                 sigc::mem_fun (*_rc_config, &RCConfiguration::get_output_auto_connect),
1246                 sigc::mem_fun (*_rc_config, &RCConfiguration::set_output_auto_connect)
1247                 );
1248
1249         oac->add (AutoConnectPhysical, _("automatically to physical outputs"));
1250         oac->add (AutoConnectMaster, _("automatically to master bus"));
1251         oac->add (ManualConnect, _("manually"));
1252
1253         add_option (_("Audio"), oac);
1254
1255         add_option (_("Audio"), new OptionEditorHeading (_("Denormals")));
1256
1257         add_option (_("Audio"),
1258              new BoolOption (
1259                      "denormal-protection",
1260                      _("Use DC bias to protect against denormals"),
1261                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_denormal_protection),
1262                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_denormal_protection)
1263                      ));
1264
1265         ComboOption<DenormalModel>* dm = new ComboOption<DenormalModel> (
1266                 "denormal-model",
1267                 _("Processor handling"),
1268                 sigc::mem_fun (*_rc_config, &RCConfiguration::get_denormal_model),
1269                 sigc::mem_fun (*_rc_config, &RCConfiguration::set_denormal_model)
1270                 );
1271
1272         dm->add (DenormalNone, _("no processor handling"));
1273
1274         FPU fpu;
1275
1276         if (fpu.has_flush_to_zero()) {
1277                 dm->add (DenormalFTZ, _("use FlushToZero"));
1278         }
1279
1280         if (fpu.has_denormals_are_zero()) {
1281                 dm->add (DenormalDAZ, _("use DenormalsAreZero"));
1282         }
1283
1284         if (fpu.has_flush_to_zero() && fpu.has_denormals_are_zero()) {
1285                 dm->add (DenormalFTZDAZ, _("use FlushToZero and DenormalsAreZero"));
1286         }
1287
1288         add_option (_("Audio"), dm);
1289
1290         add_option (_("Audio"), new OptionEditorHeading (_("Plugins")));
1291
1292         add_option (_("Audio"),
1293              new BoolOption (
1294                      "plugins-stop-with-transport",
1295                      _("Silence plugins when the transport is stopped"),
1296                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_plugins_stop_with_transport),
1297                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_plugins_stop_with_transport)
1298                      ));
1299
1300         add_option (_("Audio"),
1301              new BoolOption (
1302                      "do-not-record-plugins",
1303                      _("Disable plugins during recording"),
1304                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_do_not_record_plugins),
1305                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_do_not_record_plugins)
1306                      ));
1307
1308         add_option (_("Audio"),
1309              new BoolOption (
1310                      "new-plugins-active",
1311                      _("Make new plugins active"),
1312                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_new_plugins_active),
1313                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_new_plugins_active)
1314                      ));
1315
1316         add_option (_("Audio"),
1317              new BoolOption (
1318                      "auto-analyse-audio",
1319                      _("Enable automatic analysis of audio"),
1320                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_auto_analyse_audio),
1321                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_auto_analyse_audio)
1322                      ));
1323
1324         add_option (_("Audio"),
1325              new BoolOption (
1326                      "replicate-missing-region-channels",
1327                      _("Replicate missing region channels"),
1328                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_replicate_missing_region_channels),
1329                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_replicate_missing_region_channels)
1330                      ));
1331
1332         /* SOLO AND MUTE */
1333
1334         add_option (_("Solo / mute"),
1335              new FaderOption (
1336                      "solo-mute-gain",
1337                      _("Solo-in-place mute cut (dB)"),
1338                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_solo_mute_gain),
1339                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_solo_mute_gain)
1340                      ));
1341
1342         _solo_control_is_listen_control = new BoolOption (
1343                 "solo-control-is-listen-control",
1344                 _("Solo controls are Listen controls"),
1345                 sigc::mem_fun (*_rc_config, &RCConfiguration::get_solo_control_is_listen_control),
1346                 sigc::mem_fun (*_rc_config, &RCConfiguration::set_solo_control_is_listen_control)
1347                 );
1348
1349         add_option (_("Solo / mute"), _solo_control_is_listen_control);
1350
1351         _listen_position = new ComboOption<ListenPosition> (
1352                 "listen-position",
1353                 _("Listen Position"),
1354                 sigc::mem_fun (*_rc_config, &RCConfiguration::get_listen_position),
1355                 sigc::mem_fun (*_rc_config, &RCConfiguration::set_listen_position)
1356                 );
1357
1358         _listen_position->add (AfterFaderListen, _("after-fader (AFL)"));
1359         _listen_position->add (PreFaderListen, _("pre-fader (PFL)"));
1360
1361         add_option (_("Solo / mute"), _listen_position);
1362
1363         ComboOption<PFLPosition>* pp = new ComboOption<PFLPosition> (
1364                 "pfl-position",
1365                 _("PFL signals come from"),
1366                 sigc::mem_fun (*_rc_config, &RCConfiguration::get_pfl_position),
1367                 sigc::mem_fun (*_rc_config, &RCConfiguration::set_pfl_position)
1368                 );
1369
1370         pp->add (PFLFromBeforeProcessors, _("before pre-fader processors"));
1371         pp->add (PFLFromAfterProcessors, _("pre-fader but after pre-fader processors"));
1372
1373         add_option (_("Solo / mute"), pp);
1374
1375         ComboOption<AFLPosition>* pa = new ComboOption<AFLPosition> (
1376                 "afl-position",
1377                 _("AFL signals come from"),
1378                 sigc::mem_fun (*_rc_config, &RCConfiguration::get_afl_position),
1379                 sigc::mem_fun (*_rc_config, &RCConfiguration::set_afl_position)
1380                 );
1381
1382         pa->add (AFLFromBeforeProcessors, _("immediately post-fader"));
1383         pa->add (AFLFromAfterProcessors, _("after post-fader processors (before pan)"));
1384
1385         add_option (_("Solo / mute"), pa);
1386
1387         parameter_changed ("use-monitor-bus");
1388
1389         add_option (_("Solo / mute"),
1390              new BoolOption (
1391                      "exclusive-solo",
1392                      _("Exclusive solo"),
1393                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_exclusive_solo),
1394                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_exclusive_solo)
1395                      ));
1396
1397         add_option (_("Solo / mute"),
1398              new BoolOption (
1399                      "show-solo-mutes",
1400                      _("Show solo muting"),
1401                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_show_solo_mutes),
1402                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_show_solo_mutes)
1403                      ));
1404
1405         add_option (_("Solo / mute"),
1406              new BoolOption (
1407                      "solo-mute-override",
1408                      _("Soloing overrides muting"),
1409                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_solo_mute_override),
1410                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_solo_mute_override)
1411                      ));
1412
1413         add_option (_("Solo / mute"), new OptionEditorHeading (_("Default track / bus muting options")));
1414
1415         add_option (_("Solo / mute"),
1416              new BoolOption (
1417                      "mute-affects-pre-fader",
1418                      _("Mute affects pre-fader sends"),
1419                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_mute_affects_pre_fader),
1420                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_mute_affects_pre_fader)
1421                      ));
1422
1423         add_option (_("Solo / mute"),
1424              new BoolOption (
1425                      "mute-affects-post-fader",
1426                      _("Mute affects post-fader sends"),
1427                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_mute_affects_post_fader),
1428                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_mute_affects_post_fader)
1429                      ));
1430
1431         add_option (_("Solo / mute"),
1432              new BoolOption (
1433                      "mute-affects-control-outs",
1434                      _("Mute affects control outputs"),
1435                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_mute_affects_control_outs),
1436                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_mute_affects_control_outs)
1437                      ));
1438
1439         add_option (_("Solo / mute"),
1440              new BoolOption (
1441                      "mute-affects-main-outs",
1442                      _("Mute affects main outputs"),
1443                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_mute_affects_main_outs),
1444                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_mute_affects_main_outs)
1445                      ));
1446
1447         add_option (_("MIDI"),
1448                     new BoolOption (
1449                             "send-midi-clock",
1450                             _("Send MIDI Clock"),
1451                             sigc::mem_fun (*_rc_config, &RCConfiguration::get_send_midi_clock),
1452                             sigc::mem_fun (*_rc_config, &RCConfiguration::set_send_midi_clock)
1453                             ));
1454
1455         add_option (_("MIDI"),
1456                     new BoolOption (
1457                             "send-mtc",
1458                             _("Send MIDI Time Code"),
1459                             sigc::mem_fun (*_rc_config, &RCConfiguration::get_send_mtc),
1460                             sigc::mem_fun (*_rc_config, &RCConfiguration::set_send_mtc)
1461                             ));
1462
1463         add_option (_("MIDI"),
1464                     new SpinOption<int> (
1465                             "mtc-qf-speed-tolerance",
1466                             _("Percentage either side of normal transport speed to transmit MTC"),
1467                             sigc::mem_fun (*_rc_config, &RCConfiguration::get_mtc_qf_speed_tolerance),
1468                             sigc::mem_fun (*_rc_config, &RCConfiguration::set_mtc_qf_speed_tolerance),
1469                             0, 20, 1, 5
1470                             ));
1471
1472         add_option (_("MIDI"),
1473                     new BoolOption (
1474                             "mmc-control",
1475                             _("Obey MIDI Machine Control commands"),
1476                             sigc::mem_fun (*_rc_config, &RCConfiguration::get_mmc_control),
1477                             sigc::mem_fun (*_rc_config, &RCConfiguration::set_mmc_control)
1478                             ));
1479
1480         add_option (_("MIDI"),
1481                     new BoolOption (
1482                             "send-mmc",
1483                             _("Send MIDI Machine Control commands"),
1484                             sigc::mem_fun (*_rc_config, &RCConfiguration::get_send_mmc),
1485                             sigc::mem_fun (*_rc_config, &RCConfiguration::set_send_mmc)
1486                             ));
1487
1488         add_option (_("MIDI"),
1489                     new BoolOption (
1490                             "midi-feedback",
1491                             _("Send MIDI control feedback"),
1492                             sigc::mem_fun (*_rc_config, &RCConfiguration::get_midi_feedback),
1493                             sigc::mem_fun (*_rc_config, &RCConfiguration::set_midi_feedback)
1494                             ));
1495
1496         add_option (_("MIDI"),
1497              new SpinOption<uint8_t> (
1498                      "mmc-receive-device-id",
1499                      _("Inbound MMC device ID"),
1500                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_mmc_receive_device_id),
1501                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_mmc_receive_device_id),
1502                      0, 128, 1, 10
1503                      ));
1504
1505         add_option (_("MIDI"),
1506              new SpinOption<uint8_t> (
1507                      "mmc-send-device-id",
1508                      _("Outbound MMC device ID"),
1509                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_mmc_send_device_id),
1510                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_mmc_send_device_id),
1511                      0, 128, 1, 10
1512                      ));
1513
1514         add_option (_("MIDI"),
1515              new SpinOption<int32_t> (
1516                      "initial-program-change",
1517                      _("Initial program change"),
1518                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_initial_program_change),
1519                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_initial_program_change),
1520                      -1, 65536, 1, 10
1521                      ));
1522
1523         add_option (_("MIDI"),
1524                     new BoolOption (
1525                             "diplay-first-midi-bank-as-zero",
1526                             _("Display first MIDI bank/program as 0"),
1527                             sigc::mem_fun (*_rc_config, &RCConfiguration::get_first_midi_bank_is_zero),
1528                             sigc::mem_fun (*_rc_config, &RCConfiguration::set_first_midi_bank_is_zero)
1529                             ));
1530
1531         add_option (_("MIDI"),
1532              new BoolOption (
1533                      "never-display-periodic-midi",
1534                      _("Never display periodic MIDI messages (MTC, MIDI Clock)"),
1535                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_never_display_periodic_midi),
1536                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_never_display_periodic_midi)
1537                      ));
1538
1539         add_option (_("MIDI"),
1540              new BoolOption (
1541                      "sound-midi-notes",
1542                      _("Sound MIDI notes as they are selected"),
1543                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_sound_midi_notes),
1544                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_sound_midi_notes)
1545                      ));
1546
1547         /* USER INTERACTION */
1548
1549         add_option (_("User interaction"), new OptionEditorHeading (_("Keyboard")));
1550
1551         add_option (_("User interaction"), new KeyboardOptions);
1552
1553         add_option (_("User interaction"), new OptionEditorHeading (_("Control surfaces")));
1554
1555         add_option (_("User interaction"), new ControlSurfacesOptions (*this));
1556
1557         ComboOption<RemoteModel>* rm = new ComboOption<RemoteModel> (
1558                 "remote-model",
1559                 _("Control surface remote ID"),
1560                 sigc::mem_fun (*_rc_config, &RCConfiguration::get_remote_model),
1561                 sigc::mem_fun (*_rc_config, &RCConfiguration::set_remote_model)
1562                 );
1563
1564         rm->add (UserOrdered, _("assigned by user"));
1565         rm->add (MixerOrdered, _("follows order of mixer"));
1566         rm->add (EditorOrdered, _("follows order of editor"));
1567
1568         add_option (_("User interaction"), rm);
1569
1570         /* INTERFACE */
1571
1572         add_option (S_("Visual|Interface"),
1573              new BoolOption (
1574                      "widget-prelight",
1575                      _("Graphically indicate mouse pointer hovering over various widgets"),
1576                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_widget_prelight),
1577                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_widget_prelight)
1578                      ));
1579
1580 #ifndef GTKOSX
1581         /* font scaling does nothing with GDK/Quartz */
1582         add_option (S_("Visual|Interface"), new FontScalingOptions (_rc_config));
1583 #endif
1584         add_option (S_("Visual|Interface"),
1585                     new BoolOption (
1586                             "use-own-plugin-gui",
1587                             _("Use plugins' own interfaces instead of Ardour's"),
1588                             sigc::mem_fun (*_rc_config, &RCConfiguration::get_use_plugin_own_gui),
1589                             sigc::mem_fun (*_rc_config, &RCConfiguration::set_use_plugin_own_gui)
1590                             ));
1591
1592         /* The names of these controls must be the same as those given in MixerStrip
1593            for the actual widgets being controlled.
1594         */
1595         _mixer_strip_visibility.add (0, X_("PhaseInvert"), _("Phase Invert"));
1596         _mixer_strip_visibility.add (0, X_("SoloSafe"), _("Solo Safe"));
1597         _mixer_strip_visibility.add (0, X_("SoloIsolated"), _("Solo Isolated"));
1598         _mixer_strip_visibility.add (0, X_("Comments"), _("Comments"));
1599         _mixer_strip_visibility.add (0, X_("Group"), _("Group"));
1600         _mixer_strip_visibility.add (0, X_("MeterPoint"), _("Meter Point"));
1601         
1602         add_option (
1603                 S_("Visual|Interface"),
1604                 new VisibilityOption (
1605                         _("Mixer Strip"),
1606                         &_mixer_strip_visibility,
1607                         sigc::mem_fun (*_rc_config, &RCConfiguration::get_mixer_strip_visibility),
1608                         sigc::mem_fun (*_rc_config, &RCConfiguration::set_mixer_strip_visibility)
1609                         )
1610                 );
1611
1612         add_option (S_("Visual|Interface"),
1613              new BoolOption (
1614                      "default-narrow_ms",
1615                      _("Use narrow mixer strips by default"),
1616                      sigc::mem_fun (*_rc_config, &RCConfiguration::get_default_narrow_ms),
1617                      sigc::mem_fun (*_rc_config, &RCConfiguration::set_default_narrow_ms)
1618                      ));
1619
1620         add_option (S_("Visual|Interface"), new OptionEditorHeading (_("Metering")));
1621
1622         ComboOption<float>* mht = new ComboOption<float> (
1623                 "meter-hold",
1624                 _("Meter hold time"),
1625                 sigc::mem_fun (*_rc_config, &RCConfiguration::get_meter_hold),
1626                 sigc::mem_fun (*_rc_config, &RCConfiguration::set_meter_hold)
1627                 );
1628
1629         mht->add (MeterHoldOff, _("off"));
1630         mht->add (MeterHoldShort, _("short"));
1631         mht->add (MeterHoldMedium, _("medium"));
1632         mht->add (MeterHoldLong, _("long"));
1633
1634         add_option (S_("Visual|Interface"), mht);
1635
1636         ComboOption<float>* mfo = new ComboOption<float> (
1637                 "meter-falloff",
1638                 _("Meter fall-off"),
1639                 sigc::mem_fun (*_rc_config, &RCConfiguration::get_meter_falloff),
1640                 sigc::mem_fun (*_rc_config, &RCConfiguration::set_meter_falloff)
1641                 );
1642
1643         mfo->add (METER_FALLOFF_OFF, _("off"));
1644         mfo->add (METER_FALLOFF_SLOWEST, _("slowest"));
1645         mfo->add (METER_FALLOFF_SLOW, _("slow"));
1646         mfo->add (METER_FALLOFF_MEDIUM, _("medium"));
1647         mfo->add (METER_FALLOFF_FAST, _("fast"));
1648         mfo->add (METER_FALLOFF_FASTER, _("faster"));
1649         mfo->add (METER_FALLOFF_FASTEST, _("fastest"));
1650
1651         add_option (S_("Visual|Interface"), mfo);
1652 }
1653
1654 void
1655 RCOptionEditor::parameter_changed (string const & p)
1656 {
1657         OptionEditor::parameter_changed (p);
1658
1659         if (p == "use-monitor-bus") {
1660                 bool const s = Config->get_use_monitor_bus ();
1661                 if (!s) {
1662                         /* we can't use this if we don't have a monitor bus */
1663                         Config->set_solo_control_is_listen_control (false);
1664                 }
1665                 _solo_control_is_listen_control->set_sensitive (s);
1666                 _listen_position->set_sensitive (s);
1667         }
1668 }