tidalcycles / strudel

Web-based environment for live coding algorithmic patterns, incorporating a faithful port of TidalCycles to JavaScript
https://strudel.cc/
GNU Affero General Public License v3.0
586 stars 105 forks source link

pickr and solo with stacking info #949

Closed eefano closed 4 months ago

eefano commented 4 months ago

Now stack() (and the mininotation comma operator) populate the 'stacking' property of the hap context by pushing the stacking index into an array. The array handles nested stacking also. The outermost stacking level is the first element of the array.

The new solo() and mute() functions make use of this information by keeping only the haps that match (or not) the specified outermost stacking index. The new produced haps also have this index striped out from the stacking array, so subsequent calls of solo() can work with the inner stacking layers.

The implementation of solo() may be a little tricky. The original hap value is temporarily stored in context.tempvalue, modified to the stacking index, and then restored after the filtering operation is done.

The new pickr() and pickrmod() functions make use of solo(0), because restart("[1,2]") produces a pattern with duplicated haps. "[1,2]".solo(0) should be equivalent to "[1]", thus solving the problem.

I have also fixed two little typos in inhabit() and inhabitmod() declarations.

felixroos commented 4 months ago

I am not sure if it's a good idea to increase cost of the very fundamental stack function for this single use case, doing a lot of extra iterations and generating objects. A simpler version could be to add use tagging like this: https://strudel.cc/?yns0qGnjwmAl edit: I still like the idea of having solo / mute very much :)

eefano commented 4 months ago

No problem! I went down the rabbit hole trying to make pickr() work as intended, and came up with this overkill idea. I definitely learned something in the process!