home/ atoms/ strudel-filterhaps-vs-filtervalues

filterHaps tests the whole Hap (with timing) while filterValues tests only the value

Both methods return a new pattern with events removed by a predicate, but differ in what the predicate sees. filterHaps(hap_test) receives the full Hap object, so it can reference timing metadata such as h.whole.begin, onset position, or context. filterValues(value_test) receives only the value payload, so it is simpler but blind to timing. Choose filterHaps when the decision depends on when an event happens (e.g. probabilistic thinning by comparing time to a velocity), and filterValues when it depends only on what the event is (e.g. splitting a drum pattern by sound name).

Examples

s(“bd*8”).velocity(rand).filterHaps((h) => (h.whole.begin % 1) < h.value.velocity) const drums = s(“bd sd bd sd”) drums.filterValues((v) => v.s === ‘bd’) // kick only

Assessment

Write a filterHaps call keeping only events that start in the first half of each cycle, then say whether the same rule can be written with filterValues and why.

“Returns a new Pattern, which only returns haps that meet the given test.”
corpus · strudel-internals-pattern-as-function-of-time-functor-applic · chunk 1