2008-12-18 12:57:37 -05:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2008-2011 Carl Hetherington <carl@carlh.net>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2008-12-18 12:57:37 -05:00
|
|
|
|
2020-03-28 17:43:37 -04:00
|
|
|
#include <string>
|
|
|
|
#include <gtkmm/stock.h>
|
|
|
|
|
2023-07-10 19:09:42 -04:00
|
|
|
#include "gtkmm2ext/gtk_ui.h"
|
|
|
|
|
2008-12-18 12:57:37 -05:00
|
|
|
#include "automation_line.h"
|
2020-03-28 17:43:37 -04:00
|
|
|
#include "control_point.h"
|
|
|
|
#include "control_point_dialog.h"
|
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2008-12-18 12:57:37 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ControlPointDialog constructor.
|
|
|
|
*
|
|
|
|
* @param p ControlPoint to edit.
|
|
|
|
*/
|
|
|
|
|
2023-07-10 18:42:32 -04:00
|
|
|
ControlPointDialog::ControlPointDialog (ControlPoint* p, bool multi)
|
2020-03-28 17:43:37 -04:00
|
|
|
: ArdourDialog (_("Control point"))
|
|
|
|
, point_ (p)
|
2023-07-10 19:09:42 -04:00
|
|
|
, toggle_all_ (_("Apply to selected points"))
|
2023-07-10 18:42:32 -04:00
|
|
|
, all_selected_points_ (true)
|
2008-12-18 12:57:37 -05:00
|
|
|
{
|
|
|
|
assert (point_);
|
|
|
|
|
|
|
|
double const y_fraction = 1.0 - (p->get_y () / p->line().height ());
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2020-03-28 17:43:37 -04:00
|
|
|
/* This effectively calls ARDOUR::value_as_string */
|
|
|
|
std::string val (p->line().fraction_to_string (y_fraction));
|
|
|
|
|
|
|
|
/* Undo desc.toggled special cases */
|
|
|
|
if (val == _("on")) {
|
|
|
|
val = "1";
|
|
|
|
} else if (val == _("off")) {
|
|
|
|
val = "0";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* separate quantity and unit (if any) */
|
|
|
|
std::size_t sep = val.find_last_of (" ");
|
|
|
|
|
|
|
|
value_.set_text (val.substr (0, sep));
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-12-18 12:57:37 -05:00
|
|
|
Gtk::HBox* b = Gtk::manage (new Gtk::HBox ());
|
|
|
|
|
2023-07-10 18:42:32 -04:00
|
|
|
b->set_spacing (4);
|
2008-12-18 12:57:37 -05:00
|
|
|
b->pack_start (*Gtk::manage (new Gtk::Label (_("Value"))));
|
|
|
|
b->pack_start (value_);
|
|
|
|
|
2020-03-28 17:43:37 -04:00
|
|
|
if (sep != std::string::npos) {
|
|
|
|
b->pack_start (*Gtk::manage (new Gtk::Label (val.substr (sep + 1))));
|
2008-12-18 12:57:37 -05:00
|
|
|
}
|
2023-07-10 18:42:32 -04:00
|
|
|
get_vbox ()->pack_start (*b);
|
2023-07-10 19:09:42 -04:00
|
|
|
|
|
|
|
toggle_all_.set_active (true);
|
|
|
|
get_vbox ()->pack_start (toggle_all_);
|
|
|
|
Gtkmm2ext::UI::instance()->set_tip (toggle_all_,
|
|
|
|
_("<b>When enabled</b> the given value is applied to all selected automation points on the same line as the point being edited.\n\n"
|
|
|
|
"<b>When disabled</b> only the current automation point is modified."));
|
|
|
|
toggle_all_.set_sensitive (multi);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2023-07-10 18:42:32 -04:00
|
|
|
get_vbox ()->set_spacing (4);
|
|
|
|
show_all ();
|
2008-12-18 12:57:37 -05:00
|
|
|
|
|
|
|
add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
|
|
|
add_button (Gtk::Stock::APPLY, Gtk::RESPONSE_ACCEPT);
|
|
|
|
set_default_response (Gtk::RESPONSE_ACCEPT);
|
2023-07-10 18:42:32 -04:00
|
|
|
|
|
|
|
value_.set_activates_default ();
|
|
|
|
/* TODO: this does not work, one has to click on the entry.. */
|
|
|
|
value_.set_can_focus ();
|
|
|
|
value_.grab_focus ();
|
2008-12-18 12:57:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
ControlPointDialog::get_y_fraction () const
|
|
|
|
{
|
|
|
|
return point_->line().string_to_fraction (value_.get_text ());
|
|
|
|
}
|
2023-07-10 18:42:32 -04:00
|
|
|
|
|
|
|
bool
|
|
|
|
ControlPointDialog::all_selected_points () const
|
|
|
|
{
|
|
|
|
return toggle_all_.get_active ();
|
|
|
|
}
|