Skip to content

Instantly share code, notes, and snippets.

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 nofishonfriday/22a942c71b529ba26c784f72eafbc392 to your computer and use it in GitHub Desktop.
Save nofishonfriday/22a942c71b529ba26c784f72eafbc392 to your computer and use it in GitHub Desktop.
function main()
local newtime=os.time()
-- slow down script frequency
-- https://forum.cockos.com/showpost.php?p=1591089&postcount=14
if newtime-lasttime >= 0.5 then -- run ~every 0.5 sec.
lasttime = newtime
local me = reaper.MIDIEditor_GetActive()
if me ~= nil then
-- iterate (enum) editable takes
local i = 0
local foundPooledTake = false
while true do
local take = reaper.MIDIEditor_EnumTakes(me, i, true)
-- https://forum.cockos.com/showpost.php?p=2481441&postcount=11
if take == nil or reaper.ValidatePtr(take, "MediaItem_Take*") == false then break end
-- reaper.ShowConsoleMsg(tostring(take))
local sourceType = reaper.GetMediaSourceType(reaper.GetMediaItemTake_Source(take), '')
-- reaper.ShowConsoleMsg(sourceType)
if sourceType == "MIDIPOOL" then
foundPooledTake = true
break
end
i = i+1
end -- while true do
reaper.SetToggleCommandState(sectionID, cmdID, foundPooledTake and 1 or 0) -- convert boolean to 0/1
-- reaper.ShowConsoleMsg(tostring(foundPooledTake and 1 or 0) .. "\n")
reaper.RefreshToolbar2(sectionID, cmdID)
end -- if me ~= nil then
end -- if newtime - lasttime...
reaper.defer(main)
end -- main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment