I would like to create a midi track and write a midi note in the new created track with a Lua script.
Does anyone know an example script, where I could see how a midi track is created and how to manipulate a midi track?
For the second part, the audio-to-midi script can be of some help, that does however depend on an existing track and region (demo: https://vimeo.com/186035015 )
There is a missing link: Creating an empty midi-region to write notes into.
The API for handing Music Time (Bar, Beat) is in flux and will change with Ardour6, so a lot of the MIDI methods have not been exposed to scripting, yet. In particular MIDI region scripting API is only bare-bones at this point in time.
Editing MIDI is done by creating a diff erence command and then apply it. Something like
local midi_model = midi_region:model()
local notelist = ARDOUR.LuaAPI.note_list (midi_model)
local midi_command = midi_model:new_note_diff_command ("Description of Change")
for note in notelist:iter () do
local newnote = ARDOUR.LuaAPI.new_noteptr (note:channel(), note:time (), note:length (), note:note(), note:velocity())
midi_command:remove (note)
midi_command:add (newnote)
end
midi_model:apply_command (Session, midi_command)