I made a script that renames CCs, but to see the changes I have to close and reopen the Midi Editor.
Is there a better way to update/redraw? None of the Update functions work (Timeline, Arrange, Item in project, JS Window).
Thanks!
Is there a better way to update/redraw? None of the Update functions work (Timeline, Arrange, Item in project, JS Window).
Thanks!
Code:
local reaper = reaper
local done = false
reaper.BR_GetMouseCursorContext()
local midi_editor, _, _, lane = reaper.BR_GetMouseCursorContext_MIDI()
if not midi_editor then midi_editor = reaper.MIDIEditor_GetActive() end
if not midi_editor then return reaper.defer(function() end) end
local take = reaper.MIDIEditor_GetTake( midi_editor )
local track = reaper.GetMediaItemTake_Track( take )
if lane == -1 then
local piano = reaper.JS_Window_FindChildByID( midi_editor, 1003 )
local count, list = reaper.JS_Window_ListAllChild( piano )
local cc = {}
for address in string.gmatch(list, "%w+") do
local combo = reaper.JS_Window_HandleFromAddress( address )
local name = string.match(reaper.JS_Window_GetTitle( combo ), "%d%d%d?")
if name then cc[#cc+1] = name end
end
local caption = ""
local empty = " "
for i = #cc, 1, -1 do
caption = caption .. "CC" .. cc[i] .. " new name:,"
empty = empty .. ", "
end
local ok, retvals = reaper.GetUserInputs( "Name found CCs (one empty space for no change)", #cc, caption .. "extrawidth=68", empty )
if not ok then return reaper.defer(function() end) end
local i = #cc
for name in string.gmatch(retvals, "[^,]+") do
if not string.match(name, "^%s+$") then
reaper.SetTrackMIDINoteNameEx( 0, track, 128 + cc[i], -1, name )
done = true
end
i = i -1
end
elseif lane < 128 then
local ok, name = reaper.GetUserInputs( "Set name for CC" .. lane, 1, "CC" .. lane .. " new name:", "" )
if not ok then return reaper.defer(function() end) end
if (not string.match(name, "^%s+$") or name ~= "") then
reaper.SetTrackMIDINoteNameEx( 0, track, 128 + lane, -1, name )
done = true
end
end
if done then
reaper.JS_Window_Destroy( midi_editor )
reaper.Main_OnCommand(40153, 0) -- Item: Open in built-in MIDI editor (set default behavior in preferences)
end