Perl

From CockosWiki

Jump to: navigation, search

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 NameDescriptionContributed by
APITest.plBasic Test of your ReaScript Installationschwa
CopyAndPasteItemFXChain.plCopies the selected Item's FX Chain to the Windows ClipBoard and then to another Item or ItemsMikeLacey
CopyItemStateToClipBoard.plCopies the selected Item's state to the Windows ClipBoard, very useful.sfzgeek
EzFreeze.plAnd one that that does something more...MikeLacey
HelloWorld.plA ReaPerl script that does somethingMikeLacey
GetSetItemStateNotes.plScript to insert notes in an itemMikeLacey
ItemPitchUpOneTenth.plChange 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.plChange the volume of an item in 1dB incrementssfzgeek
RainbowColours.plCycle an item through the colours of the rainbowsfzgeek
ReaScriptLib.pmPerl module with some (hopefully) useful routines, esp for manipulating chunk dataMikeLacey
rfefat.plRemove 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 projectsfzgeek
SetTrackEnvLeft.plSet the selected tracks' pan envelope to 100% left with a single point at the beginning of the trackMikeLacey
WindowsClipBoardDemo.plDemo of using the Windows Clipboard in a ReaPerl scriptsfzgeek


Reaper Documentation/ReaScript/ReaPerl

Personal tools