Closed trentgill closed 1 year ago
Just leaving a note here that while :settable()
method is now working successfully across all datatypes, it needs to be refactored as it's a mess of nested loops, and i'm quite sure there is a far simpler recursive solution. as it stands there is a lot of 'how to copy' code mixed in with 'what are we copying' code.
i think it should just be a set of shallow if cases that ask whether the input is a sequins/flow-mod/transformer/literal/table. the only one that should do any marshalling is the table
case as it's the most general & we don't know what to do with it.
Merging now to get these into the main branch. All of the above is working well & could use some testing. It would be great to push the bake()
method and see if it strains the system. In general i think this is a really powerful & useful set of utilities to create musical patterns on crow.
sequins transformer maps
this new feature for sequins allows a value transformation function to be attached to a sequins. whenever a sequins object is called, the value it produces is passed through the transformer function before being returned.
this enables rapid pattern permutation with the full power of lua, while the interface to produce that value is left untouched. it is another tool for describing a sequence of values that will be produced in the future.
usage is with the method
:map
which takes its name from the functional programming technique of 'mapping' a function over a collection. here we map our transformer over the output values of the sequins. one key difference is that ourmap
transformation is a non-destructive effect that happens whenever a new value is taken from the sequins.because a lua function can have non-determinism (eg.
math.random()
), this can create infinitely long sequences, or at least stochastic sequences.transformers can also use sequins, which you pass in as additional arguments to
:map
. this gets into 'pattern synthesis' (thanks @dndrks) territory, enabling complex interactions to unfold, especially when using sequins of differing lengths.while any lua action is allowed, we suggest using transformers exclusively to manipulate the data in a pure fashion. if you want each value to be sent to an IO (read: real-world) function, call the sequins in a
timeline
or event handler.additionally there are shortcuts to do a single arithmetic operation, using lua's arithmetic operators. this can make transposition easy (+2), or conversion from notes-numbers to volts (/12).
you can of course apply another sequins as demonstrated above, but with a much tighter syntax. when applying other sequins, remember that the sequins on the left of the operator is the 'primary' sequins that captures the sequins (or literal) on the right hand side. this is true for literals too - the sequins must be on the left (so no, you can't negative a sequins directly, use a little function).
baking sequins
when you start working with transformation maps, you will likely want to work iteratively, building up your transformations gradually. when you land on the right transformation, rather than copying the whole sequins & creating increasingly complex
map
functions, you canbake
the current transformation into a new sequins.the
bake
function returns a completely flat sequins (ie, no nested sequins). the default behaviour of:bake()
with no arguments will create a new sequins of the same length as the original sequins (any nested sequins are treated as only 1 value).if you want to capture variations built into your original sequins, you can capture an arbitrary number of values from your sequins with
:bake(n)
wheren
is the number of values in the newly baked sequins. this technique is very useful for flattening nested tables, or flattening tables with sequins-enabled transformations.additionally, the
:bake(n)
method can be super useful for taking sequins of odd-lengths & forcing them into a repeating 8/16/32 (etc) step pattern. under the hood,:bake(n)
is just calling your sequinsn
-times and making a sequins out of the result, so it's not linked to any of the more complex sequins behaviour.TODO pull examples from https://gist.github.com/trentgill/bf930d4cb3f7f9e4a4c981432bf02356 and comments below.