refine lua-script documentation

This commit is contained in:
Robin Gareus 2016-07-10 16:48:38 +02:00
parent 7745a37394
commit 4bb54f4128
4 changed files with 35 additions and 16 deletions

View file

@ -36,8 +36,8 @@ end
function dsp_runmap (bufs, in_map, out_map, n_samples, offset) function dsp_runmap (bufs, in_map, out_map, n_samples, offset)
for c = 1,audio_ins do for c = 1,audio_ins do
-- Note: lua starts counting at 1, ardour's ChanMapping::get() at 0 -- Note: lua starts counting at 1, ardour's ChanMapping::get() at 0
local ib = in_map:get(ARDOUR.DataType("audio"), c - 1); -- get id of mapped input buffer for given cannel local ib = in_map:get(ARDOUR.DataType("audio"), c - 1); -- get id of mapped input buffer for given channel
local ob = out_map:get(ARDOUR.DataType("audio"), c - 1); -- get id of mapped output buffer for given cannel local ob = out_map:get(ARDOUR.DataType("audio"), c - 1); -- get id of mapped output buffer for given channel
assert (ib ~= ARDOUR.ChanMapping.Invalid); assert (ib ~= ARDOUR.ChanMapping.Invalid);
assert (ob ~= ARDOUR.ChanMapping.Invalid); assert (ob ~= ARDOUR.ChanMapping.Invalid);
local a = bufs:get_audio (ib):data (offset):get_table(n_samples) -- copy audio-data from input buffer local a = bufs:get_audio (ib):data (offset):get_table(n_samples) -- copy audio-data from input buffer

View file

@ -25,7 +25,7 @@ function factory ()
mb:silence (n_samples, 0); -- clear existing buffer mb:silence (n_samples, 0); -- clear existing buffer
for _,e in pairs (events) do for _,e in pairs (events) do
-- e is an http://ardourman/lua-scripting/class_reference/#Evoral:MidiEvent -- e is-a http://manual.ardour.org/lua-scripting/class_reference/#Evoral:MidiEvent
e:set_channel (2) e:set_channel (2)
mb:push_event (e) mb:push_event (e)
end end

View file

@ -16,18 +16,24 @@ end
function dsp_has_midi_input () return true end function dsp_has_midi_input () return true end
function dsp_has_midi_output () return true end function dsp_has_midi_output () return true end
-- "dsp_runmap" uses Ardour's internal processor API, eqivalent to
-- 'connect_and_run()". There is no overhead (mapping, translating buffers).
-- The lua implementation is responsible to map all the buffers directly.
function dsp_runmap (bufs, in_map, out_map, n_samples, offset) function dsp_runmap (bufs, in_map, out_map, n_samples, offset)
local ib = in_map:get(ARDOUR.DataType("midi"), 0); -- get id of input buffer -- see http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:ChanMapping
local ob = in_map:get(ARDOUR.DataType("midi"), 0); -- get id of output buffer local ib = in_map:get (ARDOUR.DataType ("midi"), 0); -- get index of the 1st mapped midi input buffer
local ob = in_map:get (ARDOUR.DataType ("midi"), 0); -- get index of the 1st mapped midi output buffer
assert (ib ~= ARDOUR.ChanMapping.Invalid); assert (ib ~= ARDOUR.ChanMapping.Invalid);
assert (ib == ob); -- inplace, buffers are identical assert (ib == ob); -- require inplace, buffers are identical
local mb = bufs:get_midi (ib) -- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:MidiBuffer
events = mb:table() -- copy event list into lua table local mb = bufs:get_midi (ib) -- get the mapped buffer
events = mb:table () -- copy event list into a lua table
-- iterate over all midi events
for _,e in pairs (events) do for _,e in pairs (events) do
-- e is an http://ardourman/lua-scripting/class_reference/#Evoral:MidiEvent -- e is-a http://manual.ardour.org/lua-scripting/class_reference/#Evoral:MidiEvent
--
--print (e:channel()) --print (e:channel())
end end
end end

View file

@ -44,8 +44,10 @@ end
-- a C memory area. -- a C memory area.
-- It needs to be in global scope. -- It needs to be in global scope.
-- When the variable is set to nil, the allocated memory -- When the variable is set to nil, the allocated memory is free()ed.
-- is free()ed -- the memory can be interpeted as float* for use in DSP, or read/write
-- to a C++ Ringbuffer instance.
-- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP:DspShm
local cmem = nil local cmem = nil
function dsp_init (rate) function dsp_init (rate)
@ -54,6 +56,7 @@ function dsp_init (rate)
dpy_wr = 0 dpy_wr = 0
-- create a ringbuffer to hold (float) audio-data -- create a ringbuffer to hold (float) audio-data
-- http://manual.ardour.org/lua-scripting/class_reference/#PBD:RingBufferF
rb = PBD.RingBufferF (2 * rate) rb = PBD.RingBufferF (2 * rate)
-- allocate memory, local mix buffer -- allocate memory, local mix buffer
@ -72,6 +75,9 @@ function dsp_init (rate)
self:table ():set (tbl); self:table ():set (tbl);
end end
-- "dsp_runmap" uses Ardour's internal processor API, eqivalent to
-- 'connect_and_run()". There is no overhead (mapping, translating buffers).
-- The lua implementation is responsible to map all the buffers directly.
function dsp_runmap (bufs, in_map, out_map, n_samples, offset) function dsp_runmap (bufs, in_map, out_map, n_samples, offset)
-- here we sum all audio input channels channels and then copy the data to a ringbuffer -- here we sum all audio input channels channels and then copy the data to a ringbuffer
-- for the GUI to process later -- for the GUI to process later
@ -80,10 +86,16 @@ function dsp_runmap (bufs, in_map, out_map, n_samples, offset)
local ccnt = 0 -- processed channel count local ccnt = 0 -- processed channel count
local mem = cmem:to_float(0) -- a "FloatArray", float* for direct C API usage from the previously allocated buffer local mem = cmem:to_float(0) -- a "FloatArray", float* for direct C API usage from the previously allocated buffer
for c = 1,audio_ins do for c = 1,audio_ins do
-- see http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:ChanMapping
-- Note: lua starts counting at 1, ardour's ChanMapping::get() at 0 -- Note: lua starts counting at 1, ardour's ChanMapping::get() at 0
local ib = in_map:get (ARDOUR.DataType ("audio"), c - 1) -- get id of mapped input buffer for given cannel local ib = in_map:get (ARDOUR.DataType ("audio"), c - 1) -- get index of mapped input buffer
local ob = out_map:get (ARDOUR.DataType ("audio"), c - 1) -- get id of mapped output buffer for given cannel local ob = out_map:get (ARDOUR.DataType ("audio"), c - 1) -- get index of mapped output buffer
-- check if the input is connected to a buffer
if (ib ~= ARDOUR.ChanMapping.Invalid) then if (ib ~= ARDOUR.ChanMapping.Invalid) then
-- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:AudioBuffer
-- http://manual.ardour.org/lua-scripting/class_reference/#ARDOUR:DSP
if c == 1 then if c == 1 then
-- first channel, copy as-is -- first channel, copy as-is
ARDOUR.DSP.copy_vector (mem, bufs:get_audio (ib):data (offset), n_samples) ARDOUR.DSP.copy_vector (mem, bufs:get_audio (ib):data (offset), n_samples)
@ -104,8 +116,8 @@ function dsp_runmap (bufs, in_map, out_map, n_samples, offset)
-- In case we're processing in-place some buffers may be identical, -- In case we're processing in-place some buffers may be identical,
-- so this must be done *after processing*. -- so this must be done *after processing*.
for c = 1,audio_ins do for c = 1,audio_ins do
local ib = in_map:get (ARDOUR.DataType ("audio"), c - 1) -- get id of mapped input buffer for given cannel local ib = in_map:get (ARDOUR.DataType ("audio"), c - 1)
local ob = out_map:get (ARDOUR.DataType ("audio"), c - 1) -- get id of mapped output buffer for given cannel local ob = out_map:get (ARDOUR.DataType ("audio"), c - 1)
if (ib == ARDOUR.ChanMapping.Invalid and ob ~= ARDOUR.ChanMapping.Invalid) then if (ib == ARDOUR.ChanMapping.Invalid and ob ~= ARDOUR.ChanMapping.Invalid) then
bufs:get_audio (ob):silence (n_samples, offset) bufs:get_audio (ob):silence (n_samples, offset)
end end
@ -122,6 +134,7 @@ function dsp_runmap (bufs, in_map, out_map, n_samples, offset)
end end
-- write data to the ringbuffer -- write data to the ringbuffer
-- http://manual.ardour.org/lua-scripting/class_reference/#PBD:RingBufferF
rb:write (mem, n_samples) rb:write (mem, n_samples)
-- emit QueueDraw every FPS -- emit QueueDraw every FPS