Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
-- @version 1.0beta
-- @author cfillion
local EXT_SECTION = 'cfillion_project_list'
local function makeKey(i)
return string.format('project%d', i)
end
local function enumOpenedProjects()
local i = 0
return function()
local retval, projfn = reaper.EnumProjects(i)
i = i + 1
if retval then
return i, projfn
end
end
end
local function getOpenedProjects()
local list = {}
for i, projfn in enumOpenedProjects() do
table.insert(list, projfn)
end
return list
end
local function saveOpenedProjects()
for i, projfn in enumOpenedProjects() do
reaper.SetExtState(EXT_SECTION, makeKey(i), projfn, true)
end
end
local function enumSavedProjects()
local i = 1
return function()
local key = makeKey(i)
i = i + 1
if reaper.HasExtState(EXT_SECTION, key) then
return key
end
end
end
local function getSavedProjects()
local list = {}
for key in enumSavedProjects() do
local projfn = reaper.GetExtState(EXT_SECTION, key)
table.insert(list, projfn)
end
return list
end
local function clearSavedProjects()
for key in enumSavedProjects() do
reaper.DeleteExtState(EXT_SECTION, key, true)
end
end
local function isDifferent(tableA, tableB)
if #tableA ~= #tableB then
return true
end
for i, val in ipairs(tableA) do
if tableB[i] ~= val then
return true
end
end
return false
end
local function compareLists()
local savedProjects = getSavedProjects()
local openedProjects = getOpenedProjects()
if isDifferent(savedProjects, openedProjects) then
reaper.MB("The saved projects are different from the currently opened ones!", "Test", 0)
end
end
--compareLists()
--clearSavedProjects()
--saveOpenedProjects()
@LexaProductions

This comment has been minimized.

Copy link

LexaProductions commented Sep 12, 2019

At line 14, is it normal that there's no 2nd argument to the enumproject function?
Shouldn't it be:
reaper.EnumProjects(i,'')

@cfillion

This comment has been minimized.

Copy link
Owner Author

cfillion commented Sep 12, 2019

It is no longer necessary since v5.982 (though the change was not mentioned in the changelog?). As seen in the documentation:

v5.981

Lua: ReaProject retval, string projfn = reaper.EnumProjects(integer idx, string projfn)

v5.982

Lua: ReaProject retval, optional string projfn = reaper.EnumProjects(integer idx)
@LexaProductions

This comment has been minimized.

Copy link

LexaProductions commented Sep 13, 2019

Thanks for this. I didn't know.
That explains why it was working for me and not for others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.