How can I make persistent ruby data within plugin?

For general discussion related FlowStone
Post Reply
Nowhk
Posts: 275
Joined: Mon Oct 27, 2014 6:45 pm

How can I make persistent ruby data within plugin?

Post 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!
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

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

Post 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
Nowhk
Posts: 275
Joined: Mon Oct 27, 2014 6:45 pm

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

Post 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!
Post Reply