Find and replace/transform/randomize in llll

Discussions, advice, bug reports and much more about the "bach" environment.
Post Reply
chrischandler
Posts: 11
Joined: Mon Oct 21, 2019 12:53 am

Find and replace/transform/randomize in llll

Post by chrischandler » Mon Oct 21, 2019 2:03 am

Hello!

I'm looking for the most efficient way to "find and replace" within an IIII, and I'm hoping for some direction. As an example, with the IIII below, I'd like to run it through a series of bach objects that find certain keywords and then processes the data accordingly.

voices ( 1 ( amp ( range 0.5 1. ) ) ( buffers ( rand sound1 sound2 ) ) ( durations ( wrand 4n 8n 2n ( weights 8 1 1) ( filter_mode rh ) ) ) ) ( 2 ( durations ( range 100 1000 ) ) ( amp ( range 0.4 1. ) ) ( buffers ( seq sound3 sound4 sound5 ) ) )

For instance, with amp ( range 0.5 1.0 ), perhaps bach.find would locate the range keyword and then pass along to another set of bach objects that randomly selects between 0.5 and 1. Or, the keyword durations is found and a weighted random value is chosen from ( wrand 4n 8n 2n ) and filtered from rhythm ( 4n ) to milliseconds ( 1000 ). A list of calculated values from the above list might look like:

voices ( 1 ( amp 0.9 ) ( buffers sound2 ) ( durations 1000 ) ) ( 2 ( durations 657 ) ( amp 0.8 ) ( buffers sound3) )

I'm aware of objects like bach.find, bach.random, bach.wrandom, and bach.replace. Am I right in thinking that these sorts of objects plus the lambda behavior will be what's needed to do this? I have this sense that this is so, but am still learning how lambda works. Is there a more efficient way to do this besides a series of bach.find objects with lambda operations for the randomizing/choosing/etc?

Thanks for any info.

Chris

danieleghisi
Site Admin
Posts: 1347
Joined: Fri Dec 03, 2010 1:25 pm

Re: Find and replace/transform/randomize in llll

Post by danieleghisi » Mon Oct 21, 2019 3:20 pm

Hi Chris,

One way is to do that "by hand", as you probably already do (bach.find, bach.keys, bach.locate, etc.). However, your best bet is to use bach.eval, with the brand new feature of key retrieving (e.g. $l1.'amp') and key replacing (e.g. $l1.'amp' = $l1.'whatever' + 20). I think this feature is currently in a Patron pre-release, otherwise you can wait for the official release, and it'll have that feature.

Maybe in the future we'll have a [bach.keyreplace] module, but to be honest bach.eval is so much handier!
Daniele

chrischandler
Posts: 11
Joined: Mon Oct 21, 2019 12:53 am

Re: Find and replace/transform/randomize in llll

Post by chrischandler » Thu Oct 24, 2019 1:39 am

Hi Daniele,

Thanks so much for the quick response. I've just signed up for Patron and am reading about bach.eval. Wow! Super powerful- a scripting language is going to make many tasks easier. Looking forward to digging in!

Post Reply