Old 06-07-2008, 08:37 PM   #1
toddhisattva
Human being with feelings
 
toddhisattva's Avatar
 
Join Date: Jun 2008
Location: Austin
Posts: 242
Default ReaLua PoC

This is a Proof of Concept release of ReaLua, a Lua interpreter you run from Reaper. It should be considered dangerously untested.

I have made a first pass at exposing some of the Reaper C API, so you can actually do some calls into Reaper from Lua.

Oh dadgummit I forgot to change the key, it still uses ALT-5 to open the console, which came from some code Xenakios (sp? credit wrong?) posted. So sorry. That will obviously change.

So, unfortunately, ALT-5 opens the Lua console.

UpdateTimeline,ClearAllRecArmed, MuteAllTracks,
TrackList_AdjustWindows, SoloAllTracks, BypassFxAllTracks,

Audio_IsRunning, Audio_IsPreBuffer, IsInRealTimeAudio,
GetMaxMidiInputs, GetMaxMidiOutputs,GetNumTracks,
GetMasterMuteSoloFlags,GetPlayState,Undo_DoRedo,
Undo_DoUndo,GetPlayPosition,GetPlayPosition2,
GetCursorPosition,GetHZoomLevel,

get_ini_file, GetExePath, Undo_CanUndo,
Undo_CanRedo

are exposed in the global namespace, the glue code is barely tested.

You need to do the ctrl-Z to exit Lua, if you use the close box you will also close Reaper. Oops. There is much work to be done, this release is just a proof of concept and will probably give you a bad day if you try anything serious.

You cannot use Reaper while the Lua console is open.

There is no persistence between invocations of the Lua console.

But you can load Lua programs and so on. You can use arrow keys to recall previous actions, edit them, and all that good console stuff. Don't get used to that, it may go away, but it's there now.

Enjoy!

Last edited by toddhisattva; 06-10-2008 at 03:38 PM.
toddhisattva is offline   Reply With Quote
Old 06-08-2008, 08:17 AM   #2
Christophe
Immortal
 
Christophe's Avatar
 
Join Date: Jan 2005
Location: Sucka Free
Posts: 250
Default

Having LUA as a Reaper script interpreter is a great idea!
Christophe is offline   Reply With Quote
Old 06-08-2008, 08:18 AM   #3
drew
Mobile
 
drew's Avatar
 
Join Date: Jan 2006
Location: London & São Paulo. Hardcore commercial REAPERite
Posts: 1,627
Default

Yeah - just waiting for Keyman Sam to show up to approve the name!
__________________
Proudly using REAPER exclusively for professional music production at Qsonics.com and recording broadcast and narrative voiceovers at DrewWhite.com.
drew is offline   Reply With Quote
Old 06-08-2008, 08:21 AM   #4
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 6,497
Default

Wow, interesting work. But would be lot's more useful with the GetSetMedia...()-functions exposed to Lua in some way...Do you have any plans on including those or releasing the source code so those could be included? Probably with some more "nicer" wrapper-functions, because you call for example GetSetMediaItemInfo() something like this from C++ :

To get item's length :

double ItemLen=*(double*)GetSetMediaItemInfo(PointerToRea perItem,"D_LENGTH",NULL);

To set item's time position :

double NewPosition=2.5;
GetSetMediaItemInfo(PointerToReaperItem,"D_POSITIO N",&NewPosition);

(The item time position property also has some additional problems about the item order indexes internally kept in Reaper, that should be handled as a separate case...SWS gave me a working solution to that, so that is covered.)

So, the Lua wrapper should give more easier access to the items etc (handle safely the stuff with pointers to the items and their takes) and wrap all the "D_LENGTH", "D_POSITION", "B_UISEL" etc stuff into separate functions/methods to get and set item/take/send/track properties...
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass and λ) :
http://xenakios.wordpress.com/
Xenakios is online now   Reply With Quote
Old 06-08-2008, 08:57 AM   #5
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 6,497
Default

Ok, now tested the plugin, seems to give sensible results given the current limitations. By the way, to anyone who is going to test this, to exit the Lua interpreter window press ctrl+z and then enter, ctrl+c will close both the cmdline and Reaper itself, beware of that!

Thanks a lot for your work toddhisattva! I hope this will expand and get more user-friendly eventually!
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass and λ) :
http://xenakios.wordpress.com/
Xenakios is online now   Reply With Quote
Old 06-08-2008, 01:43 PM   #6
Dewdman42
Human being with feelings
 
Join Date: Nov 2007
Posts: 19
Default

I was wondering when someone was gonna do this. Good call. It will be intersting to see this develop.
Dewdman42 is offline   Reply With Quote
Old 06-08-2008, 05:33 PM   #7
NAS
Human being with feelings
 
NAS's Avatar
 
Join Date: Dec 2007
Location: In church, burning it down
Posts: 1,345
Default

Super coolness
I have spoken about this very idea with Xenakios a few times
Great work

NAS
__________________
Not Gods or Saints but HUMAN be
NAS is offline   Reply With Quote
Old 06-08-2008, 08:45 PM   #8
toddhisattva
Human being with feelings
 
toddhisattva's Avatar
 
Join Date: Jun 2008
Location: Austin
Posts: 242
Default You can sniff glue code!

Quote:
Originally Posted by Xenakios View Post
Wow, interesting work. But would be lot's more useful with the GetSetMedia...()-functions exposed to Lua in some way...Do you have any plans on including those or releasing the source code so those could be included? Probably with some more "nicer" wrapper-functions, because you call for example GetSetMediaItemInfo() something like this from C++ :

To get item's length :

double ItemLen=*(double*)GetSetMediaItemInfo(PointerToRea perItem,"D_LENGTH",NULL);

To set item's time position :

double NewPosition=2.5;
GetSetMediaItemInfo(PointerToReaperItem,"D_POSITIO N",&NewPosition);

(The item time position property also has some additional problems about the item order indexes internally kept in Reaper, that should be handled as a separate case...SWS gave me a working solution to that, so that is covered.)

So, the Lua wrapper should give more easier access to the items etc (handle safely the stuff with pointers to the items and their takes) and wrap all the "D_LENGTH", "D_POSITION", "B_UISEL" etc stuff into separate functions/methods to get and set item/take/send/track properties...
Thank you I will steal that soon!

The PoC's glue code was stuff I could do pretty mechanically, and is truly a first pass through the API hunting for low-hanging fruit.

I have made another pass through the API exposing more complicated stuff, that actually took a little thought. Now it is getting fun, with InsertMedia and MoveEditCursor.

Since PCM_sink etc. are pretty big, I think I'll first expose them as just userdatas that you can at least pass around. I'm unsure at the moment, maybe they'll be tables. Maybe somebody has a great idea I will steal.

My intention is to expose every bit of the API that I can test. Collecting ideas for a test suite along the way. I figure I'll know the API pretty well by the end ;-)

Right now the code is pretty ugly, and I haven't even changed the main file's name from the "import_m3u.cpp" that I started from! I broke the "release" configuration in the project, too.

But natchurlich, the code will be made available when it is presentable.

I don't think I have any control surfaces (my MIDI controller is an Ensoniq Mirage) so somebody else needs to at least test those parts ;-) I haven't even read about them in The Truly Excellent Manual.

Hmm, is there such thing as a software control surface?
toddhisattva is offline   Reply With Quote
Old 06-08-2008, 09:02 PM   #9
toddhisattva
Human being with feelings
 
toddhisattva's Avatar
 
Join Date: Jun 2008
Location: Austin
Posts: 242
Default Thanks for the Inspiration

Quote:
Originally Posted by Christophe View Post
Having LUA as a Reaper script interpreter is a great idea!
I was inspired by Tim SWS's ReaConsole and Myriad's MyrScript, the Lua-based scripting language of Harmony Assistant:

[LINK="http://myriad-online.com/"]Myriad Web Site[/LINK]

Well that didn't work but y'all know what I meant.

ReaConsole lit the spark - that little thing is cool. I find Harmony Assistant so damn awesome that doing Lua for a musical program needs no other reason than, "the Harmony Assistant guys think Lua is good for music, I shall fanboyishly mimic them."

Oh, and of course Reaper. Good golly. They're making a Mac version and still find the time to release the Extension SDK. Yikes in an inspiring kinda way!
toddhisattva is offline   Reply With Quote
Old 06-10-2008, 03:57 PM   #10
toddhisattva
Human being with feelings
 
toddhisattva's Avatar
 
Join Date: Jun 2008
Location: Austin
Posts: 242
Default ReaLua PoMC

Proof of More Concepts

The Lua interpreter now persists between Lua console invocations.

Everything has moved to a table referenced by the global named "reaper" so the global namespace is clean.

So, you can

for k,v in pairs(reaper) do print(k,v) end

to see what's there! Several dozens of functions and constants now.

We got some numeric constants for reaper.InsertMedia(), called reaper.InsertNew and so on. Also some flags.

There is even a singular string constant but I have not yet got to the API calls that need string constants.

If you do a

mt = reaper.CSurf_TrackFromID(1,true)

the "mt" is a light userdata that you can then pass to

mn = reaper.CSurf_TrackToID(mt,true)

Or the other track functions. Query them for FX, get FX names, get FX param names.

(About that "CSurf_" - in my previous message I meant "the IReaperControlSurface stuff" not "CSurf_" as there is a lot of non-control-surface stuff behind "CSurf_" names.)

I have tried to map the Reaper C API sensibly onto Lua's data types:

For instance, if there is somefunction(char *buf, int size) it gets passed a Lua string, or if it's somefunction(char *buf, int *size) then it returns a Lua string.

reaper.TrackFX_GetParam(mt,fx,param) returns a tuple (current,min,max)

and so on through the API.

Not taking requests yet, but always open to decent suggestions.

Haben Sie Fun y'all!

Last edited by toddhisattva; 06-17-2008 at 08:10 PM.
toddhisattva is offline   Reply With Quote
Old 06-11-2008, 02:42 AM   #11
goyya76
Human being with feelings
 
Join Date: Jun 2008
Posts: 10
Default

Quote:
Originally Posted by toddhisattva View Post
Or the other track functions. Query them for FX, get FX names, get FX param names.!
Quote:
Originally Posted by toddhisattva View Post
reaper.TrackFX_GetParam(mt,fx,param) returns a tuple (current,min,max)

and so on through the API.
Hi Todd...just out of curiosity: quering track functions means that you can access and modify them or just get their value into LuA console?

if the first option is the right one, maybe we'll be able to control lots of parameters via CCs (not only the ones through Mackie HUI emulation)??

(i hope it's not just day-dreaming...)

Ciao&thanks,

Goyya
goyya76 is offline   Reply With Quote
Old 06-11-2008, 10:08 AM   #12
toddhisattva
Human being with feelings
 
toddhisattva's Avatar
 
Join Date: Jun 2008
Location: Austin
Posts: 242
Default Workinonit

Quote:
Originally Posted by goyya76 View Post
Hi Todd...just out of curiosity: quering track functions means that you can access and modify them or just get their value into LuA console?

if the first option is the right one, maybe we'll be able to control lots of parameters via CCs (not only the ones through Mackie HUI emulation)??

(i hope it's not just day-dreaming...)

Ciao&thanks,

Goyya
As far as I can tell, you can at least set a track's automation mode already, maybe more (I just looked for functions beginning with the word "set" so... let Lua tell you if what you want is there:

for k,v in pairs(reaper) do print(k,v) end

You can get Track FX counts, get and set the FX'ses parameters, and do stuff with the values. I've only tested this with a few FX.

The project turned one week old yesterday. I ain't kidding myself about the amount of heavy lifting to be done, and am actively rettin up the code so the workload can be distributed without anybody getting ill. Accrochet toi to yer dreams and share them because goals are good.

I just logged on to read X-man's suggestion regarding the more complicated GetSetBlah() functions. They might be next. I am real tired today and am no good for detail work, but to read, perchance to dream, yadda!
toddhisattva is offline   Reply With Quote
Old 06-12-2008, 11:15 AM   #13
toddhisattva
Human being with feelings
 
toddhisattva's Avatar
 
Join Date: Jun 2008
Location: Austin
Posts: 242
Default The Key

Oh yeah I changed the key that starts it to ALT-0 (zero) and it's in the "Insert" menu for no good reason.

I am at this moment implementing GetSetHoogaBoogas().
toddhisattva is offline   Reply With Quote
Old 06-17-2008, 08:09 PM   #14
toddhisattva
Human being with feelings
 
toddhisattva's Avatar
 
Join Date: Jun 2008
Location: Austin
Posts: 242
Default PoC Exposure

Proof-of-Concept release 3: Exposure

Most of the C API is exposed, and some of the C++ classes can be passed around as typed userdata.

Especially of interest are the sub-tables which wrap the GetSetHoogaBoogas(), we have:

reaper.TrackInfo which wraps GetSetMediaTrackInfo() with breakout functions like

reaper.TrackInfo.GetName(mtp)

where mtp is from something like mtp = reaper.CSurf_TrackFromID(1,true)

and its Set-partner, TrackInfo.SetName(mtp, "Newname")

Likewise, the reaper.SendInfo subtable wraps the GetSetTrackSendInfo() function with Get and Set accessors.

And reaper.ItemInfo wraps GetSetMediaItemInfo() with accessors.

Finally for now, reaper.TakeInfo wraps GetSetMediaItemTakeInfo() in nice accessors.

You can do a print(mtp) to see the metatable-driven typing in action.

And those GetSetYaddaYaddas() are available which return void pointers in userdata, and take that type for the Set variant, if you need raw access.

I highly recommend using the

for k,v in pairs(reaper) do print(k,v) end

to see what's there, and do likewise on the subtables I mentioned. You will see all the string "constants" (not read-only yet) that can be used with the raw GetSetYaddaYadda() functions - and of course the functions that have been implemented.

Those subtables are sprouting with accessors, and I've even tested some of them ;-)

Last edited by toddhisattva; 07-16-2008 at 03:32 PM.
toddhisattva is offline   Reply With Quote
Old 06-25-2008, 11:30 AM   #15
toddhisattva
Human being with feelings
 
toddhisattva's Avatar
 
Join Date: Jun 2008
Location: Austin
Posts: 242
Default ReaLua "Pre-Alpha One" Release

Now it's getting somewhere. ~360 entry points and "constants."

Best changes:

1. The console now accepts multi-line chunks. The functions you make in interactive mode can have more than one line! (I think dofile() has always worked right like this.)

2. The console maintains persistence between invocations. Command history lasts until you exit Reaper.

3. Bugfixes and gluecode architecture improvements.

*Real Work* can be done in the ReaLua console. You can even set the prompts.

And there's a text file listing the functions in the main reaper table as well as their arguments and returns (in a Lua-C pidgin that I hope is easy to pick up). It is only approximately accurate, being nothing but boiled down code comments, but should cut down on the guessing (notice I'm calling it a "text file" because it is not yet "documentation!").

Minorer changes:

1. I've removed its silly place in the "Insert" menu and now it's only accessible by ALT-0 (zero).

2. Utility "reaper.Redraw()" added which sends an UPDATENOW (or whatever) to the main Reaper window, so you can see what yer doin!

3. The dreaded close button is disabled. Ctrl-C, and I think ctrl-break, are less catastrophic.

Download! Install! Enjoy! Try:

function dumpTrackFX()
for i=1, reaper.GetNumTracks() do
mtp = reaper.CSurf_TrackFromID(i,true)
print(reaper.TrackInfo.GetName(mtp))

for j=0, reaper.TrackFX_GetCount(mtp) do
b, n = reaper.TrackFX_GetFXName(mtp,j)
if b then print(n) end
end
end
end

(Where did the tabs go? Can anyone find the confounded tabs?)

Last edited by toddhisattva; 12-18-2008 at 03:11 PM.
toddhisattva is offline   Reply With Quote
Old 06-25-2008, 02:06 PM   #16
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 6,497
Default

Thank you for your work! I've been too busy with my own coding stuff, so haven't tested and commented on your ReaLua plugin, to keep myself concentrated.

It's too bad Lua doesn't have any GUI toolkit readily available...This kind of "all-text" mode scripting will scare most potential users away at first look. But maybe it can be made more user-friendly and visual at some point...
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass and λ) :
http://xenakios.wordpress.com/
Xenakios is online now   Reply With Quote
Old 06-26-2008, 05:14 AM   #17
goyya76
Human being with feelings
 
Join Date: Jun 2008
Posts: 10
Default

Quote:
Originally Posted by Xenakios View Post
It's too bad Lua doesn't have any GUI toolkit readily available...This kind of "all-text" mode scripting will scare most potential users away at first look. But maybe it can be made more user-friendly and visual at some point...


hi guys!

a quick one: there's lua console in the form of a VST fx (http://t-zec dot org/vstlua/), which allowes to create graphical elements - source code it's available...Maybe it can be useful?

take care,
goyya
goyya76 is offline   Reply With Quote
Old 07-03-2008, 02:01 PM   #18
toddhisattva
Human being with feelings
 
toddhisattva's Avatar
 
Join Date: Jun 2008
Location: Austin
Posts: 242
Default 2 X & G!

Hi y'all. Very many thanks for finding that source code for VSTLua.

I am very interested in replacing the "DOS"-like console with something else.

Because as I discovered a day or so after last week's release, pressing the F7 key for the command history in ReaLua Console *crashes my computer.* There are other less selfish reasons too.

I am having a fight with VC++ Express 08 compiling the ATL-based "Console" http://sourceforge.net/projects/console/ but I have not yet brought the red-handled fire axe into the room. It deserves a couple more tries at least!

VSTLua uses SDL-Console or its descendant oglconsole. I spent some time yesterday trying to get the nice and tiny oglconsole to compile with Microsoft's idea of OpenGL. It might be doable.

As to how GUI-ey ReaLua should get, well that's why I'm spending a couple days poking around wxLua.

Because I do not really forsee the possibility of Lua replacing C for Reaper plug-in development! Lua is so nice and tiny, it might be a shame to bloat it with GUI. My thinking on this is "if a task needs GUI then maybe ReaLua is not appropriate." There is always C++.

Analogously, it seems relatively few people use Lua for DSP (allow me to tease y'all that I am doing pcm_source:GetSamples() now and have retrieved samples from an MP3 file) and my guess is, "that's what C and Fortran and now Python are for."

Then again, I don't see it as my job to limit what people might want to do with ReaLua. <- That's such an odd idea I am glad I can blame it on dehydration. I go drink now.
toddhisattva is offline   Reply With Quote
Old 07-16-2008, 03:41 PM   #19
toddhisattva
Human being with feelings
 
toddhisattva's Avatar
 
Join Date: Jun 2008
Location: Austin
Posts: 242
Default ReaLua pre-Alpha 2

There are PCM_source PCM_sink midi_Input midi_Output classes that are made by the proper reaper.PCM_Source_CreateFromFile() and so on that you see in the main reaper table.

They are not completely implemented. But they can do some things, and there's a MIDI_eventlist class to pass around.

I am sure I have misinterpreted some of the arguments and usages.

psp = reaper.PCM_Source_CreateFromFile("TurnItOnEinMal.m p3")

Will make a PCM_source, which is a table, and can have its contents listed to see what its "methods" are.

psp:GetType()

And so on.

mip = reaper.CreateMIDIInput(1)

mip:start()
mip:RunPreNoteTracking(1)
mip:SwapBufs(0)
mel = mip:GetReadBuf()
print(mel:GetSize())

mel is a MIDI_eventlist.

I hope I have not broken too much stuff that worked before.

Enjoy!

Last edited by toddhisattva; 12-18-2008 at 03:11 PM.
toddhisattva is offline   Reply With Quote
Old 09-23-2008, 12:08 PM   #20
toddhisattva
Human being with feelings
 
toddhisattva's Avatar
 
Join Date: Jun 2008
Location: Austin
Posts: 242
Default Pre-Alpha Three

The biggest changes are internal.

The biggest user-visible changes are the reaper info sub-tables whose names have been changed to more closely match the spelling in the reaper header files and so forth.

reaper.MediaTrackInfo
reaper.TrackSendInfo
reaper.MediaItemInfo
reaper.MediaItemTakeInfo
reaper.PCM_Source
reaper.PCM_Sink

This release has some more code snippets to play with.

Alpha in sight!

Last edited by toddhisattva; 01-10-2009 at 02:08 PM.
toddhisattva is offline   Reply With Quote
Old 09-23-2008, 03:45 PM   #21
Klinke
Human being with feelings
 
Klinke's Avatar
 
Join Date: Jul 2008
Location: Berlin / Germany
Posts: 724
Default

Just want to say "Thank you", this is a really interesting project. I played a little bit with VstLua a while ago and Lua seems to be a interesting language.
Klinke is offline   Reply With Quote
Old 09-30-2008, 05:12 AM   #22
caleb
Human being with feelings
 
caleb's Avatar
 
Join Date: Feb 2007
Posts: 635
Default

Oooh - how interesting - I only just saw this.

There is no way I'm going to learn C++ well enough to code plug-ins in that language. However, I do know Python reasonably well and have dabbled in several other similar languages.

Of course, I'm forever in love with Python and will always be quietly pining away that there isn't a Python equivalent. I'm sure I'll get over it.

I'll see if I can get some time to look at this. Thanks for your efforts.

Regards
Caleb
__________________
Happiness is the hidden behind the obvious.
caleb is offline   Reply With Quote
Old 12-18-2008, 03:07 PM   #23
toddhisattva
Human being with feelings
 
toddhisattva's Avatar
 
Join Date: Jun 2008
Location: Austin
Posts: 242
Default

Quote:
Originally Posted by caleb View Post
Of course, I'm forever in love with Python and will always be quietly pining away that there isn't a Python equivalent. I'm sure I'll get over it.
Dude, there was a one-month delay in this work because I got to do some Python and SAGE math (sagemath.org) stuff for a buddy.

Too many projects....

Stay tuned.
toddhisattva 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 03:15 PM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.