First time here? Check out the FAQ!
x

How can I generate comma-seperated CapyTalk expressions using SmallTalk?

0 votes
729 views

I made a sequencer in the Frequency parameter of a Sound, which uses multiple CapyTalk sub-expressions seperated by commas. A bunch of these sub-expressions are very repetitive so I'm wondering how I can generate them using SmallTalk.

 

If I use collect: and do something like this:

...,
((0 to: 7) collect: [:i|
    ((eva @< i) <+ (((i + rotation) mod: 8) of: seqFaders))
]),
...

That creates an array that doesn't seem happy in the middle of other comma seperated expressions.

Is there a way to generate those eight sub-expressions in a more succinct way using some SmallTalk?

 

asked Nov 11, 2018 in Capytalk & Smalltalk by alan-jackson (Virtuoso) (15,840 points)

1 Answer

+1 vote
 
Best answer

Cool! You could try building up your expression step by step, saving the cumulative expression in an instance variable (like seq in the example below):

| seqFaders seq eva rotation |

rotation := EventVariable new initialValue: 0.
eva := EventVariable new size: 8.

seqFaders := (1 to: 8) collect: [:i| !Interval suffix: i].
seq := (!Rotate switchedOn
        true: (rotation <+ ((rotation + 1) mod: 8))
        false: (nil)).
seq := (0 to: 7) inject: seq into: [ :expr :i | expr,  ((eva @< i) <+ (((i + rotation) mod: 8) of: seqFaders))].

seq := (seq, (eva @< ((1 bpm: !BPM) countTriggersMod: 8))).

seq nn + !LogFreq nn

answered Nov 12, 2018 by ssc (Savant) (128,000 points)
selected Nov 23, 2018 by alan-jackson

Fantastic thanks SSC!

Here's what the rotating sequencers sound like, using kyma's built in vocal samples.

What if I only wanted an expression with the 8 repetitive lines in it? I wouldn't have an initial expression to use with inject: into:.

Is there a way of doing this with collect: or do:?
One quick way might be to store the 0th expression in the variable before concatenating the remaining 1-to-7 expressions?

seq := ((eva @< 0) <+ ((rotation mod: 8) of: seqFaders)).
seq := (1 to: 7) inject: seq into: [ :expr :i | expr,  ((eva @< i) <+ (((i + rotation) mod: 8) of: seqFaders))].
...