|
|
|
11-10-2019, 12:32 PM
|
#1
|
Human being with feelings
Join Date: Dec 2017
Posts: 118
|
Getting started with Python and Reaper
I have a few questions about Python scripting in Reaper:
1. Is it possible to access Reaper functionality through a Python library (e.g. "import reaper") instead of through Reaper's GUI?
2. How can I get a list of VSTs known by Reaper (through the directories I set previously in the GUI)?
3. Is TrackFX_AddByName the correct way to add a new track with VST? How does it look called via Python?
4. For VSTs like Reaktor, how can I load an ensemble/patch after loading the main VST? Can I access Reaktor's file menus via Reaper?
5. How can I get a list of a particular VST's parameters (controls), their current values, and their minimum and maximum acceptable values?
6. Is RPR_MIDI_InsertNote the correct way to add a note to a track? How does it look called via Python?
7. How can I render all current tracks to a stereo WAV file?
Thank you!
-da'ud vyd
|
|
|
11-10-2019, 12:55 PM
|
#2
|
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
Quote:
Originally Posted by d.vyd
I have a few questions about Python scripting in Reaper:
1. Is it possible to access Reaper functionality through a Python library (e.g. "import reaper") instead of through Reaper's GUI?
2. How can I get a list of VSTs known by Reaper (through the directories I set previously in the GUI)?
3. Is TrackFX_AddByName the correct way to add a new track with VST? How does it look called via Python?
4. For VSTs like Reaktor, how can I load an ensemble/patch after loading the main VST? Can I access Reaktor's file menus via Reaper?
5. How can I get a list of a particular VST's parameters (controls), their current values, and their minimum and maximum acceptable values?
6. Is RPR_MIDI_InsertNote the correct way to add a note to a track? How does it look called via Python?
7. How can I render all current tracks to a stereo WAV file?
|
I don't program with Python ReaScript anymore, so I can't give code examples.
1) No, Reaper does not work as a library usable from external programs. The Reaper process must be running and in the default ReaScript implementation the scripts must be run inside Reaper itself.
2) You may be able to do that by parsing the contents of the ini-files where the plugin scan results have been written in.
3) TrackFX_AddByName adds the effect to an existing track, it doesn't create new tracks for you.
4) Support for dealing with plugin presets is poor in ReaScript. Plugin menus etc are not accessible by standard ReaScript code.
5) TrackFX_GetNumParams, TrackFX_GetParamNormalized to enumerate the parameters and their current normalized values. TrackFX_GetParam may return information about the minimum and maximum values of a parameter, but it doesn't work with all plugins/formats.
6) RPR_MIDI_InsertNote is used to add a note to takes, not tracks. You need to have previously created MIDI media items and takes in them for that to work.
7) You can set the render file name etc with GetSetProjectInfo_String and then call the action "File: Render project, using the most recent render settings, auto-close render dialog" from the script. There is no official "easy" API to render projects, but the method explained should work.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
|
|
|
11-10-2019, 01:01 PM
|
#3
|
Human being with feelings
Join Date: Dec 2017
Posts: 118
|
Thanks Xenakios! Are there example Python scripts anywhere? That is disappointing about not being able to select presets in regular VSTs or load Reactor ensembles once Reaktor has been added to a track.
|
|
|
11-11-2019, 04:18 AM
|
#4
|
Human being with feelings
Join Date: Dec 2017
Posts: 118
|
I see the API command "ShowActionList", but how do you call actions via the API? I'm not sure how to call "File: Render project, using the most recent render settings, auto-close render dialog".
|
|
|
11-11-2019, 05:40 AM
|
#5
|
Human being with feelings
Join Date: Oct 2019
Location: Location: Location: Location: ###Fatal error: Interface RecursiveLocation cannot implement itself###
Posts: 40
|
You see that the actions have Command IDs in the Action List. You pass these numbers to the RPR_Main_OnCommand or RPR_Main_OnCommandEx API functions.
__________________
Studio One 5 Pro | REAPER v6
|
|
|
11-11-2019, 06:07 AM
|
#6
|
Human being with feelings
Join Date: Dec 2017
Posts: 118
|
Thank you!
|
|
|
11-11-2019, 11:42 AM
|
#7
|
Human being with feelings
Join Date: Dec 2017
Posts: 118
|
How do I run a Python script?
I have Python 3.7 installed on my Windows10 machine.
The Reaper instructions say:
https://www.reaper.fm/sdk/reascript/reascript.php
"To load a script, click ReaScript: "Load..." in the Actions window, and select the script file you want to add to the action list (multiple selection is allowed)."
I do not have a load command (see screenshot attached) and the run/edit command is for LUA/EEL only. It will not execute Python code (I tried).
|
|
|
11-11-2019, 12:11 PM
|
#8
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
|
You also need to enable your Python installation for ReaScript use (if you haven't done that already).
Here's how it looks here (though it may differ depending on Python installation), then 'python' should also show up alongside EEL and lua in the actions.
|
|
|
11-11-2019, 12:42 PM
|
#9
|
Human being with feelings
Join Date: Dec 2017
Posts: 118
|
Unfortunately, I'm running into the problems discussed below and would prefer not to create a separate environment just for Reaper if possible. I'll contact Cockos unless someone has an idea here... I keep pointing to the DLLs and Reaper crashes the second I click on an action involving scripts! I'm using an Anaconda distribution with Python 3.7 64bit on Windows. I've setup the default environment with a bunch of packages I use regularly. Reaper is also 64bit.
https://forum.cockos.com/showthread.php?t=199301
|
|
|
11-12-2019, 08:37 AM
|
#10
|
Human being with feelings
Join Date: Dec 2017
Posts: 118
|
I tried vanilla installations from python.org including Python27, Python33, and Python38. None of them worked. Sometimes Reaper crashed. Sometimes it complained that it didn't recognize the "py" extension. However, that extension is registered on my machine. I use Python everyday. I really don't understand the issue. Does it just need a Pythonxx.dll? Anything else?
Last edited by d.vyd; 11-12-2019 at 08:58 AM.
|
|
|
11-12-2019, 12:24 PM
|
#11
|
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 15,721
|
I have not yet tested with Anaconda, however I tried the following steps (successfully):
1) Installed REAPER 5.984 x64
2) Installed Python 3.8 for x86-64 via https://www.python.org/downloads/release/python-380/ -- specifically, this installer: https://www.python.org/ftp/python/3.....8.0-amd64.exe
3) Launched REAPER/x64, went to Preferences/Plug-ins/ReaScript, clicked "Enable Python", specified C:\Program Files\Python38 for the path, specified python38.dll for the specific DLL. Clicked "OK", REAPER says that we must restart REAPER.
4) Restart REAPER
5) Go to actions window, choose ReaScript: New...
6) Specify a new file, e.g. "test.py"
7) The ReaScript IDE opens, type in RPR_MB("test","thing",0)
8) Type Ctrl+S to test it
9) (script displays MessageBox)
Edit: tested with Anaconda, created an environment and pointed REAPER to that. That does indeed cause REAPER to crash, the Python library aborts with the error "unable to load the file system codec". Not sure I feel like figuring out why.
Last edited by Justin; 11-12-2019 at 01:04 PM.
|
|
|
11-12-2019, 12:51 PM
|
#12
|
Human being with feelings
Join Date: Oct 2019
Location: Location: Location: Location: ###Fatal error: Interface RecursiveLocation cannot implement itself###
Posts: 40
|
It works here with the Python 3.7 (64 bit) that Visual Studio installs for its Python dev features too.
One point is that there are two pythonX.dll files in that directory:
python3.dll 58KB
python37.dll 3661KB
I need to tell REAPER to use python37.dll in the "Force ReaScript to use specific Python dll" text box in Preferences->ReaScript. If I instead tell it to use python3.dll I get this when trying to load a script:
Quote:
Can't initialize Python.
Extension not supported "py"
|
__________________
Studio One 5 Pro | REAPER v6
|
|
|
11-12-2019, 01:06 PM
|
#13
|
Human being with feelings
Join Date: Dec 2017
Posts: 118
|
Thanks for looking into it. I'll follow your steps exactly and see if I can get it working!
EDIT: Yes, this is working now with Python38 64bit in C:\Program Files\. Thanks!
Last edited by d.vyd; 11-12-2019 at 02:21 PM.
|
|
|
11-13-2019, 01:04 AM
|
#14
|
Human being with feelings
Join Date: Feb 2014
Posts: 240
|
|
|
|
11-13-2019, 01:35 AM
|
#15
|
Human being with feelings
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,686
|
Quote:
Originally Posted by Justin
2) Installed Python 3.8 for x86-64
|
Is Beyond compatible with that version of Python ?
-Michael
|
|
|
11-13-2019, 02:54 PM
|
#17
|
Human being with feelings
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,686
|
Beyond uses the OSC protocol to provide the Reaper API as Python object to a stand alone Python program that runs on the same box or on another box connected via network.
I understand that python-reapy lives completely inside of Reaper.
-Michael
|
|
|
11-14-2019, 06:14 AM
|
#18
|
Human being with feelings
Join Date: Dec 2017
Posts: 118
|
According to python-reapy docs:
>>>You can now import reapy from inside or outside REAPER as any standard Python module.
What is the current version of Beyond? V27.zip from 2007?
|
|
|
11-14-2019, 11:39 AM
|
#19
|
Human being with feelings
Join Date: Dec 2017
Posts: 118
|
As a person familiar with Python and not familiar with Reaper's API, reapy is pretty intuitive so far. I'm able to work in the editor I prefer (Visual Studio Code) and connect to an open Reaper window!
# load Reaper library/API
import reapy
# connect to current project
project = reapy.Project()
# add a new track
project.add_track(name="drums")
|
|
|
11-16-2019, 06:34 AM
|
#20
|
Human being with feelings
Join Date: Jan 2019
Posts: 63
|
Quote:
Originally Posted by d.vyd
python-reapy looks more current, but does not claim to access the entire API.
|
The entire ReaScript API is available in reapy. If you want for instance to use RPR_APITest, you can run:
Code:
>>> import reapy.reascript_api as RPR
>>> RPR.APITest() # Or RPR.AnyReaScriptFunction()
reapy also intends to wrap the ReaScript API in a more intuitive and pythonic API. However this second API does not cover the whole ReaScript API yet, but only about a half of it.
|
|
|
11-19-2019, 12:49 PM
|
#21
|
Human being with feelings
Join Date: Dec 2017
Posts: 118
|
Is anyone finding that the notes in the MIDI take do not appear until you double-click on the MIDI take? Then I need to edit a note in the take to make all the notes appear in Reaper's main window.
|
|
|
11-24-2019, 12:54 PM
|
#22
|
Human being with feelings
Join Date: Dec 2017
Posts: 118
|
I'm finding two problems with the script I wrote below. (1) the MIDI notes are not added to the take until I manually double-click on the take to open it, see the MIDI notes, and then click one of the MIDI notes. Then, suddenly they all appear in the main Reaper window. (2) action 41824 (render project) requires a confirm button be pressed in the GUI, which freezes Python. Is there a way to automate the whole rendering process from Python?
Code:
#load Reaper library/API
import reapy
from random import randint as r, choice
class note():
def __init__(self,pitch,start,end,velocity):
self.pitch = pitch
self.start = start
self.end = end
self.velocity = velocity
def add_pattern_Reaper(pattern,channel=1):
for n in range(len(pattern)):
note = pattern[n]
take.add_note(start=note.start,end=note.end,pitch=note.pitch,velocity=note.velocity,channel=channel,unit="beats")
project = reapy.Project()
track = project.add_track(name="synth")
track.add_fx("Ultra Analog Session 2")
item = track.add_midi_item(start=0,end=12)
take = item.active_take
# (created pitches, durations, velocities, and spacings here)
pattern_01=create_pattern(0,pitches,durations,velocities,spacings,32
add_pattern_Reaper(pattern_01)
project.perform_action(41824)
Last edited by d.vyd; 11-27-2019 at 08:44 AM.
|
|
|
11-27-2019, 01:21 PM
|
#23
|
Human being with feelings
Join Date: Jan 2019
Posts: 63
|
First question:
For some reason, it seems you have to add RPR.MIDI_Sort(take.id) at the end of your script (assuming you have imported reapy.reascript_api as RPR). I'll try to add it to the reapy source code so that one does not have to do it manually after adding notes, and let you know when it's done.
Second question:
Surpisingly, there doesn't seem to be any ReaScript function for script-based rendering. So I haven't found any better option than yours... :/
|
|
|
11-28-2019, 02:03 AM
|
#24
|
Human being with feelings
Join Date: Dec 2017
Posts: 118
|
Thanks Romeo! And thanks for your work on reapy!
I'll contact Cockos with the feature request to update the "render project" API with a "just do it!" parameter that keeps the GUI out of the way.
|
|
|
05-03-2022, 06:38 AM
|
#25
|
Human being with feelings
Join Date: May 2016
Location: Kyiv, Ukraine
Posts: 544
|
what about macOS? perhaps i have to copy "python.dilyb" to "UserPlugins" directory, but i can't find it anywhere
|
|
|
05-03-2022, 08:24 AM
|
#26
|
Human being with feelings
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
|
you dont need to copy anything to userplugins folder
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 07:30 AM.
|