Old 11-24-2019, 07:52 PM   #1
darnskewered
Human being with feelings
 
Join Date: Nov 2019
Posts: 15
Default Any way to programmatically add media file with ReaScript?

Hi, I'm very new to Reaper, and DAWs in general, but I am a programmer so I should have no trouble once pointed to the correct api calls...

Here's all I want to do:

1) Enumerate several dozen midi files which contain nothing but a single track of piano music.

2) For each of these files, insert midi file in current project as a track.

3) Attach a VSTi instrument to the track.

4) Bounce the track to wav with the same name as the midi file.

5) Repeat until all files bounced to wav. (ideally, mp3 directly, but I can convert later if not).


ALL I am looking for right now is how to interpret the API documentation. For example, I am trying to find out just how to insert a media file programmatically. I see classes like MediaItem and MediaTrack but nowhere in the documentation says how to create these objects.

It looks like maybe I can interact with "insert media item" via an action or command #, but there's nothing in the documentation that I have interpreted as: "Here's where you put the filename parameter" etc.

Any help or guidance would be appreciated. For all I know, what I want to do can be done without scripting. I have over 700 midi files I want to automate the above process for.
darnskewered is online now   Reply With Quote
Old 11-24-2019, 08:12 PM   #2
Neutronic
Human being with feelings
 
Neutronic's Avatar
 
Join Date: Sep 2013
Posts: 398
Default

Welcome to the forum! Everything you listed can be done. Since you're a programmer it's just a matter of getting yourself familiar with the API.

Quote:
Originally Posted by darnskewered View Post
For example, I am trying to find out just how to insert a media file programmatically. I see classes like MediaItem and MediaTrack but nowhere in the documentation says how to create these objects.
Check the docs for the InsertMedia() function.

For example, to add a new track and put a MIDI file on it using LUA you would type the following:

reaper.InsertMedia("path_to_file", 1)
Neutronic is offline   Reply With Quote
Old 11-24-2019, 08:26 PM   #3
darnskewered
Human being with feelings
 
Join Date: Nov 2019
Posts: 15
Default

Quote:
Originally Posted by Neutronic View Post
Welcome to the forum! Everything you listed can be done. Since you're a programmer it's just a matter of getting yourself familiar with the API.


Check the docs for the InsertMedia() function.

For example, to add a new track and put a MIDI file on it using LUA you would type the following:

reaper.InsertMedia("path_to_file", 1)
Gah! How did I miss that? I kept searching for reasonable search terms on the REAPER API functions page and somehow didn't run across this. Thanks!
darnskewered is online now   Reply With Quote
Old 11-25-2019, 08:29 AM   #4
darnskewered
Human being with feelings
 
Join Date: Nov 2019
Posts: 15
Default

Alright, next I want to add a VSTi instrument to the track once loaded. I tried this:

reaper.InsertMedia("C:/Users/derek/Dropbox/Music/midi/2009/2009 April 08.mid", 1) --this worked
track = reaper.GetTrack(0, 0)
reaper.TrackFX_AddByName(track, "Ivory (Synthogy)", false, 0) --nothing happens

But it has no effect. I want to programmatically do what happens when I click on "FX" on the track and select a VSTi instrument from the dialog.

Last edited by darnskewered; 11-25-2019 at 08:35 AM.
darnskewered is online now   Reply With Quote
Old 11-25-2019, 08:50 AM   #5
jrengmusic
Human being with feelings
 
jrengmusic's Avatar
 
Join Date: Jun 2015
Location: Indonesia Raya
Posts: 564
Default

Perhaps it might be better to create track template with chosen VSTi loaded with its samples, presets, etc.

So, the workflow would be
  • Load track template
  • Insert MIDI file
  • Render
__________________
JRENG! | M E T R I C
jrengmusic is offline   Reply With Quote
Old 11-25-2019, 08:57 AM   #6
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 9,196
Default

Hi,

the API doc for TrackFX_AddByName() says for instantiate parameter:
Quote:
Specify a negative value for instantiate to always create a new effect, 0 to only query the first instance of an effect, or a positive value to add an instance if one is not found.
So if you put 0 there it only returns in which position of a track FX chain a specific FX is found (-1 if not found) but doesn't instantiate one.
If you put -1 (always create a new effect) or 1 (add an instance if one is not found) there it should work.

Sidenote 1:
If you haven't seen it yet, X-Raym made a nice API doc with function filtering:
https://www.extremraym.com/cloud/reascript-doc/

Sidenote 2:
You could use code tags for posting your code here for a bit easier reading and keeping the formatting.
https://forum.cockos.com/misc.php?do=bbcode#code

edit:
Good suggestion from jrengmusic I think.
For loading a track template you can use Main_openProject().

Last edited by nofish; 11-25-2019 at 09:08 AM.
nofish is offline   Reply With Quote
Old 12-02-2019, 09:47 AM   #7
darnskewered
Human being with feelings
 
Join Date: Nov 2019
Posts: 15
Default

I can't seem to get TrackFX_SetPreset to work. Here's my code:

Code:
reaper.InsertMedia("C:/Users/derek/Dropbox/Music/midi/2019/2019 November 22 01.mid", 1)
track = reaper.GetTrack(0, 0)
fx = reaper.TrackFX_AddByName(track, "Ivory (Synthogy)", false, -1)
reaper.TrackFX_SetPreset(track, fx, "Bosendorfer 225 Grand Piano")
I was however able to get the above to work with a track template as suggested:
Code:
reaper.Main_openProject("C:/Users/derek/AppData/Roaming/REAPER/TrackTemplates/improvtemplate.RTrackTemplate")
reaper.InsertMedia("C:/Users/derek/Dropbox/Music/midi/2019/2019 November 22 01.mid", 0)

Now, I'm looking for how to render out the current project. The only API call I found in the documentation which has the word render in it is this:

Quote:
boolean reaper.RenderFileSection(string source_filename, string target_filename, number start_percent, number end_percent, number playrate)

Not available while playing back.
The documentation is not very helpful. What is a file section? What is the source and target file type? Project? Start and end percent sound intuitive, but then what is playrate?

I'm tempted to say this API documentation has a bit of a case of WTFM.
darnskewered is online now   Reply With Quote
Old 12-02-2019, 12:39 PM   #8
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,690
Default

Use my ultraschall-API. I've added a full set of rendering-functions into it.

https://mespotin.uber.space/Ultrasch...1_Introduction

Doing it solely with Reaper's own API it's not easy to do, so I made these functions to make it easy to code.
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old Yesterday, 12:22 PM   #9
darnskewered
Human being with feelings
 
Join Date: Nov 2019
Posts: 15
Default

I got everything working by using autohotkey as suggested by someone here. Thanks everyone!!!!
darnskewered is online now   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 02:53 PM.


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