Dynamic methodsmade from a loop

I’ve been getting deeper into Ruby thanks to Sonic Pi. I’ve been exploring the use of Hashes & keeping “lists of properties” for specific chPreformatted textannels (to be controlled by my Korg nanoKontrol2 midi input. )

I had an idea to “assign” certain “with_fx” + params to specific channels.
my problem is, I don’t know how to iterate through a list of potential FX, THEN play the sample “inside” a nested load of FX…

I had tried a repeat loop, but, the way I wrote it, means that when I set up a new “with_fx” it plays “the channel sample” each time. So, if a channel has 3 FX, it makes 3 “with_fx” containers, but plays the sample “inside” each time. (which lead to lags & FX not quite being applied as they should sound. )

My thought : can you create a “dynamic method” that can “compile” a bunch of FX, then play the sample after all the “with_fx” have been defined?

is it possible?

1 Like

Could you add three backticks between your code to make it more readable ?
Thanks and sorry no answer for your main question.

I don’t know what that is! (how do I “backTick” ? )… probably missed a “read this first”… I am a n00b , apologies. I did take a screen dump of the code & replace it above, if that helps?

1 Like

Hi @philAwesomeTech,

that’s no problem: See here what a backtick is. Three of these in a separate line before and after your code example will nicely formate and color the code and make it thus much better readable. See also Sam’s remark about formatting (scroll down the page for the headline code blocks).

Hello again!
well… I finally found what I was looking for… I can concat a string in order to make a sample be “surrounded” by as many fx as you (and the memory) want… then simply use “eval(string)”

I even found out you can pass some params for the fx & refer to a function in the string too… fantastic.

define :getSamp do
  return [:bd_boom, :bd_808, :bd_hause, :bd_ada].sample

dParams = {amp: 2, distort: 0.9, mix: 1}
rParams = {damp: 0.2, room: 0.3, mix: 0.9}

fxString = "with_fx :distortion, dParams do with_fx :reverb, rParams do with_fx :ping_pong do sample getSamp() end end end"

live_loop :pip do
  sleep 1

if there’s a more elegant way to do all this, let me know! but, I’m super chuffed I found a way of “nesting FX on the fly” to surround a sample…

1 Like