Page 2 of 3
Re: RUBY - XY Surface
Posted: Wed Feb 10, 2016 3:43 pm
by Rocko
Appreciated...
I had changed the variables to lower case... But still doesn't work.
I noticed that this works:
@sx=getViewSize;
But this doesn't:
@sx=getViewSize[0];
Why can;t I assign @sx to be a single variable out of an array ?
Re: RUBY - XY Surface
Posted: Wed Feb 10, 2016 10:24 pm
by tulamide
You can assign a single variable from an array, and it is done just as you tried it. If it doesn't work it could mean you previously used the same variable for an array. However, wild guessing won't help you. Prepare a schematic that shows your issue, so that we can have a look. I wouldn't know how else to help.
Re: RUBY - XY Surface
Posted: Thu Feb 11, 2016 2:41 am
by billv
In your fsm Rocko, there's a redraw in the draw section.
I think it also helps to define the @vw and @vh in the draw section.
For eg: This works fine...
Code: Select all
def isInMousePoint x,y
true
end
def mouseLDown x,y
captureMouse
end
def mouseMoveCaptured x,y
if x > @vw then output 0, x = @vw end
if x < 0 then output 0, x = 0 end
if y > @vh then output 1, y = @vh end
if y < 0 then output 1, y = 0 end
output 0, @x=x
output 1, @y=y
redraw
end
def mouseLUp x,y
releaseMouse
end
def draw v
@vh = v.height-1
@vw = v.width-1
pen = Brush.new @c1,0.2
v. drawEllipse pen,[@x,@y,1,1]
end
Re: RUBY - XY Surface
Posted: Thu Feb 11, 2016 11:12 am
by Rocko
Hi,
Your help to offer is really appreciated. Here is my code for your reference.
Re: RUBY - XY Surface
Posted: Thu Feb 11, 2016 11:41 am
by RJHollins
hmm ... Now I've lost track ... Is there still a problem ???
Seems to work as expected here.
The only thing I suggest ... if the window is re-sized, everything recalculates and places the 'select ball' in field.
Re: RUBY - XY Surface
Posted: Thu Feb 11, 2016 11:59 am
by Rocko
Hi,
Notice this line with the '#' mark:
#@sx=getViewSize[0]; //This is the problematic line
If you remove the # to make it active. Then restart the FSM, it doesn't start and reports an error.
Re: RUBY - XY Surface
Posted: Thu Feb 11, 2016 12:58 pm
by tulamide
Hey Rocko,
this fix should work. It was like I said, you try to access the view before it is initialized. Another tip: always use methods, don't just declare variables somewhere in the RubyEdit. The right place for this is a method called init. In this case a variation is used: Instead of initializing the vars at init of the RubyEdit, I use an afterload trigger to run another method (you can name this method as you see fit). This way I make sure that the view already exists before you access it via getViewSize.
Re: RUBY - XY Surface
Posted: Thu Feb 11, 2016 1:40 pm
by Rocko
Hi,
This is working great and now better understood. Appreciated

Currently @cx and @cy are initialized after load. This might contradict saving it in 'flowstones preset' (which I usually use to save VST data like knob and slider values).
Any hints on how to save @cx and @cy from last read - on DAW (like preset auto save mode)?
Re: RUBY - XY Surface
Posted: Thu Feb 11, 2016 2:06 pm
by tulamide
If you use this method:
Code: Select all
def init
#initialize @cx/@cy here
end
the variables will be initialized when the RubyEdit is initialized. They can then be easily overwritten by an input from the preset manager (presets update after load). You do that by extending the already existing event method:
Code: Select all
#assuming there are two inputs named px and py that are sent from the preset
def event i, v
if i == 'px'
@cx = v
redraw
elsif i == 'py'
@cy = v
redraw
end
end
Re: RUBY - XY Surface
Posted: Thu Feb 11, 2016 6:40 pm
by clemensweinhold
Does somebody know how to make a loop in ruby for multiple objects?