is it possible to somehow factor out the .s("saw, sine").lpf(200) part into another function, called something like mybass or similar? Essentially I'd like to be able to do something like this:
note("...").mybass( // ...more effects if I want to
Just looking at the expressions, and without any knowledge of internals, I expect that you could add the method mybass to (what I expect to be) the prototype/class of strudel objects
// I guess strudel has something like
base = { foo(x) { this.f = x; return this } , bar(x) { this.b = x; return this } }
// that can be used like
ob = { __proto__ : base }
ob.foo(1).bar(2) // result: { f: 1, b: 2 }
// your function
base.my = function () {return this.foo(3).bar(4)}
// use it
ob.my() // result: { f: 3, b: 4 }
// and you can combine it
ob.my().bar(0) // result { f: 3, b: 0 }
in reality, types will be different (not numeric), but since JS has no (static) types, it should still work. Does it?
I was considering something similar, but I wanted to ask here first in case there was a less hacky way to do it.
This is what I did to do what I said in the OP:
const patproto = silence.__proto__;
patproto.mybass = function() { return this.s("saw, sine").lpf(200); };
// I use it like this
note("c d e f").mybass()
This option works and isn't that hard, but if you aren't careful with the name you give your custom functions you can get in trouble. For example if a future version of strudel gets a mybass function my code would clobber it which could have unexpected consequences.
Would the developers of strudel be interested in having a standard way for users to make their own chain functions? Perhaps something like this:
adduserfunc("mybass", function() { return this.s("saw, sine").lpf(200); });
note("c a f e").user("mybass");