Perl
From CockosWiki
Reaper Documentation/ReaScript/ReaPerl
Contents |
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.
Caveats
In general you can write pretty standard Perl and not get into too much trouble. The Standard Modules are all available etc. There are a couple of things to watch out for though.
Perl Modules
You can write your own Perl modules as normal but with a couple of restrictions:
- You can't put a .pm file in the current directory, it must be in a standard /Perl/lib directory
- You can't call RPR_ functions in a .pm, only in a top level script
The <DATA> Filehandle
The <DATA> filehandle, as you know, reads data from the file containing the script after either __END__ or __DATA__ on a lines of its own. This is not supported.
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);
Compile and Runtime Errors
Be aware that whilst Perl compile and runtime errors are reported, mostly - they're not reported very fully. Use an editor that does syntax checking for you (Komodo Edit perhaps) and test at each stage.
Busy Loops
Take care when using loops, if you set an endless loop going you might have to kill REAPER without saving your open Project(s) to stop it. REAPER does a good job of spotting endless loops but best not to rely on that; get in the habit of asking the user if they want to continue every so often.
Example Scripts & Modules
These scripts are available for you to copy, use, add to and enjoy - but take care. The ReaScript API allows you to delete, edit and generally muck around with your REAPER projects. So take care when running a likely looking script; test it beforehand on a project that can get damaged without causing a problem.
Script Name | Description | Contributed by |
---|---|---|
APITest.pl | Basic Test of your ReaScript Installation | schwa |
CopyAndPasteItemFXChain.pl | Copies the selected Item's FX Chain to the Windows ClipBoard and then to another Item or Items | MikeLacey |
CopyItemStateToClipBoard.pl | Copies the selected Item's state to the Windows ClipBoard, very useful. | sfzgeek |
EzFreeze.pl | And one that that does something more... | MikeLacey |
HelloWorld.pl | A ReaPerl script that does something | MikeLacey |
GetSetItemStateNotes.pl | Script to insert notes in an item | MikeLacey |
ItemPitchUpOneTenth.pl | Change the Pitch of an item in 0.1 semitone increments. This is just a demo of GetSetItemState() and extract_section(); you should probably use the REAPER action (Item Properties: Pitch Item Up One Cent) unless you have a specific reason for needing to use a script. | MikeLacey |
NudgeItemVolume.pl | Change the volume of an item in 1dB increments | sfzgeek |
RainbowColours.pl | Cycle an item through the colours of the rainbow | sfzgeek |
ReaScriptLib.pm | Perl module with some (hopefully) useful routines, esp for manipulating chunk data | MikeLacey |
rfefat.pl | Remove file extension from active take names. This one is for neat freaks: it lops the file extension (if found) from the active take name for every media item in a project | sfzgeek |
SetTrackEnvLeft.pl | Set the selected tracks' pan envelope to 100% left with a single point at the beginning of the track | MikeLacey |
WindowsClipBoardDemo.pl | Demo of using the Windows Clipboard in a ReaPerl script | sfzgeek |
Reaper Documentation/ReaScript/ReaPerl