Perl

From CockosWiki

(Difference between revisions)
Jump to: navigation, search
(Caveats)
(Undo revision 13140 by Ucokane (Talk))
 
(12 intermediate revisions not shown)
Line 8: Line 8:
=Caveats=
=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==
-
==Don't go writing Perl Modules (just yet)==
+
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
-
You can't yet use your own modules...
+
==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==
==All REAPER API Calls Must Be On A Single Line==
Line 34: Line 39:
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.
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=
+
=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.
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.
Line 42: Line 47:
|-
|-
| [[API_Test|APITest.pl]]||Basic Test of your ReaScript Installation||schwa
| [[API_Test|APITest.pl]]||Basic Test of your ReaScript Installation||schwa
 +
|-
 +
| [[CopyAndPasteItemFXChain_pl|CopyAndPasteItemFXChain.pl]]||Copies the selected Item's FX Chain to the Windows ClipBoard and then to another Item or Items||MikeLacey
 +
|-
 +
| [[CopyItemStateToClipBoard_pl|CopyItemStateToClipBoard.pl]]||Copies the selected Item's state to the Windows ClipBoard, very useful.||sfzgeek
|-
|-
| [[EzFreeze_pl|EzFreeze.pl]]||And one that that does something more...||MikeLacey
| [[EzFreeze_pl|EzFreeze.pl]]||And one that that does something more...||MikeLacey
Line 48: Line 57:
|-
|-
| [[GetSetItemState_Notes_pl|GetSetItemStateNotes.pl]]||Script to insert notes in an item||MikeLacey
| [[GetSetItemState_Notes_pl|GetSetItemStateNotes.pl]]||Script to insert notes in an item||MikeLacey
 +
|-
 +
| [[ItemPitchUpOneTenth.pl|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|NudgeItemVolume.pl]]||Change the volume of an item in 1dB increments||sfzgeek
| [[NudgeItemVolume_pl|NudgeItemVolume.pl]]||Change the volume of an item in 1dB increments||sfzgeek
|-
|-
| [[RainbowColours_pl|RainbowColours.pl]]||Cycle an item through the colours of the rainbow||sfzgeek
| [[RainbowColours_pl|RainbowColours.pl]]||Cycle an item through the colours of the rainbow||sfzgeek
 +
|-
 +
| [[ReaScriptLib.pm|ReaScriptLib.pm]]||Perl module with some (hopefully) useful routines, esp for manipulating chunk data||MikeLacey
 +
|-
 +
| [[rfefat_pl|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|SetTrackEnvLeft.pl]]||Set the selected tracks' pan envelope to 100% left with a single point at the beginning of the track||MikeLacey
| [[SetTrackEnvLeft_pl|SetTrackEnvLeft.pl]]||Set the selected tracks' pan envelope to 100% left with a single point at the beginning of the track||MikeLacey
Line 59: Line 74:
<br>
<br>
 +
 +
[[Category:ReaScript]]
[[Category:ReaScript]]
 +
[[Category:ReaPerl]]
[[Reaper_Documentation|Reaper Documentation]]/[[ReaScript]]/[[Perl|ReaPerl]]
[[Reaper_Documentation|Reaper Documentation]]/[[ReaScript]]/[[Perl|ReaPerl]]

Latest revision as of 02:09, 19 November 2010

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