diff options
author | Robin Gareus <robin@gareus.org> | 2020-03-03 00:27:25 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2020-03-03 00:28:19 +0100 |
commit | 1a69bc4a9695b2c77cdd83c157af3987eddbb343 (patch) | |
tree | a204e1d4415a4da55129cbb4886878c82a770f67 /share | |
parent | 82541b33a4a8db57680d9cc05fcbafa35e5d8660 (diff) |
Fix off by one in Lua scripts
Lua arrays (tables) start counting at one.
Also `for i = a, b do .. end` is inclusive: a <= i <= b
Diffstat (limited to 'share')
-rw-r--r-- | share/scripts/__readable.lua | 2 | ||||
-rw-r--r-- | share/scripts/_find_nonzero_sample.lua | 4 | ||||
-rw-r--r-- | share/scripts/s_region_gain.lua | 2 |
3 files changed, 4 insertions, 4 deletions
diff --git a/share/scripts/__readable.lua b/share/scripts/__readable.lua index b9a991a782..3c918e0091 100644 --- a/share/scripts/__readable.lua +++ b/share/scripts/__readable.lua @@ -29,7 +29,7 @@ function factory () return function () -- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray local d = cmem:to_float (0):array() -- iterate over the audio sample data - for i = 0, s do + for i = 1, s do if math.abs (d[i]) > peak then peak = math.abs (d[i]) end diff --git a/share/scripts/_find_nonzero_sample.lua b/share/scripts/_find_nonzero_sample.lua index c23d2b0b4d..b79f832c9c 100644 --- a/share/scripts/_find_nonzero_sample.lua +++ b/share/scripts/_find_nonzero_sample.lua @@ -42,10 +42,10 @@ function factory () return function () -- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray local d = cmem:to_float (0):array() -- iterate over the audio sample data - for i = 0, s do + for i = 1, s do if math.abs (d[i]) > 0 then if (nonzeropos < 0 or pos + i < nonzeropos) then - nonzeropos = pos + i + nonzeropos = pos + i - 1 end break end diff --git a/share/scripts/s_region_gain.lua b/share/scripts/s_region_gain.lua index 648e76629c..87a1760b0f 100644 --- a/share/scripts/s_region_gain.lua +++ b/share/scripts/s_region_gain.lua @@ -41,7 +41,7 @@ function factory () return function () -- http://manual.ardour.org/lua-scripting/class_reference/#C:FloatArray local d = cmem:to_float (0):array() -- iterate over the audio sample data - for i = 0, s do + for i = 1, s do if math.abs (d[i]) > peak then peak = math.abs (d[i]) end |