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