Connect a MIDI input to a track with LUA

I have a flaky USB-MIDI interface that occasionally needs to be reset. I’m trying to write a LUA script to do this. I’ve got something that resets the audio interface (just stops and starts it), but I’m stuck trying to figure out to connect a physical MIDI device to a track. More specifically, I’m stuck trying to get a list of physical input MIDI devices. I’ve got this, but it prints just about everything except what I’m looking for (the physical MIDI device):

ardour {
  ["type"]    = "EditorAction",
  name        = "Reset MIDI",
  category    = "Utility",
  author      = "Brent Baccala",
  description = "Reset my MIDI interface"
}

function factory (unused_params)
  return function ()
    local engine = Session:engine();
    engine:stop();
    engine:start();
    _, t = engine:get_ports (ARDOUR.DataType.midi (), ARDOUR.PortList ());
    for p in t[2]:iter() do
	local midiport = p:to_midiport ()
        print(midiport:name())
    end
  end
end

For physical (device provided) ports, you need engine::get_backend_ports (...).

The following script may provide some inspiration:

Robin, that did it!

Thank you as always for your prompt reply!

It does seem that I need to specify ARDOUR.PortFlags.IsOutput to get an input port, but I’ll try to investigate that some more. My code is about nine months old, so I don’t have any recent patches.

1 Like

We inherited those constants from JACK and should have replaced them with less ambiguous ones.

It depends on the view-point. From Ardour’s point of view, and output port is a source. Data is provided to Ardour by an output from somewhere (usually hardware).

Likewise an input is a sink, that Ardour sends data to for some other app or hardware to read.

This is reversed if you look on the whole system from the outside…

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