import svgwrite

WIDTH, HEIGHT = 2_000, 500
DASH_ARRAY = [6, 6]
TEXT_STYLE = "fill: #fff; font-size: 18px; font-family: Inter, InterVariable, sans-serif;"

LANE_HEIGHT = HEIGHT // 5
LANE_THICKNESS = 2
LANE_TEXT_X, LANE_TEXT_Y = 12, 15

TIME_X, TIME_Y = 32, 4 * LANE_HEIGHT - LANE_THICKNESS
TIME_WIDTH = WIDTH - TIME_X
TIME_THICKNESS = 4
TICK_HEIGHT = 9

TOTAL_DUR = 4 * 60 + 44
SECTS = [
    ("\u03b1", 15),
    ("A", 41),
    ("A\u2032", 55),
    ("B", 1 * 60 + 15),
    ("C", 1 * 60 + 32),
    ("D", 1 * 60 + 45),
    ("E", 2 * 60 + 5),
    ("F", 2 * 60 + 27),
    ("G", 2 * 60 + 47),
    ("H", 3 * 60 + 10),
    ("I", 3 * 60 + 39),
    ("J", 4 * 60 + 21),
    ("K", 4 * 60 + 44),
]
GTR_1, GTR_2, BASS, DRUMKIT = 0, 1, 2, 3
TEXTURE_EVENTS = [
    # start, end, instr, voices, relation
    (0, 1 * 60 + 10, GTR_1, 1, None),
    (0, 55, GTR_2, 1, "H"),
    (0, 55, BASS, 1, "C"),
    (0, 55, DRUMKIT, 3, "S"),
    (55, 1 * 60 + 10, GTR_2, 2, "HP"),
    (55, 1 * 60 + 10, BASS, 1, "H"),
    (55, 1 * 60 + 10, DRUMKIT, 4, "R"),
    (1 * 60 + 10, 1 * 60 + 15, GTR_1, 2, None),
    (1 * 60 + 10, 1 * 60 + 15, GTR_2, 2, "R"),
    (1 * 60 + 10, 1 * 60 + 15, BASS, 1, "R"),
    (1 * 60 + 10, 1 * 60 + 15, DRUMKIT, 3, "S"),
    (1 * 60 + 15, 1 * 60 + 32, GTR_1, 1, None),
    (1 * 60 + 15, 1 * 60 + 32, GTR_2, 2, "HP"),
    (1 * 60 + 15, 1 * 60 + 32, BASS, 1, "H"),
    (1 * 60 + 15, 1 * 60 + 24, DRUMKIT, 3, "R"),
    (1 * 60 + 24, 1 * 60 + 32, DRUMKIT, 3, "S"),
    (1 * 60 + 32, 1 * 60 + 45, GTR_1, 2, None),
    (1 * 60 + 32, 1 * 60 + 45, GTR_2, 2, "R"),
    (1 * 60 + 32, 1 * 60 + 39, BASS, 1, "R"),
    (1 * 60 + 32, 1 * 60 + 39, DRUMKIT, 3, "R"),
]

WHITE = "#eeeeee"
GREY = "#7f7f7f"

dwg = svgwrite.Drawing(
    filename="textures.svg", size=(WIDTH, HEIGHT), debug=True
)

for lane, (name, offset) in enumerate(
    [("guitar 1", 3), ("guitar 2", 1), ("bass", 13), ("drumkit", 0)]
):
    if lane < 3:
        lane_y = LANE_HEIGHT * (lane + 1) - LANE_THICKNESS
        lane_line = dwg.add(dwg.line(start=(0, lane_y), end=(WIDTH, lane_y)))
        lane_line.stroke(GREY, width=LANE_THICKNESS).dasharray(DASH_ARRAY)

    text_y = LANE_TEXT_Y + LANE_HEIGHT * lane + offset
    text = dwg.add(
        dwg.text(name, insert=(LANE_TEXT_X, text_y), style=TEXT_STYLE)
    )
    text.rotate(90, (LANE_TEXT_X, text_y))

time_line = dwg.add(dwg.line(start=(TIME_X, TIME_Y), end=(WIDTH, TIME_Y)))
time_line.stroke(WHITE, width=TIME_THICKNESS)
for name, t_end in SECTS:
    tick_x = TIME_X + TIME_WIDTH * (t_end / TOTAL_DUR)
    tick = dwg.add(
        dwg.line(
            start=(tick_x, 1 + TIME_Y), end=(tick_x, 1 + TIME_Y + TICK_HEIGHT)
        )
    )
    tick.stroke(WHITE, width=TIME_THICKNESS)

dwg.save(pretty=True)
