Is there a class to draw and edit splines?

I’m a fairly experienced developer just getting started with JUCE and I’m wondering if there’s a premade class or component that does what I want to do:

I’m making a synth-thing where you will be able to place control points on a time line, it draws a spline through the points and uses this to set audio parameters such as frequency and amplitude. Points will be draggable and you’ll be able to copy/paste parts of the line etc.

Is something like this already available or should I create a new class from scratch? Just trying to avoid reimplementing the wheel. Probably going to need a graphical representation of a signal generator graph that allows editing of connections in the future too, but I might be able to repurpose parts of the AudioPluginHost which kind of looks like what I want

I was just about to suggest looking into AudioPluginHost.

About the spline editor, I am repeating myself here and in the discord chat:
A spline is a 2-dimensional curve, so it is not a good fit for a parameter automation. You want a 1-dimensional curve ideally in polynomial form, that is easy to compute.

I started to work on such a thing, but put it aside, when I got lost in the maths.
My approach was adding the equations:

• two known points to pass: `f(x0) = y0 | f(x1) = y1`
• if a point is a local extreme assume a horizontal tangent: `f'(x) = 0`
this is necessary, otherwise your function can exceed the range
• otherwise average the two line segment’s slope: `f'(x1) = (m1 + m0) / 2`
where `m(n) = (y1 - y0) / (x1 - x0)`

Dragging the control vertices is another approach, I don’t know if a 1-dimensional version exists. I would be curious as well…

1 Like

Yea, I found AudioPluginHost just after I posted the question and ninja-edited it.

Haven’t even started looking at the maths but it sounds like you’re right. Though 1d splines seem to be a thing so I’ll have to read up on the subject. Maybe I’ll start with straight lines just to get somewhere, since it’s control signals and not audio I should be able to live with it for a while

1 Like

I have a class to calculate splines. Might be something to use as a starting point: https://github.com/FigBug/Gin/blob/master/modules/gin/utilities/spline.h

I’m not aware of any component that does what you want, so you’re going to need to build it yourself.

1 Like