Skip to content

Instantly share code, notes, and snippets.

@AnastasiaDunbar
Last active October 12, 2022 01:18
Show Gist options
  • Save AnastasiaDunbar/ac5df2c91a7f1ca1cb50d85cd667630c to your computer and use it in GitHub Desktop.
Save AnastasiaDunbar/ac5df2c91a7f1ca1cb50d85cd667630c to your computer and use it in GitHub Desktop.
A script to add a grid of markers/regions to selection in Edison or Slicex (FL Studio).
script "Add grid markers" language "javascript";
var options=[2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,20,24,32,64,100,128,256];
function div(a,b){var temp1=0,temp2=0;temp1=a;temp2=b;return temp1/temp2;} //Since I can't convert int to float.
function addMarkers(index,asRegions,addEnd){
var start=0,end=0,count=options[index];
Editor.GetSelectionS(start,end);
if(asRegions){
for(var i=0;i<count-1;i++){
EditorSample.AddRegion(IntToStr(i),start+Round(div((end-start)*i,count)),start+Round(div((end-start)*(i+1),count))-1);
}
EditorSample.AddRegion(IntToStr(count-1),start+Round(div((end-start)*(count-1),count)),end);
}else{
EditorSample.AddRegion("0",start);
for(var i=1;i<count;i++){
EditorSample.AddRegion(IntToStr(i),start+Round(div((end-start)*i,count)));
}
}
if(addEnd){EditorSample.AddRegion(IntToStr(count),end+1);}
}
var Form=CreateScriptDialog("Add grid markers","Add a number of even markers to the selection.");
var optionsStr="";
for(var i=0;i<options.length-1;i++){optionsStr+=IntToStr(options[i])+",";}
optionsStr+=IntToStr(options[options.length-1]);
try{
Form.AddInputCombo("Count",optionsStr,0);
Form.AddInputCombo("As regions?","No,Yes",0);
Form.AddInputCombo("Add one at end?","No,Yes",0);
if(Form.Execute()){
addMarkers(Form.GetInputValue("Count"),Form.GetInputValue("As regions?"),Form.GetInputValue("Add one at end?"));
}
}finally{
Form.Free();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment