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"
43 #include "evoral/Curve.hpp"
45 #include "canvas/debug.h"
47 #include "automation_line.h"
48 #include "control_point.h"
49 #include "gui_thread.h"
50 #include "rgb_macros.h"
51 #include "ardour_ui.h"
52 #include "public_editor.h"
54 #include "selection.h"
55 #include "time_axis_view.h"
56 #include "point_selection.h"
57 #include "automation_time_axis.h"
59 #include "ardour/event_type_map.h"
60 #include "ardour/session.h"
65 using namespace ARDOUR;
67 using namespace Editing;
69 /** @param converter A TimeConverter whose origin_b is the start time of the AutomationList in session frames.
70 * This will not be deleted by AutomationLine.
72 AutomationLine::AutomationLine (const string& name, TimeAxisView& tv, ArdourCanvas::Group& parent,
73 boost::shared_ptr<AutomationList> al,
74 Evoral::TimeConverter<double, framepos_t>* converter)
78 , _time_converter (converter ? converter : new Evoral::IdentityConverter<double, framepos_t>)
79 , _parent_group (parent)
81 , _maximum_time (max_framepos)
84 _time_converter = converter;
85 _our_time_converter = false;
87 _time_converter = new Evoral::IdentityConverter<double, framepos_t>;
88 _our_time_converter = true;
93 update_pending = false;
95 _uses_gain_mapping = false;
98 terminal_points_can_slide = true;
101 group = new ArdourCanvas::Group (&parent);
102 CANVAS_DEBUG_NAME (group, "region gain envelope group");
104 line = new ArdourCanvas::PolyLine (group);
105 CANVAS_DEBUG_NAME (line, "region gain envelope line");
106 line->set_data ("line", this);
107 line->set_outline_width (2.0);
108 line->set_covers_threshold (4.0);
110 line->Event.connect (sigc::mem_fun (*this, &AutomationLine::event_handler));
112 trackview.session()->register_with_memento_command_factory(alist->id(), this);
114 if (alist->parameter().type() == GainAutomation ||
115 alist->parameter().type() == EnvelopeAutomation) {
116 set_uses_gain_mapping (true);
119 interpolation_changed (alist->interpolation ());
124 AutomationLine::~AutomationLine ()
126 vector_delete (&control_points);
129 if (_our_time_converter) {
130 delete _time_converter;
135 AutomationLine::event_handler (GdkEvent* event)
137 return PublicEditor::instance().canvas_line_event (event, line, this);
141 AutomationLine::update_visibility ()
143 if (_visible & Line) {
144 /* Only show the line there are some points, otherwise we may show an out-of-date line
145 when automation points have been removed (the line will still follow the shape of the
148 if (alist->interpolation() != AutomationList::Discrete && control_points.size() >= 2) {
154 if (_visible & ControlPoints) {
155 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
158 } else if (_visible & SelectedControlPoints) {
159 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
160 if ((*i)->get_selected()) {
167 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
174 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
182 AutomationLine::hide ()
184 /* leave control points setting unchanged, we are just hiding the
188 set_visibility (AutomationLine::VisibleAspects (_visible & ~Line));
192 AutomationLine::control_point_box_size ()
194 if (alist->interpolation() == AutomationList::Discrete) {
195 return max((_height*4.0) / (double)(alist->parameter().max() - alist->parameter().min()),
199 if (_height > TimeAxisView::preset_height (HeightLarger)) {
201 } else if (_height > (guint32) TimeAxisView::preset_height (HeightNormal)) {
208 AutomationLine::set_height (guint32 h)
213 double bsz = control_point_box_size();
215 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
216 (*i)->set_size (bsz);
224 AutomationLine::set_line_color (uint32_t color)
227 line->set_outline_color (color);
231 AutomationLine::set_uses_gain_mapping (bool yn)
233 if (yn != _uses_gain_mapping) {
234 _uses_gain_mapping = yn;
240 AutomationLine::nth (uint32_t n)
242 if (n < control_points.size()) {
243 return control_points[n];
250 AutomationLine::nth (uint32_t n) const
252 if (n < control_points.size()) {
253 return control_points[n];
260 AutomationLine::modify_point_y (ControlPoint& cp, double y)
262 /* clamp y-coord appropriately. y is supposed to be a normalized fraction (0.0-1.0),
263 and needs to be converted to a canvas unit distance.
268 y = _height - (y * _height);
270 double const x = trackview.editor().sample_to_pixel_unrounded (_time_converter->to((*cp.model())->when) - _offset);
272 trackview.editor().session()->begin_reversible_command (_("automation event move"));
273 trackview.editor().session()->add_command (
274 new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0));
276 cp.move_to (x, y, ControlPoint::Full);
278 reset_line_coords (cp);
280 if (line_points.size() > 1) {
281 line->set (line_points);
285 sync_model_with_view_point (cp);
288 update_pending = false;
290 trackview.editor().session()->add_command (
291 new MementoCommand<AutomationList> (memento_command_binder(), 0, &alist->get_state()));
293 trackview.editor().session()->commit_reversible_command ();
294 trackview.editor().session()->set_dirty ();
298 AutomationLine::reset_line_coords (ControlPoint& cp)
300 if (cp.view_index() < line_points.size()) {
301 line_points[cp.view_index()].x = cp.get_x ();
302 line_points[cp.view_index()].y = cp.get_y ();
307 AutomationLine::sync_model_with_view_points (list<ControlPoint*> cp)
309 update_pending = true;
311 for (list<ControlPoint*>::iterator i = cp.begin(); i != cp.end(); ++i) {
312 sync_model_with_view_point (**i);
317 AutomationLine::get_verbose_cursor_string (double fraction) const
319 std::string s = fraction_to_string (fraction);
320 if (_uses_gain_mapping) {
328 AutomationLine::get_verbose_cursor_relative_string (double original, double fraction) const
330 std::string s = fraction_to_string (fraction);
331 if (_uses_gain_mapping) {
335 std::string d = fraction_to_relative_string (original, fraction);
342 if (_uses_gain_mapping) {
353 * @param fraction y fraction
354 * @return string representation of this value, using dB if appropriate.
357 AutomationLine::fraction_to_string (double fraction) const
361 if (_uses_gain_mapping) {
362 if (fraction == 0.0) {
363 snprintf (buf, sizeof (buf), "-inf");
365 snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain_with_max (fraction, Config->get_max_gain())));
368 view_to_model_coord_y (fraction);
369 if (EventTypeMap::instance().is_integer (alist->parameter())) {
370 snprintf (buf, sizeof (buf), "%d", (int)fraction);
372 snprintf (buf, sizeof (buf), "%.2f", fraction);
380 * @param original an old y-axis fraction
381 * @param fraction the new y fraction
382 * @return string representation of the difference between original and fraction, using dB if appropriate.
385 AutomationLine::fraction_to_relative_string (double original, double fraction) const
389 if (original == fraction) {
393 if (_uses_gain_mapping) {
394 if (original == 0.0) {
395 /* there is no sensible representation of a relative
396 change from -inf dB, so return an empty string.
399 } else if (fraction == 0.0) {
400 snprintf (buf, sizeof (buf), "-inf");
402 double old_db = accurate_coefficient_to_dB (slider_position_to_gain_with_max (original, Config->get_max_gain()));
403 double new_db = accurate_coefficient_to_dB (slider_position_to_gain_with_max (fraction, Config->get_max_gain()));
404 snprintf (buf, sizeof (buf), "%.1f", new_db - old_db);
407 view_to_model_coord_y (original);
408 view_to_model_coord_y (fraction);
409 if (EventTypeMap::instance().is_integer (alist->parameter())) {
410 snprintf (buf, sizeof (buf), "%d", (int)fraction - (int)original);
412 snprintf (buf, sizeof (buf), "%.2f", fraction - original);
420 * @param s Value string in the form as returned by fraction_to_string.
421 * @return Corresponding y fraction.
424 AutomationLine::string_to_fraction (string const & s) const
431 sscanf (s.c_str(), "%lf", &v);
433 if (_uses_gain_mapping) {
434 v = gain_to_slider_position_with_max (dB_to_coefficient (v), Config->get_max_gain());
437 model_to_view_coord (dummy, v);
443 /** Start dragging a single point, possibly adding others if the supplied point is selected and there
444 * are other selected points.
446 * @param cp Point to drag.
447 * @param x Initial x position (units).
448 * @param fraction Initial y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
451 AutomationLine::start_drag_single (ControlPoint* cp, double x, float fraction)
453 trackview.editor().session()->begin_reversible_command (_("automation event move"));
454 trackview.editor().session()->add_command (
455 new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0));
457 _drag_points.clear ();
458 _drag_points.push_back (cp);
460 if (cp->get_selected ()) {
461 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
462 if (*i != cp && (*i)->get_selected()) {
463 _drag_points.push_back (*i);
468 start_drag_common (x, fraction);
471 /** Start dragging a line vertically (with no change in x)
472 * @param i1 Control point index of the `left' point on the line.
473 * @param i2 Control point index of the `right' point on the line.
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_line (uint32_t i1, uint32_t i2, float fraction)
479 trackview.editor().session()->begin_reversible_command (_("automation range move"));
480 trackview.editor().session()->add_command (
481 new MementoCommand<AutomationList> (memento_command_binder (), &get_state(), 0));
483 _drag_points.clear ();
485 for (uint32_t i = i1; i <= i2; i++) {
486 _drag_points.push_back (nth (i));
489 start_drag_common (0, fraction);
492 /** Start dragging multiple points (with no change in x)
493 * @param cp Points to drag.
494 * @param fraction Initial y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
497 AutomationLine::start_drag_multiple (list<ControlPoint*> cp, float fraction, XMLNode* state)
499 trackview.editor().session()->begin_reversible_command (_("automation range move"));
500 trackview.editor().session()->add_command (
501 new MementoCommand<AutomationList> (memento_command_binder(), state, 0));
504 start_drag_common (0, fraction);
507 struct ControlPointSorter
509 bool operator() (ControlPoint const * a, ControlPoint const * b) const {
510 if (floateq (a->get_x(), b->get_x(), 1)) {
511 return a->view_index() < b->view_index();
513 return a->get_x() < b->get_x();
517 AutomationLine::ContiguousControlPoints::ContiguousControlPoints (AutomationLine& al)
518 : line (al), before_x (0), after_x (DBL_MAX)
523 AutomationLine::ContiguousControlPoints::compute_x_bounds ()
525 uint32_t sz = size();
527 if (sz > 0 && sz < line.npoints()) {
529 /* determine the limits on x-axis motion for this
530 contiguous range of control points
533 if (front()->view_index() > 0) {
534 before_x = line.nth (front()->view_index() - 1)->get_x();
537 /* if our last point has a point after it in the line,
538 we have an "after" bound
541 if (back()->view_index() < (line.npoints() - 2)) {
542 after_x = line.nth (back()->view_index() + 1)->get_x();
548 AutomationLine::ContiguousControlPoints::clamp_dx (double dx)
554 /* get the maximum distance we can move any of these points along the x-axis
557 double tx; /* possible position a point would move to, given dx */
561 /* check the last point, since we're moving later in time */
564 /* check the first point, since we're moving earlier in time */
568 tx = cp->get_x() + dx; // new possible position if we just add the motion
569 tx = max (tx, before_x); // can't move later than following point
570 tx = min (tx, after_x); // can't move earlier than preceeding point
571 return tx - cp->get_x ();
575 AutomationLine::ContiguousControlPoints::move (double dx, double dy)
577 for (std::list<ControlPoint*>::iterator i = begin(); i != end(); ++i) {
578 (*i)->move_to ((*i)->get_x() + dx, (*i)->get_y() - line.height() * dy, ControlPoint::Full);
579 line.reset_line_coords (**i);
583 /** Common parts of starting a drag.
584 * @param x Starting x position in units, or 0 if x is being ignored.
585 * @param fraction Starting y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
588 AutomationLine::start_drag_common (double x, float fraction)
592 _last_drag_fraction = fraction;
593 _drag_had_movement = false;
596 /* they are probably ordered already, but we have to make sure */
598 _drag_points.sort (ControlPointSorter());
602 /** Should be called to indicate motion during a drag.
603 * @param x New x position of the drag in canvas units, or undefined if ignore_x == true.
604 * @param fraction New y fraction.
605 * @return x position and y fraction that were actually used (once clamped).
608 AutomationLine::drag_motion (double const x, float fraction, bool ignore_x, bool with_push, uint32_t& final_index)
610 if (_drag_points.empty()) {
611 return pair<double,float> (x,fraction);
614 double dx = ignore_x ? 0 : (x - _drag_x);
615 double dy = fraction - _last_drag_fraction;
617 if (!_drag_had_movement) {
619 /* "first move" ... do some stuff that we don't want to do if
620 no motion ever took place, but need to do before we handle
624 /* partition the points we are dragging into (potentially several)
625 * set(s) of contiguous points. this will not happen with a normal
626 * drag, but if the user does a discontiguous selection, it can.
629 uint32_t expected_view_index = 0;
632 for (list<ControlPoint*>::iterator i = _drag_points.begin(); i != _drag_points.end(); ++i) {
633 if (i == _drag_points.begin() || (*i)->view_index() != expected_view_index) {
634 contig.reset (new ContiguousControlPoints (*this));
635 contiguous_points.push_back (contig);
637 contig->push_back (*i);
638 expected_view_index = (*i)->view_index() + 1;
641 if (contiguous_points.back()->empty()) {
642 contiguous_points.pop_back ();
645 for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
646 (*ccp)->compute_x_bounds ();
650 /* OK, now on to the stuff related to *this* motion event. First, for
651 * each contiguous range, figure out the maximum x-axis motion we are
652 * allowed (because of neighbouring points that are not moving.
654 * if we are moving forwards with push, we don't need to do this,
655 * since all later points will move too.
658 if (dx < 0 || ((dx > 0) && !with_push)) {
659 for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
660 double dxt = (*ccp)->clamp_dx (dx);
661 if (fabs (dxt) < fabs (dx)) {
669 for (list<ControlPoint*>::iterator i = _drag_points.begin(); i != _drag_points.end(); ++i) {
670 double const y = ((_height - (*i)->get_y()) / _height) + dy;
681 /* and now move each section */
683 for (vector<CCP>::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) {
684 (*ccp)->move (dx, dy);
687 final_index = contiguous_points.back()->back()->view_index () + 1;
689 uint32_t i = final_index;
690 while ((p = nth (i)) != 0 && p->can_slide()) {
691 p->move_to (p->get_x() + dx, p->get_y(), ControlPoint::Full);
692 reset_line_coords (*p);
697 /* update actual line coordinates (will queue a redraw)
700 if (line_points.size() > 1) {
701 line->set (line_points);
705 _drag_distance += dx;
707 _last_drag_fraction = fraction;
708 _drag_had_movement = true;
709 did_push = with_push;
711 return pair<double, float> (_drag_x + dx, _last_drag_fraction + dy);
714 /** Should be called to indicate the end of a drag */
716 AutomationLine::end_drag (bool with_push, uint32_t final_index)
718 if (!_drag_had_movement) {
723 sync_model_with_view_points (_drag_points);
727 uint32_t i = final_index;
728 while ((p = nth (i)) != 0 && p->can_slide()) {
729 sync_model_with_view_point (*p);
736 update_pending = false;
738 trackview.editor().session()->add_command (
739 new MementoCommand<AutomationList>(memento_command_binder (), 0, &alist->get_state()));
741 trackview.editor().session()->set_dirty ();
744 contiguous_points.clear ();
748 AutomationLine::sync_model_with_view_point (ControlPoint& cp)
750 /* find out where the visual control point is.
751 initial results are in canvas units. ask the
752 line to convert them to something relevant.
755 double view_x = cp.get_x();
756 double view_y = 1.0 - (cp.get_y() / _height);
758 /* if xval has not changed, set it directly from the model to avoid rounding errors */
760 if (view_x == trackview.editor().sample_to_pixel_unrounded (_time_converter->to ((*cp.model())->when)) - _offset) {
761 view_x = (*cp.model())->when - _offset;
763 view_x = trackview.editor().pixel_to_sample (view_x);
764 view_x = _time_converter->from (view_x + _offset);
767 update_pending = true;
769 view_to_model_coord_y (view_y);
771 alist->modify (cp.model(), view_x, view_y);
775 AutomationLine::control_points_adjacent (double xval, uint32_t & before, uint32_t& after)
777 ControlPoint *bcp = 0;
778 ControlPoint *acp = 0;
781 unit_xval = trackview.editor().sample_to_pixel_unrounded (xval);
783 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
785 if ((*i)->get_x() <= unit_xval) {
787 if (!bcp || (*i)->get_x() > bcp->get_x()) {
789 before = bcp->view_index();
792 } else if ((*i)->get_x() > unit_xval) {
794 after = acp->view_index();
803 AutomationLine::is_last_point (ControlPoint& cp)
805 // If the list is not empty, and the point is the last point in the list
807 if (alist->empty()) {
811 AutomationList::const_iterator i = alist->end();
814 if (cp.model() == i) {
822 AutomationLine::is_first_point (ControlPoint& cp)
824 // If the list is not empty, and the point is the first point in the list
826 if (!alist->empty() && cp.model() == alist->begin()) {
833 // This is copied into AudioRegionGainLine
835 AutomationLine::remove_point (ControlPoint& cp)
837 trackview.editor().session()->begin_reversible_command (_("remove control point"));
838 XMLNode &before = alist->get_state();
840 alist->erase (cp.model());
842 trackview.editor().session()->add_command(
843 new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state()));
845 trackview.editor().session()->commit_reversible_command ();
846 trackview.editor().session()->set_dirty ();
849 /** Get selectable points within an area.
850 * @param start Start position in session frames.
851 * @param end End position in session frames.
852 * @param bot Bottom y range, as a fraction of line height, where 0 is the bottom of the line.
853 * @param top Top y range, as a fraction of line height, where 0 is the bottom of the line.
854 * @param result Filled in with selectable things; in this case, ControlPoints.
857 AutomationLine::get_selectables (framepos_t start, framepos_t end, double botfrac, double topfrac, list<Selectable*>& results)
859 /* convert fractions to display coordinates with 0 at the top of the track */
860 double const bot_track = (1 - topfrac) * trackview.current_height ();
861 double const top_track = (1 - botfrac) * trackview.current_height ();
863 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
864 double const model_when = (*(*i)->model())->when;
866 /* model_when is relative to the start of the source, so we just need to add on the origin_b here
867 (as it is the session frame position of the start of the source)
870 framepos_t const session_frames_when = _time_converter->to (model_when) + _time_converter->origin_b ();
872 if (session_frames_when >= start && session_frames_when <= end && (*i)->get_y() >= bot_track && (*i)->get_y() <= top_track) {
873 results.push_back (*i);
879 AutomationLine::get_inverted_selectables (Selection&, list<Selectable*>& /*results*/)
885 AutomationLine::set_selected_points (PointSelection const & points)
887 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
888 (*i)->set_selected (false);
891 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
892 (*i)->set_selected (true);
898 void AutomationLine::set_colors ()
900 set_line_color (ARDOUR_UI::config()->get_canvasvar_AutomationLine());
901 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
907 AutomationLine::list_changed ()
909 DEBUG_TRACE (DEBUG::Automation, string_compose ("\tline changed, existing update pending? %1\n", update_pending));
911 if (!update_pending) {
912 update_pending = true;
913 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AutomationLine::queue_reset, this));
918 AutomationLine::reset_callback (const Evoral::ControlList& events)
924 if (events.empty()) {
925 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
928 control_points.clear ();
933 /* hide all existing points, and the line */
935 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
942 Evoral::ControlList& e = const_cast<Evoral::ControlList&> (events);
944 for (AutomationList::iterator ai = e.begin(); ai != e.end(); ++ai, ++pi) {
946 double tx = (*ai)->when;
947 double ty = (*ai)->value;
949 /* convert from model coordinates to canonical view coordinates */
951 model_to_view_coord (tx, ty);
953 if (isnan (tx) || isnan (ty)) {
954 warning << string_compose (_("Ignoring illegal points on AutomationLine \"%1\""),
959 if (tx >= max_framepos || tx < 0 || tx >= _maximum_time) {
963 /* convert x-coordinate to a canvas unit coordinate (this takes
964 * zoom and scroll into account).
967 tx = trackview.editor().sample_to_pixel_unrounded (tx);
969 /* convert from canonical view height (0..1.0) to actual
970 * height coordinates (using X11's top-left rooted system)
973 ty = _height - (ty * _height);
975 add_visible_control_point (vp, pi, tx, ty, ai, np);
979 /* discard extra CP's to avoid confusing ourselves */
981 while (control_points.size() > vp) {
982 ControlPoint* cp = control_points.back();
983 control_points.pop_back ();
987 if (!terminal_points_can_slide) {
988 control_points.back()->set_can_slide(false);
993 /* reset the line coordinates given to the CanvasLine */
995 while (line_points.size() < vp) {
996 line_points.push_back (ArdourCanvas::Duple (0,0));
999 while (line_points.size() > vp) {
1000 line_points.pop_back ();
1003 for (uint32_t n = 0; n < vp; ++n) {
1004 line_points[n].x = control_points[n]->get_x();
1005 line_points[n].y = control_points[n]->get_y();
1008 line->set (line_points);
1010 update_visibility ();
1013 set_selected_points (trackview.editor().get_selection().points);
1017 AutomationLine::reset ()
1019 DEBUG_TRACE (DEBUG::Automation, "\t\tLINE RESET\n");
1020 update_pending = false;
1021 have_timeout = false;
1027 alist->apply_to_points (*this, &AutomationLine::reset_callback);
1031 AutomationLine::queue_reset ()
1033 /* this must be called from the GUI thread
1036 if (trackview.editor().session()->transport_rolling() && alist->automation_write()) {
1037 /* automation write pass ... defer to a timeout */
1038 /* redraw in 1/4 second */
1039 if (!have_timeout) {
1040 DEBUG_TRACE (DEBUG::Automation, "\tqueue timeout\n");
1041 Glib::signal_timeout().connect (sigc::bind_return (sigc::mem_fun (*this, &AutomationLine::reset), false), 250);
1042 have_timeout = true;
1044 DEBUG_TRACE (DEBUG::Automation, "\ttimeout already queued, change ignored\n");
1052 AutomationLine::clear ()
1054 /* parent must create and commit command */
1055 XMLNode &before = alist->get_state();
1058 trackview.editor().session()->add_command (
1059 new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state()));
1063 AutomationLine::change_model (AutomationList::iterator /*i*/, double /*x*/, double /*y*/)
1068 AutomationLine::set_list (boost::shared_ptr<ARDOUR::AutomationList> list)
1076 AutomationLine::add_visibility (VisibleAspects va)
1078 VisibleAspects old = _visible;
1080 _visible = VisibleAspects (_visible | va);
1082 if (old != _visible) {
1083 update_visibility ();
1088 AutomationLine::set_visibility (VisibleAspects va)
1090 if (_visible != va) {
1092 update_visibility ();
1097 AutomationLine::remove_visibility (VisibleAspects va)
1099 VisibleAspects old = _visible;
1101 _visible = VisibleAspects (_visible & ~va);
1103 if (old != _visible) {
1104 update_visibility ();
1109 AutomationLine::track_entered()
1111 if (alist->interpolation() != AutomationList::Discrete) {
1112 add_visibility (ControlPoints);
1117 AutomationLine::track_exited()
1119 if (alist->interpolation() != AutomationList::Discrete) {
1120 remove_visibility (ControlPoints);
1125 AutomationLine::get_state (void)
1127 /* function as a proxy for the model */
1128 return alist->get_state();
1132 AutomationLine::set_state (const XMLNode &node, int version)
1134 /* function as a proxy for the model */
1135 return alist->set_state (node, version);
1139 AutomationLine::view_to_model_coord (double& x, double& y) const
1141 x = _time_converter->from (x);
1142 view_to_model_coord_y (y);
1146 AutomationLine::view_to_model_coord_y (double& y) const
1148 /* TODO: This should be more generic ... */
1149 if (alist->parameter().type() == GainAutomation ||
1150 alist->parameter().type() == EnvelopeAutomation) {
1151 y = slider_position_to_gain_with_max (y, Config->get_max_gain());
1154 } else if (alist->parameter().type() == PanAzimuthAutomation ||
1155 alist->parameter().type() == PanElevationAutomation) {
1157 } else if (alist->parameter().type() == PanWidthAutomation) {
1159 } else if (alist->parameter().type() == PluginAutomation) {
1160 y = y * (double)(alist->get_max_y()- alist->get_min_y()) + alist->get_min_y();
1162 y = rint (y * alist->parameter().max());
1167 AutomationLine::model_to_view_coord (double& x, double& y) const
1169 /* TODO: This should be more generic ... */
1170 if (alist->parameter().type() == GainAutomation ||
1171 alist->parameter().type() == EnvelopeAutomation) {
1172 y = gain_to_slider_position_with_max (y, Config->get_max_gain());
1173 } else if (alist->parameter().type() == PanAzimuthAutomation ||
1174 alist->parameter().type() == PanElevationAutomation) {
1176 } else if (alist->parameter().type() == PanWidthAutomation) {
1178 } else if (alist->parameter().type() == PluginAutomation) {
1179 y = (y - alist->get_min_y()) / (double)(alist->get_max_y()- alist->get_min_y());
1181 y = y / (double)alist->parameter().max(); /* ... like this */
1184 x = _time_converter->to (x) - _offset;
1187 /** Called when our list has announced that its interpolation style has changed */
1189 AutomationLine::interpolation_changed (AutomationList::InterpolationStyle style)
1191 if (style == AutomationList::Discrete) {
1192 set_visibility (ControlPoints);
1195 set_visibility (Line);
1200 AutomationLine::add_visible_control_point (uint32_t view_index, uint32_t pi, double tx, double ty,
1201 AutomationList::iterator model, uint32_t npoints)
1203 ControlPoint::ShapeType shape;
1205 if (view_index >= control_points.size()) {
1207 /* make sure we have enough control points */
1209 ControlPoint* ncp = new ControlPoint (*this);
1210 ncp->set_size (control_point_box_size ());
1212 control_points.push_back (ncp);
1215 if (!terminal_points_can_slide) {
1217 control_points[view_index]->set_can_slide (false);
1219 shape = ControlPoint::Start;
1221 shape = ControlPoint::Full;
1223 } else if (pi == npoints - 1) {
1224 control_points[view_index]->set_can_slide (false);
1225 shape = ControlPoint::End;
1227 control_points[view_index]->set_can_slide (true);
1228 shape = ControlPoint::Full;
1231 control_points[view_index]->set_can_slide (true);
1232 shape = ControlPoint::Full;
1235 control_points[view_index]->reset (tx, ty, model, view_index, shape);
1237 /* finally, control visibility */
1239 if (_visible & ControlPoints) {
1240 control_points[view_index]->show ();
1242 control_points[view_index]->hide ();
1247 AutomationLine::connect_to_list ()
1249 _list_connections.drop_connections ();
1251 alist->StateChanged.connect (_list_connections, invalidator (*this), boost::bind (&AutomationLine::list_changed, this), gui_context());
1253 alist->InterpolationChanged.connect (
1254 _list_connections, invalidator (*this), boost::bind (&AutomationLine::interpolation_changed, this, _1), gui_context());
1257 MementoCommandBinder<AutomationList>*
1258 AutomationLine::memento_command_binder ()
1260 return new SimpleMementoCommandBinder<AutomationList> (*alist.get());
1263 /** Set the maximum time that points on this line can be at, relative
1264 * to the start of the track or region that it is on.
1267 AutomationLine::set_maximum_time (framecnt_t t)
1269 if (_maximum_time == t) {
1278 /** @return min and max x positions of points that are in the list, in session frames */
1279 pair<framepos_t, framepos_t>
1280 AutomationLine::get_point_x_range () const
1282 pair<framepos_t, framepos_t> r (max_framepos, 0);
1284 for (AutomationList::const_iterator i = the_list()->begin(); i != the_list()->end(); ++i) {
1285 r.first = min (r.first, session_position (i));
1286 r.second = max (r.second, session_position (i));
1293 AutomationLine::session_position (AutomationList::const_iterator p) const
1295 return _time_converter->to ((*p)->when) + _offset + _time_converter->origin_b ();
1299 AutomationLine::set_offset (framepos_t off)
1301 if (_offset == off) {