X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Foption_editor.cc;h=f19babaae46b37ae126b58d328be77bfa15a9c83;hb=cf52d6e4b40111eb04b244ec054055a4ec15dbe0;hp=c261aba6498b1057ece02726a7d898216847dff4;hpb=3be16e8afbd891c0bfe7227158384ed0d127597f;p=ardour.git diff --git a/gtk2_ardour/option_editor.cc b/gtk2_ardour/option_editor.cc index c261aba649..f19babaae4 100644 --- a/gtk2_ardour/option_editor.cc +++ b/gtk2_ardour/option_editor.cc @@ -1,1466 +1,746 @@ /* - Copyright (C) 2001-2006 Paul Davis + Copyright (C) 2001-2009 Paul Davis - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include // for fontmap resolution control for GnomeCanvas -#include // for fontmap resolution control for GnomeCanvas - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include + +#include +#include +#include "gtkmm2ext/utils.h" + +#include "ardour/dB.h" +#include "ardour/rc_configuration.h" +#include "ardour/session.h" +#include "ardour/types.h" +#include "ardour/utils.h" + +#include "pbd/configuration.h" +#include "pbd/replace_all.h" +#include "pbd/strsplit.h" -#include "public_editor.h" -#include "keyboard.h" -#include "mixer_ui.h" -#include "ardour_ui.h" -#include "io_selector.h" -#include "gain_meter.h" -#include "sfdb_ui.h" -#include "utils.h" -#include "editing.h" -#include "option_editor.h" -#include "midi_port_dialog.h" #include "gui_thread.h" +#include "option_editor.h" +#include "public_editor.h" #include "utils.h" +#include "pbd/i18n.h" -#include "i18n.h" - -using namespace ARDOUR; -using namespace PBD; +using namespace std; using namespace Gtk; -using namespace Editing; using namespace Gtkmm2ext; -using namespace std; - -static vector positional_sync_strings; - -OptionEditor::OptionEditor (ARDOUR_UI& uip, PublicEditor& ed, Mixer_UI& mixui) - : ArdourDialog ("options editor", false), - ui (uip), - editor (ed), - mixer (mixui), - - /* Paths */ - path_table (11, 2), - - /* misc */ - - short_xfade_adjustment (0, 1.0, 500.0, 5.0, 100.0), - short_xfade_slider (short_xfade_adjustment), - destructo_xfade_adjustment (1.0, 1.0, 500.0, 1.0, 100.0), - destructo_xfade_slider (destructo_xfade_adjustment), - history_depth (20, -1, 100, 1.0, 10.0), - saved_history_depth (20, 0, 100, 1.0, 10.0), - history_depth_spinner (history_depth), - saved_history_depth_spinner (saved_history_depth), - limit_history_button (_("Limit undo history")), - save_history_button (_("Save undo history")), - - /* Sync */ - - smpte_offset_clock (X_("smpteoffset"), false, X_("SMPTEOffsetClock"), true, true), - smpte_offset_negative_button (_("SMPTE offset is negative")), - synced_timecode_button (_("Timecode source is sample-clock synced")), - - /* MIDI */ - - midi_port_table (4, 12), - mmc_receive_device_id_adjustment (0.0, 0.0, (double) 0x7f, 1.0, 16.0), - mmc_receive_device_id_spinner (mmc_receive_device_id_adjustment), - mmc_send_device_id_adjustment (0.0, 0.0, (double) 0x7f, 1.0, 16.0), - mmc_send_device_id_spinner (mmc_send_device_id_adjustment), - add_midi_port_button (_("Add new MIDI port")), - initial_program_change_adjustment (0.0, -1.0, (double) 0x7f, 1.0, 16.0), - initial_program_change_spinner (initial_program_change_adjustment), - - /* Click */ - - click_table (2, 3), - click_browse_button (_("Browse")), - click_emphasis_browse_button (_("Browse")), - - /* kbd/mouse */ - - keyboard_mouse_table (4, 4), - delete_button_adjustment (3, 1, 5), - delete_button_spin (delete_button_adjustment), - edit_button_adjustment (3, 1, 5), - edit_button_spin (edit_button_adjustment) +using namespace ARDOUR; +void +OptionEditorComponent::add_widget_to_page (OptionEditorPage* p, Gtk::Widget* w) { - using namespace Notebook_Helpers; - - first_click_setup = true; - click_io_selector = 0; - auditioner_io_selector = 0; - session = 0; - - WindowTitle title(Glib::get_application_name()); - title += _("Preferences"); - set_title(title.get_string()); - - set_default_size (300, 300); - set_wmclass (X_("ardour_preferences"), "Ardour"); - - set_name ("Preferences"); - add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK); - - VBox *vbox = get_vbox(); - set_border_width (3); - - vbox->set_spacing (4); - vbox->pack_start(notebook); - - signal_delete_event().connect (mem_fun(*this, &OptionEditor::wm_close)); - - notebook.set_show_tabs (true); - notebook.set_show_border (true); - notebook.set_name ("OptionsNotebook"); - - setup_sync_options(); - setup_path_options(); - setup_misc_options (); - setup_keyboard_options (); - setup_auditioner_editor (); - - notebook.pages().push_back (TabElem (sync_packer, _("Sync"))); - notebook.pages().push_back (TabElem (path_table, _("Paths/Files"))); - notebook.pages().push_back (TabElem (keyboard_mouse_table, _("Kbd/Mouse"))); - notebook.pages().push_back (TabElem (click_packer, _("Click"))); - notebook.pages().push_back (TabElem (audition_packer, _("Audition"))); - notebook.pages().push_back (TabElem (misc_packer, _("Misc"))); - - setup_midi_options (); - notebook.pages().push_back (TabElem (midi_packer, _("MIDI"))); + int const n = p->table.property_n_rows(); + int m = n + 1; + if (!_note.empty ()) { + ++m; + } - set_session (0); - show_all_children(); + p->table.resize (m, 3); + p->table.attach (*w, 1, 3, n, n + 1, FILL | EXPAND); - Config->map_parameters (mem_fun (*this, &OptionEditor::parameter_changed)); - Config->ParameterChanged.connect (mem_fun (*this, &OptionEditor::parameter_changed)); + maybe_add_note (p, n + 1); } void -OptionEditor::set_session (Session *s) +OptionEditorComponent::add_widgets_to_page (OptionEditorPage* p, Gtk::Widget* wa, Gtk::Widget* wb) { - clear_click_editor (); - clear_auditioner_editor (); - - click_path_entry.set_text (""); - click_emphasis_path_entry.set_text (""); - session_raid_entry.set_text (""); - - click_path_entry.set_sensitive (false); - click_emphasis_path_entry.set_sensitive (false); - session_raid_entry.set_sensitive (false); - - short_xfade_slider.set_sensitive (false); - smpte_offset_negative_button.set_sensitive (false); - - smpte_offset_clock.set_session (s); - - if ((session = s) == 0) { - return; + int const n = p->table.property_n_rows(); + int m = n + 1; + if (!_note.empty ()) { + ++m; } - click_path_entry.set_sensitive (true); - click_emphasis_path_entry.set_sensitive (true); - session_raid_entry.set_sensitive (true); - short_xfade_slider.set_sensitive (true); - smpte_offset_negative_button.set_sensitive (true); - - smpte_offset_clock.set_session (s); - smpte_offset_clock.set (s->smpte_offset (), true); - - smpte_offset_negative_button.set_active (session->smpte_offset_negative()); + p->table.resize (m, 3); + p->table.attach (*wa, 1, 2, n, n + 1, FILL); + p->table.attach (*wb, 2, 3, n, n + 1, FILL | EXPAND); - redisplay_midi_ports (); - - setup_click_editor (); - connect_audition_editor (); - - short_xfade_adjustment.set_value ((Crossfade::short_xfade_length() / (float) session->frame_rate()) * 1000.0); - - add_session_paths (); + maybe_add_note (p, n + 1); } -OptionEditor::~OptionEditor () +void +OptionEditorComponent::maybe_add_note (OptionEditorPage* p, int n) { + if (!_note.empty ()) { + Gtk::Label* l = manage (new Gtk::Label (string_compose (X_("%1"), _note))); + l->set_use_markup (true); + p->table.attach (*l, 1, 3, n, n + 1, FILL | EXPAND); + } } void -OptionEditor::setup_path_options() +OptionEditorComponent::set_note (string const & n) { - Gtk::Label* label; - - path_table.set_homogeneous (false); - path_table.set_border_width (12); - path_table.set_row_spacings (5); - - session_raid_entry.set_name ("OptionsEntry"); + _note = n; +} - session_raid_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::raid_path_changed)); +OptionEditorHeading::OptionEditorHeading (string const & h) +{ + std::stringstream s; + s << "" << h << ""; + _label = manage (left_aligned_label (s.str())); + _label->set_use_markup (true); +} - label = manage(new Label(_("session RAID path"))); - label->set_name ("OptionsLabel"); - path_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL); - path_table.attach (session_raid_entry, 1, 3, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL); +void +OptionEditorHeading::add_to_page (OptionEditorPage* p) +{ + int const n = p->table.property_n_rows(); + p->table.resize (n + 2, 3); - path_table.show_all(); + p->table.attach (*manage (new Label ("")), 0, 3, n, n + 1, FILL | EXPAND); + p->table.attach (*_label, 0, 3, n + 1, n + 2, FILL | EXPAND); } void -OptionEditor::add_session_paths () +OptionEditorBox::add_to_page (OptionEditorPage* p) { - click_path_entry.set_sensitive (true); - click_emphasis_path_entry.set_sensitive (true); - session_raid_entry.set_sensitive (true); + add_widget_to_page (p, _box); +} - if (Config->get_click_sound().empty()) { - click_path_entry.set_text (_("internal")); - } else { - click_path_entry.set_text (Config->get_click_sound()); +RcActionButton::RcActionButton (std::string const & t, const Glib::SignalProxy0< void >::SlotType & slot, std::string const & l) + : _label (NULL) +{ + _button = manage (new Button (t)); + _button->signal_clicked().connect (slot); + if (!l.empty ()) { + _label = manage (right_aligned_label (l)); } +} - if (Config->get_click_emphasis_sound().empty()) { - click_emphasis_path_entry.set_text (_("internal")); +void +RcActionButton::add_to_page (OptionEditorPage *p) +{ + int const n = p->table.property_n_rows(); + int m = n + 1; + p->table.resize (m, 3); + if (_label) { + p->table.attach (*_label, 1, 2, n, n + 1, FILL | EXPAND); + p->table.attach (*_button, 2, 3, n, n + 1, FILL | EXPAND); } else { - click_emphasis_path_entry.set_text (Config->get_click_emphasis_sound()); + p->table.attach (*_button, 1, 3, n, n + 1, FILL | EXPAND); } - - session_raid_entry.set_text(session->raid_path()); } -static void -font_scale_changed (Gtk::Adjustment* adj) +RcConfigDisplay::RcConfigDisplay (string const & i, string const & n, sigc::slot g, char s) + : _get (g) + , _id (i) + , _sep (s) { - Config->set_font_scale((long)floor (adj->get_value() * 1024)); - reset_dpi(); + _label = manage (right_aligned_label (n)); + _info = manage (new Label); + _info-> set_line_wrap (true); + set_state_from_config (); } void -OptionEditor::setup_misc_options () +RcConfigDisplay::set_state_from_config () { - Gtk::HBox* hbox; - Label* label; - -#ifndef GTKOSX - /* font scaling does nothing with GDK/Quartz */ - - Gtk::Adjustment* dpi_adj = new Gtk::Adjustment ((double)Config->get_font_scale() / 1024, 50, 250, 1, 10); - Gtk::HScale * dpi_range = new Gtk::HScale (*dpi_adj); - - label = manage (new Label (_("Font Scaling"))); - label->set_name ("OptionsLabel"); - - dpi_range->set_update_policy (Gtk::UPDATE_DISCONTINUOUS); - dpi_adj->signal_value_changed().connect (bind (sigc::ptr_fun (font_scale_changed), dpi_adj)); - - hbox = manage (new HBox); - hbox->set_border_width (5); - hbox->set_spacing (10); - hbox->pack_start (*label, false, false); - hbox->pack_start (*dpi_range, true, true); - misc_packer.pack_start (*hbox, false, false); -#endif - - label = manage (new Label (_("Short crossfade length (msecs)"))); - label->set_name ("OptionsLabel"); - - hbox = manage (new HBox); - hbox->set_border_width (5); - hbox->set_spacing (10); - hbox->pack_start (*label, false, false); - hbox->pack_start (short_xfade_slider, true, true); - misc_packer.pack_start (*hbox, false, false); - - short_xfade_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::short_xfade_adjustment_changed)); - - label = manage (new Label (_("Destructive crossfade length (msecs)"))); - label->set_name ("OptionsLabel"); - - hbox = manage (new HBox); - hbox->set_border_width (5); - hbox->set_spacing (10); - hbox->pack_start (*label, false, false); - hbox->pack_start (destructo_xfade_slider, true, true); - misc_packer.pack_start (*hbox, false, false); - - - destructo_xfade_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::destructo_xfade_adjustment_changed)); - - hbox = manage (new HBox); - hbox->set_border_width (5); - hbox->set_spacing (10); - hbox->pack_start (limit_history_button, false, false); - misc_packer.pack_start (*hbox, false, false); - - label = manage (new Label (_("History depth (commands)"))); - label->set_name ("OptionsLabel"); - - hbox = manage (new HBox); - hbox->set_border_width (5); - hbox->set_spacing (10); - hbox->pack_start (*label, false, false); - hbox->pack_start (history_depth_spinner, false, false); - misc_packer.pack_start (*hbox, false, false); - - history_depth.signal_value_changed().connect (mem_fun (*this, &OptionEditor::history_depth_changed)); - saved_history_depth.signal_value_changed().connect (mem_fun (*this, &OptionEditor::saved_history_depth_changed)); - save_history_button.signal_toggled().connect (mem_fun (*this, &OptionEditor::save_history_toggled)); - limit_history_button.signal_toggled().connect (mem_fun (*this, &OptionEditor::limit_history_toggled)); - - hbox = manage (new HBox); - hbox->set_border_width (5); - hbox->set_spacing (10); - hbox->pack_start (save_history_button, false, false); - misc_packer.pack_start (*hbox, false, false); - - label = manage (new Label (_("Saved history depth (commands)"))); - label->set_name ("OptionsLabel"); - - hbox = manage (new HBox); - hbox->set_border_width (5); - hbox->set_spacing (10); - hbox->pack_start (*label, false, false); - hbox->pack_start (saved_history_depth_spinner, false, false); - misc_packer.pack_start (*hbox, false, false); - - short_xfade_slider.set_update_policy (UPDATE_DISCONTINUOUS); - destructo_xfade_slider.set_update_policy (UPDATE_DISCONTINUOUS); - - destructo_xfade_adjustment.set_value (Config->get_destructive_xfade_msecs()); - - misc_packer.show_all (); + string p = _get(); + if (_sep) { + std::replace (p.begin(), p.end(), _sep, '\n'); + } + _info->set_text (p); } void -OptionEditor::limit_history_toggled () +RcConfigDisplay::parameter_changed (std::string const & p) { - bool x = limit_history_button.get_active(); - - if (!x) { - Config->set_history_depth (0); - history_depth_spinner.set_sensitive (false); - } else { - if (Config->get_history_depth() == 0) { - /* get back to a sane default */ - Config->set_history_depth (20); - } - history_depth_spinner.set_sensitive (true); + if (p == _id) { + set_state_from_config (); } } void -OptionEditor::save_history_toggled () +RcConfigDisplay::add_to_page (OptionEditorPage *p) { - bool x = save_history_button.get_active(); - - if (x != Config->get_save_history()) { - Config->set_save_history (x); - saved_history_depth_spinner.set_sensitive (x); - } + int const n = p->table.property_n_rows(); + int m = n + 1; + p->table.resize (m, 3); + p->table.attach (*_label, 1, 2, n, n + 1, FILL | EXPAND); + p->table.attach (*_info, 2, 3, n, n + 1, FILL | EXPAND); } -void -OptionEditor::history_depth_changed() + +BoolOption::BoolOption (string const & i, string const & n, sigc::slot g, sigc::slot s) + : Option (i, n), + _get (g), + _set (s) { - Config->set_history_depth ((int32_t) floor (history_depth.get_value())); + _button = manage (new CheckButton); + _label = manage (new Label); + _label->set_markup (n); + _button->add (*_label); + _button->set_active (_get ()); + _button->signal_toggled().connect (sigc::mem_fun (*this, &BoolOption::toggled)); } void -OptionEditor::saved_history_depth_changed() +BoolOption::add_to_page (OptionEditorPage* p) { - Config->set_saved_history_depth ((int32_t) floor (saved_history_depth.get_value())); + add_widget_to_page (p, _button); } void -OptionEditor::short_xfade_adjustment_changed () +BoolOption::set_state_from_config () { - if (session) { - float val = short_xfade_adjustment.get_value(); - - /* val is in msecs */ - - Crossfade::set_short_xfade_length ((nframes_t) floor (session->frame_rate() * (val / 1000.0))); - } + _button->set_active (_get ()); } void -OptionEditor::destructo_xfade_adjustment_changed () +BoolOption::toggled () { - float val = destructo_xfade_adjustment.get_value(); - - /* val is in msecs */ - - - Config->set_destructive_xfade_msecs ((uint32_t) floor (val)); - - if (session) { - SndFileSource::setup_standard_crossfades (session->frame_rate()); + if (!_set (_button->get_active ())) { + _button->set_active (_get ()); } } -void -OptionEditor::setup_sync_options () +RouteDisplayBoolOption::RouteDisplayBoolOption (string const & i, string const & n, sigc::slot g, sigc::slot s) + : BoolOption (i, n, g, s) { - HBox* hbox; - vector dumb; - - smpte_offset_clock.set_mode (AudioClock::SMPTE); - smpte_offset_clock.ValueChanged.connect (mem_fun(*this, &OptionEditor::smpte_offset_chosen)); - - smpte_offset_negative_button.set_name ("OptionEditorToggleButton"); - - smpte_offset_negative_button.unset_flags (Gtk::CAN_FOCUS); - - Label *smpte_offset_label = manage (new Label (_("SMPTE Offset"))); - smpte_offset_label->set_name("OptionsLabel"); - - hbox = manage (new HBox); - hbox->set_border_width (5); - hbox->set_spacing (10); - hbox->pack_start (*smpte_offset_label, false, false); - hbox->pack_start (smpte_offset_clock, false, false); - hbox->pack_start (smpte_offset_negative_button, false, false); - - sync_packer.pack_start (*hbox, false, false); - sync_packer.pack_start (synced_timecode_button, false, false); - - smpte_offset_negative_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::smpte_offset_negative_clicked)); - synced_timecode_button.signal_toggled().connect (mem_fun(*this, &OptionEditor::synced_timecode_toggled)); } void -OptionEditor::smpte_offset_negative_clicked () +RouteDisplayBoolOption::toggled () { - if (session) { - session->set_smpte_offset_negative (smpte_offset_negative_button.get_active()); - } + DisplaySuspender ds; + BoolOption::toggled (); } -void -OptionEditor::synced_timecode_toggled () +EntryOption::EntryOption (string const & i, string const & n, sigc::slot g, sigc::slot s) + : Option (i, n), + _get (g), + _set (s) { - bool x; - - if ((x = synced_timecode_button.get_active()) != Config->get_timecode_source_is_synced()) { - Config->set_timecode_source_is_synced (x); - Config->save_state(); - } + _label = manage (left_aligned_label (n + ":")); + _entry = manage (new Entry); + _entry->signal_activate().connect (sigc::mem_fun (*this, &EntryOption::activated)); + _entry->signal_focus_out_event().connect (sigc::mem_fun (*this, &EntryOption::focus_out)); + _entry->signal_insert_text().connect (sigc::mem_fun (*this, &EntryOption::filter_text)); } void -OptionEditor::smpte_offset_chosen() +EntryOption::add_to_page (OptionEditorPage* p) { - if (session) { - nframes_t frames = smpte_offset_clock.current_duration(); - session->set_smpte_offset (frames); - } + add_widgets_to_page (p, _label, _entry); } - void -OptionEditor::setup_midi_options () +EntryOption::set_state_from_config () { - HBox* hbox; - Label* label; - - midi_port_table.set_row_spacings (6); - midi_port_table.set_col_spacings (10); - - redisplay_midi_ports (); - - mmc_receive_device_id_adjustment.set_value (Config->get_mmc_receive_device_id()); - mmc_send_device_id_adjustment.set_value (Config->get_mmc_send_device_id()); - - mmc_receive_device_id_adjustment.signal_value_changed().connect (mem_fun (*this, &OptionEditor::mmc_receive_device_id_adjusted)); - mmc_send_device_id_adjustment.signal_value_changed().connect (mem_fun (*this, &OptionEditor::mmc_send_device_id_adjusted)); - - hbox = manage (new HBox); - hbox->set_border_width (6); - hbox->pack_start (midi_port_table, true, false); - - midi_packer.pack_start (*hbox, false, false); - add_midi_port_button.set_label ("Add MIDI port"); - midi_packer.pack_start (add_midi_port_button, false, false); - - hbox = manage (new HBox); - hbox->set_border_width (6); - hbox->set_spacing (6); - label = (manage (new Label (_("Inbound MMC Device ID")))); - hbox->pack_start (mmc_receive_device_id_spinner, false, false); - hbox->pack_start (*label, false, false); - midi_packer.pack_start (*hbox, false, false); - - mmc_receive_device_id_spinner.set_value(Config->get_mmc_receive_device_id ()); - - hbox = manage (new HBox); - hbox->set_border_width (6); - hbox->set_spacing (6); - label = (manage (new Label (_("Outbound MMC Device ID")))); - hbox->pack_start (mmc_send_device_id_spinner, false, false); - hbox->pack_start (*label, false, false); - midi_packer.pack_start (*hbox, false, false); - - mmc_send_device_id_spinner.set_value(Config->get_mmc_send_device_id ()); - - hbox = manage (new HBox); - hbox->set_border_width (6); - hbox->set_spacing (6); - label = (manage (new Label (_("Startup program change")))); - hbox->pack_start (initial_program_change_spinner, false, false); - hbox->pack_start (*label, false, false); - midi_packer.pack_start (*hbox, false, false); - - initial_program_change_spinner.set_value (Config->get_initial_program_change()); - initial_program_change_adjustment.signal_value_changed().connect (mem_fun (*this, &OptionEditor::initial_program_change_adjusted)); - - add_midi_port_button.signal_clicked().connect (mem_fun (*this, &OptionEditor::add_midi_port)); + _entry->set_text (_get ()); } void -OptionEditor::initial_program_change_adjusted () +EntryOption::set_sensitive (bool s) { - Config->set_initial_program_change (((int32_t) floor (initial_program_change_adjustment.get_value())) & 0x7f); + _entry->set_sensitive (s); } void -OptionEditor::redisplay_midi_ports () +EntryOption::filter_text (const Glib::ustring&, int*) { - MIDI::Manager::PortMap::const_iterator i; - const MIDI::Manager::PortMap& ports = MIDI::Manager::instance()->get_midi_ports(); - int n; - - /* remove all existing widgets */ - - // XXX broken in gtkmm 2.10 - // midi_port_table.clear (); - - for (vector::iterator w = midi_port_table_widgets.begin(); w != midi_port_table_widgets.end(); ++w) { - midi_port_table.remove (**w); + std::string text = _entry->get_text (); + for (size_t i = 0; i < _invalid.length(); ++i) { + text.erase (std::remove(text.begin(), text.end(), _invalid.at(i)), text.end()); } - - midi_port_table_widgets.clear (); - - midi_port_table.resize (ports.size() + 4, 12); - - Gtk::Label* label; - - label = (manage (new Label (_("Port")))); - label->show (); - midi_port_table_widgets.push_back (label); - midi_port_table.attach (*label, 0, 1, 0, 1); - label = (manage (new Label (_("Offline")))); - label->show (); - midi_port_table_widgets.push_back (label); - midi_port_table.attach (*label, 1, 2, 0, 1); - label = (manage (new Label (_("Trace\nInput")))); - label->show (); - midi_port_table_widgets.push_back (label); - midi_port_table.attach (*label, 2, 3, 0, 1); - label = (manage (new Label (_("Trace\nOutput")))); - label->show (); - midi_port_table_widgets.push_back (label); - midi_port_table.attach (*label, 3, 4, 0, 1); - label = (manage (new Label (_("MTC")))); - label->show (); - midi_port_table_widgets.push_back (label); - midi_port_table.attach (*label, 4, 5, 0, 1); - label = (manage (new Label (_("MIDI\nClock")))); - label->show (); - midi_port_table_widgets.push_back (label); - midi_port_table.attach (*label, 6, 7, 0, 1); - label = (manage (new Label (_("MMC")))); - label->show (); - midi_port_table_widgets.push_back (label); - midi_port_table.attach (*label, 8, 9, 0, 1); - label = (manage (new Label (_("MIDI Parameter\nControl")))); - label->show (); - midi_port_table_widgets.push_back (label); - midi_port_table.attach (*label, 10, 11, 0, 1); - - Gtk::HSeparator* hsep = (manage (new HSeparator())); - hsep->show (); - midi_port_table_widgets.push_back (hsep); - midi_port_table.attach (*hsep, 0, 11, 1, 2); - Gtk::VSeparator* vsep = (manage (new VSeparator())); - vsep->show (); - midi_port_table_widgets.push_back (vsep); - midi_port_table.attach (*vsep, 5, 6, 0, 8); - vsep = (manage (new VSeparator())); - vsep->show (); - midi_port_table_widgets.push_back (vsep); - midi_port_table.attach (*vsep, 7, 8, 0, 8); - vsep = (manage (new VSeparator())); - vsep->show (); - midi_port_table_widgets.push_back (vsep); - midi_port_table.attach (*vsep, 9, 10, 0, 8); - - for (n = 0, i = ports.begin(); i != ports.end(); ++n, ++i) { - - ToggleButton* tb; - RadioButton* rb; - Button* bb; - - /* the remove button. create early so we can pass it to various callbacks */ - - bb = manage (new Button (Stock::REMOVE)); - bb->set_name ("OptionEditorToggleButton"); - bb->show (); - midi_port_table_widgets.push_back (bb); - midi_port_table.attach (*bb, 11, 12, n+2, n+3, FILL|EXPAND, FILL); - bb->signal_clicked().connect (bind (mem_fun(*this, &OptionEditor::remove_midi_port), i->second)); - bb->set_sensitive (port_removable (i->second)); - - label = (manage (new Label (i->first))); - label->show (); - midi_port_table_widgets.push_back (label); - midi_port_table.attach (*label, 0, 1, n+2, n+3,FILL|EXPAND, FILL ); - - tb = manage (new ToggleButton (_("online"))); - tb->set_name ("OptionEditorToggleButton"); - - /* remember, we have to handle the i18n case where the relative - lengths of the strings in language N is different than in english. - */ - - if (strlen (_("offline")) > strlen (_("online"))) { - set_size_request_to_display_given_text (*tb, _("offline"), 15, 12); - } else { - set_size_request_to_display_given_text (*tb, _("online"), 15, 12); - } - - if (i->second->input()) { - tb->set_active (!i->second->input()->offline()); - tb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::port_online_toggled), i->second, tb)); - i->second->input()->OfflineStatusChanged.connect (bind (mem_fun(*this, &OptionEditor::map_port_online), (*i).second, tb)); - } - tb->show (); - midi_port_table_widgets.push_back (tb); - midi_port_table.attach (*tb, 1, 2, n+2, n+3, FILL|EXPAND, FILL); - - // Trace MIDI Input - tb = manage (new ToggleButton ()); - tb->set_name ("OptionEditorToggleButton"); - tb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::port_trace_in_toggled), (*i).second, tb)); - tb->set_size_request (10, 10); - tb->show (); - midi_port_table_widgets.push_back (tb); - midi_port_table.attach (*tb, 2, 3, n+2, n+3, FILL|EXPAND, FILL); - - // Trace MIDI Output - tb = manage (new ToggleButton ()); - tb->set_name ("OptionEditorToggleButton"); - tb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::port_trace_out_toggled), (*i).second, tb)); - tb->set_size_request (10, 10); - tb->show (); - midi_port_table_widgets.push_back (tb); - midi_port_table.attach (*tb, 3, 4, n+2, n+3, FILL|EXPAND, FILL); - - // MTC Radio Button - rb = manage (new RadioButton ()); - rb->set_name ("OptionEditorToggleButton"); - if (n == 0) { - mtc_button_group = rb->get_group(); - } else { - rb->set_group (mtc_button_group); - } - rb->show (); - midi_port_table_widgets.push_back (rb); - midi_port_table.attach (*rb, 4, 5, n+2, n+3, FILL|EXPAND, FILL); - rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::mtc_port_chosen), (*i).second, rb, bb)); - - if (session && i->second == session->mtc_port()) { - rb->set_active (true); - } - - // MIDI Clock Radio Button - rb = manage (new RadioButton ()); - rb->set_name ("OptionEditorToggleButton"); - if (n == 0) { - midi_clock_button_group = rb->get_group(); - } else { - rb->set_group (midi_clock_button_group); - } - rb->show (); - midi_port_table_widgets.push_back (rb); - midi_port_table.attach (*rb, 6, 7, n+2, n+3, FILL|EXPAND, FILL); - rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::midi_clock_port_chosen), (*i).second, rb, bb)); - - if (session && i->second == session->midi_clock_port()) { - rb->set_active (true); - } - - rb = manage (new RadioButton ()); - rb->set_name ("OptionEditorToggleButton"); - if (n == 0) { - mmc_button_group = rb->get_group(); - } else { - rb->set_group (mmc_button_group); - } - rb->show (); - midi_port_table_widgets.push_back (rb); - midi_port_table.attach (*rb, 8, 9, n+2, n+3, FILL|EXPAND, FILL); - rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::mmc_port_chosen), (*i).second, rb, bb)); - - if (session && i->second == session->mmc_port()) { - rb->set_active (true); - } - - rb = manage (new RadioButton ()); - rb->set_name ("OptionEditorToggleButton"); - if (n == 0) { - midi_button_group = rb->get_group(); - } else { - rb->set_group (midi_button_group); - } - rb->show (); - midi_port_table_widgets.push_back (rb); - midi_port_table.attach (*rb, 10, 11, n+2, n+3, FILL|EXPAND, FILL); - rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::midi_port_chosen), (*i).second, rb, bb)); - - if (session && i->second == session->midi_port()) { - rb->set_active (true); - } - + if (text != _entry->get_text ()) { + _entry->set_text (text); } - - midi_port_table.show(); } void -OptionEditor::remove_midi_port (MIDI::Port* port) +EntryOption::activated () { - MIDI::Manager::instance()->remove_port (port); - redisplay_midi_ports (); + _set (_entry->get_text ()); } -void -OptionEditor::add_midi_port () +bool +EntryOption::focus_out (GdkEventFocus*) { - MidiPortDialog dialog; - - dialog.set_position (WIN_POS_MOUSE); - dialog.set_transient_for (*this); - - dialog.show (); - - int ret = dialog.run (); - - switch (ret) { - case RESPONSE_ACCEPT: - break; - default: - return; - break; - } - - Glib::ustring mode = dialog.port_mode_combo.get_active_text(); - std::string smod; - - if (mode == _("input")) { - smod = X_("input"); - } else if (mode == (_("output"))) { - smod = X_("output"); - } else { - smod = "duplex"; - } - - - XMLNode node (X_("MIDI-port")); - - node.add_property ("tag", dialog.port_name.get_text()); - node.add_property ("device", X_("ardour")); // XXX this can't be right for all types - node.add_property ("type", MIDI::PortFactory::default_port_type()); - node.add_property ("mode", smod); - - if (MIDI::Manager::instance()->add_port (node) != 0) { - redisplay_midi_ports (); - } + _set (_entry->get_text ()); + return true; } -bool -OptionEditor::port_removable (MIDI::Port *port) +/** Construct a BoolComboOption. + * @param i id + * @param n User-visible name. + * @param t Text to give for the variable being true. + * @param f Text to give for the variable being false. + * @param g Slot to get the variable's value. + * @param s Slot to set the variable's value. + */ +BoolComboOption::BoolComboOption ( + string const & i, string const & n, string const & t, string const & f, + sigc::slot g, sigc::slot s + ) + : Option (i, n) + , _get (g) + , _set (s) { - if (!session) { - return true; - } + _label = manage (new Label (n + ":")); + _label->set_alignment (0, 0.5); + _combo = manage (new ComboBoxText); - if (port == session->mtc_port() || - port == session->mmc_port() || - port == session->midi_port()) { - return false; - } - return true; + /* option 0 is the false option */ + _combo->append_text (f); + /* and option 1 is the true */ + _combo->append_text (t); + + _combo->signal_changed().connect (sigc::mem_fun (*this, &BoolComboOption::changed)); } void -OptionEditor::mtc_port_chosen (MIDI::Port *port, Gtk::RadioButton* rb, Gtk::Button* bb) +BoolComboOption::set_state_from_config () { - if (session) { - if (rb->get_active()) { - session->set_mtc_port (port->name()); - Config->set_mtc_port_name (port->name()); - } else { - session->set_mtc_port (""); - } - bb->set_sensitive (port_removable (port)); - } + _combo->set_active (_get() ? 1 : 0); } void -OptionEditor::mmc_port_chosen (MIDI::Port* port, Gtk::RadioButton* rb, Gtk::Button* bb) +BoolComboOption::add_to_page (OptionEditorPage* p) { - if (session) { - if (rb->get_active()) { - session->set_mmc_port (port->name()); - Config->set_mtc_port_name (port->name()); - } else { - session->set_mmc_port (""); - } - bb->set_sensitive (port_removable (port)); - } + add_widgets_to_page (p, _label, _combo); } void -OptionEditor::midi_port_chosen (MIDI::Port* port, Gtk::RadioButton* rb, Gtk::Button* bb) +BoolComboOption::changed () { - if (session) { - if (rb->get_active()) { - session->set_midi_port (port->name()); - Config->set_midi_port_name (port->name()); - } else { - session->set_midi_port (""); - } - bb->set_sensitive (port_removable (port)); - } + _set (_combo->get_active_row_number () == 0 ? false : true); } void -OptionEditor::midi_clock_port_chosen (MIDI::Port *port, Gtk::RadioButton* rb, Gtk::Button* bb) +BoolComboOption::set_sensitive (bool yn) { - if (session) { - if (rb->get_active()) { - session->set_midi_clock_port (port->name()); - Config->set_midi_clock_port_name (port->name()); - } else { - session->set_midi_clock_port (""); - } - bb->set_sensitive (port_removable (port)); - } + _combo->set_sensitive (yn); } -void -OptionEditor::port_online_toggled (MIDI::Port* port, ToggleButton* tb) + + +FaderOption::FaderOption (string const & i, string const & n, sigc::slot g, sigc::slot s) + : Option (i, n) + , _db_adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain()), 0, 1, 0.01, 0.1) + , _get (g) + , _set (s) { - bool wanted = tb->get_active(); + _db_slider = manage (new HSliderController (&_db_adjustment, boost::shared_ptr(), 115, 18)); - if (port->input()) { - if (wanted != port->input()->offline()) { - port->input()->set_offline (wanted); - } - } + _label.set_text (n + ":"); + _label.set_alignment (0, 0.5); + _label.set_name (X_("OptionsLabel")); + + _fader_centering_box.pack_start (*_db_slider, true, false); + + _box.set_spacing (4); + _box.set_homogeneous (false); + _box.pack_start (_fader_centering_box, false, false); + _box.pack_start (_db_display, false, false); + _box.show_all (); + + set_size_request_to_display_given_text (_db_display, "-99.00", 12, 12); + + _db_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &FaderOption::db_changed)); + _db_display.signal_activate().connect (sigc::mem_fun (*this, &FaderOption::on_activate)); + _db_display.signal_key_press_event().connect (sigc::mem_fun (*this, &FaderOption::on_key_press), false); } void -OptionEditor::map_port_online (MIDI::Port* port, ToggleButton* tb) +FaderOption::set_state_from_config () { - bool bstate = tb->get_active (); + gain_t const val = _get (); + _db_adjustment.set_value (gain_to_slider_position_with_max (val, Config->get_max_gain ())); - if (port->input()) { - if (bstate != port->input()->offline()) { - if (port->input()->offline()) { - tb->set_label (_("offline")); - tb->set_active (false); - } else { - tb->set_label (_("online")); - tb->set_active (true); - } - } + char buf[16]; + + if (val == 0.0) { + snprintf (buf, sizeof (buf), "-inf"); + } else { + snprintf (buf, sizeof (buf), "%.2f", accurate_coefficient_to_dB (val)); } -} -void -OptionEditor::mmc_receive_device_id_adjusted () -{ - uint8_t id = (uint8_t) mmc_receive_device_id_spinner.get_value(); - Config->set_mmc_receive_device_id (id); + _db_display.set_text (buf); } void -OptionEditor::mmc_send_device_id_adjusted () +FaderOption::db_changed () { - uint8_t id = (uint8_t) mmc_send_device_id_spinner.get_value(); - Config->set_mmc_send_device_id (id); + _set (slider_position_to_gain_with_max (_db_adjustment.get_value (), Config->get_max_gain())); } void -OptionEditor::port_trace_in_toggled (MIDI::Port* port, ToggleButton* tb) +FaderOption::on_activate () { - bool trace = tb->get_active(); + float db_val = atof (_db_display.get_text ().c_str ()); + gain_t coeff_val = dB_to_coefficient (db_val); - if (port->input()) { - if (port->input()->tracing() != trace) { - port->input()->trace (trace, &cerr, string (port->name()) + string (" input: ")); - } - } + _db_adjustment.set_value (gain_to_slider_position_with_max (coeff_val, Config->get_max_gain ())); } -void -OptionEditor::port_trace_out_toggled (MIDI::Port* port, ToggleButton* tb) +bool +FaderOption::on_key_press (GdkEventKey* ev) { - bool trace = tb->get_active(); - - if (port->output()) { - if (port->output()->tracing() != trace) { - port->output()->trace (trace, &cerr, string (port->name()) + string (" output: ")); - } + if (ARDOUR_UI_UTILS::key_is_legal_for_numeric_entry (ev->keyval)) { + /* drop through to normal handling */ + return false; } + /* illegal key for gain entry */ + return true; } void -OptionEditor::save () +FaderOption::add_to_page (OptionEditorPage* p) { - /* XXX a bit odd that we save the entire session state here */ - - ui.save_state (""); + add_widgets_to_page (p, &_label, &_box); } -gint -OptionEditor::wm_close (GdkEventAny *ev) +ClockOption::ClockOption (string const & i, string const & n, sigc::slot g, sigc::slot s) + : Option (i, n) + , _clock (X_("timecode-offset"), true, X_(""), true, false, true, false) + , _get (g) + , _set (s) { - save (); - hide (); - return TRUE; + _label.set_text (n + ":"); + _label.set_alignment (0, 0.5); + _label.set_name (X_("OptionsLabel")); + _clock.ValueChanged.connect (sigc::mem_fun (*this, &ClockOption::save_clock_time)); } void -OptionEditor::raid_path_changed () +ClockOption::set_state_from_config () { - if (session) { - Config->set_raid_path (session_raid_entry.get_text()); + Timecode::Time TC; + framepos_t when; + if (!Timecode::parse_timecode_format(_get(), TC)) { + _clock.set (0, true); } + TC.rate = _session->frames_per_timecode_frame(); + TC.drop = _session->timecode_drop_frames(); + _session->timecode_to_sample(TC, when, false, false); + if (TC.negative) { when=-when; } + _clock.set (when, true); } void -OptionEditor::click_browse_clicked () +ClockOption::save_clock_time () { - SoundFileChooser sfdb (*this, _("Choose Click"), session); - - sfdb.show_all (); - sfdb.present (); - - int result = sfdb.run (); - - if (result == Gtk::RESPONSE_OK) { - click_chosen(sfdb.get_filename()); - } + Timecode::Time TC; + _session->sample_to_timecode(_clock.current_time(), TC, false, false); + _set (Timecode::timecode_format_time(TC)); } void -OptionEditor::click_chosen (const string & path) +ClockOption::add_to_page (OptionEditorPage* p) { - click_path_entry.set_text (path); - click_sound_changed (); + add_widgets_to_page (p, &_label, &_clock); } void -OptionEditor::click_emphasis_browse_clicked () +ClockOption::set_session (Session* s) { - SoundFileChooser sfdb (*this, _("Choose Click Emphasis"), session); - - sfdb.show_all (); - sfdb.present (); - - int result = sfdb.run (); - - if (result == Gtk::RESPONSE_OK) { - click_emphasis_chosen (sfdb.get_filename()); - } + _session = s; + _clock.set_session (s); } -void -OptionEditor::click_emphasis_chosen (const string & path) +OptionEditorPage::OptionEditorPage (Gtk::Notebook& n, std::string const & t) + : table (1, 3) { - click_emphasis_path_entry.set_text (path); - click_emphasis_sound_changed (); + table.set_spacings (4); + table.set_col_spacing (0, 32); + box.pack_start (table, false, false); + box.set_border_width (4); + n.append_page (box, t); } -void -OptionEditor::click_sound_changed () +/** Construct an OptionEditor. + * @param o Configuration to edit. + * @param t Title for the dialog. + */ +OptionEditor::OptionEditor (PBD::Configuration* c) + : _config (c) + , option_tree (TreeStore::create (option_columns)) + , option_treeview (option_tree) { - if (session) { - string path = click_path_entry.get_text(); + using namespace Notebook_Helpers; - if (path == Config->get_click_sound()) { - return; - } + _notebook.set_show_tabs (false); + _notebook.set_show_border (true); + _notebook.set_name ("OptionsNotebook"); - strip_whitespace_edges (path); + option_treeview.append_column ("", option_columns.name); + option_treeview.set_enable_search(true); + option_treeview.set_search_column(0); + option_treeview.set_name ("OptionsTreeView"); + option_treeview.set_headers_visible (false); - if (path == _("internal")) { - Config->set_click_sound (""); - } else { - Config->set_click_sound (path); - } - } + option_treeview.get_selection()->set_mode (Gtk::SELECTION_SINGLE); + option_treeview.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &OptionEditor::treeview_row_selected)); + + /* Watch out for changes to parameters */ + _config->ParameterChanged.connect (config_connection, invalidator (*this), boost::bind (&OptionEditor::parameter_changed, this, _1), gui_context()); } -void -OptionEditor::click_emphasis_sound_changed () +OptionEditor::~OptionEditor () { - if (session) { - string path = click_emphasis_path_entry.get_text(); - - if (path == Config->get_click_emphasis_sound()) { - return; - } - - strip_whitespace_edges (path); - - if (path == _("internal")) { - Config->set_click_emphasis_sound (""); - } else { - Config->set_click_emphasis_sound (path); + for (std::map::iterator i = _pages.begin(); i != _pages.end(); ++i) { + for (std::list::iterator j = i->second->components.begin(); j != i->second->components.end(); ++j) { + delete *j; } + delete i->second; } } +/** Called when a configuration parameter has been changed. + * @param p Parameter name. + */ void -OptionEditor::clear_click_editor () +OptionEditor::parameter_changed (std::string const & p) { - if (click_io_selector) { - click_hpacker.remove (*click_io_selector); - click_hpacker.remove (*click_gpm); - delete click_io_selector; - delete click_gpm; - click_io_selector = 0; - click_gpm = 0; - } -} + ENSURE_GUI_THREAD (*this, &OptionEditor::parameter_changed, p) -void -OptionEditor::setup_click_editor () -{ - Label* label; - - if (first_click_setup) { - - click_path_entry.set_name ("OptionsEntry"); - click_emphasis_path_entry.set_name ("OptionsEntry"); - - click_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_sound_changed)); - click_emphasis_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_emphasis_sound_changed)); - - click_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_sound_changed)); - click_emphasis_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_emphasis_sound_changed)); - - click_browse_button.set_name ("EditorGTKButton"); - click_emphasis_browse_button.set_name ("EditorGTKButton"); - - click_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_browse_clicked)); - click_emphasis_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_emphasis_browse_clicked)); - - click_packer.set_border_width (12); - click_packer.set_spacing (5); - - click_table.set_col_spacings (10); - - label = manage(new Label(_("Click audio file"))); - label->set_name ("OptionsLabel"); - click_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL); - click_table.attach (click_path_entry, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL); - click_table.attach (click_browse_button, 2, 3, 0, 1, FILL|EXPAND, FILL); - - label = manage(new Label(_("Click emphasis audiofile"))); - label->set_name ("OptionsLabel"); - click_table.attach (*label, 0, 1, 1, 2, FILL|EXPAND, FILL); - click_table.attach (click_emphasis_path_entry, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL); - click_table.attach (click_emphasis_browse_button, 2, 3, 1, 2, FILL|EXPAND, FILL); - - click_packer.pack_start (click_table, false, false); - click_packer.pack_start (click_hpacker, false, false); - - - click_hpacker.set_spacing (10); - - first_click_setup = false; + for (std::map::iterator i = _pages.begin(); i != _pages.end(); ++i) { + for (std::list::iterator j = i->second->components.begin(); j != i->second->components.end(); ++j) { + (*j)->parameter_changed (p); + } } - - click_path_entry.set_sensitive (true); - click_emphasis_path_entry.set_sensitive (true); - - click_io_selector = new IOSelector (*session, session->click_io(), false); - click_gpm = new GainMeter (*session); - click_gpm->set_io (session->click_io()); - - click_hpacker.pack_start (*click_io_selector, false, false); - click_hpacker.pack_start (*click_gpm, false, false); - - click_table.set_col_spacings (10); - - label = manage(new Label(_("Click audio file"))); - label->set_name ("OptionsLabel"); - click_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL); - click_table.attach (click_path_entry, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL); - click_table.attach (click_browse_button, 2, 3, 0, 1, FILL|EXPAND, FILL); - - label = manage(new Label(_("Click emphasis audiofile"))); - label->set_name ("OptionsLabel"); - click_table.attach (*label, 0, 1, 1, 2, FILL|EXPAND, FILL); - click_table.attach (click_emphasis_path_entry, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL); - click_table.attach (click_emphasis_browse_button, 2, 3, 1, 2, FILL|EXPAND, FILL); - - click_packer.show_all (); } void -OptionEditor::clear_auditioner_editor () +OptionEditor::treeview_row_selected () { - if (auditioner_io_selector) { - audition_hpacker.remove (*auditioner_io_selector); - audition_hpacker.remove (*auditioner_gpm); - delete auditioner_io_selector; - delete auditioner_gpm; - auditioner_io_selector = 0; - auditioner_gpm = 0; + Glib::RefPtr selection = option_treeview.get_selection(); + TreeModel::iterator iter = selection->get_selected(); + if(iter) { + TreeModel::Row row = *iter; + Gtk::Widget* w = row[option_columns.widget]; + if (w) { + _notebook.set_current_page (_notebook.page_num (*w)); + } } } void -OptionEditor::setup_auditioner_editor () +OptionEditor::add_path_to_treeview (std::string const & pn, Gtk::Widget& widget) { - audition_packer.set_border_width (12); - audition_packer.set_spacing (5); - audition_hpacker.set_spacing (10); - - audition_label.set_name ("OptionEditorAuditionerLabel"); - audition_label.set_text (_("The auditioner is a dedicated mixer strip used\n" - "for listening to specific regions outside the context\n" - "of the overall mix. It can be connected just like any\n" - "other mixer strip.")); - - audition_packer.pack_start (audition_label, false, false, 10); - audition_packer.pack_start (audition_hpacker, false, false); -} + option_treeview.set_model (Glib::RefPtr()); -void -OptionEditor::connect_audition_editor () -{ - auditioner_io_selector = new IOSelector (*session, session->the_auditioner(), false); - auditioner_gpm = new GainMeter (*session); - auditioner_gpm->set_io (session->the_auditioner()); + if (pn.find ('/') == std::string::npos) { + /* new top level item in tree */ - audition_hpacker.pack_start (*auditioner_io_selector, false, false); - audition_hpacker.pack_start (*auditioner_gpm, false, false); + TreeModel::iterator new_row = option_tree->append (); + TreeModel::Row row = *new_row; + row[option_columns.name] = pn; + row[option_columns.widget] = &widget; - auditioner_io_selector->show_all (); - auditioner_gpm->show_all (); -} + } else { -bool -OptionEditor::focus_out_event_handler (GdkEventFocus* ev, void (OptionEditor::*pmf)()) -{ - (this->*pmf)(); - return false; -} + /* find parent */ -static const struct { - const char *name; - guint modifier; -} modifiers[] = { - -#ifdef GTKOSX - - /* Command = Meta - Option/Alt = Mod1 - */ - - { "Shift", GDK_SHIFT_MASK }, - { "Command", GDK_META_MASK }, - { "Control", GDK_CONTROL_MASK }, - { "Option", GDK_MOD1_MASK }, - { "Command-Shift", GDK_MOD1_MASK|GDK_SHIFT_MASK }, - { "Command-Option", GDK_MOD1_MASK|GDK_MOD5_MASK }, - { "Shift-Option", GDK_SHIFT_MASK|GDK_MOD5_MASK }, - { "Shift-Command-Option", GDK_MOD5_MASK|GDK_SHIFT_MASK|GDK_MOD1_MASK }, - -#else - { "Shift", GDK_SHIFT_MASK }, - { "Control", GDK_CONTROL_MASK }, - { "Alt (Mod1)", GDK_MOD1_MASK }, - { "Control-Shift", GDK_CONTROL_MASK|GDK_SHIFT_MASK }, - { "Control-Alt", GDK_CONTROL_MASK|GDK_MOD1_MASK }, - { "Shift-Alt", GDK_SHIFT_MASK|GDK_MOD1_MASK }, - { "Control-Shift-Alt", GDK_CONTROL_MASK|GDK_SHIFT_MASK|GDK_MOD1_MASK }, - { "Mod2", GDK_MOD2_MASK }, - { "Mod3", GDK_MOD3_MASK }, - { "Mod4", GDK_MOD4_MASK }, - { "Mod5", GDK_MOD5_MASK }, -#endif - { 0, 0 } -}; + /* split page name, which is actually a path, into each + * component + */ -void -OptionEditor::setup_keyboard_options () -{ - vector dumb; - Label* label; + std::vector components; + split (pn, components, '/'); - keyboard_mouse_table.set_border_width (12); - keyboard_mouse_table.set_row_spacings (5); - keyboard_mouse_table.set_col_spacings (5); + /* start with top level children */ - /* internationalize and prepare for use with combos */ + typedef Gtk::TreeModel::Children type_children; //minimise code length. + type_children children = option_tree->children(); - for (int i = 0; modifiers[i].name; ++i) { - dumb.push_back (_(modifiers[i].name)); - } + /* foreach path component ... */ - set_popdown_strings (edit_modifier_combo, dumb); - edit_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::edit_modifier_chosen)); + for (std::vector::const_iterator s = components.begin(); s != components.end(); ) { - for (int x = 0; modifiers[x].name; ++x) { - if (modifiers[x].modifier == Keyboard::edit_modifier ()) { - edit_modifier_combo.set_active_text (_(modifiers[x].name)); - break; - } - } + bool component_found = false; - label = manage (new Label (_("Edit using"))); - label->set_name ("OptionsLabel"); - label->set_alignment (1.0, 0.5); + type_children::iterator iter; - keyboard_mouse_table.attach (*label, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL); - keyboard_mouse_table.attach (edit_modifier_combo, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL); + /* look through the children at this level */ - label = manage (new Label (_("+ button"))); - label->set_name ("OptionsLabel"); + for (iter = children.begin(); iter != children.end(); ++iter) { + Gtk::TreeModel::Row row = *iter; - keyboard_mouse_table.attach (*label, 3, 4, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL); - keyboard_mouse_table.attach (edit_button_spin, 4, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL); + std::string row_name = row[option_columns.name]; + if (row_name == (*s)) { - edit_button_spin.set_name ("OptionsEntry"); - edit_button_adjustment.set_value (Keyboard::edit_button()); - edit_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::edit_button_changed)); + /* found it */ - set_popdown_strings (delete_modifier_combo, dumb); - delete_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::delete_modifier_chosen)); + component_found = true; - for (int x = 0; modifiers[x].name; ++x) { - if (modifiers[x].modifier == Keyboard::delete_modifier ()) { - delete_modifier_combo.set_active_text (_(modifiers[x].name)); - break; - } - } + /* reset children to point to + * the children of this row + */ - label = manage (new Label (_("Delete using"))); - label->set_name ("OptionsLabel"); - label->set_alignment (1.0, 0.5); + children = row.children(); + break; + } + } - keyboard_mouse_table.attach (*label, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL); - keyboard_mouse_table.attach (delete_modifier_combo, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL); + if (!component_found) { - label = manage (new Label (_("+ button"))); - label->set_name ("OptionsLabel"); + /* missing component. If it is the last + * one, append a real page. Otherwise + * just put an entry in the tree model + * since it is a navigational/sorting + * component. + */ - keyboard_mouse_table.attach (*label, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL); - keyboard_mouse_table.attach (delete_button_spin, 4, 5, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL); + TreeModel::iterator new_row = option_tree->append (children); + TreeModel::Row row = *new_row; + row[option_columns.name] = *s; - delete_button_spin.set_name ("OptionsEntry"); - delete_button_adjustment.set_value (Keyboard::delete_button()); - delete_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::delete_button_changed)); + ++s; - set_popdown_strings (snap_modifier_combo, dumb); - snap_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::snap_modifier_chosen)); + if (s == components.end()) { + row[option_columns.widget] = &widget; + } else { + row[option_columns.widget] = 0; + } - for (int x = 0; modifiers[x].name; ++x) { - if (modifiers[x].modifier == (guint) Keyboard::snap_modifier ()) { - snap_modifier_combo.set_active_text (_(modifiers[x].name)); - break; - } - } + children = row.children (); - label = manage (new Label (_("Ignore snap using"))); - label->set_name ("OptionsLabel"); - label->set_alignment (1.0, 0.5); + } else { - keyboard_mouse_table.attach (*label, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL); - keyboard_mouse_table.attach (snap_modifier_combo, 1, 2, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL); + /* component found, just move on to the + * next one. children has already been + * reset appropriately. + */ - vector strs; + ++s; + } + } - for (std::map::iterator bf = Keyboard::binding_files.begin(); bf != Keyboard::binding_files.end(); ++bf) { - strs.push_back (bf->first); } - set_popdown_strings (keyboard_layout_selector, strs); - keyboard_layout_selector.set_active_text (Keyboard::current_binding_name()); - keyboard_layout_selector.signal_changed().connect (mem_fun (*this, &OptionEditor::bindings_changed)); - - label = manage (new Label (_("Keyboard layout"))); - label->set_name ("OptionsLabel"); - label->set_alignment (1.0, 0.5); - - keyboard_mouse_table.attach (*label, 0, 1, 3, 4, Gtk::FILL|Gtk::EXPAND, FILL); - keyboard_mouse_table.attach (keyboard_layout_selector, 1, 2, 3, 4, Gtk::FILL|Gtk::EXPAND, FILL); + option_treeview.set_model (option_tree); + option_treeview.expand_all (); } +/** Add a component to a given page. + * @param pn Page name (will be created if it doesn't already exist) + * @param o Component. + */ void -OptionEditor::bindings_changed () +OptionEditor::add_option (std::string const & pn, OptionEditorComponent* o) { - string txt; + if (_pages.find (pn) == _pages.end()) { + OptionEditorPage* oep = new OptionEditorPage (_notebook, pn); + _pages[pn] = oep; - txt = keyboard_layout_selector.get_active_text(); - - for (std::map::iterator i = Keyboard::binding_files.begin(); i != Keyboard::binding_files.end(); ++i) { - if (txt == i->first) { - if (Keyboard::load_keybindings (i->second)) { - Keyboard::save_keybindings (); - } - } + add_path_to_treeview (pn, oep->box); } -} -void -OptionEditor::edit_modifier_chosen () -{ - string txt; - - txt = edit_modifier_combo.get_active_text(); + OptionEditorPage* p = _pages[pn]; + p->components.push_back (o); - for (int i = 0; modifiers[i].name; ++i) { - if (txt == _(modifiers[i].name)) { - Keyboard::set_edit_modifier (modifiers[i].modifier); - break; - } - } + o->add_to_page (p); + o->set_state_from_config (); } +/** Add a new page + * @param pn Page name (will be created if it doesn't already exist) + * @param w widget that fills the page + */ void -OptionEditor::delete_modifier_chosen () +OptionEditor::add_page (std::string const & pn, Gtk::Widget& w) { - string txt; - - txt = delete_modifier_combo.get_active_text(); - - for (int i = 0; modifiers[i].name; ++i) { - if (txt == _(modifiers[i].name)) { - Keyboard::set_delete_modifier (modifiers[i].modifier); - break; - } + if (_pages.find (pn) == _pages.end()) { + OptionEditorPage* oep = new OptionEditorPage (_notebook, pn); + _pages[pn] = oep; + add_path_to_treeview (pn, oep->box); } + + OptionEditorPage* p = _pages[pn]; + p->box.pack_start (w, true, true); } void -OptionEditor::snap_modifier_chosen () +OptionEditor::set_current_page (string const & p) { - string txt; - - txt = snap_modifier_combo.get_active_text(); - - for (int i = 0; modifiers[i].name; ++i) { - if (txt == _(modifiers[i].name)) { - Keyboard::set_snap_modifier (modifiers[i].modifier); - break; + int i = 0; + while (i < _notebook.get_n_pages ()) { + if (_notebook.get_tab_label_text (*_notebook.get_nth_page (i)) == p) { + _notebook.set_current_page (i); + return; } + + ++i; } } -void -OptionEditor::delete_button_changed () + +DirectoryOption::DirectoryOption (string const & i, string const & n, sigc::slot g, sigc::slot s) + : Option (i, n) + , _get (g) + , _set (s) { - Keyboard::set_delete_button ((guint) delete_button_adjustment.get_value()); + _file_chooser.set_action (Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); + _file_chooser.signal_selection_changed().connect (sigc::mem_fun (*this, &DirectoryOption::selection_changed)); } + void -OptionEditor::edit_button_changed () +DirectoryOption::set_state_from_config () { - Keyboard::set_edit_button ((guint) edit_button_adjustment.get_value()); + _file_chooser.set_current_folder (poor_mans_glob(_get ())); } void -OptionEditor::fixup_combo_size (Gtk::ComboBoxText& combo, vector& strings) +DirectoryOption::add_to_page (OptionEditorPage* p) { - /* find the widest string */ - - string::size_type maxlen = 0; - string maxstring; - - for (vector::iterator i = strings.begin(); i != strings.end(); ++i) { - string::size_type l; - - if ((l = (*i).length()) > maxlen) { - maxlen = l; - maxstring = *i; - } - } - - /* try to include ascenders and descenders */ - - if (maxstring.length() > 2) { - maxstring[0] = 'g'; - maxstring[1] = 'l'; - } - - const guint32 FUDGE = 10; // Combo's are stupid - they steal space from the entry for the button - - set_size_request_to_display_given_text (combo, maxstring.c_str(), 10 + FUDGE, 10); + Gtk::Label *label = manage (new Label (_name)); + label->set_alignment (0, 0.5); + label->set_name (X_("OptionsLabel")); + add_widgets_to_page (p, label, &_file_chooser); } void -OptionEditor::parameter_changed (const char* parameter_name) +DirectoryOption::selection_changed () { - ENSURE_GUI_THREAD (bind (mem_fun (*this, &OptionEditor::parameter_changed), parameter_name)); - -#define PARAM_IS(x) (!strcmp (parameter_name, (x))) + _set (poor_mans_glob(_file_chooser.get_filename ())); +} - if (PARAM_IS ("timecode-source-is-synced")) { - synced_timecode_button.set_active (Config->get_timecode_source_is_synced()); - } else if (PARAM_IS ("history-depth")) { - int32_t depth = Config->get_history_depth(); +/*--------------------------*/ - history_depth.set_value (depth); - history_depth_spinner.set_sensitive (depth != 0); - limit_history_button.set_active (depth != 0); +OptionEditorContainer::OptionEditorContainer (PBD::Configuration* c, string const& str) + : OptionEditor (c) +{ + set_border_width (4); + hpacker.pack_start (treeview(), false, false); + hpacker.pack_start (notebook(), true, true); + pack_start (hpacker, true, true); - } else if (PARAM_IS ("saved-history-depth")) { + hpacker.show_all (); + show (); +} - saved_history_depth.set_value (Config->get_saved_history_depth()); +OptionEditorWindow::OptionEditorWindow (PBD::Configuration* c, string const& str) + : OptionEditor (c) + , ArdourWindow (str) +{ + container.set_border_width (4); + hpacker.pack_start (treeview(), false, false); + hpacker.pack_start (notebook(), true, true); - } else if (PARAM_IS ("save-history")) { + container.pack_start (hpacker, true, true); - bool x = Config->get_save_history(); + hpacker.show_all (); + container.show (); - save_history_button.set_active (x); - saved_history_depth_spinner.set_sensitive (x); - } else if (PARAM_IS ("font-scale")) { - reset_dpi(); - } + add (container); }