[PHP] Code Duplicator

Share your custom plugins and applications to enhance Rainmeter.
User avatar

[PHP] Code Duplicator

May 13th, 2018, 2:56 pm
dudebaker
   [37 posts]

Hi together,

today while creating new skins (yes I should stay away from this beast of rainmeter :lol:) I was (again) annoyed of the typical find/replace + copy/paste procedure.

I had this in the past multiple times (duplicate measures/meters for skins with multiple entries) and I couldn't find a faster way then copying the code-snippet into a new tab and do there the find/replace stuff with up-numbering and then copy-pasting it to the other file.

Imagine this with a skin of 20 entries and you have spent some useless time doing this.

So today I've decided to create a small PHP script which solves this problem.
Maybe someone has the same issues like me, so I'll share it here...

Available at Github:
https://github.com/Dudebaker/CodeDuplicator

PS:
Sorry if this is the false category, then please move it to the correct one.
Last edited by dudebaker on June 1st, 2018, 8:14 am, edited 1 time in total.

Re: [PHP] Code Duplicator

May 15th, 2018, 8:16 pm
buckb
   [26 posts]

Hi dudebaker,

If I understand your post and your php correctly, I think we are both wrestling with the same issue: how to ease development and maintenance of skins that have repeating elements. Please see my post here:

https://forum.rainmeter.net/viewtopic.php?f=14&t=28412

You may also want to see the readme in the "includes" subdirectory of the WorldClock skin posted here:

https://forum.rainmeter.net/viewtopic.php?f=27&t=28386


I would be interested in your thoughts.


--buckb
User avatar

Re: [PHP] Code Duplicator

May 16th, 2018, 6:06 pm
dudebaker
   [37 posts]

Hi buckb,

yes you're right, we have the same issues but use different ways to solve it (file vs files).
But it's really a elegant way to do this with a .vbs file.

Normally, I'm just trying to outsource those things that are used by multiple skins.
But when I look at my BOINC Projects Skin, which has 2.2k lines, I probably should go that way on such skins too. :D

Your suggestions would solve most redundant code - should be added to the roadmap of rainmeter. :thumbup:
User avatar

Re: [PHP] Code Duplicator

May 16th, 2018, 9:23 pm
eclectic-tech
Rainmeter Sage   [2843 posts]

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
User avatar

Re: [PHP] Code Duplicator

May 17th, 2018, 5:18 pm
dudebaker
   [37 posts]

Honestly I've never touched lua scripting - didn't need it a single time in my complete suite and could solve all "natively".
But now I have a reason to do it. :)

That's really a awesome script and makes it much easier to do such skins.
They can be way smaller and easier to maintain.

Thanks for this hint!
User avatar

Re: [PHP] Code Duplicator

May 18th, 2018, 11:20 pm
tjhrulz
Developer   [221 posts]

dudebaker wrote:Honestly I've never touched lua scripting - didn't need it a single time in my complete suite and could solve all "natively".
But now I have a reason to do it. :)

That's really a awesome script and makes it much easier to do such skins.
They can be way smaller and easier to maintain.

Thanks for this hint!


Yeah it is a pretty awesome script, never have I had it not be able to do something I want.

Return to “Plugins & Addons”



Who is online

Users browsing this forum: No registered users and 5 guests