- this_rx = (uint32_t) rint (tx);
- this_ry = (uint32_t) rint (ty);
-
- if (view_index && pi != npoints && /* not the first, not the last */
- (((this_rx == prev_rx) && (this_ry == prev_ry)) || /* same point */
- (((this_rx - prev_rx) < (box_size + 2)) && /* not identical, but still too close horizontally */
- (abs ((int)(this_ry - prev_ry)) < (int) (box_size + 2))))) { /* too close vertically */
- continue;
- }
-
- /* ok, we should display this point */
-
- if (view_index >= cpsize) {
-
- /* make sure we have enough control points */
-
- ControlPoint* ncp = new ControlPoint (*this);
-
- ncp->set_size (box_size);
-
- control_points.push_back (ncp);
- ++cpsize;
- }
-
- ControlPoint::ShapeType shape;
-
- if (!terminal_points_can_slide) {
- if (pi == 0) {
- control_points[view_index]->set_can_slide(false);
- if (tx == 0) {
- shape = ControlPoint::Start;
- } else {
- shape = ControlPoint::Full;
- }
- } else if (pi == npoints - 1) {
- control_points[view_index]->set_can_slide(false);
- shape = ControlPoint::End;
- } else {
- control_points[view_index]->set_can_slide(true);
- shape = ControlPoint::Full;
- }
- } else {
- control_points[view_index]->set_can_slide(true);
- shape = ControlPoint::Full;
- }
-
- last_control_point_x = tx;
- last_control_point_y = ty;
-
- control_points[view_index]->reset (tx, ty, model, view_index, shape);
-
- prev_rx = this_rx;
- prev_ry = this_ry;
-
- /* finally, control visibility */
-
- if (_visible && points_visible) {
- control_points[view_index]->show ();
- control_points[view_index]->set_visible (true);
- } else {
- if (!points_visible) {
- control_points[view_index]->set_visible (false);
- }
- }
-
- view_index++;
- }
-
- /* discard extra CP's to avoid confusing ourselves */
-
- while (control_points.size() > view_index) {
- ControlPoint* cp = control_points.back();
- control_points.pop_back ();
- delete cp;
- }
-
- if (!terminal_points_can_slide) {
- control_points.back()->set_can_slide(false);
- }
-
- delete [] slope;
-
- if (view_index > 1) {
-
- npoints = view_index;
-
- /* reset the line coordinates */
-
- while (line_points.size() < npoints) {
- line_points.push_back (Art::Point (0,0));
- }
-
- while (line_points.size() > npoints) {
- line_points.pop_back ();
- }
-
- for (view_index = 0; view_index < npoints; ++view_index) {
- line_points[view_index].set_x (control_points[view_index]->get_x());
- line_points[view_index].set_y (control_points[view_index]->get_y());
- }
-
- line->property_points() = line_points;
-
- if (_visible && _interpolation != AutomationList::Discrete) {
- line->show();
- }
-
- }
-
- set_selected_points (trackview.editor().get_selection().points);
-
-}
-
-string
-AutomationLine::get_verbose_cursor_string (double fraction) const
-{
- std::string s = fraction_to_string (fraction);
- if (_uses_gain_mapping) {
- s += " dB";
- }
-
- return s;
-}
-
-/**
- * @param fraction y fraction
- * @return string representation of this value, using dB if appropriate.
- */
-string
-AutomationLine::fraction_to_string (double fraction) const
-{
- char buf[32];
-
- if (_uses_gain_mapping) {
- if (fraction == 0.0) {
- snprintf (buf, sizeof (buf), "-inf");
- } else {
- snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain (fraction)));
- }
- } else {
- double dummy = 0.0;
- view_to_model_coord (dummy, fraction);
- if (EventTypeMap::instance().is_integer (alist->parameter())) {
- snprintf (buf, sizeof (buf), "%d", (int)fraction);
- } else {
- snprintf (buf, sizeof (buf), "%.2f", fraction);
- }
- }
-
- return buf;
-}
-
-
-/**
- * @param s Value string in the form as returned by fraction_to_string.
- * @return Corresponding y fraction.
- */
-double
-AutomationLine::string_to_fraction (string const & s) const
-{
- if (s == "-inf") {
- return 0;
- }
-
- double v;
- sscanf (s.c_str(), "%lf", &v);
-
- if (_uses_gain_mapping) {
- v = gain_to_slider_position (dB_to_coefficient (v));
- } else {
- double dummy = 0.0;
- model_to_view_coord (dummy, v);
- }
-
- return v;
-}
-
-bool
-AutomationLine::invalid_point (ALPoints& p, uint32_t index)
-{
- return p[index].x == max_frames && p[index].y == DBL_MAX;
-}
-
-void
-AutomationLine::invalidate_point (ALPoints& p, uint32_t index)
-{
- p[index].x = max_frames;
- p[index].y = DBL_MAX;
-}
-
-void
-AutomationLine::start_drag (ControlPoint* cp, nframes_t x, float fraction)
-{
- if (trackview.editor().session() == 0) { /* how? */
- return;
- }
-
- string str;
-
- if (cp) {
- str = _("automation event move");
- } else {
- str = _("automation range drag");
- }
-
- trackview.editor().session()->begin_reversible_command (str);
- trackview.editor().session()->add_command (new MementoCommand<AutomationList>(*alist.get(), &get_state(), 0));
-
- drag_x = x;
- drag_distance = 0;
- first_drag_fraction = fraction;
- last_drag_fraction = fraction;
- drags = 0;
- did_push = false;