Old 05-24-2016, 05:29 PM   #1
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,909
Default Interactive ReaScript (Lua)

This script implements a REPL shell for Lua ReaScript inside of REAPER, for quickly experimenting code and API functions.



Main Features:
  • Autocompletion
  • Code history
  • Colored output
  • Copy/paste from clipboard
  • Error catching
  • Multiline input (functions, conditions...)
  • Pretty print return values
  • Run actions (!command_id, !!midi_editor_action)
  • Scrolling
  • Text selection
  • Text wrapping for long lines
Known Issues/Limitations:
Install:

iReaScript is available from ReaTeam's ReaScript repository in ReaPack.

Last edited by cfillion; 08-02-2018 at 08:34 AM.
cfillion is offline   Reply With Quote
Old 05-24-2016, 11:53 PM   #2
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,956
Default

This is Amazing!
mpl is offline   Reply With Quote
Old 05-25-2016, 03:29 AM   #3
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,866
Default

This is what I call an experimental script haha

Well done, it seems pretty good !
X-Raym is offline   Reply With Quote
Old 05-25-2016, 08:57 AM   #4
Claudiohbsantos
Human being with feelings
 
Join Date: Aug 2014
Location: New York
Posts: 135
Default

This is awesome, gonna have to give it a shot later tonight. I can see this becoming a very handy tool while reascripting
__________________
My Reapack Repo - Reapack Extension
Claudiohbsantos is offline   Reply With Quote
Old 06-07-2016, 08:09 PM   #5
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,909
Default

iReaScript v0.2

+ enhance formatting of arrays containing nil values
+ implement Delete key
+ implement word movement keys (Shift+Left and Shift+Right)
+ imply the return statement by default
+ limit maximum depth when formatting tables
+ protect against overriding of built-in variables
cfillion is offline   Reply With Quote
Old 06-07-2016, 09:03 PM   #6
semiquaver
Human being with feelings
 
Join Date: Jun 2008
Posts: 4,923
Default

yes !!
semiquaver is offline   Reply With Quote
Old 07-14-2016, 07:53 PM   #7
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,909
Default

iReaScript v0.3

+ added autocompletion with Tab key
+ added PageUp/PageDown keys to scroll faster
+ fix formatting of multiline text chunks
+ implement clipboard read/write with Ctrl+C and Ctrl+V (works best on OS X)
+ preserve current input and history on .clear
+ protect against invalid access on reaper/gfx tables (using X-Raym's workaround)
+ set global `_` variable to the first return value of last statement
+ support multi-line statements (like long functions, conditions...)


Last edited by cfillion; 07-14-2016 at 08:03 PM.
cfillion is offline   Reply With Quote
Old 07-14-2016, 08:33 PM   #8
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 7,215
Default

wow... I didn't know about this.
mind blown
amazing!
heda is offline   Reply With Quote
Old 07-14-2016, 09:34 PM   #9
semiquaver
Human being with feelings
 
Join Date: Jun 2008
Posts: 4,923
Default

my new favorite script
semiquaver is offline   Reply With Quote
Old 07-15-2016, 05:49 AM   #10
me2beats
Human being with feelings
 
me2beats's Avatar
 
Join Date: Jul 2015
Location: Yekaterinburg, Russia
Posts: 400
Default

omg wow
me2beats is offline   Reply With Quote
Old 07-15-2016, 06:09 AM   #11
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,887
Default

Neat.
IXix is offline   Reply With Quote
Old 08-17-2016, 06:25 PM   #12
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,909
Default

iReaScript v0.4

+ autocomplete partial matches
+ don't execute empty code input (v0.3 regression)
+ enhance formatting of string values
+ fix input of tildes
+ increase maximum buffer size to 2048 lines
+ limit maximum size of tables values when formatting
+ optimize layout by only computing new or modified text segments
+ preserve current input when using Ctrl+L shortcut
+ prevent cursor position from affecting text position
+ remove reaper/gfx proxy variable workaround (requires REAPER v5.23 [t=177319])
+ rewrite drawing & scrolling code
+ wait at least one second before blinking the cursor

Last edited by cfillion; 08-18-2016 at 12:19 PM.
cfillion is offline   Reply With Quote
Old 10-06-2016, 11:27 PM   #13
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,909
Default

iReaScript v0.4.1

+ fix auto-completion of exact matches
+ fix caret display in multiline input
+ improve how partially visible lines affect the scrollbar
+ remember docked state (use `gfx.dock(N)` to put in dock)

iReaScript v0.4.2

+ fix formatting of zero-indexed table
+ fix formatting of zero-sized (yet non-empty) tables
+ override global 'print' function
+ use braces instead of non-lua brackets for tables with numeric indexes

Last edited by cfillion; 10-07-2016 at 05:17 PM.
cfillion is offline   Reply With Quote
Old 11-29-2016, 04:12 PM   #14
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,909
Default

@TonE It's called "cfillion_Interactive ReaScript.lua" in the action list and ReaPack v1.0 (in v1.1 the "iReaScript" is also displayed).

Last edited by cfillion; 11-29-2016 at 04:29 PM.
cfillion is offline   Reply With Quote
Old 12-12-2016, 08:38 PM   #15
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,909
Default

iReaScript v0.5

+ add Copy/Paste/Clear/Dock/Close actions to the right click context menu
+ display errors using bold font
+ document the built-in functions and variables in .help
+ fix formatting of \t and \r in strings when they are followed by numbers
+ implement (fix) display of empty lines
+ remember window position, size and docked state
+ store every return values in _ global variable

iReaScript v0.6

+ allow .clear to be recorded in the history
+ do not crash on clipboard read/write failure (eg. 32-bit windows)
+ don't evaluate command/actions while in a lua block
+ implement !ACTION for Main actions, !!ACTION for MIDI Editor actions
+ remove extra newline inserted when executing an empty command since v0.5

Last edited by cfillion; 01-20-2017 at 04:26 PM.
cfillion is offline   Reply With Quote
Old 12-13-2016, 02:41 AM   #16
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,887
Default

Bravo!
IXix is offline   Reply With Quote
Old 02-17-2017, 01:31 AM   #17
Outboarder
Human being with feelings
 
Outboarder's Avatar
 
Join Date: Feb 2014
Posts: 834
Default

This is exactly what I need, Thank you.
__________________
Outboarder Scripts
Outboarder is offline   Reply With Quote
Old 02-17-2017, 02:12 AM   #18
ceanganb
Human being with feelings
 
Join Date: May 2009
Location: Brazil
Posts: 323
Default

Very very useful tool, thanks.
__________________
Ceanganb
ceanganb is offline   Reply With Quote
Old 03-21-2017, 05:32 PM   #19
Airal
Banned
 
Join Date: Nov 2015
Posts: 406
Default

Very cool! Is there any way to have a default script run at startup? I could probably modify the code, but probably better for it to be done by the repository. Is there still a gfx issue? I assume the problem is due to the script itself using the gfx?
Airal is offline   Reply With Quote
Old 03-21-2017, 05:53 PM   #20
Airal
Banned
 
Join Date: Nov 2015
Posts: 406
Default

There seems to be some bugs in the script. When I execute the script in reaper it works fine but when I execute it in repl it fails iwth

attempt to compare nil with number.

I am simply trying to execute `reaper.CountTracks(0)`

and so it should work fine, this suggests it is a script. Other code works fine.

If I copy the code I'm using in to repl:

function NumTracks()
return reaper.CountTracks(0)
end

and then call it, it works fine.

Seems like some type of parsing issue of the library I'm importing using "require".

---

Ok, what it is, is that it is not loading the new library after I save it. Could we get an update that monitors any require's for changes(file size/hash) and if it changes to reload it automatically or to even restart the repl session if necessary?

repl is great for debugging but if it can't refresh after changes without requiring it to restart, it slows things down greatly.
Airal is offline   Reply With Quote
Old 03-21-2017, 07:31 PM   #21
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,909
Default

Quote:
Originally Posted by Airal View Post
Very cool! Is there any way to have a default script run at startup? I could probably modify the code, but probably better for it to be done by the repository.
Not currently. For now you might be interested with the `.` (dot) command which re-runs the previous code or the up/down arrows which navigate in the code history (TODO: save the history to file so it's not lost on the next startup).

Quote:
Originally Posted by Airal View Post
Is there still a gfx issue? I assume the problem is due to the script itself using the gfx?
Yes, until REAPER allows a single script to open multiple windows using gfx.

Quote:
Originally Posted by Airal View Post
There seems to be some bugs in the script. When I execute the script in reaper it works fine but when I execute it in repl it fails iwth

attempt to compare nil with number.

I am simply trying to execute `reaper.CountTracks(0)`
Perhaps the script you are loading is defining and using some local variables? If so, Lua erases those after the evaluation. This would explain the nil.
cfillion is offline   Reply With Quote
Old 03-22-2017, 09:05 AM   #22
Airal
Banned
 
Join Date: Nov 2015
Posts: 406
Default

Thanks. Could you had the ability for it to execute a simple script at startup automatically. e.g.,

iReaScriptStartup.lua

(if it exists in the scripts or lua dir it is executed automatically)

Should be simple to add(load file then parse it line by line as if the user typed it in)

By having that and the the history, it should work well. It would still require one to reload the script but it won't require a complete restart of the entire process like it does now.

Also, it would be nice if the `esc` key would clear the current line. It seems that the graphics window also loses focus when pasting which requires one to grab the mouse and reselect it... pretty annoying ;. Also, when starting the script for the first time, it loses focus.

It would be nice to do simple expressions.

e.g., one can't compute 1/3

I suppose this is because you are simply eval the expression as is. Maybe add a test for something like an expression and if the line seems like an expression(doesn't start with local, =, alpha, etc) then prepend a `local val =` to it then report the `value of val`. If it fails try executing the line directly(or vice versa).

Last edited by Airal; 03-22-2017 at 03:37 PM.
Airal is offline   Reply With Quote
Old 08-30-2017, 02:08 AM   #23
Ivannn Bennnettt
Human being with feelings
 
Join Date: Feb 2017
Posts: 305
Default

Thank you a lot!
Ivannn Bennnettt is offline   Reply With Quote
Old 10-05-2017, 06:48 PM   #24
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,909
Default

iReaScript v0.7

Implemented text selection!


Last edited by cfillion; 10-05-2017 at 06:54 PM.
cfillion is offline   Reply With Quote
Old 10-06-2017, 03:48 AM   #25
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,866
Default

@cfillion
I was just about to ask you abut that !! Nice !!
X-Raym is offline   Reply With Quote
Old 11-21-2017, 07:23 PM   #26
TonE
Human being with feelings
 
Join Date: Feb 2009
Location: Reaper HAS send control via midi !!!
Posts: 4,031
Default

Looks great for learning, now we need to find best resources about as much reaper lua as possible, besides having the millions of .lua examples!

We need a separate reaper blog with youtube videos where any of the million .lua is taken as an example, then analyzed, brought to its minimal form. As a formula the tutorial should do:

luaexample := skelett + flesh

The goal would be removing the complete flesh, leaving only the skelett which could be used then for other related experiments.

One example: Can we have dynamic arrangements, rather than static arrangements? Like for all items in a folder, and around playing bar region, like current bar plus and minus 2 bars, every 15 seconds, switch to another item (next,prev,random). Could be fun, something like a probability, but on item level. Then watching in Interactive ReaScript some statistics which files were used how often.

Another example: Reprogramming all available midi mappings, for a set of tracks/effects according to some algorithm. Directly inside Reaper. I did something in the past with Autohotkey, by simply editing .rpp and generating another .rpp, but doing it directly inside the project would be more fun, if everything would work properly. Interactive ReaScript could show the current mapping values for example.

Last edited by TonE; 11-21-2017 at 07:31 PM.
TonE is offline   Reply With Quote
Old 08-01-2018, 05:20 PM   #27
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,909
Default

iReaScript v0.8

+ Added support for multibyte and full-width characters (though they can't be typed directly)



+ iReaScript's global print(...) function can now be used from external scripts for debugging



+ allow reaper and gfx to be overwritten without crashing
+ autocomplete multi-dimensional tables
+ fix table autocompletion when the variable name contains digits
+ fix table autocompletion when there are more than one spaces surrounding the dot
+ fix {[1]=1, [255]=2} being displayed as just {1}
+ redraw the screen only when necessary for reduced CPU usage
+ show a full traceback when iReaScript crashes

iReaScript v0.8.1

+ add ctrl+w to erase the current word from the cursor
+ fix moving the cursor to the start of the previous word (shift+left) with multiple leading whitespaces
# fix off-by-one character offsets in double-click whole word selection (0.8 regression)
+ harden against ill-formed UTF-8 sequences in the history file

Last edited by cfillion; 08-02-2018 at 08:38 AM.
cfillion is offline   Reply With Quote
Old 08-01-2018, 06:58 PM   #28
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

So hot.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 08-02-2018, 03:37 AM   #29
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,866
Default

Thnks for the update !


Few things:
  • Backspace on selected text only remove one character instead of all the selection
  • selection via CTRL + ← works but it doesn't display the selection background


:P
X-Raym is offline   Reply With Quote
Old 08-02-2018, 08:30 AM   #30
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,909
Default

This behavior is similar to common terminal emulators and shells where selection is separate from edit operations.

You can use Ctrl+U to erase to the beginning or Ctrl+W to erase a single word (I've just added the later in 0.8.1):

Shift+Left moves the caret the the start of the current/previous word. For convenience, Ctrl+C copies the whole line when there is no selection.

Last edited by cfillion; 08-02-2018 at 08:35 AM.
cfillion is offline   Reply With Quote
Old 08-02-2018, 02:42 PM   #31
mccrabney
Human being with feelings
 
mccrabney's Avatar
 
Join Date: Aug 2015
Posts: 3,664
Default

this seems like it'll be really helpful as i dive into scripts more.

i'm not quite getting it, though.

i want to use reaper.TrackFX_GetParam( track, fx, param ) to see the retval of "param." what syntax would i type in order to see that? i keep getting bad argument messages and can't figure out what to input.
__________________
mccrabney scripts: MIDI edits from the Arrange screen ala jjos/MPC sequencer
|sis - - - anacru| isn't what we performed: pls no extra noteons in loop recording
| - - - - - anacru|sis <==this is what we actually performed.
mccrabney is offline   Reply With Quote
Old 08-02-2018, 03:06 PM   #32
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,909
Default

Quote:
Originally Posted by mccrabney View Post
i want to use reaper.TrackFX_GetParam( track, fx, param ) to see the retval of "param."
That API function needs a MediaTrack*, the FX number and the parameter number (counting from zero). It returns {current internal value, minimum, maximum}.

To get the first track's first FX's first parameter:

Code:
track = reaper.GetTrack(0, 0)
reaper.TrackFX_GetParam(track, 0, 0)

Last edited by cfillion; 08-02-2018 at 03:11 PM.
cfillion is offline   Reply With Quote
Old 08-02-2018, 03:19 PM   #33
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,866
Default

@cfillion
Ok so no prolem if it is the expected behavior :P
X-Raym is offline   Reply With Quote
Old 08-02-2018, 03:22 PM   #34
mccrabney
Human being with feelings
 
mccrabney's Avatar
 
Join Date: Aug 2015
Posts: 3,664
Default

got it, thanks! great tool.
__________________
mccrabney scripts: MIDI edits from the Arrange screen ala jjos/MPC sequencer
|sis - - - anacru| isn't what we performed: pls no extra noteons in loop recording
| - - - - - anacru|sis <==this is what we actually performed.
mccrabney is offline   Reply With Quote
Old 03-17-2020, 10:32 PM   #35
TonE
Human being with feelings
 
Join Date: Feb 2009
Location: Reaper HAS send control via midi !!!
Posts: 4,031
Default

Quote:
Originally Posted by cfillion View Post
That API function needs a MediaTrack*, the FX number and the parameter number (counting from zero). It returns {current internal value, minimum, maximum}.

To get the first track's first FX's first parameter:

Code:
track = reaper.GetTrack(0, 0)
reaper.TrackFX_GetParam(track, 0, 0)
And how to get the midi mapping of that parameter?
TonE is offline   Reply With Quote
Old 06-11-2020, 10:25 AM   #36
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,866
Default

Hi !


It seems that \ character become _\ on the console... I was trying to input windows path. :S


Thx !
X-Raym is offline   Reply With Quote
Old 06-11-2020, 11:00 AM   #37
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,909
Default

I can't reproduce that on macOS or Windows (typing a \ inserts only a \). Maybe it's tied to a specific keyboard layout? What does gfx.getchar() and utf8.char(theReturnValueFromGetChar) returns?
cfillion is offline   Reply With Quote
Old 06-11-2020, 12:11 PM   #38
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,866
Default

Win x10 Azerty keyboard (I press ALT GR + 8 to get \ )


gfx.getchar() returns 0 in your console script, so the utf8 is \0
X-Raym is offline   Reply With Quote
Old 06-11-2020, 09:22 PM   #39
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,909
Default

With an AZERTY layout, pressing AltGr+8 produces a single '\' character in iReaScript here. gfx.getchar returns 92.0 once for it without a leading underscore.

Do you get the same issue in other ReaScripts that use keyboard input?
cfillion is offline   Reply With Quote
Old 11-12-2020, 10:52 AM   #40
chrisfr
Human being with feelings
 
Join Date: May 2018
Posts: 13
Default

I confirm the same problem on my side(french azerty keyboard). Actually I have it not only for \ but also for other AltGr keys:

AltGr + 3 => "#
AltGr + 4 => '{
AltGr + 5 => ([
AltGr + 6 => -|
AltGr + 8 => _\
AltGr + ° => =}
AltGr + + => =}

The 1st char is the one that is obtained when you don't press AltGr + the concerned key (and the second the one that is expected while pressing AltGr).
NB: numbers are what are obtained with shift + <key>

I also tested on a GUI build with Scythe V3 and I have the same behavior. The input field event reports 2 key strokes...

Config : Reaper 6.15/x64 on Windows 10 (1909).
chrisfr 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:57 PM.


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