- 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().current_session() == 0) { /* how? */
- return;
- }
-
- string str;
-
- if (cp) {
- str = _("automation event move");
- } else {
- str = _("automation range drag");
- }
-
- trackview.editor().current_session()->begin_reversible_command (str);
- trackview.editor().current_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;
-}
-
-void
-AutomationLine::point_drag (ControlPoint& cp, nframes_t x, float fraction, bool with_push)
-{
- if (x > drag_x) {
- drag_distance += (x - drag_x);
- } else {
- drag_distance -= (drag_x - x);
- }
-
- drag_x = x;
-
- modify_view_point (cp, x, fraction, with_push);
-
- if (line_points.size() > 1) {
- line->property_points() = line_points;
- }
-
- drags++;
- did_push = with_push;
-}
-
-void
-AutomationLine::line_drag (uint32_t i1, uint32_t i2, float fraction, bool with_push)
-{
- double ydelta = fraction - last_drag_fraction;
-
- did_push = with_push;
-
- last_drag_fraction = fraction;
-
- line_drag_cp1 = i1;
- line_drag_cp2 = i2;
-
- //check if one of the control points on the line is in a selected range
- bool range_found = false;
- ControlPoint *cp;
-
- for (uint32_t i = i1 ; i <= i2; i++) {
- cp = nth (i);
- if (cp->selected()) {
- range_found = true;
- }
- }
-
- if (range_found) {
- for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
- if ((*i)->selected()) {
- modify_view_point (*(*i), trackview.editor().unit_to_frame ((*i)->get_x()), ((_height - (*i)->get_y()) /_height) + ydelta, with_push);
- }
- }
- } else {
- ControlPoint *cp;
- for (uint32_t i = i1 ; i <= i2; i++) {
- cp = nth (i);
- modify_view_point (*cp, trackview.editor().unit_to_frame (cp->get_x()), ((_height - cp->get_y()) /_height) + ydelta, with_push);
- }
- }
-
- if (line_points.size() > 1) {
- line->property_points() = line_points;
- }
-
- drags++;