Perl
From CockosWiki
Introduction
ReaScript Perl uses the standard module FFI, but there's no need to include the line
use FFI;
in your scripts because ReaScript will do that for you; it doesn't hurt if you do include that line.
Caveats
All REAPER API Calls Must Be On A Single Line
This is valid Perl
$return_value = RPR_ShowMessageBox( $msg_1, $title, MSG_BOX_YES_NO );
But... It won't work under REAPER at the moment, all calls to the REAPER API have to be on a single line, like this.
$return_value = RPR_ShowMessageBox($msg_1,$title,MSG_BOX_YES_NO);
Example Scripts
This is the REAPER equivalent of Hello world!, it presses the Play button for you
# # First.pl # # simulate pressing the play button in the current project RPR_Main_OnCommand(1007,0);
It does just the one thing, calls the REAPER API function RPR_Main_OnCommand() with the value 1007 -- which means Play.
There's very little to it, just the one line calling the API function, doesn't even look ilke Perl really.
Ok then another, slightly longer script.
# # Freeze.pl # use strict; use warnings; use constant MSG_BOX_OK => 0; use constant MSG_BOX_YES_NO => 4; use constant MSG_BOX_YES => 6; use constant MSG_BOX_NO => 7; use constant CMD_RNDR_TO_STEREO_STEMS => 40788; use constant DEBUG => 1; # set to zero to turn off console messages RPR_ShowConsoleMsg("Initialising\n") if DEBUG; my $title = 'Freeze Track(s)'; my $msg = "This will \"Freeze\" currently selected tracks by rendering " . "them to stem tracks, inserting those stem tracks in the project and " . "muting the original tracks to save processing power.\n "; my $msg_1 = $msg . "Do you want to Freeze the selected tracks?"; my $msg_2 = $msg . "You don't have any tracks selected at the moment. " . "select one or more tracks and try again.\n"; my $return_value = 0; RPR_ShowConsoleMsg("Counting selected tracks\n") if DEBUG; if(RPR_CountSelectedTracks(0)==0){ RPR_ShowConsoleMsg("No tracks selected, telling user and exiting\n") if DEBUG; $return_value = RPR_ShowMessageBox($msg_2,$title,MSG_BOX_OK); exit(0); } RPR_ShowConsoleMsg("At least one track selected\n") if DEBUG; RPR_ShowConsoleMsg("Calling RPR_ShowMessageBox()\n") if DEBUG; # Check to make sure we really want to do this. $return_value = RPR_ShowMessageBox($msg_1,$title,MSG_BOX_YES_NO); RPR_ShowConsoleMsg("Dialogue Box returns...\n") if DEBUG; if($return_value == MSG_BOX_YES){ RPR_ShowConsoleMsg("Dialogue Box returns: YES, rendering\n") if DEBUG; RPR_Main_OnCommand(CMD_RNDR_TO_STEREO_STEMS, 0); RPR_ShowConsoleMsg("Rendering done\n") if DEBUG; } elsif($return_value == MSG_BOX_NO) { RPR_ShowConsoleMsg("Dialogue Box returns: NO, exiting\n") if DEBUG; } else{ RPR_ShowConsoleMsg("Unexpected return value from Dialogue Box: $return_value\n") if DEBUG; }
This one does a little more and uses some of the techniques found in much longer scripts, constants, debugging output etc. It's recognisably a Perl script and even does a little error checking.
Notice that the calls to the REAPER API functions all start with RPR_
Also - Note that while this is valid Perl
$return_value = RPR_ShowMessageBox( $msg_1, $title, MSG_BOX_YES_NO );
It won't work under REAPER at the moment, all calls to the REAPER API have to be on a single line, like this.
$return_value = RPR_ShowMessageBox($msg_1,$title,MSG_BOX_YES_NO);
This might well change in a future release.