Lua Scripting with REAPER 5 - Part. 1: The Console Output
-
0:00 - 0:02Hello everyone,
this is X-Raym -
0:02 - 0:07for a tutorial about
Scripting in REAPER 5 -
0:07 - 0:10I assume that
you already know REAPER -
0:10 - 0:13the sound editing software
-
0:13 - 0:20and my series of articles called
"ReaScript Basics" -
0:20 - 0:23which introduce the concept of ReaScript
-
0:23 - 0:27in other words,
coding Scripts for REAPER -
0:27 - 0:33I will advice you to read the
interview I gave for The REAPER Blog -
0:33 - 0:40in which I explain all you have to know
before getting in. -
0:40 - 0:45The purpose of this video
is to start coding -
0:45 - 0:50by practicing.
-
0:50 - 0:53This will be done in several steps
-
0:53 - 0:56We will see in this first video,
-
0:56 - 0:58how to use the Console, and why.
-
0:58 - 1:03We will create a new Action/Script
-
1:03 - 1:09by launching the Action Window,
and then by clicking on ReaScript -> New -
1:09 - 1:13The User Scripts directory opens
-
1:13 - 1:15and I enter a new script name.
-
1:15 - 1:20"my new script"
-
1:20 - 1:25I then write the file extension, ".lua".
-
1:25 - 1:29This extension will determine
what language is use to code this script. -
1:29 - 1:33There is two languages that can be
interpreted natively in REAPER, EEL and Lua -
1:33 - 1:38Python is possible too for scripting,
but it needs external libraries. -
1:38 - 1:42We will choose for its
native interpretation, -
1:42 - 1:45but also for its ease of writing,
-
1:45 - 1:50and for its high performance,
and its flexibility. -
1:52 - 1:54If I press save, a window appears.
-
1:54 - 1:57The "ReaScript Development Environment"
-
1:57 - 2:02in which you can code your script
directly within REAPER -
2:02 - 2:05which is very powerful.
-
2:05 - 2:08This window is new in REAPER 5,
-
2:08 - 2:11just as the integration of Lua.
-
2:11 - 2:17We will start by coding a script
that will display a message in the Console. -
2:17 - 2:22The Console is a window that can be
used to develop your script. -
2:22 - 2:26For this, you will have to use a function
nammed "ShowConsoleMsg()" -
2:32 - 2:35Because it is a native REAPER function,
-
2:35 - 2:39you will have to set the prefix
"reaper." -
2:42 - 2:48As parameters, we put a string
between double quotes "" -
2:53 - 2:59If I press CTRL+S again, the script
is saved and executed. -
2:59 - 3:04As you can see,
the ReaScript Console Output opens -
3:04 - 3:06With the message we set.
-
3:06 - 3:09If I press start again,
-
3:09 - 3:16You can see that the message is put
after what was already in the console. -
3:16 - 3:19For cleaning the console,
you can press Clear. -
3:19 - 3:25The idea behind ShowConsoleMsg
is too display the value of a variable. -
3:27 - 3:30We will then create a variable.
-
3:30 - 3:38We will call it string,
and set "Hellow World!" as value. -
3:38 - 3:46Here, we replace the string
by the variable name. -
3:46 - 3:52As you can see, it displays
the variable value in the Console. -
3:52 - 3:54Just like before.
-
3:54 - 4:01Now, if I want to display a second line,
-
4:01 - 4:09we will create a second variable,
with the value "How are you today?" -
4:13 - 4:17We now just have to dupplicate the function
ShowConsoleMsg -
4:17 - 4:22and to set the second
variable as parameter. -
4:22 - 4:23If I display the result...
-
4:25 - 4:31If I display the result, you can see that the
values are displayed one after the other. -
4:31 - 4:35As you can see, the console
hasn't been cleared. -
4:35 - 4:41It bothers me as I will have to run the
script several time during its development. -
4:41 - 4:44To initialize the console,
we just have to write... -
4:45 - 4:47reaper. ShowConsoleMsg()
-
4:48 - 4:51with an empty string "" as parameter.
-
4:51 - 4:53It allows to clean the console.
-
4:54 - 4:58Here is a demo. If I delete all this
and I save + run, -
4:58 - 5:00The console is cleared.
-
5:00 - 5:01If I restore,
-
5:03 - 5:07the two lines come back.
-
5:07 - 5:09If I press start,
-
5:10 - 5:13Nothing change because
the console is cleared -
5:13 - 5:16and then the strings are
displayed once again. -
5:17 - 5:22I now want a break line between
the two strings. -
5:22 - 5:28We will write
reaper. ShowConsoleMsg() -
5:28 - 5:36and set "\n" as parameters.
-
5:36 - 5:38It is the code the make a line break.
-
5:38 - 5:42As you can see, a break line has been put
between our two strings. -
5:42 - 5:46Instead of writing this
using several functions, -
5:46 - 5:48or should I say,
several times the ShowConsoleMsg function; -
5:48 - 5:53I could put all this in
one single function. -
6:00 - 6:02I could put all this at the same time.
-
6:02 - 6:07That would give the following thing...
-
6:09 - 6:14If I save + run,
it gives the same results as before. -
6:14 - 6:20Once again, I could add
other strings after that. -
6:20 - 6:27For exemple,
"I'm fine, thank you" -
6:29 - 6:33The break line hasn't been added,
I can add it -
6:33 - 6:37either here, at the beginiing, for exemple,
-
6:37 - 6:42I can add it here,
the output is still the same, -
6:42 - 6:45or make just like before...
-
6:49 - 6:52and all this output the same result.
-
6:52 - 7:00Rather than use several time reaper.
ShowConsoleMsg which is long to write -
7:00 - 7:03and to add break lines everywhere,
-
7:03 - 7:09I can create a function
that we will called Msg. -
7:09 - 7:14And which will have one parameter.
-
7:19 - 7:20The function ends by "end",
-
7:20 - 7:24and I write inside the declaration
what the function will do if we call it. -
7:24 - 7:30It will display that we
will put as parameters. -
7:31 - 7:35And it will add to this a breakline.
-
7:35 - 7:36This means that,
-
7:38 - 7:40if I call the function
-
7:42 - 7:45and that I write a parameters in it
-
7:45 - 7:46string in this case,
-
7:50 - 7:51and string2
-
7:55 - 7:58As, we can see here an error message
-
7:58 - 8:00"reaper. ShowConsole is unknown"
-
8:00 - 8:04I just forgot to add Msg
to the function name. -
8:05 - 8:08As you can see the line break
has been added automatically -
8:08 - 8:10I didn't have to rewrite it.
-
8:10 - 8:12I duplicate this...
-
8:14 - 8:17You can see that the break
line is added automatically, -
8:17 - 8:19and it is very faster to code.
-
8:21 - 8:28The ShowConsoleMsg can accept numbers,
-
8:28 - 8:31If I put 6,
-
8:31 - 8:34You can see that the console output "6".
-
8:34 - 8:37But if the variable value
we want to display doesn't exist, -
8:37 - 8:41for example, string3,
-
8:41 - 8:44I will have an error message,
that will tell me -
8:44 - 8:50that I try to merge a nil
value with a string. -
8:50 - 8:54Nil is a type of value used in Lua,
that is used to define -
8:54 - 8:59that variable hasn't be declared
or that its value is nil. -
9:00 - 9:06For exemple, I will have the same result
if I put nil directly as parameter, -
9:06 - 9:08You can see a bug report message.
-
9:08 - 9:11Same thing will occurs if string3...
-
9:15 - 9:17had for value nil.
-
9:19 - 9:25It is very important to avoid
this kind of message in a script, -
9:25 - 9:27It means that the scripts has bug,
it is not executed entirely. -
9:28 - 9:31In the case of our script,
to be sure that it works, -
9:31 - 9:33we will use a Lua native function
(not a REAPER special one) -
9:33 - 9:40which will convert in string
the parameter we put in it. -
9:40 - 9:44If I run the script again,
it display "nil" in plain text, -
9:44 - 9:46and there is no error anymore.
-
9:46 - 9:51Our message function in then ready
to be used in our next script.
- Title:
- Lua Scripting with REAPER 5 - Part. 1: The Console Output
- Description:
-
Build your own REAPER custom actions with scripting !
This series of videos is about learning how to code scripts in Lua for REAPER 5.
If you don't know what ReaScript is, please take a look at the ReaScript Basics series of article on my website:
http://extremraym.com/reascript-basics-part1/If you enjoyed this free tutorial, please consider making a donation ♥
http://extremraym.com/donation/Any feedback is welcome !
- Video Language:
- French
- Duration:
- 09:57
Extrem Raym edited English, British subtitles for Lua Scripting with REAPER 5 - Part. 1: The Console Output | ||
Extrem Raym edited English, British subtitles for Lua Scripting with REAPER 5 - Part. 1: The Console Output | ||
Extrem Raym edited English, British subtitles for Lua Scripting with REAPER 5 - Part. 1: The Console Output |