Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Ruby for noobs!

Post any examples or modules that you want to share here

Ruby for noobs!

Postby Jay » Sun Jan 06, 2013 4:22 pm

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
Jay
 
Posts: 276
Joined: Tue Jul 13, 2010 5:42 pm

Re: Ruby for noobs!

Postby pall » Sun Jan 06, 2013 6:01 pm

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!
pall
 
Posts: 31
Joined: Thu Dec 09, 2010 1:27 pm
Location: Transilvania

Re: Ruby for noobs!

Postby pall » Sat Jan 19, 2013 11:24 am

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.
Attachments
roundrectangle 01.fsm
correction in prop. pannel
(720 Bytes) Downloaded 1370 times
pall
 
Posts: 31
Joined: Thu Dec 09, 2010 1:27 pm
Location: Transilvania

Re: Ruby for noobs!

Postby Nubeat7 » Sat Jan 19, 2013 10:58 pm

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...
Attachments
roundrectangle 02.fsm
(1.15 KiB) Downloaded 1391 times
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: Ruby for noobs!

Postby pall » Sun Jan 20, 2013 9:54 am

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!
Attachments
roundrectangle 03.fsm
(1.67 KiB) Downloaded 1346 times
pall
 
Posts: 31
Joined: Thu Dec 09, 2010 1:27 pm
Location: Transilvania

Re: Ruby for noobs!

Postby Nubeat7 » Sun Jan 20, 2013 12:35 pm

do you mean the different cursors? its shown in this example how to drag your shape around and how to choose another cursor...
Attachments
roundrectangle 04.fsm
(1.4 KiB) Downloaded 1361 times
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: Ruby for noobs!

Postby Nubeat7 » Sun Jan 20, 2013 9:10 pm

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...
Attachments
roundrectangle_xy.fsm
(1.76 KiB) Downloaded 1367 times
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Re: Ruby for noobs!

Postby pall » Mon Jan 21, 2013 8:41 am

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? ;)
Attachments
roundrectangle_xy 01.fsm
(5.71 KiB) Downloaded 1363 times
pall
 
Posts: 31
Joined: Thu Dec 09, 2010 1:27 pm
Location: Transilvania

Re: Ruby for noobs!

Postby trogluddite » Mon Jan 21, 2013 11:03 am

Maybe this is more like you are after?
roundrectangle_xy Absolute.fsm
(1.72 KiB) Downloaded 1435 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! :)
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Ruby for noobs!

Postby Nubeat7 » Mon Jan 21, 2013 6:12 pm

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?
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

Next

Return to User Examples

Who is online

Users browsing this forum: No registered users and 43 guests