Modulators
In ixfx, a modulate function is simply one that takes an input number and returns an output. Values are usually on the 0..1 scale, but functions can overshoot these, for example a spring which might bounce past the end.
For example:
We often want to modulate with some temporality, and ixfx has two main ways of doing so. One is most obviously by clock time, setting up a modulator to run over a given period of milliseconds, for example. Time is useful because it’s very human-relatable and is independent of how fast other parts of your code are running.
The second technique is ‘ticks’. A tick is essentially a counter that increases by one whenever it is used. This allows you to move something forward exactly when you want.
When work with temporality, the input for the modulate function represents the progress towards completion (either time or total number of ticks) on a scale of 0..1.
With those two forms of temporality out of the way, we can look at two ways of using time and ticks with modulation.
Simple
The very simple approach is to use Modulation.time and Modulation.ticks . These both take a modulation function and some duration, returning a function that yields a value.
Here’s a more complete example:
Instead of providing your own modulation function, you might want to use one from ixfx, for example:
Using other functions from ixfx we can do things like compute the numeric value of several modulators at once:
What about envelopes? Envelopes already have an in-built time context, Modulation.time
and ticks
aren’t very useful. Envelopes.adsr provides the handiness of a simple function that returns a value.
Advanced
More advanced control is also possible. For example if you want to reset a modulator, or check if it has completed.
Then you want to use timeModulator and tickModulator . Like their simpler counterparts, they both take a modulation function and a duration of time or total ticks.
Instead of returning a function, they return a Type ModulatorTimed has this type:
With this return object, we can work with the modulator:
More practical uses for Type ModulatorTimed is resetting a modulator based on a ‘pointerup’ event, adding a CSS class when a modulator is finished and so on.