properly handle meter channel count changes
[ardour.git] / scripts / amp3.lua
1 ardour {
2         ["type"]    = "dsp",
3         name        = "Simple Amp III",
4         category    = "Example",
5         license     = "MIT",
6         author      = "Ardour Lua Task Force",
7         description = [[
8         An Example DSP Plugin for processing audio, to
9         be used with Ardour's Lua scripting facility.]]
10 }
11
12 function dsp_ioconfig ()
13         return
14         {
15                 { audio_in = -1, audio_out = -1},
16         }
17 end
18
19
20 function dsp_params ()
21         return
22         {
23                 { ["type"] = "input", name = "Gain", min = -20, max = 20, default = 6, unit="dB", scalepoints = { ["0"] = 0, ["twice as loud"] = 6 , ["half as loud"] = -6 } },
24         }
25 end
26
27
28 -- use ardour's vectorized functions
29 --
30 -- This is as efficient as Ardour doing it itself in C++
31 -- Lua function overhead is negligible
32 --
33 -- this also exemplifies the /simpler/ way of delegating the
34 -- channel-mapping to ardour.
35
36 function dsp_run (ins, outs, n_samples)
37         local ctrl = CtrlPorts:array() -- get control port array (read/write)
38         local gain = ARDOUR.DSP.dB_to_coefficient (ctrl[1])
39         assert (#ins == #outs) -- ensure that we can run in-place (channel count matches)
40         for c = 1,#ins do
41                 assert (ins[c]:sameinstance(outs[c])) -- check in-place
42                 ARDOUR.DSP.apply_gain_to_buffer (ins[c], n_samples, gain); -- process in-place
43         end
44 end