Skip to content

Web

The engine builds as a wasm module (crates/walkit-web) with plain JS modules around it. The JS needs no build step and no npm.

Terminal window
rustup target add wasm32-unknown-unknown
tools/web-build.sh # the modules into web/dist/, with their sizes
tools/web-pack.sh <dir> # the walkit-web package for a page to vendor

The package holds the JS modules, their types in embed.d.ts, and the module as walkit.wasm.

examples/web is a complete page built on it.

embed.mjs is the entry point for a page that brings a player and places the windows itself. It loads the module, opens a skin archive and draws each window on a canvas.

import { loadWalkit } from "walkit-web";
const walkit = await loadWalkit({
invalidate() {}, // something changed; draw soon
windowOpen(kind) { return null; }, // "doublesize", "ontop": true, false or null
player(command, value) {}, // play, pause, stop, next, previous, eject, play_track,
// seek, volume, pan, shuffle, repeat, eq, preamp, band0..9
action(action, param, from) {}, // MENU, CLOSE, MINIMIZE, EQ_PRESETS, PLAYLIST, ...;
// from.rect is where the button sits, for a menu
}); // walkit.wasm next to embed.mjs, or { wasm: url }
const skin = await walkit.openSkin(skinBytes, { base, wasabi }); // or a URL; see below
skin.rt.setFree(true, innerWidth, innerHeight); // windows apart, docked as on Winamp's desktop
function frame(now) {
skin.rt.setPlayerState({ status: "playing", positionMs, lengthMs, title, volume });
skin.rt.setPlaylist(tracks); // [{ title, lengthMs }], when it changes
skin.rt.setVis({ spectrum, waveform, vu }); // 75 levels, 576 samples, [left, right]
if (skin.tick(now)) {
for (const w of skin.windows()) skin.paint(canvasFor(w), w, devicePixelRatio);
}
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);

openSkin tells a classic skin from a modern one by its own files and lays the matching base under it. base is a classic base skin, such as Winamp’s base skin, used only under a classic skin (.wsz): it gives every bitmap the skin leaves out. wasabi is Winamp’s wasabi base, used only under a modern skin (.wal). Each is an archive’s bytes, its URL, or a Map of path to bytes, and either may be left out.

Each window is {id, container, layout, rect}, listed bottom to top. With one canvas per window at rect, the page between the windows stays clickable.

The pointer goes to skin.rt.pointerDown, pointerMove, pointerUp and doubleTap, in viewport pixels. player and action run after the engine call that raised them returns, so they may call back into the engine.

Besides drawing, the runtime:

  • places, opens and closes windows: placeWindow, openWindow, closeWindow, setWindowLayout;
  • scales a window: setWindowScale(container, 2) for Winamp’s double size, any factor from 0.25 to 8, and docked windows stay docked;
  • names a classic frame: setWindowTitle;
  • says where the page draws its visualizer: visRect, a classic skin’s avs window framed by gen.bmp, or a modern skin’s AVS holder;
  • says which window has the focus and gives it to another: focusedWindow, focusWindow;
  • shows the page’s playlist selection, scrolls a playlist and brings a classic playlist’s row into view: setPlaylistSelection, scrollPlaylist, playlistScroll, showPlaylistRow;
  • scrolls the list under the mouse wheel, wherever the skin shows one: scrollAt;
  • says which cursor belongs at a point of a modern skin, over a divider between panes or a window’s resize grip: pointerShapeAt;
  • keeps a classic skin’s time direction and equalizer auto in step with the host’s settings: timeRemaining, eqAuto and their setters;
  • widens the reach within which an equalizer or balance slider snaps to its middle: setSnapReach.

embed.d.ts types the whole surface.

walkit.mjs wraps the module’s exports directly, for a host that decodes pictures and measures text itself:

import { Walkit } from "./walkit.mjs";
const w = await Walkit.load(wasmBytes, {
decode: (file, bytes) => null, // {w, h, argb: Uint32Array} of a skin picture
textWidth: (text, font, size, bold) => 0,
lineMetrics: (font, size, bold) => null, // [ascent, descent]
imageSize: (file) => null, // [w, h]
pixels: (file, x, y, w, h) => null, // Uint32Array, ARGB
log: (line) => console.log(line),
});
const skin = w.filesFrom(entriesOfTheWal); // path -> Uint8Array
const stack = w.stack(skin, w.filesFrom(wasabi)); // over the wasabi base, or a classic base skin
const rt = w.runtime(stack, "Winamp Modern");
rt.load();
rt.setNow(performance.now());
if (rt.tick()) draw(rt.draw()); // the draw list, one command per line

web/player.html shows a skin served from a local folder, or a .wal dropped on the page, with the engine’s fake player. The repository’s web/README.md shows how to serve it.