Skip to content

Instantly share code, notes, and snippets.

@frabert
Created March 12, 2020 13:10
Show Gist options
  • Save frabert/0c20a89119aa68868f4f62c8ea89033c to your computer and use it in GitHub Desktop.
Save frabert/0c20a89119aa68868f4f62c8ea89033c to your computer and use it in GitHub Desktop.
local selectedMediaItems = reaper.CountSelectedMediaItems(0)
local notes = { 'A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#' }
function transpose(amount, note)
local index = 0
for i, v in ipairs(notes) do
if v == note then
index = i
end
end
if index ~= 0 then
local newIndex = (index + amount - 1) % #notes
return notes[newIndex + 1]
end
end
for i=0,selectedMediaItems-1 do
local mediaItem = reaper.GetSelectedMediaItem(0, i)
local note = reaper.ULT_GetMediaItemNote(mediaItem)
note = string.gsub(note, "([A-G]#?)", function(n)
return transpose(1, n)
end)
reaper.ULT_SetMediaItemNote(mediaItem, note)
end
reaper.UpdateArrange()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment