This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* @lachrymaL_F | |
BPM Grid -> Adobe After Effects | |
03/25/2020 */ | |
{ | |
function BPMGrid(thisObj) { | |
function BPMGrid_buildUI(thisObj) { | |
var mainPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "BPM Grid Creator", undefined, {resizable: true, closeButton: true}); | |
res = "group{orientation:'column',\ | |
groupBPM: Group{orientation:'row',\ | |
BPMEntryDesc: StaticText{text:'BPM: '},\ | |
BPMEntry: EditText{text:'120'},\ | |
},\ | |
groupSpacing: Panel{orientation:'row',\ | |
spacingDesc: StaticText{text:'Spacing: '},\ | |
spacingNumer: EditText{text:'1'},\ | |
spacingDivText: StaticText{text:'/'},\ | |
spacingDenom: EditText{text:'4'},\ | |
},\ | |
groupButton: Panel{orientation:'row',\ | |
createButton: Button{text:'Create Grid'},\ | |
},\ | |
}"; | |
mainPanel.grp = mainPanel.add(res); | |
mainPanel.grp.groupButton.createButton.onClick = function() { | |
var BPM = posNumParser(Number(mainPanel.grp.groupBPM.BPMEntry.text)); | |
var spacing = posNumParser(Number(mainPanel.grp.groupSpacing.spacingNumer.text)) / posNumParser(Number(mainPanel.grp.groupSpacing.spacingDenom.text)); | |
createGrid(BPM, spacing); | |
} | |
mainPanel.layout.layout(true); | |
return mainPanel; | |
} | |
var myScriptPal = BPMGrid_buildUI(thisObj); | |
if(myScriptPal != null && myScriptPal instanceof Window) { | |
myScriptPal.center(); | |
myScriptPal.show(); | |
} | |
} | |
BPMGrid(this); | |
} | |
function posNumParser(inp) { | |
if (inp !== inp || inp <= 0) { | |
alert('Please enter valid values!'); | |
throw 'Illegal Inputs!'; | |
} | |
return inp | |
} | |
function createGrid(BPM, spacing) { | |
app.beginUndoGroup("Create BPM Grid"); | |
var BPMnull = app.project.activeItem.layers.addNull(app.project.activeItem.duration); | |
BPMnull.name = "BPM Grid"; | |
BPMnull.source.name ="BPM Grid" | |
var marginBetweenMarkers = (60 / BPM) * spacing; | |
var finishLine = BPMnull.outPoint; | |
for (var t = 0; t < finishLine; t = t + marginBetweenMarkers){ | |
BPMnull.Marker.addKey(t); | |
} | |
BPMnull.locked = true; | |
BPMnull.enabled = false; | |
app.endUndoGroup(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment