Skip to content

Add monotone cubic Hermite plot style to TimeValueLayer#3

Open
DMGiulioRomano wants to merge 1 commit into
sonic-visualiser:defaultfrom
DMGiulioRomano:cubic-hermite-plot-style
Open

Add monotone cubic Hermite plot style to TimeValueLayer#3
DMGiulioRomano wants to merge 1 commit into
sonic-visualiser:defaultfrom
DMGiulioRomano:cubic-hermite-plot-style

Conversation

@DMGiulioRomano

Copy link
Copy Markdown

Adds a new PlotCubicHermite plot style (appended to the PlotStyle enum as value 7) that draws a smooth curve through the layer's breakpoints using monotone cubic Hermite interpolation with Fritsch-Carlson tangents (Fritsch & Carlson, "Monotone Piecewise Cubic Interpolation", SIAM J. Numer. Anal. 17(2), 1980).

Unlike PlotCurve, which uses Bezier control points and can overshoot the data on steep transitions or narrow peaks, this style is guaranteed to stay within the range of the surrounding breakpoints: tangents are driven to zero at local extrema, so plateaus stay flat and monotone runs never overshoot. With only two breakpoints the curve degenerates to a symmetric smoothstep.

Implementation (layer/TimeValueLayer.{h,cpp} only):

  • Two file-local helpers, computeFritschCarlsonTangents() and cubicHermite(). Coincident frames are guarded against division by zero.
  • A dedicated rendering branch in paint() that samples the curve at 1px (O(paint width), same cost as PlotCurve) and draws it with drawPath and antialiasing. A single point falls back to a small rectangular marker.
  • Plot Type range extended (max 6 -> 7) and a "Cubic Hermite" label.
  • The style is treated as scrollable, like the other curve styles.

Tangents are computed over all model events, not just the visible window, so the curve does not change shape while scrolling; for the same reason the branch runs before the visible-window emptiness check, so a curve passing between two off-screen breakpoints is still drawn. Interpolation is done in value space and each sample is mapped through the vertical CoordinateScale, so the curve is correct on a logarithmic vertical scale.

Save/load needs no change: toXml already serialises m_plotStyle as an integer and setProperties casts it back, so plotStyle="7" round-trips, and appending the value keeps the existing styles 0-6 unchanged.

Claude-Session: https://claude.ai/code/session_016ANtJmJppqkSVEk6AVtKrn

Adds a new PlotCubicHermite plot style (appended to the PlotStyle enum as
value 7) that draws a smooth curve through the layer's breakpoints using
monotone cubic Hermite interpolation with Fritsch-Carlson tangents
(Fritsch & Carlson, "Monotone Piecewise Cubic Interpolation",
SIAM J. Numer. Anal. 17(2), 1980).

Unlike PlotCurve, which uses Bezier control points and can overshoot the
data on steep transitions or narrow peaks, this style is guaranteed to
stay within the range of the surrounding breakpoints: tangents are driven
to zero at local extrema, so plateaus stay flat and monotone runs never
overshoot. With only two breakpoints the curve degenerates to a symmetric
smoothstep.

Implementation (layer/TimeValueLayer.{h,cpp} only):

- Two file-local helpers, computeFritschCarlsonTangents() and
  cubicHermite(). Coincident frames are guarded against division by zero.
- A dedicated rendering branch in paint() that samples the curve at 1px
  (O(paint width), same cost as PlotCurve) and draws it with drawPath and
  antialiasing. A single point falls back to a small rectangular marker.
- Plot Type range extended (max 6 -> 7) and a "Cubic Hermite" label.
- The style is treated as scrollable, like the other curve styles.

Tangents are computed over all model events, not just the visible window,
so the curve does not change shape while scrolling; for the same reason
the branch runs before the visible-window emptiness check, so a curve
passing between two off-screen breakpoints is still drawn. Interpolation
is done in value space and each sample is mapped through the vertical
CoordinateScale, so the curve is correct on a logarithmic vertical scale.

Save/load needs no change: toXml already serialises m_plotStyle as an
integer and setProperties casts it back, so plotStyle="7" round-trips, and
appending the value keeps the existing styles 0-6 unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016ANtJmJppqkSVEk6AVtKrn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants