Cockos Incorporated Forums reapy: a pythonic wrapper around the ReaScript API
 Register Track Bugs/Feature Requests Search Today's Posts Mark Forums Read

 04-09-2019, 04:02 AM #41 Centauria Human being with feelings   Join Date: Apr 2019 Posts: 3 Hey bro, when I ran python -m reapy, it can't find python.dll ================================================== = (py36) C:\Users\Administrator>python -m reapy D:\PF\Anaconda3\envs\py36\lib\site-packages\reapy\tools\dist_program.py:14: Disa bledDistAPIWarning: Can't reach distant API. Please start REAPER, or call reapy. config.enable_dist_api() from inside REAPER to enable distant API. warnings.warn(DisabledDistAPIWarning()) ====================== reapy config infos ====================== Python DLL ---------- Can't find python DLL... Enable or disable reapy dist API -------------------------------- Enable dist API D:\PF\Anaconda3\envs\py36\lib\site-packages\reapy\reascripts\enable_dist_api .py Disable dist API D:\PF\Anaconda3\envs\py36\lib\site-packages\reapy\reascripts\disable_dist_ap i.py ================================================== and I ran into an issue when I was trying to run enable_dist_api.py in REAPER ================================================== = Script execution error Traceback (most recent call last): File "enable_dist_api.py", line 12, in import reapy ModuleNotFoundError: No module named 'reapy' ================================================== = why can't find the module reapy? I am sure about the version of python is the one REAPER uses. Help...
 04-09-2019, 04:40 AM #42 romeo_despres Human being with feelings   Join Date: Jan 2019 Posts: 40 @nir.arad To be honest I am puzzled by your bug... I'll let you know if I find out where that comes from. @Centauria It seems you have installed reapy through Anaconda? I am not an Anaconda expert but from your traceback I am guessing REAPER might have trouble finding the path to your conda environment... Could you try running the following inside REAPER and show us the result? Code: import sys RPR_ShowConsoleMsg(sys.path)
 04-09-2019, 05:09 AM #43 Centauria Human being with feelings   Join Date: Apr 2019 Posts: 3 The output is ['C:/Users/Administrator/AppData/Roaming/REAPER/Scripts', 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64\\Lib', 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64\\DLLs', 'D:\\PF\\REAPER (x64)', 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64', 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64\\lib\\site-packages', 'D://PF//REAPER (x64)//Plugins'] thx.
 04-09-2019, 05:23 AM #44 romeo_despres Human being with feelings   Join Date: Jan 2019 Posts: 40 Thanks. So you can see that the place where reapy is located (D:\PF\Anaconda3\envs\py36\lib\site-packages) is not in sys.path by default when you run Python outside Anaconda. That explains why REAPER can't find it. You can extend sys.path permanently by creating a path configuration file. In your case, go to C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages and create a .pth file (for instance, "anaconda_env.pth") containing the following: Code: D:\PF\Anaconda3\envs\py36\lib\site-packages If I'm not missing anything about Anaconda, you should now be able to import reapy from inside REAPER and thus to enable the distant API. Last edited by romeo_despres; 04-09-2019 at 05:29 AM.
 04-09-2019, 09:27 AM #45 Centauria Human being with feelings   Join Date: Apr 2019 Posts: 3 It worked! Thank you
 04-21-2019, 12:29 PM #46 chabErch Human being with feelings   Join Date: Feb 2017 Posts: 1 Hi @romeo_despres, great work! Is it possible to run sws scripts with reapy?
 04-21-2019, 03:15 PM #47 fladd Human being with feelings     Join Date: May 2006 Posts: 969 This is great! I already thought I'm the only one who cares about pep8 :-) __________________ www.fladd.de/sound
 05-13-2019, 08:59 AM #48 romeo_despres Human being with feelings   Join Date: Jan 2019 Posts: 40 Quick update: thanks to chabErch's contribution, SWS functions can now be run from outside REAPER with reapy. More precisely, if the SWS extension is installed, then reapy.reascript_api contains all functions in sws_python; otherwise it only contains native ReaScript functions.
 05-13-2019, 10:31 AM #49 X-Raym Human being with feelings     Join Date: Apr 2013 Location: France Posts: 6,372 @romeo_despres Cool ! Does it also contains JS_ReaScript and Reapack API functions ? __________________ My ReaScripts - Premium Scripts - My Theme - Stash Files - Feature Requests - Learn ReaScript - Website - Donation - ReaComics - Scripts Custom Dev - Alien 2347
 05-14-2019, 02:48 AM #50 romeo_despres Human being with feelings   Join Date: Jan 2019 Posts: 40 I have only recently discovered these and haven't been able to make them work yet (I posted a related question recently but didn't get any reply...) But it would definitely make sense to include them as well
 05-14-2019, 03:53 AM #51 X-Raym Human being with feelings     Join Date: Apr 2013 Location: France Posts: 6,372 Ok so it is not an automatic way to load all extensions API. Thanks for the infos ! __________________ My ReaScripts - Premium Scripts - My Theme - Stash Files - Feature Requests - Learn ReaScript - Website - Donation - ReaComics - Scripts Custom Dev - Alien 2347
05-14-2019, 06:01 AM   #52
nofish
Human being with feelings

Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,500

Quote:
 Originally Posted by romeo_despres I have only recently discovered these and haven't been able to make them work yet (I posted a related question recently but didn't get any reply...) But it would definitely make sense to include them as well
Maybe post in the related threads (here and here) for them to not miss it.

05-14-2019, 06:39 AM   #53
romeo_despres
Human being with feelings

Join Date: Jan 2019
Posts: 40

Quote:
 Originally Posted by X-Raym Ok so it is not an automatic way to load all extensions API. Thanks for the infos !
That's what I was trying to do in the first place... Someday hopefully

@nofish

Thanks you're right I'll do that!

 05-14-2019, 08:01 AM #54 nofish Human being with feelings     Join Date: Oct 2007 Location: home is where the heart is Posts: 9,500 @romeo_despres Not sure if it helps, but SWS uses a Pearl script to generate the Python function wrappers: https://github.com/reaper-oss/sws/bl...ript_python.pl
 05-14-2019, 11:08 AM #55 mespotine Human being with feelings     Join Date: May 2017 Location: Leipzig, Germany Posts: 2,034 Somebody made one for JS-extension, even if it's a little outdated. Just browse through the JS-extension-thread. Maybe you can use it and update it. __________________ Pronounce me with she/her, when referencing me, please. Thanks :) Ultraschall-API - 1111 ReaScript functions for Reaper Reaper Internals - Developerdocs4Reaper
05-28-2019, 01:22 AM   #56
X-Raym
Human being with feelings

Join Date: Apr 2013
Location: France
Posts: 6,372

Quote:
 Great I'm glad it eventually worked! About your "command window" problem, I have found this which seems to answer your question (I wasn't aware of that technique and haven't tried it though).
I confirm that running a reapy script on windows by double cliking on it on WIndows is possible without having CMD window by having extension set to .pyw instead of .py.

--
Here is a minimal tkinter code snippet for reapy:

https://github.com/ReaTeam/ReaScript...er%20reapy.pyw

It is not extra quick to launch (count 1-2 seconds), I don't know if it is reapy limitation or just python. Script run from action list are quicker (but they still keyboard focus).

05-28-2019, 02:58 AM   #57
romeo_despres
Human being with feelings

Join Date: Jan 2019
Posts: 40

Quote:
 Originally Posted by X-Raym It is not extra quick to launch (count 1-2 seconds), I don't know if it is reapy limitation or just python. Script run from action list are quicker (but they still keyboard focus).
On my computer, both are quite slow: starting Python itself, but also importing reapy from outside REAPER. It indeed requires several interactions with the REAPER Web Interface, which is pretty slow.

05-28-2019, 04:07 AM   #58
X-Raym
Human being with feelings

Join Date: Apr 2013
Location: France
Posts: 6,372

Quote:
 On my computer, both are quite slow: starting Python itself, but also importing reapy from outside REAPER. It indeed requires several interactions with the REAPER Web Interface, which is pretty slow.

It is not that a problem if the scripts seems complex (like have a nice polish GUI with lots of elements), but it really feels not good if it is just a single user input.

But I don't think anything can be done on this so we'll live with it.
It still have a lot of advantage compare to native way (like allowing all kind of python dependencies and not stealing keyboard focus).

 05-28-2019, 05:21 AM #59 romeo_despres Human being with feelings   Join Date: Jan 2019 Posts: 40 Indeed one probably has to wonder which option is best depending on the complexity of the program. For a simple user input, I guess it's better to use the ReaScript function "GetUserInputs" from inside REAPER. It makes me realize there is no reapy counterpart to this function, which is once again not very easy to use for a standard Python programmer... I'll try to add one soon!
06-06-2019, 01:38 AM   #60
Kostik Vento
Human being with feelings

Join Date: Nov 2013
Location: Yekaterinburg, Russia
Posts: 11

Quote:
 Originally Posted by romeo_despres I think this project can become interesting only if other people in the community provide feedback and improvement, on the code itself as well as the documentation, structure, etc. So please don't hesitate to try it out and report bugs or missing features. And if you feel like coding yourself, feel free to fork the repository! As a Python ReaScripter, I know you dream like me of a well-established community-based REAPER API!
That's about me)) I like both Python and Reaper, I do dream, so I've forked ))
And I do have some suggestions about improvements, would you prefer to discuss them here or on GitHub?

Quote:
 Originally Posted by romeo_despres P.P.S. reapy should be cross-platform but since I have only tested it on Windows I couldn't swear. Yet I do think this is an important feature. We all love REAPER for Linux.
I've tried on MacOSX Sierra, it works fine for me. There are, still, minor bugs, I've opened pull requests for them, hope to see them reviewed soon))
And there's a serious bug I've almost run into — if your reaper.ini contains non-ASCII chars, rewriting config would crash half-way with the rest of your settings gone( My luck was to have the file opened in a text editor which had the full copy of the lost contents.

P.S. I made it work under Python2 (except enable/disable_dist_api), but the resulting code lost its pythonicity a bit, so I'll keep refactoring. And alas, you can't use reapy.print in Python2 because print is reserved there and cannot be used as identifier.

Last edited by Kostik Vento; 06-06-2019 at 01:54 AM.

 06-06-2019, 05:41 AM #61 romeo_despres Human being with feelings   Join Date: Jan 2019 Posts: 40 Thank you a lot for your help! I think the simplest is to communicate on GitHub as you did. I've seen your requests but been very busy lately so I haven't been able to review them in detail... But they seem to fix a lot of important issues! I'll try to reply to you asap there
 10-03-2019, 03:10 PM #62 tparker24 Human being with feelings   Join Date: Dec 2017 Posts: 56 How invoke? I'm a little confused on how to invoke the python script that uses reapy. I actually want the script to run OUTSIDE of Reaper, but I want to be able to invoke the script from WITHIN Reaper, say via an Action item (or a Button and/or a shortcut). Would I need a small script to call it, that just runs maybe one of these: ExecProcess() or reaper.CF_ShellExecute() and supplying the full path name to my python script, e.g. Code: ExecProcess("C:\some\path\to\my_python_script.py") Or am I making this too hard?
 10-06-2019, 09:23 AM #63 romeo_despres Human being with feelings   Join Date: Jan 2019 Posts: 40 I think you're right, the correct way to do that would be to have two scripts, one that runs inside REAPER and looks like: Code: RPR_ExecProcess('py path/to/external_script.py', -1) and a second one (external_script.py) which is the actual reapy app.
10-06-2019, 10:01 AM   #64
tparker24
Human being with feelings

Join Date: Dec 2017
Posts: 56

Ok, thanks for confirming.

I've just started using reapy, and I'm very impressed! It was easy to install and seems very straightforward to use. Running python outside of Reaper really opens up some possibilities, because some python things don't run too well (or at all) inside the Reaper environment ... for example PyQt or wXPthon, two powerful GUI programs.

reapy kind of unleashes python. Thanks for making it available.

Quote:
 Originally Posted by romeo_despres I think you're right, the correct way to do that would be to have two scripts, one that runs inside REAPER and looks like: Code: RPR_ExecProcess('py path/to/external_script.py', -1) and a second one (external_script.py) which is the actual reapy app.

 10-10-2019, 11:33 AM #65 tparker24 Human being with feelings   Join Date: Dec 2017 Posts: 56 reapy.Project.n_selected_tracks I thought reapy.Project.n_selected_tracks was supposed to return an integer, but I'm getting a property object instead: Code: Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import reapy >>> reapy.Project.n_selected_tracks  BTW, I get the exact same output, if there are 0, 1, or more tracks selected.
 10-10-2019, 12:07 PM #66 tparker24 Human being with feelings   Join Date: Dec 2017 Posts: 56 reapy.Project.n_selected_tracks I got it to work by adding some parens: Code: >>> reapy.Project().n_selected_tracks 1 Or another way: Code: >>> my_project = reapy.Project() >>> my_project.n_selected_tracks 1
 10-10-2019, 04:13 PM #67 tparker24 Human being with feelings   Join Date: Dec 2017 Posts: 56 play_state problem This might be a little bug: Code: File if project.play_state == "pause": File "C:\Users\Tom Parker\AppData\Local\Programs\Python\Python37\lib\site-packages\reapy\core\project\project.py", line 690, in play_state state = states[RPR.GetPlayStateEx(self.id)] KeyError: 0
 10-10-2019, 05:49 PM #68 tparker24 Human being with feelings   Join Date: Dec 2017 Posts: 56 Track objects I've noticed that reapy uses a slightly different format for the track object than does RPR: Code: project.get_selected_track() Track("(MediaTrack*)0x000000000395E870") # reapy RPR.GetSelectedTrack(0,0) (MediaTrack*)0x000000000395E870 # RPR And Reaper doesn't like the reapy format, for example: Code: x = RPR.GetSelectedTrack(0,0) # RPR format of track_id RPR.GetMediaTrackInfo_Value(x, 'IP_TRACKNUMBER') # Returns the correct 10.0 x = project.get_selected_track() # reapy format of track_id RPR.GetMediaTrackInfo_Value(x, 'IP_TRACKNUMBER') # Returns incorrect 0 This causes me a little problem, because I have to use some reapy and some RPR. In particular, there are no direct reapy counterparts for RPR.NF_GetSWSTrackNotes and RPR.NF_SetSWSTrackNotes. So to use those two, I guess I will have to first get the RPR form of track id, using RPR.GetSelectedTrack(0,0). Just a small annoyance, but something to be aware of. Do I have this right?
 10-10-2019, 11:12 PM #69 mschnell Human being with feelings     Join Date: Jun 2013 Location: Krefeld, Germany Posts: 8,648 Is Romeo still with us ? Will Reapy be able to replace Beyond so that the Pyton API is identical for internal Reaper (script) use as for external/networked Beyond-alike access to Reaper ? Can/will Reapy be released and documented via ReaPack ? -Michael __________________ http://www.boa-sorte.de, http://www.bschnell.de/b
 10-11-2019, 10:42 AM #70 tparker24 Human being with feelings   Join Date: Dec 2017 Posts: 56 Sockets? 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: ResourceWarning: unclosed  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() ?
 10-12-2019, 11:50 AM #71 jahudka Human being with feelings   Join Date: Jul 2010 Posts: 36 Sends & receives & envelopes @tparker24, just as a side note about the compatibility of reapy.Track and the native MediaTrack - the native MediaTrack object should be available as track.id if I'm reading reapy source well - so you should be able to do this: Code: x = project.get_selected_track() RPR.GetMediaTrackInfo_Value(x.id, 'IP_TRACKNUMBER') Anyway, I wanted to ask about APIs for track send / receive envelopes. When I'm working on a larger project with lots of aux busses for stuff like reverbs and delays I often need to toggle visibility for a lot of send volume envelopes, preferably with a single keystroke. I've tried writing a ReaScript for that, but I'm stuck because the ReaScript API doesn't have nice methods for working with send / receive envelopes' states - there is just the RPR_SetEnvelopeStateChunk method for setting the state as XML, but that's just such a pain to work with.. So I'd like to ask if you have any pointers about working with the XML chunk (like a documentation link), and also suggest a couple of features for reapy which would allow me to do this (and which might be of interest to others as well): Implement __eq__ magic methods throughout the API to allow checking object identity ("is this track from project.tracks the same as this track from project.selected_tracks?") Add reapy.Track.receives (now there's only Track.sends, which I believe doesn't include receives) Add methods to reapy.Envelope to allow changing envelope state (active, visible, armed) Add reapy.Send.envelopes and reapy.FX.envelopes - those two would be awesome, but also I think they'd be the hardest to implement, because from the ReaScript perspective there's no such thing as a send's envelope - it's the track's envelope - so I think these envelope lists should somehow proxy and filter the owning track's envelopes list (but not sure how you'd do that since I'm not sure you can check that a given track's envelope actually corresponds to a given send's or effect's parameter) Also I'm loving this API! Truly amazing work, sir, even though I'm not all too proficient in Python I can appreciate how much easier it would be to develop custom actions and extensions using reapy than the native API. Thank you for all the time and effort you're putting into this!
10-12-2019, 02:33 PM   #72
tparker24
Human being with feelings

Join Date: Dec 2017
Posts: 56
Track objects

Quote:
 Originally Posted by jahudka @tparker24, just as a side note about the compatibility of reapy.Track and the native MediaTrack - the native MediaTrack object should be available as track.id if I'm reading reapy source well - so you should be able to do this: Code: x = project.get_selected_track() RPR.GetMediaTrackInfo_Value(x.id, 'IP_TRACKNUMBER')

@jahudka,

Yes, indeed, that did it! Thank you very much!

 11-21-2019, 11:35 AM #73 kkecm Human being with feelings   Join Date: Nov 2019 Posts: 2 Inserting points in envelope or automatizing fx Reapy is running seamlessly so far and has a lot of functionality. Thanks for this great contribution! @romeo_despres I was able to extract all envelope values from Reaper from outside. However when I try to do the inverse process (modify the envelopes from an external script) there is no change at all. I understand that reascript_api.InsertEnvelopePoint cannot be invoked from outside as this is a dynamic library. Then I tried to set the cursor_position at some value, change the automation mode to write and modify the fx parameter. This action moves the knob but no point is inserted until I make the Reaper window active again. However, as I want to insert multiple points along the envelope this methods is not useful. After setting the fx parameter at multiple cursor positions and coming back to the Reaper window the only envelope point inserted is the corresponding to the last value. Is there any other way to write to an envelope from Reapy? Or in the worst case, is there any method to keep the Reaper window active? I tried to change the automatization mode inside the loop, selecting tracks with no luck. Thanks!
11-23-2019, 02:50 PM   #75
mschnell
Human being with feelings

Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 8,648

Quote:
 Originally Posted by romeo_despres @mschnell I'm not entirely sure I understand your question. I believe reapy can already replace Beyond. In which case would it not?
Maybe I am wrong. I understand that reapy provides the Reaper API for Python scrips that work called up (and hence internal of) Reaper, While Beyond provides the Reaper API for stand alone Python programs that are to be connected to Reaper (running on the same or on a different PC) via Network (i.e. tunneled through the OSC protocol).

So they target different purposes.

-Michael

 11-24-2019, 09:36 AM #76 romeo_despres Human being with feelings   Join Date: Jan 2019 Posts: 40 No, ReaScript functions can also be run from outside REAPER with reapy (they are available in reapy.reascript_api). For now, reapy can only control a REAPER instance that is on the same computer, but I'm currently working on extending this to include distant slave machines.
11-24-2019, 11:50 AM   #77
mschnell
Human being with feelings

Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 8,648

Quote:
 Originally Posted by romeo_despres For now, reapy can only control a REAPER instance that is on the same computer,
What communication protocol is used between the Reaper instance and the Python program that is running separate from Reaper ?

-Michael

 11-24-2019, 01:00 PM #78 d.vyd Human being with feelings   Join Date: Dec 2017 Posts: 69 Hi Folks, Looks like this is the correct place to post about reapy. I've been posting code here: https://forum.cockos.com/showthread....69#post2206669. I'm glad I found you folks! I'm using reapy in Visual Studio Code. I've encountered two problems: (1) MIDI notes do not show up in the main Reaper window until I double click on the take and click on a note. (2) rendering the project pops up a GUI window, which prevents me from automating everything via Python. Can anyone offer ideas for how to overcome these issues? -da'ud vyd
11-24-2019, 02:27 PM   #79
romeo_despres
Human being with feelings

Join Date: Jan 2019
Posts: 40

Quote:
 Originally Posted by mschnell What communication protocol is used between the Reaper instance and the Python program that is running separate from Reaper ?
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.

 11-24-2019, 02:28 PM #80 romeo_despres Human being with feelings   Join Date: Jan 2019 Posts: 40 @d.vyd I'll take a look as soon as i can and let you know what I've found. EDIT: Done on the original thread. Last edited by romeo_despres; 11-27-2019 at 01:22 PM.

 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 BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home REAPER Forums     REAPER General Discussion Forum     newbieland     REAPER Q&A, Tips, Tricks and Howto     Recording Technologies and Techniques     REAPER Compatibility     REAPER Color Themes and Icon Sets     MIDI Hardware, Control Surfaces, and OSC     REAPER Non-English Speaking User Forums         Forum de REAPER en français         Foro de REAPER en Español         Fórum do REAPER em português         Forum di REAPER in italiano         Deutschsprachiges REAPER Userforum         Pyccкоязычный фopyм REAPER     REAPER Bug Reports     REAPER Feature Requests     Dstruct's Casa De Nitpicks     REAPER for Live Use     REAPER for Video Editing/Mangling     REAPER for Ambisonic and 3D positional audio uses     ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum     REAPER for macOS X     REAPER for Linux     REAPER Pre-Release Discussion     REAPER Music/Collaboration Discussion NINJAM Discussion     NINJAM User Discussion     NINJAM Developer Discussion Other Software Discussion     WDL users forum     LICEcap Discussion     OSCII-bot forum     Old Cockos Products Forum

All times are GMT -7. The time now is 01:24 PM.

 -- Cockos ---- REAPER 5 ---- Reaper 3 ---- Reaper 2 ---- Reaper 1 Contact Us - Çockos Incorporated - Archive - Top