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 "simplerect.h"
39 #include "automation_line.h"
40 #include "control_point.h"
41 #include "gui_thread.h"
42 #include "rgb_macros.h"
43 #include "ardour_ui.h"
44 #include "public_editor.h"
46 #include "selection.h"
47 #include "time_axis_view.h"
48 #include "point_selection.h"
49 #include "automation_time_axis.h"
51 #include "ardour/event_type_map.h"
52 #include "ardour/session.h"
57 using namespace ARDOUR;
59 using namespace Editing;
60 using namespace Gnome; // for Canvas
62 /** @param converter A TimeConverter whose origin_b is the start time of the AutomationList in session frames.
63 * This will not be deleted by AutomationLine.
65 AutomationLine::AutomationLine (const string& name, TimeAxisView& tv, ArdourCanvas::Group& parent,
66 boost::shared_ptr<AutomationList> al,
67 Evoral::TimeConverter<double, framepos_t>* converter)
71 , _time_converter (converter ? converter : new Evoral::IdentityConverter<double, framepos_t>)
72 , _parent_group (parent)
74 , _maximum_time (max_framepos)
77 _time_converter = converter;
78 _our_time_converter = false;
80 _time_converter = new Evoral::IdentityConverter<double, framepos_t>;
81 _our_time_converter = true;
86 update_pending = false;
88 _uses_gain_mapping = false;
91 terminal_points_can_slide = true;
94 group = new ArdourCanvas::Group (parent);
95 group->property_x() = 0.0;
96 group->property_y() = 0.0;
98 line = new ArdourCanvas::Line (*group);
99 line->property_width_pixels() = (guint)1;
100 line->set_data ("line", this);
102 line->signal_event().connect (sigc::mem_fun (*this, &AutomationLine::event_handler));
104 trackview.session()->register_with_memento_command_factory(alist->id(), this);
106 if (alist->parameter().type() == GainAutomation ||
107 alist->parameter().type() == EnvelopeAutomation) {
108 set_uses_gain_mapping (true);
111 interpolation_changed (alist->interpolation ());
116 AutomationLine::~AutomationLine ()
118 vector_delete (&control_points);
121 if (_our_time_converter) {
122 delete _time_converter;
127 AutomationLine::event_handler (GdkEvent* event)
129 return PublicEditor::instance().canvas_line_event (event, line, this);
133 AutomationLine::show ()
135 if (_visible & Line) {
136 /* Only show the line there are some points, otherwise we may show an out-of-date line
137 when automation points have been removed (the line will still follow the shape of the
140 if (alist->interpolation() != AutomationList::Discrete && control_points.size() >= 2) {
149 if (_visible & ControlPoints) {
150 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
151 (*i)->set_visible (true);
154 } else if (_visible & SelectedControlPoints) {
155 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
156 (*i)->set_visible ((*i)->get_selected());
159 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
160 (*i)->set_visible (false);
166 AutomationLine::hide ()
168 set_visibility (VisibleAspects (0));
172 AutomationLine::control_point_box_size ()
174 if (alist->interpolation() == AutomationList::Discrete) {
175 return max((_height*4.0) / (double)(alist->parameter().max() - alist->parameter().min()),
179 if (_height > TimeAxisView::preset_height (HeightLarger)) {
181 } else if (_height > (guint32) TimeAxisView::preset_height (HeightNormal)) {
188 AutomationLine::set_height (guint32 h)
193 double bsz = control_point_box_size();
195 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
196 (*i)->set_size (bsz);
204 AutomationLine::set_line_color (uint32_t color)
207 line->property_fill_color_rgba() = color;
211 AutomationLine::set_uses_gain_mapping (bool yn)
213 if (yn != _uses_gain_mapping) {
214 _uses_gain_mapping = yn;
220 AutomationLine::nth (uint32_t n)
222 if (n < control_points.size()) {
223 return control_points[n];
230 AutomationLine::nth (uint32_t n) const
232 if (n < control_points.size()) {
233 return control_points[n];
240 AutomationLine::modify_point_y (ControlPoint& cp, double y)
242 /* clamp y-coord appropriately. y is supposed to be a normalized fraction (0.0-1.0),
243 and needs to be converted to a canvas unit distance.
248 y = _height - (y * _height);
250 double const x = trackview.editor().frame_to_unit_unrounded (_time_converter->to((*cp.model())->when) - _offset);
252 trackview.editor().session()->begin_reversible_command (_("automation event move"));
253 trackview.editor().session()->add_command (
254 new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0)
257 cp.move_to (x, y, ControlPoint::Full);
259 reset_line_coords (cp);
261 if (line_points.size() > 1) {
262 line->property_points() = line_points;
266 sync_model_with_view_point (cp);
269 update_pending = false;
271 trackview.editor().session()->add_command (
272 new MementoCommand<AutomationList> (memento_command_binder(), 0, &alist->get_state())
275 trackview.editor().session()->commit_reversible_command ();
276 trackview.editor().session()->set_dirty ();
280 AutomationLine::reset_line_coords (ControlPoint& cp)
282 if (cp.view_index() < line_points.size()) {
283 line_points[cp.view_index()].set_x (cp.get_x());
284 line_points[cp.view_index()].set_y (cp.get_y());
289 AutomationLine::sync_model_with_view_points (list<ControlPoint*> cp)
291 update_pending = true;
293 for (list<ControlPoint*>::iterator i = cp.begin(); i != cp.end(); ++i) {
294 sync_model_with_view_point (**i);
299 AutomationLine::get_verbose_cursor_string (double fraction) const
301 std::string s = fraction_to_string (fraction);
302 if (_uses_gain_mapping) {
310 AutomationLine::get_verbose_cursor_relative_string (double original, double fraction) const
312 std::string s = fraction_to_string (fraction);
313 if (_uses_gain_mapping) {
317 std::string d = fraction_to_relative_string (original, fraction);
324 if (_uses_gain_mapping) {
335 * @param fraction y fraction
336 * @return string representation of this value, using dB if appropriate.
339 AutomationLine::fraction_to_string (double fraction) const
343 if (_uses_gain_mapping) {
344 if (fraction == 0.0) {
345 snprintf (buf, sizeof (buf), "-inf");
347 snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain_with_max (fraction, Config->get_max_gain())));
350 view_to_model_coord_y (fraction);
351 if (EventTypeMap::instance().is_integer (alist->parameter())) {
352 snprintf (buf, sizeof (buf), "%d", (int)fraction);
354 snprintf (buf, sizeof (buf), "%.2f", fraction);
362 * @param original an old y-axis fraction
363 * @param fraction the new y fraction
364 * @return string representation of the difference between original and fraction, using dB if appropriate.
367 AutomationLine::fraction_to_relative_string (double original, double fraction) const
371 if (original == fraction) {
375 if (_uses_gain_mapping) {
376 if (original == 0.0) {
377 /* there is no sensible representation of a relative
378 change from -inf dB, so return an empty string.
381 } else if (fraction == 0.0) {
382 snprintf (buf, sizeof (buf), "-inf");
384 double old_db = accurate_coefficient_to_dB (slider_position_to_gain_with_max (original, Config->get_max_gain()));
385 double new_db = accurate_coefficient_to_dB (slider_position_to_gain_with_max (fraction, Config->get_max_gain()));
386 snprintf (buf, sizeof (buf), "%.1f", new_db - old_db);
389 view_to_model_coord_y (original);
390 view_to_model_coord_y (fraction);
391 if (EventTypeMap::instance().is_integer (alist->parameter())) {
392 snprintf (buf, sizeof (buf), "%d", (int)fraction - (int)original);
394 snprintf (buf, sizeof (buf), "%.2f", fraction - original);
402 * @param s Value string in the form as returned by fraction_to_string.
403 * @return Corresponding y fraction.
406 AutomationLine::string_to_fraction (string const & s) const
413 sscanf (s.c_str(), "%lf", &v);
415 if (_uses_gain_mapping) {
416 v = gain_to_slider_position_with_max (dB_to_coefficient (v), Config->get_max_gain());
419 model_to_view_coord (dummy, v);
425 /** Start dragging a single point, possibly adding others if the supplied point is selected and there
426 * are other selected points.
428 * @param cp Point to drag.
429 * @param x Initial x position (units).
430 * @param fraction Initial y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
433 AutomationLine::start_drag_single (ControlPoint* cp, double x, float fraction)
435 trackview.editor().session()->begin_reversible_command (_("automation event move"));
436 trackview.editor().session()->add_command (
437 new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0)
440 _drag_points.clear ();
441 _drag_points.push_back (cp);
443 if (cp->get_selected ()) {
444 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
445 if (*i != cp && (*i)->get_selected()) {
446 _drag_points.push_back (*i);
451 start_drag_common (x, fraction);
454 /** Start dragging a line vertically (with no change in x)
455 * @param i1 Control point index of the `left' point on the line.
456 * @param i2 Control point index of the `right' point on the line.
457 * @param fraction Initial y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
460 AutomationLine::start_drag_line (uint32_t i1, uint32_t i2, float fraction)
462 trackview.editor().session()->begin_reversible_command (_("automation range move"));
463 trackview.editor().session()->add_command (
464 new MementoCommand<AutomationList> (memento_command_binder (), &get_state(), 0)
467 _drag_points.clear ();
469 for (uint32_t i = i1; i <= i2; i++) {
470 _drag_points.push_back (nth (i));
473 start_drag_common (0, fraction);
476 /** Start dragging multiple points (with no change in x)
477 * @param cp Points to drag.
478 * @param fraction Initial y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
481 AutomationLine::start_drag_multiple (list<ControlPoint*> cp, float fraction, XMLNode* state)
483 trackview.editor().session()->begin_reversible_command (_("automation range move"));
484 trackview.editor().session()->add_command (
485 new MementoCommand<AutomationList> (memento_command_binder(), state, 0)
489 start_drag_common (0, fraction);
492 struct ControlPointSorter
494 bool operator() (ControlPoint const * a, ControlPoint const * b) const {
495 if (floateq (a->get_x(), b->get_x(), 1)) {
496 return a->view_index() < b->view_index();
498 return a->get_x() < b->get_x();
502 AutomationLine::ContiguousControlPoints::ContiguousControlPoints (AutomationLine& al)
503 : line (al), before_x (0), after_x (DBL_MAX)
508 AutomationLine::ContiguousControlPoints::compute_x_bounds ()
511 /* determine the limits on x-axis motion for this
512 contiguous range of control points
515 if (front()->view_index() > 0) {
516 before_x = line.nth (front()->view_index() - 1)->get_x();
519 if (back()->view_index() < (line.npoints() - 2)) {
520 after_x = line.nth (back()->view_index() + 1)->get_x();
526 AutomationLine::ContiguousControlPoints::clamp_dx (double dx)
532 /* get the maximum distance we can move any of these points along the x-axis
535 double tx; /* possible position a point would move to, given dx */
539 /* check the last point, since we're moving later in time */
542 /* check the first point, since we're moving earlier in time */
546 tx = cp->get_x() + dx; // new possible position if we just add the motion
547 tx = max (tx, before_x); // can't move later than following point
548 tx = min (tx, after_x); // can't move earlier than preceeding point
549 return tx - cp->get_x ();
553 AutomationLine::ContiguousControlPoints::move (double dx, double dy)
555 for (std::list<ControlPoint*>::iterator i = begin(); i != end(); ++i) {
556 (*i)->move_to ((*i)->get_x() + dx, (*i)->get_y() - line.height() * dy, ControlPoint::Full);
557 line.reset_line_coords (**i);
561 /** Common parts of starting a drag.
562 * @param x Starting x position in units, or 0 if x is being ignored.
563 * @param fraction Starting y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
566 AutomationLine::start_drag_common (double x, float fraction)
570 _last_drag_fraction = fraction;
571 _drag_had_movement = false;
574 /* they are probably ordered already, but we have to make sure */
576 _drag_points.sort (ControlPointSorter());
580 /** Should be called to indicate motion during a drag.
581 * @param x New x position of the drag in canvas units, or undefined if ignore_x == true.
582 * @param fraction New y fraction.
583 * @return x position and y fraction that were actually used (once clamped).
586 AutomationLine::drag_motion (double const x, float fraction, bool ignore_x, bool with_push, uint32_t& final_index)
588 if (_drag_points.empty()) {
589 return pair<double,float> (x,fraction);
592 double dx = ignore_x ? 0 : (x - _drag_x);
593 double dy = fraction - _last_drag_fraction;
595 if (!_drag_had_movement) {
597 /* "first move" ... do some stuff that we don't want to do if
598 no motion ever took place, but need to do before we handle
602 /* partition the points we are dragging into (potentially several)
603 * set(s) of contiguous points. this will not happen with a normal
604 * drag, but if the user does a discontiguous selection, it can.
607 uint32_t expected_view_index = 0;
610 for (list<ControlPoint*>::iterator i = _drag_points.begin(); i != _drag_points.end(); ++i) {
611 if (i == _drag_points.begin() || (*i)->view_index() != expected_view_index) {
612 contig.reset (new ContiguousControlPoints (*this));
613 contiguous_points.push_back (contig);
615 contig->push_back (*i);
616 expected_view_index = (*i)->view_index() + 1;
619 if (contiguous_points.back()->empty()) {
620 contiguous_points.pop_back ();
623 for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
624 (*ccp)->compute_x_bounds ();
628 /* OK, now on to the stuff related to *this* motion event. First, for
629 * each contiguous range, figure out the maximum x-axis motion we are
630 * allowed (because of neighbouring points that are not moving.
632 * if we are moving forwards with push, we don't need to do this,
633 * since all later points will move too.
636 if (dx < 0 || ((dx > 0) && !with_push)) {
637 for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
638 double dxt = (*ccp)->clamp_dx (dx);
639 if (fabs (dxt) < fabs (dx)) {
647 for (list<ControlPoint*>::iterator i = _drag_points.begin(); i != _drag_points.end(); ++i) {
648 double const y = ((_height - (*i)->get_y()) / _height) + dy;
659 /* and now move each section */
661 for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
662 (*ccp)->move (dx, dy);
665 final_index = contiguous_points.back()->back()->view_index () + 1;
667 uint32_t i = final_index;
668 while ((p = nth (i)) != 0 && p->can_slide()) {
669 p->move_to (p->get_x() + dx, p->get_y(), ControlPoint::Full);
670 reset_line_coords (*p);
675 /* update actual line coordinates (will queue a redraw)
678 line->property_points() = line_points;
681 _drag_distance += dx;
683 _last_drag_fraction = fraction;
684 _drag_had_movement = true;
685 did_push = with_push;
687 return pair<double, float> (_drag_x + dx, _last_drag_fraction + dy);
690 /** Should be called to indicate the end of a drag */
692 AutomationLine::end_drag (bool with_push, uint32_t final_index)
694 if (!_drag_had_movement) {
699 sync_model_with_view_points (_drag_points);
703 uint32_t i = final_index;
704 while ((p = nth (i)) != 0 && p->can_slide()) {
705 sync_model_with_view_point (*p);
712 update_pending = false;
714 trackview.editor().session()->add_command (
715 new MementoCommand<AutomationList>(memento_command_binder (), 0, &alist->get_state())
718 trackview.editor().session()->set_dirty ();
721 contiguous_points.clear ();
725 AutomationLine::sync_model_with_view_point (ControlPoint& cp)
727 /* find out where the visual control point is.
728 initial results are in canvas units. ask the
729 line to convert them to something relevant.
732 double view_x = cp.get_x();
733 double view_y = 1.0 - (cp.get_y() / _height);
735 /* if xval has not changed, set it directly from the model to avoid rounding errors */
737 if (view_x == trackview.editor().frame_to_unit_unrounded (_time_converter->to ((*cp.model())->when)) - _offset) {
738 view_x = (*cp.model())->when - _offset;
740 view_x = trackview.editor().unit_to_frame (view_x);
741 view_x = _time_converter->from (view_x + _offset);
744 update_pending = true;
746 view_to_model_coord_y (view_y);
748 alist->modify (cp.model(), view_x, view_y);
752 AutomationLine::control_points_adjacent (double xval, uint32_t & before, uint32_t& after)
754 ControlPoint *bcp = 0;
755 ControlPoint *acp = 0;
758 unit_xval = trackview.editor().frame_to_unit_unrounded (xval);
760 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
762 if ((*i)->get_x() <= unit_xval) {
764 if (!bcp || (*i)->get_x() > bcp->get_x()) {
766 before = bcp->view_index();
769 } else if ((*i)->get_x() > unit_xval) {
771 after = acp->view_index();
780 AutomationLine::is_last_point (ControlPoint& cp)
782 // If the list is not empty, and the point is the last point in the list
784 if (alist->empty()) {
788 AutomationList::const_iterator i = alist->end();
791 if (cp.model() == i) {
799 AutomationLine::is_first_point (ControlPoint& cp)
801 // If the list is not empty, and the point is the first point in the list
803 if (!alist->empty() && cp.model() == alist->begin()) {
810 // This is copied into AudioRegionGainLine
812 AutomationLine::remove_point (ControlPoint& cp)
814 trackview.editor().session()->begin_reversible_command (_("remove control point"));
815 XMLNode &before = alist->get_state();
817 alist->erase (cp.model());
819 trackview.editor().session()->add_command(
820 new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state())
823 trackview.editor().session()->commit_reversible_command ();
824 trackview.editor().session()->set_dirty ();
827 /** Get selectable points within an area.
828 * @param start Start position in session frames.
829 * @param end End position in session frames.
830 * @param bot Bottom y range, as a fraction of line height, where 0 is the bottom of the line.
831 * @param top Top y range, as a fraction of line height, where 0 is the bottom of the line.
832 * @param result Filled in with selectable things; in this case, ControlPoints.
835 AutomationLine::get_selectables (framepos_t start, framepos_t end, double botfrac, double topfrac, list<Selectable*>& results)
837 /* convert fractions to display coordinates with 0 at the top of the track */
838 double const bot_track = (1 - topfrac) * trackview.current_height ();
839 double const top_track = (1 - botfrac) * trackview.current_height ();
841 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
842 double const model_when = (*(*i)->model())->when;
844 /* model_when is relative to the start of the source, so we just need to add on the origin_b here
845 (as it is the session frame position of the start of the source)
848 framepos_t const session_frames_when = _time_converter->to (model_when) + _time_converter->origin_b ();
850 if (session_frames_when >= start && session_frames_when <= end && (*i)->get_y() >= bot_track && (*i)->get_y() <= top_track) {
851 results.push_back (*i);
857 AutomationLine::get_inverted_selectables (Selection&, list<Selectable*>& /*results*/)
863 AutomationLine::set_selected_points (PointSelection const & points)
865 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
866 (*i)->set_selected (false);
869 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
870 (*i)->set_selected (true);
876 void AutomationLine::set_colors ()
878 set_line_color (ARDOUR_UI::config()->canvasvar_AutomationLine.get());
879 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
885 AutomationLine::list_changed ()
887 DEBUG_TRACE (DEBUG::Automation, string_compose ("\tline changed, existing update pending? %1\n", update_pending));
889 if (!update_pending) {
890 update_pending = true;
891 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AutomationLine::queue_reset, this));
896 AutomationLine::reset_callback (const Evoral::ControlList& events)
902 if (events.empty()) {
903 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
906 control_points.clear ();
911 /* hide all existing points, and the line */
913 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
920 Evoral::ControlList& e = const_cast<Evoral::ControlList&> (events);
922 for (AutomationList::iterator ai = e.begin(); ai != e.end(); ++ai, ++pi) {
924 double tx = (*ai)->when;
925 double ty = (*ai)->value;
927 /* convert from model coordinates to canonical view coordinates */
929 model_to_view_coord (tx, ty);
931 if (std::isnan (tx) || std::isnan (ty)) {
932 warning << string_compose (_("Ignoring illegal points on AutomationLine \"%1\""),
937 if (tx >= max_framepos || tx < 0 || tx >= _maximum_time) {
941 /* convert x-coordinate to a canvas unit coordinate (this takes
942 * zoom and scroll into account).
945 tx = trackview.editor().frame_to_unit_unrounded (tx);
947 /* convert from canonical view height (0..1.0) to actual
948 * height coordinates (using X11's top-left rooted system)
951 ty = _height - (ty * _height);
953 add_visible_control_point (vp, pi, tx, ty, ai, np);
957 /* discard extra CP's to avoid confusing ourselves */
959 while (control_points.size() > vp) {
960 ControlPoint* cp = control_points.back();
961 control_points.pop_back ();
965 if (!terminal_points_can_slide) {
966 control_points.back()->set_can_slide(false);
971 /* reset the line coordinates given to the CanvasLine */
973 while (line_points.size() < vp) {
974 line_points.push_back (Art::Point (0,0));
977 while (line_points.size() > vp) {
978 line_points.pop_back ();
981 for (uint32_t n = 0; n < vp; ++n) {
982 line_points[n].set_x (control_points[n]->get_x());
983 line_points[n].set_y (control_points[n]->get_y());
986 line->property_points() = line_points;
988 if (_visible && alist->interpolation() != AutomationList::Discrete) {
993 set_selected_points (trackview.editor().get_selection().points);
997 AutomationLine::reset ()
999 DEBUG_TRACE (DEBUG::Automation, "\t\tLINE RESET\n");
1000 update_pending = false;
1001 have_timeout = false;
1007 alist->apply_to_points (*this, &AutomationLine::reset_callback);
1011 AutomationLine::queue_reset ()
1013 /* this must be called from the GUI thread
1016 if (trackview.editor().session()->transport_rolling() && alist->automation_write()) {
1017 /* automation write pass ... defer to a timeout */
1018 /* redraw in 1/4 second */
1019 if (!have_timeout) {
1020 DEBUG_TRACE (DEBUG::Automation, "\tqueue timeout\n");
1021 Glib::signal_timeout().connect (sigc::bind_return (sigc::mem_fun (*this, &AutomationLine::reset), false), 250);
1022 have_timeout = true;
1024 DEBUG_TRACE (DEBUG::Automation, "\ttimeout already queued, change ignored\n");
1032 AutomationLine::clear ()
1034 /* parent must create and commit command */
1035 XMLNode &before = alist->get_state();
1038 trackview.editor().session()->add_command (
1039 new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state())
1044 AutomationLine::change_model (AutomationList::iterator /*i*/, double /*x*/, double /*y*/)
1049 AutomationLine::set_list (boost::shared_ptr<ARDOUR::AutomationList> list)
1057 AutomationLine::add_visibility (VisibleAspects va)
1059 _visible = VisibleAspects (_visible | va);
1064 AutomationLine::set_visibility (VisibleAspects va)
1071 AutomationLine::remove_visibility (VisibleAspects va)
1073 _visible = VisibleAspects (_visible & ~va);
1078 AutomationLine::track_entered()
1080 if (alist->interpolation() != AutomationList::Discrete) {
1081 add_visibility (ControlPoints);
1086 AutomationLine::track_exited()
1088 if (alist->interpolation() != AutomationList::Discrete) {
1089 remove_visibility (ControlPoints);
1094 AutomationLine::get_state (void)
1096 /* function as a proxy for the model */
1097 return alist->get_state();
1101 AutomationLine::set_state (const XMLNode &node, int version)
1103 /* function as a proxy for the model */
1104 return alist->set_state (node, version);
1108 AutomationLine::view_to_model_coord (double& x, double& y) const
1110 x = _time_converter->from (x);
1111 view_to_model_coord_y (y);
1115 AutomationLine::view_to_model_coord_y (double& y) const
1117 /* TODO: This should be more generic ... */
1118 if (alist->parameter().type() == GainAutomation ||
1119 alist->parameter().type() == EnvelopeAutomation) {
1120 y = slider_position_to_gain_with_max (y, Config->get_max_gain());
1123 } else if (alist->parameter().type() == PanAzimuthAutomation ||
1124 alist->parameter().type() == PanElevationAutomation ||
1125 alist->parameter().type() == PanWidthAutomation) {
1127 } else if (alist->parameter().type() == PluginAutomation) {
1128 y = y * (double)(alist->get_max_y()- alist->get_min_y()) + alist->get_min_y();
1130 y = rint (y * alist->parameter().max());
1135 AutomationLine::model_to_view_coord (double& x, double& y) const
1137 /* TODO: This should be more generic ... */
1138 if (alist->parameter().type() == GainAutomation ||
1139 alist->parameter().type() == EnvelopeAutomation) {
1140 y = gain_to_slider_position_with_max (y, Config->get_max_gain());
1141 } else if (alist->parameter().type() == PanAzimuthAutomation ||
1142 alist->parameter().type() == PanElevationAutomation ||
1143 alist->parameter().type() == PanWidthAutomation) {
1144 // vertical coordinate axis reversal
1146 } else if (alist->parameter().type() == PluginAutomation) {
1147 y = (y - alist->get_min_y()) / (double)(alist->get_max_y()- alist->get_min_y());
1149 y = y / (double)alist->parameter().max(); /* ... like this */
1152 x = _time_converter->to (x) - _offset;
1155 /** Called when our list has announced that its interpolation style has changed */
1157 AutomationLine::interpolation_changed (AutomationList::InterpolationStyle style)
1159 if (style == AutomationList::Discrete) {
1160 set_visibility (ControlPoints);
1163 set_visibility (Line);
1168 AutomationLine::add_visible_control_point (uint32_t view_index, uint32_t pi, double tx, double ty,
1169 AutomationList::iterator model, uint32_t npoints)
1171 ControlPoint::ShapeType shape;
1173 if (view_index >= control_points.size()) {
1175 /* make sure we have enough control points */
1177 ControlPoint* ncp = new ControlPoint (*this);
1178 ncp->set_size (control_point_box_size ());
1180 control_points.push_back (ncp);
1183 if (!terminal_points_can_slide) {
1185 control_points[view_index]->set_can_slide (false);
1187 shape = ControlPoint::Start;
1189 shape = ControlPoint::Full;
1191 } else if (pi == npoints - 1) {
1192 control_points[view_index]->set_can_slide (false);
1193 shape = ControlPoint::End;
1195 control_points[view_index]->set_can_slide (true);
1196 shape = ControlPoint::Full;
1199 control_points[view_index]->set_can_slide (true);
1200 shape = ControlPoint::Full;
1203 control_points[view_index]->reset (tx, ty, model, view_index, shape);
1205 /* finally, control visibility */
1207 if (_visible & ControlPoints) {
1208 control_points[view_index]->show ();
1209 control_points[view_index]->set_visible (true);
1211 control_points[view_index]->set_visible (false);
1216 AutomationLine::connect_to_list ()
1218 _list_connections.drop_connections ();
1220 alist->StateChanged.connect (_list_connections, invalidator (*this), boost::bind (&AutomationLine::list_changed, this), gui_context());
1222 alist->InterpolationChanged.connect (
1223 _list_connections, invalidator (*this), boost::bind (&AutomationLine::interpolation_changed, this, _1), gui_context()
1227 MementoCommandBinder<AutomationList>*
1228 AutomationLine::memento_command_binder ()
1230 return new SimpleMementoCommandBinder<AutomationList> (*alist.get());
1233 /** Set the maximum time that points on this line can be at, relative
1234 * to the start of the track or region that it is on.
1237 AutomationLine::set_maximum_time (framecnt_t t)
1239 if (_maximum_time == t) {
1248 /** @return min and max x positions of points that are in the list, in session frames */
1249 pair<framepos_t, framepos_t>
1250 AutomationLine::get_point_x_range () const
1252 pair<framepos_t, framepos_t> r (max_framepos, 0);
1254 for (AutomationList::const_iterator i = the_list()->begin(); i != the_list()->end(); ++i) {
1255 r.first = min (r.first, session_position (i));
1256 r.second = max (r.second, session_position (i));
1263 AutomationLine::session_position (AutomationList::const_iterator p) const
1265 return _time_converter->to ((*p)->when) + _offset + _time_converter->origin_b ();
1269 AutomationLine::set_offset (framepos_t off)
1271 if (_offset == off) {