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.
25 #include "boost/shared_ptr.hpp"
27 #include "pbd/floating.h"
28 #include "pbd/memento_command.h"
29 #include "pbd/stl_delete.h"
30 #include "pbd/stacktrace.h"
32 #include "ardour/automation_list.h"
33 #include "ardour/dB.h"
34 #include "ardour/debug.h"
36 #include "evoral/Curve.hpp"
38 #include "automation_line.h"
39 #include "control_point.h"
40 #include "gui_thread.h"
41 #include "rgb_macros.h"
42 #include "ardour_ui.h"
43 #include "public_editor.h"
45 #include "selection.h"
46 #include "time_axis_view.h"
47 #include "point_selection.h"
48 #include "automation_time_axis.h"
50 #include "ardour/event_type_map.h"
51 #include "ardour/session.h"
56 using namespace ARDOUR;
58 using namespace Editing;
60 /** @param converter A TimeConverter whose origin_b is the start time of the AutomationList in session frames.
61 * This will not be deleted by AutomationLine.
63 AutomationLine::AutomationLine (const string& name, TimeAxisView& tv, ArdourCanvas::Group& parent,
64 boost::shared_ptr<AutomationList> al,
65 Evoral::TimeConverter<double, framepos_t>* converter)
69 , _time_converter (converter ? converter : new Evoral::IdentityConverter<double, framepos_t>)
70 , _parent_group (parent)
72 , _maximum_time (max_framepos)
75 _time_converter = converter;
76 _our_time_converter = false;
78 _time_converter = new Evoral::IdentityConverter<double, framepos_t>;
79 _our_time_converter = true;
84 update_pending = false;
86 _uses_gain_mapping = false;
89 terminal_points_can_slide = true;
92 group = new ArdourCanvas::Group (&parent);
94 line = new ArdourCanvas::Curve (group);
95 line->set_data ("line", this);
96 line->set_outline_width (2.0);
98 line->Event.connect (sigc::mem_fun (*this, &AutomationLine::event_handler));
100 trackview.session()->register_with_memento_command_factory(alist->id(), this);
102 if (alist->parameter().type() == GainAutomation ||
103 alist->parameter().type() == EnvelopeAutomation) {
104 set_uses_gain_mapping (true);
107 interpolation_changed (alist->interpolation ());
112 AutomationLine::~AutomationLine ()
114 vector_delete (&control_points);
117 if (_our_time_converter) {
118 delete _time_converter;
123 AutomationLine::event_handler (GdkEvent* event)
125 return PublicEditor::instance().canvas_line_event (event, line, this);
129 AutomationLine::show ()
131 if (_visible & Line) {
132 /* Only show the line there are some points, otherwise we may show an out-of-date line
133 when automation points have been removed (the line will still follow the shape of the
136 if (alist->interpolation() != AutomationList::Discrete && control_points.size() >= 2) {
145 if (_visible & ControlPoints) {
146 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
147 (*i)->set_visible (true);
150 } else if (_visible & SelectedControlPoints) {
151 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
152 (*i)->set_visible ((*i)->get_selected());
155 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
156 (*i)->set_visible (false);
162 AutomationLine::hide ()
164 set_visibility (VisibleAspects (0));
168 AutomationLine::control_point_box_size ()
170 if (alist->interpolation() == AutomationList::Discrete) {
171 return max((_height*4.0) / (double)(alist->parameter().max() - alist->parameter().min()),
175 if (_height > TimeAxisView::preset_height (HeightLarger)) {
177 } else if (_height > (guint32) TimeAxisView::preset_height (HeightNormal)) {
184 AutomationLine::set_height (guint32 h)
189 double bsz = control_point_box_size();
191 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
192 (*i)->set_size (bsz);
200 AutomationLine::set_line_color (uint32_t color)
203 line->set_outline_color (color);
207 AutomationLine::set_uses_gain_mapping (bool yn)
209 if (yn != _uses_gain_mapping) {
210 _uses_gain_mapping = yn;
216 AutomationLine::nth (uint32_t n)
218 if (n < control_points.size()) {
219 return control_points[n];
226 AutomationLine::nth (uint32_t n) const
228 if (n < control_points.size()) {
229 return control_points[n];
236 AutomationLine::modify_point_y (ControlPoint& cp, double y)
238 /* clamp y-coord appropriately. y is supposed to be a normalized fraction (0.0-1.0),
239 and needs to be converted to a canvas unit distance.
244 y = _height - (y * _height);
246 double const x = trackview.editor().sample_to_pixel_unrounded (_time_converter->to((*cp.model())->when) - _offset);
248 trackview.editor().session()->begin_reversible_command (_("automation event move"));
249 trackview.editor().session()->add_command (
250 new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0)
253 cp.move_to (x, y, ControlPoint::Full);
255 reset_line_coords (cp);
257 if (line_points.size() > 1) {
258 line->set (line_points);
262 sync_model_with_view_point (cp);
265 update_pending = false;
267 trackview.editor().session()->add_command (
268 new MementoCommand<AutomationList> (memento_command_binder(), 0, &alist->get_state())
271 trackview.editor().session()->commit_reversible_command ();
272 trackview.editor().session()->set_dirty ();
276 AutomationLine::reset_line_coords (ControlPoint& cp)
278 if (cp.view_index() < line_points.size()) {
279 line_points[cp.view_index()].x = cp.get_x ();
280 line_points[cp.view_index()].y = cp.get_y ();
285 AutomationLine::sync_model_with_view_points (list<ControlPoint*> cp)
287 update_pending = true;
289 for (list<ControlPoint*>::iterator i = cp.begin(); i != cp.end(); ++i) {
290 sync_model_with_view_point (**i);
295 AutomationLine::get_verbose_cursor_string (double fraction) const
297 std::string s = fraction_to_string (fraction);
298 if (_uses_gain_mapping) {
306 AutomationLine::get_verbose_cursor_relative_string (double original, double fraction) const
308 std::string s = fraction_to_string (fraction);
309 if (_uses_gain_mapping) {
313 std::string d = fraction_to_relative_string (original, fraction);
320 if (_uses_gain_mapping) {
331 * @param fraction y fraction
332 * @return string representation of this value, using dB if appropriate.
335 AutomationLine::fraction_to_string (double fraction) const
339 if (_uses_gain_mapping) {
340 if (fraction == 0.0) {
341 snprintf (buf, sizeof (buf), "-inf");
343 snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain_with_max (fraction, Config->get_max_gain())));
346 view_to_model_coord_y (fraction);
347 if (EventTypeMap::instance().is_integer (alist->parameter())) {
348 snprintf (buf, sizeof (buf), "%d", (int)fraction);
350 snprintf (buf, sizeof (buf), "%.2f", fraction);
358 * @param original an old y-axis fraction
359 * @param fraction the new y fraction
360 * @return string representation of the difference between original and fraction, using dB if appropriate.
363 AutomationLine::fraction_to_relative_string (double original, double fraction) const
367 if (original == fraction) {
371 if (_uses_gain_mapping) {
372 if (original == 0.0) {
373 /* there is no sensible representation of a relative
374 change from -inf dB, so return an empty string.
377 } else if (fraction == 0.0) {
378 snprintf (buf, sizeof (buf), "-inf");
380 double old_db = accurate_coefficient_to_dB (slider_position_to_gain_with_max (original, Config->get_max_gain()));
381 double new_db = accurate_coefficient_to_dB (slider_position_to_gain_with_max (fraction, Config->get_max_gain()));
382 snprintf (buf, sizeof (buf), "%.1f", new_db - old_db);
385 view_to_model_coord_y (original);
386 view_to_model_coord_y (fraction);
387 if (EventTypeMap::instance().is_integer (alist->parameter())) {
388 snprintf (buf, sizeof (buf), "%d", (int)fraction - (int)original);
390 snprintf (buf, sizeof (buf), "%.2f", fraction - original);
398 * @param s Value string in the form as returned by fraction_to_string.
399 * @return Corresponding y fraction.
402 AutomationLine::string_to_fraction (string const & s) const
409 sscanf (s.c_str(), "%lf", &v);
411 if (_uses_gain_mapping) {
412 v = gain_to_slider_position_with_max (dB_to_coefficient (v), Config->get_max_gain());
415 model_to_view_coord (dummy, v);
421 /** Start dragging a single point, possibly adding others if the supplied point is selected and there
422 * are other selected points.
424 * @param cp Point to drag.
425 * @param x Initial x position (units).
426 * @param fraction Initial y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
429 AutomationLine::start_drag_single (ControlPoint* cp, double x, float fraction)
431 trackview.editor().session()->begin_reversible_command (_("automation event move"));
432 trackview.editor().session()->add_command (
433 new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0)
436 _drag_points.clear ();
437 _drag_points.push_back (cp);
439 if (cp->get_selected ()) {
440 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
441 if (*i != cp && (*i)->get_selected()) {
442 _drag_points.push_back (*i);
447 start_drag_common (x, fraction);
450 /** Start dragging a line vertically (with no change in x)
451 * @param i1 Control point index of the `left' point on the line.
452 * @param i2 Control point index of the `right' point on the line.
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_line (uint32_t i1, uint32_t i2, float fraction)
458 trackview.editor().session()->begin_reversible_command (_("automation range move"));
459 trackview.editor().session()->add_command (
460 new MementoCommand<AutomationList> (memento_command_binder (), &get_state(), 0)
463 _drag_points.clear ();
465 for (uint32_t i = i1; i <= i2; i++) {
466 _drag_points.push_back (nth (i));
469 start_drag_common (0, fraction);
472 /** Start dragging multiple points (with no change in x)
473 * @param cp Points to drag.
474 * @param fraction Initial y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
477 AutomationLine::start_drag_multiple (list<ControlPoint*> cp, float fraction, XMLNode* state)
479 trackview.editor().session()->begin_reversible_command (_("automation range move"));
480 trackview.editor().session()->add_command (
481 new MementoCommand<AutomationList> (memento_command_binder(), state, 0)
485 start_drag_common (0, fraction);
488 struct ControlPointSorter
490 bool operator() (ControlPoint const * a, ControlPoint const * b) const {
491 if (floateq (a->get_x(), b->get_x(), 1)) {
492 return a->view_index() < b->view_index();
494 return a->get_x() < b->get_x();
498 AutomationLine::ContiguousControlPoints::ContiguousControlPoints (AutomationLine& al)
499 : line (al), before_x (0), after_x (DBL_MAX)
504 AutomationLine::ContiguousControlPoints::compute_x_bounds ()
506 uint32_t sz = size();
508 if (sz > 0 && sz < line.npoints()) {
510 /* determine the limits on x-axis motion for this
511 contiguous range of control points
514 if (front()->view_index() > 0) {
515 before_x = line.nth (front()->view_index() - 1)->get_x();
518 /* if our last point has a point after it in the line,
519 we have an "after" bound
522 if (back()->view_index() < (line.npoints() - 2)) {
523 after_x = line.nth (back()->view_index() + 1)->get_x();
529 AutomationLine::ContiguousControlPoints::clamp_dx (double dx)
535 /* get the maximum distance we can move any of these points along the x-axis
538 double tx; /* possible position a point would move to, given dx */
542 /* check the last point, since we're moving later in time */
545 /* check the first point, since we're moving earlier in time */
549 tx = cp->get_x() + dx; // new possible position if we just add the motion
550 tx = max (tx, before_x); // can't move later than following point
551 tx = min (tx, after_x); // can't move earlier than preceeding point
552 return tx - cp->get_x ();
556 AutomationLine::ContiguousControlPoints::move (double dx, double dy)
558 for (std::list<ControlPoint*>::iterator i = begin(); i != end(); ++i) {
559 (*i)->move_to ((*i)->get_x() + dx, (*i)->get_y() - line.height() * dy, ControlPoint::Full);
560 line.reset_line_coords (**i);
564 /** Common parts of starting a drag.
565 * @param x Starting x position in units, or 0 if x is being ignored.
566 * @param fraction Starting y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
569 AutomationLine::start_drag_common (double x, float fraction)
573 _last_drag_fraction = fraction;
574 _drag_had_movement = false;
577 /* they are probably ordered already, but we have to make sure */
579 _drag_points.sort (ControlPointSorter());
583 /** Should be called to indicate motion during a drag.
584 * @param x New x position of the drag in canvas units, or undefined if ignore_x == true.
585 * @param fraction New y fraction.
586 * @return x position and y fraction that were actually used (once clamped).
589 AutomationLine::drag_motion (double const x, float fraction, bool ignore_x, bool with_push, uint32_t& final_index)
591 if (_drag_points.empty()) {
592 return pair<double,float> (x,fraction);
595 double dx = ignore_x ? 0 : (x - _drag_x);
596 double dy = fraction - _last_drag_fraction;
598 if (!_drag_had_movement) {
600 /* "first move" ... do some stuff that we don't want to do if
601 no motion ever took place, but need to do before we handle
605 /* partition the points we are dragging into (potentially several)
606 * set(s) of contiguous points. this will not happen with a normal
607 * drag, but if the user does a discontiguous selection, it can.
610 uint32_t expected_view_index = 0;
613 for (list<ControlPoint*>::iterator i = _drag_points.begin(); i != _drag_points.end(); ++i) {
614 if (i == _drag_points.begin() || (*i)->view_index() != expected_view_index) {
615 contig.reset (new ContiguousControlPoints (*this));
616 contiguous_points.push_back (contig);
618 contig->push_back (*i);
619 expected_view_index = (*i)->view_index() + 1;
622 if (contiguous_points.back()->empty()) {
623 contiguous_points.pop_back ();
626 for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
627 (*ccp)->compute_x_bounds ();
631 /* OK, now on to the stuff related to *this* motion event. First, for
632 * each contiguous range, figure out the maximum x-axis motion we are
633 * allowed (because of neighbouring points that are not moving.
635 * if we are moving forwards with push, we don't need to do this,
636 * since all later points will move too.
639 if (dx < 0 || ((dx > 0) && !with_push)) {
640 for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
641 double dxt = (*ccp)->clamp_dx (dx);
642 if (fabs (dxt) < fabs (dx)) {
650 for (list<ControlPoint*>::iterator i = _drag_points.begin(); i != _drag_points.end(); ++i) {
651 double const y = ((_height - (*i)->get_y()) / _height) + dy;
662 /* and now move each section */
664 for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
665 (*ccp)->move (dx, dy);
668 final_index = contiguous_points.back()->back()->view_index () + 1;
670 uint32_t i = final_index;
671 while ((p = nth (i)) != 0 && p->can_slide()) {
672 p->move_to (p->get_x() + dx, p->get_y(), ControlPoint::Full);
673 reset_line_coords (*p);
678 /* update actual line coordinates (will queue a redraw)
681 if (line_points.size() > 1) {
682 line->set (line_points);
686 _drag_distance += dx;
688 _last_drag_fraction = fraction;
689 _drag_had_movement = true;
690 did_push = with_push;
692 return pair<double, float> (_drag_x + dx, _last_drag_fraction + dy);
695 /** Should be called to indicate the end of a drag */
697 AutomationLine::end_drag (bool with_push, uint32_t final_index)
699 if (!_drag_had_movement) {
704 sync_model_with_view_points (_drag_points);
708 uint32_t i = final_index;
709 while ((p = nth (i)) != 0 && p->can_slide()) {
710 sync_model_with_view_point (*p);
717 update_pending = false;
719 trackview.editor().session()->add_command (
720 new MementoCommand<AutomationList>(memento_command_binder (), 0, &alist->get_state())
723 trackview.editor().session()->set_dirty ();
726 contiguous_points.clear ();
730 AutomationLine::sync_model_with_view_point (ControlPoint& cp)
732 /* find out where the visual control point is.
733 initial results are in canvas units. ask the
734 line to convert them to something relevant.
737 double view_x = cp.get_x();
738 double view_y = 1.0 - (cp.get_y() / _height);
740 /* if xval has not changed, set it directly from the model to avoid rounding errors */
742 if (view_x == trackview.editor().sample_to_pixel_unrounded (_time_converter->to ((*cp.model())->when)) - _offset) {
743 view_x = (*cp.model())->when - _offset;
745 view_x = trackview.editor().pixel_to_sample (view_x);
746 view_x = _time_converter->from (view_x + _offset);
749 update_pending = true;
751 view_to_model_coord_y (view_y);
753 alist->modify (cp.model(), view_x, view_y);
757 AutomationLine::control_points_adjacent (double xval, uint32_t & before, uint32_t& after)
759 ControlPoint *bcp = 0;
760 ControlPoint *acp = 0;
763 unit_xval = trackview.editor().sample_to_pixel_unrounded (xval);
765 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
767 if ((*i)->get_x() <= unit_xval) {
769 if (!bcp || (*i)->get_x() > bcp->get_x()) {
771 before = bcp->view_index();
774 } else if ((*i)->get_x() > unit_xval) {
776 after = acp->view_index();
785 AutomationLine::is_last_point (ControlPoint& cp)
787 // If the list is not empty, and the point is the last point in the list
789 if (alist->empty()) {
793 AutomationList::const_iterator i = alist->end();
796 if (cp.model() == i) {
804 AutomationLine::is_first_point (ControlPoint& cp)
806 // If the list is not empty, and the point is the first point in the list
808 if (!alist->empty() && cp.model() == alist->begin()) {
815 // This is copied into AudioRegionGainLine
817 AutomationLine::remove_point (ControlPoint& cp)
819 trackview.editor().session()->begin_reversible_command (_("remove control point"));
820 XMLNode &before = alist->get_state();
822 alist->erase (cp.model());
824 trackview.editor().session()->add_command(
825 new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state())
828 trackview.editor().session()->commit_reversible_command ();
829 trackview.editor().session()->set_dirty ();
832 /** Get selectable points within an area.
833 * @param start Start position in session frames.
834 * @param end End position in session frames.
835 * @param bot Bottom y range, as a fraction of line height, where 0 is the bottom of the line.
836 * @param top Top y range, as a fraction of line height, where 0 is the bottom of the line.
837 * @param result Filled in with selectable things; in this case, ControlPoints.
840 AutomationLine::get_selectables (framepos_t start, framepos_t end, double botfrac, double topfrac, list<Selectable*>& results)
842 /* convert fractions to display coordinates with 0 at the top of the track */
843 double const bot_track = (1 - topfrac) * trackview.current_height ();
844 double const top_track = (1 - botfrac) * trackview.current_height ();
846 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
847 double const model_when = (*(*i)->model())->when;
849 /* model_when is relative to the start of the source, so we just need to add on the origin_b here
850 (as it is the session frame position of the start of the source)
853 framepos_t const session_frames_when = _time_converter->to (model_when) + _time_converter->origin_b ();
855 if (session_frames_when >= start && session_frames_when <= end && (*i)->get_y() >= bot_track && (*i)->get_y() <= top_track) {
856 results.push_back (*i);
862 AutomationLine::get_inverted_selectables (Selection&, list<Selectable*>& /*results*/)
868 AutomationLine::set_selected_points (PointSelection const & points)
870 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
871 (*i)->set_selected (false);
874 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
875 (*i)->set_selected (true);
881 void AutomationLine::set_colors ()
883 set_line_color (ARDOUR_UI::config()->get_canvasvar_AutomationLine());
884 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
890 AutomationLine::list_changed ()
892 DEBUG_TRACE (DEBUG::Automation, string_compose ("\tline changed, existing update pending? %1\n", update_pending));
894 if (!update_pending) {
895 update_pending = true;
896 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AutomationLine::queue_reset, this));
901 AutomationLine::reset_callback (const Evoral::ControlList& events)
907 if (events.empty()) {
908 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
911 control_points.clear ();
916 /* hide all existing points, and the line */
918 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
925 Evoral::ControlList& e = const_cast<Evoral::ControlList&> (events);
927 for (AutomationList::iterator ai = e.begin(); ai != e.end(); ++ai, ++pi) {
929 double tx = (*ai)->when;
930 double ty = (*ai)->value;
932 /* convert from model coordinates to canonical view coordinates */
934 model_to_view_coord (tx, ty);
936 if (std::isnan (tx) || std::isnan (ty)) {
937 warning << string_compose (_("Ignoring illegal points on AutomationLine \"%1\""),
942 if (tx >= max_framepos || tx < 0 || tx >= _maximum_time) {
946 /* convert x-coordinate to a canvas unit coordinate (this takes
947 * zoom and scroll into account).
950 tx = trackview.editor().sample_to_pixel_unrounded (tx);
952 /* convert from canonical view height (0..1.0) to actual
953 * height coordinates (using X11's top-left rooted system)
956 ty = _height - (ty * _height);
958 add_visible_control_point (vp, pi, tx, ty, ai, np);
962 /* discard extra CP's to avoid confusing ourselves */
964 while (control_points.size() > vp) {
965 ControlPoint* cp = control_points.back();
966 control_points.pop_back ();
970 if (!terminal_points_can_slide) {
971 control_points.back()->set_can_slide(false);
976 /* reset the line coordinates given to the CanvasLine */
978 while (line_points.size() < vp) {
979 line_points.push_back (ArdourCanvas::Duple (0,0));
982 while (line_points.size() > vp) {
983 line_points.pop_back ();
986 for (uint32_t n = 0; n < vp; ++n) {
987 line_points[n].x = control_points[n]->get_x();
988 line_points[n].y = control_points[n]->get_y();
991 line->set (line_points);
993 if (_visible && alist->interpolation() != AutomationList::Discrete) {
998 set_selected_points (trackview.editor().get_selection().points);
1002 AutomationLine::reset ()
1004 DEBUG_TRACE (DEBUG::Automation, "\t\tLINE RESET\n");
1005 update_pending = false;
1006 have_timeout = false;
1012 alist->apply_to_points (*this, &AutomationLine::reset_callback);
1016 AutomationLine::queue_reset ()
1018 /* this must be called from the GUI thread
1021 if (trackview.editor().session()->transport_rolling() && alist->automation_write()) {
1022 /* automation write pass ... defer to a timeout */
1023 /* redraw in 1/4 second */
1024 if (!have_timeout) {
1025 DEBUG_TRACE (DEBUG::Automation, "\tqueue timeout\n");
1026 Glib::signal_timeout().connect (sigc::bind_return (sigc::mem_fun (*this, &AutomationLine::reset), false), 250);
1027 have_timeout = true;
1029 DEBUG_TRACE (DEBUG::Automation, "\ttimeout already queued, change ignored\n");
1037 AutomationLine::clear ()
1039 /* parent must create and commit command */
1040 XMLNode &before = alist->get_state();
1043 trackview.editor().session()->add_command (
1044 new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state())
1049 AutomationLine::change_model (AutomationList::iterator /*i*/, double /*x*/, double /*y*/)
1054 AutomationLine::set_list (boost::shared_ptr<ARDOUR::AutomationList> list)
1062 AutomationLine::add_visibility (VisibleAspects va)
1064 _visible = VisibleAspects (_visible | va);
1069 AutomationLine::set_visibility (VisibleAspects va)
1076 AutomationLine::remove_visibility (VisibleAspects va)
1078 _visible = VisibleAspects (_visible & ~va);
1083 AutomationLine::track_entered()
1085 if (alist->interpolation() != AutomationList::Discrete) {
1086 add_visibility (ControlPoints);
1091 AutomationLine::track_exited()
1093 if (alist->interpolation() != AutomationList::Discrete) {
1094 remove_visibility (ControlPoints);
1099 AutomationLine::get_state (void)
1101 /* function as a proxy for the model */
1102 return alist->get_state();
1106 AutomationLine::set_state (const XMLNode &node, int version)
1108 /* function as a proxy for the model */
1109 return alist->set_state (node, version);
1113 AutomationLine::view_to_model_coord (double& x, double& y) const
1115 x = _time_converter->from (x);
1116 view_to_model_coord_y (y);
1120 AutomationLine::view_to_model_coord_y (double& y) const
1122 /* TODO: This should be more generic ... */
1123 if (alist->parameter().type() == GainAutomation ||
1124 alist->parameter().type() == EnvelopeAutomation) {
1125 y = slider_position_to_gain_with_max (y, Config->get_max_gain());
1128 } else if (alist->parameter().type() == PanAzimuthAutomation ||
1129 alist->parameter().type() == PanElevationAutomation ||
1130 alist->parameter().type() == PanWidthAutomation) {
1132 } else if (alist->parameter().type() == PluginAutomation) {
1133 y = y * (double)(alist->get_max_y()- alist->get_min_y()) + alist->get_min_y();
1135 y = rint (y * alist->parameter().max());
1140 AutomationLine::model_to_view_coord (double& x, double& y) const
1142 /* TODO: This should be more generic ... */
1143 if (alist->parameter().type() == GainAutomation ||
1144 alist->parameter().type() == EnvelopeAutomation) {
1145 y = gain_to_slider_position_with_max (y, Config->get_max_gain());
1146 } else if (alist->parameter().type() == PanAzimuthAutomation ||
1147 alist->parameter().type() == PanElevationAutomation ||
1148 alist->parameter().type() == PanWidthAutomation) {
1149 // vertical coordinate axis reversal
1151 } else if (alist->parameter().type() == PluginAutomation) {
1152 y = (y - alist->get_min_y()) / (double)(alist->get_max_y()- alist->get_min_y());
1154 y = y / (double)alist->parameter().max(); /* ... like this */
1157 x = _time_converter->to (x) - _offset;
1160 /** Called when our list has announced that its interpolation style has changed */
1162 AutomationLine::interpolation_changed (AutomationList::InterpolationStyle style)
1164 if (style == AutomationList::Discrete) {
1165 set_visibility (ControlPoints);
1168 set_visibility (Line);
1173 AutomationLine::add_visible_control_point (uint32_t view_index, uint32_t pi, double tx, double ty,
1174 AutomationList::iterator model, uint32_t npoints)
1176 ControlPoint::ShapeType shape;
1178 if (view_index >= control_points.size()) {
1180 /* make sure we have enough control points */
1182 ControlPoint* ncp = new ControlPoint (*this);
1183 ncp->set_size (control_point_box_size ());
1185 control_points.push_back (ncp);
1188 if (!terminal_points_can_slide) {
1190 control_points[view_index]->set_can_slide (false);
1192 shape = ControlPoint::Start;
1194 shape = ControlPoint::Full;
1196 } else if (pi == npoints - 1) {
1197 control_points[view_index]->set_can_slide (false);
1198 shape = ControlPoint::End;
1200 control_points[view_index]->set_can_slide (true);
1201 shape = ControlPoint::Full;
1204 control_points[view_index]->set_can_slide (true);
1205 shape = ControlPoint::Full;
1208 control_points[view_index]->reset (tx, ty, model, view_index, shape);
1210 /* finally, control visibility */
1212 if (_visible & ControlPoints) {
1213 control_points[view_index]->show ();
1214 control_points[view_index]->set_visible (true);
1216 control_points[view_index]->set_visible (false);
1221 AutomationLine::connect_to_list ()
1223 _list_connections.drop_connections ();
1225 alist->StateChanged.connect (_list_connections, invalidator (*this), boost::bind (&AutomationLine::list_changed, this), gui_context());
1227 alist->InterpolationChanged.connect (
1228 _list_connections, invalidator (*this), boost::bind (&AutomationLine::interpolation_changed, this, _1), gui_context()
1232 MementoCommandBinder<AutomationList>*
1233 AutomationLine::memento_command_binder ()
1235 return new SimpleMementoCommandBinder<AutomationList> (*alist.get());
1238 /** Set the maximum time that points on this line can be at, relative
1239 * to the start of the track or region that it is on.
1242 AutomationLine::set_maximum_time (framecnt_t t)
1244 if (_maximum_time == t) {
1253 /** @return min and max x positions of points that are in the list, in session frames */
1254 pair<framepos_t, framepos_t>
1255 AutomationLine::get_point_x_range () const
1257 pair<framepos_t, framepos_t> r (max_framepos, 0);
1259 for (AutomationList::const_iterator i = the_list()->begin(); i != the_list()->end(); ++i) {
1260 r.first = min (r.first, session_position (i));
1261 r.second = max (r.second, session_position (i));
1268 AutomationLine::session_position (AutomationList::const_iterator p) const
1270 return _time_converter->to ((*p)->when) + _offset + _time_converter->origin_b ();
1274 AutomationLine::set_offset (framepos_t off)
1276 if (_offset == off) {