RUBY - XY Surface

For general discussion related FlowStone
Rocko
Posts: 186
Joined: Tue May 15, 2012 12:42 pm

Re: RUBY - XY Surface

Post 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 ?
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: RUBY - XY Surface

Post 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.
"There lies the dog buried" (German saying translated literally)
billv
Posts: 1165
Joined: Tue Aug 31, 2010 3:34 pm
Location: Australia
Contact:

Re: RUBY - XY Surface

Post 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
Rocko
Posts: 186
Joined: Tue May 15, 2012 12:42 pm

Re: RUBY - XY Surface

Post by Rocko »

Hi,

Your help to offer is really appreciated. Here is my code for your reference.
Attachments
XY_Test_v4.fsm
(1.44 KiB) Downloaded 1156 times
RJHollins
Posts: 1573
Joined: Thu Mar 08, 2012 7:58 pm

Re: RUBY - XY Surface

Post 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.
Rocko
Posts: 186
Joined: Tue May 15, 2012 12:42 pm

Re: RUBY - XY Surface

Post 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.
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: RUBY - XY Surface

Post 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.
Attachments
XY_Test_v4 [tula].fsm
(1.45 KiB) Downloaded 1131 times
"There lies the dog buried" (German saying translated literally)
Rocko
Posts: 186
Joined: Tue May 15, 2012 12:42 pm

Re: RUBY - XY Surface

Post by Rocko »

Hi,

This is working great and now better understood. Appreciated :D :D

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)?
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: RUBY - XY Surface

Post 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
"There lies the dog buried" (German saying translated literally)
clemensweinhold
Posts: 2
Joined: Wed Apr 08, 2015 7:06 pm

Re: RUBY - XY Surface

Post by clemensweinhold »

Does somebody know how to make a loop in ruby for multiple objects?
Post Reply