Skip to content

Instantly share code, notes, and snippets.

@cfillion
Last active September 13, 2019 02:12
Show Gist options
  • Select an option

  • Save cfillion/ec296fe84bf8c33fcaf82e6d865f6092 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

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

@cfillion

cfillion commented Sep 12, 2019

Copy link
Copy Markdown
Author

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
Copy Markdown

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