Page 1 of 3

Ruby for noobs!

Posted: Sun Jan 06, 2013 4:22 pm
by Jay
Hi guys

I am a completely lost soul when it comes to ruby but i would like to try out scripts that other people have made available on the net! trouble is i have not the slightest clue as to how we use them or prep them for use in FlowStone and Im sure there will be more like me!

I have tried pasting a few into the ruby box but Im lost on how we set up the data ins and outs to use the scripts

Is there any chance one of you more learned fellows could rattle together a little tutorial on this subject? any pointers would be really really appreciated :D

Best Regards Jay

Re: Ruby for noobs!

Posted: Sun Jan 06, 2013 6:01 pm
by pall
For some time I kept getting ready to start such a subject. I think most users SM did not have to do with some programming language. Or even if they had not sufficiently mastered for various reasons.
When I chose SynthMaker I liked that I could do many things without being forced to write a line of code.
Now I really want to do more, but existing tutorials are not enough. For that I suggest that those who know the language well, they give us simple examples with more detailed comments (if possible) at regular intervals. :)
I think this would be the benefit of all.

Thank You!

Re: Ruby for noobs!

Posted: Sat Jan 19, 2013 11:24 am
by pall
Let's learn together Ruby. :) I think it's better to start from the bottom level.
Here is a customizable RoundRectangle. I do not know how accurate it is, therefore please those advanced in ruby, come with corrections.
I think we can learn a lot from each other.

Re: Ruby for noobs!

Posted: Sat Jan 19, 2013 10:58 pm
by Nubeat7
here it is with outline, you can turn outline and back to on or off and you can set the outline to inset or center, everything is customizeable in the properties...

Re: Ruby for noobs!

Posted: Sun Jan 20, 2013 9:54 am
by pall
Hi Nubeat!
I'm glad you're here.
I am very curious if mouse pointer can be applied to RoundRectangle in the same form.
In green primitives be able only square areas.
Cheers!

Re: Ruby for noobs!

Posted: Sun Jan 20, 2013 12:35 pm
by Nubeat7
do you mean the different cursors? its shown in this example how to drag your shape around and how to choose another cursor...

Re: Ruby for noobs!

Posted: Sun Jan 20, 2013 9:10 pm
by Nubeat7
ok, while playing with this ihad the idea to do a x/y pad from it, it seems it is working ok but i have the problem that the cursor is not over the middle of the shape which makes it not very comfortable when changing the position ?? someone could fix this? - i couldn`t find the way to do it right.. and also the load and save state should be done! i was wondering why this

Code: Select all

def saveState
  [@valx,@valy]
end
def loadState
  @valx,@valy = v
end

after reloading the project i get an error message that loadState is wrong arguments 1 from 0??
anyway i`m not sure if the load and save states that important in this case, i just thuoght because it is also inside the sliders and knobs...

Re: Ruby for noobs!

Posted: Mon Jan 21, 2013 8:41 am
by pall
A suggestion Nubeat...
The main objective for this window (X / Y pad) is to get the correct visual effect. If the output is not correct value, it can be solved with green, or with another ruby.
But maybe I'm wrong? ;)

Re: Ruby for noobs!

Posted: Mon Jan 21, 2013 11:03 am
by trogluddite
Maybe this is more like you are after?
roundrectangle_xy Absolute.fsm
(1.72 KiB) Downloaded 1621 times

I've just changed the mouseLDown and mouseMoveCaptured methods. Previously, they were using the technique used for knobs - finding out how much the cursor has moved, times sensitivity, then adding that to the current position.
Because you want the object to "stick" to the cursor in this case, it's simpler to just take the absolute value of the cursor position and just scale it by the window size - the object will then stick to the cursor regardless of the window size.

I also slightly edited the 'handle' size variables 'h' and 'w' by putting ".0" after the numbers. That might seem strange, but you need that sometimes to make Ruby realise that you want a float value. Without a decimal point there, it assumes you want an integer; 'h/2' and 'w/2' would then have an integer on both sides of the divide, and Ruby would do an integer divide with an integer answer - which for an odd number would be wrong by 0.5.
You can also force an integer to be treated as a float using the '.to_f' method...

Code: Select all

myInteger = 10
myFloat = myInteger.to_f

...but in the case of static values, just adding the '.0' is much simpler and more efficient.

Nubeat7 wrote:after reloading the project i get an error message that loadState is wrong arguments 1 from 0??

You just need to add one letter!
The missing argument is for loadState - the value 'v' used in the variable assignment represents the loaded data, which is fed automatically to the method by FS when it loads. So all that's needed is to declare 'v' as an argument to the method on the 'def' line, so that FS has somewhere to put the data...

Code: Select all

def loadState v
# Get your values out of v
end


Aside from those little glitches it's looking very good - another useful addition to our new FS arsenal of goodies! :)

Re: Ruby for noobs!

Posted: Mon Jan 21, 2013 6:12 pm
by Nubeat7
thanks trog for your improvements!

w,h = getViewSize was doing the trick! thats smart, i tried it yesterday to get this variables into the mouseparts... thats ruby - i always wondering how easy it is at the end :lol:

...is the load and save state needful in this example to work correct with a presetmanager?