Skip to content

Instantly share code, notes, and snippets.

@andmatand
Last active June 25, 2025 04:01
Show Gist options
  • Save andmatand/b990256d0f2472fd94b1a84414b16732 to your computer and use it in GitHub Desktop.
Save andmatand/b990256d0f2472fd94b1a84414b16732 to your computer and use it in GitHub Desktop.
Ardour script to export all range markers in a session
ardour {
type = "EditorAction",
name = "Export all range markers as a JSON array",
author = "Andrew Anderson",
description = [[
Writes the name, start, and end (in hh:mm:ss format) of all range markers to
the file `export/range_markers.json`
]],
license = "MIT",
}
-- Timestamp conversion code is adapted from
-- https://github.com/Ardour/ardour/blob/master/share/scripts/export_mp4chaps.lua
-- Author: Johannes Mueller
-- License: GPLv2
function format_timepos(pos)
local fr = Session:sample_rate()
local t = pos:samples()
local h = math.floor(t / (3600*fr))
local r = t - (h*3600*fr)
local m = math.floor(r / (60*fr))
r = r - m*60*fr
local s = math.floor(r / fr)
r = r - s*fr
local ms = math.floor(r*1000/fr)
return string.format("%02d:%02d:%02d.%03d", h, m, s, ms)
end
function get_ranges()
local ranges = {}
for l in Session:locations():list():iter() do
if l:is_range_marker() then
local name = l:name()
local start_formatted = format_timepos(l:start())
local end_formatted = format_timepos(l:_end())
local range = {
name = name,
start = start_formatted,
_end = end_formatted
}
table.insert(ranges, range)
end
end
return ranges
end
function escape_json_string(s)
return s:gsub('"', '\\"')
end
function format_range_as_json_object(range)
return string.format(
'{"name": "%s", "start": "%s", "end": "%s"}',
escape_json_string(range.name),
range.start,
range._end
)
end
function factory(unused_params)
return function()
local ranges = get_ranges()
local path = ARDOUR.LuaAPI.build_filename(
Session:path(),
"export",
"range_markers.json"
)
local file = io.open(path, "w")
file:write("[")
for i, range in ipairs(ranges) do
if i > 1 then
file:write(",")
end
local obj = format_range_as_json_object(range)
file:write(obj)
end
file:write("]")
file:close()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment