Yingonito referenced a post from a few years ago, that used a script measure with an option#/value# scheme to generate measures and meters. It was not very user-friendly because you had to convert each line of an 'ini' formatted measure or meter to an option#/value# format used in the script
I recently came across a script from alatsombath's Ocean visualizer, 'GenerateBands' which can create incremental sections from a template created in standard 'ini' measure/meter format.
I integrated the script into 2 repeating template generator skins:
'GenerateMeasures.ini' creates '#@#My#Template#Measures.inc' using a predefined template file or one you create.
'GenerateMeters.ini' creates '#@#My#Template#Meters.inc' using a predefined template file or one you create.
Those skins are setup and controlled by '@RepeatingVariables.inc' file. It contains the name of your template and the number of repeating measures/meters variables.
I created 2 example packages showing how you might use the repeating template generators in your own skins.
For audio visualizers which basically use 1 incremented measure and 1 related meter, it can create @include files with the number of repeating measures and meters, on the fly, for use in a visualizer. See 'RepeatingTemplateVisualizer' demo package.
For webparser skins, the demo can create title/link (2 indexes... but as many as needed can be added) measures and meters. It uses a few variables and a repeatable formula to automatically calculate the stringindex values. It can dynaically create any number of measures and meters on-the-fly. See 'RepeatingTemplateGoogleNews' package.
Here are the scripts. They are identical, except for the !Log entry. When used in a skin, I comment out opening the created file in an editor.
RepeatMeasureSection.lua
Code: Select all
-- RepeatSection v1.2
-- LICENSE: Creative Commons Attribution-Non-Commercial-Share Alike 3.0
-- Author: alatsombath from 'Ocean', 'Generate Bands' skin
function Initialize()
local index, section, gsub, readFile = 1, {}, string.gsub, io.input(SKIN:ReplaceVariables(SELF:GetOption("ReadFile"))):read("*all")
local substitution, lowerLimit, upperLimit = SELF:GetOption("Substitution"), SELF:GetNumberOption("LowerLimit") + 1, SELF:GetNumberOption("UpperLimit") + 1
for i = lowerLimit, upperLimit do
section[index], index = gsub(readFile, substitution, i-1), index + 1
end
local file = io.open(SKIN:ReplaceVariables(SELF:GetOption("WriteFile")), "w")
file:write(table.concat(section, "\n\n"))
file:close()
SKIN:Bang('!Log', 'Created #@#My#Template#Measures.inc.')
-- Add comment to the line below to prevent opening the file in an editor
SKIN:Bang('#@#My#Template#Measures.inc.')
end
RepeatingMeterSection.lua
Code: Select all
-- RepeatSection v1.2
-- LICENSE: Creative Commons Attribution-Non-Commercial-Share Alike 3.0
-- Author: alatsombath from 'Ocean', 'Generate Bands' skin
function Initialize()
local index, section, gsub, readFile = 1, {}, string.gsub, io.input(SKIN:ReplaceVariables(SELF:GetOption("ReadFile"))):read("*all")
local substitution, lowerLimit, upperLimit = SELF:GetOption("Substitution"), SELF:GetNumberOption("LowerLimit") + 1, SELF:GetNumberOption("UpperLimit") + 1
for i = lowerLimit, upperLimit do
section[index], index = gsub(readFile, substitution, i-1), index + 1
end
local file = io.open(SKIN:ReplaceVariables(SELF:GetOption("WriteFile")), "w")
file:write(table.concat(section, "\n\n"))
file:close()
SKIN:Bang('!Log', 'Created #@#My#Template#Meters.inc.')
-- Add comment to the line below to prevent opening the file in an editor
SKIN:Bang('#@#My#Template#Meters.inc.')
end
More details, a modular 'TemplateGenerators' method, and working examples are here:
COMMUNITY TIP