Skip to main content

A pythonic wrapper for REAPER's ReaScript Python API

Project description

reapy-boost

reapy is a nice pythonic wrapper around the quite unpythonic ReaScript Python API for REAPER.

the boost

This fork started as local copy for working on the repository as contributor. But since I've added a lot of functionality, that is still waits for approval (probably for an infinity), I made this fork to establish my own API.

So, I'll try to keep the fork as consistent as possible with the original repository, but while @RomeoDespres adds some own API which conflicts with API of the fork — they are going aside.

feel free to contribute!

So, the baseline and base principle of the fork is to be «boosted»: review PRs as fast as possible, and, if they makes what they declare — just put them into the project. It may produce not very consistent codebase and not so clean architecture, but it will produce a stable API that can be used in the projects of contributors.

Contents

  1. Installation
  2. Usage
  3. Contributing
  4. Author
  5. License

Installation

If you feel you need more explanation than the straightforward instructions below, head to the detailed installation guide.

reapy is available via pip:

$ pip install python-reapy

One additional step is required to let REAPER know reapy is available. First, open REAPER. Then in a terminal, run:

$ python -c "import reapy; reapy.configure_reaper()"

Restart REAPER, and you're all set! You can now import reapy from inside or outside REAPER as any standard Python module.

Instead of creating a new ReaScript containing:

from reaper_python import *
RPR_ShowConsoleMsg("Hello world!")

you can open your usual Python shell and type:

>>> import reapy
>>> reapy.print("Hello world!")

Usage

ReaScript API

All ReaScript API functions are available in reapy in the sub-module reapy.reascript_api. Note that in ReaScript Python API, all function names start with "RPR_". That unnecessary pseudo-namespace has been removed in reapy. Thus, you shall call reapy.reascript_api.GetCursorPosition in order to trigger reaper_python.RPR_GetCursorPosition. See example below.

>>> from reapy import reascript_api as RPR
>>> RPR.GetCursorPosition()
0.0
>>> RPR.SetEditCurPos(1, True, True)
>>> RPR.GetCursorPosition()
1.0

Note that if you have the SWS extension installed, the additional ReaScript functions it provides will be available in reapy.reascript_api and usable inside and outside REAPER as well.

reapy API

The purpose of reapy is to provide a more pythonic API as a substitute for ReaScript API. Below is the reapy way of executing the example above.

>>> import reapy
>>> project = reapy.Project() # Current project
>>> project.cursor_position
0.0
>>> project.cursor_position = 1
>>> project.cursor_position
1.0

The translation table matches ReaScript functions with their reapy counterparts.

Performance

When used from inside REAPER, reapy has almost identical performance than native ReaScript API. Yet when it is used from the outside, the performance is quite worse. More precisely, since external API calls are processed in a defer loop inside REAPER, there can only be around 30 to 60 of them per second. In a time-critical context, you should make use of the reapy.inside_reaper context manager.

>>> import reapy
>>> project = reapy.Project() # Current project
>>> # Unefficient (and useless) call
>>> bpms = [project.bpm for _ in range(1000)] # Takes at least 30 seconds...
>>> # Efficient call
>>> with reapy.inside_reaper():
...     bpms = [project.bpm for _ in range(1000)]
...
>>> # Takes only 0.1 second!

While reapy.inside_reaper saves time on defered calls, performance outside REAPER can be increased within method map which exsists on every notable reapy object. Within object.map("method_name", iterables={"arg_name":[<list of values>]}, defaults{"def_arg_name":value}) performance can be insreased with saving on socket connections between outside and inside scripts.

import reapy
take = reapy.Project().selected_items[0].active_take

@reapy.inside_reaper()
def test():
    for i in [6.0] * 1000000:
        take.time_to_ppq(6.0)

def test_map():
    take.map('time_to_ppq', iterables={'time': [6.0] * 1000000})

test()      # runs 140s
test_map()  # runs 12s as from outside as from inside

Documentation

Check the documentation and especially the API guide and Translation Table for more information.

Contributing

For now, about a half of ReaScript API has a reapy counterpart, the docs are far from great, and many bugs are waiting to be found. Feel free to improve the project by checking the contribution guide!

License

This project is licensed under the MIT License - see the LICENSE.txt file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reapy-boost-0.10.0.tar.gz (319.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reapy_boost-0.10.0-py2.py3-none-any.whl (375.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file reapy-boost-0.10.0.tar.gz.

File metadata

  • Download URL: reapy-boost-0.10.0.tar.gz
  • Upload date:
  • Size: 319.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.2 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/22.2.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9

File hashes

Hashes for reapy-boost-0.10.0.tar.gz
Algorithm Hash digest
SHA256 831cc551baae237c2880083e998a5c9ae5ebbe240835e40e5c51244adcbeb403
MD5 2f5569aaae81c497aa33b8c05af21127
BLAKE2b-256 75287041d4db238e31d594f916b17b8e7588fad1d4575b1ae5f0d6b47a0f1733

See more details on using hashes here.

File details

Details for the file reapy_boost-0.10.0-py2.py3-none-any.whl.

File metadata

  • Download URL: reapy_boost-0.10.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 375.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.2 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/22.2.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.9

File hashes

Hashes for reapy_boost-0.10.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1c89c629400ceef4ae1461073c7bcf80cc4169e624aeb0347e4d99553d921b6b
MD5 8ef0300ac372aa950490c25a770136b6
BLAKE2b-256 cf9314dfa096508ae5a71210250fd21ee6cc7539d683ce74238010375eca6eeb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page