Callbacks in Ruby?

For general discussion related FlowStone
Exo
Posts: 426
Joined: Wed Aug 04, 2010 8:58 pm
Location: UK
Contact:

Re: Callbacks in Ruby?

Post by Exo »

MyCo wrote:I'm a bit concerned though... When I remember correctly, classes are shared between the plugins as well :twisted:

See Attachment


Yes this is concerning!

What will happen if there is a clash in class names?

If I declare class "Foo" and then someone else in their plugin has declared the same class, what happens?

Would one be completely overridden, ignored or modified?

If it would just be modified (adding new methods) then everything would seemingly be fine unless someone declares a method or class variable with same name. Which is very likely in the case of the class name being the same, because it will probably be doing a similar or same thing.

So it seems much more important now to declare classes in their own name space to avoid conflicts.
Flowstone Guru. Blog and download site for Flowstone.
Best VST Plugins. Initial Audio.
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: Callbacks in Ruby?

Post by Nubeat7 »

fs 3.03 changelog:

"The ruby dll no longer needs to be distributed with exported plugins because we now link it directly with our code. As a result of this each plugin now has its own Ruby interpreter, no more worrying about potential conflicts with other people's plugins."

shouldn't this be same for having more instances of the same plugin?
User avatar
MyCo
Posts: 718
Joined: Tue Jul 13, 2010 12:33 pm
Location: Germany
Contact:

Re: Callbacks in Ruby?

Post by MyCo »

Just checked it. The same DLL loaded twice share the same interpreter. When you copy the DLL file and load the original and the copy, they don't share the interpreter.
That's just because DLLs are loaded by the host only once into memory, and the ruby interpreter get's initialized on DLL load. So any DLL has its own interpreter, but instances of the VST in the DLL share the same interpreter.
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: Callbacks in Ruby?

Post by Nubeat7 »

thx for clearing this myco
Exo
Posts: 426
Joined: Wed Aug 04, 2010 8:58 pm
Location: UK
Contact:

Re: Callbacks in Ruby?

Post by Exo »

Ah I thought we was talking about ALL plugins not just instances of the same one.

This then is much less of an issue for me, as long as we know globals are shared amongst instances we can write code accordingly.

I have not looked at your example yet MyCo but I think the best solution then for a callback system is the original one I proposed. It is simple and doesn't rely on any global variables.

Global variables could be used for a callback system where we want to tell instances to update themselves with a change from another instance. I can think of some use in that.
Flowstone Guru. Blog and download site for Flowstone.
Best VST Plugins. Initial Audio.
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Callbacks in Ruby?

Post by tulamide »

Exo wrote:Ah I thought we was talking about ALL plugins not just instances of the same one.

Me too :D
"There lies the dog buried" (German saying translated literally)
Exo
Posts: 426
Joined: Wed Aug 04, 2010 8:58 pm
Location: UK
Contact:

Re: Callbacks in Ruby?

Post by Exo »

I have come up with yet another solution :)

New Callback.fsm
(1.6 KiB) Downloaded 919 times


This one doesn't use global variables but relies on wireless links. This I think is the ideal solution, the callback method can only be called from the same level or below. If you wanted to call it from above to below then I actual think just using wireless links is more appropriate .

The benefit also of using a wireless link is "Follow wireless" feature in menu. Now it is easy to find where the callback is called!

I also decoupled the class declaration from the implementation of the callback. Now the data is passed seamlessly to the outputs. When calling "actionPerformed" we pass an Event object which contains the output name and the data, also we pass a reference to the object (ie RubyEdit, but could be any object). With this "source" object we can then call any methods that belong to it. I currently don't make use of "source" object but we can override the actionPerformed method when we create the class. We can then "callback" into the source object to get any extra data we might need.

This method is very generic, safe (no globals) and can seamlessly pass any type of data! Just set up your outputs with names and then send the Event with that name.

We can also easily create new callbacks without having to define brand new callback classes. The previous methods meant that you couldn't have more than one without duplicating code and creating basically the same class but with a slightly different name.
Flowstone Guru. Blog and download site for Flowstone.
Best VST Plugins. Initial Audio.
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Callbacks in Ruby?

Post by tulamide »

A solid, not harming solution. Most generic ones to date. Thanks for them!
"There lies the dog buried" (German saying translated literally)
Exo
Posts: 426
Joined: Wed Aug 04, 2010 8:58 pm
Location: UK
Contact:

Re: Callbacks in Ruby?

Post by Exo »

I made an improvement, now new callbacks can be made and called with any number of inputs and data types without writing a single line of code! 8-)

New Callback 2.fsm
(1.59 KiB) Downloaded 943 times


All you have to do is make sure that you name the inputs and the outputs the same and everything will work.

I get the name of the input, pass it along with the Event and then use the input name to send to the output. So as long as these names match it works without modifying any code , no ugly if/elsif statements like in previous example. :)
Flowstone Guru. Blog and download site for Flowstone.
Best VST Plugins. Initial Audio.
User avatar
Walter Sommerfeld
Posts: 250
Joined: Wed Jul 14, 2010 6:00 pm
Location: HH - Made in Germany
Contact:

Re: Callbacks in Ruby?

Post by Walter Sommerfeld »

That's awesome Exo...!

Ruby at its best: one line of code and it works :D

Keep on doing!
Walter

P.S.: I tried it also with a bitmap: works like a charm
Post Reply