I picked up @jfrey 's latest obtuse Gate plugin; sure enough, it relays velocity now.
It turns out I didn’t really need obtuse Gate to relay velocity at all. Here’s how I got it all working.
I created two tracks. One takes input from my Input track and feeds obtuse Gate, followed by MIDI Event Filter set to discard all NoteOn messages. This is why I don’t really need velocity - those messages get discarded. That’s it for the first track. The second track takes input from the Input track as well as the obtuse Gate track, and thus I get two NoteOff messages for each NoteOn message. I run it through the Lua script/plugin below, and then on to sfizz (the instrument):
ardour {
["type"] = "dsp",
name = "Discard Alternate NoteOff",
category = "Utility",
author = "Brent Baccala",
description = [[use in conjunction with obtuse Gate plugin to implement a delay gate with a minimum but unbounded note time]]
}
function dsp_ioconfig ()
return { { midi_in = 1, midi_out = 1, audio_in = 0, audio_out = 0}, }
end
-- table to hold the NoteOff state; key is note number; nil means no NoteOff seen; t means NoteOff seen
state = { }
function process_midi_messages()
kout = 1
for k,b in pairs (midiin) do
local t = b["time"] -- t = [ 1 .. n_samples ]
local d = b["data"] -- midi-event data
local event_type
local channel
if #d == 0 then
event_type = -1
channel = -1
else
event_type = d[1] >> 4
channel = d[1] & 15
end
if (event_type == 8) then
-- only pass alternate NoteOff messages (on a per-key basis)
note = d[2]
if (state[note]) then
midiout[kout] = midiin[k]
kout = kout + 1
state[note] = nil
else
state[note] = t
end
else
-- pass through all other MIDI messages
midiout[kout] = midiin[k]
kout = kout + 1
end
end
end
function dsp_run (_, _, n_samples)
-- without pcall, any errors would crash Ardour; instead, just ignore errors
-- doesn't seem to stop errors in process_midi_messages from crashing Ardour
status, error = pcall(process_midi_messages)
if not status then
print(error)
end
end
It’s been a nice learning experience, and I thank everyone for their suggestions. I’m starting to think that what I want is something like a drum machine triggered from the keybed. This is a very simple example of that, but ultimately I want NoteOn messages to be able to trigger either a one-shot sequence or start a repeating pattern playing. Pads are fine between songs, but too difficult to use while playing, that’s why I’m starting to think I want to trigger stuff from the keybed, and this is a very simple example of that.
No, I see now that it’s not a “Trance Gate”; it’s something else (a drum machine?).
I still don’t quite understand what a Trance Gate does, but at least I know that it exists.