Old 11-24-2019, 02:46 PM   #81
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 8,648
Default

Quote:
Originally Posted by romeo_despres View Post
It's just JSON messages sent over the local network. Outer-reapy tells inner-reapy which fonctions it needs him to call, then inner-reapy sends the results back to outer-reapy.
I see. This in fact is rather similar to beyond. Only that beyond uses OSC instead of JSON.

I do know that OSC (close to always) uses UDP as a transport. What transport layer does reapy use to send JSON messages ?

-Michael
mschnell is offline   Reply With Quote
Old 11-25-2019, 01:50 AM   #82
romeo_despres
Human being with feelings
 
Join Date: Jan 2019
Posts: 40
Default

Indeed it is very similar. I've decided to recode it myself rather than just reuse Beyond mostly because I didn't like the way Beyond fills builtins with global variables without being asked to. Quite a creative choice, but not my cup of tea

I think reapy uses TCP... I don't know much about networking though so I might be wrong!...
romeo_despres is offline   Reply With Quote
Old 11-25-2019, 09:10 AM   #83
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 8,648
Default

Quote:
Originally Posted by romeo_despres View Post
I think reapy uses TCP...
Then it would be no problem at all to use it across two networked boxes.

-Michael
mschnell is offline   Reply With Quote
Old 11-25-2019, 11:27 AM   #84
kkecm
Human being with feelings
 
Join Date: Nov 2019
Posts: 2
Default

Quote:
Originally Posted by romeo_despres View Post
Why exactly do you not want to use reapy.reascript_api.InsertEnvelopePoint? I do agree that it would be better to have a nicer function for this purpose, but it should still work, even from the outside.
Thanks for the quick response. In fact reapy.reascript_api.InsertEnvelopePoint works after I realized that the envelopes and tracks must be all obtained with reascript_api and not with reapy. reapy.Project().tracks[0] is not at the same level than reapy.reascript_api.GetTrack(0, 0).
kkecm is offline   Reply With Quote
Old 11-25-2019, 02:09 PM   #85
romeo_despres
Human being with feelings
 
Join Date: Jan 2019
Posts: 40
Default

@mschnell

Indeed, that's why I've started doing it!

@kkecm

The objects that ReaScripts functions take as arguments are string identifiers. You can access them with the id property of reapy objects.

In your case, you could do:

Code:
import reapy
import reapy.reascript_api as RPR

t = reapy.Project().tracks[0]
RPR.InsertEnvelopePoint(t.id, ...)
romeo_despres is offline   Reply With Quote
Old 11-27-2019, 01:14 PM   #86
tparker24
Human being with feelings
 
Join Date: Dec 2017
Posts: 56
Default

Quote:
Originally Posted by tparker24 View Post
If my python script (running outside of Reaper) has certain problems, I do a sys.exit() to terminate the script. When that happens I get the following:

Code:
Exception ignored in: <socket.socket fd=488, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 50268), raddr=('127.0.0.1', 2306)>
ResourceWarning: unclosed <socket.socket fd=488, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 50268), raddr=('127.0.0.1', 2306)>
I'm wondering if this might be related to reapy. If so, do I need to somehow shutdown reapy more gracefully, before I sys.exit() ?
I now think it was self-inflicted, because I had
Code:
warnings.filterwarnings("error")
tparker24 is offline   Reply With Quote
Old 12-29-2019, 03:47 AM   #87
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 8,648
Default

I have a developing project that sleeps since many month.

I did this as a suite of JSFXes. But as this is not a realtime thingy, I think It would be a good idea to use ReaScript Python or an external Python (via Reapy) for some complex "offline" calculation and data handling.

Does Reapy already provide a kind of "library" for communicating with JSFXes ?

If there is not, I can do something myself, but of course I would like to work together with the Reapy team on such basic stuff.

-Michael
mschnell is offline   Reply With Quote
Old 01-03-2020, 03:44 PM   #88
romeo_despres
Human being with feelings
 
Join Date: Jan 2019
Posts: 40
Default

Quote:
Originally Posted by mschnell View Post
I have a developing project that sleeps since many month.

I did this as a suite of JSFXes. But as this is not a realtime thingy, I think It would be a good idea to use ReaScript Python or an external Python (via Reapy) for some complex "offline" calculation and data handling.

Does Reapy already provide a kind of "library" for communicating with JSFXes ?

If there is not, I can do something myself, but of course I would like to work together with the Reapy team on such basic stuff.

-Michael
I'm not sure what "communicating with JSFX" means. What kind of information would you like to exchange between a python script and a JSFX? What you can do so far with reapy is control the FX parameters (as for any FX), is it relevant to you?
romeo_despres is offline   Reply With Quote
Old 01-04-2020, 07:52 AM   #89
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 2,034
Default

Quote:
Originally Posted by mschnell View Post
I have a developing project that sleeps since many month.

I did this as a suite of JSFXes. But as this is not a realtime thingy, I think It would be a good idea to use ReaScript Python or an external Python (via Reapy) for some complex "offline" calculation and data handling.

Does Reapy already provide a kind of "library" for communicating with JSFXes ?

If there is not, I can do something myself, but of course I would like to work together with the Reapy team on such basic stuff.

-Michael
AFAIK, there's no gmem-access in Python, only in EEL2, LUA, VideoProcessor and JSFX. So the answer is probably no.
__________________
Pronounce me with she/her, when referencing me, please. Thanks :)
Ultraschall-API - 1111 ReaScript functions for Reaper
Reaper Internals - Developerdocs4Reaper
mespotine is offline   Reply With Quote
Old 01-04-2020, 03:02 PM   #90
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 8,648
Default

Quote:
Originally Posted by romeo_despres View Post
I'm not sure what "communicating with JSFX" means. What kind of information would you like to exchange between a python script and a JSFX? What you can do so far with reapy is control the FX parameters (as for any FX), is it relevant to you?
External python programs doable with reapy live in their own application thread.

Scripts live in the Reaper GUI Thread.

JSFXes live in the realtime thread associated with the appropriate thread.

That is why each of those have their own implications regarding performance / latency / ability to access certain APIs, libraries, etc. Hence it sometimes makes sense (or even is required) to do some of the functionality of a complex propram in a dedicated of these environments.

AFAIU, there is a shared memory that can be accessed by both scripts and JSFXes. This is a nice basis for splitting functionality between scripts and JSFXes. Moreover we need triggers to mutually signal events (to do full blown remote procedure calls or more basic stuff). This can be done e.g. by a JSFX sending a message via MidiToReaControlPath to trigger an action and with that a scrip. or a script move a slider of a JSFX.

It would be great to have a formalized tool set for all this and an appropriate libary for JSFX and reapy that provides functions for such functionality.

-Michael
mschnell is offline   Reply With Quote
Old 01-04-2020, 03:06 PM   #91
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 8,648
Default

Quote:
Originally Posted by mespotine View Post
AFAIK, there's no gmem-access in Python, only in EEL2, LUA, VideoProcessor and JSFX. So the answer is probably no.
That would be very bad !
I seem to remember that gmem access for scripts (ELL and LUA) has been added not too long ago. Has the Python API for this really been forgotten ? If so this decently needs needs to be mended.
-Michael
mschnell is offline   Reply With Quote
Old 03-03-2020, 09:45 AM   #92
RCJacH
Human being with feelings
 
Join Date: Apr 2016
Location: Beijing, China
Posts: 170
Default

I have a quick question.
As you mentioned, reaper crashes when trying to import numpy. What's the reapy's way to solve this problem? Do we have to write a server side and a (local) client side of the script and run them separately?
RCJacH is offline   Reply With Quote
Old 03-03-2020, 11:47 AM   #93
romeo_despres
Human being with feelings
 
Join Date: Jan 2019
Posts: 40
Default

The reapy way of solving that is to run your script outside REAPER, just as any Python script. As all ReaScript functions become available outside REAPER via reapy.reascript_api, there is (hopefully) nothing you can do with Python inside REAPER that you can not do outside using reapy.

Is that clear enough? If you tell me more about why you need client and server parts of your script, I can maybe help you with adapting it to reapy.
romeo_despres is offline   Reply With Quote
Old 03-03-2020, 02:12 PM   #94
RCJacH
Human being with feelings
 
Join Date: Apr 2016
Location: Beijing, China
Posts: 170
Default

I see, thanks for the explanation, that clears things up.

I'm trying to incorporate Magenta into my production workflow, and doing so with local script freezes reaper. Although it works using beyond.reaper (I don't know how it manages to pass reaper scripts to a local server since the source code is way beyond my py-fu level), but as you said, it's a bit slow and the API isn't pythonic. I guess I need to code up a Magenta Studio like interface to use it outside of reaper.


Just for information. I tried writing a script to run inside reaper that launches an external file, and here's the result:

1. I successfully launched another reaper.exe with the following code:
Code:
import os
path = os.path.join(os.getcwd(), "reaper.exe")
os.startfile(path)
This also works for opening a directory with the default file explorer.

2. I wrote another py file to test crash and file action, and for simplicity put it in the same folder as reaper.exe:
Code:
# external_py.py
import numpy

with open("test.txt", mode="w") as f:
    f.write(str(numpy))
Using os.startfile as mentioned above does not create that test.txt.

What worked is the following:
Code:
path = os.path.join(os.getcwd(), "external_py.py")
os.system('pyenv exec python -m external_py.py')
Note: I have numpy in a dedicated python 3.7 thus the "pyenv exec" before "python".


3. Using exec(open(path).read()) crashes reaper, it's the same as importing the external_py as a module.
RCJacH is offline   Reply With Quote
Old 03-05-2020, 10:42 AM   #95
romeo_despres
Human being with feelings
 
Join Date: Jan 2019
Posts: 40
Default

Looks nice, thanks for the explanation. Good to know your third snippet works. Note however that it will freeze REAPER until external.py is done running. Thus if you need cpu-expensive deep learning scripts (as I guess Magenta uses), or if you want some kind of GUI, you would be better off running your scripts entirely from outside REAPER. Is it because you want to trigger scripts with keyboards shortcuts that you still run them from inside REAPER (with the os.system trick)?
romeo_despres is offline   Reply With Quote
Old 03-13-2020, 09:21 AM   #96
RCJacH
Human being with feelings
 
Join Date: Apr 2016
Location: Beijing, China
Posts: 170
Default

Yeah, I would like to open designated GUIs with short-cuts or toolbar buttons, but I can settle with opening the software externally if that fails.

I noticed that when launching reaper with os.system("reaper.exe"), a cmd.exe window pops up and freezes the original reaper until manually closing the command prompt window.

However using os.startfile solves that issue. A new reaper window is started without freezing the original reaper window. Unfortunately it only works in windows.

After a bit of searching, I found out that the following code works without freezing reaper.

Code:
import subprocess
subprocess.Popen("reaper.exe")
I might need to think about how this works with detecting which python env is needed to run the script, so it might not work as well as intended. However this might work if a package is compiled into an application.

I also confirmed that python v3.8 works when using reapy externally, however only 3.7 can be detected by reaper. (and unfortunately magenta only supports 3.7 currently).


A question, I am currently trying to add more ReaScript APIs (especially MIDI related ones) into reapy. I have also read the CONTRIBUTING.md and the log convention. I see a lot of .pyi files there, are they actually useful for the package or are they created by pycharm or something? I normally use vscode, do I need to manually update .pyi files as well when I made a change to a .py file?

Last edited by RCJacH; 03-13-2020 at 09:28 AM.
RCJacH is offline   Reply With Quote
Old 03-13-2020, 01:28 PM   #97
TonE
Human being with feelings
 
Join Date: Feb 2009
Location: Reaper HAS send control via midi !!!
Posts: 2,300
Default

You can use any command line program via python in Reaper as actions.

Here one example how you can run even .ahk programs directly without needing to compile them to .exe first.

PHP Code:
import subprocess
subprocess
.Popen(r'C:/ahk/AutoHotkey.exe "C:/Program Files/REAPER/Scripts/your/magic_ahk_script_uncompiled_improve_edit_as_often_as_you_want.ahk"'
Maybe we should start a new thread where we collect interesting command line musical tools, worth combining with Reaper, we have the freedom to do so anyway, thanks to the devs futuristic vision. Any command line can be an internal action inside Reaper, what else one would want? What does Cubase give instead? 20 GB downloads.

UPDATE: Thread created, see https://forum.cockos.com/showpost.ph...55&postcount=1

Last edited by TonE; 03-13-2020 at 01:37 PM.
TonE is offline   Reply With Quote
Old 03-13-2020, 01:36 PM   #98
RCJacH
Human being with feelings
 
Join Date: Apr 2016
Location: Beijing, China
Posts: 170
Default

Quote:
Originally Posted by TonE View Post
You can use any command line program via python in Reaper as actions.

Here one example how you can run even .ahk programs directly without needing to compile them to .exe first.

PHP Code:
import subprocess
subprocess
.Popen(r'C:/ahk/AutoHotkey.exe "C:/Program Files/REAPER/Scripts/your/magic_ahk_script_uncompiled_improve_edit_as_often_as_you_want.ahk"'
Maybe we should start a new thread where we collect interesting command line musical tools, worth combining with Reaper, we have the freedom to do so anyway, thanks to the devs futuristic vision. Any command line can be an internal action inside Reaper, what else one would want? What does Cubase give instead? 20 GB downloads.

Well the problem is when the python version or venv you wish to run script with is not the same as your global one that gets triggered by the command line. Even worse when you need the package to run on multiple systems across different OS with perhaps different path to the package lol...
RCJacH is offline   Reply With Quote
Old 03-13-2020, 01:43 PM   #99
TonE
Human being with feelings
 
Join Date: Feb 2009
Location: Reaper HAS send control via midi !!!
Posts: 2,300
Default

Quote:
Originally Posted by RCJacH View Post
Well the problem is when the python version or venv you wish to run script with is not the same as your global one that gets triggered by the command line. Even worse when you need the package to run on multiple systems across different OS with perhaps different path to the package lol...
My use case is where every user creates something for themselves. Take anything, make it a Reaper action. Of course the path has to exist on your computer. If there is no other standard, then one solution could be requiring the command line programs to be available in some Reaper subdirectory, e.g. in Scripts/command_line_tools/lowkey.exe (for example)

Your tool should require minimal versions if possible, so it should work with as old versions as possible.
TonE is offline   Reply With Quote
Old 03-18-2020, 03:01 AM   #100
romeo_despres
Human being with feelings
 
Join Date: Jan 2019
Posts: 40
Default

Quote:
Originally Posted by RCJacH View Post
A question, I am currently trying to add more ReaScript APIs (especially MIDI related ones) into reapy. I have also read the CONTRIBUTING.md and the log convention. I see a lot of .pyi files there, are they actually useful for the package or are they created by pycharm or something? I normally use vscode, do I need to manually update .pyi files as well when I made a change to a .py file?
.pyi files are type hints. If you run python with a typechecker, such as mypy, these files will be used to enforce type consistency.

In order to allow anyone to contribute, type hinting is not mandatory for now. In other words, you can contribute to .py files only, and we'll be very happy with it Maybe your pull request will be edited to add type hinting, or maybe it will simply be done later.

Thanks for making me realize this should be addressed in the contributing guide. I'll try to add it soon!
romeo_despres is offline   Reply With Quote
Old 03-25-2020, 03:11 PM   #101
dimentorium
Human being with feelings
 
Join Date: Jan 2020
Posts: 21
Default

Hello romeo,
I am currently working on some python stuff in reaper and heavily using your API. Really nice work!!

One idea I wanted to ask for is, to include the RPP library for parsing and changing the project file.
https://github.com/Perlence/rpp

With that you can change the rendering settings in the file or export reaper presets programatically.
dimentorium is offline   Reply With Quote
Old 03-27-2020, 01:03 PM   #102
romeo_despres
Human being with feelings
 
Join Date: Jan 2019
Posts: 40
Default

Quote:
Originally Posted by dimentorium View Post
Hello romeo,
I am currently working on some python stuff in reaper and heavily using your API. Really nice work!!

One idea I wanted to ask for is, to include the RPP library for parsing and changing the project file.
https://github.com/Perlence/rpp

With that you can change the rendering settings in the file or export reaper presets programatically.
Hi, it's very nice to hear, thanks I had never heard of this project before but it seems pretty cool! Why exactly would you need to see it included in reapy? Don't they simply complement one another?
romeo_despres is offline   Reply With Quote
Old 03-28-2020, 03:08 PM   #103
dimentorium
Human being with feelings
 
Join Date: Jan 2020
Posts: 21
Default

Hello romeo,

you are tight, they definately complement. Just thought this might be useful to add rendering functionality to reapy.

Also did some testing because I was looking for a way to read and set custom presets for VSTIs. By using the chunk function and RPP this seems to work well. Until now I did not find a good way to set or read patches programmatically (except vstpreset).

import reapy
import rpp

#get references
project = reapy.Project()
vst_track = project.tracks[0]

#load configuration from first track
vst_track_chunk = reapy.reascript_api.GetTrackStateChunk(vst_track.i d,"",8192,False)
vst_track_chunk_parsed = rpp.loads(vst_track_chunk[2])
tag_fx = vst_track_chunk_parsed.find("FXCHAIN")
tag_vst = tag_fx.find("VST")

#reference 2nd track
track2 = project.tracks[1]
track2_chunk = reapy.reascript_api.GetTrackStateChunk(track2.id," ",8192,False)
track2_chunk_parsed = rpp.loads(track2_chunk[2])
#add vsti configuration from 1st track
track2_chunk_parsed.append(tag_fx)
#convert to writeable chunk
new_chunk = rpp.dumps(track2_chunk_parsed)
#set new chunk
reapy.reascript_api.SetTrackStateChunk(track2.id,t est[2],False)
dimentorium is offline   Reply With Quote
Old 03-30-2020, 01:44 PM   #104
dimentorium
Human being with feelings
 
Join Date: Jan 2020
Posts: 21
Default

Hi romeo,
one other question, maybe you have an idea.
Is there a way to communicate from reaper to reapy? I would like to send a command from a button to my python application. At current I have the problem that my application does not load within reaper, so I probably need to use osc or comparable.
dimentorium is offline   Reply With Quote
Old Yesterday, 04:16 AM   #105
mcannon
Human being with feelings
 
Join Date: Mar 2020
Posts: 2
Default

I can't get this to work and I'm assuming it's because I can't get Reaper to use the right version of Python (3.8.2).

I've tried adding a symlink to libpython.dylib but the terminal comes back with 'operation not permitted'.

any ideas on how to get Reaper to run the correct version?
mcannon is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 12:10 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.