灵符lingfu

LingSys

↓ 0 downloads

Your machine's memory, GPU, motherboard and network, drawn and played in the Ling design system: LingSys, a small build for USB liquid-cooler displays, LingNet for IPv4/IPv6, DNS and packets, and a LingOS edition. 64-bit and 32-bit Windows builds included.

Keywords system-monitor, visualization, network, ipv6, gpu, lcd, lingos, ling
lingfu install LingSys
LicenseMIT
AuthorsLing Lin <taellinglin@gmail.com>
READMECode / FilesVersionsDependency GraphDependentsSecurityBuildsSettings

Code / Files (48)

src/90_main.ling
# ───────────────────────────── main ──────────────────────────────────────────
bind SHOT_SEQ = [[0, 0], [1, 0], [1, 1], [1, 2], [1, 3], [2, 0], [2, 1], [2, 2], [2, 3], [3, 0], [3, 1], [3, 2], [4, 0], [4, 1], [4, 2]]

bind start = do {
    bind args = get_args()
    bind full = 0
    bind forceSim = 0
    bind shot = 0
    bind ai = 0
    while ai < len(args) {
        if args[ai] == "full" { bind full = 1 }
        if args[ai] == "sim" { bind forceSim = 1 }
        if args[ai] == "shot" { bind shot = 1 }
        bind ai = ai + 1
    }
    if full == 1 { open_fullscreen("HatchSYS") } else { open_window(1280, 720, "HatchSYS") }
    bind W = get_width()
    bind FH = get_height()
    bind Hc = FH - MENU_H
    set_blend(1)
    set_frame_blur(0.45)
    audio_volume(0.7)
    audio_fx_reverb(0.55)
    audio_fx_delay(0.42, 0.45, 0.3)

    bind hil = hilbert_table(32)
    bind t0 = time_now()
    bind tprev = 0.0
    bind sec = 0
    bind view = 0
    bind auto = 0
    bind showHud = 1
    bind mute = 0
    bind pluck = 0
    bind alOn = 1
    bind alBase = [0.0, 0.0, 0.0, 0.0]
    bind alLast = [0.0 - 100.0, 0.0 - 100.0, 0.0 - 100.0, 0.0 - 100.0, 0.0 - 100.0, 0.0 - 100.0, 0.0 - 100.0, 0.0 - 100.0, 0.0 - 100.0]
    bind alLeft = 0
    bind alNext = 0.0
    bind alCode = 0
    bind alText = ""
    bind alBorn = 0.0 - 100.0
    bind lastRead = 0.0 - 10.0
    bind lastSfx = 0.0
    bind autoT = 0.0
    bind prevDown = 0
    bind shotIdx = 0
    bind shotN = 0
    bind gsel = 0

    # sampler liveness: 0 = no data (simulated), 1 = live, 2 = stale; and the stamp last seen from each
    bind liveM = 0
    bind liveG = 0
    bind liveB = 0
    bind liveN = 0
    bind tsM = 0.0
    bind tsG = 0.0
    bind tsB = 0.0
    bind tsN = 0.0
    bind chgM = 0.0
    bind chgG = 0.0
    bind chgB = 0.0
    bind chgN = 0.0

    # memory: smoothed state and targets
    bind cats = sim_cats(0.0)
    bind tgtCats = cats
    bind total = 16384.0
    bind rates = [0.0, 0.0, 0.0, 0.0]
    bind tgtRates = rates
    bind names = SIM_NAMES
    bind ws = []
    bind pv = []
    bind ior = []
    bind iow = []
    bind i = 0
    while i < len(SIM_NAMES) {
        bind ws = list_push(ws, 100.0)
        bind pv = list_push(pv, 80.0)
        bind ior = list_push(ior, 0.0)
        bind iow = list_push(iow, 0.0)
        bind i = i + 1
    }
    bind tws = ws
    bind tpv = pv

    # gpu, board, network: the latest packs and the smoothed numbers inside them
    bind tgtGP = sim_gpu(0.0)
    bind gpv = tgtGP[GP_VEC]
    bind gpe = tgtGP[GP_ENG]
    bind tgtBP = sim_board(0.0)
    bind bvS = tgtBP[BP_BV]
    bind cuS = tgtBP[BP_CU]
    bind cfS = tgtBP[BP_CF]
    bind tgtNP = sim_net(0.0)
    bind nvS = tgtNP[NP_NV]
    bind hsAll = hs_new()
    bind lastHs = 0.0

    bind energy = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    bind A = [0.0, 0.0, 0.0, 0.0]
    bind ev = []
    bind hist = []
    bind rot = 0.0
    bind hueShift = 0.0
    bind act = 0.0
    bind rdA = 0.0
    bind wrA = 0.0
    bind fltA = 0.0
    bind alA = 0.0

    while window_is_open() {
        bind t = time_now() - t0
        bind dt = clamp(t - tprev, 0.001, 0.1)
        bind tprev = t

        # ---- input
        bind mx = mouse_x()
        bind my = mouse_y()
        bind click = 0
        if mouse_down() {
            if prevDown == 0 { bind click = 1 }
            bind prevDown = 1
        } else {
            bind prevDown = 0
        }
        bind nsec = sec
        bind nview = view
        bind setv = 0
        if key_pressed("escape") {
            if sec == 0 { close_window() } else { bind nsec = 0 }
        }
        if key_pressed("q") { close_window() }
        if key_pressed("0") { bind nsec = 0 }
        if key_pressed("home") { bind nsec = 0 }
        if key_pressed("1") { bind nsec = 1 }
        if key_pressed("2") { bind nsec = 2 }
        if key_pressed("3") { bind nsec = 3 }
        if key_pressed("4") { bind nsec = 4 }
        if key_pressed("right") { bind nsec = (sec + 1) % 5 }
        if key_pressed("left") { bind nsec = (sec + 4) % 5 }
        if key_pressed("tab") {
            if VIEW_COUNT[sec] > 1 { bind nview = (view + 1) % VIEW_COUNT[sec] } else { bind nsec = (sec + 1) % 5 }
        }
        if key_pressed("space") {
            if VIEW_COUNT[sec] > 1 { bind nview = (view + 1) % VIEW_COUNT[sec] } else { bind nsec = (sec + 1) % 5 }
        }
        if sec == 2 {
            if key_pressed("up") { bind gsel = gsel + tgtGP[GP_N] - 1 }
            if key_pressed("down") { bind gsel = gsel + 1 }
        }
        if click == 1 {
            bind mh = menu_hit(mx, my, W, FH, sec)
            if mh >= 0 {
                if mh < 5 { bind nsec = mh }
                if mh >= 10 { bind nview = mh - 10 }
            }
            if sec == 2 {
                if view == 3 {
                    bind ghit = fleet_hit(mx, my, W, Hc, tgtGP[GP_N])
                    if ghit >= 0 { bind gsel = ghit }
                }
            }
            if sec == 0 {
                bind chit = card_hit(mx, my, W, Hc)
                if chit >= 0 { bind nsec = chit + 1 }
            }
        }
        if key_pressed("a") { bind auto = 1 - auto }
        if key_pressed("h") { bind showHud = 1 - showHud }
        if key_pressed("m") { bind mute = 1 - mute }
        if key_pressed("p") { bind pluck = 1 - pluck }
        if key_pressed("n") { bind alOn = 1 - alOn }
        if auto == 1 {
            if t - autoT > 28.0 {
                bind autoT = t
                bind setv = 1
                bind nview = view + 1
                if nview >= VIEW_COUNT[sec] {
                    bind nview = 0
                    bind nsec = (sec + 1) % 5
                }
            }
        }
        if shot == 1 {
            bind setv = 1
            bind nsec = SHOT_SEQ[shotIdx][0]
            bind nview = SHOT_SEQ[shotIdx][1]
            bind shotN = shotN + 1
            bind need = 170
            if shotIdx == 0 { bind need = 600 }
            if shotN == need {
                screenshot("hatchsys_" + SEC_NAME[nsec] + "_" + SUB_NAME[nsec][nview])
                bind shotIdx = shotIdx + 1
                bind shotN = 0
                if shotIdx >= len(SHOT_SEQ) {
                    bind shotIdx = len(SHOT_SEQ) - 1
                    close_window()
                }
            }
        }
        if nsec != sec {
            if setv == 0 { bind nview = 0 }
            bind ev = []
            bind hist = []
            bind autoT = t
        }
        bind sec = nsec
        bind view = min(nview, VIEW_COUNT[sec] - 1)
        bind gsel = gsel % tgtGP[GP_N]

        # ---- data: the snapshots, re-read about twice a second
        if t - lastRead > 0.4 {
            bind lastRead = t
            bind liveM = 0
            bind liveG = 0
            bind liveB = 0
            bind liveN = 0
            if forceSim == 0 {
                if file_exists("mem.snap") {
                    bind snap = parse_snap(read_file("mem.snap"))
                    if snap[0] == 1 {
                        bind liveM = 1
                        bind g = snap[1]
                        bind r = snap[2]
                        bind total = g[0]
                        bind tgtCats = categories(g, snap[3])
                        bind tgtRates = [r[0], r[1] + r[3], r[2] + r[4] + r[7], r[5]]
                        bind names = snap[4]
                        bind tws = snap[5]
                        bind tpv = snap[6]
                        bind ior = snap[7]
                        bind iow = snap[8]
                        if snap[9] != tsM {
                            bind tsM = snap[9]
                            bind chgM = t
                        }
                        if t - chgM > 8.0 { bind liveM = 2 }
                    }
                }
                if file_exists("gpu.snap") {
                    bind gn = parse_gpu(read_file("gpu.snap"))
                    if gn[0] == 1 {
                        bind tgtGP = gn
                        bind liveG = 1
                        if gn[8] != tsG {
                            bind tsG = gn[8]
                            bind chgG = t
                        }
                        if t - chgG > 8.0 { bind liveG = 2 }
                    }
                }
                if file_exists("board.snap") {
                    bind bn = parse_board(read_file("board.snap"))
                    if bn[0] == 1 {
                        bind tgtBP = bn
                        bind liveB = 1
                        if bn[9] != tsB {
                            bind tsB = bn[9]
                            bind chgB = t
                        }
                        if t - chgB > 8.0 { bind liveB = 2 }
                    }
                }
                if file_exists("net.snap") {
                    bind nn = parse_net(read_file("net.snap"))
                    if nn[0] == 1 {
                        bind tgtNP = nn
                        bind liveN = 1
                        if nn[5] != tsN {
                            bind tsN = nn[5]
                            bind chgN = t
                        }
                        if t - chgN > 8.0 { bind liveN = 2 }
                    }
                }
            }
            if liveM == 0 {
                bind total = 16384.0
                bind tgtCats = sim_cats(t)
                bind sr = sim_rates(t)
                bind tgtRates = [sr[0], sr[1], sr[2], sr[0] * 0.2]
                bind names = SIM_NAMES
                bind tws = []
                bind tpv = []
                bind ior = []
                bind iow = []
                bind q = 0
                while q < len(SIM_NAMES) {
                    bind base = 3000.0 / (1.0 + q * 0.7)
                    bind tws = list_push(tws, base * (1.0 + 0.3 * sin(t * 0.1 + q)))
                    bind tpv = list_push(tpv, base * 0.7 * (1.0 + 0.2 * sin(t * 0.13 + q * 2.0)))
                    bind ior = list_push(ior, 400.0 * pow(abs(sin(t * 0.3 + q * 1.7)), 6.0))
                    bind iow = list_push(iow, 300.0 * pow(abs(sin(t * 0.27 + q * 2.3)), 6.0))
                    bind q = q + 1
                }
            }
            if liveG == 0 { bind tgtGP = sim_gpu(t) }
            if liveB == 0 { bind tgtBP = sim_board(t) }
            if liveN == 0 { bind tgtNP = sim_net(t) }
        }

        # glide toward the targets so the drawing and the synth never jump
        bind k = clamp(dt * 2.5, 0.0, 1.0)
        bind cats = glide(cats, tgtCats, k)
        bind rates = glide(rates, tgtRates, clamp(dt * 3.0, 0.0, 1.0))
        if len(tws) == len(ws) {
            bind ws = glide(ws, tws, k)
            bind pv = glide(pv, tpv, k)
        } else {
            bind ws = tws
            bind pv = tpv
        }
        bind gpv = glide_ll(gpv, tgtGP[GP_VEC], k)
        bind gpe = glide_ll(gpe, tgtGP[GP_ENG], k)
        bind bvS = glide(bvS, tgtBP[BP_BV], k)
        bind cuS = glide(cuS, tgtBP[BP_CU], k)
        bind cfS = glide(cfS, tgtBP[BP_CF], k)
        bind nvS = glide(nvS, tgtNP[NP_NV], k)

        # the packs the views read
        bind gpD = [1, tgtGP[GP_N], tgtGP[GP_NAME], tgtGP[GP_DRV], gpv, gpe, tgtGP[GP_PROC], gsel]
        bind bpD = [1, tgtBP[BP_INFO], bvS, cuS, cfS, tgtBP[BP_DIMM], tgtBP[BP_DISK], tgtBP[BP_DIO], tgtBP[BP_SENS]]
        bind npD = [1, tgtNP[NP_AD], nvS, tgtNP[NP_NODE], tgtNP[NP_PROC]]
        bind fl = rates[0]
        bind rd = rates[1]
        bind wr = rates[2]
        bind al = rates[3]
        bind usedM = clamp(1.0 - (cats[6] + cats[1]) / total, 0.0, 1.0)
        bind memD = [cats, total, rd, wr, fl, usedM, al, names, ws, ior, iow]

        # ---- what the current section feeds the look, the pulses and the sound
        bind dr = drive(sec, memD, gpD, bpD, npD, A, gsel)
        bind tg = dr[DR_TG]
        bind used = dr[DR_USED]
        bind kk = clamp(dt * 2.0, 0.0, 1.0)
        bind rdA = mix(rdA, tg[0], kk)
        bind wrA = mix(wrA, tg[1], kk)
        bind fltA = mix(fltA, tg[2], kk)
        bind alA = mix(alA, tg[3], kk)
        bind A = [rdA, wrA, fltA, alA]
        bind act = (rdA + wrA + fltA) / 3.0

        # ---- look: rotation, hue and saturation follow the machine
        bind rot = rot + dt * (0.06 + 0.9 * act)
        bind hueShift = 10.0 * sin(t * 0.05) + 26.0 * wrA - 12.0 * rdA
        bind sat = 52.0 + 40.0 * used
        bind enT = dr[DR_EN]
        bind ne = []
        bind i = 0
        while i < 7 {
            bind ne = list_push(ne, mix(energy[i], clamp(enT[i], 0.0, 1.0), clamp(dt * 3.0, 0.0, 1.0)))
            bind i = i + 1
        }
        bind energy = ne

        # ---- pulses: in = circles, out = squares, allocations are circles in the section's allocation channel
        bind ev = ev_cull(ev, t, 1.9)
        bind hist = ev_cull(hist, t, 14.5)
        bind f0 = 55.0 * pow(2.0, 0.55 * used)
        bind nsp = 0
        bind rate = [14.0 * rdA, 14.0 * wrA, 9.0 * alA]
        bind src = 0
        while src < 3 {
            bind want = rate[src] * dt
            bind cnt = floor(want)
            if rand() < want - cnt { bind cnt = cnt + 1 }
            bind m = 0
            while m < cnt {
                bind kind = 0
                bind wts = dr[DR_RW]
                bind pws = dr[DR_PWR]
                if src == 1 {
                    bind kind = 1
                    bind wts = dr[DR_WW]
                    bind pws = dr[DR_PWW]
                }
                bind cat = dr[DR_ALC]
                if src < 2 { bind cat = pick(wts, rand()) }
                bind proc = pick(pws, rand())
                bind seed = rand()
                bind mag = 0.3 + 0.7 * rand()
                bind ev = ev_add(ev, kind, cat, t, seed, mag, proc)
                bind hist = ev_add(hist, kind, cat, t, seed, mag, proc)
                if nsp < 3 + 2 * pluck {
                    if t - lastSfx > 0.07 - 0.03 * pluck {
                        if mute == 0 { chime(kind, cat, mag, f0, seed, pluck) }
                        bind lastSfx = t
                        bind nsp = nsp + 1
                    }
                }
                bind m = m + 1
            }
            bind src = src + 1
        }
        # the scrolling views want four numbers a note: kind, category, born, magnitude
        bind h4 = []
        bind i = 0
        while i < len(hist) {
            bind h4 = list_push(h4, hist[i])
            bind h4 = list_push(h4, hist[i + 1])
            bind h4 = list_push(h4, hist[i + 2])
            bind h4 = list_push(h4, hist[i + 4])
            bind i = i + 6
        }
        # the history strips take a sample every half second
        if t - lastHs > 0.5 {
            bind lastHs = t
            bind hsAll = hs_sample(hsAll, gpD, bpD, npD, usedM, fl)
        }

        # ---- alerts: anything irregular, in any section
        bind gm = 0.0
        bind g = 0
        while g < len(gpv) {
            bind gm = max(gm, gpv[g][GV_UTIL])
            bind g = g + 1
        }
        bind alM = [bvS[BV_UTIL] / 100.0, gm / 100.0, lg(nvS[NV_RX] + nvS[NV_TX], 9.0)]
        bind lives = [liveM, liveG, liveB, liveN]
        if alOn == 1 {
            if t > 12.0 {
                bind code = alert_check(alM, alBase, bvS, gpv, lives, usedM, nvS)
                if code >= 0 {
                    if t - alLast[code] > AL_COOL {
                        bind alLast = list_set(alLast, code, t)
                        bind alCode = code
                        bind alText = AL_TEXT[code]
                        bind alBorn = t
                        bind alLeft = 3
                        if code <= 4 { bind alLeft = 4 }
                        bind alNext = t
                    }
                }
            }
        }
        bind ar = clamp(dt * 0.15, 0.0, 1.0)
        bind alBase = [mix(alBase[0], alM[0], ar), mix(alBase[1], alM[1], ar), mix(alBase[2], alM[2], ar), alBase[3]]
        if nvS[NV_RTT] > 0.0 {
            if alBase[3] <= 0.0 {
                bind alBase = list_set(alBase, 3, nvS[NV_RTT])
            } else {
                bind alBase = list_set(alBase, 3, mix(alBase[3], nvS[NV_RTT], ar))
            }
        }
        if alLeft > 0 {
            if t >= alNext {
                if mute == 0 { alert_beep(alCode, alLeft) }
                bind alLeft = alLeft - 1
                bind alNext = t + 0.22
            }
        }

        # ---- state, synth, picture
        bind zl = liveM
        if sec == 2 { bind zl = liveG }
        if sec == 3 { bind zl = liveB }
        if sec == 4 { bind zl = liveN }
        if sec == 0 {
            bind zl = 3
            if liveM + liveG + liveB + liveN == 0 { bind zl = 0 }
            if liveM == 1 {
                if liveG == 1 {
                    if liveB == 1 {
                        if liveN == 1 { bind zl = 1 }
                    }
                }
            }
        }
        bind zCats = enT
        bind zTotal = 1.0
        bind zrd = pow(10.0, rdA * 3.6) - 1.0
        bind zwr = pow(10.0, wrA * 3.6) - 1.0
        bind zfl = pow(10.0, fltA * 5.0) - 1.0
        if sec == 1 {
            bind zCats = cats
            bind zTotal = total
            bind zrd = rd
            bind zwr = wr
            bind zfl = fl
        }
        bind Dp = [gpD, bpD, npD, hsAll, memD, [liveM, liveG, liveB, liveN], lastHs]
        bind Z = [t, rot, hueShift, sat, W, Hc, zCats, zTotal, act, zrd, zwr, zfl, ev, names, ws, pv, ior, iow, h4, used, energy, hil, zl, FH, Dp, dr[DR_STAT], mx, my, sec, view, enT, CH_ALL[sec], [alText, alBorn, AL_SEC[alCode]]]
        bind level = 1.0
        if sec == 0 { bind level = 0.5 }
        if mute == 1 { bind level = 0.0 }
        if pluck == 1 { bind level = 0.0 }
        synth(Z, f0, level)

        fill(0, 0, 0)
        if sec == 0 { view_main(Z) }
        if sec == 1 {
            if view == 0 { view_rings(Z) }
            if view == 1 { view_tiles(Z) }
            if view == 2 { view_orbits(Z) }
            if view == 3 { view_weave(Z) }
        }
        if sec == 2 {
            if view == 0 { view_gpu_engines(Z) }
            if view == 1 { view_gpu_vram(Z) }
            if view == 2 { view_gpu_dials(Z) }
            if view == 3 { view_gpu_fleet(Z) }
        }
        if sec == 3 {
            if view == 0 { view_board_layout(Z) }
            if view == 1 { view_board_cores(Z) }
            if view == 2 { view_board_signals(Z) }
        }
        if sec == 4 {
            if view == 0 { view_net_flow(Z) }
            if view == 1 { view_net_links(Z) }
            if view == 2 { view_net_traces(Z) }
        }
        menu_bar(Z, sec, view)
        alert_banner(Z)
        if showHud == 1 { hud(Z, sec, view, auto, mute, pluck, alOn) }
        present()
    }
}

← Back to index