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"
28 #include "ardour/session.h"
30 #include "option_editor.h"
31 #include "gui_thread.h"
37 using namespace Gtkmm2ext;
38 using namespace ARDOUR;
41 OptionEditorComponent::add_widget_to_page (OptionEditorPage* p, Gtk::Widget* w)
43 int const n = p->table.property_n_rows();
45 if (!_note.empty ()) {
49 p->table.resize (m, 3);
50 p->table.attach (*w, 1, 3, n, n + 1, FILL | EXPAND);
52 maybe_add_note (p, n + 1);
56 OptionEditorComponent::add_widgets_to_page (OptionEditorPage* p, Gtk::Widget* wa, Gtk::Widget* wb)
58 int const n = p->table.property_n_rows();
60 if (!_note.empty ()) {
64 p->table.resize (m, 3);
65 p->table.attach (*wa, 1, 2, n, n + 1, FILL);
66 p->table.attach (*wb, 2, 3, n, n + 1, FILL | EXPAND);
68 maybe_add_note (p, n + 1);
72 OptionEditorComponent::maybe_add_note (OptionEditorPage* p, int n)
74 if (!_note.empty ()) {
75 Gtk::Label* l = manage (new Gtk::Label (string_compose (X_("<i>%1</i>"), _note)));
76 l->set_use_markup (true);
77 p->table.attach (*l, 1, 3, n, n + 1, FILL | EXPAND);
82 OptionEditorComponent::set_note (string const & n)
87 OptionEditorHeading::OptionEditorHeading (string const & h)
90 s << "<b>" << h << "</b>";
91 _label = manage (left_aligned_label (s.str()));
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);
117 _label = manage (new Label);
118 _label->set_markup (n);
119 _button->add (*_label);
120 _button->set_active (_get ());
121 _button->signal_toggled().connect (sigc::mem_fun (*this, &BoolOption::toggled));
125 BoolOption::add_to_page (OptionEditorPage* p)
127 add_widget_to_page (p, _button);
131 BoolOption::set_state_from_config ()
133 _button->set_active (_get ());
137 BoolOption::toggled ()
139 _set (_button->get_active ());
142 EntryOption::EntryOption (string const & i, string const & n, sigc::slot<string> g, sigc::slot<bool, string> s)
147 _label = manage (left_aligned_label (n + ":"));
148 _entry = manage (new Entry);
149 _entry->signal_activate().connect (sigc::mem_fun (*this, &EntryOption::activated));
153 EntryOption::add_to_page (OptionEditorPage* p)
155 add_widgets_to_page (p, _label, _entry);
159 EntryOption::set_state_from_config ()
161 _entry->set_text (_get ());
165 EntryOption::activated ()
167 _set (_entry->get_text ());
170 /** Construct a BoolComboOption.
172 * @param n User-visible name.
173 * @param t Text to give for the variable being true.
174 * @param f Text to give for the variable being false.
175 * @param g Slot to get the variable's value.
176 * @param s Slot to set the variable's value.
178 BoolComboOption::BoolComboOption (
179 string const & i, string const & n, string const & t, string const & f,
180 sigc::slot<bool> g, sigc::slot<bool, bool> s
186 _label = manage (new Label (n + ":"));
187 _label->set_alignment (0, 0.5);
188 _combo = manage (new ComboBoxText);
190 /* option 0 is the false option */
191 _combo->append_text (f);
192 /* and option 1 is the true */
193 _combo->append_text (t);
195 _combo->signal_changed().connect (sigc::mem_fun (*this, &BoolComboOption::changed));
199 BoolComboOption::set_state_from_config ()
201 _combo->set_active (_get() ? 1 : 0);
205 BoolComboOption::add_to_page (OptionEditorPage* p)
207 add_widgets_to_page (p, _label, _combo);
211 BoolComboOption::changed ()
213 _set (_combo->get_active_row_number () == 0 ? false : true);
217 BoolComboOption::set_sensitive (bool yn)
219 _combo->set_sensitive (yn);
224 FaderOption::FaderOption (string const & i, string const & n, sigc::slot<gain_t> g, sigc::slot<bool, gain_t> s)
226 , _db_adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain()), 0, 1, 0.01, 0.1)
230 _db_slider = manage (new HSliderController (&_db_adjustment, 115, 18, false));
232 _label.set_text (n + ":");
233 _label.set_name (X_("OptionsLabel"));
235 _fader_centering_box.pack_start (*_db_slider, true, false);
237 _box.set_spacing (4);
238 _box.set_homogeneous (false);
239 _box.pack_start (_fader_centering_box, false, false);
240 _box.pack_start (_db_display, false, false);
243 set_size_request_to_display_given_text (_db_display, "-99.00", 12, 12);
245 _db_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &FaderOption::db_changed));
249 FaderOption::set_state_from_config ()
251 gain_t const val = _get ();
252 _db_adjustment.set_value (gain_to_slider_position_with_max (val, Config->get_max_gain ()));
257 snprintf (buf, sizeof (buf), "-inf");
259 snprintf (buf, sizeof (buf), "%.2f", accurate_coefficient_to_dB (val));
262 _db_display.set_text (buf);
266 FaderOption::db_changed ()
268 _set (slider_position_to_gain_with_max (_db_adjustment.get_value (), Config->get_max_gain()));
272 FaderOption::add_to_page (OptionEditorPage* p)
274 add_widgets_to_page (p, &_label, &_box);
277 ClockOption::ClockOption (string const & i, string const & n, sigc::slot<std::string> g, sigc::slot<bool, std::string> s)
279 , _clock (X_("timecode-offset"), false, X_(""), true, false, true, false)
283 _label.set_text (n + ":");
284 _label.set_alignment (0, 0.5);
285 _label.set_name (X_("OptionsLabel"));
286 _clock.ValueChanged.connect (sigc::mem_fun (*this, &ClockOption::save_clock_time));
290 ClockOption::set_state_from_config ()
294 if (!Timecode::parse_timecode_format(_get(), TC)) {
295 _clock.set (0, true);
297 TC.rate = _session->frames_per_timecode_frame();
298 TC.drop = _session->timecode_drop_frames();
299 _session->timecode_to_sample(TC, when, false, false);
300 if (TC.negative) { when=-when; }
301 _clock.set (when, true);
305 ClockOption::save_clock_time ()
308 _session->sample_to_timecode(_clock.current_time(), TC, false, false);
309 _set (Timecode::timecode_format_time(TC));
313 ClockOption::add_to_page (OptionEditorPage* p)
315 add_widgets_to_page (p, &_label, &_clock);
319 ClockOption::set_session (Session* s)
322 _clock.set_session (s);
325 OptionEditorPage::OptionEditorPage (Gtk::Notebook& n, std::string const & t)
328 table.set_spacings (4);
329 table.set_col_spacing (0, 32);
330 box.pack_start (table, false, false);
331 box.set_border_width (4);
332 n.append_page (box, t);
335 /** Construct an OptionEditor.
336 * @param o Configuration to edit.
337 * @param t Title for the dialog.
339 OptionEditor::OptionEditor (Configuration* c, std::string const & t)
340 : ArdourWindow (t), _config (c)
342 using namespace Notebook_Helpers;
344 set_default_size (300, 300);
345 set_wmclass (X_("ardour_preferences"), PROGRAM_NAME);
347 set_name ("Preferences");
348 add_events (Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);
350 set_border_width (4);
354 _notebook.set_show_tabs (true);
355 _notebook.set_show_border (true);
356 _notebook.set_name ("OptionsNotebook");
360 /* Watch out for changes to parameters */
361 _config->ParameterChanged.connect (config_connection, invalidator (*this), boost::bind (&OptionEditor::parameter_changed, this, _1), gui_context());
364 OptionEditor::~OptionEditor ()
366 for (std::map<std::string, OptionEditorPage*>::iterator i = _pages.begin(); i != _pages.end(); ++i) {
367 for (std::list<OptionEditorComponent*>::iterator j = i->second->components.begin(); j != i->second->components.end(); ++j) {
374 /** Called when a configuration parameter has been changed.
375 * @param p Parameter name.
378 OptionEditor::parameter_changed (std::string const & p)
380 ENSURE_GUI_THREAD (*this, &OptionEditor::parameter_changed, p)
382 for (std::map<std::string, OptionEditorPage*>::iterator i = _pages.begin(); i != _pages.end(); ++i) {
383 for (std::list<OptionEditorComponent*>::iterator j = i->second->components.begin(); j != i->second->components.end(); ++j) {
384 (*j)->parameter_changed (p);
389 /** Add a component to a given page.
390 * @param pn Page name (will be created if it doesn't already exist)
391 * @param o Component.
394 OptionEditor::add_option (std::string const & pn, OptionEditorComponent* o)
396 if (_pages.find (pn) == _pages.end()) {
397 _pages[pn] = new OptionEditorPage (_notebook, pn);
400 OptionEditorPage* p = _pages[pn];
401 p->components.push_back (o);
404 o->set_state_from_config ();
408 OptionEditor::set_current_page (string const & p)
411 while (i < _notebook.get_n_pages ()) {
412 if (_notebook.get_tab_label_text (*_notebook.get_nth_page (i)) == p) {
413 _notebook.set_current_page (i);
422 DirectoryOption::DirectoryOption (string const & i, string const & n, sigc::slot<string> g, sigc::slot<bool, string> s)
427 _file_chooser.set_action (Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
428 _file_chooser.signal_file_set().connect (sigc::mem_fun (*this, &DirectoryOption::file_set));
429 _file_chooser.signal_current_folder_changed().connect (sigc::mem_fun (*this, &DirectoryOption::current_folder_set));
434 DirectoryOption::set_state_from_config ()
436 _file_chooser.set_current_folder (_get ());
440 DirectoryOption::add_to_page (OptionEditorPage* p)
442 add_widgets_to_page (p, manage (new Label (_name)), &_file_chooser);
446 DirectoryOption::file_set ()
448 _set (_file_chooser.get_filename ());
452 DirectoryOption::current_folder_set ()
454 _set (_file_chooser.get_current_folder ());