Skip to content

Function export to ReaScripts

nofish edited this page Aug 19, 2018 · 9 revisions

Some functions hosted by the SWS extension can be called from Python, EEL and Lua ReaScripts and from other extension plugins (C++). To get the list of exported functions and detailed documentation, see REAPER > Main menu > Help > ReaScript documentation.

On Windows OS, everything is automatically installed with the extension.

On OS X, everything is automatically installed with the extension for EEL and Lua ReaScripts. For Python, just make sure to drag-drop all .py files from the installer (.dmg) into ~/Library/Application Support/REAPER/Scripts. Also, note Python scripts that use SWS functions must reside in this directory.

There is no constraints for Lua or EEL ReaScripts that use SWS functions.

Exporting your own functions to ReaScript:
If you want to export your own functions to ReaScript, see infos here.

For Python ReaScripts, you need to import "sws_python".
Note: when importing "sws_python", the modules "reaper_python" (functions exported by REAPER) and "re" (regex expressions) and are also imported for you.

Python ReaScript Example:

from sws_python import *

# adding a receive (min. 2 tracks must be selected for this example to work)
SNM_AddReceive(RPR_GetSelectedTrack(0, 0), RPR_GetSelectedTrack(0, 1), -1)

# getting a config var
RPR_ShowConsoleMsg("Ticks: %d\n" % SNM_GetIntConfigVar("miditicksperbeat", -666))

# getting/setting the source state of a take (an item must be selected for this example to work)
fastStr = SNM_CreateFastString("")
if SNM_GetSetSourceState(RPR_GetSelectedMediaItem(0, 0), -1, fastStr, False):
    RPR_ShowConsoleMsg(SNM_GetFastString(fastStr))
# set source example: clear the active take of the 1st selected item
SNM_SetFastString(fastStr, "<SOURCE EMPTY\n\n>\n")
if SNM_GetSetSourceState(RPR_GetSelectedMediaItem(0, 0), -1, fastStr, True):
    RPR_UpdateTimeline()
    RPR_Undo_OnStateChangeEx2(0, "Clear take", -1, -1);

SNM_DeleteFastString(fastStr) # you must delete strings created with SNM_CreateFastString()
You can’t perform that action at this time.