home/ atoms/ strudel-register-custom-method

register() adds a new method to Strudel's Pattern class and returns it as a standalone function

register(name, func, patternify) is the official extension point for adding pattern methods to Strudel. It installs the method on the Pattern class and also returns the equivalent standalone function. func receives its declared arguments plus the current pattern as the last argument. patternify defaults to true, meaning argument values are automatically converted to patterns before func runs; setting it false hands you the raw arguments so you can patternify or query them yourself. All built-in methods are registered this way, so user-defined methods behave as first-class pattern operators.

Examples

const vlpf = register(‘vlpf’, (freq, pat) => pat.fmap((v) => ({…v, cutoff: freq * (v.velocity ?? 1)})) ) s(“saw”).seg(8).velocity(rand).vlpf(800)

Assessment

Write a register call creating a .transpose(n) method that shifts every .note value by n semitones, then call it on a melody. State what patternify=false would change about your argument handling.

“Registers a new pattern method. The method is added to the Pattern class + the standalone function is returned from register.”
corpus · strudel-internals-pattern-as-function-of-time-functor-applic · chunk 1