Old 05-21-2017, 04:43 PM   #1
Airal
Banned
 
Join Date: Nov 2015
Posts: 406
Default Lua for Effect

Is it possible to be able to get the ability to use Lua to write FX's similar JS? Seems like it would not be too difficult since Lua already has been set up to deal with graphics and API so the only difficulty would be passing the audio data, which is not difficult at all.

e.g., A Lua FX could be defined in such a way that all it must do is contain a certain function that is called for each data block that needs to be processed(similar to a VST, but not as complex since we don't need all the capabilities that a VST offers(else we would write a VST instead)).


e.g.,

MyLuaFX.luaFX

...

function ProcessBlock(Channels, Data)
... Reaper calls this function to process the audio data
end

...



The only issue would be speed but since Lua is fast and everything can be compiled down it should be quite fast(relatively speaking)?

This would allow one to create a much more powerful FX since we could then have access to the API and all that. It would be great for making complex VST like effects that extend beyond just an audio processor and would also allow one to quickly test audio processing ideas rather than having to write a full blown VST and deal with all that.
Airal is offline   Reply With Quote
Old 05-21-2017, 06:31 PM   #2
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

My understanding is that unfortunately there are issues with Lua when using it for stuff like realtime audio processing. I think it has to do with how it is a garbage collected language. The collection may trigger at unpredictable times and cause the audio thread to block and cause a glitch...Perhaps in theory the Lua scripts could be written in a style that minimizes the amount of garbage collection needed but then the code would probably start resembling that yucky Eel/JesuSonic code...

In any case, there in fact already is a plugin that allows writing Lua code, called ProtoPlug. I myself dropped looking further into that because it apparently doesn't run on 64 bit OS-X. I don't recall right now how that deals with the garbage collection issue. Perhaps the Lua variant (LuaJit) it is using, avoids some of those issues in some manner.

By the way, the reason JesuSonic doesn't support calling the Reaper API functions is that Cockos wanted it to work like that. There's no technical reason as such for it to not work. (ReaScript scripts can be written in the Eel language too...) It's just generally a bad idea to allow complicated API calls from realtime audio thread type contexts.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 05-21-2017, 09:22 PM   #3
Airal
Banned
 
Join Date: Nov 2015
Posts: 406
Default

The main problem I have with JS is its awful syntax. I've programmed in 20+ languages and it's syntax is the most odd looking I've seen.

It probably wouldn't be all that bad but the editor is horrendous. Like to use shift-ins to paste and all that ends up doing is toggling ins and I end up overwriting text unexpectedly. It has other weird behavior that makes me queasy using it. In fact I use notepad++ to edit scripts since that at least is more sane even though it is a hassle to switch back and forth.

As far as the Lua issue, I'm sure it could be worked around. Assuming decent performance could be had in the ideal case(which I believe it could be since Lua is supposedly one of the fastest scripting languages out), then it's worth trying as I'm sure the major issues in performance could be minimized.

http://www.lua.org/manual/5.1/manual.html#2.10

It seems that Lua has manual memory management and I doubt it will be an issue with the processing function since it shouldn't be allocating anyways.

So, all that would really need to be done is for the processor to be ran in a different thread/process that the garbage collector. In that case, the only issue is accessing memory... which could be done by passing a context pointer or some ingenious tricks(e.g., use some page mappings to duplicate the memory space of the script and run the audio processor in it).

I'll try out the protoplug. While it is nice in general, having reaper sort of have that built in with access to the API would be much better. (e.g., for graphics, input, etc)

[Edit: tried protoplug and it crashed reaper when trying on of the filter examples. Some worked though]
Airal is offline   Reply With Quote
Old 05-21-2017, 10:04 PM   #4
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,690
Default

Quote:
Originally Posted by Airal View Post
The main problem I have with JS is its awful syntax. I've programmed in 20+ languages and it's syntax is the most odd looking I've seen.
While of course the EEL language is not "common" or "mainstream", and it does have it's specific learning curve, I don't think it is "more awful" than other computer languages (I do know lots of them), but just rather "basic" and especially tweaked for the job at hand.

The JSFXes in EEL run extremely fast with audio samples. Seeming astonishingly close to doing VSTs in C. I doubt that a system using a more common language such as LUA or Python (or e.g. Java Script) syntax could come close.

So if you don't like EEL, you always can use C (many IDEs available) to do your plugins as VSTs. I even once successfully tested a way to do VSTs in (Delphi-) Pascal.

In fact, I, too, would like to use "shift-ins to paste", but I use several other systems that don't allow for this, so I never complained, even though I think it would be an easy to do feature request.

-Michael

Last edited by mschnell; 05-23-2017 at 11:09 PM.
mschnell is offline   Reply With Quote
Old 05-24-2017, 12:04 PM   #5
snooks
Banned
 
Join Date: Sep 2015
Posts: 1,650
Default

I wouldn't argue against having LuaJIT for JSFX, but at the same time I think that having API calls in a separate section within JSFX, like @gfx, would be the biggie. At the moment, scripts can probe custom JSFX for parameter changes and get info from them that way, but having direct calls from the JSFX would be better.
snooks is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 08:45 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.