Skip to content

Instantly share code, notes, and snippets.

@derwok
Last active August 17, 2021 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derwok/5f818e804b0d58e1ccf8f14099fe2272 to your computer and use it in GitHub Desktop.
Save derwok/5f818e804b0d58e1ccf8f14099fe2272 to your computer and use it in GitHub Desktop.
Ardour: Check for 0-length MIDI Notes on Save
ardour {
name = "Check for 0-length MIDI Notes on Save",
description = "Run on each SAVE, check for MIDI notes with length <= 0.001",
author = "Wolfram Esser, derwok",
["type"] = "EditorHook"
}
-- HowTo:
-- Save to your OS's script path described here: https://manual.ardour.org/lua-scripting/
-- Then launch Ardour
-- Activate script via menu: Edit / Lua Script / Script Manager / Action Hooks
-- Click "New Hook" and select this script
-- Check will now run on current session on every Session save (signal: StateSaved)
function signals ()
s = LuaSignal.Set()
s:add ({[LuaSignal.StateSaved] = true})
return s
end
function factory (params)
return function (signal, ref, ...)
MIN_LEN = 0.001 -- fractions of a beat 1/128 = 0.007
zero_found = false
if (signal == LuaSignal.StateSaved) then
print ("")
print ("You Saved! Checking for Zero-Length MIDI notes")
for r in Session:get_tracks ():iter () do
track_name = "Track: "..r:name()
for p in Session:playlists():playlists_for_track (r:to_track()):iter() do
playlist_name = p:name()
if (p == r:to_track():playlist()) then
playlist_name = "Active Playlist: " .. playlist_name
else
playlist_name = "In-Active Playlist: " .. playlist_name
end
for g in p:region_list (): iter() do
local mr = g:to_midiregion ()
if mr:isnil () then goto next end
region_name = "MIDI Region: " .. g:name () .." Pos:" .. g:position () .. " Start:" .. g:start ()
notes_errors = ""
local nl = ARDOUR.LuaAPI.note_list (mr:model ())
for n in nl:iter () do
if n:length ():to_double() <= MIN_LEN then
local note_error = "Zero MIDI Note @beat:" .. n:time ():to_double() ..
" " .. ARDOUR.ParameterDescriptor.midi_note_name (n:note ()) ..
" Len:" .. n:length ():to_double()
notes_errors = notes_errors .. note_error .. "\n"
zero_found = true
end
end -- notelist
if notes_errors ~= "" then
print (track_name)
print (" ", playlist_name)
print (" ", region_name)
print (notes_errors)
end -- if
::next::
end -- regions
end -- playlists
end -- tracks
if zero_found then
local md = LuaDialog.Message ("WARNING! Zero-Length MIDI Notes!", "There were zero-length MIDI notes!\nPlease click 'OK', then check Ardour's Error Log",
LuaDialog.MessageType.Warning, LuaDialog.ButtonType.OK)
md:run()
else
print ("** Check OK. No 0-length MIDI notes found.")
print ("")
end -- if
end -- signal == StateSaved
end -- function
end -- factory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment