fix import/embed with "sequence files" option
[ardour2.git] / gtk2_ardour / option_editor.cc
blob53119ea96817a3e1ef7261a177110d6879532303
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 #ifndef GTKOSX
261 static void
262 font_scale_changed (Gtk::Adjustment* adj)
264 Config->set_font_scale((long)floor (adj->get_value() * 1024));
265 reset_dpi();
267 #endif
269 void
270 OptionEditor::setup_misc_options ()
272 Gtk::HBox* hbox;
273 Label* label;
275 #ifndef GTKOSX
276 /* font scaling does nothing with GDK/Quartz */
278 Gtk::Adjustment* dpi_adj = new Gtk::Adjustment ((double)Config->get_font_scale() / 1024, 50, 250, 1, 10);
279 Gtk::HScale * dpi_range = new Gtk::HScale (*dpi_adj);
281 label = manage (new Label (_("Font Scaling")));
282 label->set_name ("OptionsLabel");
284 dpi_range->set_update_policy (Gtk::UPDATE_DISCONTINUOUS);
285 dpi_adj->signal_value_changed().connect (bind (sigc::ptr_fun (font_scale_changed), dpi_adj));
287 hbox = manage (new HBox);
288 hbox->set_border_width (5);
289 hbox->set_spacing (10);
290 hbox->pack_start (*label, false, false);
291 hbox->pack_start (*dpi_range, true, true);
292 misc_packer.pack_start (*hbox, false, false);
293 #endif
295 label = manage (new Label (_("Short crossfade length (msecs)")));
296 label->set_name ("OptionsLabel");
298 hbox = manage (new HBox);
299 hbox->set_border_width (5);
300 hbox->set_spacing (10);
301 hbox->pack_start (*label, false, false);
302 hbox->pack_start (short_xfade_slider, true, true);
303 misc_packer.pack_start (*hbox, false, false);
305 short_xfade_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::short_xfade_adjustment_changed));
307 label = manage (new Label (_("Destructive crossfade length (msecs)")));
308 label->set_name ("OptionsLabel");
310 hbox = manage (new HBox);
311 hbox->set_border_width (5);
312 hbox->set_spacing (10);
313 hbox->pack_start (*label, false, false);
314 hbox->pack_start (destructo_xfade_slider, true, true);
315 misc_packer.pack_start (*hbox, false, false);
318 destructo_xfade_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::destructo_xfade_adjustment_changed));
320 hbox = manage (new HBox);
321 hbox->set_border_width (5);
322 hbox->set_spacing (10);
323 hbox->pack_start (limit_history_button, false, false);
324 misc_packer.pack_start (*hbox, false, false);
326 label = manage (new Label (_("History depth (commands)")));
327 label->set_name ("OptionsLabel");
329 hbox = manage (new HBox);
330 hbox->set_border_width (5);
331 hbox->set_spacing (10);
332 hbox->pack_start (*label, false, false);
333 hbox->pack_start (history_depth_spinner, false, false);
334 misc_packer.pack_start (*hbox, false, false);
336 history_depth.signal_value_changed().connect (mem_fun (*this, &OptionEditor::history_depth_changed));
337 saved_history_depth.signal_value_changed().connect (mem_fun (*this, &OptionEditor::saved_history_depth_changed));
338 save_history_button.signal_toggled().connect (mem_fun (*this, &OptionEditor::save_history_toggled));
339 limit_history_button.signal_toggled().connect (mem_fun (*this, &OptionEditor::limit_history_toggled));
341 hbox = manage (new HBox);
342 hbox->set_border_width (5);
343 hbox->set_spacing (10);
344 hbox->pack_start (save_history_button, false, false);
345 misc_packer.pack_start (*hbox, false, false);
347 label = manage (new Label (_("Saved history depth (commands)")));
348 label->set_name ("OptionsLabel");
350 hbox = manage (new HBox);
351 hbox->set_border_width (5);
352 hbox->set_spacing (10);
353 hbox->pack_start (*label, false, false);
354 hbox->pack_start (saved_history_depth_spinner, false, false);
355 misc_packer.pack_start (*hbox, false, false);
357 short_xfade_slider.set_update_policy (UPDATE_DISCONTINUOUS);
358 destructo_xfade_slider.set_update_policy (UPDATE_DISCONTINUOUS);
360 destructo_xfade_adjustment.set_value (Config->get_destructive_xfade_msecs());
362 misc_packer.show_all ();
365 void
366 OptionEditor::limit_history_toggled ()
368 bool x = limit_history_button.get_active();
370 if (!x) {
371 Config->set_history_depth (0);
372 history_depth_spinner.set_sensitive (false);
373 } else {
374 if (Config->get_history_depth() == 0) {
375 /* get back to a sane default */
376 Config->set_history_depth (20);
378 history_depth_spinner.set_sensitive (true);
382 void
383 OptionEditor::save_history_toggled ()
385 bool x = save_history_button.get_active();
387 if (x != Config->get_save_history()) {
388 Config->set_save_history (x);
389 saved_history_depth_spinner.set_sensitive (x);
393 void
394 OptionEditor::history_depth_changed()
396 Config->set_history_depth ((int32_t) floor (history_depth.get_value()));
399 void
400 OptionEditor::saved_history_depth_changed()
402 Config->set_saved_history_depth ((int32_t) floor (saved_history_depth.get_value()));
405 void
406 OptionEditor::short_xfade_adjustment_changed ()
408 if (session) {
409 float val = short_xfade_adjustment.get_value();
411 /* val is in msecs */
413 Crossfade::set_short_xfade_length ((nframes_t) floor (session->frame_rate() * (val / 1000.0)));
417 void
418 OptionEditor::destructo_xfade_adjustment_changed ()
420 float val = destructo_xfade_adjustment.get_value();
422 /* val is in msecs */
425 Config->set_destructive_xfade_msecs ((uint32_t) floor (val));
427 if (session) {
428 SndFileSource::setup_standard_crossfades (session->frame_rate());
432 void
433 OptionEditor::setup_sync_options ()
435 HBox* hbox;
436 vector<string> dumb;
438 smpte_offset_clock.set_mode (AudioClock::SMPTE);
439 smpte_offset_clock.ValueChanged.connect (mem_fun(*this, &OptionEditor::smpte_offset_chosen));
441 smpte_offset_negative_button.set_name ("OptionEditorToggleButton");
443 smpte_offset_negative_button.unset_flags (Gtk::CAN_FOCUS);
445 Label *smpte_offset_label = manage (new Label (_("SMPTE Offset")));
446 smpte_offset_label->set_name("OptionsLabel");
448 hbox = manage (new HBox);
449 hbox->set_border_width (5);
450 hbox->set_spacing (10);
451 hbox->pack_start (*smpte_offset_label, false, false);
452 hbox->pack_start (smpte_offset_clock, false, false);
453 hbox->pack_start (smpte_offset_negative_button, false, false);
455 sync_packer.pack_start (*hbox, false, false);
456 sync_packer.pack_start (synced_timecode_button, false, false);
458 smpte_offset_negative_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::smpte_offset_negative_clicked));
459 synced_timecode_button.signal_toggled().connect (mem_fun(*this, &OptionEditor::synced_timecode_toggled));
462 void
463 OptionEditor::smpte_offset_negative_clicked ()
465 if (session) {
466 session->set_smpte_offset_negative (smpte_offset_negative_button.get_active());
470 void
471 OptionEditor::synced_timecode_toggled ()
473 bool x;
475 if ((x = synced_timecode_button.get_active()) != Config->get_timecode_source_is_synced()) {
476 Config->set_timecode_source_is_synced (x);
477 Config->save_state();
481 void
482 OptionEditor::smpte_offset_chosen()
484 if (session) {
485 nframes_t frames = smpte_offset_clock.current_duration();
486 session->set_smpte_offset (frames);
491 void
492 OptionEditor::setup_midi_options ()
494 HBox* hbox;
495 Label* label;
497 midi_port_table.set_row_spacings (6);
498 midi_port_table.set_col_spacings (10);
500 redisplay_midi_ports ();
502 mmc_receive_device_id_adjustment.set_value (Config->get_mmc_receive_device_id());
503 mmc_send_device_id_adjustment.set_value (Config->get_mmc_send_device_id());
505 mmc_receive_device_id_adjustment.signal_value_changed().connect (mem_fun (*this, &OptionEditor::mmc_receive_device_id_adjusted));
506 mmc_send_device_id_adjustment.signal_value_changed().connect (mem_fun (*this, &OptionEditor::mmc_send_device_id_adjusted));
508 hbox = manage (new HBox);
509 hbox->set_border_width (6);
510 hbox->pack_start (midi_port_table, true, false);
512 midi_packer.pack_start (*hbox, false, false);
513 midi_packer.pack_start (add_midi_port_button, false, false);
515 hbox = manage (new HBox);
516 hbox->set_border_width (6);
517 hbox->set_spacing (6);
518 label = (manage (new Label (_("Inbound MMC Device ID"))));
519 hbox->pack_start (mmc_receive_device_id_spinner, false, false);
520 hbox->pack_start (*label, false, false);
521 midi_packer.pack_start (*hbox, false, false);
523 mmc_receive_device_id_spinner.set_value(Config->get_mmc_receive_device_id ());
525 hbox = manage (new HBox);
526 hbox->set_border_width (6);
527 hbox->set_spacing (6);
528 label = (manage (new Label (_("Outbound MMC Device ID"))));
529 hbox->pack_start (mmc_send_device_id_spinner, false, false);
530 hbox->pack_start (*label, false, false);
531 midi_packer.pack_start (*hbox, false, false);
533 mmc_send_device_id_spinner.set_value(Config->get_mmc_send_device_id ());
535 hbox = manage (new HBox);
536 hbox->set_border_width (6);
537 hbox->set_spacing (6);
538 label = (manage (new Label (_("Startup program change"))));
539 hbox->pack_start (initial_program_change_spinner, false, false);
540 hbox->pack_start (*label, false, false);
541 midi_packer.pack_start (*hbox, false, false);
543 initial_program_change_spinner.set_value (Config->get_initial_program_change());
544 initial_program_change_adjustment.signal_value_changed().connect (mem_fun (*this, &OptionEditor::initial_program_change_adjusted));
546 add_midi_port_button.signal_clicked().connect (mem_fun (*this, &OptionEditor::add_midi_port));
549 void
550 OptionEditor::initial_program_change_adjusted ()
552 Config->set_initial_program_change (((int32_t) floor (initial_program_change_adjustment.get_value())) & 0x7f);
555 void
556 OptionEditor::redisplay_midi_ports ()
558 MIDI::Manager::PortMap::const_iterator i;
559 const MIDI::Manager::PortMap& ports = MIDI::Manager::instance()->get_midi_ports();
560 int n;
562 /* remove all existing widgets */
564 // XXX broken in gtkmm 2.10
565 // midi_port_table.clear ();
567 for (vector<Widget*>::iterator w = midi_port_table_widgets.begin(); w != midi_port_table_widgets.end(); ++w) {
568 midi_port_table.remove (**w);
571 midi_port_table_widgets.clear ();
573 midi_port_table.resize (ports.size() + 4, 11);
575 Gtk::Label* label;
577 label = (manage (new Label (_("Port"))));
578 label->show ();
579 midi_port_table_widgets.push_back (label);
580 midi_port_table.attach (*label, 0, 1, 0, 1);
581 label = (manage (new Label (_("Offline"))));
582 label->show ();
583 midi_port_table_widgets.push_back (label);
584 midi_port_table.attach (*label, 1, 2, 0, 1);
585 label = (manage (new Label (_("Trace\nInput"))));
586 label->show ();
587 midi_port_table_widgets.push_back (label);
588 midi_port_table.attach (*label, 2, 3, 0, 1);
589 label = (manage (new Label (_("Trace\nOutput"))));
590 label->show ();
591 midi_port_table_widgets.push_back (label);
592 midi_port_table.attach (*label, 3, 4, 0, 1);
593 label = (manage (new Label (_("MTC"))));
594 label->show ();
595 midi_port_table_widgets.push_back (label);
596 midi_port_table.attach (*label, 4, 5, 0, 1);
597 label = (manage (new Label (_("MMC"))));
598 label->show ();
599 midi_port_table_widgets.push_back (label);
600 midi_port_table.attach (*label, 6, 7, 0, 1);
601 label = (manage (new Label (_("MIDI Parameter\nControl"))));
602 label->show ();
603 midi_port_table_widgets.push_back (label);
604 midi_port_table.attach (*label, 8, 9, 0, 1);
606 Gtk::HSeparator* hsep = (manage (new HSeparator()));
607 hsep->show ();
608 midi_port_table_widgets.push_back (hsep);
609 midi_port_table.attach (*hsep, 0, 9, 1, 2);
610 Gtk::VSeparator* vsep = (manage (new VSeparator()));
611 vsep->show ();
612 midi_port_table_widgets.push_back (vsep);
613 midi_port_table.attach (*vsep, 5, 6, 0, 8);
614 vsep = (manage (new VSeparator()));
615 vsep->show ();
616 midi_port_table_widgets.push_back (vsep);
617 midi_port_table.attach (*vsep, 7, 8, 0, 8);
619 for (n = 0, i = ports.begin(); i != ports.end(); ++n, ++i) {
621 ToggleButton* tb;
622 RadioButton* rb;
623 Button* bb;
625 /* the remove button. create early so we can pass it to various callbacks */
627 bb = manage (new Button (Stock::REMOVE));
628 bb->set_name ("OptionEditorToggleButton");
629 bb->show ();
630 midi_port_table_widgets.push_back (bb);
631 midi_port_table.attach (*bb, 9, 10, n+2, n+3, FILL|EXPAND, FILL);
632 bb->signal_clicked().connect (bind (mem_fun(*this, &OptionEditor::remove_midi_port), i->second));
633 bb->set_sensitive (port_removable (i->second));
635 label = (manage (new Label (i->first)));
636 label->show ();
637 midi_port_table_widgets.push_back (label);
638 midi_port_table.attach (*label, 0, 1, n+2, n+3,FILL|EXPAND, FILL );
640 tb = manage (new ToggleButton (_("online")));
641 tb->set_name ("OptionEditorToggleButton");
643 /* remember, we have to handle the i18n case where the relative
644 lengths of the strings in language N is different than in english.
647 if (strlen (_("offline")) > strlen (_("online"))) {
648 set_size_request_to_display_given_text (*tb, _("offline"), 15, 12);
649 } else {
650 set_size_request_to_display_given_text (*tb, _("online"), 15, 12);
653 if (i->second->input()) {
654 tb->set_active (!i->second->input()->offline());
655 tb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::port_online_toggled), i->second, tb));
656 i->second->input()->OfflineStatusChanged.connect (bind (mem_fun(*this, &OptionEditor::map_port_online), (*i).second, tb));
658 tb->show ();
659 midi_port_table_widgets.push_back (tb);
660 midi_port_table.attach (*tb, 1, 2, n+2, n+3, FILL|EXPAND, FILL);
662 tb = manage (new ToggleButton ());
663 tb->set_name ("OptionEditorToggleButton");
664 tb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::port_trace_in_toggled), (*i).second, tb));
665 tb->set_size_request (10, 10);
666 tb->show ();
667 midi_port_table_widgets.push_back (tb);
668 midi_port_table.attach (*tb, 2, 3, n+2, n+3, FILL|EXPAND, FILL);
670 tb = manage (new ToggleButton ());
671 tb->set_name ("OptionEditorToggleButton");
672 tb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::port_trace_out_toggled), (*i).second, tb));
673 tb->set_size_request (10, 10);
674 tb->show ();
675 midi_port_table_widgets.push_back (tb);
676 midi_port_table.attach (*tb, 3, 4, n+2, n+3, FILL|EXPAND, FILL);
678 rb = manage (new RadioButton ());
679 rb->set_name ("OptionEditorToggleButton");
680 if (n == 0) {
681 mtc_button_group = rb->get_group();
682 } else {
683 rb->set_group (mtc_button_group);
686 rb->show ();
687 midi_port_table_widgets.push_back (rb);
688 midi_port_table.attach (*rb, 4, 5, n+2, n+3, FILL|EXPAND, FILL);
689 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::mtc_port_chosen), (*i).second, rb, bb));
691 if (session && i->second == session->mtc_port()) {
692 rb->set_active (true);
695 rb = manage (new RadioButton ());
696 rb->set_name ("OptionEditorToggleButton");
697 if (n == 0) {
698 mmc_button_group = rb->get_group();
699 } else {
700 rb->set_group (mmc_button_group);
702 rb->show ();
703 midi_port_table_widgets.push_back (rb);
704 midi_port_table.attach (*rb, 6, 7, n+2, n+3, FILL|EXPAND, FILL);
705 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::mmc_port_chosen), (*i).second, rb, bb));
707 if (session && i->second == session->mmc_port()) {
708 rb->set_active (true);
711 rb = manage (new RadioButton ());
712 rb->set_name ("OptionEditorToggleButton");
713 if (n == 0) {
714 midi_button_group = rb->get_group();
715 } else {
716 rb->set_group (midi_button_group);
718 rb->show ();
719 midi_port_table_widgets.push_back (rb);
720 midi_port_table.attach (*rb, 8, 9, n+2, n+3, FILL|EXPAND, FILL);
721 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::midi_port_chosen), (*i).second, rb, bb));
723 if (session && i->second == session->midi_port()) {
724 rb->set_active (true);
729 midi_port_table.show();
732 void
733 OptionEditor::remove_midi_port (MIDI::Port* port)
735 MIDI::Manager::instance()->remove_port (port);
736 redisplay_midi_ports ();
739 void
740 OptionEditor::add_midi_port ()
742 MidiPortDialog dialog;
744 dialog.set_position (WIN_POS_MOUSE);
745 dialog.set_transient_for (*this);
747 dialog.show ();
749 int ret = dialog.run ();
751 switch (ret) {
752 case RESPONSE_ACCEPT:
753 break;
754 default:
755 return;
756 break;
759 Glib::ustring mode = dialog.port_mode_combo.get_active_text();
760 std::string smod;
762 if (mode == _("input")) {
763 smod = X_("input");
764 } else if (mode == (_("output"))) {
765 smod = X_("output");
766 } else {
767 smod = "duplex";
771 XMLNode node (X_("MIDI-port"));
773 node.add_property ("tag", dialog.port_name.get_text());
774 node.add_property ("device", X_("ardour")); // XXX this can't be right for all types
775 node.add_property ("type", MIDI::PortFactory::default_port_type());
776 node.add_property ("mode", smod);
778 if (MIDI::Manager::instance()->add_port (node) != 0) {
779 redisplay_midi_ports ();
783 bool
784 OptionEditor::port_removable (MIDI::Port *port)
786 if (!session) {
787 return true;
790 if (port == session->mtc_port() ||
791 port == session->mmc_port() ||
792 port == session->midi_port()) {
793 return false;
795 return true;
798 void
799 OptionEditor::mtc_port_chosen (MIDI::Port *port, Gtk::RadioButton* rb, Gtk::Button* bb)
801 if (session) {
802 if (rb->get_active()) {
803 session->set_mtc_port (port->name());
804 Config->set_mtc_port_name (port->name());
805 } else {
806 session->set_mtc_port ("");
808 bb->set_sensitive (port_removable (port));
812 void
813 OptionEditor::mmc_port_chosen (MIDI::Port* port, Gtk::RadioButton* rb, Gtk::Button* bb)
815 if (session) {
816 if (rb->get_active()) {
817 session->set_mmc_port (port->name());
818 Config->set_mtc_port_name (port->name());
819 } else {
820 session->set_mmc_port ("");
822 bb->set_sensitive (port_removable (port));
826 void
827 OptionEditor::midi_port_chosen (MIDI::Port* port, Gtk::RadioButton* rb, Gtk::Button* bb)
829 if (session) {
830 if (rb->get_active()) {
831 session->set_midi_port (port->name());
832 Config->set_midi_port_name (port->name());
833 } else {
834 session->set_midi_port ("");
836 bb->set_sensitive (port_removable (port));
840 void
841 OptionEditor::port_online_toggled (MIDI::Port* port, ToggleButton* tb)
843 bool wanted = tb->get_active();
845 if (port->input()) {
846 if (wanted != port->input()->offline()) {
847 port->input()->set_offline (wanted);
852 void
853 OptionEditor::map_port_online (MIDI::Port* port, ToggleButton* tb)
855 bool bstate = tb->get_active ();
857 if (port->input()) {
858 if (bstate != port->input()->offline()) {
859 if (port->input()->offline()) {
860 tb->set_label (_("offline"));
861 tb->set_active (false);
862 } else {
863 tb->set_label (_("online"));
864 tb->set_active (true);
870 void
871 OptionEditor::mmc_receive_device_id_adjusted ()
873 uint8_t id = (uint8_t) mmc_receive_device_id_spinner.get_value();
874 Config->set_mmc_receive_device_id (id);
877 void
878 OptionEditor::mmc_send_device_id_adjusted ()
880 uint8_t id = (uint8_t) mmc_send_device_id_spinner.get_value();
881 Config->set_mmc_send_device_id (id);
884 void
885 OptionEditor::port_trace_in_toggled (MIDI::Port* port, ToggleButton* tb)
887 bool trace = tb->get_active();
889 if (port->input()) {
890 if (port->input()->tracing() != trace) {
891 port->input()->trace (trace, &cerr, string (port->name()) + string (" input: "));
896 void
897 OptionEditor::port_trace_out_toggled (MIDI::Port* port, ToggleButton* tb)
899 bool trace = tb->get_active();
901 if (port->output()) {
902 if (port->output()->tracing() != trace) {
903 port->output()->trace (trace, &cerr, string (port->name()) + string (" output: "));
908 void
909 OptionEditor::save ()
911 /* XXX a bit odd that we save the entire session state here */
913 ui.save_state ("");
916 gint
917 OptionEditor::wm_close (GdkEventAny *ev)
919 save ();
920 hide ();
921 return TRUE;
924 void
925 OptionEditor::raid_path_changed ()
927 if (session) {
928 Config->set_raid_path (session_raid_entry.get_text());
932 void
933 OptionEditor::click_browse_clicked ()
935 SoundFileChooser sfdb (*this, _("Choose Click"), session);
937 sfdb.show_all ();
938 sfdb.present ();
940 int result = sfdb.run ();
942 if (result == Gtk::RESPONSE_OK) {
943 click_chosen(sfdb.get_filename());
947 void
948 OptionEditor::click_chosen (const string & path)
950 click_path_entry.set_text (path);
951 click_sound_changed ();
954 void
955 OptionEditor::click_emphasis_browse_clicked ()
957 SoundFileChooser sfdb (*this, _("Choose Click Emphasis"), session);
959 sfdb.show_all ();
960 sfdb.present ();
962 int result = sfdb.run ();
964 if (result == Gtk::RESPONSE_OK) {
965 click_emphasis_chosen (sfdb.get_filename());
969 void
970 OptionEditor::click_emphasis_chosen (const string & path)
972 click_emphasis_path_entry.set_text (path);
973 click_emphasis_sound_changed ();
976 void
977 OptionEditor::click_sound_changed ()
979 if (session) {
980 string path = click_path_entry.get_text();
982 if (path == Config->get_click_sound()) {
983 return;
986 strip_whitespace_edges (path);
988 if (path == _("internal")) {
989 Config->set_click_sound ("");
990 } else {
991 Config->set_click_sound (path);
996 void
997 OptionEditor::click_emphasis_sound_changed ()
999 if (session) {
1000 string path = click_emphasis_path_entry.get_text();
1002 if (path == Config->get_click_emphasis_sound()) {
1003 return;
1006 strip_whitespace_edges (path);
1008 if (path == _("internal")) {
1009 Config->set_click_emphasis_sound ("");
1010 } else {
1011 Config->set_click_emphasis_sound (path);
1016 void
1017 OptionEditor::clear_click_editor ()
1019 if (click_io_selector) {
1020 click_hpacker.remove (*click_io_selector);
1021 click_hpacker.remove (*click_gpm);
1022 delete click_io_selector;
1023 delete click_gpm;
1024 click_io_selector = 0;
1025 click_gpm = 0;
1029 void
1030 OptionEditor::setup_click_editor ()
1032 Label* label;
1034 if (first_click_setup) {
1036 click_path_entry.set_name ("OptionsEntry");
1037 click_emphasis_path_entry.set_name ("OptionsEntry");
1039 click_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_sound_changed));
1040 click_emphasis_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_emphasis_sound_changed));
1042 click_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_sound_changed));
1043 click_emphasis_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_emphasis_sound_changed));
1045 click_browse_button.set_name ("EditorGTKButton");
1046 click_emphasis_browse_button.set_name ("EditorGTKButton");
1048 click_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_browse_clicked));
1049 click_emphasis_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_emphasis_browse_clicked));
1051 click_packer.set_border_width (12);
1052 click_packer.set_spacing (5);
1054 click_table.set_col_spacings (10);
1056 label = manage(new Label(_("Click audio file")));
1057 label->set_name ("OptionsLabel");
1058 click_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL);
1059 click_table.attach (click_path_entry, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1060 click_table.attach (click_browse_button, 2, 3, 0, 1, FILL|EXPAND, FILL);
1062 label = manage(new Label(_("Click emphasis audiofile")));
1063 label->set_name ("OptionsLabel");
1064 click_table.attach (*label, 0, 1, 1, 2, FILL|EXPAND, FILL);
1065 click_table.attach (click_emphasis_path_entry, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1066 click_table.attach (click_emphasis_browse_button, 2, 3, 1, 2, FILL|EXPAND, FILL);
1068 click_packer.pack_start (click_table, false, false);
1069 click_packer.pack_start (click_hpacker, false, false);
1072 click_hpacker.set_spacing (10);
1074 first_click_setup = false;
1077 click_path_entry.set_sensitive (true);
1078 click_emphasis_path_entry.set_sensitive (true);
1080 click_io_selector = new IOSelector (*session, session->click_io(), false);
1081 click_gpm = new GainMeter (*session);
1082 click_gpm->set_io (session->click_io());
1084 click_hpacker.pack_start (*click_io_selector, false, false);
1085 click_hpacker.pack_start (*click_gpm, false, false);
1087 click_packer.show_all ();
1090 void
1091 OptionEditor::clear_auditioner_editor ()
1093 if (auditioner_io_selector) {
1094 audition_hpacker.remove (*auditioner_io_selector);
1095 audition_hpacker.remove (*auditioner_gpm);
1096 delete auditioner_io_selector;
1097 delete auditioner_gpm;
1098 auditioner_io_selector = 0;
1099 auditioner_gpm = 0;
1103 void
1104 OptionEditor::setup_auditioner_editor ()
1106 audition_packer.set_border_width (12);
1107 audition_packer.set_spacing (5);
1108 audition_hpacker.set_spacing (10);
1110 audition_label.set_name ("OptionEditorAuditionerLabel");
1111 audition_label.set_text (_("The auditioner is a dedicated mixer strip used\n"
1112 "for listening to specific regions outside the context\n"
1113 "of the overall mix. It can be connected just like any\n"
1114 "other mixer strip."));
1116 audition_packer.pack_start (audition_label, false, false, 10);
1117 audition_packer.pack_start (audition_hpacker, false, false);
1120 void
1121 OptionEditor::connect_audition_editor ()
1123 auditioner_io_selector = new IOSelector (*session, session->the_auditioner(), false);
1124 auditioner_gpm = new GainMeter (*session);
1125 auditioner_gpm->set_io (session->the_auditioner());
1127 audition_hpacker.pack_start (*auditioner_io_selector, false, false);
1128 audition_hpacker.pack_start (*auditioner_gpm, false, false);
1130 auditioner_io_selector->show_all ();
1131 auditioner_gpm->show_all ();
1134 bool
1135 OptionEditor::focus_out_event_handler (GdkEventFocus* ev, void (OptionEditor::*pmf)())
1137 (this->*pmf)();
1138 return false;
1141 static const struct {
1142 const char *name;
1143 guint modifier;
1144 } modifiers[] = {
1146 #ifdef GTKOSX
1148 /* Command = Meta
1149 Option/Alt = Mod1
1152 { "Shift", GDK_SHIFT_MASK },
1153 { "Command", GDK_META_MASK },
1154 { "Control", GDK_CONTROL_MASK },
1155 { "Option", GDK_MOD1_MASK },
1156 { "Command-Shift", GDK_MOD1_MASK|GDK_SHIFT_MASK },
1157 { "Command-Option", GDK_MOD1_MASK|GDK_MOD5_MASK },
1158 { "Shift-Option", GDK_SHIFT_MASK|GDK_MOD5_MASK },
1159 { "Shift-Command-Option", GDK_MOD5_MASK|GDK_SHIFT_MASK|GDK_MOD1_MASK },
1161 #else
1162 { "Shift", GDK_SHIFT_MASK },
1163 { "Control", GDK_CONTROL_MASK },
1164 { "Alt (Mod1)", GDK_MOD1_MASK },
1165 { "Control-Shift", GDK_CONTROL_MASK|GDK_SHIFT_MASK },
1166 { "Control-Alt", GDK_CONTROL_MASK|GDK_MOD1_MASK },
1167 { "Shift-Alt", GDK_SHIFT_MASK|GDK_MOD1_MASK },
1168 { "Control-Shift-Alt", GDK_CONTROL_MASK|GDK_SHIFT_MASK|GDK_MOD1_MASK },
1169 { "Mod2", GDK_MOD2_MASK },
1170 { "Mod3", GDK_MOD3_MASK },
1171 { "Mod4", GDK_MOD4_MASK },
1172 { "Mod5", GDK_MOD5_MASK },
1173 #endif
1174 { 0, 0 }
1177 void
1178 OptionEditor::setup_keyboard_options ()
1180 vector<string> dumb;
1181 Label* label;
1183 keyboard_mouse_table.set_border_width (12);
1184 keyboard_mouse_table.set_row_spacings (5);
1185 keyboard_mouse_table.set_col_spacings (5);
1187 /* internationalize and prepare for use with combos */
1189 for (int i = 0; modifiers[i].name; ++i) {
1190 dumb.push_back (_(modifiers[i].name));
1193 set_popdown_strings (edit_modifier_combo, dumb);
1194 edit_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::edit_modifier_chosen));
1196 for (int x = 0; modifiers[x].name; ++x) {
1197 if (modifiers[x].modifier == Keyboard::edit_modifier ()) {
1198 edit_modifier_combo.set_active_text (_(modifiers[x].name));
1199 break;
1203 label = manage (new Label (_("Edit using")));
1204 label->set_name ("OptionsLabel");
1205 label->set_alignment (1.0, 0.5);
1207 keyboard_mouse_table.attach (*label, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1208 keyboard_mouse_table.attach (edit_modifier_combo, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1210 label = manage (new Label (_("+ button")));
1211 label->set_name ("OptionsLabel");
1213 keyboard_mouse_table.attach (*label, 3, 4, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1214 keyboard_mouse_table.attach (edit_button_spin, 4, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
1216 edit_button_spin.set_name ("OptionsEntry");
1217 edit_button_adjustment.set_value (Keyboard::edit_button());
1218 edit_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::edit_button_changed));
1220 set_popdown_strings (delete_modifier_combo, dumb);
1221 delete_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::delete_modifier_chosen));
1223 for (int x = 0; modifiers[x].name; ++x) {
1224 if (modifiers[x].modifier == Keyboard::delete_modifier ()) {
1225 delete_modifier_combo.set_active_text (_(modifiers[x].name));
1226 break;
1230 label = manage (new Label (_("Delete using")));
1231 label->set_name ("OptionsLabel");
1232 label->set_alignment (1.0, 0.5);
1234 keyboard_mouse_table.attach (*label, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1235 keyboard_mouse_table.attach (delete_modifier_combo, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1237 label = manage (new Label (_("+ button")));
1238 label->set_name ("OptionsLabel");
1240 keyboard_mouse_table.attach (*label, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1241 keyboard_mouse_table.attach (delete_button_spin, 4, 5, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
1243 delete_button_spin.set_name ("OptionsEntry");
1244 delete_button_adjustment.set_value (Keyboard::delete_button());
1245 delete_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::delete_button_changed));
1247 set_popdown_strings (snap_modifier_combo, dumb);
1248 snap_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::snap_modifier_chosen));
1250 for (int x = 0; modifiers[x].name; ++x) {
1251 if (modifiers[x].modifier == (guint) Keyboard::snap_modifier ()) {
1252 snap_modifier_combo.set_active_text (_(modifiers[x].name));
1253 break;
1257 label = manage (new Label (_("Ignore snap using")));
1258 label->set_name ("OptionsLabel");
1259 label->set_alignment (1.0, 0.5);
1261 keyboard_mouse_table.attach (*label, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
1262 keyboard_mouse_table.attach (snap_modifier_combo, 1, 2, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
1264 vector<string> strs;
1266 for (std::map<std::string,std::string>::iterator bf = Keyboard::binding_files.begin(); bf != Keyboard::binding_files.end(); ++bf) {
1267 strs.push_back (bf->first);
1270 set_popdown_strings (keyboard_layout_selector, strs);
1271 keyboard_layout_selector.set_active_text (Keyboard::current_binding_name());
1272 keyboard_layout_selector.signal_changed().connect (mem_fun (*this, &OptionEditor::bindings_changed));
1274 label = manage (new Label (_("Keyboard layout")));
1275 label->set_name ("OptionsLabel");
1276 label->set_alignment (1.0, 0.5);
1278 keyboard_mouse_table.attach (*label, 0, 1, 3, 4, Gtk::FILL|Gtk::EXPAND, FILL);
1279 keyboard_mouse_table.attach (keyboard_layout_selector, 1, 2, 3, 4, Gtk::FILL|Gtk::EXPAND, FILL);
1282 void
1283 OptionEditor::bindings_changed ()
1285 string txt;
1287 txt = keyboard_layout_selector.get_active_text();
1289 for (std::map<string,string>::iterator i = Keyboard::binding_files.begin(); i != Keyboard::binding_files.end(); ++i) {
1290 if (txt == i->first) {
1291 if (Keyboard::load_keybindings (i->second)) {
1292 Keyboard::save_keybindings ();
1298 void
1299 OptionEditor::edit_modifier_chosen ()
1301 string txt;
1303 txt = edit_modifier_combo.get_active_text();
1305 for (int i = 0; modifiers[i].name; ++i) {
1306 if (txt == _(modifiers[i].name)) {
1307 Keyboard::set_edit_modifier (modifiers[i].modifier);
1308 break;
1313 void
1314 OptionEditor::delete_modifier_chosen ()
1316 string txt;
1318 txt = delete_modifier_combo.get_active_text();
1320 for (int i = 0; modifiers[i].name; ++i) {
1321 if (txt == _(modifiers[i].name)) {
1322 Keyboard::set_delete_modifier (modifiers[i].modifier);
1323 break;
1328 void
1329 OptionEditor::snap_modifier_chosen ()
1331 string txt;
1333 txt = snap_modifier_combo.get_active_text();
1335 for (int i = 0; modifiers[i].name; ++i) {
1336 if (txt == _(modifiers[i].name)) {
1337 Keyboard::set_snap_modifier (modifiers[i].modifier);
1338 break;
1343 void
1344 OptionEditor::delete_button_changed ()
1346 Keyboard::set_delete_button ((guint) delete_button_adjustment.get_value());
1349 void
1350 OptionEditor::edit_button_changed ()
1352 Keyboard::set_edit_button ((guint) edit_button_adjustment.get_value());
1355 void
1356 OptionEditor::parameter_changed (const char* parameter_name)
1358 ENSURE_GUI_THREAD (bind (mem_fun (*this, &OptionEditor::parameter_changed), parameter_name));
1360 #define PARAM_IS(x) (!strcmp (parameter_name, (x)))
1362 if (PARAM_IS ("timecode-source-is-synced")) {
1363 synced_timecode_button.set_active (Config->get_timecode_source_is_synced());
1364 } else if (PARAM_IS ("history-depth")) {
1365 int32_t depth = Config->get_history_depth();
1367 history_depth.set_value (depth);
1368 history_depth_spinner.set_sensitive (depth != 0);
1369 limit_history_button.set_active (depth != 0);
1371 } else if (PARAM_IS ("saved-history-depth")) {
1373 saved_history_depth.set_value (Config->get_saved_history_depth());
1375 } else if (PARAM_IS ("save-history")) {
1377 bool x = Config->get_save_history();
1379 save_history_button.set_active (x);
1380 saved_history_depth_spinner.set_sensitive (x);
1381 } else if (PARAM_IS ("font-scale")) {
1382 reset_dpi();