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.
22 /* isinf() & isnan() are C99 standards, which older MSVC doesn't provide */
23 #define isinf(val) !((bool)_finite((double)val))
24 #define isnan(val) (bool)_isnan((double)val)
32 #include "boost/shared_ptr.hpp"
34 #include "pbd/floating.h"
35 #include "pbd/memento_command.h"
36 #include "pbd/stl_delete.h"
37 #include "pbd/stacktrace.h"
39 #include "ardour/automation_list.h"
40 #include "ardour/dB.h"
41 #include "ardour/debug.h"
42 #include "ardour/parameter_types.h"
43 #include "ardour/tempo.h"
45 #include "evoral/Curve.hpp"
47 #include "canvas/debug.h"
49 #include "automation_line.h"
50 #include "control_point.h"
51 #include "gui_thread.h"
52 #include "rgb_macros.h"
53 #include "ardour_ui.h"
54 #include "public_editor.h"
55 #include "selection.h"
56 #include "time_axis_view.h"
57 #include "point_selection.h"
58 #include "automation_time_axis.h"
60 #include "ardour/event_type_map.h"
61 #include "ardour/session.h"
62 #include "ardour/value_as_string.h"
67 using namespace ARDOUR;
69 using namespace Editing;
71 /** @param converter A TimeConverter whose origin_b is the start time of the AutomationList in session frames.
72 * This will not be deleted by AutomationLine.
74 AutomationLine::AutomationLine (const string& name,
76 ArdourCanvas::Item& parent,
77 boost::shared_ptr<AutomationList> al,
78 const ParameterDescriptor& desc,
79 Evoral::TimeConverter<double, framepos_t>* converter)
83 , _time_converter (converter ? converter : new Evoral::IdentityConverter<double, framepos_t>)
84 , _parent_group (parent)
86 , _maximum_time (max_framepos)
90 _our_time_converter = false;
92 _our_time_converter = true;
97 update_pending = false;
99 _uses_gain_mapping = false;
102 terminal_points_can_slide = true;
105 group = new ArdourCanvas::Container (&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);
112 line->set_covers_threshold (4.0);
114 line->Event.connect (sigc::mem_fun (*this, &AutomationLine::event_handler));
116 trackview.session()->register_with_memento_command_factory(alist->id(), this);
118 if (alist->parameter().type() == GainAutomation ||
119 alist->parameter().type() == EnvelopeAutomation ||
120 desc.unit == ParameterDescriptor::DB) {
121 set_uses_gain_mapping (true);
124 interpolation_changed (alist->interpolation ());
129 AutomationLine::~AutomationLine ()
131 vector_delete (&control_points);
134 if (_our_time_converter) {
135 delete _time_converter;
140 AutomationLine::event_handler (GdkEvent* event)
142 return PublicEditor::instance().canvas_line_event (event, line, this);
146 AutomationLine::update_visibility ()
148 if (_visible & Line) {
149 /* Only show the line there are some points, otherwise we may show an out-of-date line
150 when automation points have been removed (the line will still follow the shape of the
153 if (alist->interpolation() != AutomationList::Discrete && control_points.size() >= 2) {
159 if (_visible & ControlPoints) {
160 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
163 } else if (_visible & SelectedControlPoints) {
164 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
165 if ((*i)->get_selected()) {
172 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
179 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
187 AutomationLine::hide ()
189 /* leave control points setting unchanged, we are just hiding the
193 set_visibility (AutomationLine::VisibleAspects (_visible & ~Line));
197 AutomationLine::control_point_box_size ()
199 if (alist->interpolation() == AutomationList::Discrete) {
200 return max((_height*4.0) / (double)(alist->parameter().max() - alist->parameter().min()),
204 if (_height > TimeAxisView::preset_height (HeightLarger)) {
206 } else if (_height > (guint32) TimeAxisView::preset_height (HeightNormal)) {
213 AutomationLine::set_height (guint32 h)
218 double bsz = control_point_box_size();
220 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
221 (*i)->set_size (bsz);
229 AutomationLine::set_line_color (uint32_t color)
232 line->set_outline_color (color);
236 AutomationLine::set_uses_gain_mapping (bool yn)
238 if (yn != _uses_gain_mapping) {
239 _uses_gain_mapping = yn;
245 AutomationLine::nth (uint32_t n)
247 if (n < control_points.size()) {
248 return control_points[n];
255 AutomationLine::nth (uint32_t n) const
257 if (n < control_points.size()) {
258 return control_points[n];
265 AutomationLine::modify_point_y (ControlPoint& cp, double y)
267 /* clamp y-coord appropriately. y is supposed to be a normalized fraction (0.0-1.0),
268 and needs to be converted to a canvas unit distance.
273 y = _height - (y * _height);
275 double const x = trackview.editor().sample_to_pixel_unrounded (_time_converter->to((*cp.model())->when) - _offset);
277 trackview.editor().session()->begin_reversible_command (_("automation event move"));
278 trackview.editor().session()->add_command (
279 new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0));
281 cp.move_to (x, y, ControlPoint::Full);
283 reset_line_coords (cp);
285 if (line_points.size() > 1) {
286 line->set (line_points);
290 sync_model_with_view_point (cp);
293 update_pending = false;
295 trackview.editor().session()->add_command (
296 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
364 if (_uses_gain_mapping) {
366 if (fraction == 0.0) {
367 snprintf (buf, sizeof (buf), "-inf");
369 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 return ARDOUR::value_as_string (_desc, fraction);
377 return ""; /*NOTREACHED*/
381 * @param original an old y-axis fraction
382 * @param fraction the new y fraction
383 * @return string representation of the difference between original and fraction, using dB if appropriate.
386 AutomationLine::fraction_to_relative_string (double original, double fraction) const
390 if (original == fraction) {
394 if (_uses_gain_mapping) {
395 if (original == 0.0) {
396 /* there is no sensible representation of a relative
397 change from -inf dB, so return an empty string.
400 } else if (fraction == 0.0) {
401 snprintf (buf, sizeof (buf), "-inf");
403 double old_db = accurate_coefficient_to_dB (slider_position_to_gain_with_max (original, Config->get_max_gain()));
404 double new_db = accurate_coefficient_to_dB (slider_position_to_gain_with_max (fraction, Config->get_max_gain()));
405 snprintf (buf, sizeof (buf), "%.1f", new_db - old_db);
408 view_to_model_coord_y (original);
409 view_to_model_coord_y (fraction);
410 return ARDOUR::value_as_string (_desc, fraction - original);
417 * @param s Value string in the form as returned by fraction_to_string.
418 * @return Corresponding y fraction.
421 AutomationLine::string_to_fraction (string const & s) const
428 sscanf (s.c_str(), "%lf", &v);
430 if (_uses_gain_mapping) {
431 v = gain_to_slider_position_with_max (dB_to_coefficient (v), Config->get_max_gain());
434 model_to_view_coord (dummy, v);
440 /** Start dragging a single point, possibly adding others if the supplied point is selected and there
441 * are other selected points.
443 * @param cp Point to drag.
444 * @param x Initial x position (units).
445 * @param fraction Initial y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
448 AutomationLine::start_drag_single (ControlPoint* cp, double x, float fraction)
450 trackview.editor().session()->begin_reversible_command (_("automation event move"));
451 trackview.editor().session()->add_command (
452 new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0));
454 _drag_points.clear ();
455 _drag_points.push_back (cp);
457 if (cp->get_selected ()) {
458 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
459 if (*i != cp && (*i)->get_selected()) {
460 _drag_points.push_back (*i);
465 start_drag_common (x, fraction);
468 /** Start dragging a line vertically (with no change in x)
469 * @param i1 Control point index of the `left' point on the line.
470 * @param i2 Control point index of the `right' point on the line.
471 * @param fraction Initial y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
474 AutomationLine::start_drag_line (uint32_t i1, uint32_t i2, float fraction)
476 trackview.editor().session()->begin_reversible_command (_("automation range move"));
477 trackview.editor().session()->add_command (
478 new MementoCommand<AutomationList> (memento_command_binder (), &get_state(), 0));
480 _drag_points.clear ();
482 for (uint32_t i = i1; i <= i2; i++) {
483 _drag_points.push_back (nth (i));
486 start_drag_common (0, fraction);
489 /** Start dragging multiple points (with no change in x)
490 * @param cp Points to drag.
491 * @param fraction Initial y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
494 AutomationLine::start_drag_multiple (list<ControlPoint*> cp, float fraction, XMLNode* state)
496 trackview.editor().session()->begin_reversible_command (_("automation range move"));
497 trackview.editor().session()->add_command (
498 new MementoCommand<AutomationList> (memento_command_binder(), state, 0));
501 start_drag_common (0, fraction);
504 struct ControlPointSorter
506 bool operator() (ControlPoint const * a, ControlPoint const * b) const {
507 if (floateq (a->get_x(), b->get_x(), 1)) {
508 return a->view_index() < b->view_index();
510 return a->get_x() < b->get_x();
514 AutomationLine::ContiguousControlPoints::ContiguousControlPoints (AutomationLine& al)
515 : line (al), before_x (0), after_x (DBL_MAX)
520 AutomationLine::ContiguousControlPoints::compute_x_bounds (PublicEditor& e)
522 uint32_t sz = size();
524 if (sz > 0 && sz < line.npoints()) {
525 const TempoMap& map (e.session()->tempo_map());
527 /* determine the limits on x-axis motion for this
528 contiguous range of control points
531 if (front()->view_index() > 0) {
532 before_x = line.nth (front()->view_index() - 1)->get_x();
534 const framepos_t pos = e.pixel_to_sample(before_x);
535 const Meter& meter = map.meter_at (pos);
536 const framecnt_t len = ceil (meter.frames_per_bar (map.tempo_at (pos), e.session()->frame_rate())
537 / (Timecode::BBT_Time::ticks_per_beat * meter.divisions_per_bar()) );
538 const double one_tick_in_pixels = e.sample_to_pixel_unrounded (len);
540 before_x += one_tick_in_pixels;
543 /* if our last point has a point after it in the line,
544 we have an "after" bound
547 if (back()->view_index() < (line.npoints() - 1)) {
548 after_x = line.nth (back()->view_index() + 1)->get_x();
550 const framepos_t pos = e.pixel_to_sample(after_x);
551 const Meter& meter = map.meter_at (pos);
552 const framecnt_t len = ceil (meter.frames_per_bar (map.tempo_at (pos), e.session()->frame_rate())
553 / (Timecode::BBT_Time::ticks_per_beat * meter.divisions_per_bar()));
554 const double one_tick_in_pixels = e.sample_to_pixel_unrounded (len);
556 after_x -= one_tick_in_pixels;
562 AutomationLine::ContiguousControlPoints::clamp_dx (double dx)
568 /* get the maximum distance we can move any of these points along the x-axis
571 double tx; /* possible position a point would move to, given dx */
575 /* check the last point, since we're moving later in time */
578 /* check the first point, since we're moving earlier in time */
582 tx = cp->get_x() + dx; // new possible position if we just add the motion
583 tx = max (tx, before_x); // can't move later than following point
584 tx = min (tx, after_x); // can't move earlier than preceeding point
585 return tx - cp->get_x ();
589 AutomationLine::ContiguousControlPoints::move (double dx, double dy)
591 for (std::list<ControlPoint*>::iterator i = begin(); i != end(); ++i) {
592 (*i)->move_to ((*i)->get_x() + dx, (*i)->get_y() - line.height() * dy, ControlPoint::Full);
593 line.reset_line_coords (**i);
597 /** Common parts of starting a drag.
598 * @param x Starting x position in units, or 0 if x is being ignored.
599 * @param fraction Starting y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
602 AutomationLine::start_drag_common (double x, float fraction)
606 _last_drag_fraction = fraction;
607 _drag_had_movement = false;
610 /* they are probably ordered already, but we have to make sure */
612 _drag_points.sort (ControlPointSorter());
616 /** Should be called to indicate motion during a drag.
617 * @param x New x position of the drag in canvas units, or undefined if ignore_x == true.
618 * @param fraction New y fraction.
619 * @return x position and y fraction that were actually used (once clamped).
622 AutomationLine::drag_motion (double const x, float fraction, bool ignore_x, bool with_push, uint32_t& final_index)
624 if (_drag_points.empty()) {
625 return pair<double,float> (x,fraction);
628 double dx = ignore_x ? 0 : (x - _drag_x);
629 double dy = fraction - _last_drag_fraction;
631 if (!_drag_had_movement) {
633 /* "first move" ... do some stuff that we don't want to do if
634 no motion ever took place, but need to do before we handle
638 /* partition the points we are dragging into (potentially several)
639 * set(s) of contiguous points. this will not happen with a normal
640 * drag, but if the user does a discontiguous selection, it can.
643 uint32_t expected_view_index = 0;
646 for (list<ControlPoint*>::iterator i = _drag_points.begin(); i != _drag_points.end(); ++i) {
647 if (i == _drag_points.begin() || (*i)->view_index() != expected_view_index) {
648 contig.reset (new ContiguousControlPoints (*this));
649 contiguous_points.push_back (contig);
651 contig->push_back (*i);
652 expected_view_index = (*i)->view_index() + 1;
655 if (contiguous_points.back()->empty()) {
656 contiguous_points.pop_back ();
659 for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
660 (*ccp)->compute_x_bounds (trackview.editor());
664 /* OK, now on to the stuff related to *this* motion event. First, for
665 * each contiguous range, figure out the maximum x-axis motion we are
666 * allowed (because of neighbouring points that are not moving.
668 * if we are moving forwards with push, we don't need to do this,
669 * since all later points will move too.
672 if (dx < 0 || ((dx > 0) && !with_push)) {
673 for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
674 double dxt = (*ccp)->clamp_dx (dx);
675 if (fabs (dxt) < fabs (dx)) {
683 for (list<ControlPoint*>::iterator i = _drag_points.begin(); i != _drag_points.end(); ++i) {
684 double const y = ((_height - (*i)->get_y()) / _height) + dy;
695 /* and now move each section */
697 for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
698 (*ccp)->move (dx, dy);
701 final_index = contiguous_points.back()->back()->view_index () + 1;
703 uint32_t i = final_index;
704 while ((p = nth (i)) != 0 && p->can_slide()) {
705 p->move_to (p->get_x() + dx, p->get_y(), ControlPoint::Full);
706 reset_line_coords (*p);
711 /* update actual line coordinates (will queue a redraw)
714 if (line_points.size() > 1) {
715 line->set (line_points);
719 _drag_distance += dx;
721 _last_drag_fraction = fraction;
722 _drag_had_movement = true;
723 did_push = with_push;
725 return pair<double, float> (_drag_x + dx, _last_drag_fraction + dy);
728 /** Should be called to indicate the end of a drag */
730 AutomationLine::end_drag (bool with_push, uint32_t final_index)
732 if (!_drag_had_movement) {
737 sync_model_with_view_points (_drag_points);
741 uint32_t i = final_index;
742 while ((p = nth (i)) != 0 && p->can_slide()) {
743 sync_model_with_view_point (*p);
750 update_pending = false;
752 trackview.editor().session()->add_command (
753 new MementoCommand<AutomationList>(memento_command_binder (), 0, &alist->get_state()));
755 trackview.editor().session()->set_dirty ();
758 contiguous_points.clear ();
762 AutomationLine::sync_model_with_view_point (ControlPoint& cp)
764 /* find out where the visual control point is.
765 initial results are in canvas units. ask the
766 line to convert them to something relevant.
769 double view_x = cp.get_x();
770 double view_y = 1.0 - (cp.get_y() / _height);
772 /* if xval has not changed, set it directly from the model to avoid rounding errors */
774 if (view_x == trackview.editor().sample_to_pixel_unrounded (_time_converter->to ((*cp.model())->when)) - _offset) {
775 view_x = (*cp.model())->when - _offset;
777 view_x = trackview.editor().pixel_to_sample (view_x);
778 view_x = _time_converter->from (view_x + _offset);
781 update_pending = true;
783 view_to_model_coord_y (view_y);
785 alist->modify (cp.model(), view_x, view_y);
789 AutomationLine::control_points_adjacent (double xval, uint32_t & before, uint32_t& after)
791 ControlPoint *bcp = 0;
792 ControlPoint *acp = 0;
795 unit_xval = trackview.editor().sample_to_pixel_unrounded (xval);
797 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
799 if ((*i)->get_x() <= unit_xval) {
801 if (!bcp || (*i)->get_x() > bcp->get_x()) {
803 before = bcp->view_index();
806 } else if ((*i)->get_x() > unit_xval) {
808 after = acp->view_index();
817 AutomationLine::is_last_point (ControlPoint& cp)
819 // If the list is not empty, and the point is the last point in the list
821 if (alist->empty()) {
825 AutomationList::const_iterator i = alist->end();
828 if (cp.model() == i) {
836 AutomationLine::is_first_point (ControlPoint& cp)
838 // If the list is not empty, and the point is the first point in the list
840 if (!alist->empty() && cp.model() == alist->begin()) {
847 // This is copied into AudioRegionGainLine
849 AutomationLine::remove_point (ControlPoint& cp)
851 trackview.editor().session()->begin_reversible_command (_("remove control point"));
852 XMLNode &before = alist->get_state();
854 alist->erase (cp.model());
856 trackview.editor().session()->add_command(
857 new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state()));
859 trackview.editor().session()->commit_reversible_command ();
860 trackview.editor().session()->set_dirty ();
863 /** Get selectable points within an area.
864 * @param start Start position in session frames.
865 * @param end End position in session frames.
866 * @param bot Bottom y range, as a fraction of line height, where 0 is the bottom of the line.
867 * @param top Top y range, as a fraction of line height, where 0 is the bottom of the line.
868 * @param result Filled in with selectable things; in this case, ControlPoints.
871 AutomationLine::get_selectables (framepos_t start, framepos_t end, double botfrac, double topfrac, list<Selectable*>& results)
873 /* convert fractions to display coordinates with 0 at the top of the track */
874 double const bot_track = (1 - topfrac) * trackview.current_height ();
875 double const top_track = (1 - botfrac) * trackview.current_height ();
877 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
878 double const model_when = (*(*i)->model())->when;
880 /* model_when is relative to the start of the source, so we just need to add on the origin_b here
881 (as it is the session frame position of the start of the source)
884 framepos_t const session_frames_when = _time_converter->to (model_when) + _time_converter->origin_b ();
886 if (session_frames_when >= start && session_frames_when <= end && (*i)->get_y() >= bot_track && (*i)->get_y() <= top_track) {
887 results.push_back (*i);
893 AutomationLine::get_inverted_selectables (Selection&, list<Selectable*>& /*results*/)
899 AutomationLine::set_selected_points (PointSelection const & points)
901 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
902 (*i)->set_selected (false);
905 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
906 (*i)->set_selected (true);
912 void AutomationLine::set_colors ()
914 set_line_color (ARDOUR_UI::config()->get_AutomationLine());
915 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
921 AutomationLine::list_changed ()
923 DEBUG_TRACE (DEBUG::Automation, string_compose ("\tline changed, existing update pending? %1\n", update_pending));
925 if (!update_pending) {
926 update_pending = true;
927 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AutomationLine::queue_reset, this));
932 AutomationLine::reset_callback (const Evoral::ControlList& events)
938 if (events.empty()) {
939 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
942 control_points.clear ();
947 /* hide all existing points, and the line */
949 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
956 Evoral::ControlList& e = const_cast<Evoral::ControlList&> (events);
958 for (AutomationList::iterator ai = e.begin(); ai != e.end(); ++ai, ++pi) {
960 double tx = (*ai)->when;
961 double ty = (*ai)->value;
963 /* convert from model coordinates to canonical view coordinates */
965 model_to_view_coord (tx, ty);
967 if (isnan (tx) || isnan (ty)) {
968 warning << string_compose (_("Ignoring illegal points on AutomationLine \"%1\""),
973 if (tx >= max_framepos || tx < 0 || tx >= _maximum_time) {
977 /* convert x-coordinate to a canvas unit coordinate (this takes
978 * zoom and scroll into account).
981 tx = trackview.editor().sample_to_pixel_unrounded (tx);
983 /* convert from canonical view height (0..1.0) to actual
984 * height coordinates (using X11's top-left rooted system)
987 ty = _height - (ty * _height);
989 add_visible_control_point (vp, pi, tx, ty, ai, np);
993 /* discard extra CP's to avoid confusing ourselves */
995 while (control_points.size() > vp) {
996 ControlPoint* cp = control_points.back();
997 control_points.pop_back ();
1001 if (!terminal_points_can_slide) {
1002 control_points.back()->set_can_slide(false);
1007 /* reset the line coordinates given to the CanvasLine */
1009 while (line_points.size() < vp) {
1010 line_points.push_back (ArdourCanvas::Duple (0,0));
1013 while (line_points.size() > vp) {
1014 line_points.pop_back ();
1017 for (uint32_t n = 0; n < vp; ++n) {
1018 line_points[n].x = control_points[n]->get_x();
1019 line_points[n].y = control_points[n]->get_y();
1022 line->set (line_points);
1024 update_visibility ();
1027 set_selected_points (trackview.editor().get_selection().points);
1031 AutomationLine::reset ()
1033 DEBUG_TRACE (DEBUG::Automation, "\t\tLINE RESET\n");
1034 update_pending = false;
1035 have_timeout = false;
1041 alist->apply_to_points (*this, &AutomationLine::reset_callback);
1045 AutomationLine::queue_reset ()
1047 /* this must be called from the GUI thread
1050 if (trackview.editor().session()->transport_rolling() && alist->automation_write()) {
1051 /* automation write pass ... defer to a timeout */
1052 /* redraw in 1/4 second */
1053 if (!have_timeout) {
1054 DEBUG_TRACE (DEBUG::Automation, "\tqueue timeout\n");
1055 Glib::signal_timeout().connect (sigc::bind_return (sigc::mem_fun (*this, &AutomationLine::reset), false), 250);
1056 have_timeout = true;
1058 DEBUG_TRACE (DEBUG::Automation, "\ttimeout already queued, change ignored\n");
1066 AutomationLine::clear ()
1068 /* parent must create and commit command */
1069 XMLNode &before = alist->get_state();
1072 trackview.editor().session()->add_command (
1073 new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state()));
1077 AutomationLine::change_model (AutomationList::iterator /*i*/, double /*x*/, double /*y*/)
1082 AutomationLine::set_list (boost::shared_ptr<ARDOUR::AutomationList> list)
1090 AutomationLine::add_visibility (VisibleAspects va)
1092 VisibleAspects old = _visible;
1094 _visible = VisibleAspects (_visible | va);
1096 if (old != _visible) {
1097 update_visibility ();
1102 AutomationLine::set_visibility (VisibleAspects va)
1104 if (_visible != va) {
1106 update_visibility ();
1111 AutomationLine::remove_visibility (VisibleAspects va)
1113 VisibleAspects old = _visible;
1115 _visible = VisibleAspects (_visible & ~va);
1117 if (old != _visible) {
1118 update_visibility ();
1123 AutomationLine::track_entered()
1125 if (alist->interpolation() != AutomationList::Discrete) {
1126 add_visibility (ControlPoints);
1131 AutomationLine::track_exited()
1133 if (alist->interpolation() != AutomationList::Discrete) {
1134 remove_visibility (ControlPoints);
1139 AutomationLine::get_state (void)
1141 /* function as a proxy for the model */
1142 return alist->get_state();
1146 AutomationLine::set_state (const XMLNode &node, int version)
1148 /* function as a proxy for the model */
1149 return alist->set_state (node, version);
1153 AutomationLine::view_to_model_coord (double& x, double& y) const
1155 x = _time_converter->from (x);
1156 view_to_model_coord_y (y);
1160 AutomationLine::view_to_model_coord_y (double& y) const
1162 /* TODO: This should be more generic (use ParameterDescriptor) */
1163 if (alist->parameter().type() == GainAutomation ||
1164 alist->parameter().type() == EnvelopeAutomation) {
1165 y = slider_position_to_gain_with_max (y, Config->get_max_gain());
1168 } else if (alist->parameter().type() == PanAzimuthAutomation ||
1169 alist->parameter().type() == PanElevationAutomation) {
1171 } else if (alist->parameter().type() == PanWidthAutomation) {
1174 y = y * (double)(alist->get_max_y() - alist->get_min_y()) + alist->get_min_y();
1175 if (ARDOUR::parameter_is_midi((ARDOUR::AutomationType)alist->parameter().type())) {
1182 AutomationLine::model_to_view_coord (double& x, double& y) const
1184 /* TODO: This should be more generic (use ParameterDescriptor) */
1185 if (alist->parameter().type() == GainAutomation ||
1186 alist->parameter().type() == EnvelopeAutomation) {
1187 y = gain_to_slider_position_with_max (y, Config->get_max_gain());
1188 } else if (alist->parameter().type() == PanAzimuthAutomation ||
1189 alist->parameter().type() == PanElevationAutomation) {
1191 } else if (alist->parameter().type() == PanWidthAutomation) {
1194 y = (y - alist->get_min_y()) / (double)(alist->get_max_y() - alist->get_min_y());
1197 x = _time_converter->to (x) - _offset;
1200 /** Called when our list has announced that its interpolation style has changed */
1202 AutomationLine::interpolation_changed (AutomationList::InterpolationStyle style)
1204 if (style == AutomationList::Discrete) {
1205 set_visibility (ControlPoints);
1208 set_visibility (Line);
1213 AutomationLine::add_visible_control_point (uint32_t view_index, uint32_t pi, double tx, double ty,
1214 AutomationList::iterator model, uint32_t npoints)
1216 ControlPoint::ShapeType shape;
1218 if (view_index >= control_points.size()) {
1220 /* make sure we have enough control points */
1222 ControlPoint* ncp = new ControlPoint (*this);
1223 ncp->set_size (control_point_box_size ());
1225 control_points.push_back (ncp);
1228 if (!terminal_points_can_slide) {
1230 control_points[view_index]->set_can_slide (false);
1232 shape = ControlPoint::Start;
1234 shape = ControlPoint::Full;
1236 } else if (pi == npoints - 1) {
1237 control_points[view_index]->set_can_slide (false);
1238 shape = ControlPoint::End;
1240 control_points[view_index]->set_can_slide (true);
1241 shape = ControlPoint::Full;
1244 control_points[view_index]->set_can_slide (true);
1245 shape = ControlPoint::Full;
1248 control_points[view_index]->reset (tx, ty, model, view_index, shape);
1250 /* finally, control visibility */
1252 if (_visible & ControlPoints) {
1253 control_points[view_index]->show ();
1255 control_points[view_index]->hide ();
1260 AutomationLine::connect_to_list ()
1262 _list_connections.drop_connections ();
1264 alist->StateChanged.connect (_list_connections, invalidator (*this), boost::bind (&AutomationLine::list_changed, this), gui_context());
1266 alist->InterpolationChanged.connect (
1267 _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) {