Profile
- Name
- Band Stretch 1.0
- ID
- 48288
- Shared with
- Public
- Parent
- None
- Children
- None
- Created on
- February 20, 2014 at 04:37 AM UTC
- Updated on
- February 20, 2014 at 04:37 AM UTC
- Description
Stretches or shrinks bands by the specified factor, 1-500. Values less than 100 shrink bands, over 100 streches bands. Works only on non-zero bands. Excludes disabled bands by default, optionally includes them.
Best for
Code
--[[
* Band Stretch
* Original Author: LociOiling
* Version 1.0 February 19, 2014
* adjust band length
- select length factor between 1 and 500
> values below 100 shrink bands, above 100 stretch bands
- disabled bands not adjusted, optionally include disabled bands
- zero-length bands not adjusted
- the "Goal Length" of the band is adjusted
- click "Adjust" to apply the change
- click "Exit" to leave the script
]]--
version = '1.0'
title = 'Band Stretch v'..version
print ( title )
nBnd = band.GetCount ( )
print ( "number of bands = " .. nBnd )
bLength = 0
nBndD = 0
nBndNz = 0
for jj = 1, nBnd do
if band.GetGoalLength ( jj ) ~= 0 then
nBndNz = nBndNz + 1
end
if not band.IsEnabled ( jj ) then
nBndD = nBndD + 1
end
end
if nBndD > 0 then
print ( "disabled bands = " .. nBndD )
end
if nBndNz ~= nBnd then
print ( "zero-length bands = " .. nBnd - nBndNz )
end
function round3 ( x ) --cut all afer 3-rd place
return x - x % 0.001
end
function AvgBandLen ( allBands )
bLength = 0
nBnd = 0
for jj = 1, band.GetCount () do
jLen = band.GetGoalLength ( jj )
if jLen > 0 then
if allBands or band.IsEnabled ( jj ) then
bLength = bLength + jLen
nBnd = nBnd + 1
end
end
end
if nBnd > 0 then
return bLength / nBnd
else
return 0
end
end
enabledBandAvg = AvgBandLen ( false )
print ( "average enabled band non-zero length = " .. round3 ( enabledBandAvg ) )
allBandAvg = AvgBandLen ( true )
print ( "average length all non-zero bands = " .. round3 ( allBandAvg ) )
bStretch = 100
function AskStretch ()
disabledB = false;
local ask = dialog.CreateDialog ( title )
repeat
ask.bStretch = dialog.AddSlider ( "Stretch factor:", bStretch, 1, 500, 0 )
ask.disabledB = dialog.AddCheckbox ( "Include disabled bands?", disabledB )
ask.l1 = dialog.AddLabel ( "Average enabled non-zero band length = " .. round3 ( enabledBandAvg ) )
ask.l2 = dialog.AddLabel ( "Average length all non-zero bands = " .. round3 ( allBandAvg ) )
ask.OK = dialog.AddButton ( "Adjust", 1 )
ask.Cancel = dialog.AddButton ( "Exit", 0 )
askresult = dialog.Show ( ask )
if askresult > 0 then
bStretch = ask.bStretch.value
strechF = bStretch / 100
disabledB = ask.disabledB.value
print ( "stretch factor " .. strechF )
for jj = 1, band.GetCount () do
if band.IsEnabled ( jj ) or disabledB then
jLen = band.GetGoalLength ( jj )
if ( jLen > 0 ) then
jLen = jLen * strechF
band.SetGoalLength ( jj, jLen )
end
end
end
enabledBandAvg = AvgBandLen ( false )
print ( "average enabled non-zero band length = " .. round3 ( enabledBandAvg ) )
allBandAvg = AvgBandLen ( true )
print ( "average length non-zero all bands = " .. round3 ( allBandAvg ) )
end
until askresult < 1
return
end
AskStretch ()