#include "ardour/automation_list.h"
#include "ardour/dB.h"
#include "ardour/debug.h"
+#include "ardour/tempo.h"
#include "evoral/Curve.hpp"
#include "rgb_macros.h"
#include "ardour_ui.h"
#include "public_editor.h"
-#include "utils.h"
#include "selection.h"
#include "time_axis_view.h"
#include "point_selection.h"
#include "ardour/event_type_map.h"
#include "ardour/session.h"
+#include "ardour/value_as_string.h"
#include "i18n.h"
/** @param converter A TimeConverter whose origin_b is the start time of the AutomationList in session frames.
* This will not be deleted by AutomationLine.
*/
-AutomationLine::AutomationLine (const string& name, TimeAxisView& tv, ArdourCanvas::Group& parent,
- boost::shared_ptr<AutomationList> al,
+AutomationLine::AutomationLine (const string& name,
+ TimeAxisView& tv,
+ ArdourCanvas::Item& parent,
+ boost::shared_ptr<AutomationList> al,
+ const ParameterDescriptor& desc,
Evoral::TimeConverter<double, framepos_t>* converter)
: trackview (tv)
, _name (name)
, _parent_group (parent)
, _offset (0)
, _maximum_time (max_framepos)
+ , _desc (desc)
{
if (converter) {
- _time_converter = converter;
_our_time_converter = false;
} else {
- _time_converter = new Evoral::IdentityConverter<double, framepos_t>;
_our_time_converter = true;
}
terminal_points_can_slide = true;
_height = 0;
- group = new ArdourCanvas::Group (&parent);
+ group = new ArdourCanvas::Container (&parent);
CANVAS_DEBUG_NAME (group, "region gain envelope group");
line = new ArdourCanvas::PolyLine (group);
CANVAS_DEBUG_NAME (line, "region gain envelope line");
line->set_data ("line", this);
line->set_outline_width (2.0);
+ line->set_covers_threshold (4.0);
line->Event.connect (sigc::mem_fun (*this, &AutomationLine::event_handler));
trackview.session()->register_with_memento_command_factory(alist->id(), this);
if (alist->parameter().type() == GainAutomation ||
- alist->parameter().type() == EnvelopeAutomation) {
+ alist->parameter().type() == EnvelopeAutomation ||
+ desc.unit == ParameterDescriptor::DB) {
set_uses_gain_mapping (true);
}
}
void
-AutomationLine::show ()
+AutomationLine::update_visibility ()
{
if (_visible & Line) {
/* Only show the line there are some points, otherwise we may show an out-of-date line
} else {
line->hide ();
}
- } else {
- line->hide();
- /* if the line is not visible, then no control points should be visible */
- for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
- (*i)->hide ();
- }
- return;
- }
- if (_visible & ControlPoints) {
- for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
- (*i)->show ();
- }
- } else if (_visible & SelectedControlPoints) {
- for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
- if ((*i)->get_selected()) {
+ if (_visible & ControlPoints) {
+ for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
(*i)->show ();
- } else {
+ }
+ } else if (_visible & SelectedControlPoints) {
+ for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
+ if ((*i)->get_selected()) {
+ (*i)->show ();
+ } else {
+ (*i)->hide ();
+ }
+ }
+ } else {
+ for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
(*i)->hide ();
}
}
+
} else {
+ line->hide ();
for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
(*i)->hide ();
}
}
+
}
void
string
AutomationLine::fraction_to_string (double fraction) const
{
- char buf[32];
-
if (_uses_gain_mapping) {
+ char buf[32];
if (fraction == 0.0) {
snprintf (buf, sizeof (buf), "-inf");
} else {
snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain_with_max (fraction, Config->get_max_gain())));
}
+ return buf;
} else {
view_to_model_coord_y (fraction);
- if (EventTypeMap::instance().is_integer (alist->parameter())) {
- snprintf (buf, sizeof (buf), "%d", (int)fraction);
- } else {
- snprintf (buf, sizeof (buf), "%.2f", fraction);
- }
+ return ARDOUR::value_as_string (_desc, fraction);
}
- return buf;
+ return ""; /*NOTREACHED*/
}
/**
} else {
view_to_model_coord_y (original);
view_to_model_coord_y (fraction);
- if (EventTypeMap::instance().is_integer (alist->parameter())) {
- snprintf (buf, sizeof (buf), "%d", (int)fraction - (int)original);
- } else {
- snprintf (buf, sizeof (buf), "%.2f", fraction - original);
- }
+ return ARDOUR::value_as_string (_desc, fraction - original);
}
return buf;
}
void
-AutomationLine::ContiguousControlPoints::compute_x_bounds ()
+AutomationLine::ContiguousControlPoints::compute_x_bounds (PublicEditor& e)
{
uint32_t sz = size();
if (sz > 0 && sz < line.npoints()) {
+ const TempoMap& map (e.session()->tempo_map());
/* determine the limits on x-axis motion for this
contiguous range of control points
if (front()->view_index() > 0) {
before_x = line.nth (front()->view_index() - 1)->get_x();
+
+ const framepos_t pos = e.pixel_to_sample(before_x);
+ const Meter& meter = map.meter_at (pos);
+ const framecnt_t len = ceil (meter.frames_per_bar (map.tempo_at (pos), e.session()->frame_rate())
+ / (Timecode::BBT_Time::ticks_per_beat * meter.divisions_per_bar()) );
+ const double one_tick_in_pixels = e.sample_to_pixel_unrounded (len);
+
+ before_x += one_tick_in_pixels;
}
/* if our last point has a point after it in the line,
we have an "after" bound
*/
- if (back()->view_index() < (line.npoints() - 2)) {
+ if (back()->view_index() < (line.npoints() - 1)) {
after_x = line.nth (back()->view_index() + 1)->get_x();
+
+ const framepos_t pos = e.pixel_to_sample(after_x);
+ const Meter& meter = map.meter_at (pos);
+ const framecnt_t len = ceil (meter.frames_per_bar (map.tempo_at (pos), e.session()->frame_rate())
+ / (Timecode::BBT_Time::ticks_per_beat * meter.divisions_per_bar()));
+ const double one_tick_in_pixels = e.sample_to_pixel_unrounded (len);
+
+ after_x -= one_tick_in_pixels;
}
}
}
}
for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
- (*ccp)->compute_x_bounds ();
+ (*ccp)->compute_x_bounds (trackview.editor());
}
}
void AutomationLine::set_colors ()
{
- set_line_color (ARDOUR_UI::config()->get_canvasvar_AutomationLine());
+ set_line_color (ARDOUR_UI::config()->get_AutomationLine());
for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
(*i)->set_color ();
}
line->set (line_points);
- if (_visible && alist->interpolation() != AutomationList::Discrete) {
- line->show();
- }
+ update_visibility ();
}
set_selected_points (trackview.editor().get_selection().points);
_visible = VisibleAspects (_visible | va);
if (old != _visible) {
- show ();
+ update_visibility ();
}
}
{
if (_visible != va) {
_visible = va;
- show ();
+ update_visibility ();
}
}
_visible = VisibleAspects (_visible & ~va);
if (old != _visible) {
- show ();
+ update_visibility ();
}
}
void
AutomationLine::view_to_model_coord_y (double& y) const
{
- /* TODO: This should be more generic ... */
+ /* TODO: This should be more generic (use ParameterDescriptor) */
if (alist->parameter().type() == GainAutomation ||
alist->parameter().type() == EnvelopeAutomation) {
y = slider_position_to_gain_with_max (y, Config->get_max_gain());
y = 1.0 - y;
} else if (alist->parameter().type() == PanWidthAutomation) {
y = 2.0 * y - 1.0;
- } else if (alist->parameter().type() == PluginAutomation) {
- y = y * (double)(alist->get_max_y()- alist->get_min_y()) + alist->get_min_y();
} else {
- y = rint (y * alist->parameter().max());
+ y = y * (double)(alist->get_max_y() - alist->get_min_y()) + alist->get_min_y();
}
}
void
AutomationLine::model_to_view_coord (double& x, double& y) const
{
- /* TODO: This should be more generic ... */
+ /* TODO: This should be more generic (use ParameterDescriptor) */
if (alist->parameter().type() == GainAutomation ||
alist->parameter().type() == EnvelopeAutomation) {
y = gain_to_slider_position_with_max (y, Config->get_max_gain());
y = 1.0 - y;
} else if (alist->parameter().type() == PanWidthAutomation) {
y = .5 + y * .5;
- } else if (alist->parameter().type() == PluginAutomation) {
- y = (y - alist->get_min_y()) / (double)(alist->get_max_y()- alist->get_min_y());
} else {
- y = y / (double)alist->parameter().max(); /* ... like this */
+ y = (y - alist->get_min_y()) / (double)(alist->get_max_y() - alist->get_min_y());
}
x = _time_converter->to (x) - _offset;