fixes for MIDI port setup; options editor now sets trace options correctly (still...
[ardour.git] / gtk2_ardour / option_editor.cc
1 /*
2     Copyright (C) 2001-2006 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 <pbd/whitespace.h>
22
23 #include <ardour/audio_library.h>
24 #include <ardour/session.h>
25 #include <ardour/audioengine.h>
26 #include <ardour/configuration.h>
27 #include <ardour/auditioner.h>
28 #include <ardour/destructive_filesource.h>
29 #include <ardour/crossfade.h>
30 #include <midi++/manager.h>
31 #include <gtkmm2ext/stop_signal.h>
32 #include <gtkmm2ext/utils.h>
33
34 #include "public_editor.h"
35 #include "mixer_ui.h"
36 #include "ardour_ui.h"
37 #include "io_selector.h"
38 #include "gain_meter.h"
39 #include "sfdb_ui.h"
40 #include "utils.h"
41 #include "editing.h"
42 #include "option_editor.h"
43
44 #include "i18n.h"
45
46 using namespace ARDOUR;
47 using namespace PBD;
48 using namespace Gtk;
49 using namespace Editing;
50 using namespace Gtkmm2ext;
51 using namespace std;
52
53 static vector<string> positional_sync_strings;
54
55 OptionEditor::OptionEditor (ARDOUR_UI& uip, PublicEditor& ed, Mixer_UI& mixui)
56         : Dialog ("option editor"),
57           ui (uip),
58           editor (ed),
59           mixer (mixui),
60
61           /* Paths */
62           path_table (11, 2),
63           sfdb_path_view(),
64
65           /* Fades */
66
67           short_xfade_adjustment (0, 1.0, 500.0, 5.0, 100.0),
68           short_xfade_slider (short_xfade_adjustment),
69           destructo_xfade_adjustment (1.0, 1.0, 500.0, 1.0, 100.0),
70           destructo_xfade_slider (destructo_xfade_adjustment),
71
72           /* Sync */
73
74           smpte_offset_clock (X_("SMPTEOffsetClock"), true, true),
75           smpte_offset_negative_button (_("SMPTE offset is negative")),
76
77           /* MIDI */
78
79           /* Click */
80
81           click_table (2, 3),
82           click_browse_button (_("Browse")),
83           click_emphasis_browse_button (_("Browse")),
84
85           /* kbd/mouse */
86
87           keyboard_mouse_table (3, 4),
88           delete_button_adjustment (3, 1, 5),
89           delete_button_spin (delete_button_adjustment),
90           edit_button_adjustment (3, 1, 5),
91           edit_button_spin (edit_button_adjustment)
92           
93 {
94         using namespace Notebook_Helpers;
95
96         click_io_selector = 0;
97         auditioner_io_selector = 0;
98         session = 0;
99
100         set_default_size (300, 300);
101         set_title (_("ardour: options editor"));
102         set_wmclass (_("ardour_option_editor"), "Ardour");
103
104         set_name ("OptionsWindow");
105         add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
106         
107         VBox *vbox = get_vbox();
108         set_border_width (3);
109
110         vbox->set_spacing (4);
111         vbox->pack_start(notebook);
112
113         signal_delete_event().connect (mem_fun(*this, &OptionEditor::wm_close));
114
115         notebook.set_show_tabs (true);
116         notebook.set_show_border (true);
117         notebook.set_name ("OptionsNotebook");
118
119         setup_sync_options();
120         setup_path_options();
121         setup_fade_options ();
122         setup_keyboard_options ();
123         setup_auditioner_editor ();
124
125         notebook.pages().push_back (TabElem (sync_packer, _("Sync")));
126         notebook.pages().push_back (TabElem (path_table, _("Paths/Files")));
127         notebook.pages().push_back (TabElem (keyboard_mouse_table, _("Kbd/Mouse")));
128         notebook.pages().push_back (TabElem (click_packer, _("Click")));
129         notebook.pages().push_back (TabElem (audition_packer, _("Audition")));
130         notebook.pages().push_back (TabElem (fade_packer, _("Layers & Fades")));
131
132         if (!MIDI::Manager::instance()->get_midi_ports().empty()) {
133                 setup_midi_options ();
134                 notebook.pages().push_back (TabElem (midi_packer, _("MIDI")));
135         }
136
137         set_session (0);
138         show_all_children();
139 }
140
141 void
142 OptionEditor::set_session (Session *s)
143 {
144         clear_click_editor ();
145         clear_auditioner_editor ();
146
147         click_path_entry.set_text ("");
148         click_emphasis_path_entry.set_text ("");
149         session_raid_entry.set_text ("");
150
151         click_path_entry.set_sensitive (false);
152         click_emphasis_path_entry.set_sensitive (false);
153         session_raid_entry.set_sensitive (false);
154
155         short_xfade_slider.set_sensitive (false);
156         smpte_offset_negative_button.set_sensitive (false);
157
158         smpte_offset_clock.set_session (s);
159
160         if ((session = s) == 0) {
161                 return;
162         }
163
164         click_path_entry.set_sensitive (true);
165         click_emphasis_path_entry.set_sensitive (true);
166         session_raid_entry.set_sensitive (true);
167         short_xfade_slider.set_sensitive (true);
168         smpte_offset_negative_button.set_sensitive (true);
169
170         smpte_offset_clock.set_session (s);
171         smpte_offset_clock.set (s->smpte_offset (), true);
172
173         smpte_offset_negative_button.set_active (session->smpte_offset_negative());
174
175         /* set up port assignments */
176
177         std::map<MIDI::Port*,vector<RadioButton*> >::iterator res;
178
179         if (session->mtc_port()) {
180                 if ((res = port_toggle_buttons.find (session->mtc_port())) != port_toggle_buttons.end()) {
181                         (*res).second[MtcIndex]->set_active (true);
182                 }
183         } 
184
185         if (session->mmc_port ()) {
186                 if ((res = port_toggle_buttons.find (session->mmc_port())) != port_toggle_buttons.end()) {
187                         (*res).second[MmcIndex]->set_active (true);
188                 } 
189         }
190
191         if (session->midi_port()) {
192                 if ((res = port_toggle_buttons.find (session->midi_port())) != port_toggle_buttons.end()) {
193                         (*res).second[MidiIndex]->set_active (true);
194                 }
195         }
196
197         setup_click_editor ();
198         connect_audition_editor ();
199
200         short_xfade_adjustment.set_value ((Crossfade::short_xfade_length() / (float) session->frame_rate()) * 1000.0);
201
202         add_session_paths ();
203 }
204
205 OptionEditor::~OptionEditor ()
206 {
207 }
208
209 void
210 OptionEditor::setup_path_options()
211 {
212         Gtk::Label* label;
213
214         path_table.set_homogeneous (false);
215         path_table.set_border_width (12);
216         path_table.set_row_spacings (5);
217
218         session_raid_entry.set_name ("OptionsEntry");
219
220         session_raid_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::raid_path_changed));
221
222         label = manage(new Label(_("session RAID path")));
223         label->set_name ("OptionsLabel");
224         path_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL);
225         path_table.attach (session_raid_entry, 1, 3, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
226
227         label = manage(new Label(_("Soundfile Search Paths")));
228         label->set_name("OptionsLabel");
229         path_table.attach(*label, 0, 1, 2, 3, FILL|EXPAND, FILL);
230         path_table.attach(sfdb_path_view, 1, 3, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
231
232         sfdb_path_view.set_paths(Library->get_paths());
233         sfdb_path_view.PathsUpdated.connect (mem_fun(*this, &OptionEditor::sfdb_paths_changed));
234
235         path_table.show_all();
236 }
237
238 void
239 OptionEditor::sfdb_paths_changed ()
240 {
241         Library->set_paths (sfdb_path_view.get_paths());
242 }
243
244 void
245 OptionEditor::add_session_paths ()
246 {
247         click_path_entry.set_sensitive (true);
248         click_emphasis_path_entry.set_sensitive (true);
249         session_raid_entry.set_sensitive (true);
250
251         if (Config->get_click_sound().empty()) {
252                 click_path_entry.set_text (_("internal"));
253         } else {
254                 click_path_entry.set_text (Config->get_click_sound());
255         }
256
257         if (Config->get_click_emphasis_sound().empty()) {
258                 click_emphasis_path_entry.set_text (_("internal"));
259         } else {
260                 click_emphasis_path_entry.set_text (Config->get_click_emphasis_sound());
261         }
262
263         session_raid_entry.set_text(session->raid_path());
264 }
265
266 void
267 OptionEditor::setup_fade_options ()
268 {
269         Gtk::HBox* hbox;
270         
271         Label* label = manage (new Label (_("Short crossfade length (msecs)")));
272         label->set_name ("OptionsLabel");
273         
274         hbox = manage (new HBox);
275         hbox->set_border_width (5);
276         hbox->set_spacing (10);
277         hbox->pack_start (*label, false, false);
278         hbox->pack_start (short_xfade_slider, true, true);
279         fade_packer.pack_start (*hbox, false, false);
280
281         short_xfade_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::short_xfade_adjustment_changed));
282
283         label = manage (new Label (_("Destructive crossfade length (msecs)")));
284         label->set_name ("OptionsLabel");
285         
286         hbox = manage (new HBox);
287         hbox->set_border_width (5);
288         hbox->set_spacing (10);
289         hbox->pack_start (*label, false, false);
290         hbox->pack_start (destructo_xfade_slider, true, true);
291         fade_packer.pack_start (*hbox, false, false);
292         
293         destructo_xfade_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::destructo_xfade_adjustment_changed));
294
295         short_xfade_slider.set_update_policy (UPDATE_DISCONTINUOUS);
296         destructo_xfade_slider.set_update_policy (UPDATE_DISCONTINUOUS);
297
298         destructo_xfade_adjustment.set_value (Config->get_destructive_xfade_msecs());
299
300         fade_packer.show_all ();
301 }
302
303 void
304 OptionEditor::short_xfade_adjustment_changed ()
305 {
306         if (session) {
307                 float val = short_xfade_adjustment.get_value();
308                 
309                 /* val is in msecs */
310                 
311                 Crossfade::set_short_xfade_length ((nframes_t) floor (session->frame_rate() * (val / 1000.0)));
312         }
313 }
314
315 void
316 OptionEditor::destructo_xfade_adjustment_changed ()
317 {
318         float val = destructo_xfade_adjustment.get_value();
319
320         /* val is in msecs */
321
322         
323         Config->set_destructive_xfade_msecs ((uint32_t) floor (val));
324
325         if (session) {
326                 SndFileSource::setup_standard_crossfades (session->frame_rate());
327         } 
328 }
329
330 void
331 OptionEditor::setup_sync_options ()
332 {
333         HBox* hbox;
334         vector<string> dumb;
335
336         smpte_offset_clock.set_mode (AudioClock::SMPTE);
337         smpte_offset_clock.ValueChanged.connect (mem_fun(*this, &OptionEditor::smpte_offset_chosen));
338         
339         smpte_offset_negative_button.set_name ("OptionEditorToggleButton");
340
341         smpte_offset_negative_button.unset_flags (Gtk::CAN_FOCUS);
342
343         Label *smpte_offset_label = manage (new Label (_("SMPTE Offset")));
344         smpte_offset_label->set_name("OptionsLabel");
345         
346         hbox = manage (new HBox);
347         hbox->set_border_width (5);
348         hbox->set_spacing (10);
349         hbox->pack_start (*smpte_offset_label, false, false);
350         hbox->pack_start (smpte_offset_clock, false, false);
351         hbox->pack_start (smpte_offset_negative_button, false, false);
352
353         sync_packer.pack_start (*hbox, false, false);
354
355         smpte_offset_negative_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::smpte_offset_negative_clicked));
356 }
357
358 void
359 OptionEditor::smpte_offset_negative_clicked ()
360 {
361         if (session) {
362                 session->set_smpte_offset_negative (smpte_offset_negative_button.get_active());
363         }
364 }
365
366 void
367 OptionEditor::smpte_offset_chosen()
368 {
369         if (session) {
370                 nframes_t frames = smpte_offset_clock.current_duration();
371                 session->set_smpte_offset (frames);
372         }
373 }
374
375
376 void
377 OptionEditor::setup_midi_options ()
378 {
379         HBox* hbox;
380         MIDI::Manager::PortMap::const_iterator i;
381         const MIDI::Manager::PortMap& ports = MIDI::Manager::instance()->get_midi_ports();
382         int n;
383         ToggleButton* tb;
384         RadioButton* rb;
385
386         Gtk::Table* table = manage (new Table (ports.size() + 4, 9));
387
388         table->set_row_spacings (6);
389         table->set_col_spacings (10);
390
391         table->attach (*(manage (new Label (X_("Port")))), 0, 1, 0, 1);
392         table->attach (*(manage (new Label (X_("Offline")))), 1, 2, 0, 1);
393         table->attach (*(manage (new Label (X_("Trace\nInput")))), 2, 3, 0, 1);
394         table->attach (*(manage (new Label (X_("Trace\nOutput")))), 3, 4, 0, 1);
395         table->attach (*(manage (new Label (X_("MTC")))), 4, 5, 0, 1);
396         table->attach (*(manage (new Label (X_("MMC")))), 6, 7, 0, 1);
397         table->attach (*(manage (new Label (X_("MIDI Parameter\nControl")))), 8, 9, 0, 1);
398
399         table->attach (*(manage (new HSeparator())), 0, 9, 1, 2);
400         table->attach (*(manage (new VSeparator())), 5, 6, 0, 8);
401         table->attach (*(manage (new VSeparator())), 7, 8, 0, 8);
402         
403         for (n = 0, i = ports.begin(); i != ports.end(); ++n, ++i) {
404
405                 pair<MIDI::Port*,vector<RadioButton*> > newpair;
406
407                 newpair.first = i->second;
408
409                 table->attach (*(manage (new Label (i->first))), 0, 1, n+2, n+3,FILL|EXPAND, FILL );
410                 tb = manage (new ToggleButton (_("online")));
411                 tb->set_name ("OptionEditorToggleButton");
412
413                 /* remember, we have to handle the i18n case where the relative
414                    lengths of the strings in language N is different than in english.
415                 */
416
417                 if (strlen (_("offline")) > strlen (_("online"))) {
418                         set_size_request_to_display_given_text (*tb, _("offline"), 15, 12);
419                 } else {
420                         set_size_request_to_display_given_text (*tb, _("online"), 15, 12);
421                 }
422
423                 tb->set_active (!(*i).second->input()->offline());
424                 tb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::port_online_toggled), (*i).second, tb));
425                 (*i).second->input()->OfflineStatusChanged.connect (bind (mem_fun(*this, &OptionEditor::map_port_online), (*i).second, tb));
426                 table->attach (*tb, 1, 2, n+2, n+3, FILL|EXPAND, FILL);
427
428                 tb = manage (new ToggleButton ());
429                 tb->set_name ("OptionEditorToggleButton");
430                 tb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::port_trace_in_toggled), (*i).second, tb));
431                 tb->set_size_request (10, 10);
432                 table->attach (*tb, 2, 3, n+2, n+3, FILL|EXPAND, FILL);
433
434                 tb = manage (new ToggleButton ());
435                 tb->set_name ("OptionEditorToggleButton");
436                 tb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::port_trace_out_toggled), (*i).second, tb));
437                 tb->set_size_request (10, 10);
438                 table->attach (*tb, 3, 4, n+2, n+3, FILL|EXPAND, FILL);
439
440                 rb = manage (new RadioButton ());
441                 newpair.second.push_back (rb);
442                 rb->set_name ("OptionEditorToggleButton");
443                 if (n == 0) {
444                         mtc_button_group = rb->get_group();
445                 } else {
446                         rb->set_group (mtc_button_group);
447
448                 }
449                 table->attach (*rb, 4, 5, n+2, n+3, FILL|EXPAND, FILL);
450                 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::mtc_port_chosen), (*i).second, rb));
451
452                 if (Config->get_mtc_port_name() == i->first) {
453                         rb->set_active (true);
454                 }
455                 
456                 rb = manage (new RadioButton ());
457                 newpair.second.push_back (rb);
458                 rb->set_name ("OptionEditorToggleButton");
459                 if (n == 0) {
460                         mmc_button_group = rb->get_group();
461                 } else {
462                         rb->set_group (mmc_button_group);
463                 }
464                 table->attach (*rb, 6, 7, n+2, n+3, FILL|EXPAND, FILL);
465                 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::mmc_port_chosen), (*i).second, rb));
466
467                 if (Config->get_mmc_port_name() == i->first) {
468                         rb->set_active (true);
469                 }
470
471                 rb = manage (new RadioButton ());
472                 newpair.second.push_back (rb);
473                 rb->set_name ("OptionEditorToggleButton");
474                 if (n == 0) {
475                         midi_button_group = rb->get_group();
476                 } else {
477                         rb->set_group (midi_button_group);
478                 }
479                 table->attach (*rb, 8, 9, n+2, n+3, FILL|EXPAND, FILL);
480                 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::midi_port_chosen), (*i).second, rb));
481
482                 if (Config->get_midi_port_name() == i->first) {
483                         rb->set_active (true);
484                 }
485                 
486                 port_toggle_buttons.insert (newpair);
487         }
488
489         table->show_all ();
490
491         hbox = manage (new HBox);
492         hbox->set_border_width (6);
493         hbox->pack_start (*table, true, false);
494         midi_packer.pack_start (*hbox, false, false);
495 }
496
497 void
498 OptionEditor::mtc_port_chosen (MIDI::Port *port, Gtk::RadioButton* rb) 
499 {
500         if (session) {
501                 if (rb->get_active()) {
502                         cerr << "Activating MTC port " << port->name() << endl;
503                         if (port) {
504                                 session->set_mtc_port (port->name());
505                                 Config->set_mtc_port_name (port->name());
506                         } else {
507                                 session->set_mtc_port ("");
508                         }
509                         rb->set_active (true);
510                 }
511         }
512 }
513
514 void
515 OptionEditor::mmc_port_chosen (MIDI::Port* port, Gtk::RadioButton* rb)
516 {
517         if (session) {
518                 if (rb->get_active()) {
519                         cerr << "Activating MMC port " << port->name() << endl;
520                         if (port) {
521                                 session->set_mmc_port (port->name());
522                                 Config->set_mtc_port_name (port->name());
523                         } else {
524                                 session->set_mmc_port ("");
525                         }
526                         rb->set_active (true);
527                 }
528         }
529 }
530
531 void
532 OptionEditor::midi_port_chosen (MIDI::Port* port, Gtk::RadioButton* rb)
533 {
534         if (session) {
535                 if (rb->get_active()) {
536                         cerr << "Activating MIDI port " << port->name() << endl;
537                         if (port) {
538                                 session->set_midi_port (port->name());
539                                 Config->set_midi_port_name (port->name());
540                         } else {
541                                 session->set_midi_port ("");
542                         }
543                         rb->set_active (true);
544                 }
545         }
546 }
547
548 void
549 OptionEditor::port_online_toggled (MIDI::Port* port, ToggleButton* tb)
550 {
551         bool wanted = tb->get_active();
552         
553         if (wanted != port->input()->offline()) {
554                 port->input()->set_offline (wanted);
555         } 
556 }
557
558 void
559 OptionEditor::map_port_online (MIDI::Port* port, ToggleButton* tb)
560 {
561         if (port->input()->offline()) {
562                 tb->set_label (_("offline"));
563                 tb->set_active (false);
564         } else {
565                 tb->set_label (_("online"));
566                 tb->set_active (true);
567         }
568 }
569
570 void
571 OptionEditor::port_trace_in_toggled (MIDI::Port* port, ToggleButton* tb)
572 {
573         bool trace = tb->get_active();
574
575         if (port->input()->tracing() != trace) {
576                 port->output()->trace (trace, &cerr, string (port->name()) + string (" input: "));
577         }
578 }
579
580 void
581 OptionEditor::port_trace_out_toggled (MIDI::Port* port, ToggleButton* tb)
582 {
583         bool trace = tb->get_active();
584
585         if (port->output()->tracing() != trace) {
586                 port->output()->trace (trace, &cerr, string (port->name()) + string (" output: "));
587         }
588 }
589
590 void
591 OptionEditor::save ()
592 {
593         /* XXX a bit odd that we save the entire session state here */
594
595         ui.save_state ("");
596 }
597
598 gint
599 OptionEditor::wm_close (GdkEventAny *ev)
600 {
601         save ();
602         hide ();
603         return TRUE;
604 }
605
606 void
607 OptionEditor::raid_path_changed ()
608 {
609         if (session) {
610                 Config->set_raid_path (session_raid_entry.get_text());
611         }
612 }
613
614 void
615 OptionEditor::click_browse_clicked ()
616 {
617         SoundFileChooser sfdb (_("Choose Click"), session);
618         
619         int result = sfdb.run ();
620
621         if (result == Gtk::RESPONSE_OK) {
622                 click_chosen(sfdb.get_filename());
623         }
624 }
625
626 void
627 OptionEditor::click_chosen (const string & path)
628 {
629         click_path_entry.set_text (path);
630         click_sound_changed ();
631 }
632
633 void
634 OptionEditor::click_emphasis_browse_clicked ()
635 {
636         SoundFileChooser sfdb (_("Choose Click Emphasis"), session);
637
638         int result = sfdb.run ();
639
640         if (result == Gtk::RESPONSE_OK) {
641                 click_emphasis_chosen (sfdb.get_filename());
642         }
643 }
644
645 void
646 OptionEditor::click_emphasis_chosen (const string & path)
647 {       
648         click_emphasis_path_entry.set_text (path);
649         click_emphasis_sound_changed ();
650 }
651
652 void
653 OptionEditor::click_sound_changed ()
654 {
655         if (session) {
656                 string path = click_path_entry.get_text();
657
658                 if (path == Config->get_click_sound()) {
659                         return;
660                 }
661
662                 if (path.empty()) {
663
664                         Config->set_click_sound ("");
665
666                 } else {
667
668                         strip_whitespace_edges (path);
669                         
670                         if (path == _("internal")) {
671                                 Config->set_click_sound ("");
672                         } else {
673                                 Config->set_click_sound (path);
674                         }
675                 }
676         }
677 }
678
679 void
680 OptionEditor::click_emphasis_sound_changed ()
681 {
682         if (session) {
683                 string path = click_emphasis_path_entry.get_text();
684
685                 if (path == Config->get_click_emphasis_sound()) {
686                         return;
687                 }
688
689                 if (path.empty()) {
690
691                         Config->set_click_emphasis_sound ("");
692
693                 } else {
694
695                         strip_whitespace_edges (path);
696
697                         if (path == _("internal")) {
698                                 Config->set_click_emphasis_sound ("");
699                         } else {
700                                 Config->set_click_emphasis_sound (path);
701                         }
702                 }
703         }
704 }
705
706 void
707 OptionEditor::clear_click_editor ()
708 {
709         if (click_io_selector) {
710                 click_packer.remove (*click_io_selector);
711                 click_packer.remove (*click_gpm);
712                 delete click_io_selector;
713                 delete click_gpm;
714                 click_io_selector = 0;
715                 click_gpm = 0;
716         }
717 }
718
719 void
720 OptionEditor::setup_click_editor ()
721 {
722         Label* label;
723         HBox* hpacker = manage (new HBox);
724
725         click_path_entry.set_sensitive (true);
726         click_emphasis_path_entry.set_sensitive (true);
727
728         click_path_entry.set_name ("OptionsEntry");
729         click_emphasis_path_entry.set_name ("OptionsEntry");
730         
731         click_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_sound_changed));
732         click_emphasis_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_emphasis_sound_changed));
733
734         click_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_sound_changed));
735         click_emphasis_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_emphasis_sound_changed));
736
737         click_browse_button.set_name ("EditorGTKButton");
738         click_emphasis_browse_button.set_name ("EditorGTKButton");
739         click_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_browse_clicked));
740         click_emphasis_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_emphasis_browse_clicked));
741
742         click_packer.set_border_width (12);
743         click_packer.set_spacing (5);
744
745         click_io_selector = new IOSelector (*session, session->click_io(), false);
746         click_gpm = new GainMeter (session->click_io(), *session);
747
748         click_table.set_col_spacings (10);
749         
750         label = manage(new Label(_("Click audio file")));
751         label->set_name ("OptionsLabel");
752         click_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL);
753         click_table.attach (click_path_entry, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
754         click_table.attach (click_browse_button, 2, 3, 0, 1, FILL|EXPAND, FILL);
755         
756         label = manage(new Label(_("Click emphasis audiofile")));
757         label->set_name ("OptionsLabel");
758         click_table.attach (*label, 0, 1, 1, 2, FILL|EXPAND, FILL);
759         click_table.attach (click_emphasis_path_entry, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
760         click_table.attach (click_emphasis_browse_button, 2, 3, 1, 2, FILL|EXPAND, FILL);
761
762         hpacker->set_spacing (10);
763         hpacker->pack_start (*click_io_selector, false, false);
764         hpacker->pack_start (*click_gpm, false, false);
765
766         click_packer.pack_start (click_table, false, false);
767         click_packer.pack_start (*hpacker, false, false);
768
769         click_packer.show_all ();
770 }
771
772 void
773 OptionEditor::clear_auditioner_editor ()
774 {
775         if (auditioner_io_selector) {
776                 audition_hpacker.remove (*auditioner_io_selector);
777                 audition_hpacker.remove (*auditioner_gpm);
778                 delete auditioner_io_selector;
779                 delete auditioner_gpm;
780                 auditioner_io_selector = 0;
781                 auditioner_gpm = 0;
782         }
783 }
784
785 void
786 OptionEditor::setup_auditioner_editor ()
787 {
788         audition_packer.set_border_width (12);
789         audition_packer.set_spacing (5);
790         audition_hpacker.set_spacing (10);
791
792         audition_label.set_name ("OptionEditorAuditionerLabel");
793         audition_label.set_text (_("The auditioner is a dedicated mixer strip used\n"
794                                    "for listening to specific regions outside the context\n"
795                                    "of the overall mix. It can be connected just like any\n"
796                                    "other mixer strip."));
797         
798         audition_packer.pack_start (audition_label, false, false, 10);
799         audition_packer.pack_start (audition_hpacker, false, false);
800 }
801
802 void
803 OptionEditor::connect_audition_editor ()
804 {
805         auditioner_io_selector = new IOSelector (*session, session->the_auditioner(), false);
806         auditioner_gpm = new GainMeter (session->the_auditioner(), *session);
807
808         audition_hpacker.pack_start (*auditioner_io_selector, false, false);
809         audition_hpacker.pack_start (*auditioner_gpm, false, false);
810
811         auditioner_io_selector->show_all ();
812         auditioner_gpm->show_all ();
813 }
814
815 bool
816 OptionEditor::focus_out_event_handler (GdkEventFocus* ev, void (OptionEditor::*pmf)()) 
817 {
818         (this->*pmf)();
819         return false;
820 }
821
822 static const struct {
823     const char *name;
824     guint   modifier;
825 } modifiers[] = {
826         { "Shift", GDK_SHIFT_MASK },
827         { "Control", GDK_CONTROL_MASK },
828         { "Alt (Mod1)", GDK_MOD1_MASK },
829         { "Control-Shift", GDK_CONTROL_MASK|GDK_SHIFT_MASK },
830         { "Control-Alt", GDK_CONTROL_MASK|GDK_MOD1_MASK },
831         { "Shift-Alt", GDK_SHIFT_MASK|GDK_MOD1_MASK },
832         { "Control-Shift-Alt", GDK_CONTROL_MASK|GDK_SHIFT_MASK|GDK_MOD1_MASK },
833         { "Mod2", GDK_MOD2_MASK },
834         { "Mod3", GDK_MOD3_MASK },
835         { "Mod4", GDK_MOD4_MASK },
836         { "Mod5", GDK_MOD5_MASK },
837         { 0, 0 }
838 };
839
840 void
841 OptionEditor::setup_keyboard_options ()
842 {
843         vector<string> dumb;
844         Label* label;
845
846         keyboard_mouse_table.set_border_width (12);
847         keyboard_mouse_table.set_row_spacings (5);
848         keyboard_mouse_table.set_col_spacings (5);
849
850         /* internationalize and prepare for use with combos */
851
852         for (int i = 0; modifiers[i].name; ++i) {
853                 dumb.push_back (_(modifiers[i].name));
854         }
855
856         set_popdown_strings (edit_modifier_combo, dumb);
857         edit_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::edit_modifier_chosen));
858
859         for (int x = 0; modifiers[x].name; ++x) {
860                 if (modifiers[x].modifier == Keyboard::edit_modifier ()) {
861                         edit_modifier_combo.set_active_text (_(modifiers[x].name));
862                         break;
863                 }
864         }
865
866         label = manage (new Label (_("Edit using")));
867         label->set_name ("OptionsLabel");
868         label->set_alignment (1.0, 0.5);
869                 
870         keyboard_mouse_table.attach (*label, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
871         keyboard_mouse_table.attach (edit_modifier_combo, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
872
873         label = manage (new Label (_("+ button")));
874         label->set_name ("OptionsLabel");
875         
876         keyboard_mouse_table.attach (*label, 3, 4, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
877         keyboard_mouse_table.attach (edit_button_spin, 4, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
878
879         edit_button_spin.set_name ("OptionsEntry");
880         edit_button_adjustment.set_value (Keyboard::edit_button());
881         edit_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::edit_button_changed));
882
883         set_popdown_strings (delete_modifier_combo, dumb);
884         delete_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::delete_modifier_chosen));
885
886         for (int x = 0; modifiers[x].name; ++x) {
887                 if (modifiers[x].modifier == Keyboard::delete_modifier ()) {
888                         delete_modifier_combo.set_active_text (_(modifiers[x].name));
889                         break;
890                 }
891         }
892
893         label = manage (new Label (_("Delete using")));
894         label->set_name ("OptionsLabel");
895         label->set_alignment (1.0, 0.5);
896                 
897         keyboard_mouse_table.attach (*label, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
898         keyboard_mouse_table.attach (delete_modifier_combo, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
899
900         label = manage (new Label (_("+ button")));
901         label->set_name ("OptionsLabel");
902
903         keyboard_mouse_table.attach (*label, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
904         keyboard_mouse_table.attach (delete_button_spin, 4, 5, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
905
906         delete_button_spin.set_name ("OptionsEntry");
907         delete_button_adjustment.set_value (Keyboard::delete_button());
908         delete_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::delete_button_changed));
909
910         set_popdown_strings (snap_modifier_combo, dumb);
911         snap_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::snap_modifier_chosen));
912         
913         for (int x = 0; modifiers[x].name; ++x) {
914                 if (modifiers[x].modifier == (guint) Keyboard::snap_modifier ()) {
915                         snap_modifier_combo.set_active_text (_(modifiers[x].name));
916                         break;
917                 }
918         }
919
920         label = manage (new Label (_("Ignore snap using")));
921         label->set_name ("OptionsLabel");
922         label->set_alignment (1.0, 0.5);
923         
924         keyboard_mouse_table.attach (*label, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
925         keyboard_mouse_table.attach (snap_modifier_combo, 1, 2, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
926 }
927
928 void
929 OptionEditor::edit_modifier_chosen ()
930 {
931         string txt;
932         
933         txt = edit_modifier_combo.get_active_text();
934
935         for (int i = 0; modifiers[i].name; ++i) {
936                 if (txt == _(modifiers[i].name)) {
937                         Keyboard::set_edit_modifier (modifiers[i].modifier);
938                         break;
939                 }
940         }
941 }
942
943 void
944 OptionEditor::delete_modifier_chosen ()
945 {
946         string txt;
947         
948         txt = delete_modifier_combo.get_active_text();
949
950         for (int i = 0; modifiers[i].name; ++i) {
951                 if (txt == _(modifiers[i].name)) {
952                         Keyboard::set_delete_modifier (modifiers[i].modifier);
953                         break;
954                 }
955         }
956 }
957
958 void
959 OptionEditor::snap_modifier_chosen ()
960 {
961         string txt;
962         
963         txt = snap_modifier_combo.get_active_text();
964
965         for (int i = 0; modifiers[i].name; ++i) {
966                 if (txt == _(modifiers[i].name)) {
967                         Keyboard::set_snap_modifier (modifiers[i].modifier);
968                         break;
969                 }
970         }
971 }
972
973 void
974 OptionEditor::delete_button_changed ()
975 {
976         Keyboard::set_delete_button ((guint) delete_button_adjustment.get_value());
977 }
978
979 void
980 OptionEditor::edit_button_changed ()
981 {
982         Keyboard::set_edit_button ((guint) edit_button_adjustment.get_value());
983 }
984
985 void
986 OptionEditor::fixup_combo_size (Gtk::ComboBoxText& combo, vector<string>& strings)
987 {
988         /* find the widest string */
989
990         string::size_type maxlen = 0;
991         string maxstring;
992
993         for (vector<string>::iterator i = strings.begin(); i != strings.end(); ++i) {
994                 string::size_type l;
995
996                 if ((l = (*i).length()) > maxlen) {
997                         maxlen = l;
998                         maxstring = *i;
999                 }
1000         }
1001
1002         /* try to include ascenders and descenders */
1003
1004         if (maxstring.length() > 2) {
1005                 maxstring[0] = 'g';
1006                 maxstring[1] = 'l';
1007         }
1008
1009         const guint32 FUDGE = 10; // Combo's are stupid - they steal space from the entry for the button
1010
1011         set_size_request_to_display_given_text (combo, maxstring.c_str(), 10 + FUDGE, 10);
1012 }
1013