< Return to Video

Lua Scripting with REAPER 5 - Part. 1: The Console Output

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

more » « less
Video Language:
French
Duration:
09:57

English, British subtitles

Revisions