Skip to content

Instantly share code, notes, and snippets.

@cfillion
Last active September 13, 2019 02:12
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 cfillion/ec296fe84bf8c33fcaf82e6d865f6092 to your computer and use it in GitHub Desktop.
Save cfillion/ec296fe84bf8c33fcaf82e6d865f6092 to your computer and use it in GitHub Desktop.
-- @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
Copy link

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

@cfillion
Copy link
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
Copy link

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