Page 1 of 1

How can I make persistent ruby data within plugin?

Posted: Tue Nov 10, 2015 11:11 am
by Nowhk
Hi,

I create an array and I randomize its value using a ruby function:

Code: Select all

def init
   @lfo_size = 100
   @lfo_shape_1 = Array.new @lfo_size
end

def event i, v
   if (i == "start")
        # somethings
   elsif (i == "random")
        randomLFOs
   end
end

def randomLFOs
   for i in 0..@lfo_size
      @lfo_shape_1[i]=rand(100)
   end
end

Once I create it, I'd like that every time I edit ruby script (recompile) or I close/reopen the project/plugin, the array stay persistent. So I work on the same values every time.

Once I re-random it, it recreate the array and store the new one. How this is possible in ruby? In Kontakt scripting for example I use make_persistent(myArray).

Is there somethings similar in FlowStone?
Thanks!

Re: How can I make persistent ruby data within plugin?

Posted: Wed Nov 11, 2015 2:16 am
by KG_is_back
You can use saveState and loadState methods to store values. it is described in the manual. However, I'm not sure if it will do what you are looking for

Re: How can I make persistent ruby data within plugin?

Posted: Wed Nov 11, 2015 12:49 pm
by Nowhk
KG_is_back wrote:You can use saveState and loadState methods to store values. it is described in the manual. However, I'm not sure if it will do what you are looking for

Uhm yeah, it seems to works pretty nice:

Code: Select all

def loadState v
   @lfo_shape_1, @lfo_shape_2 = v
end

def saveState
   [@lfo_shape_1, @lfo_shape_2]
end

Why it shouldn't works? Thank you!