1ardour { 2 ["type"] = "dsp", 3 name = "LTC Reader", 4 category = "Utility", 5 author = "Ardour Team", 6 license = "MIT", 7 description = [[Linear Timecode (LTC) Decoder with mixer strip inline display]] 8} 9 10function dsp_ioconfig () 11 return { { audio_in = 1, audio_out = 1}, } 12end 13 14function dsp_init (rate) 15 timeout = rate 16 samplerate = rate 17 ltc_reader = ARDOUR.DSP.LTCReader (rate / 25, ARDOUR.DSP.LTC_TV_STANDARD.LTC_TV_FILM_24) 18 self:shmem():allocate(5) 19end 20 21function dsp_run (ins, outs, n_samples) 22 if ins[1] ~= outs[1] then 23 ARDOUR.DSP.copy_vector (outs[1]:offset (0), ins[1]:offset (0), n_samples) 24 end 25 ltc_reader:write (ins[1]:offset (0), n_samples, 0) 26 timeout = timeout + n_samples 27 local to_ui = self:shmem():to_int(0):array() 28 local rv 29 repeat 30 local tc 31 rv, tc = ltc_reader:read (0, 0, 0, 0) 32 if rv >= 0 then 33 timeout = 0 34 self:shmem():atomic_set_int (0, 1) 35 self:shmem():atomic_set_int (1, tc[1]) 36 self:shmem():atomic_set_int (2, tc[2]) 37 self:shmem():atomic_set_int (3, tc[3]) 38 self:shmem():atomic_set_int (4, tc[4]) 39 self:queue_draw () 40 end 41 until rv < 0 42 if timeout > samplerate then 43 if 0 ~= self:shmem():atomic_get_int (0) then 44 self:shmem():atomic_set_int (0, 0) 45 self:queue_draw () 46 end 47 end 48end 49 50------------------------------------------------------------------------------- 51-- inline UI 52-- 53local txt = nil -- a pango context 54local vpadding = 2 55 56function render_inline (ctx, displaywidth, max_h) 57 if not txt then 58 txt = Cairo.PangoLayout (ctx, "Mono 10px") 59 end 60 61 local d = self:shmem():to_int(0):array() 62 if d[1] == 0 then 63 txt:set_text("--:--:--:--") 64 else 65 txt:set_text(string.format("%02d:%02d:%02d:%02d", d[2], d[3], d[4], d[5])) 66 end 67 68 -- compute the size of the display 69 local txtwidth, lineheight = txt:get_pixel_size() 70 local displayheight = math.min(vpadding + (lineheight + vpadding), max_h) 71 72 -- clear background 73 ctx:rectangle (0, 0, displaywidth, displayheight) 74 ctx:set_source_rgba (.2, .2, .2, 1.0) 75 ctx:fill () 76 ctx:set_source_rgba (.8, .8, .8, 1.0) 77 ctx:move_to ((displaywidth - txtwidth) / 2, 1) 78 txt:show_in_cairo_context (ctx) 79 80 return {displaywidth, displayheight} 81end 82 83