Python

From CockosWiki

Jump to: navigation, search

Reaper Documentation/ReaScript

Contents

Introduction

Multiple Versions of Python Installed

On a Mac, if you have both Python 2 and 3 installed and it's causing you problems, you can try this from Reaper 3.1415:

In REAPER.ini, the [reaper] section which is usually the top 50% of the file, add a line like this:

pythonlib=/Library/Frameworks/Python.framework/Versions/3.1/lib/libpython3.1.dylib 

(Your path to the Python 3 dylib is probably different - so don't just copy the line above...)

Caveats

Recommended Script Editors

IDLE - which is included in more recent Python distributions.
PythonWin - A rather simple but well integrated Python text editor that is included with the pywin32 extensions. (Can be found in \Python31\Lib\site-packages\pythonwin after installation)
Notepad++
PSPad
Emacs - bit of a learning curve but probably the most powerful text editor out there

Coding Tips

Function Aliasing

You can use function aliasing to reduce the length of your code in cases where a function is used many times. For example:

def msg(m):
    RPR_ShowConsoleMsg(m)
# ------------------------
# so now you can write msg() instead of RPR_ShowConsoleMsg() each time

Finding Documentation For Installed Modules

You can use the integrated pydoc module to find and extract documentation for Python standard modules, 3rd party modules and libraries.

On Windows (assuming you have Python installed on the C drive), run the following command to start the pydoc GUI interface.

python C:\Python31\Lib\pydoc.py -g

The pydoc GUI Interface:

Pydoc.jpg

You can search for the documentation of any installed modules or libraries. Double-clicking on a result will open an html page with the requested documentation in your browser. Alternatively, click the open browser button to open an html page with a list of all the installed Python modules and links to their relevant documentation.

Example Scripts

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
HappySnake.pyCoding example in the form of ASCII prank:liteon
GetSourceExtension.pytesting the extension of one selected item EvilDragon
GuiTest.pyShort demonstration of the TK Gui - excellent stuff which solves a lot of problemsMalevol3nt
MoveToNextEdit.py & MoveToPrevEdit.pyMoves the cursor to the next, or previous "edit point". In this context an edit point is a project marker, project start or end, item start and end points, and fade points. The two scripts are nearly identical with just a single variable specifying which way to search in the project. ThomasE
QuickName.pyopens a dialog box to ask user for new media item take nameliteon
RemoveTakeNamesExtensions.pyA Python version of sfzgeek's Perl scriptEvilDragon
SetCustomColour.pyThis script sets the track colour if just the track is selected and the item colour if just the item is suggestedEvilDragon
SoxConvert.pySample rate conversion with SOX and ReaScriptdub3000
Reaper Documentation > ReaScript
Personal tools