ReaScript

From CockosWiki

(Difference between revisions)
Jump to: navigation, search
(Getting Started)
(Requirements)
 
(8 intermediate revisions not shown)
Line 17: Line 17:
The company ActiveState make free versions of both Perl & Python available on their web site (http://www.activestate.com) and whilst they're not the only source of these two utilities they are very good.
The company ActiveState make free versions of both Perl & Python available on their web site (http://www.activestate.com) and whilst they're not the only source of these two utilities they are very good.
-
Python: ReaScript requires Python 3.1.
+
Python: ReaScript requires Python 3.1 ('''not 3.2''').
*http://www.python.org/download/ (official Python advice)
*http://www.python.org/download/ (official Python advice)
*https://www.activestate.com/activepython/downloads/
*https://www.activestate.com/activepython/downloads/
 +
*http://downloads.activestate.com/ActivePython/releases/ (archive of older versions)
  NOTE: x64 Reaper needs x64 Python, x86 Reaper needs x86 Python.
  NOTE: x64 Reaper needs x64 Python, x86 Reaper needs x86 Python.
Line 29: Line 30:
If the FFI module is not included with your version of Perl (for some builds it is part of the ActiveState distribution, but not always for some reason) then it's also in a .zip file [http://www.reaper.fm/sdk/reascript/perl/FFI-W32.zip here] for Win32, and [http://www.reaper.fm/sdk/reascript/perl/FFI-OSX.zip here] for OSX. The two files in the .zip file should both be placed in the Perl/lib directory of your Perl installation.
If the FFI module is not included with your version of Perl (for some builds it is part of the ActiveState distribution, but not always for some reason) then it's also in a .zip file [http://www.reaper.fm/sdk/reascript/perl/FFI-W32.zip here] for Win32, and [http://www.reaper.fm/sdk/reascript/perl/FFI-OSX.zip here] for OSX. The two files in the .zip file should both be placed in the Perl/lib directory of your Perl installation.
-
=Getting Started=
+
=Quick Start=
 +
A [[Quick Start ReaPerl]] for ReaPerl.
-
This should get you started, for Windows & Perl anyway.
+
A [[Quick Start ReaPython]] for ReaPython.
-
 
+
-
First download your scripting language
+
-
 
+
-
=Download and Install Perl=
+
-
* Go to http://www.activestate.com/activeperl/ and download the Perl set-up file, save it on your desktop
+
-
* Run the downloaded set-up file; it's a standard Windows installation file, a .msi
+
-
 
+
-
=Download and Install an Editor=
+
-
You'll need a programmer's editor to create and edit scripts. There are a number of options but, if you haven't got one already, you can start here http://www.activestate.com/komodo_edit/ and do ok.
+
-
 
+
-
* Go to http://www.activestate.com/komodo_edit/ and download the Komodo Edit set-up file, save it on your desktop
+
-
* Run the downloaded set-up file; it's a standard Windows installation file, a .msi
+
-
 
+
-
=Download and Install the FFI Module=
+
-
This is the '''F'''oreign '''F'''unction '''I'''nterface module and it's the way Perl talks to REAPER functions.
+
-
 
+
-
"Install" is probably a bit of a grand description, it's just two files.
+
-
 
+
-
* Download http://www.reaper.fm/sdk/reascript/perl/FFI-W32.zip and save it on your desktop
+
-
* Extract the files from the .zip
+
-
* Copy the two files into c:/Perl/lib
+
-
 
+
-
=Reboot=
+
-
Installing Perl changes PATH variables and no doubt other things as well. A reboot won't hurt.
+
-
 
+
-
=Test Your Set-Up=
+
-
Two steps
+
-
=1 - Use REAPER to Test The Perl Installation=
+
-
* Start REAPER
+
-
* Actions menu, Show actions list
+
-
* Enter '''script''' in the filter text box
+
-
* Run the '''ReaScript: open ReaScript help (html)...''' action. A browser window will open, the second line in the browser should say that Perl is installed on this machine.
+
-
 
+
-
=2 - Run a test Perl script=
+
=Running ReaScripts=
=Running ReaScripts=
Line 73: Line 41:
To write a new script, show the Actions list (bound to the ? key by default), and click ReaScript: Load. You will be prompted for the location to save your new script, the default location is recommended. Name your script something like test.py or test.pl, then click ReaScript: Edit. A text editor will open.
To write a new script, show the Actions list (bound to the ? key by default), and click ReaScript: Load. You will be prompted for the location to save your new script, the default location is recommended. Name your script something like test.py or test.pl, then click ReaScript: Edit. A text editor will open.
-
The simplest possible ReaScript in Python is:
+
The simplest possible ReaScript in either Perl or Python is:
-
 
+
-
RPR_APITest()
+
-
 
+
-
or in Perl:
+
-
RPR_APITest();
+
RPR_APITest();
-
Please note - in Perl you do not have to specify use FFI; as REAPER will do that for you
+
In Python, of course, the semicolon is optional.
Save the ReaScript, and then click Run. You should see a window that says "Test OK". Common reasons for the script failing are:
Save the ReaScript, and then click Run. You should see a window that says "Test OK". Common reasons for the script failing are:

Latest revision as of 14:41, 28 August 2011

Reaper Documentation

Contents

Introduction

ReaScript is a feature that allows you to run Perl or Python scripts within REAPER. From within the script, you can call any REAPER action, and also call back into most of the REAPER Extensions SDK functions. ReaScript can be used to create anything from advanced macros to full-featured REAPER Extensions.

Perl and Python are freely available and widely used scripting languages; details at the sites below.

Requirements

To use ReaScript, you must have either Python or Perl installed on your computer. Both are freely available in several free distributions. OSX comes with both Python and Perl already installed, although older OSX installations may not have the most recent versions of Python or Perl.

Installing either Python or Perl is usually a simple, straightforward process. Both are open-source projects, so the source code is available for anyone to build, but most people will simply run install programn just like installing any other program (such as REAPER).

The company ActiveState make free versions of both Perl & Python available on their web site (http://www.activestate.com) and whilst they're not the only source of these two utilities they are very good.

Python: ReaScript requires Python 3.1 (not 3.2).

NOTE: x64 Reaper needs x64 Python, x86 Reaper needs x86 Python.

Perl: ReaScript requires Perl 5.10, and a standard Perl module called FFI.

If the FFI module is not included with your version of Perl (for some builds it is part of the ActiveState distribution, but not always for some reason) then it's also in a .zip file here for Win32, and here for OSX. The two files in the .zip file should both be placed in the Perl/lib directory of your Perl installation.

Quick Start

A Quick Start ReaPerl for ReaPerl.

A Quick Start ReaPython for ReaPython.

Running ReaScripts

To run a ReaScript, first you will need to either write a script, or copy a script from another user. Scripts can be placed anywhere on your disk, but it's convenient to keep them all in the REAPER/Scripts application data directory.

To write a new script, show the Actions list (bound to the ? key by default), and click ReaScript: Load. You will be prompted for the location to save your new script, the default location is recommended. Name your script something like test.py or test.pl, then click ReaScript: Edit. A text editor will open.

The simplest possible ReaScript in either Perl or Python is:

RPR_APITest();

In Python, of course, the semicolon is optional.

Save the ReaScript, and then click Run. You should see a window that says "Test OK". Common reasons for the script failing are:

   * Python or Perl not installed
   * Wrong version of Python or Perl installed
   * Multiple versions of Python or Perl installed, and the system picks up the wrong version
   * Syntax error (typo, missing newline, incorrect indentation in Python) 
   * The python parser requires a blank new line at the end of any script

You can treat a ReaScript just like any custom action: bind it to a key shortcut, MIDI controller, or toolbar button. ReaScripts can also be run a la carte, via the actions "ReaScript: run..." and "ReaScript: run last script".

Calling REAPER Actions

You can call any REAPER action from ReaScript by using the API function.

RPR_Main_OnCommand(actionnumber, 0)

From version 3.14 there is also a version for controlling the MIDI editor.

RPR_MIDIEditor_OnCommand(MIDIEditor,actionnumber)

With MIDIEditor_OnCommand() you need to specify which MIDI editor you need to control as you can have more than one open at once. Simple enough though, have a look at the documentation.

Find the action number for a given action by opening the Actions list, scroll the window right to show the action numbers. For example, from ReaScript you can call the REAPER action "Item: Split item under mouse cursor", like this:

RPR_Main_OnCommand(40746, 0)

If you would like to call either custom actions or extension actions (e.g. SWS extension), you'll notice that instead of command numbers in the Reaper dialog there are action strings. These are necessary because of the dynamic nature of these types of actions. To run these actions from your script, a call to NamedCommandLookup is necessary, as follows:

RPR_Main_OnCommand(RPR_NamedCommandLookup("_ACTIONSTRING"), 0)

These are the API functions you will need (to start with) if you are planning to use ReaScript as an advanced macro language.

ReaScript API

ReaScripts also have access to most of the REAPER Extensions SDK functions. There is a list of all the API functions available to ReaScripts available whilst running, run the REAPER action "ReaScript: open ReaScript help (html)".

The Wiki pages for each API Function are here: ReaScript API Functions

The help page will explain the basics of how to call API functions, which may require idiosyncratic syntax, because API functions can return information in the parameter list as well as the function return value. For convenience, there are also basic API functions for getting information from, and showing information to, the user.

NOTE: API function names are commonly referred to without specifying RPR_ -- but you have to specify RPR_ in your scripts

For more help on ReaScript, to report bugs, to request additional API functions, to share ReaScripts, or just to discuss the possibilities, please use the REAPER Developer Forum. http://forum.cockos.com/forumdisplay.php?f=35

Language specific documentation and examples

Reaper Documentation