Icon representing a recipe

Recipe: bandsliders2

created by jeff101

Profile


Name
bandsliders2
ID
44316
Shared with
Public
Parent
None
Children
Created on
October 08, 2012 at 01:59 AM UTC
Updated on
October 08, 2012 at 01:59 AM UTC
Description

Graphic equalizer for bands.

Same as bandsliders2d3.txt 10pm 10/7/12.

Best for


Code


function Main() -- bandsliders begun 10/1/12 by jeff101 -- -- goal is to be like graphic equalizer for bands -- -- last updated 951pm 10/7/12 -- nbands=band.GetCount() rtot=structure.GetCount() print('Run of bandsliders on '..puzzle.GetName()..' with Puzzle ID '..puzzle.GetPuzzleID()..':') print('Has '..rtot..' residues, '..nbands..' bands, and score '..round3(current.GetScore())..' at '..os.date()..'.') bstrs={} blens={} bglens={} bison={} bdiffs={} bonstr={} print('------ STARTING WITH VALUES BELOW ------') for bnum=1,nbands do bstrs[bnum]=band.GetStrength(bnum) blens[bnum]=band.GetLength(bnum) bglens[bnum]=band.GetGoalLength(bnum) bison[bnum]=band.IsEnabled(bnum) if bison[bnum]==true then bonstr[bnum]='ENABLED' else bonstr[bnum]='disabled' end -- if bison bdiffs[bnum]=math.abs(bglens[bnum]-blens[bnum]) print('Band '..bnum..' is '..bonstr[bnum]..' with strength '..round1(bstrs[bnum])..', goal length '..round2(bglens[bnum])..', length '..round2(blens[bnum])..', and difference '..round2(bdiffs[bnum])..'.') end -- for bnum print('------ STARTING WITH VALUES ABOVE ------') blos={} bhis={} bwid=5 num=0 for bnum=1,nbands,bwid do num=num+1 blos[num]=bnum bhis[num]=bnum+bwid-1 if bhis[num]>nbands then bhis[num]=nbands end -- if bhis end -- for bnum nwids=num -- nwids should be length of blos num=1 qflag=0 if nbands<1 then qflag=1 end -- if nbands glflag=0 while qflag==0 do band.DisableAll() numm1=num-1 if numm1<1 then numm1=nwids end nump1=num+1 if nump1>nwids then nump1=1 end local ask=dialog.CreateDialog(('bandsliders for bands '..blos[num]..'-'..bhis[num]..' of '..nbands)) for bnum=blos[num],bhis[num] do if bison[bnum]==true then band.Enable(bnum) end -- if bison ask["Label"..bnum]=dialog.AddLabel(('band '..bnum..' '..bonstr[bnum]..' str='..round1(bstrs[bnum])..' goal len='..round2(bglens[bnum])..' len='..round2(blens[bnum])..' diff='..round2(bdiffs[bnum]))) if glflag==1 then -- show goal length -- glmax sets largest allowed new goal length glmax=bglens[bnum] if glmax<0.5 then glmax=0.5 end -- if glmax glmax=math.ceil(10^(0.5*math.ceil(2*math.log10(3*glmax)))) if glmax>10000 then glmax=10000 end -- if glmax ask["Input"..bnum]=dialog.AddSlider(('band '..bnum..' goal len: '),bglens[bnum],0,glmax,2) else -- show band strength ask["Input"..bnum]=dialog.AddSlider(('band '..bnum..' strength: '),bstrs[bnum],0.1,10,1) end -- if glflag ask["Box"..bnum]=dialog.AddCheckbox(('check/uncheck box to left to enable/disable band '..bnum),bison[bnum]) end -- for bnum svstr='Save Above' ask[svstr]=dialog.AddButton(svstr,1) rsstr='Undo Above' ask[rsstr]=dialog.AddButton(rsstr,2) if glflag==1 then -- show goal length swstr=('Show Strs') else -- show band strength swstr=('Show Lens') end -- if glflag ask[swstr]=dialog.AddButton(swstr,3) rng1str=('Show '..blos[numm1]..'-'..bhis[numm1]) rng2str=('Show '..blos[nump1]..'-'..bhis[nump1]) ask[rng1str]=dialog.AddButton(rng1str,4) ask[rng2str]=dialog.AddButton(rng2str,5) ask.Quit=dialog.AddButton("Quit",6) askres=dialog.Show(ask) -- askres==2 does nothing if askres==1 then -- SAVE print('Changing to the following settings:') for bnum=blos[num],bhis[num] do bison[bnum]=ask["Box"..bnum].value if bison[bnum]==true then band.Enable(bnum) bonstr[bnum]='ENABLED' else band.Disable(bnum) bonstr[bnum]='disabled' end -- if bison if glflag==1 then -- set goal length bglens[bnum]=ask["Input"..bnum].value+0 band.SetGoalLength(bnum,bglens[bnum]) bdiffs[bnum]=math.abs(bglens[bnum]-blens[bnum]) else -- set band strength bstrs[bnum]=ask["Input"..bnum].value+0 band.SetStrength(bnum,bstrs[bnum]) end -- if glflag print('Band '..bnum..' is '..bonstr[bnum]..' with strength '..round1(bstrs[bnum])..', goal length '..round2(bglens[bnum])..', length '..round2(blens[bnum])..', and difference '..round2(bdiffs[bnum])..'.') end -- for bnum elseif askres==3 then -- SWITCH glflag=1-glflag elseif askres==4 then -- RANGE1 num=numm1 elseif askres==5 then -- RANGE2 num=nump1 elseif askres==6 then -- QUIT qflag=1 end -- if askres end -- while qflag==0 band.DisableAll() for bnum=1,nbands do if bison[bnum]==true then band.Enable(bnum) end -- if bison end -- for bnum print('------ ENDING WITH VALUES BELOW ------') for bnum=1,nbands do bstrs[bnum]=band.GetStrength(bnum) blens[bnum]=band.GetLength(bnum) bglens[bnum]=band.GetGoalLength(bnum) bison[bnum]=band.IsEnabled(bnum) if bison[bnum]==true then bonstr[bnum]='ENABLED' else bonstr[bnum]='disabled' end -- if bison bdiffs[bnum]=math.abs(bglens[bnum]-blens[bnum]) print('Band '..bnum..' is '..bonstr[bnum]..' with strength '..round1(bstrs[bnum])..', goal length '..round2(bglens[bnum])..', length '..round2(blens[bnum])..', and difference '..round2(bdiffs[bnum])..'.') end -- for bnum print('------ ENDING WITH VALUES ABOVE ------') nbands=band.GetCount() print('All done at '..os.date()..' with '..nbands..' bands.') end -- Main() -- below rounds to 3 decimal places function round3(numi) local numo=round(numi*1000)/1000 return numo end -- round3() -- below rounds to 2 decimal places function round2(numi) local numo=round(numi*100)/100 return numo end -- round2() -- below rounds to 1 decimal place function round1(numi) local numo=round(numi*10)/10 return numo end -- round1() -- below rounds val to the nearest integer to get res function round(val) local res=math.floor(val) if val-res>=0.5 then res=res+1 end -- if val return res end -- round() Main()

Comments


jeff101 Lv 1

Special thanks go to truestone, brow42, Crashguard303, pauldunn, and Timo van der Laan for helping me figure out how to code this recipe. It turns out that

ask.Label5=dialog.AddLabel(bstr)

and

num=5
ask["Label"..num]=dialog.AddLabel(bstr)

do the same thing, but the latter lets you put it into a loop.