2 Copyright (C) 2001-2009 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.
20 #include <gtkmm/box.h>
21 #include <gtkmm/alignment.h>
22 #include "gtkmm2ext/utils.h"
24 #include "ardour/configuration.h"
25 #include "ardour/rc_configuration.h"
26 #include "ardour/utils.h"
27 #include "ardour/dB.h"
29 #include "option_editor.h"
30 #include "gui_thread.h"
36 using namespace Gtkmm2ext;
37 using namespace ARDOUR;
40 OptionEditorComponent::add_widget_to_page (OptionEditorPage* p, Gtk::Widget* w)
42 int const n = p->table.property_n_rows();
44 if (!_note.empty ()) {
48 p->table.resize (m, 3);
49 p->table.attach (*w, 1, 3, n, n + 1, FILL | EXPAND);
51 maybe_add_note (p, n + 1);
55 OptionEditorComponent::add_widgets_to_page (OptionEditorPage* p, Gtk::Widget* wa, Gtk::Widget* wb)
57 int const n = p->table.property_n_rows();
59 if (!_note.empty ()) {
63 p->table.resize (m, 3);
64 p->table.attach (*wa, 1, 2, n, n + 1, FILL);
65 p->table.attach (*wb, 2, 3, n, n + 1, FILL | EXPAND);
67 maybe_add_note (p, n + 1);
71 OptionEditorComponent::maybe_add_note (OptionEditorPage* p, int n)
73 if (!_note.empty ()) {
74 Gtk::Label* l = manage (new Gtk::Label (string_compose (X_("<i>%1</i>"), _note)));
75 l->set_use_markup (true);
76 p->table.attach (*l, 1, 3, n, n + 1, FILL | EXPAND);
81 OptionEditorComponent::set_note (string const & n)
86 OptionEditorHeading::OptionEditorHeading (string const & h)
89 s << "<b>" << h << "</b>";
90 _label = manage (new Label (s.str()));
91 _label->set_alignment (0, 0.5);
92 _label->set_use_markup (true);
96 OptionEditorHeading::add_to_page (OptionEditorPage* p)
98 int const n = p->table.property_n_rows();
99 p->table.resize (n + 2, 3);
101 p->table.attach (*manage (new Label ("")), 0, 3, n, n + 1, FILL | EXPAND);
102 p->table.attach (*_label, 0, 3, n + 1, n + 2, FILL | EXPAND);
106 OptionEditorBox::add_to_page (OptionEditorPage* p)
108 add_widget_to_page (p, _box);
111 BoolOption::BoolOption (string const & i, string const & n, sigc::slot<bool> g, sigc::slot<bool, bool> s)
116 _button = manage (new CheckButton (n));
117 _button->set_active (_get ());
118 _button->signal_toggled().connect (sigc::mem_fun (*this, &BoolOption::toggled));
122 BoolOption::add_to_page (OptionEditorPage* p)
124 add_widget_to_page (p, _button);
128 BoolOption::set_state_from_config ()
130 _button->set_active (_get ());
134 BoolOption::toggled ()
136 _set (_button->get_active ());
139 EntryOption::EntryOption (string const & i, string const & n, sigc::slot<string> g, sigc::slot<bool, string> s)
144 _label = manage (new Label (n + ":"));
145 _label->set_alignment (0, 0.5);
146 _entry = manage (new Entry);
147 _entry->signal_activate().connect (sigc::mem_fun (*this, &EntryOption::activated));
151 EntryOption::add_to_page (OptionEditorPage* p)
153 add_widgets_to_page (p, _label, _entry);
157 EntryOption::set_state_from_config ()
159 _entry->set_text (_get ());
163 EntryOption::activated ()
165 _set (_entry->get_text ());
168 FaderOption::FaderOption (string const & i, string const & n, sigc::slot<gain_t> g, sigc::slot<bool, gain_t> s)
170 , _db_adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain()), 0, 1, 0.01, 0.1)
174 _pix = ::get_icon (X_("fader_belt_h"));
176 throw failed_constructor ();
179 _pix_desensitised = ::get_icon (X_("fader_belt_h_desensitised"));
180 if (_pix_desensitised == 0) {
181 throw failed_constructor ();
184 _db_slider = manage (new HSliderController (_pix,
190 _label.set_text (n + ":");
191 _label.set_name (X_("OptionsLabel"));
193 _fader_centering_box.pack_start (*_db_slider, true, false);
195 _box.set_spacing (4);
196 _box.set_homogeneous (false);
197 _box.pack_start (_fader_centering_box, false, false);
198 _box.pack_start (_db_display, false, false);
201 set_size_request_to_display_given_text (_db_display, "-99.00", 12, 12);
203 _db_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &FaderOption::db_changed));
207 FaderOption::set_state_from_config ()
209 gain_t const val = _get ();
210 _db_adjustment.set_value (gain_to_slider_position_with_max (val, Config->get_max_gain ()));
215 snprintf (buf, sizeof (buf), "-inf");
217 snprintf (buf, sizeof (buf), "%.2f", accurate_coefficient_to_dB (val));
220 _db_display.set_text (buf);
224 FaderOption::db_changed ()
226 _set (slider_position_to_gain_with_max (_db_adjustment.get_value (), Config->get_max_gain()));
230 FaderOption::add_to_page (OptionEditorPage* p)
232 add_widgets_to_page (p, &_label, &_box);
235 ClockOption::ClockOption (string const & i, string const & n, sigc::slot<framecnt_t> g, sigc::slot<bool, framecnt_t> s)
237 , _clock (X_("timecode-offset"), false, X_(""), true, false, true, false)
241 _label.set_text (n + ":");
242 _label.set_alignment (0, 0.5);
243 _label.set_name (X_("OptionsLabel"));
247 ClockOption::set_state_from_config ()
249 _clock.set (_get ());
253 ClockOption::add_to_page (OptionEditorPage* p)
255 add_widgets_to_page (p, &_label, &_clock);
259 ClockOption::set_session (Session* s)
261 _clock.set_session (s);
264 OptionEditorPage::OptionEditorPage (Gtk::Notebook& n, std::string const & t)
267 table.set_spacings (4);
268 table.set_col_spacing (0, 32);
269 box.pack_start (table, false, false);
270 box.set_border_width (4);
271 n.append_page (box, t);
274 /** Construct an OptionEditor.
275 * @param o Configuration to edit.
276 * @param t Title for the dialog.
278 OptionEditor::OptionEditor (Configuration* c, std::string const & t)
279 : ArdourWindow (t), _config (c)
281 using namespace Notebook_Helpers;
283 set_default_size (300, 300);
284 set_wmclass (X_("ardour_preferences"), PROGRAM_NAME);
286 set_name ("Preferences");
287 add_events (Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);
289 set_border_width (4);
293 _notebook.set_show_tabs (true);
294 _notebook.set_show_border (true);
295 _notebook.set_name ("OptionsNotebook");
299 /* Watch out for changes to parameters */
300 _config->ParameterChanged.connect (config_connection, invalidator (*this), boost::bind (&OptionEditor::parameter_changed, this, _1), gui_context());
303 OptionEditor::~OptionEditor ()
305 for (std::map<std::string, OptionEditorPage*>::iterator i = _pages.begin(); i != _pages.end(); ++i) {
306 for (std::list<OptionEditorComponent*>::iterator j = i->second->components.begin(); j != i->second->components.end(); ++j) {
313 /** Called when a configuration parameter has been changed.
314 * @param p Parameter name.
317 OptionEditor::parameter_changed (std::string const & p)
319 ENSURE_GUI_THREAD (*this, &OptionEditor::parameter_changed, p)
321 for (std::map<std::string, OptionEditorPage*>::iterator i = _pages.begin(); i != _pages.end(); ++i) {
322 for (std::list<OptionEditorComponent*>::iterator j = i->second->components.begin(); j != i->second->components.end(); ++j) {
323 (*j)->parameter_changed (p);
328 /** Add a component to a given page.
329 * @param pn Page name (will be created if it doesn't already exist)
330 * @param o Component.
333 OptionEditor::add_option (std::string const & pn, OptionEditorComponent* o)
335 if (_pages.find (pn) == _pages.end()) {
336 _pages[pn] = new OptionEditorPage (_notebook, pn);
339 OptionEditorPage* p = _pages[pn];
340 p->components.push_back (o);
343 o->set_state_from_config ();
347 OptionEditor::set_current_page (string const & p)
350 while (i < _notebook.get_n_pages ()) {
351 if (_notebook.get_tab_label_text (*_notebook.get_nth_page (i)) == p) {
352 _notebook.set_current_page (i);
361 DirectoryOption::DirectoryOption (string const & i, string const & n, sigc::slot<string> g, sigc::slot<bool, string> s)
366 _file_chooser.set_action (Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
367 _file_chooser.signal_file_set().connect (sigc::mem_fun (*this, &DirectoryOption::file_set));
368 _file_chooser.signal_current_folder_changed().connect (sigc::mem_fun (*this, &DirectoryOption::current_folder_set));
373 DirectoryOption::set_state_from_config ()
375 _file_chooser.set_current_folder (_get ());
379 DirectoryOption::add_to_page (OptionEditorPage* p)
381 add_widgets_to_page (p, manage (new Label (_name)), &_file_chooser);
385 DirectoryOption::file_set ()
387 _set (_file_chooser.get_filename ());
391 DirectoryOption::current_folder_set ()
393 _set (_file_chooser.get_current_folder ());