*/
+#include <cmath>
+
#ifdef COMPILER_MSVC
#include <float.h>
-/* isinf() & isnan() are C99 standards, which older MSVC doesn't provide */
-#define isinf(val) !((bool)_finite((double)val))
-#define isnan(val) (bool)_isnan((double)val)
+
+// 'std::isnan()' is not available in MSVC.
+#define isnan_local(val) (bool)_isnan((double)val)
+#else
+#define isnan_local std::isnan
#endif
-#include <cmath>
#include <climits>
#include <vector>
#include <fstream>
#include "ardour/automation_list.h"
#include "ardour/dB.h"
#include "ardour/debug.h"
+#include "ardour/parameter_types.h"
#include "ardour/tempo.h"
#include "evoral/Curve.hpp"
#include "ardour/event_type_map.h"
#include "ardour/session.h"
+#include "ardour/value_as_string.h"
#include "i18n.h"
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) {
_our_time_converter = false;
terminal_points_can_slide = true;
_height = 0;
- group = new ArdourCanvas::Container (&parent);
+ group = new ArdourCanvas::Container (&parent, ArdourCanvas::Duple(0, 1.5));
CANVAS_DEBUG_NAME (group, "region gain envelope group");
line = new ArdourCanvas::PolyLine (group);
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);
}
return PublicEditor::instance().canvas_line_event (event, line, this);
}
+bool
+AutomationLine::is_stepped() const
+{
+ return (_desc.toggled ||
+ (alist && alist->interpolation() == AutomationList::Discrete));
+}
+
void
AutomationLine::update_visibility ()
{
if (_visible & Line) {
- /* Only show the line there are some points, otherwise we may show an out-of-date line
+ /* Only show the line when there are some points, otherwise we may show an out-of-date line
when automation points have been removed (the line will still follow the shape of the
old points).
*/
- if (alist->interpolation() != AutomationList::Discrete && control_points.size() >= 2) {
+ if (control_points.size() >= 2) {
line->show();
} else {
line->hide ();
} else {
line->hide ();
for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
- (*i)->hide ();
+ if (_visible & ControlPoints) {
+ (*i)->show ();
+ } else {
+ (*i)->hide ();
+ }
}
}
double
AutomationLine::control_point_box_size ()
{
- if (alist->interpolation() == AutomationList::Discrete) {
- return max((_height*4.0) / (double)(alist->parameter().max() - alist->parameter().min()),
- 4.0);
- }
-
if (_height > TimeAxisView::preset_height (HeightLarger)) {
return 8.0;
} else if (_height > (guint32) TimeAxisView::preset_height (HeightNormal)) {
double const x = trackview.editor().sample_to_pixel_unrounded (_time_converter->to((*cp.model())->when) - _offset);
- trackview.editor().session()->begin_reversible_command (_("automation event move"));
+ trackview.editor().begin_reversible_command (_("automation event move"));
trackview.editor().session()->add_command (
new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0));
cp.move_to (x, y, ControlPoint::Full);
+ alist->freeze ();
+ sync_model_with_view_point (cp);
+ alist->thaw ();
+
reset_line_coords (cp);
if (line_points.size() > 1) {
- line->set (line_points);
+ line->set_steps (line_points, is_stepped());
}
- alist->freeze ();
- sync_model_with_view_point (cp);
- alist->thaw ();
-
update_pending = false;
trackview.editor().session()->add_command (
new MementoCommand<AutomationList> (memento_command_binder(), 0, &alist->get_state()));
- trackview.editor().session()->commit_reversible_command ();
+ trackview.editor().commit_reversible_command ();
trackview.editor().session()->set_dirty ();
}
}
}
-void
+bool
AutomationLine::sync_model_with_view_points (list<ControlPoint*> cp)
{
update_pending = true;
+ bool moved = false;
for (list<ControlPoint*>::iterator i = cp.begin(); i != cp.end(); ++i) {
- sync_model_with_view_point (**i);
+ moved = sync_model_with_view_point (**i) || moved;
}
+
+ return moved;
}
string
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::start_drag_single (ControlPoint* cp, double x, float fraction)
{
- trackview.editor().session()->begin_reversible_command (_("automation event move"));
+ trackview.editor().begin_reversible_command (_("automation event move"));
trackview.editor().session()->add_command (
new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0));
void
AutomationLine::start_drag_line (uint32_t i1, uint32_t i2, float fraction)
{
- trackview.editor().session()->begin_reversible_command (_("automation range move"));
+ trackview.editor().begin_reversible_command (_("automation range move"));
trackview.editor().session()->add_command (
new MementoCommand<AutomationList> (memento_command_binder (), &get_state(), 0));
void
AutomationLine::start_drag_multiple (list<ControlPoint*> cp, float fraction, XMLNode* state)
{
- trackview.editor().session()->begin_reversible_command (_("automation range move"));
+ trackview.editor().begin_reversible_command (_("automation range move"));
trackview.editor().session()->add_command (
new MementoCommand<AutomationList> (memento_command_binder(), state, 0));
*/
if (line_points.size() > 1) {
- line->set (line_points);
+ line->set_steps (line_points, is_stepped());
}
}
}
alist->freeze ();
- sync_model_with_view_points (_drag_points);
+ bool moved = sync_model_with_view_points (_drag_points);
if (with_push) {
ControlPoint* p;
uint32_t i = final_index;
while ((p = nth (i)) != 0 && p->can_slide()) {
- sync_model_with_view_point (*p);
+ moved = sync_model_with_view_point (*p) || moved;
++i;
}
}
update_pending = false;
+ if (moved) {
+ /* A point has moved as a result of sync (clamped to integer or boolean
+ value), update line accordingly. */
+ line->set_steps (line_points, is_stepped());
+ }
+
trackview.editor().session()->add_command (
new MementoCommand<AutomationList>(memento_command_binder (), 0, &alist->get_state()));
contiguous_points.clear ();
}
-void
+bool
AutomationLine::sync_model_with_view_point (ControlPoint& cp)
{
/* find out where the visual control point is.
view_to_model_coord_y (view_y);
alist->modify (cp.model(), view_x, view_y);
+
+ /* convert back from model to view y for clamping position (for integer/boolean/etc) */
+ model_to_view_coord_y (view_y);
+ const double point_y = _height - (view_y * _height);
+ if (point_y != cp.get_y()) {
+ cp.move_to (cp.get_x(), point_y, ControlPoint::Full);
+ reset_line_coords (cp);
+ return true;
+ }
+
+ return false;
}
bool
void
AutomationLine::remove_point (ControlPoint& cp)
{
- trackview.editor().session()->begin_reversible_command (_("remove control point"));
+ trackview.editor().begin_reversible_command (_("remove control point"));
XMLNode &before = alist->get_state();
alist->erase (cp.model());
trackview.editor().session()->add_command(
new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state()));
- trackview.editor().session()->commit_reversible_command ();
+ trackview.editor().commit_reversible_command ();
trackview.editor().session()->set_dirty ();
}
(*i)->set_selected (true);
}
+ if (points.empty()) {
+ remove_visibility (SelectedControlPoints);
+ } else {
+ add_visibility (SelectedControlPoints);
+ }
+
set_colors ();
}
void AutomationLine::set_colors ()
{
- set_line_color (ARDOUR_UI::config()->get_AutomationLine());
+ set_line_color (ARDOUR_UI::config()->color ("automation line"));
for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
(*i)->set_color ();
}
model_to_view_coord (tx, ty);
- if (isnan (tx) || isnan (ty)) {
+ if (isnan_local (tx) || isnan_local (ty)) {
warning << string_compose (_("Ignoring illegal points on AutomationLine \"%1\""),
_name) << endmsg;
continue;
line_points[n].y = control_points[n]->get_y();
}
- line->set (line_points);
+ line->set_steps (line_points, is_stepped());
update_visibility ();
}
new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state()));
}
-void
-AutomationLine::change_model (AutomationList::iterator /*i*/, double /*x*/, double /*y*/)
-{
-}
-
void
AutomationLine::set_list (boost::shared_ptr<ARDOUR::AutomationList> list)
{
void
AutomationLine::track_entered()
{
- if (alist->interpolation() != AutomationList::Discrete) {
- add_visibility (ControlPoints);
- }
+ add_visibility (ControlPoints);
}
void
AutomationLine::track_exited()
{
- if (alist->interpolation() != AutomationList::Discrete) {
- remove_visibility (ControlPoints);
- }
+ remove_visibility (ControlPoints);
}
XMLNode &
y = 2.0 * y - 1.0;
} else {
y = y * (double)(alist->get_max_y() - alist->get_min_y()) + alist->get_min_y();
+ if (_desc.integer_step) {
+ y = round(y);
+ } else if (_desc.toggled) {
+ y = (y > 0.5) ? 1.0 : 0.0;
+ }
}
}
void
-AutomationLine::model_to_view_coord (double& x, double& y) const
+AutomationLine::model_to_view_coord_y (double& y) const
{
/* TODO: This should be more generic (use ParameterDescriptor) */
if (alist->parameter().type() == GainAutomation ||
} else {
y = (y - alist->get_min_y()) / (double)(alist->get_max_y() - alist->get_min_y());
}
+}
+void
+AutomationLine::model_to_view_coord (double& x, double& y) const
+{
+ model_to_view_coord_y (y);
x = _time_converter->to (x) - _offset;
}
void
AutomationLine::interpolation_changed (AutomationList::InterpolationStyle style)
{
- if (style == AutomationList::Discrete) {
- set_visibility (ControlPoints);
- line->hide();
- } else {
- set_visibility (Line);
+ if (line_points.size() > 1) {
+ line->set_steps(line_points, is_stepped());
}
}