Import a file with OSC / Lua programmatically at runtime

I need to load an audio file (import) programmatically at runtime. How do I load file that exists on my PC and place it on existing track (or create a new one). Ideally I would like to do this with OSC and provide a String parameter that equals to file absolute path.

I don’t believe you can do this with OSC.

Importing files relies on the Editor GUI (mainly to handle this in a non-blocking way).
You can use a Lua script Action (and also trigger that script in GUI context), but actions do not have any parameters. For each file you want to load, you’d need a dedicated action.

ok, thanks - and I can trigger action with OSC right? So, as I see it, I have only option - to have a specific directory and copy + rename my file there, then call the lua script to load that file - and I think Ardour is creating a copy of that file in RAM right? So I can later delete that file and repeat the process with another file. Would be nice for a Lua action to have parameters thought - that would make it a lot simpler. But how about this - I will rename the name of the first track to filename path I want - lua script will read name of the first track - use that as a parameter. Sounds good?

I got it working - to dynamically load file I will first call OSC:
"/strip/name", id, val
where val is String path and id is track order which I want to rename.
Then I can trigger Action - lua script that will read first track name and load file with path equals track name:

ardour {
	["type"] = "EditorAction",
	name = "Load File Path from Track Name",
	author = "trackme518",
	description = [[Use previously set track name by OSC as a variable String absolute path to load audio file]]

function factory () return function ()
	-- t is-a
	r = Session:get_remote_nth_route(0)
	local track = r:to_track()
	print( track:name() )

	local files = C.StringVector();
	files:push_back( track:name() )

	local pos = Temporal.timepos_t(0)
	Editor:do_import (files,Editing.ImportDistinctFiles, Editing.ImportAsTrack, ARDOUR.SrcQuality.SrcBest,ARDOUR.MidiTrackNameSource.SMFTrackName, 
	pos, ARDOUR.PluginInfo(), ARDOUR.Track(), false)
end end
1 Like

Now that is a neat hack !!

1 Like

OSC call Lua Action:

somehow this does not work - do you know how I can trigger script action from OSC?

It should be possible via OSC “/access_action” after loading the script Menu > Edit > Lua Scripts > Script Manager > Action Scripts (the first 12 action scripts are also assignable using the buttons top-right in the toolbar)

I think I am experiencing some bug - when I insert the lua script inside the Scripting windows and click run it will do what I intend. But when I assign the script to Action 3 slot in Scripting manager window and click call it will do nothing. Also when I click edit it will do nothing…

My bad - it’s working now! I had a typo in saved lua script.

Just for clarification for other - OSC to call action is:
osc.send( target, “/access_action”, “LuaAction/script-3” );

1 Like

A bug in your own script :slight_smile: Well, happens to everyone.
It’s great you figured this all out and got things working.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.