X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fautomation_line.cc;h=9c1aa13198bc52c76dfbb2b9595d5c7491cad4ed;hb=f413b83cb9fa50954969a3d849999e1890ce6690;hp=a422bf972331c5e284510b31a8200b481684ff60;hpb=cf52d6e4b40111eb04b244ec054055a4ec15dbe0;p=ardour.git diff --git a/gtk2_ardour/automation_line.cc b/gtk2_ardour/automation_line.cc index a422bf9723..9c1aa13198 100644 --- a/gtk2_ardour/automation_line.cc +++ b/gtk2_ardour/automation_line.cc @@ -99,7 +99,6 @@ AutomationLine::AutomationLine (const string& name, update_pending = false; have_timeout = false; - _uses_gain_mapping = false; no_draw = false; _is_boolean = false; terminal_points_can_slide = true; @@ -118,12 +117,6 @@ AutomationLine::AutomationLine (const string& name, trackview.session()->register_with_memento_command_factory(alist->id(), this); - if (alist->parameter().type() == GainAutomation || - alist->parameter().type() == TrimAutomation || - alist->parameter().type() == EnvelopeAutomation) { - set_uses_gain_mapping (true); - } - interpolation_changed (alist->interpolation ()); connect_to_list (); @@ -194,7 +187,19 @@ AutomationLine::update_visibility () } } } +} +bool +AutomationLine::get_uses_gain_mapping () const +{ + switch (_desc.type) { + case GainAutomation: + case EnvelopeAutomation: + case TrimAutomation: + return true; + default: + return false; + } } void @@ -244,16 +249,10 @@ AutomationLine::set_line_color (uint32_t color) { _line_color = color; line->set_outline_color (color); - line->set_fill_color ((color & 0xffff00) + 80); // XXX TODO configurable transparency -} -void -AutomationLine::set_uses_gain_mapping (bool yn) -{ - if (yn != _uses_gain_mapping) { - _uses_gain_mapping = yn; - reset (); - } + ArdourCanvas::SVAModifier mod = UIConfiguration::instance().modifier ("automation line fill"); + + line->set_fill_color ((color & 0xffffff00) + mod.a()*255); } ControlPoint* @@ -339,37 +338,15 @@ AutomationLine::sync_model_with_view_points (list cp) string AutomationLine::get_verbose_cursor_string (double fraction) const { - std::string s = fraction_to_string (fraction); - if (_uses_gain_mapping) { - s += " dB"; - } - - return s; + return fraction_to_string (fraction); } string -AutomationLine::get_verbose_cursor_relative_string (double original, double fraction) const +AutomationLine::get_verbose_cursor_relative_string (double fraction, double delta) const { std::string s = fraction_to_string (fraction); - if (_uses_gain_mapping) { - s += " dB"; - } - - std::string d = fraction_to_relative_string (original, fraction); - - if (!d.empty()) { - - s += " (\u0394"; - s += d; - - if (_uses_gain_mapping) { - s += " dB"; - } - - s += ')'; - } - - return s; + std::string d = delta_to_string (delta); + return s + " (" + d + ")"; } /** @@ -379,62 +356,18 @@ AutomationLine::get_verbose_cursor_relative_string (double original, double frac string AutomationLine::fraction_to_string (double fraction) const { - if (_uses_gain_mapping) { - char buf[32]; - if (_desc.type == GainAutomation || _desc.type == EnvelopeAutomation || _desc.lower == 0) { - if (fraction == 0.0) { - snprintf (buf, sizeof (buf), "-inf"); - } else { - snprintf (buf, sizeof (buf), "%.1f", accurate_coefficient_to_dB (slider_position_to_gain_with_max (fraction, _desc.upper))); - } - } else { - const double lower_db = accurate_coefficient_to_dB (_desc.lower); - const double range_db = accurate_coefficient_to_dB (_desc.upper) - lower_db; - snprintf (buf, sizeof (buf), "%.1f", lower_db + fraction * range_db); - } - return buf; - } else { - view_to_model_coord_y (fraction); - return ARDOUR::value_as_string (_desc, fraction); - } - - return ""; /*NOTREACHED*/ + view_to_model_coord_y (fraction); + return ARDOUR::value_as_string (_desc, fraction); } -/** - * @param original an old y-axis fraction - * @param fraction the new y fraction - * @return string representation of the difference between original and fraction, using dB if appropriate. - */ string -AutomationLine::fraction_to_relative_string (double original, double fraction) const +AutomationLine::delta_to_string (double delta) const { - char buf[32]; - - if (original == fraction) { - return "0"; - } - - if (_uses_gain_mapping) { - if (original == 0.0) { - /* there is no sensible representation of a relative - change from -inf dB, so return an empty string. - */ - return ""; - } else if (fraction == 0.0) { - snprintf (buf, sizeof (buf), "-inf"); - } else { - double old_db = accurate_coefficient_to_dB (slider_position_to_gain_with_max (original, Config->get_max_gain())); - double new_db = accurate_coefficient_to_dB (slider_position_to_gain_with_max (fraction, Config->get_max_gain())); - snprintf (buf, sizeof (buf), "%.1f", new_db - old_db); - } + if (!get_uses_gain_mapping () && _desc.logarithmic) { + return "x " + ARDOUR::value_as_string (_desc, delta); } else { - view_to_model_coord_y (original); - view_to_model_coord_y (fraction); - return ARDOUR::value_as_string (_desc, fraction - original); + return "\u0394 " + ARDOUR::value_as_string (_desc, delta); } - - return buf; } /** @@ -444,20 +377,23 @@ AutomationLine::fraction_to_relative_string (double original, double fraction) c 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_with_max (dB_to_coefficient (v), Config->get_max_gain()); - } else { - double dummy = 0.0; - model_to_view_coord (dummy, v); + switch (_desc.type) { + case GainAutomation: + case EnvelopeAutomation: + case TrimAutomation: + if (s == "-inf") { /* translation */ + v = 0; + } else { + v = dB_to_coefficient (v); + } + break; + default: + break; } - + model_to_view_coord_y (v); return v; } @@ -607,10 +543,17 @@ AutomationLine::ContiguousControlPoints::clamp_dx (double dx) } void -AutomationLine::ContiguousControlPoints::move (double dx, double dy) +AutomationLine::ContiguousControlPoints::move (double dx, double dvalue) { for (std::list::iterator i = begin(); i != end(); ++i) { - (*i)->move_to ((*i)->get_x() + dx, (*i)->get_y() - line.height() * dy, ControlPoint::Full); + // compute y-axis delta + double view_y = 1.0 - (*i)->get_y() / line.height(); + line.view_to_model_coord_y (view_y); + line.apply_delta (view_y, dvalue); + line.model_to_view_coord_y (view_y); + view_y = (1.0 - view_y) * line.height(); + + (*i)->move_to ((*i)->get_x() + dx, view_y, ControlPoint::Full); line.reset_line_coords (**i); } } @@ -639,11 +582,11 @@ AutomationLine::start_drag_common (double x, float fraction) * @param fraction New y fraction. * @return x position and y fraction that were actually used (once clamped). */ -pair +pair AutomationLine::drag_motion (double const x, float fraction, bool ignore_x, bool with_push, uint32_t& final_index) { if (_drag_points.empty()) { - return pair (x,fraction); + return pair (fraction, _desc.is_linear () ? 0 : 1); } double dx = ignore_x ? 0 : (x - _drag_x); @@ -700,24 +643,42 @@ AutomationLine::drag_motion (double const x, float fraction, bool ignore_x, bool } } + /* compute deflection */ + double delta_value; + { + double value0 = _last_drag_fraction; + double value1 = _last_drag_fraction + dy; + view_to_model_coord_y (value0); + view_to_model_coord_y (value1); + delta_value = compute_delta (value0, value1); + } + + /* special case -inf */ + if (delta_value == 0 && dy > 0 && !_desc.is_linear ()) { + assert (_desc.lower == 0); + delta_value = 1.0; + } + /* clamp y */ for (list::iterator i = _drag_points.begin(); i != _drag_points.end(); ++i) { - double const y = ((_height - (*i)->get_y()) / _height) + dy; - if (y < 0) { - dy -= y; + double vy = 1.0 - (*i)->get_y() / _height; + view_to_model_coord_y (vy); + const double orig = vy; + apply_delta (vy, delta_value); + if (vy < _desc.lower) { + delta_value = compute_delta (orig, _desc.lower); } - if (y > 1) { - dy -= (y - 1); + if (vy > _desc.upper) { + delta_value = compute_delta (orig, _desc.upper); } } if (dx || dy) { - /* and now move each section */ - for (vector::iterator ccp = contiguous_points.begin(); ccp != contiguous_points.end(); ++ccp) { - (*ccp)->move (dx, dy); + (*ccp)->move (dx, delta_value); } + if (with_push) { final_index = contiguous_points.back()->back()->view_index () + 1; ControlPoint* p; @@ -729,20 +690,32 @@ AutomationLine::drag_motion (double const x, float fraction, bool ignore_x, bool } } - /* update actual line coordinates (will queue a redraw) - */ + /* update actual line coordinates (will queue a redraw) */ if (line_points.size() > 1) { line->set_steps (line_points, is_stepped()); } } + + /* calculate effective delta */ + ControlPoint* cp = _drag_points.front(); + double vy = 1.0 - cp->get_y() / (double)_height; + view_to_model_coord_y (vy); + float val = (*(cp->model ()))->value; + float effective_delta = _desc.compute_delta (val, vy); + /* special case recovery from -inf */ + if (val == 0 && effective_delta == 0 && vy > 0) { + assert (!_desc.is_linear ()); + effective_delta = HUGE_VAL; // +Infinity + } + double const result_frac = _last_drag_fraction + dy; _drag_distance += dx; _drag_x += dx; _last_drag_fraction = result_frac; did_push = with_push; - return pair (_drag_x + dx, result_frac); + return pair (result_frac, effective_delta); } /** Should be called to indicate the end of a drag */ @@ -793,7 +766,7 @@ AutomationLine::sync_model_with_view_point (ControlPoint& cp) */ double view_x = cp.get_x(); - double view_y = 1.0 - (cp.get_y() / _height); + double view_y = 1.0 - cp.get_y() / (double)_height; /* if xval has not changed, set it directly from the model to avoid rounding errors */ @@ -1195,58 +1168,55 @@ AutomationLine::view_to_model_coord (double& x, double& y) const void AutomationLine::view_to_model_coord_y (double& y) const { - /* TODO: This should be more generic (use ParameterDescriptor) - * or better yet: Controllable -> set_interface(); - */ - if ( alist->parameter().type() == GainAutomation - || alist->parameter().type() == EnvelopeAutomation - || (_desc.logarithmic && _desc.lower == 0. && _desc.upper > _desc.lower)) { - y = slider_position_to_gain_with_max (y, _desc.upper); - y = max ((double)_desc.lower, y); - y = min ((double)_desc.upper, y); - } else if (alist->parameter().type() == TrimAutomation - || (_desc.logarithmic && _desc.lower * _desc.upper > 0 && _desc.upper > _desc.lower)) { - const double lower_db = accurate_coefficient_to_dB (_desc.lower); - const double range_db = accurate_coefficient_to_dB (_desc.upper) - lower_db; - y = max (0.0, y); - y = min (1.0, y); - y = dB_to_coefficient (lower_db + y * range_db); - } else if (alist->parameter().type() == PanAzimuthAutomation || - alist->parameter().type() == PanElevationAutomation) { - y = 1.0 - y; - } else if (alist->parameter().type() == PanWidthAutomation) { - y = 2.0 * y - 1.0; - } else { - y = y * (double)(alist->get_max_y() - alist->get_min_y()) + alist->get_min_y(); - if (_desc.integer_step) { - y = round(y); - } else if (_desc.toggled) { - y = (y > 0.5) ? 1.0 : 0.0; +#ifdef XXX_NEW_INTERPOLATON__BREAK_SESSION_FORMAT_XXX + if (alist->default_interpolation () != alist->interpolation()) { + switch (alist->interpolation()) { + case AutomationList::Linear: + y = y * (_desc.upper - _desc.lower) + _desc.lower; + return; + default: + assert (0); + break; } } +#endif + y = _desc.from_interface (y); +} + +double +AutomationLine::compute_delta (double from, double to) const +{ + return _desc.compute_delta (from, to); +} + +void +AutomationLine::apply_delta (double& val, double delta) const +{ + if (val == 0 && !_desc.is_linear () && delta >= 1.0) { + /* recover from -inf */ + val = 1.0 / _height; + view_to_model_coord_y (val); + return; + } + val = _desc.apply_delta (val, delta); } void AutomationLine::model_to_view_coord_y (double& y) const { - /* TODO: This should be more generic (use ParameterDescriptor) */ - if ( alist->parameter().type() == GainAutomation - || alist->parameter().type() == EnvelopeAutomation - || (_desc.logarithmic && _desc.lower == 0. && _desc.upper > _desc.lower)) { - y = gain_to_slider_position_with_max (y, _desc.upper); - } else if (alist->parameter().type() == TrimAutomation - || (_desc.logarithmic && _desc.lower * _desc.upper > 0 && _desc.upper > _desc.lower)) { - const double lower_db = accurate_coefficient_to_dB (_desc.lower); - const double range_db = accurate_coefficient_to_dB (_desc.upper) - lower_db; - y = (accurate_coefficient_to_dB (y) - lower_db) / range_db; - } else if (alist->parameter().type() == PanAzimuthAutomation || - alist->parameter().type() == PanElevationAutomation) { - y = 1.0 - y; - } else if (alist->parameter().type() == PanWidthAutomation) { - y = .5 + y * .5; - } else { - y = (y - alist->get_min_y()) / (double)(alist->get_max_y() - alist->get_min_y()); +#ifdef XXX_NEW_INTERPOLATON__BREAK_SESSION_FORMAT_XXX + if (alist->default_interpolation () != alist->interpolation()) { + switch (alist->interpolation()) { + case AutomationList::Linear: + y = (y - _desc.lower) / (_desc.upper - _desc.lower); + return; + default: + assert (0); + break; + } } +#endif + y = _desc.to_interface (y); } void @@ -1261,6 +1231,7 @@ void AutomationLine::interpolation_changed (AutomationList::InterpolationStyle style) { if (line_points.size() > 1) { + reset (); line->set_steps(line_points, is_stepped()); } }