Skip to content

Add A/B loop points visual indicator #724

@NeoLc

Description

@NeoLc

Expected behavior of the wanted feature

-- ** AI Coding use gemini **

local function draw_a_b_range(element, elem_ass)
    --log("Name:", element.name, "Width:", elem_geo.w, "Type:", element.type)
    if element.name ~= "seekbar" then return end

    local duration = mp.get_property_number("duration")
    local ab_a = mp.get_property_number("ab-loop-a")
    local ab_b = mp.get_property_number("ab-loop-b")
    if not duration or duration <= 0 or not ab_a or ab_a < 0 then return end

    local slider_lo = element.layout.slider
    local elem_geo = element.layout.geometry

    ----------------------------------------------------------------
    -- 🎯 第一步:实现类似 t2x 的坐标映射逻辑
    ----------------------------------------------------------------
    local margin = slider_lo.margin or 3
    local usable_width = elem_geo.w - (margin * 2)

    local function t2x(sec)
        local pos = sec / duration
        if pos < 0 then pos = 0 elseif pos > 1 then pos = 1 end
        -- 核心映射公式:起始边距 + (比例 * 有效宽度)
        return margin + (pos * usable_width)
    end

    ----------------------------------------------------------------
    -- 🎯 第二步:计算 A 和 B 的 X 坐标
    ----------------------------------------------------------------
    local ax = t2x(ab_a)
    local bx = (ab_b and ab_b > ab_a and ab_b <= duration) and t2x(ab_b) or nil

    local function draw_nibble(ass, s)
        if slider_lo.gap >= 5 then
            local bar_h = 3
            if slider_lo.nibbles_top then
                if slider_lo.nibbles_style == "triangle" then
                    ass:move_to(s - 3, slider_lo.gap - 5)
                    ass:line_to(s + 3, slider_lo.gap - 5)
                    ass:line_to(s, slider_lo.gap - 1)
                elseif slider_lo.nibbles_style == "bar" then
                    ass:rect_cw(s - 1, slider_lo.gap - bar_h, s + 1, slider_lo.gap)
                else
                    ass:rect_cw(s - 1, slider_lo.gap - bar_h, s + 1, elem_geo.h - slider_lo.gap)
                end
            end
            if slider_lo.nibbles_bottom then
                if slider_lo.nibbles_style == "triangle" then
                    ass:move_to(s - 3, elem_geo.h - slider_lo.gap + 5)
                    ass:line_to(s, elem_geo.h - slider_lo.gap + 1)
                    ass:line_to(s + 3, elem_geo.h - slider_lo.gap + 5)
                elseif slider_lo.nibbles_style == "bar" then
                    ass:rect_cw(s - 1, elem_geo.h - slider_lo.gap, s + 1, elem_geo.h - slider_lo.gap + bar_h)
                else
                    ass:rect_cw(s - 1, slider_lo.gap, s + 1, elem_geo.h - slider_lo.gap + bar_h)
                end
            end
        else
            if slider_lo.nibbles_top then
                ass:rect_cw(s - 1, 0, s + 1, slider_lo.gap)
            end
            if slider_lo.nibbles_bottom then
                ass:rect_cw(s - 1, elem_geo.h - slider_lo.gap, s + 1, elem_geo.h)
            end
        end
    end

    ----------------------------------------------------------------
    -- 🎯 第三步:绘制 A 和 B 的 浮标
    ----------------------------------------------------------------
    if ax then 
        draw_nibble(elem_ass, ax)
    end
    
    if bx then 
        draw_nibble(elem_ass, bx)
    end
end

local function draw_seekbar_nibbles(element, elem_ass)
   -- ...
   draw_a_b_range(element, elem_ass)
   -- ...
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestNew feature or requestneed-feedbackMore feedback is needed to reach a conclusion

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions