fix issue with initialization of a BBT_Time variable.
[ardour.git] / scripts / scope.lua
index 961670a0ac12996e028a2e71a6eb78380369d55c..1952c100c431151fa6ac3534105cf646618c8a70 100644 (file)
@@ -1,11 +1,10 @@
 ardour {
        ["type"]    = "dsp",
-       name        = "Inline Scope",
-       license     = "GPLv2",
-       author      = "Robin Gareus",
-       email       = "robin@gareus.org",
-       site        = "http://gareus.org",
-       description = [[An Example DSP Plugin to display the waveform on the mixer strip]]
+       name        = "a-Inline Scope",
+       category    = "Visualization",
+       license     = "MIT",
+       author      = "Ardour Team",
+       description = [[Mixer strip inline waveform display]]
 }
 
 -- return possible i/o configurations
@@ -17,9 +16,9 @@ end
 function dsp_params ()
        return
        {
-               { ["type"] = "input", name = "timescale", min = .1, max = 5, default = 2, unit="sec", logarithmic = true },
-               { ["type"] = "input", name = "loscale", min = 0, max = 1, default = 0, toggled = true },
-               { ["type"] = "input", name = "height", min = 0, max = 3, default = 1, unit="dB", enum = true, scalepoints =
+               { ["type"] = "input", name = "Timescale", min = .1, max = 5, default = 2, unit="sec", logarithmic = true },
+               { ["type"] = "input", name = "Logscale", min = 0, max = 1, default = 0, toggled = true },
+               { ["type"] = "input", name = "Height (Aspect)", min = 0, max = 3, default = 1, enum = true, scalepoints =
                        {
                                ["Min"] = 0,
                                ["16:10"] = 1,
@@ -42,8 +41,6 @@ end
 function dsp_configure (ins, outs)
        -- store configuration in global variable
        audio_ins = ins:n_audio ()
-       local audio_outs = outs:n_audio ()
-       assert (audio_ins == audio_outs)
        -- allocate shared memory area
        -- this is used to speed up DSP computaton (using a C array)
        -- and to share data with the GUI
@@ -63,14 +60,35 @@ function dsp_runmap (bufs, in_map, out_map, n_samples, offset)
        for c = 1,audio_ins do
                -- 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
-               assert (ib ~= ARDOUR.ChanMapping.Invalid)
+               local ob = out_map:get (ARDOUR.DataType ("audio"), c - 1); -- get id of mapped output buffer for given cannel
                local chn_off = 4 + bufsiz * (c - 1)
-               if (write_ptr + n_samples < bufsiz) then
-                       ARDOUR.DSP.copy_vector (shmem:to_float (write_ptr + chn_off), bufs:get_audio (ib):data (offset), n_samples)
+               if (ib ~= ARDOUR.ChanMapping.Invalid) then
+                       if (write_ptr + n_samples < bufsiz) then
+                               ARDOUR.DSP.copy_vector (shmem:to_float (write_ptr + chn_off), bufs:get_audio (ib):data (offset), n_samples)
+                       else
+                               local w0 = bufsiz - write_ptr;
+                               ARDOUR.DSP.copy_vector (shmem:to_float (write_ptr + chn_off), bufs:get_audio (ib):data (offset), w0)
+                               ARDOUR.DSP.copy_vector (shmem:to_float (chn_off)            , bufs:get_audio (ib):data (offset + w0), n_samples - w0)
+                       end
+                       if (ob ~= ARDOUR.ChanMapping.Invalid and ib ~= ob) then
+                               ARDOUR.DSP.copy_vector (bufs:get_audio (ob):data (offset), bufs:get_audio (ib):data (offset), n_samples)
+                       end
                else
-                       local w0 = bufsiz - write_ptr;
-                       ARDOUR.DSP.copy_vector (shmem:to_float (write_ptr + chn_off), bufs:get_audio (ib):data (offset), w0)
-                       ARDOUR.DSP.copy_vector (shmem:to_float (chn_off)            , bufs:get_audio (ib):data (offset), n_samples - w0)
+                       if (write_ptr + n_samples < bufsiz) then
+                               ARDOUR.DSP.memset (shmem:to_float (write_ptr + chn_off), 0, n_samples)
+                       else
+                               local w0 = bufsiz - write_ptr;
+                               ARDOUR.DSP.memset (shmem:to_float (write_ptr + chn_off), 0, w0)
+                               ARDOUR.DSP.memset (shmem:to_float (chn_off)            , 0, n_samples - w0)
+                       end
+               end
+       end
+       -- clear unconnected inplace buffers
+       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 ob = out_map:get (ARDOUR.DataType ("audio"), c - 1); -- get id of mapped output buffer for given cannel
+               if (ib == ARDOUR.ChanMapping.Invalid and ob ~= ARDOUR.ChanMapping.Invalid) then
+                       bufs:get_audio (ob):silence (n_samples, offset)
                end
        end
 
@@ -140,9 +158,9 @@ function render_inline (ctx, w, max_h)
 
        -- prepare drawing
        ctx:set_line_width (1.0)
-       local dash3 = ARDOUR.DoubleVector ()
+       local dash3 = C.DoubleVector ()
        dash3:add ({1, 3})
-       local dash4 = ARDOUR.DoubleVector ()
+       local dash4 = C.DoubleVector ()
        dash4:add ({1, 4})
 
        -- plot every channel