2 Copyright (C) 2002-2003 Paul Davis
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.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 // 'std::isinf()' and 'std::isnan()' are not available in MSVC.
24 #define isinf(val) !((bool)_finite((double)val))
25 #define isnan(val) (bool)_isnan((double)val)
36 #include "boost/shared_ptr.hpp"
38 #include "pbd/floating.h"
39 #include "pbd/memento_command.h"
40 #include "pbd/stl_delete.h"
41 #include "pbd/stacktrace.h"
43 #include "ardour/automation_list.h"
44 #include "ardour/dB.h"
45 #include "ardour/debug.h"
47 #include "evoral/Curve.hpp"
49 #include "canvas/debug.h"
51 #include "automation_line.h"
52 #include "control_point.h"
53 #include "gui_thread.h"
54 #include "rgb_macros.h"
55 #include "ardour_ui.h"
56 #include "public_editor.h"
58 #include "selection.h"
59 #include "time_axis_view.h"
60 #include "point_selection.h"
61 #include "automation_time_axis.h"
63 #include "ardour/event_type_map.h"
64 #include "ardour/session.h"
69 using namespace ARDOUR;
71 using namespace Editing;
73 /** @param converter A TimeConverter whose origin_b is the start time of the AutomationList in session frames.
74 * This will not be deleted by AutomationLine.
76 AutomationLine::AutomationLine (const string& name, TimeAxisView& tv, ArdourCanvas::Group& parent,
77 boost::shared_ptr<AutomationList> al,
78 Evoral::TimeConverter<double, framepos_t>* converter)
82 , _time_converter (converter ? converter : new Evoral::IdentityConverter<double, framepos_t>)
83 , _parent_group (parent)
85 , _maximum_time (max_framepos)
88 _time_converter = converter;
89 _our_time_converter = false;
91 _time_converter = new Evoral::IdentityConverter<double, framepos_t>;
92 _our_time_converter = true;
97 update_pending = false;
99 _uses_gain_mapping = false;
102 terminal_points_can_slide = true;
105 group = new ArdourCanvas::Group (&parent);
106 CANVAS_DEBUG_NAME (group, "region gain envelope group");
108 line = new ArdourCanvas::PolyLine (group);
109 CANVAS_DEBUG_NAME (line, "region gain envelope line");
110 line->set_data ("line", this);
111 line->set_outline_width (2.0);
113 line->Event.connect (sigc::mem_fun (*this, &AutomationLine::event_handler));
115 trackview.session()->register_with_memento_command_factory(alist->id(), this);
117 if (alist->parameter().type() == GainAutomation ||
118 alist->parameter().type() == EnvelopeAutomation) {
119 set_uses_gain_mapping (true);
122 interpolation_changed (alist->interpolation ());
127 AutomationLine::~AutomationLine ()
129 vector_delete (&control_points);
132 if (_our_time_converter) {
133 delete _time_converter;
138 AutomationLine::event_handler (GdkEvent* event)
140 return PublicEditor::instance().canvas_line_event (event, line, this);
144 AutomationLine::show ()
146 if (_visible & Line) {
147 /* Only show the line there are some points, otherwise we may show an out-of-date line
148 when automation points have been removed (the line will still follow the shape of the
151 if (alist->interpolation() != AutomationList::Discrete && control_points.size() >= 2) {
158 /* if the line is not visible, then no control points should be visible */
159 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
165 if (_visible & ControlPoints) {
166 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
169 } else if (_visible & SelectedControlPoints) {
170 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
171 if ((*i)->get_selected()) {
178 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
185 AutomationLine::hide ()
187 /* leave control points setting unchanged, we are just hiding the
191 set_visibility (AutomationLine::VisibleAspects (_visible & ~Line));
195 AutomationLine::control_point_box_size ()
197 if (alist->interpolation() == AutomationList::Discrete) {
198 return max((_height*4.0) / (double)(alist->parameter().max() - alist->parameter().min()),
202 if (_height > TimeAxisView::preset_height (HeightLarger)) {
204 } else if (_height > (guint32) TimeAxisView::preset_height (HeightNormal)) {
211 AutomationLine::set_height (guint32 h)
216 double bsz = control_point_box_size();
218 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
219 (*i)->set_size (bsz);
227 AutomationLine::set_line_color (uint32_t color)
230 line->set_outline_color (color);
234 AutomationLine::set_uses_gain_mapping (bool yn)
236 if (yn != _uses_gain_mapping) {
237 _uses_gain_mapping = yn;
243 AutomationLine::nth (uint32_t n)
245 if (n < control_points.size()) {
246 return control_points[n];
253 AutomationLine::nth (uint32_t n) const
255 if (n < control_points.size()) {
256 return control_points[n];
263 AutomationLine::modify_point_y (ControlPoint& cp, double y)
265 /* clamp y-coord appropriately. y is supposed to be a normalized fraction (0.0-1.0),
266 and needs to be converted to a canvas unit distance.
271 y = _height - (y * _height);
273 double const x = trackview.editor().sample_to_pixel_unrounded (_time_converter->to((*cp.model())->when) - _offset);
275 trackview.editor().session()->begin_reversible_command (_("automation event move"));
276 trackview.editor().session()->add_command (
277 new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0)
280 cp.move_to (x, y, ControlPoint::Full);
282 reset_line_coords (cp);
284 if (line_points.size() > 1) {
285 line->set (line_points);
289 sync_model_with_view_point (cp);
292 update_pending = false;
294 trackview.editor().session()->add_command (
295 new MementoCommand<AutomationList> (memento_command_binder(), 0, &alist->get_state())
298 trackview.editor().session()->commit_reversible_command ();
299 trackview.editor().session()->set_dirty ();
303 AutomationLine::reset_line_coords (ControlPoint& cp)
305 if (cp.view_index() < line_points.size()) {
306 line_points[cp.view_index()].x = cp.get_x ();
307 line_points[cp.view_index()].y = cp.get_y ();
312 AutomationLine::sync_model_with_view_points (list<ControlPoint*> cp)
314 update_pending = true;
316 for (list<ControlPoint*>::iterator i = cp.begin(); i != cp.end(); ++i) {
317 sync_model_with_view_point (**i);
322 AutomationLine::get_verbose_cursor_string (double fraction) const
324 std::string s = fraction_to_string (fraction);
325 if (_uses_gain_mapping) {
333 AutomationLine::get_verbose_cursor_relative_string (double original, double fraction) const
335 std::string s = fraction_to_string (fraction);
336 if (_uses_gain_mapping) {
340 std::string d = fraction_to_relative_string (original, fraction);
347 if (_uses_gain_mapping) {
358 * @param fraction y fraction
359 * @return string representation of this value, using dB if appropriate.
362 AutomationLine::fraction_to_string (double fraction) const
366 if (_uses_gain_mapping) {
367 if (fraction == 0.0) {
368 snprintf (buf, sizeof (buf), "-inf");
370 snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain_with_max (fraction, Config->get_max_gain())));
373 view_to_model_coord_y (fraction);
374 if (EventTypeMap::instance().is_integer (alist->parameter())) {
375 snprintf (buf, sizeof (buf), "%d", (int)fraction);
377 snprintf (buf, sizeof (buf), "%.2f", fraction);
385 * @param original an old y-axis fraction
386 * @param fraction the new y fraction
387 * @return string representation of the difference between original and fraction, using dB if appropriate.
390 AutomationLine::fraction_to_relative_string (double original, double fraction) const
394 if (original == fraction) {
398 if (_uses_gain_mapping) {
399 if (original == 0.0) {
400 /* there is no sensible representation of a relative
401 change from -inf dB, so return an empty string.
404 } else if (fraction == 0.0) {
405 snprintf (buf, sizeof (buf), "-inf");
407 double old_db = accurate_coefficient_to_dB (slider_position_to_gain_with_max (original, Config->get_max_gain()));
408 double new_db = accurate_coefficient_to_dB (slider_position_to_gain_with_max (fraction, Config->get_max_gain()));
409 snprintf (buf, sizeof (buf), "%.1f", new_db - old_db);
412 view_to_model_coord_y (original);
413 view_to_model_coord_y (fraction);
414 if (EventTypeMap::instance().is_integer (alist->parameter())) {
415 snprintf (buf, sizeof (buf), "%d", (int)fraction - (int)original);
417 snprintf (buf, sizeof (buf), "%.2f", fraction - original);
425 * @param s Value string in the form as returned by fraction_to_string.
426 * @return Corresponding y fraction.
429 AutomationLine::string_to_fraction (string const & s) const
436 sscanf (s.c_str(), "%lf", &v);
438 if (_uses_gain_mapping) {
439 v = gain_to_slider_position_with_max (dB_to_coefficient (v), Config->get_max_gain());
442 model_to_view_coord (dummy, v);
448 /** Start dragging a single point, possibly adding others if the supplied point is selected and there
449 * are other selected points.
451 * @param cp Point to drag.
452 * @param x Initial x position (units).
453 * @param fraction Initial y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
456 AutomationLine::start_drag_single (ControlPoint* cp, double x, float fraction)
458 trackview.editor().session()->begin_reversible_command (_("automation event move"));
459 trackview.editor().session()->add_command (
460 new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0)
463 _drag_points.clear ();
464 _drag_points.push_back (cp);
466 if (cp->get_selected ()) {
467 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
468 if (*i != cp && (*i)->get_selected()) {
469 _drag_points.push_back (*i);
474 start_drag_common (x, fraction);
477 /** Start dragging a line vertically (with no change in x)
478 * @param i1 Control point index of the `left' point on the line.
479 * @param i2 Control point index of the `right' point on the line.
480 * @param fraction Initial y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
483 AutomationLine::start_drag_line (uint32_t i1, uint32_t i2, float fraction)
485 trackview.editor().session()->begin_reversible_command (_("automation range move"));
486 trackview.editor().session()->add_command (
487 new MementoCommand<AutomationList> (memento_command_binder (), &get_state(), 0)
490 _drag_points.clear ();
492 for (uint32_t i = i1; i <= i2; i++) {
493 _drag_points.push_back (nth (i));
496 start_drag_common (0, fraction);
499 /** Start dragging multiple points (with no change in x)
500 * @param cp Points to drag.
501 * @param fraction Initial y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
504 AutomationLine::start_drag_multiple (list<ControlPoint*> cp, float fraction, XMLNode* state)
506 trackview.editor().session()->begin_reversible_command (_("automation range move"));
507 trackview.editor().session()->add_command (
508 new MementoCommand<AutomationList> (memento_command_binder(), state, 0)
512 start_drag_common (0, fraction);
515 struct ControlPointSorter
517 bool operator() (ControlPoint const * a, ControlPoint const * b) const {
518 if (floateq (a->get_x(), b->get_x(), 1)) {
519 return a->view_index() < b->view_index();
521 return a->get_x() < b->get_x();
525 AutomationLine::ContiguousControlPoints::ContiguousControlPoints (AutomationLine& al)
526 : line (al), before_x (0), after_x (DBL_MAX)
531 AutomationLine::ContiguousControlPoints::compute_x_bounds ()
533 uint32_t sz = size();
535 if (sz > 0 && sz < line.npoints()) {
537 /* determine the limits on x-axis motion for this
538 contiguous range of control points
541 if (front()->view_index() > 0) {
542 before_x = line.nth (front()->view_index() - 1)->get_x();
545 /* if our last point has a point after it in the line,
546 we have an "after" bound
549 if (back()->view_index() < (line.npoints() - 2)) {
550 after_x = line.nth (back()->view_index() + 1)->get_x();
556 AutomationLine::ContiguousControlPoints::clamp_dx (double dx)
562 /* get the maximum distance we can move any of these points along the x-axis
565 double tx; /* possible position a point would move to, given dx */
569 /* check the last point, since we're moving later in time */
572 /* check the first point, since we're moving earlier in time */
576 tx = cp->get_x() + dx; // new possible position if we just add the motion
577 tx = max (tx, before_x); // can't move later than following point
578 tx = min (tx, after_x); // can't move earlier than preceeding point
579 return tx - cp->get_x ();
583 AutomationLine::ContiguousControlPoints::move (double dx, double dy)
585 for (std::list<ControlPoint*>::iterator i = begin(); i != end(); ++i) {
586 (*i)->move_to ((*i)->get_x() + dx, (*i)->get_y() - line.height() * dy, ControlPoint::Full);
587 line.reset_line_coords (**i);
591 /** Common parts of starting a drag.
592 * @param x Starting x position in units, or 0 if x is being ignored.
593 * @param fraction Starting y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
596 AutomationLine::start_drag_common (double x, float fraction)
600 _last_drag_fraction = fraction;
601 _drag_had_movement = false;
604 /* they are probably ordered already, but we have to make sure */
606 _drag_points.sort (ControlPointSorter());
610 /** Should be called to indicate motion during a drag.
611 * @param x New x position of the drag in canvas units, or undefined if ignore_x == true.
612 * @param fraction New y fraction.
613 * @return x position and y fraction that were actually used (once clamped).
616 AutomationLine::drag_motion (double const x, float fraction, bool ignore_x, bool with_push, uint32_t& final_index)
618 if (_drag_points.empty()) {
619 return pair<double,float> (x,fraction);
622 double dx = ignore_x ? 0 : (x - _drag_x);
623 double dy = fraction - _last_drag_fraction;
625 if (!_drag_had_movement) {
627 /* "first move" ... do some stuff that we don't want to do if
628 no motion ever took place, but need to do before we handle
632 /* partition the points we are dragging into (potentially several)
633 * set(s) of contiguous points. this will not happen with a normal
634 * drag, but if the user does a discontiguous selection, it can.
637 uint32_t expected_view_index = 0;
640 for (list<ControlPoint*>::iterator i = _drag_points.begin(); i != _drag_points.end(); ++i) {
641 if (i == _drag_points.begin() || (*i)->view_index() != expected_view_index) {
642 contig.reset (new ContiguousControlPoints (*this));
643 contiguous_points.push_back (contig);
645 contig->push_back (*i);
646 expected_view_index = (*i)->view_index() + 1;
649 if (contiguous_points.back()->empty()) {
650 contiguous_points.pop_back ();
653 for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
654 (*ccp)->compute_x_bounds ();
658 /* OK, now on to the stuff related to *this* motion event. First, for
659 * each contiguous range, figure out the maximum x-axis motion we are
660 * allowed (because of neighbouring points that are not moving.
662 * if we are moving forwards with push, we don't need to do this,
663 * since all later points will move too.
666 if (dx < 0 || ((dx > 0) && !with_push)) {
667 for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
668 double dxt = (*ccp)->clamp_dx (dx);
669 if (fabs (dxt) < fabs (dx)) {
677 for (list<ControlPoint*>::iterator i = _drag_points.begin(); i != _drag_points.end(); ++i) {
678 double const y = ((_height - (*i)->get_y()) / _height) + dy;
689 /* and now move each section */
691 for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
692 (*ccp)->move (dx, dy);
695 final_index = contiguous_points.back()->back()->view_index () + 1;
697 uint32_t i = final_index;
698 while ((p = nth (i)) != 0 && p->can_slide()) {
699 p->move_to (p->get_x() + dx, p->get_y(), ControlPoint::Full);
700 reset_line_coords (*p);
705 /* update actual line coordinates (will queue a redraw)
708 if (line_points.size() > 1) {
709 line->set (line_points);
713 _drag_distance += dx;
715 _last_drag_fraction = fraction;
716 _drag_had_movement = true;
717 did_push = with_push;
719 return pair<double, float> (_drag_x + dx, _last_drag_fraction + dy);
722 /** Should be called to indicate the end of a drag */
724 AutomationLine::end_drag (bool with_push, uint32_t final_index)
726 if (!_drag_had_movement) {
731 sync_model_with_view_points (_drag_points);
735 uint32_t i = final_index;
736 while ((p = nth (i)) != 0 && p->can_slide()) {
737 sync_model_with_view_point (*p);
744 update_pending = false;
746 trackview.editor().session()->add_command (
747 new MementoCommand<AutomationList>(memento_command_binder (), 0, &alist->get_state())
750 trackview.editor().session()->set_dirty ();
753 contiguous_points.clear ();
757 AutomationLine::sync_model_with_view_point (ControlPoint& cp)
759 /* find out where the visual control point is.
760 initial results are in canvas units. ask the
761 line to convert them to something relevant.
764 double view_x = cp.get_x();
765 double view_y = 1.0 - (cp.get_y() / _height);
767 /* if xval has not changed, set it directly from the model to avoid rounding errors */
769 if (view_x == trackview.editor().sample_to_pixel_unrounded (_time_converter->to ((*cp.model())->when)) - _offset) {
770 view_x = (*cp.model())->when - _offset;
772 view_x = trackview.editor().pixel_to_sample (view_x);
773 view_x = _time_converter->from (view_x + _offset);
776 update_pending = true;
778 view_to_model_coord_y (view_y);
780 alist->modify (cp.model(), view_x, view_y);
784 AutomationLine::control_points_adjacent (double xval, uint32_t & before, uint32_t& after)
786 ControlPoint *bcp = 0;
787 ControlPoint *acp = 0;
790 unit_xval = trackview.editor().sample_to_pixel_unrounded (xval);
792 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
794 if ((*i)->get_x() <= unit_xval) {
796 if (!bcp || (*i)->get_x() > bcp->get_x()) {
798 before = bcp->view_index();
801 } else if ((*i)->get_x() > unit_xval) {
803 after = acp->view_index();
812 AutomationLine::is_last_point (ControlPoint& cp)
814 // If the list is not empty, and the point is the last point in the list
816 if (alist->empty()) {
820 AutomationList::const_iterator i = alist->end();
823 if (cp.model() == i) {
831 AutomationLine::is_first_point (ControlPoint& cp)
833 // If the list is not empty, and the point is the first point in the list
835 if (!alist->empty() && cp.model() == alist->begin()) {
842 // This is copied into AudioRegionGainLine
844 AutomationLine::remove_point (ControlPoint& cp)
846 trackview.editor().session()->begin_reversible_command (_("remove control point"));
847 XMLNode &before = alist->get_state();
849 alist->erase (cp.model());
851 trackview.editor().session()->add_command(
852 new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state())
855 trackview.editor().session()->commit_reversible_command ();
856 trackview.editor().session()->set_dirty ();
859 /** Get selectable points within an area.
860 * @param start Start position in session frames.
861 * @param end End position in session frames.
862 * @param bot Bottom y range, as a fraction of line height, where 0 is the bottom of the line.
863 * @param top Top y range, as a fraction of line height, where 0 is the bottom of the line.
864 * @param result Filled in with selectable things; in this case, ControlPoints.
867 AutomationLine::get_selectables (framepos_t start, framepos_t end, double botfrac, double topfrac, list<Selectable*>& results)
869 /* convert fractions to display coordinates with 0 at the top of the track */
870 double const bot_track = (1 - topfrac) * trackview.current_height ();
871 double const top_track = (1 - botfrac) * trackview.current_height ();
873 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
874 double const model_when = (*(*i)->model())->when;
876 /* model_when is relative to the start of the source, so we just need to add on the origin_b here
877 (as it is the session frame position of the start of the source)
880 framepos_t const session_frames_when = _time_converter->to (model_when) + _time_converter->origin_b ();
882 if (session_frames_when >= start && session_frames_when <= end && (*i)->get_y() >= bot_track && (*i)->get_y() <= top_track) {
883 results.push_back (*i);
889 AutomationLine::get_inverted_selectables (Selection&, list<Selectable*>& /*results*/)
895 AutomationLine::set_selected_points (PointSelection const & points)
897 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
898 (*i)->set_selected (false);
901 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
902 (*i)->set_selected (true);
908 void AutomationLine::set_colors ()
910 set_line_color (ARDOUR_UI::config()->get_canvasvar_AutomationLine());
911 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
917 AutomationLine::list_changed ()
919 DEBUG_TRACE (DEBUG::Automation, string_compose ("\tline changed, existing update pending? %1\n", update_pending));
921 if (!update_pending) {
922 update_pending = true;
923 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AutomationLine::queue_reset, this));
928 AutomationLine::reset_callback (const Evoral::ControlList& events)
934 if (events.empty()) {
935 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
938 control_points.clear ();
943 /* hide all existing points, and the line */
945 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
952 Evoral::ControlList& e = const_cast<Evoral::ControlList&> (events);
954 for (AutomationList::iterator ai = e.begin(); ai != e.end(); ++ai, ++pi) {
956 double tx = (*ai)->when;
957 double ty = (*ai)->value;
959 /* convert from model coordinates to canonical view coordinates */
961 model_to_view_coord (tx, ty);
963 if (isnan (tx) || isnan (ty)) {
964 warning << string_compose (_("Ignoring illegal points on AutomationLine \"%1\""),
969 if (tx >= max_framepos || tx < 0 || tx >= _maximum_time) {
973 /* convert x-coordinate to a canvas unit coordinate (this takes
974 * zoom and scroll into account).
977 tx = trackview.editor().sample_to_pixel_unrounded (tx);
979 /* convert from canonical view height (0..1.0) to actual
980 * height coordinates (using X11's top-left rooted system)
983 ty = _height - (ty * _height);
985 add_visible_control_point (vp, pi, tx, ty, ai, np);
989 /* discard extra CP's to avoid confusing ourselves */
991 while (control_points.size() > vp) {
992 ControlPoint* cp = control_points.back();
993 control_points.pop_back ();
997 if (!terminal_points_can_slide) {
998 control_points.back()->set_can_slide(false);
1003 /* reset the line coordinates given to the CanvasLine */
1005 while (line_points.size() < vp) {
1006 line_points.push_back (ArdourCanvas::Duple (0,0));
1009 while (line_points.size() > vp) {
1010 line_points.pop_back ();
1013 for (uint32_t n = 0; n < vp; ++n) {
1014 line_points[n].x = control_points[n]->get_x();
1015 line_points[n].y = control_points[n]->get_y();
1018 line->set (line_points);
1020 if (_visible && alist->interpolation() != AutomationList::Discrete) {
1025 set_selected_points (trackview.editor().get_selection().points);
1029 AutomationLine::reset ()
1031 DEBUG_TRACE (DEBUG::Automation, "\t\tLINE RESET\n");
1032 update_pending = false;
1033 have_timeout = false;
1039 alist->apply_to_points (*this, &AutomationLine::reset_callback);
1043 AutomationLine::queue_reset ()
1045 /* this must be called from the GUI thread
1048 if (trackview.editor().session()->transport_rolling() && alist->automation_write()) {
1049 /* automation write pass ... defer to a timeout */
1050 /* redraw in 1/4 second */
1051 if (!have_timeout) {
1052 DEBUG_TRACE (DEBUG::Automation, "\tqueue timeout\n");
1053 Glib::signal_timeout().connect (sigc::bind_return (sigc::mem_fun (*this, &AutomationLine::reset), false), 250);
1054 have_timeout = true;
1056 DEBUG_TRACE (DEBUG::Automation, "\ttimeout already queued, change ignored\n");
1064 AutomationLine::clear ()
1066 /* parent must create and commit command */
1067 XMLNode &before = alist->get_state();
1070 trackview.editor().session()->add_command (
1071 new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state())
1076 AutomationLine::change_model (AutomationList::iterator /*i*/, double /*x*/, double /*y*/)
1081 AutomationLine::set_list (boost::shared_ptr<ARDOUR::AutomationList> list)
1089 AutomationLine::add_visibility (VisibleAspects va)
1091 VisibleAspects old = _visible;
1093 _visible = VisibleAspects (_visible | va);
1095 if (old != _visible) {
1101 AutomationLine::set_visibility (VisibleAspects va)
1103 if (_visible != va) {
1110 AutomationLine::remove_visibility (VisibleAspects va)
1112 VisibleAspects old = _visible;
1114 _visible = VisibleAspects (_visible & ~va);
1116 if (old != _visible) {
1122 AutomationLine::track_entered()
1124 if (alist->interpolation() != AutomationList::Discrete) {
1125 add_visibility (ControlPoints);
1130 AutomationLine::track_exited()
1132 if (alist->interpolation() != AutomationList::Discrete) {
1133 remove_visibility (ControlPoints);
1138 AutomationLine::get_state (void)
1140 /* function as a proxy for the model */
1141 return alist->get_state();
1145 AutomationLine::set_state (const XMLNode &node, int version)
1147 /* function as a proxy for the model */
1148 return alist->set_state (node, version);
1152 AutomationLine::view_to_model_coord (double& x, double& y) const
1154 x = _time_converter->from (x);
1155 view_to_model_coord_y (y);
1159 AutomationLine::view_to_model_coord_y (double& y) const
1161 /* TODO: This should be more generic ... */
1162 if (alist->parameter().type() == GainAutomation ||
1163 alist->parameter().type() == EnvelopeAutomation) {
1164 y = slider_position_to_gain_with_max (y, Config->get_max_gain());
1167 } else if (alist->parameter().type() == PanAzimuthAutomation ||
1168 alist->parameter().type() == PanElevationAutomation ||
1169 alist->parameter().type() == PanWidthAutomation) {
1171 } else if (alist->parameter().type() == PluginAutomation) {
1172 y = y * (double)(alist->get_max_y()- alist->get_min_y()) + alist->get_min_y();
1174 y = rint (y * alist->parameter().max());
1179 AutomationLine::model_to_view_coord (double& x, double& y) const
1181 /* TODO: This should be more generic ... */
1182 if (alist->parameter().type() == GainAutomation ||
1183 alist->parameter().type() == EnvelopeAutomation) {
1184 y = gain_to_slider_position_with_max (y, Config->get_max_gain());
1185 } else if (alist->parameter().type() == PanAzimuthAutomation ||
1186 alist->parameter().type() == PanElevationAutomation ||
1187 alist->parameter().type() == PanWidthAutomation) {
1188 // vertical coordinate axis reversal
1190 } else if (alist->parameter().type() == PluginAutomation) {
1191 y = (y - alist->get_min_y()) / (double)(alist->get_max_y()- alist->get_min_y());
1193 y = y / (double)alist->parameter().max(); /* ... like this */
1196 x = _time_converter->to (x) - _offset;
1199 /** Called when our list has announced that its interpolation style has changed */
1201 AutomationLine::interpolation_changed (AutomationList::InterpolationStyle style)
1203 if (style == AutomationList::Discrete) {
1204 set_visibility (ControlPoints);
1207 set_visibility (Line);
1212 AutomationLine::add_visible_control_point (uint32_t view_index, uint32_t pi, double tx, double ty,
1213 AutomationList::iterator model, uint32_t npoints)
1215 ControlPoint::ShapeType shape;
1217 if (view_index >= control_points.size()) {
1219 /* make sure we have enough control points */
1221 ControlPoint* ncp = new ControlPoint (*this);
1222 ncp->set_size (control_point_box_size ());
1224 control_points.push_back (ncp);
1227 if (!terminal_points_can_slide) {
1229 control_points[view_index]->set_can_slide (false);
1231 shape = ControlPoint::Start;
1233 shape = ControlPoint::Full;
1235 } else if (pi == npoints - 1) {
1236 control_points[view_index]->set_can_slide (false);
1237 shape = ControlPoint::End;
1239 control_points[view_index]->set_can_slide (true);
1240 shape = ControlPoint::Full;
1243 control_points[view_index]->set_can_slide (true);
1244 shape = ControlPoint::Full;
1247 control_points[view_index]->reset (tx, ty, model, view_index, shape);
1249 /* finally, control visibility */
1251 if (_visible & ControlPoints) {
1252 control_points[view_index]->show ();
1254 control_points[view_index]->hide ();
1259 AutomationLine::connect_to_list ()
1261 _list_connections.drop_connections ();
1263 alist->StateChanged.connect (_list_connections, invalidator (*this), boost::bind (&AutomationLine::list_changed, this), gui_context());
1265 alist->InterpolationChanged.connect (
1266 _list_connections, invalidator (*this), boost::bind (&AutomationLine::interpolation_changed, this, _1), gui_context()
1270 MementoCommandBinder<AutomationList>*
1271 AutomationLine::memento_command_binder ()
1273 return new SimpleMementoCommandBinder<AutomationList> (*alist.get());
1276 /** Set the maximum time that points on this line can be at, relative
1277 * to the start of the track or region that it is on.
1280 AutomationLine::set_maximum_time (framecnt_t t)
1282 if (_maximum_time == t) {
1291 /** @return min and max x positions of points that are in the list, in session frames */
1292 pair<framepos_t, framepos_t>
1293 AutomationLine::get_point_x_range () const
1295 pair<framepos_t, framepos_t> r (max_framepos, 0);
1297 for (AutomationList::const_iterator i = the_list()->begin(); i != the_list()->end(); ++i) {
1298 r.first = min (r.first, session_position (i));
1299 r.second = max (r.second, session_position (i));
1306 AutomationLine::session_position (AutomationList::const_iterator p) const
1308 return _time_converter->to ((*p)->when) + _offset + _time_converter->origin_b ();
1312 AutomationLine::set_offset (framepos_t off)
1314 if (_offset == off) {