Skip to content

Instantly share code, notes, and snippets.

@catfact
Last active May 4, 2019 21:54
Show Gist options
  • Select an option

  • Save catfact/7a8f5ae56341c144e235fe83abdfdd69 to your computer and use it in GitHub Desktop.

Select an option

Save catfact/7a8f5ae56341c144e235fe83abdfdd69 to your computer and use it in GitHub Desktop.
module providing "factory preset" functionality for norns scripts
local factory = include('lib/factory')
function init()
--- add parameters here...
-- this will copy .pset and .pmap from dust/code/example/data/*, to dust/data/example/*,
-- (without overwriting existing files)
factory.init()
-- then this will load the default values (user or factory)
params:default()
end
local factory = {}
factory.init = function()
local name = norns.state.name
-- local data files (factory presets)
local factory_data = norns.state.path .. 'data/'
local factory_pset = factory_data .. norns.state.name .. '.pset'
local factory_pmap = factory_data .. norns.state.name .. '.pmap'
-- top-level data files (user presets)
local user_data = norns.state.data
local user_pset = user_data .. name .. '.pset'
local user_pmap = user_data .. name .. '.pmap'
local f = io.open(user_pset)
if f == nil then
os.execute("cp "..factory_pset.." "..user_pset)
end
f = io.open(user_pmap)
if f == nil then
os.execute("cp "..factory_pmap.." "..user_pmap)
end
end
return factory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment