Second round of Lua script API updates

This commit is contained in:
Robin Gareus 2022-09-27 18:58:53 +02:00
parent 1abf6a77d6
commit 76c0f42ecb
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
23 changed files with 76 additions and 112 deletions

View file

@ -134,20 +134,20 @@ function factory (unused_params)
Session:begin_reversible_command("Add LFO automation to region")
local before = al:get_state() -- save previous state (for undo)
-- Clear events in target automation-list for the selected region.
al:clear(region:position() - region:start(), region:position() - region:start() + region:length())
al:clear(region:position() - region:start(), region:position() + region:length() - region:start())
local values = lut[wave]
local last = nil
for i = 0, cycles - 1 do
-- cycle length = region:length() / cycles
local cycle_start = region:position() - region:start() + i * region:length() / cycles
local offset = region:length() / cycles / (#values - 1)
local cycle_start = region:position() - region:start() + region:length():scale(Temporal.ratio(i, cycles))
local offset = region:length():scale (Temporal.ratio (1, cycles * (#values - 1)))
for k, v in pairs(values) do
local pos = cycle_start + (k - 1) * offset
local pos = cycle_start + offset:scale (Temporal.ratio (k - 1, 1))
if k == 1 and v ~= last then
-- Move event one sample further. A larger offset might be needed to avoid unwanted effects.
pos = pos + 1
pos = pos:increment ()
end
if k > 1 or v ~= last then
@ -167,7 +167,9 @@ function factory (unused_params)
-- Save undo
Session:add_command(al:memento_command(before, al:get_state()))
Session:commit_reversible_command(nil)
if not Session:abort_empty_reversible_command () then
Session:commit_reversible_command (nil)
end
region, al, lut = nil, nil, nil
end