Not by me, but I thought I would include a lua sample of creating duplicate number-incremented section, on the fly, for any skin.
This code is used in many visualizers to auto-generate include files of hundreds of meters. The 'Factory.lua' writes to the defined include file, based on a master 'option/value' list in the script section, and then the 'Refresher.lua' refreshes the file to read the newly created include files.
For a working demonstration, I would recommend dissecting the
Lano Visualizer by marcopixel.
Here are the lua files by Malody Hoe.
Factory.lua
Code: Select all
-- @author Malody Hoe / GitHub: madhoe / Twitter: maddhoexD
-- Structure of Script Measure:
---- IncFile=
---- Number=
---- SectionName=
---- OptionN=
---- ValueN=
---- where N is an ordered number from 0
-- Use %% to substitute it as the iteration number (which is specified by the Number option)
---- For example, if you specify 10, it will create 10 sections and replace the first section's %%
---- with 0, the second section's %% with 1, etc...
-- Wrap any formulas you want to parse in {} that otherwise RM would treat as a string
---- For example, [Measure{%%+1}] will have this script parse it for you
function Initialize()
local num = SELF:GetNumberOption("Number")
local sectionName = SELF:GetOption("SectionName")
local file = io.open(SKIN:MakePathAbsolute(SELF:GetOption("IncFile")), "w")
local t = {}
for i = 0, num-1 do
table.insert(t, "[" .. doSub(sectionName, i) .. "]")
local j = 0
while true do
local opt = SELF:GetOption("Option" .. j)
if opt == "" then
break
end
table.insert(t, opt .. "=" .. doSub(SELF:GetOption("Value" .. j), i))
j = j + 1
end
end
file:write(table.concat(t, "\n"))
file:close()
end
-- does all the substitution!
function doSub(value, i)
return value:gsub("%%%%", i):gsub("{.-}", parseFormula)
end
-- sub to remove {the curly braces}, then add (parentheses), then parse it
function parseFormula(formula)
return SKIN:ParseFormula("(" .. formula:sub(2, -2) .. ")")
end
Refresher.lua
Code: Select all
-- @author Malody Hoe / GitHub: madhoe / Twitter: maddhoexD
-- Add this after all incs!
function Initialize()
if SELF:GetOption("Refreshed", "0") == "0" then
SKIN:Bang("!WriteKeyValue", SELF:GetName(), "Refreshed", "1")
SKIN:Bang("!Refresh")
else
SKIN:Bang("!WriteKeyValue", SELF:GetName(), "Refreshed", "0")
end
end
And the visualizer.ini by marcopixel
Code: Select all
[Rainmeter]
Update=16
[Metadata]
Name=Lano Visualizer
Author=marcopixel
Version=1.0
License=CC BY-NC-SA 4.0
[Variables]
; Includes the variables/styles used for the skin.
@include=#@#variables.ini
; These variables are constants and are better untouched! Changing here will probably break something.
BarHeight=(#WORKAREAHEIGHT#*#Scale#)/4
BarGapCalc=(#BarGap#*#Scale#)
BarWidthCalc=(#BarWidth#*#Scale#)
BarCountCalc=(#BarCount#+1)
; Measure AudioLevel - spectrum input
[MeasureAudio]
Measure=Plugin
Plugin=AudioLevel
Port=Output
FFTSize=#FFTSize#
FFTOverlap=#FFTOverlap#
FFTAttack=#FFTAttack#
FFTDecay=#FFTDecay#
Bands=#BarCountCalc#
FreqMin=50
FreqMax=12000
Sensitivity=#Sensitivity#
; Script Factory - generates the bars for the visualizer
[ScriptFactoryBars]
Measure=Script
ScriptFile=#@#scripts\Factory.lua
IncFile=#@#include\MeterBars.inc
Number=#BarCount#
SectionName=MeterBar%%
Option0=Meter
Value0=BAR
Option1=BarColor
Value1=#Color#
Option2=MeasureName
Value2=MeasureAudioSmoothed{%%+1}
Option3=X
Value3=#BarGapCalc#R
Option4=Y
Value4=0
Option5=W
Value5=#BarWidthCalc#
Option6=H
Value6=#BarHeight#
Option7=BarOrientation
Value7=Vertical
UpdateDivider=-1
[ScriptFactoryRoundedBarBottom]
Measure=Script
ScriptFile=#@#scripts\Factory.lua
IncFile=#@#include\MeterRoundedBarBottom.inc
Number=#BarCount#
SectionName=MeterRoundedBarBottom{%%+1}
Option0=Meter
Value0=Roundline
Option1=X
Value1=#BarGapCalc#R
Option2=Y
Value2=#BarHeight#-#BarWidthCalc#/2
Option3=W
Value3=#BarWidthCalc#
Option4=H
Value4=#BarWidthCalc#
Option5=StartAngle
Value5=0
Option6=RotationAngle
Value6=#BarWidthCalc#
Option7=LineLength
Value7=#BarWidthCalc#/2
Option8=LineColor
Value8=#Color#
Option9=Solid
Value9=1
Option10=AntiAlias
Value10=1
UpdateDivider=-1
[ScriptFactoryRoundedBarTop]
Measure=Script
ScriptFile=#@#scripts\Factory.lua
IncFile=#@#include\MeterRoundedBarTop.inc
Number=#BarCount#
SectionName=MeterRoundedBarTop{%%+1}
Option0=Meter
Value0=Roundline
Option1=X
Value1=#BarGapCalc#R
Option2=Y
Value2=#BarHeight#+#BarHeight#*-[MeasureAudioSmoothed{%%+1}]-#BarWidthCalc#/2
Option3=W
Value3=#BarWidthCalc#
Option4=H
Value4=#BarWidthCalc#
Option5=StartAngle
Value5=0
Option6=RotationAngle
Value6=#BarWidthCalc#
Option7=LineLength
Value7=#BarWidthCalc#/2
Option8=LineColor
Value8=#Color#
Option9=Solid
Value9=1
Option10=AntiAlias
Value10=1
Option11=DynamicVariables
Value11=1
UpdateDivider=-1
; Script Refresher - refreshes the code to apply the changes from the factory scripts
[ScriptRefresher]
Measure=Script
ScriptFile=#@#scripts\Refresher.lua
UpdateDivider=-1
Refreshed=0
; Include the BandMeasures with raw data
@include3=#@#include\BandMeasures.inc
; Include the BandMeasures with smoothed data
@include4=#@#include\BandMeasuresSmoothed.inc
; Include the band meters
@include5=#@#include\MeterBars.inc
[MeterAlignRoundedBarBottom]
Meter=String
X=0
Y=#BarHeight#-#BarWidthCalc#/2
; Include the roundline meters at the bottom
@include6=#@#include\MeterRoundedBarBottom.inc
[MeterAlignRoundedBarTop]
Meter=String
X=0
Y=#BarHeight#-#BarWidthCalc#/2
; Include the roundline meters at the top
@include7=#@#include\MeterRoundedBarTop.inc