add (back) PlaySelection to menus
[ardour2.git] / gtk2_ardour / option_editor.cc
blob1b9c326f6b41cc9a3b3d6689f248089791ed25f3
1 /*
2 Copyright (C) 2001-2006 Paul Davis
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.
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.
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.
19 #include <pango/pangoft2.h> // for fontmap resolution control for GnomeCanvas
20 #include <pango/pangocairo.h> // for fontmap resolution control for GnomeCanvas
22 #include <pbd/whitespace.h>
24 #include <ardour/ardour.h>
25 #include <ardour/session.h>
26 #include <ardour/audioengine.h>
27 #include <ardour/configuration.h>
28 #include <ardour/auditioner.h>
29 #include <ardour/sndfilesource.h>
30 #include <ardour/crossfade.h>
31 #include <ardour/profile.h>
32 #include <midi++/manager.h>
33 #include <midi++/factory.h>
34 #include <gtkmm2ext/stop_signal.h>
35 #include <gtkmm2ext/utils.h>
36 #include <gtkmm2ext/window_title.h>
38 #include "public_editor.h"
39 #include "keyboard.h"
40 #include "mixer_ui.h"
41 #include "ardour_ui.h"
42 #include "io_selector.h"
43 #include "gain_meter.h"
44 #include "sfdb_ui.h"
45 #include "utils.h"
46 #include "editing.h"
47 #include "option_editor.h"
48 #include "midi_port_dialog.h"
49 #include "gui_thread.h"
50 #include "utils.h"
52 #include "i18n.h"
54 using namespace ARDOUR;
55 using namespace PBD;
56 using namespace Gtk;
57 using namespace Editing;
58 using namespace Gtkmm2ext;
59 using namespace std;
61 static vector<string> positional_sync_strings;
63 OptionEditor::OptionEditor (ARDOUR_UI& uip, PublicEditor& ed, Mixer_UI& mixui)
64 : ArdourDialog ("options editor", false),
65 ui (uip),
66 editor (ed),
67 mixer (mixui),
69 /* Paths */
70 path_table (11, 2),
72 /* misc */
74 short_xfade_adjustment (0, 1.0, 500.0, 5.0, 100.0),
75 short_xfade_slider (short_xfade_adjustment),
76 destructo_xfade_adjustment (1.0, 1.0, 500.0, 1.0, 100.0),
77 destructo_xfade_slider (destructo_xfade_adjustment),
78 history_depth (20, -1, 100, 1.0, 10.0),
79 saved_history_depth (20, 0, 100, 1.0, 10.0),
80 history_depth_spinner (history_depth),
81 saved_history_depth_spinner (saved_history_depth),
82 limit_history_button (_("Limit undo history")),
83 save_history_button (_("Save undo history")),
85 /* Sync */
87 smpte_offset_clock (X_("smpteoffset"), false, X_("SMPTEOffsetClock"), true, true),
88 smpte_offset_negative_button (_("SMPTE offset is negative")),
89 synced_timecode_button (_("Timecode source is sample-clock synced")),
91 /* MIDI */
93 midi_port_table (4, 11),
94 mmc_receive_device_id_adjustment (0.0, 0.0, (double) 0x7f, 1.0, 16.0),
95 mmc_receive_device_id_spinner (mmc_receive_device_id_adjustment),
96 mmc_send_device_id_adjustment (0.0, 0.0, (double) 0x7f, 1.0, 16.0),
97 mmc_send_device_id_spinner (mmc_send_device_id_adjustment),
98 add_midi_port_button (_("Add new MIDI port")),
99 initial_program_change_adjustment (0.0, -1.0, (double) 0x7f, 1.0, 16.0),
100 initial_program_change_spinner (initial_program_change_adjustment),
102 /* Click */
104 click_table (2, 3),
105 click_browse_button (_("Browse")),
106 click_emphasis_browse_button (_("Browse")),
108 /* kbd/mouse */
110 keyboard_mouse_table (4, 4),
111 delete_button_adjustment (3, 1, 5),
112 delete_button_spin (delete_button_adjustment),
113 edit_button_adjustment (3, 1, 5),
114 edit_button_spin (edit_button_adjustment)
117 using namespace Notebook_Helpers;
119 first_click_setup = true;
120 click_io_selector = 0;
121 auditioner_io_selector = 0;
122 session = 0;
124 set_title(_("Preferences"));
126 set_default_size (300, 300);
127 set_wmclass (X_("ardour_preferences"), "Ardour");
129 set_name ("Preferences");
130 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
132 VBox *vbox = get_vbox();
133 set_border_width (3);
135 vbox->set_spacing (4);
136 vbox->pack_start(notebook);
138 signal_delete_event().connect (mem_fun(*this, &OptionEditor::wm_close));
140 notebook.set_show_tabs (true);
141 notebook.set_show_border (true);
142 notebook.set_name ("OptionsNotebook");
144 setup_sync_options();
145 setup_path_options();
146 setup_misc_options ();
147 setup_keyboard_options ();
148 setup_auditioner_editor ();
150 if (!Profile->get_sae()) {
151 notebook.pages().push_back (TabElem (sync_packer, _("Sync")));
152 notebook.pages().push_back (TabElem (path_table, _("Paths/Files")));
153 notebook.pages().push_back (TabElem (keyboard_mouse_table, _("Kbd/Mouse")));
155 notebook.pages().push_back (TabElem (click_packer, _("Click")));
156 notebook.pages().push_back (TabElem (audition_packer, _("Audition")));
157 notebook.pages().push_back (TabElem (misc_packer, _("Misc")));
159 setup_midi_options ();
160 notebook.pages().push_back (TabElem (midi_packer, _("MIDI")));
162 set_session (0);
163 show_all_children();
165 Config->map_parameters (mem_fun (*this, &OptionEditor::parameter_changed));
166 Config->ParameterChanged.connect (mem_fun (*this, &OptionEditor::parameter_changed));
169 void
170 OptionEditor::set_session (Session *s)
172 clear_click_editor ();
173 clear_auditioner_editor ();
175 click_path_entry.set_text ("");
176 click_emphasis_path_entry.set_text ("");
177 session_raid_entry.set_text ("");
179 click_path_entry.set_sensitive (false);
180 click_emphasis_path_entry.set_sensitive (false);
181 session_raid_entry.set_sensitive (false);
183 short_xfade_slider.set_sensitive (false);
184 smpte_offset_negative_button.set_sensitive (false);
186 smpte_offset_clock.set_session (s);
188 if ((session = s) == 0) {
189 return;
192 click_path_entry.set_sensitive (true);
193 click_emphasis_path_entry.set_sensitive (true);
194 session_raid_entry.set_sensitive (true);
195 short_xfade_slider.set_sensitive (true);
196 smpte_offset_negative_button.set_sensitive (true);
198 smpte_offset_clock.set_session (s);
199 smpte_offset_clock.set (s->smpte_offset (), true);
201 smpte_offset_negative_button.set_active (session->smpte_offset_negative());
203 redisplay_midi_ports ();
205 setup_click_editor ();
206 connect_audition_editor ();
208 short_xfade_adjustment.set_value ((Crossfade::short_xfade_length() / (float) session->frame_rate()) * 1000.0);
210 add_session_paths ();
213 OptionEditor::~OptionEditor ()
217 void
218 OptionEditor::setup_path_options()
220 Gtk::Label* label;
222 path_table.set_homogeneous (false);
223 path_table.set_border_width (12);
224 path_table.set_row_spacings (5);
226 session_raid_entry.set_name ("OptionsEntry");
228 session_raid_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::raid_path_changed));
230 label = manage(new Label(_("session RAID path")));
231 label->set_name ("OptionsLabel");
232 path_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL);
233 path_table.attach (session_raid_entry, 1, 3, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
235 path_table.show_all();
238 void
239 OptionEditor::add_session_paths ()
241 click_path_entry.set_sensitive (true);
242 click_emphasis_path_entry.set_sensitive (true);
243 session_raid_entry.set_sensitive (true);
245 if (Config->get_click_sound().empty()) {
246 click_path_entry.set_text (_("internal"));
247 } else {
248 click_path_entry.set_text (Config->get_click_sound());
251 if (Config->get_click_emphasis_sound().empty()) {
252 click_emphasis_path_entry.set_text (_("internal"));
253 } else {
254 click_emphasis_path_entry.set_text (Config->get_click_emphasis_sound());
257 session_raid_entry.set_text(session->raid_path());
260 static void
261 font_scale_changed (Gtk::Adjustment* adj)
263 Config->set_font_scale((long)floor (adj->get_value() * 1024));
264 reset_dpi();
267 void
268 OptionEditor::setup_misc_options ()
270 Gtk::HBox* hbox;
271 Label* label;
273 #ifndef GTKOSX
274 /* font scaling does nothing with GDK/Quartz */
276 Gtk::Adjustment* dpi_adj = new Gtk::Adjustment ((double)Config->get_font_scale() / 1024, 50, 250, 1, 10);
277 Gtk::HScale * dpi_range = new Gtk::HScale (*dpi_adj);
279 label = manage (new Label (_("Font Scaling")));
280 label->set_name ("OptionsLabel");
282 dpi_range->set_update_policy (Gtk::UPDATE_DISCONTINUOUS);
283 dpi_adj->signal_value_changed().connect (bind (sigc::ptr_fun (font_scale_changed), dpi_adj));
285 hbox = manage (new HBox);
286 hbox->set_border_width (5);
287 hbox->set_spacing (10);
288 hbox->pack_start (*label, false, false);
289 hbox->pack_start (*dpi_range, true, true);
290 misc_packer.pack_start (*hbox, false, false);
291 #endif
293 label = manage (new Label (_("Short crossfade length (msecs)")));
294 label->set_name ("OptionsLabel");
296 hbox = manage (new HBox);
297 hbox->set_border_width (5);
298 hbox->set_spacing (10);
299 hbox->pack_start (*label, false, false);
300 hbox->pack_start (short_xfade_slider, true, true);
301 misc_packer.pack_start (*hbox, false, false);
303 short_xfade_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::short_xfade_adjustment_changed));
305 label = manage (new Label (_("Destructive crossfade length (msecs)")));
306 label->set_name ("OptionsLabel");
308 hbox = manage (new HBox);
309 hbox->set_border_width (5);
310 hbox->set_spacing (10);
311 hbox->pack_start (*label, false, false);
312 hbox->pack_start (destructo_xfade_slider, true, true);
313 misc_packer.pack_start (*hbox, false, false);
316 destructo_xfade_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::destructo_xfade_adjustment_changed));
318 hbox = manage (new HBox);
319 hbox->set_border_width (5);
320 hbox->set_spacing (10);
321 hbox->pack_start (limit_history_button, false, false);
322 misc_packer.pack_start (*hbox, false, false);
324 label = manage (new Label (_("History depth (commands)")));
325 label->set_name ("OptionsLabel");
327 hbox = manage (new HBox);
328 hbox->set_border_width (5);
329 hbox->set_spacing (10);
330 hbox->pack_start (*label, false, false);
331 hbox->pack_start (history_depth_spinner, false, false);
332 misc_packer.pack_start (*hbox, false, false);
334 history_depth.signal_value_changed().connect (mem_fun (*this, &OptionEditor::history_depth_changed));
335 saved_history_depth.signal_value_changed().connect (mem_fun (*this, &OptionEditor::saved_history_depth_changed));
336 save_history_button.signal_toggled().connect (mem_fun (*this, &OptionEditor::save_history_toggled));
337 limit_history_button.signal_toggled().connect (mem_fun (*this, &OptionEditor::limit_history_toggled));
339 hbox = manage (new HBox);
340 hbox->set_border_width (5);
341 hbox->set_spacing (10);
342 hbox->pack_start (save_history_button, false, false);
343 misc_packer.pack_start (*hbox, false, false);
345 label = manage (new Label (_("Saved history depth (commands)")));
346 label->set_name ("OptionsLabel");
348 hbox = manage (new HBox);
349 hbox->set_border_width (5);
350 hbox->set_spacing (10);
351 hbox->pack_start (*label, false, false);
352 hbox->pack_start (saved_history_depth_spinner, false, false);
353 misc_packer.pack_start (*hbox, false, false);
355 short_xfade_slider.set_update_policy (UPDATE_DISCONTINUOUS);
356 destructo_xfade_slider.set_update_policy (UPDATE_DISCONTINUOUS);
358 destructo_xfade_adjustment.set_value (Config->get_destructive_xfade_msecs());
360 misc_packer.show_all ();
363 void
364 OptionEditor::limit_history_toggled ()
366 bool x = limit_history_button.get_active();
368 if (!x) {
369 Config->set_history_depth (0);
370 history_depth_spinner.set_sensitive (false);
371 } else {
372 if (Config->get_history_depth() == 0) {
373 /* get back to a sane default */
374 Config->set_history_depth (20);
376 history_depth_spinner.set_sensitive (true);
380 void
381 OptionEditor::save_history_toggled ()
383 bool x = save_history_button.get_active();
385 if (x != Config->get_save_history()) {
386 Config->set_save_history (x);
387 saved_history_depth_spinner.set_sensitive (x);
391 void
392 OptionEditor::history_depth_changed()
394 Config->set_history_depth ((int32_t) floor (history_depth.get_value()));
397 void
398 OptionEditor::saved_history_depth_changed()
400 Config->set_saved_history_depth ((int32_t) floor (saved_history_depth.get_value()));
403 void
404 OptionEditor::short_xfade_adjustment_changed ()
406 if (session) {
407 float val = short_xfade_adjustment.get_value();
409 /* val is in msecs */
411 Crossfade::set_short_xfade_length ((nframes_t) floor (session->frame_rate() * (val / 1000.0)));
415 void
416 OptionEditor::destructo_xfade_adjustment_changed ()
418 float val = destructo_xfade_adjustment.get_value();
420 /* val is in msecs */
423 Config->set_destructive_xfade_msecs ((uint32_t) floor (val));
425 if (session) {
426 SndFileSource::setup_standard_crossfades (session->frame_rate());
430 void
431 OptionEditor::setup_sync_options ()
433 HBox* hbox;
434 vector<string> dumb;
436 smpte_offset_clock.set_mode (AudioClock::SMPTE);
437 smpte_offset_clock.ValueChanged.connect (mem_fun(*this, &OptionEditor::smpte_offset_chosen));
439 smpte_offset_negative_button.set_name ("OptionEditorToggleButton");
441 smpte_offset_negative_button.unset_flags (Gtk::CAN_FOCUS);
443 Label *smpte_offset_label = manage (new Label (_("SMPTE Offset")));
444 smpte_offset_label->set_name("OptionsLabel");
446 hbox = manage (new HBox);
447 hbox->set_border_width (5);
448 hbox->set_spacing (10);
449 hbox->pack_start (*smpte_offset_label, false, false);
450 hbox->pack_start (smpte_offset_clock, false, false);
451 hbox->pack_start (smpte_offset_negative_button, false, false);
453 sync_packer.pack_start (*hbox, false, false);
454 sync_packer.pack_start (synced_timecode_button, false, false);
456 smpte_offset_negative_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::smpte_offset_negative_clicked));
457 synced_timecode_button.signal_toggled().connect (mem_fun(*this, &OptionEditor::synced_timecode_toggled));
460 void
461 OptionEditor::smpte_offset_negative_clicked ()
463 if (session) {
464 session->set_smpte_offset_negative (smpte_offset_negative_button.get_active());
468 void
469 OptionEditor::synced_timecode_toggled ()
471 bool x;
473 if ((x = synced_timecode_button.get_active()) != Config->get_timecode_source_is_synced()) {
474 Config->set_timecode_source_is_synced (x);
475 Config->save_state();
479 void
480 OptionEditor::smpte_offset_chosen()
482 if (session) {
483 nframes_t frames = smpte_offset_clock.current_duration();
484 session->set_smpte_offset (frames);
489 void
490 OptionEditor::setup_midi_options ()
492 HBox* hbox;
493 Label* label;
495 midi_port_table.set_row_spacings (6);
496 midi_port_table.set_col_spacings (10);
498 redisplay_midi_ports ();
500 mmc_receive_device_id_adjustment.set_value (Config->get_mmc_receive_device_id());
501 mmc_send_device_id_adjustment.set_value (Config->get_mmc_send_device_id());
503 mmc_receive_device_id_adjustment.signal_value_changed().connect (mem_fun (*this, &OptionEditor::mmc_receive_device_id_adjusted));
504 mmc_send_device_id_adjustment.signal_value_changed().connect (mem_fun (*this, &OptionEditor::mmc_send_device_id_adjusted));
506 hbox = manage (new HBox);
507 hbox->set_border_width (6);
508 hbox->pack_start (midi_port_table, true, false);
510 midi_packer.pack_start (*hbox, false, false);
511 midi_packer.pack_start (add_midi_port_button, false, false);
513 hbox = manage (new HBox);
514 hbox->set_border_width (6);
515 hbox->set_spacing (6);
516 label = (manage (new Label (_("Inbound MMC Device ID"))));
517 hbox->pack_start (mmc_receive_device_id_spinner, false, false);
518 hbox->pack_start (*label, false, false);
519 midi_packer.pack_start (*hbox, false, false);
521 mmc_receive_device_id_spinner.set_value(Config->get_mmc_receive_device_id ());
523 hbox = manage (new HBox);
524 hbox->set_border_width (6);
525 hbox->set_spacing (6);
526 label = (manage (new Label (_("Outbound MMC Device ID"))));
527 hbox->pack_start (mmc_send_device_id_spinner, false, false);
528 hbox->pack_start (*label, false, false);
529 midi_packer.pack_start (*hbox, false, false);
531 mmc_send_device_id_spinner.set_value(Config->get_mmc_send_device_id ());
533 hbox = manage (new HBox);
534 hbox->set_border_width (6);
535 hbox->set_spacing (6);
536 label = (manage (new Label (_("Startup program change"))));
537 hbox->pack_start (initial_program_change_spinner, false, false);
538 hbox->pack_start (*label, false, false);
539 midi_packer.pack_start (*hbox, false, false);
541 initial_program_change_spinner.set_value (Config->get_initial_program_change());
542 initial_program_change_adjustment.signal_value_changed().connect (mem_fun (*this, &OptionEditor::initial_program_change_adjusted));
544 add_midi_port_button.signal_clicked().connect (mem_fun (*this, &OptionEditor::add_midi_port));
547 void
548 OptionEditor::initial_program_change_adjusted ()
550 Config->set_initial_program_change (((int32_t) floor (initial_program_change_adjustment.get_value())) & 0x7f);
553 void
554 OptionEditor::redisplay_midi_ports ()
556 MIDI::Manager::PortMap::const_iterator i;
557 const MIDI::Manager::PortMap& ports = MIDI::Manager::instance()->get_midi_ports();
558 int n;
560 /* remove all existing widgets */
562 // XXX broken in gtkmm 2.10
563 // midi_port_table.clear ();
565 for (vector<Widget*>::iterator w = midi_port_table_widgets.begin(); w != midi_port_table_widgets.end(); ++w) {
566 midi_port_table.remove (**w);
569 midi_port_table_widgets.clear ();
571 midi_port_table.resize (ports.size() + 4, 11);
573 Gtk::Label* label;
575 label = (manage (new Label (_("Port"))));
576 label->show ();
577 midi_port_table_widgets.push_back (label);
578 midi_port_table.attach (*label, 0, 1, 0, 1);
579 label = (manage (new Label (_("Offline"))));
580 label->show ();
581 midi_port_table_widgets.push_back (label);
582 midi_port_table.attach (*label, 1, 2, 0, 1);
583 label = (manage (new Label (_("Trace\nInput"))));
584 label->show ();
585 midi_port_table_widgets.push_back (label);
586 midi_port_table.attach (*label, 2, 3, 0, 1);
587 label = (manage (new Label (_("Trace\nOutput"))));
588 label->show ();
589 midi_port_table_widgets.push_back (label);
590 midi_port_table.attach (*label, 3, 4, 0, 1);
591 label = (manage (new Label (_("MTC"))));
592 label->show ();
593 midi_port_table_widgets.push_back (label);
594 midi_port_table.attach (*label, 4, 5, 0, 1);
595 label = (manage (new Label (_("MMC"))));
596 label->show ();
597 midi_port_table_widgets.push_back (label);
598 midi_port_table.attach (*label, 6, 7, 0, 1);
599 label = (manage (new Label (_("MIDI Parameter\nControl"))));
600 label->show ();
601 midi_port_table_widgets.push_back (label);
602 midi_port_table.attach (*label, 8, 9, 0, 1);
604 Gtk::HSeparator* hsep = (manage (new HSeparator()));
605 hsep->show ();
606 midi_port_table_widgets.push_back (hsep);
607 midi_port_table.attach (*hsep, 0, 9, 1, 2);
608 Gtk::VSeparator* vsep = (manage (new VSeparator()));
609 vsep->show ();
610 midi_port_table_widgets.push_back (vsep);
611 midi_port_table.attach (*vsep, 5, 6, 0, 8);
612 vsep = (manage (new VSeparator()));
613 vsep->show ();
614 midi_port_table_widgets.push_back (vsep);
615 midi_port_table.attach (*vsep, 7, 8, 0, 8);
617 for (n = 0, i = ports.begin(); i != ports.end(); ++n, ++i) {
619 ToggleButton* tb;
620 RadioButton* rb;
621 Button* bb;
623 /* the remove button. create early so we can pass it to various callbacks */
625 bb = manage (new Button (Stock::REMOVE));
626 bb->set_name ("OptionEditorToggleButton");
627 bb->show ();
628 midi_port_table_widgets.push_back (bb);
629 midi_port_table.attach (*bb, 9, 10, n+2, n+3, FILL|EXPAND, FILL);
630 bb->signal_clicked().connect (bind (mem_fun(*this, &OptionEditor::remove_midi_port), i->second));
631 bb->set_sensitive (port_removable (i->second));
633 label = (manage (new Label (i->first)));
634 label->show ();
635 midi_port_table_widgets.push_back (label);
636 midi_port_table.attach (*label, 0, 1, n+2, n+3,FILL|EXPAND, FILL );
638 tb = manage (new ToggleButton (_("online")));
639 tb->set_name ("OptionEditorToggleButton");
641 /* remember, we have to handle the i18n case where the relative
642 lengths of the strings in language N is different than in english.
645 if (strlen (_("offline")) > strlen (_("online"))) {
646 set_size_request_to_display_given_text (*tb, _("offline"), 15, 12);
647 } else {
648 set_size_request_to_display_given_text (*tb, _("online"), 15, 12);
651 if (i->second->input()) {
652 tb->set_active (!i->second->input()->offline());
653 tb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::port_online_toggled), i->second, tb));
654 i->second->input()->OfflineStatusChanged.connect (bind (mem_fun(*this, &OptionEditor::map_port_online), (*i).second, tb));
656 tb->show ();
657 midi_port_table_widgets.push_back (tb);
658 midi_port_table.attach (*tb, 1, 2, n+2, n+3, FILL|EXPAND, FILL);
660 tb = manage (new ToggleButton ());
661 tb->set_name ("OptionEditorToggleButton");
662 tb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::port_trace_in_toggled), (*i).second, tb));
663 tb->set_size_request (10, 10);
664 tb->show ();
665 midi_port_table_widgets.push_back (tb);
666 midi_port_table.attach (*tb, 2, 3, n+2, n+3, FILL|EXPAND, FILL);
668 tb = manage (new ToggleButton ());
669 tb->set_name ("OptionEditorToggleButton");
670 tb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::port_trace_out_toggled), (*i).second, tb));
671 tb->set_size_request (10, 10);
672 tb->show ();
673 midi_port_table_widgets.push_back (tb);
674 midi_port_table.attach (*tb, 3, 4, n+2, n+3, FILL|EXPAND, FILL);
676 rb = manage (new RadioButton ());
677 rb->set_name ("OptionEditorToggleButton");
678 if (n == 0) {
679 mtc_button_group = rb->get_group();
680 } else {
681 rb->set_group (mtc_button_group);
684 rb->show ();
685 midi_port_table_widgets.push_back (rb);
686 midi_port_table.attach (*rb, 4, 5, n+2, n+3, FILL|EXPAND, FILL);
687 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::mtc_port_chosen), (*i).second, rb, bb));
689 if (session && i->second == session->mtc_port()) {
690 rb->set_active (true);
693 rb = manage (new RadioButton ());
694 rb->set_name ("OptionEditorToggleButton");
695 if (n == 0) {
696 mmc_button_group = rb->get_group();
697 } else {
698 rb->set_group (mmc_button_group);
700 rb->show ();
701 midi_port_table_widgets.push_back (rb);
702 midi_port_table.attach (*rb, 6, 7, n+2, n+3, FILL|EXPAND, FILL);
703 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::mmc_port_chosen), (*i).second, rb, bb));
705 if (session && i->second == session->mmc_port()) {
706 rb->set_active (true);
709 rb = manage (new RadioButton ());
710 rb->set_name ("OptionEditorToggleButton");
711 if (n == 0) {
712 midi_button_group = rb->get_group();
713 } else {
714 rb->set_group (midi_button_group);
716 rb->show ();
717 midi_port_table_widgets.push_back (rb);
718 midi_port_table.attach (*rb, 8, 9, n+2, n+3, FILL|EXPAND, FILL);
719 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::midi_port_chosen), (*i).second, rb, bb));
721 if (session && i->second == session->midi_port()) {
722 rb->set_active (true);
727 midi_port_table.show();
730 void
731 OptionEditor::remove_midi_port (MIDI::Port* port)
733 MIDI::Manager::instance()->remove_port (port);
734 redisplay_midi_ports ();
737 void
738 OptionEditor::add_midi_port ()
740 MidiPortDialog dialog;
742 dialog.set_position (WIN_POS_MOUSE);
743 dialog.set_transient_for (*this);
745 dialog.show ();
747 int ret = dialog.run ();
749 switch (ret) {
750 case RESPONSE_ACCEPT:
751 break;
752 default:
753 return;
754 break;
757 Glib::ustring mode = dialog.port_mode_combo.get_active_text();
758 std::string smod;
760 if (mode == _("input")) {
761 smod = X_("input");
762 } else if (mode == (_("output"))) {
763 smod = X_("output");
764 } else {
765 smod = "duplex";
769 XMLNode node (X_("MIDI-port"));
771 node.add_property ("tag", dialog.port_name.get_text());
772 node.add_property ("device", X_("ardour")); // XXX this can't be right for all types
773 node.add_property ("type", MIDI::PortFactory::default_port_type());
774 node.add_property ("mode", smod);
776 if (MIDI::Manager::instance()->add_port (node) != 0) {
777 redisplay_midi_ports ();
781 bool
782 OptionEditor::port_removable (MIDI::Port *port)
784 if (!session) {
785 return true;
788 if (port == session->mtc_port() ||
789 port == session->mmc_port() ||
790 port == session->midi_port()) {
791 return false;
793 return true;
796 void
797 OptionEditor::mtc_port_chosen (MIDI::Port *port, Gtk::RadioButton* rb, Gtk::Button* bb)
799 if (session) {
800 if (rb->get_active()) {
801 session->set_mtc_port (port->name());
802 Config->set_mtc_port_name (port->name());
803 } else {
804 session->set_mtc_port ("");
806 bb->set_sensitive (port_removable (port));
810 void
811 OptionEditor::mmc_port_chosen (MIDI::Port* port, Gtk::RadioButton* rb, Gtk::Button* bb)
813 if (session) {
814 if (rb->get_active()) {
815 session->set_mmc_port (port->name());
816 Config->set_mtc_port_name (port->name());
817 } else {
818 session->set_mmc_port ("");
820 bb->set_sensitive (port_removable (port));
824 void
825 OptionEditor::midi_port_chosen (MIDI::Port* port, Gtk::RadioButton* rb, Gtk::Button* bb)
827 if (session) {
828 if (rb->get_active()) {
829 session->set_midi_port (port->name());
830 Config->set_midi_port_name (port->name());
831 } else {
832 session->set_midi_port ("");
834 bb->set_sensitive (port_removable (port));
838 void
839 OptionEditor::port_online_toggled (MIDI::Port* port, ToggleButton* tb)
841 bool wanted = tb->get_active();
843 if (port->input()) {
844 if (wanted != port->input()->offline()) {
845 port->input()->set_offline (wanted);
850 void
851 OptionEditor::map_port_online (MIDI::Port* port, ToggleButton* tb)
853 bool bstate = tb->get_active ();
855 if (port->input()) {
856 if (bstate != port->input()->offline()) {
857 if (port->input()->offline()) {
858 tb->set_label (_("offline"));
859 tb->set_active (false);
860 } else {
861 tb->set_label (_("online"));
862 tb->set_active (true);
868 void
869 OptionEditor::mmc_receive_device_id_adjusted ()
871 uint8_t id = (uint8_t) mmc_receive_device_id_spinner.get_value();
872 Config->set_mmc_receive_device_id (id);
875 void
876 OptionEditor::mmc_send_device_id_adjusted ()
878 uint8_t id = (uint8_t) mmc_send_device_id_spinner.get_value();
879 Config->set_mmc_send_device_id (id);
882 void
883 OptionEditor::port_trace_in_toggled (MIDI::Port* port, ToggleButton* tb)
885 bool trace = tb->get_active();
887 if (port->input()) {
888 if (port->input()->tracing() != trace) {
889 port->input()->trace (trace, &cerr, string (port->name()) + string (" input: "));
894 void
895 OptionEditor::port_trace_out_toggled (MIDI::Port* port, ToggleButton* tb)
897 bool trace = tb->get_active();
899 if (port->output()) {
900 if (port->output()->tracing() != trace) {
901 port->output()->trace (trace, &cerr, string (port->name()) + string (" output: "));
906 void
907 OptionEditor::save ()
909 /* XXX a bit odd that we save the entire session state here */
911 ui.save_state ("");
914 gint
915 OptionEditor::wm_close (GdkEventAny *ev)
917 save ();
918 hide ();
919 return TRUE;
922 void
923 OptionEditor::raid_path_changed ()
925 if (session) {
926 Config->set_raid_path (session_raid_entry.get_text());
930 void
931 OptionEditor::click_browse_clicked ()
933 SoundFileChooser sfdb (*this, _("Choose Click"), session);
935 sfdb.show_all ();
936 sfdb.present ();
938 int result = sfdb.run ();
940 if (result == Gtk::RESPONSE_OK) {
941 click_chosen(sfdb.get_filename());
945 void
946 OptionEditor::click_chosen (const string & path)
948 click_path_entry.set_text (path);
949 click_sound_changed ();
952 void
953 OptionEditor::click_emphasis_browse_clicked ()
955 SoundFileChooser sfdb (*this, _("Choose Click Emphasis"), session);
957 sfdb.show_all ();
958 sfdb.present ();
960 int result = sfdb.run ();
962 if (result == Gtk::RESPONSE_OK) {
963 click_emphasis_chosen (sfdb.get_filename());
967 void
968 OptionEditor::click_emphasis_chosen (const string & path)
970 click_emphasis_path_entry.set_text (path);
971 click_emphasis_sound_changed ();
974 void
975 OptionEditor::click_sound_changed ()
977 if (session) {
978 string path = click_path_entry.get_text();
980 if (path == Config->get_click_sound()) {
981 return;
984 strip_whitespace_edges (path);
986 if (path == _("internal")) {
987 Config->set_click_sound ("");
988 } else {
989 Config->set_click_sound (path);
994 void
995 OptionEditor::click_emphasis_sound_changed ()
997 if (session) {
998 string path = click_emphasis_path_entry.get_text();
1000 if (path == Config->get_click_emphasis_sound()) {
1001 return;
1004 strip_whitespace_edges (path);
1006 if (path == _("internal")) {
1007 Config->set_click_emphasis_sound ("");
1008 } else {
1009 Config->set_click_emphasis_sound (path);
1014 void
1015 OptionEditor::clear_click_editor ()
1017 if (click_io_selector) {
1018 click_hpacker.remove (*click_io_selector);
1019 click_hpacker.remove (*click_gpm);
1020 delete click_io_selector;
1021 delete click_gpm;
1022 click_io_selector = 0;
1023 click_gpm = 0;
1027 void
1028 OptionEditor::setup_click_editor ()
1030 Label* label;
1032 if (first_click_setup) {
1034 click_path_entry.set_name ("OptionsEntry");
1035 click_emphasis_path_entry.set_name ("OptionsEntry");
1037 click_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_sound_changed));
1038 click_emphasis_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_emphasis_sound_changed));
1040 click_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_sound_changed));
1041 click_emphasis_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_emphasis_sound_changed));
1043 click_browse_button.set_name ("EditorGTKButton");
1044 click_emphasis_browse_button.set_name ("EditorGTKButton");
1046 click_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_browse_clicked));
1047 click_emphasis_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_emphasis_browse_clicked));
1049 click_packer.set_border_width (12);
1050 click_packer.set_spacing (5);
1052 click_table.set_col_spacings (10);
1054 label = manage(new Label(_("Click audio file")));
1055 label->set_name ("OptionsLabel");
1056 click_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL);
1057 click_table.attach (click_path_entry, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1058 click_table.attach (click_browse_button, 2, 3, 0, 1, FILL|EXPAND, FILL);
1060 label = manage(new Label(_("Click emphasis audiofile")));
1061 label->set_name ("OptionsLabel");
1062 click_table.attach (*label, 0, 1, 1, 2, FILL|EXPAND, FILL);
1063 click_table.attach (click_emphasis_path_entry, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1064 click_table.attach (click_emphasis_browse_button, 2, 3, 1, 2, FILL|EXPAND, FILL);
1066 click_packer.pack_start (click_table, false, false);
1067 click_packer.pack_start (click_hpacker, false, false);
1070 click_hpacker.set_spacing (10);
1072 first_click_setup = false;
1075 click_path_entry.set_sensitive (true);
1076 click_emphasis_path_entry.set_sensitive (true);
1078 click_io_selector = new IOSelector (*session, session->click_io(), false);
1079 click_gpm = new GainMeter (*session);
1080 click_gpm->set_io (session->click_io());
1082 click_hpacker.pack_start (*click_io_selector, false, false);
1083 click_hpacker.pack_start (*click_gpm, false, false);
1085 click_packer.show_all ();
1088 void
1089 OptionEditor::clear_auditioner_editor ()
1091 if (auditioner_io_selector) {
1092 audition_hpacker.remove (*auditioner_io_selector);
1093 audition_hpacker.remove (*auditioner_gpm);
1094 delete auditioner_io_selector;
1095 delete auditioner_gpm;
1096 auditioner_io_selector = 0;
1097 auditioner_gpm = 0;
1101 void
1102 OptionEditor::setup_auditioner_editor ()
1104 audition_packer.set_border_width (12);
1105 audition_packer.set_spacing (5);
1106 audition_hpacker.set_spacing (10);
1108 audition_label.set_name ("OptionEditorAuditionerLabel");
1109 audition_label.set_text (_("The auditioner is a dedicated mixer strip used\n"
1110 "for listening to specific regions outside the context\n"
1111 "of the overall mix. It can be connected just like any\n"
1112 "other mixer strip."));
1114 audition_packer.pack_start (audition_label, false, false, 10);
1115 audition_packer.pack_start (audition_hpacker, false, false);
1118 void
1119 OptionEditor::connect_audition_editor ()
1121 auditioner_io_selector = new IOSelector (*session, session->the_auditioner(), false);
1122 auditioner_gpm = new GainMeter (*session);
1123 auditioner_gpm->set_io (session->the_auditioner());
1125 audition_hpacker.pack_start (*auditioner_io_selector, false, false);
1126 audition_hpacker.pack_start (*auditioner_gpm, false, false);
1128 auditioner_io_selector->show_all ();
1129 auditioner_gpm->show_all ();
1132 bool
1133 OptionEditor::focus_out_event_handler (GdkEventFocus* ev, void (OptionEditor::*pmf)())
1135 (this->*pmf)();
1136 return false;
1139 static const struct {
1140 const char *name;
1141 guint modifier;
1142 } modifiers[] = {
1144 #ifdef GTKOSX
1146 /* Command = Meta
1147 Option/Alt = Mod1
1150 { "Shift", GDK_SHIFT_MASK },
1151 { "Command", GDK_META_MASK },
1152 { "Control", GDK_CONTROL_MASK },
1153 { "Option", GDK_MOD1_MASK },
1154 { "Command-Shift", GDK_MOD1_MASK|GDK_SHIFT_MASK },
1155 { "Command-Option", GDK_MOD1_MASK|GDK_MOD5_MASK },
1156 { "Shift-Option", GDK_SHIFT_MASK|GDK_MOD5_MASK },
1157 { "Shift-Command-Option", GDK_MOD5_MASK|GDK_SHIFT_MASK|GDK_MOD1_MASK },
1159 #else
1160 { "Shift", GDK_SHIFT_MASK },
1161 { "Control", GDK_CONTROL_MASK },
1162 { "Alt (Mod1)", GDK_MOD1_MASK },
1163 { "Control-Shift", GDK_CONTROL_MASK|GDK_SHIFT_MASK },
1164 { "Control-Alt", GDK_CONTROL_MASK|GDK_MOD1_MASK },
1165 { "Shift-Alt", GDK_SHIFT_MASK|GDK_MOD1_MASK },
1166 { "Control-Shift-Alt", GDK_CONTROL_MASK|GDK_SHIFT_MASK|GDK_MOD1_MASK },
1167 { "Mod2", GDK_MOD2_MASK },
1168 { "Mod3", GDK_MOD3_MASK },
1169 { "Mod4", GDK_MOD4_MASK },
1170 { "Mod5", GDK_MOD5_MASK },
1171 #endif
1172 { 0, 0 }
1175 void
1176 OptionEditor::setup_keyboard_options ()
1178 vector<string> dumb;
1179 Label* label;
1181 keyboard_mouse_table.set_border_width (12);
1182 keyboard_mouse_table.set_row_spacings (5);
1183 keyboard_mouse_table.set_col_spacings (5);
1185 /* internationalize and prepare for use with combos */
1187 for (int i = 0; modifiers[i].name; ++i) {
1188 dumb.push_back (_(modifiers[i].name));
1191 set_popdown_strings (edit_modifier_combo, dumb);
1192 edit_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::edit_modifier_chosen));
1194 for (int x = 0; modifiers[x].name; ++x) {
1195 if (modifiers[x].modifier == Keyboard::edit_modifier ()) {
1196 edit_modifier_combo.set_active_text (_(modifiers[x].name));
1197 break;
1201 label = manage (new Label (_("Edit using")));
1202 label->set_name ("OptionsLabel");
1203 label->set_alignment (1.0, 0.5);
1205 keyboard_mouse_table.attach (*label, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1206 keyboard_mouse_table.attach (edit_modifier_combo, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1208 label = manage (new Label (_("+ button")));
1209 label->set_name ("OptionsLabel");
1211 keyboard_mouse_table.attach (*label, 3, 4, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1212 keyboard_mouse_table.attach (edit_button_spin, 4, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1214 edit_button_spin.set_name ("OptionsEntry");
1215 edit_button_adjustment.set_value (Keyboard::edit_button());
1216 edit_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::edit_button_changed));
1218 set_popdown_strings (delete_modifier_combo, dumb);
1219 delete_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::delete_modifier_chosen));
1221 for (int x = 0; modifiers[x].name; ++x) {
1222 if (modifiers[x].modifier == Keyboard::delete_modifier ()) {
1223 delete_modifier_combo.set_active_text (_(modifiers[x].name));
1224 break;
1228 label = manage (new Label (_("Delete using")));
1229 label->set_name ("OptionsLabel");
1230 label->set_alignment (1.0, 0.5);
1232 keyboard_mouse_table.attach (*label, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1233 keyboard_mouse_table.attach (delete_modifier_combo, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1235 label = manage (new Label (_("+ button")));
1236 label->set_name ("OptionsLabel");
1238 keyboard_mouse_table.attach (*label, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1239 keyboard_mouse_table.attach (delete_button_spin, 4, 5, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1241 delete_button_spin.set_name ("OptionsEntry");
1242 delete_button_adjustment.set_value (Keyboard::delete_button());
1243 delete_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::delete_button_changed));
1245 set_popdown_strings (snap_modifier_combo, dumb);
1246 snap_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::snap_modifier_chosen));
1248 for (int x = 0; modifiers[x].name; ++x) {
1249 if (modifiers[x].modifier == (guint) Keyboard::snap_modifier ()) {
1250 snap_modifier_combo.set_active_text (_(modifiers[x].name));
1251 break;
1255 label = manage (new Label (_("Ignore snap using")));
1256 label->set_name ("OptionsLabel");
1257 label->set_alignment (1.0, 0.5);
1259 keyboard_mouse_table.attach (*label, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
1260 keyboard_mouse_table.attach (snap_modifier_combo, 1, 2, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
1262 vector<string> strs;
1264 for (std::map<std::string,std::string>::iterator bf = Keyboard::binding_files.begin(); bf != Keyboard::binding_files.end(); ++bf) {
1265 strs.push_back (bf->first);
1268 set_popdown_strings (keyboard_layout_selector, strs);
1269 keyboard_layout_selector.set_active_text (Keyboard::current_binding_name());
1270 keyboard_layout_selector.signal_changed().connect (mem_fun (*this, &OptionEditor::bindings_changed));
1272 label = manage (new Label (_("Keyboard layout")));
1273 label->set_name ("OptionsLabel");
1274 label->set_alignment (1.0, 0.5);
1276 keyboard_mouse_table.attach (*label, 0, 1, 3, 4, Gtk::FILL|Gtk::EXPAND, FILL);
1277 keyboard_mouse_table.attach (keyboard_layout_selector, 1, 2, 3, 4, Gtk::FILL|Gtk::EXPAND, FILL);
1280 void
1281 OptionEditor::bindings_changed ()
1283 string txt;
1285 txt = keyboard_layout_selector.get_active_text();
1287 for (std::map<string,string>::iterator i = Keyboard::binding_files.begin(); i != Keyboard::binding_files.end(); ++i) {
1288 if (txt == i->first) {
1289 if (Keyboard::load_keybindings (i->second)) {
1290 Keyboard::save_keybindings ();
1296 void
1297 OptionEditor::edit_modifier_chosen ()
1299 string txt;
1301 txt = edit_modifier_combo.get_active_text();
1303 for (int i = 0; modifiers[i].name; ++i) {
1304 if (txt == _(modifiers[i].name)) {
1305 Keyboard::set_edit_modifier (modifiers[i].modifier);
1306 break;
1311 void
1312 OptionEditor::delete_modifier_chosen ()
1314 string txt;
1316 txt = delete_modifier_combo.get_active_text();
1318 for (int i = 0; modifiers[i].name; ++i) {
1319 if (txt == _(modifiers[i].name)) {
1320 Keyboard::set_delete_modifier (modifiers[i].modifier);
1321 break;
1326 void
1327 OptionEditor::snap_modifier_chosen ()
1329 string txt;
1331 txt = snap_modifier_combo.get_active_text();
1333 for (int i = 0; modifiers[i].name; ++i) {
1334 if (txt == _(modifiers[i].name)) {
1335 Keyboard::set_snap_modifier (modifiers[i].modifier);
1336 break;
1341 void
1342 OptionEditor::delete_button_changed ()
1344 Keyboard::set_delete_button ((guint) delete_button_adjustment.get_value());
1347 void
1348 OptionEditor::edit_button_changed ()
1350 Keyboard::set_edit_button ((guint) edit_button_adjustment.get_value());
1353 void
1354 OptionEditor::parameter_changed (const char* parameter_name)
1356 ENSURE_GUI_THREAD (bind (mem_fun (*this, &OptionEditor::parameter_changed), parameter_name));
1358 #define PARAM_IS(x) (!strcmp (parameter_name, (x)))
1360 if (PARAM_IS ("timecode-source-is-synced")) {
1361 synced_timecode_button.set_active (Config->get_timecode_source_is_synced());
1362 } else if (PARAM_IS ("history-depth")) {
1363 int32_t depth = Config->get_history_depth();
1365 history_depth.set_value (depth);
1366 history_depth_spinner.set_sensitive (depth != 0);
1367 limit_history_button.set_active (depth != 0);
1369 } else if (PARAM_IS ("saved-history-depth")) {
1371 saved_history_depth.set_value (Config->get_saved_history_depth());
1373 } else if (PARAM_IS ("save-history")) {
1375 bool x = Config->get_save_history();
1377 save_history_button.set_active (x);
1378 saved_history_depth_spinner.set_sensitive (x);
1379 } else if (PARAM_IS ("font-scale")) {
1380 reset_dpi();