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 "pbd/stl_delete.h"
26 #include "pbd/memento_command.h"
27 #include "pbd/stacktrace.h"
29 #include "ardour/automation_list.h"
30 #include "ardour/dB.h"
31 #include "evoral/Curve.hpp"
33 #include "simplerect.h"
34 #include "automation_line.h"
35 #include "control_point.h"
36 #include "gui_thread.h"
37 #include "rgb_macros.h"
38 #include "ardour_ui.h"
39 #include "public_editor.h"
41 #include "selection.h"
42 #include "time_axis_view.h"
43 #include "point_selection.h"
44 #include "automation_time_axis.h"
46 #include "ardour/event_type_map.h"
47 #include "ardour/session.h"
52 using namespace ARDOUR;
54 using namespace Editing;
55 using namespace Gnome; // for Canvas
57 /** @param converter A TimeConverter whose origin_b is the start time of the AutomationList in session frames.
58 * This will not be deleted by AutomationLine.
60 AutomationLine::AutomationLine (const string& name, TimeAxisView& tv, ArdourCanvas::Group& parent,
61 boost::shared_ptr<AutomationList> al,
62 Evoral::TimeConverter<double, framepos_t>* converter)
66 , _time_converter (converter ? converter : new Evoral::IdentityConverter<double, framepos_t>)
67 , _parent_group (parent)
69 , _maximum_time (max_framepos)
72 _time_converter = converter;
73 _our_time_converter = false;
75 _time_converter = new Evoral::IdentityConverter<double, framepos_t>;
76 _our_time_converter = true;
81 update_pending = false;
82 _uses_gain_mapping = false;
85 terminal_points_can_slide = true;
88 group = new ArdourCanvas::Group (parent);
89 group->property_x() = 0.0;
90 group->property_y() = 0.0;
92 line = new ArdourCanvas::Line (*group);
93 line->property_width_pixels() = (guint)1;
94 line->set_data ("line", this);
96 line->signal_event().connect (sigc::mem_fun (*this, &AutomationLine::event_handler));
98 trackview.session()->register_with_memento_command_factory(alist->id(), this);
100 if (alist->parameter().type() == GainAutomation ||
101 alist->parameter().type() == EnvelopeAutomation) {
102 set_uses_gain_mapping (true);
105 interpolation_changed (alist->interpolation ());
110 AutomationLine::~AutomationLine ()
112 vector_delete (&control_points);
115 if (_our_time_converter) {
116 delete _time_converter;
121 AutomationLine::event_handler (GdkEvent* event)
123 return PublicEditor::instance().canvas_line_event (event, line, this);
127 AutomationLine::queue_reset ()
129 if (!update_pending) {
130 update_pending = true;
131 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AutomationLine::reset, this));
136 AutomationLine::show ()
138 if (_visible & Line) {
139 /* Only show the line there are some points, otherwise we may show an out-of-date line
140 when automation points have been removed (the line will still follow the shape of the
143 if (alist->interpolation() != AutomationList::Discrete && control_points.size() >= 2) {
152 if (_visible & ControlPoints) {
153 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
154 (*i)->set_visible (true);
157 } else if (_visible & SelectedControlPoints) {
158 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
159 (*i)->set_visible ((*i)->get_selected());
162 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
163 (*i)->set_visible (false);
169 AutomationLine::hide ()
171 set_visibility (VisibleAspects (0));
175 AutomationLine::control_point_box_size ()
177 if (alist->interpolation() == AutomationList::Discrete) {
178 return max((_height*4.0) / (double)(alist->parameter().max() - alist->parameter().min()),
182 if (_height > TimeAxisView::preset_height (HeightLarger)) {
184 } else if (_height > (guint32) TimeAxisView::preset_height (HeightNormal)) {
191 AutomationLine::set_height (guint32 h)
196 double bsz = control_point_box_size();
198 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
199 (*i)->set_size (bsz);
207 AutomationLine::set_line_color (uint32_t color)
210 line->property_fill_color_rgba() = color;
214 AutomationLine::set_uses_gain_mapping (bool yn)
216 if (yn != _uses_gain_mapping) {
217 _uses_gain_mapping = yn;
223 AutomationLine::nth (uint32_t n)
225 if (n < control_points.size()) {
226 return control_points[n];
233 AutomationLine::nth (uint32_t n) const
235 if (n < control_points.size()) {
236 return control_points[n];
243 AutomationLine::modify_point_y (ControlPoint& cp, double y)
245 /* clamp y-coord appropriately. y is supposed to be a normalized fraction (0.0-1.0),
246 and needs to be converted to a canvas unit distance.
251 y = _height - (y * _height);
253 double const x = trackview.editor().frame_to_unit_unrounded (_time_converter->to((*cp.model())->when) - _offset);
255 trackview.editor().session()->begin_reversible_command (_("automation event move"));
256 trackview.editor().session()->add_command (
257 new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0)
260 cp.move_to (x, y, ControlPoint::Full);
262 reset_line_coords (cp);
264 if (line_points.size() > 1) {
265 line->property_points() = line_points;
269 sync_model_with_view_point (cp);
272 update_pending = false;
274 trackview.editor().session()->add_command (
275 new MementoCommand<AutomationList> (memento_command_binder(), 0, &alist->get_state())
278 trackview.editor().session()->commit_reversible_command ();
279 trackview.editor().session()->set_dirty ();
283 AutomationLine::reset_line_coords (ControlPoint& cp)
285 if (cp.view_index() < line_points.size()) {
286 line_points[cp.view_index()].set_x (cp.get_x());
287 line_points[cp.view_index()].set_y (cp.get_y());
292 AutomationLine::sync_model_with_view_points (list<ControlPoint*> cp)
294 update_pending = true;
296 for (list<ControlPoint*>::iterator i = cp.begin(); i != cp.end(); ++i) {
297 sync_model_with_view_point (**i);
302 AutomationLine::get_verbose_cursor_string (double fraction) const
304 std::string s = fraction_to_string (fraction);
305 if (_uses_gain_mapping) {
313 AutomationLine::get_verbose_cursor_relative_string (double original, double fraction) const
315 std::string s = fraction_to_string (fraction);
316 if (_uses_gain_mapping) {
320 std::string d = fraction_to_relative_string (original, fraction);
327 if (_uses_gain_mapping) {
338 * @param fraction y fraction
339 * @return string representation of this value, using dB if appropriate.
342 AutomationLine::fraction_to_string (double fraction) const
346 if (_uses_gain_mapping) {
347 if (fraction == 0.0) {
348 snprintf (buf, sizeof (buf), "-inf");
350 snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain_with_max (fraction, Config->get_max_gain())));
353 view_to_model_coord_y (fraction);
354 if (EventTypeMap::instance().is_integer (alist->parameter())) {
355 snprintf (buf, sizeof (buf), "%d", (int)fraction);
357 snprintf (buf, sizeof (buf), "%.2f", fraction);
365 * @param original an old y-axis fraction
366 * @param fraction the new y fraction
367 * @return string representation of the difference between original and fraction, using dB if appropriate.
370 AutomationLine::fraction_to_relative_string (double original, double fraction) const
374 if (original == fraction) {
378 if (_uses_gain_mapping) {
379 if (original == 0.0) {
380 /* there is no sensible representation of a relative
381 change from -inf dB, so return an empty string.
384 } else if (fraction == 0.0) {
385 snprintf (buf, sizeof (buf), "-inf");
387 double old_db = accurate_coefficient_to_dB (slider_position_to_gain_with_max (original, Config->get_max_gain()));
388 double new_db = accurate_coefficient_to_dB (slider_position_to_gain_with_max (fraction, Config->get_max_gain()));
389 snprintf (buf, sizeof (buf), "%.1f", new_db - old_db);
392 view_to_model_coord_y (original);
393 view_to_model_coord_y (fraction);
394 if (EventTypeMap::instance().is_integer (alist->parameter())) {
395 snprintf (buf, sizeof (buf), "%d", (int)fraction - (int)original);
397 snprintf (buf, sizeof (buf), "%.2f", fraction - original);
405 * @param s Value string in the form as returned by fraction_to_string.
406 * @return Corresponding y fraction.
409 AutomationLine::string_to_fraction (string const & s) const
416 sscanf (s.c_str(), "%lf", &v);
418 if (_uses_gain_mapping) {
419 v = gain_to_slider_position_with_max (dB_to_coefficient (v), Config->get_max_gain());
422 model_to_view_coord (dummy, v);
428 /** Start dragging a single point, possibly adding others if the supplied point is selected and there
429 * are other selected points.
431 * @param cp Point to drag.
432 * @param x Initial x position (units).
433 * @param fraction Initial y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
436 AutomationLine::start_drag_single (ControlPoint* cp, double x, float fraction)
438 trackview.editor().session()->begin_reversible_command (_("automation event move"));
439 trackview.editor().session()->add_command (
440 new MementoCommand<AutomationList> (memento_command_binder(), &get_state(), 0)
443 _drag_points.clear ();
444 _drag_points.push_back (cp);
446 if (cp->get_selected ()) {
447 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
448 if (*i != cp && (*i)->get_selected()) {
449 _drag_points.push_back (*i);
454 start_drag_common (x, fraction);
457 /** Start dragging a line vertically (with no change in x)
458 * @param i1 Control point index of the `left' point on the line.
459 * @param i2 Control point index of the `right' point on the line.
460 * @param fraction Initial y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
463 AutomationLine::start_drag_line (uint32_t i1, uint32_t i2, float fraction)
465 trackview.editor().session()->begin_reversible_command (_("automation range move"));
466 trackview.editor().session()->add_command (
467 new MementoCommand<AutomationList> (memento_command_binder (), &get_state(), 0)
470 _drag_points.clear ();
471 for (uint32_t i = i1; i <= i2; i++) {
472 _drag_points.push_back (nth (i));
475 start_drag_common (0, fraction);
478 /** Start dragging multiple points (with no change in x)
479 * @param cp Points to drag.
480 * @param fraction Initial y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
483 AutomationLine::start_drag_multiple (list<ControlPoint*> cp, float fraction, XMLNode* state)
485 trackview.editor().session()->begin_reversible_command (_("automation range move"));
486 trackview.editor().session()->add_command (
487 new MementoCommand<AutomationList> (memento_command_binder(), state, 0)
491 start_drag_common (0, fraction);
495 struct ControlPointSorter
497 bool operator() (ControlPoint const * a, ControlPoint const * b) {
498 return a->get_x() < b->get_x();
502 /** Common parts of starting a drag.
503 * @param x Starting x position in units, or 0 if x is being ignored.
504 * @param fraction Starting y position (as a fraction of the track height, where 0 is the bottom and 1 the top)
507 AutomationLine::start_drag_common (double x, float fraction)
511 _last_drag_fraction = fraction;
512 _drag_had_movement = false;
515 _drag_points.sort (ControlPointSorter ());
517 /* find the additional points that will be dragged when the user is holding
521 uint32_t i = _drag_points.back()->view_index () + 1;
523 _push_points.clear ();
524 while ((p = nth (i)) != 0 && p->can_slide()) {
525 _push_points.push_back (p);
530 /** Should be called to indicate motion during a drag.
531 * @param x New x position of the drag in canvas units, or undefined if ignore_x == true.
532 * @param fraction New y fraction.
533 * @return x position and y fraction that were actually used (once clamped).
536 AutomationLine::drag_motion (double const x, float fraction, bool ignore_x, bool with_push)
538 /* setup the points that are to be moved this time round */
539 list<ControlPoint*> points = _drag_points;
541 copy (_push_points.begin(), _push_points.end(), back_inserter (points));
542 points.sort (ControlPointSorter ());
545 double dx = ignore_x ? 0 : (x - _drag_x);
546 double dy = fraction - _last_drag_fraction;
548 for (list<ControlPoint*>::iterator i = points.begin(); i != points.end(); ++i) {
549 /* Find the points that aren't being moved before and after
550 this one on the control_points list
553 ControlPoint* before = 0;
554 ControlPoint* after = 0;
556 ControlPoint* last = 0;
557 for (vector<ControlPoint*>::iterator j = control_points.begin(); j != control_points.end(); ++j) {
563 vector<ControlPoint*>::iterator k = j;
568 /* Now move past any points that are being moved this time */
569 while (find (points.begin(), points.end(), *k) != points.end() && k != control_points.end ()) {
573 if (k != control_points.end()) {
579 if (find (points.begin(), points.end(), *j) == points.end ()) {
580 /* This point isn't being moved, so it's the `last' point we've seen */
585 /* Clamp dx for this point */
586 double const before_x = before ? before->get_x() : 0;
587 double const after_x = after ? after->get_x() : DBL_MAX;
589 double tx = (*i)->get_x() + dx;
590 tx = max (tx, before_x);
591 tx = min (tx, after_x);
592 dx = tx - (*i)->get_x ();
596 for (list<ControlPoint*>::iterator i = points.begin(); i != points.end(); ++i) {
597 double const y = ((_height - (*i)->get_y()) / _height) + dy;
606 pair<double, float> const clamped (_drag_x + dx, _last_drag_fraction + dy);
607 _drag_distance += dx;
609 _last_drag_fraction = fraction;
611 for (list<ControlPoint*>::iterator i = _drag_points.begin(); i != _drag_points.end(); ++i) {
612 (*i)->move_to ((*i)->get_x() + dx, (*i)->get_y() - _height * dy, ControlPoint::Full);
613 reset_line_coords (**i);
617 /* move push points, preserving their y */
618 for (list<ControlPoint*>::iterator i = _push_points.begin(); i != _push_points.end(); ++i) {
619 (*i)->move_to ((*i)->get_x() + dx, (*i)->get_y(), ControlPoint::Full);
620 reset_line_coords (**i);
624 if (line_points.size() > 1) {
625 line->property_points() = line_points;
628 _drag_had_movement = true;
630 did_push = with_push;
636 /** Should be called to indicate the end of a drag */
638 AutomationLine::end_drag ()
640 if (!_drag_had_movement) {
646 /* set up the points that were moved this time round */
647 list<ControlPoint*> points = _drag_points;
649 copy (_push_points.begin(), _push_points.end(), back_inserter (points));
650 points.sort (ControlPointSorter ());
653 sync_model_with_view_points (points);
657 update_pending = false;
659 trackview.editor().session()->add_command (
660 new MementoCommand<AutomationList>(memento_command_binder (), 0, &alist->get_state())
663 trackview.editor().session()->set_dirty ();
668 AutomationLine::sync_model_with_view_point (ControlPoint& cp)
670 /* find out where the visual control point is.
671 initial results are in canvas units. ask the
672 line to convert them to something relevant.
675 double view_x = cp.get_x();
676 double view_y = 1.0 - (cp.get_y() / _height);
678 /* if xval has not changed, set it directly from the model to avoid rounding errors */
680 if (view_x == trackview.editor().frame_to_unit_unrounded (_time_converter->to ((*cp.model())->when)) - _offset) {
681 view_x = (*cp.model())->when - _offset;
683 view_x = trackview.editor().unit_to_frame (view_x);
684 view_x = _time_converter->from (view_x + _offset);
687 update_pending = true;
689 view_to_model_coord_y (view_y);
691 alist->modify (cp.model(), view_x, view_y);
695 AutomationLine::control_points_adjacent (double xval, uint32_t & before, uint32_t& after)
697 ControlPoint *bcp = 0;
698 ControlPoint *acp = 0;
701 unit_xval = trackview.editor().frame_to_unit_unrounded (xval);
703 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
705 if ((*i)->get_x() <= unit_xval) {
707 if (!bcp || (*i)->get_x() > bcp->get_x()) {
709 before = bcp->view_index();
712 } else if ((*i)->get_x() > unit_xval) {
714 after = acp->view_index();
723 AutomationLine::is_last_point (ControlPoint& cp)
725 // If the list is not empty, and the point is the last point in the list
727 if (alist->empty()) {
731 AutomationList::const_iterator i = alist->end();
734 if (cp.model() == i) {
742 AutomationLine::is_first_point (ControlPoint& cp)
744 // If the list is not empty, and the point is the first point in the list
746 if (!alist->empty() && cp.model() == alist->begin()) {
753 // This is copied into AudioRegionGainLine
755 AutomationLine::remove_point (ControlPoint& cp)
757 trackview.editor().session()->begin_reversible_command (_("remove control point"));
758 XMLNode &before = alist->get_state();
760 alist->erase (cp.model());
762 trackview.editor().session()->add_command(
763 new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state())
766 trackview.editor().session()->commit_reversible_command ();
767 trackview.editor().session()->set_dirty ();
770 /** Get selectable points within an area.
771 * @param start Start position in session frames.
772 * @param end End position in session frames.
773 * @param bot Bottom y range, as a fraction of line height, where 0 is the bottom of the line.
774 * @param top Top y range, as a fraction of line height, where 0 is the bottom of the line.
775 * @param result Filled in with selectable things; in this case, ControlPoints.
778 AutomationLine::get_selectables (
779 framepos_t start, framepos_t end, double botfrac, double topfrac, list<Selectable*>& results
782 /* convert fractions to display coordinates with 0 at the top of the track */
783 double const bot_track = (1 - topfrac) * trackview.current_height ();
784 double const top_track = (1 - botfrac) * trackview.current_height ();
786 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
787 double const model_when = (*(*i)->model())->when;
789 /* model_when is relative to the start of the source, so we just need to add on the origin_b here
790 (as it is the session frame position of the start of the source)
793 framepos_t const session_frames_when = _time_converter->to (model_when) + _time_converter->origin_b ();
795 if (session_frames_when >= start && session_frames_when <= end && (*i)->get_y() >= bot_track && (*i)->get_y() <= top_track) {
796 results.push_back (*i);
802 AutomationLine::get_inverted_selectables (Selection&, list<Selectable*>& /*results*/)
808 AutomationLine::set_selected_points (PointSelection const & points)
810 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
811 (*i)->set_selected (false);
814 for (PointSelection::const_iterator i = points.begin(); i != points.end(); ++i) {
815 (*i)->set_selected (true);
821 void AutomationLine::set_colors ()
823 set_line_color (ARDOUR_UI::config()->canvasvar_AutomationLine.get());
824 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
830 AutomationLine::list_changed ()
836 AutomationLine::reset_callback (const Evoral::ControlList& events)
842 if (events.empty()) {
843 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
846 control_points.clear ();
851 /* hide all existing points, and the line */
853 for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
860 Evoral::ControlList& e = const_cast<Evoral::ControlList&> (events);
862 for (AutomationList::iterator ai = e.begin(); ai != e.end(); ++ai, ++pi) {
864 double tx = (*ai)->when;
865 double ty = (*ai)->value;
867 /* convert from model coordinates to canonical view coordinates */
869 model_to_view_coord (tx, ty);
871 if (std::isnan (tx) || std::isnan (ty)) {
872 warning << string_compose (_("Ignoring illegal points on AutomationLine \"%1\""),
877 if (tx >= max_framepos || tx < 0 || tx >= _maximum_time) {
881 /* convert x-coordinate to a canvas unit coordinate (this takes
882 * zoom and scroll into account).
885 tx = trackview.editor().frame_to_unit_unrounded (tx);
887 /* convert from canonical view height (0..1.0) to actual
888 * height coordinates (using X11's top-left rooted system)
891 ty = _height - (ty * _height);
893 add_visible_control_point (vp, pi, tx, ty, ai, np);
897 /* discard extra CP's to avoid confusing ourselves */
899 while (control_points.size() > vp) {
900 ControlPoint* cp = control_points.back();
901 control_points.pop_back ();
905 if (!terminal_points_can_slide) {
906 control_points.back()->set_can_slide(false);
911 /* reset the line coordinates given to the CanvasLine */
913 while (line_points.size() < vp) {
914 line_points.push_back (Art::Point (0,0));
917 while (line_points.size() > vp) {
918 line_points.pop_back ();
921 for (uint32_t n = 0; n < vp; ++n) {
922 line_points[n].set_x (control_points[n]->get_x());
923 line_points[n].set_y (control_points[n]->get_y());
926 line->property_points() = line_points;
928 if (_visible && alist->interpolation() != AutomationList::Discrete) {
933 set_selected_points (trackview.editor().get_selection().points);
937 AutomationLine::reset ()
939 update_pending = false;
945 alist->apply_to_points (*this, &AutomationLine::reset_callback);
949 AutomationLine::clear ()
951 /* parent must create and commit command */
952 XMLNode &before = alist->get_state();
955 trackview.editor().session()->add_command (
956 new MementoCommand<AutomationList> (memento_command_binder (), &before, &alist->get_state())
961 AutomationLine::change_model (AutomationList::iterator /*i*/, double /*x*/, double /*y*/)
966 AutomationLine::set_list (boost::shared_ptr<ARDOUR::AutomationList> list)
974 AutomationLine::add_visibility (VisibleAspects va)
976 _visible = VisibleAspects (_visible | va);
981 AutomationLine::set_visibility (VisibleAspects va)
988 AutomationLine::remove_visibility (VisibleAspects va)
990 _visible = VisibleAspects (_visible & ~va);
995 AutomationLine::track_entered()
997 if (alist->interpolation() != AutomationList::Discrete) {
998 add_visibility (ControlPoints);
1003 AutomationLine::track_exited()
1005 if (alist->interpolation() != AutomationList::Discrete) {
1006 remove_visibility (ControlPoints);
1011 AutomationLine::get_state (void)
1013 /* function as a proxy for the model */
1014 return alist->get_state();
1018 AutomationLine::set_state (const XMLNode &node, int version)
1020 /* function as a proxy for the model */
1021 return alist->set_state (node, version);
1025 AutomationLine::view_to_model_coord (double& x, double& y) const
1027 x = _time_converter->from (x);
1028 view_to_model_coord_y (y);
1032 AutomationLine::view_to_model_coord_y (double& y) const
1034 /* TODO: This should be more generic ... */
1035 if (alist->parameter().type() == GainAutomation ||
1036 alist->parameter().type() == EnvelopeAutomation) {
1037 y = slider_position_to_gain_with_max (y, Config->get_max_gain());
1040 } else if (alist->parameter().type() == PanAzimuthAutomation ||
1041 alist->parameter().type() == PanElevationAutomation ||
1042 alist->parameter().type() == PanWidthAutomation) {
1044 } else if (alist->parameter().type() == PluginAutomation) {
1045 y = y * (double)(alist->get_max_y()- alist->get_min_y()) + alist->get_min_y();
1047 y = rint (y * alist->parameter().max());
1052 AutomationLine::model_to_view_coord (double& x, double& y) const
1054 /* TODO: This should be more generic ... */
1055 if (alist->parameter().type() == GainAutomation ||
1056 alist->parameter().type() == EnvelopeAutomation) {
1057 y = gain_to_slider_position_with_max (y, Config->get_max_gain());
1058 } else if (alist->parameter().type() == PanAzimuthAutomation ||
1059 alist->parameter().type() == PanElevationAutomation ||
1060 alist->parameter().type() == PanWidthAutomation) {
1061 // vertical coordinate axis reversal
1063 } else if (alist->parameter().type() == PluginAutomation) {
1064 y = (y - alist->get_min_y()) / (double)(alist->get_max_y()- alist->get_min_y());
1066 y = y / (double)alist->parameter().max(); /* ... like this */
1069 x = _time_converter->to (x) - _offset;
1072 /** Called when our list has announced that its interpolation style has changed */
1074 AutomationLine::interpolation_changed (AutomationList::InterpolationStyle style)
1076 if (style == AutomationList::Discrete) {
1077 set_visibility (ControlPoints);
1080 set_visibility (Line);
1085 AutomationLine::add_visible_control_point (uint32_t view_index, uint32_t pi, double tx, double ty,
1086 AutomationList::iterator model, uint32_t npoints)
1088 ControlPoint::ShapeType shape;
1090 if (view_index >= control_points.size()) {
1092 /* make sure we have enough control points */
1094 ControlPoint* ncp = new ControlPoint (*this);
1095 ncp->set_size (control_point_box_size ());
1097 control_points.push_back (ncp);
1100 if (!terminal_points_can_slide) {
1102 control_points[view_index]->set_can_slide (false);
1104 shape = ControlPoint::Start;
1106 shape = ControlPoint::Full;
1108 } else if (pi == npoints - 1) {
1109 control_points[view_index]->set_can_slide (false);
1110 shape = ControlPoint::End;
1112 control_points[view_index]->set_can_slide (true);
1113 shape = ControlPoint::Full;
1116 control_points[view_index]->set_can_slide (true);
1117 shape = ControlPoint::Full;
1120 control_points[view_index]->reset (tx, ty, model, view_index, shape);
1122 /* finally, control visibility */
1124 if (_visible & ControlPoints) {
1125 control_points[view_index]->show ();
1126 control_points[view_index]->set_visible (true);
1128 control_points[view_index]->set_visible (false);
1133 AutomationLine::connect_to_list ()
1135 _list_connections.drop_connections ();
1137 alist->StateChanged.connect (_list_connections, invalidator (*this), boost::bind (&AutomationLine::list_changed, this), gui_context());
1139 alist->InterpolationChanged.connect (
1140 _list_connections, invalidator (*this), boost::bind (&AutomationLine::interpolation_changed, this, _1), gui_context()
1144 MementoCommandBinder<AutomationList>*
1145 AutomationLine::memento_command_binder ()
1147 return new SimpleMementoCommandBinder<AutomationList> (*alist.get());
1150 /** Set the maximum time that points on this line can be at, relative
1151 * to the start of the track or region that it is on.
1154 AutomationLine::set_maximum_time (framecnt_t t)
1156 if (_maximum_time == t) {
1165 /** @return min and max x positions of points that are in the list, in session frames */
1166 pair<framepos_t, framepos_t>
1167 AutomationLine::get_point_x_range () const
1169 pair<framepos_t, framepos_t> r (max_framepos, 0);
1171 for (AutomationList::const_iterator i = the_list()->begin(); i != the_list()->end(); ++i) {
1172 r.first = min (r.first, session_position (i));
1173 r.second = max (r.second, session_position (i));
1180 AutomationLine::session_position (AutomationList::const_iterator p) const
1182 return _time_converter->to ((*p)->when) + _offset + _time_converter->origin_b ();
1186 AutomationLine::set_offset (framepos_t off)
1188 if (_offset == off) {