1 /*
2 * Copyright (C) 2008-2011 Carl Hetherington <carl@carlh.net>
3 *
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.
8 *
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.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include <string>
20 #include <gtkmm/stock.h>
21
22 #include "automation_line.h"
23 #include "control_point.h"
24 #include "control_point_dialog.h"
25
26 #include "pbd/i18n.h"
27
28 /**
29 * ControlPointDialog constructor.
30 *
31 * @param p ControlPoint to edit.
32 */
33
ControlPointDialog(ControlPoint * p)34 ControlPointDialog::ControlPointDialog (ControlPoint* p)
35 : ArdourDialog (_("Control point"))
36 , point_ (p)
37 {
38 assert (point_);
39
40 double const y_fraction = 1.0 - (p->get_y () / p->line().height ());
41
42 /* This effectively calls ARDOUR::value_as_string */
43 std::string val (p->line().fraction_to_string (y_fraction));
44
45 /* Undo desc.toggled special cases */
46 if (val == _("on")) {
47 val = "1";
48 } else if (val == _("off")) {
49 val = "0";
50 }
51
52 /* separate quantity and unit (if any) */
53 std::size_t sep = val.find_last_of (" ");
54
55 value_.set_text (val.substr (0, sep));
56 value_.set_activates_default ();
57
58 Gtk::HBox* b = Gtk::manage (new Gtk::HBox ());
59
60 b->pack_start (*Gtk::manage (new Gtk::Label (_("Value"))));
61 b->pack_start (value_);
62
63 if (sep != std::string::npos) {
64 b->pack_start (*Gtk::manage (new Gtk::Label (val.substr (sep + 1))));
65 }
66
67 get_vbox ()->pack_end (*b);
68 b->show_all ();
69
70 add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
71 add_button (Gtk::Stock::APPLY, Gtk::RESPONSE_ACCEPT);
72 set_default_response (Gtk::RESPONSE_ACCEPT);
73 }
74
75 double
get_y_fraction() const76 ControlPointDialog::get_y_fraction () const
77 {
78 return point_->line().string_to_fraction (value_.get_text ());
79 }
80