|
|
|
11-24-2019, 07:52 PM
|
#1
|
Human being with feelings
Join Date: Nov 2019
Posts: 16
|
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.
|
|
|
11-24-2019, 08:12 PM
|
#2
|
Human being with feelings
Join Date: Sep 2013
Posts: 657
|
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
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)
|
|
|
11-24-2019, 08:26 PM
|
#3
|
Human being with feelings
Join Date: Nov 2019
Posts: 16
|
Quote:
Originally Posted by Neutronic
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!
|
|
|
11-25-2019, 08:29 AM
|
#4
|
Human being with feelings
Join Date: Nov 2019
Posts: 16
|
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.
|
|
|
11-25-2019, 08:50 AM
|
#5
|
Human being with feelings
Join Date: Jun 2015
Location: Indonesia Raya
Posts: 684
|
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
|
|
|
11-25-2019, 08:57 AM
|
#6
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,110
|
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.
|
|
|
12-02-2019, 09:47 AM
|
#7
|
Human being with feelings
Join Date: Nov 2019
Posts: 16
|
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.
|
|
|
12-02-2019, 12:39 PM
|
#8
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,630
|
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.
|
|
|
12-14-2019, 12:22 PM
|
#9
|
Human being with feelings
Join Date: Nov 2019
Posts: 16
|
I got everything working by using autohotkey as suggested by someone here. Thanks everyone!!!!
|
|
|
07-16-2020, 05:05 AM
|
#10
|
Human being with feelings
Join Date: May 2020
Posts: 4
|
Quote:
Originally Posted by Neutronic
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)
|
Thank soooooo much!! That InsertMedia() function is so useful!!!!
|
|
|
06-27-2023, 03:04 PM
|
#11
|
Human being with feelings
Join Date: Jun 2023
Posts: 14
|
Quote:
Originally Posted by Neutronic
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)
|
I'm going to ressurect this thread, as I'm having a serious problem with InsertMedia() automation. Once the InsertMedia() function is called a "MIDI File Import" window pops up and requires manual input to click "okay". There are ways to catch this window and close is with a script when the file is imported manually (as in this post: https://forums.cockos.com/showthread.php?t=246364), however when imported by a script the scripting thread seems to be busy already and the MIDI window remains open stopping all operations until manual input is provided.
Do you have any idea how to go around this? Without closing that "MIDI File Import" window by a script the whole automation is useless.
|
|
|
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 03:28 AM.
|