*/
+#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>
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);
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).
*/
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_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
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));
}
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 ();
}
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;
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)
{
y = 2.0 * y - 1.0;
} else {
y = y * (double)(alist->get_max_y() - alist->get_min_y()) + alist->get_min_y();
- if (_desc.toggled || _desc.integer_step) {
+ if (_desc.integer_step) {
y = round(y);
+ } else if (_desc.toggled) {
+ y = (y > 0.5) ? 1.0 : 0.0;
}
}
}