Commit Graph

3 Commits

Author SHA1 Message Date
tyler cef7619833 feat(web): proper viewport scaling, instant load, and file downloads
Make the Emscripten build behave like the desktop app for loading, window
scaling, and exporting. All changes are #ifdef __EMSCRIPTEN__-gated or no-op on
desktop, so native behavior is unchanged.

Scaling:
- Drop FLAG_WINDOW_HIGHDPI on web. The emscripten-GLFW shim forces a fixed
  pixel canvas style (!important) when HiDPI-aware, overriding the shell's
  100vw/100vh CSS so the canvas can't fill the page; raylib's own resize/window
  callbacks also disagree about dividing by devicePixelRatio, desyncing the
  framebuffer from the reported screen size.
- Sync raylib's window size to window.innerWidth/innerHeight each frame via
  SetWindowSize (guarded against no-op churn). This keeps screen size, GL
  viewport, and projection consistent, so the UI fills the viewport and reflows
  on resize like the desktop window.

Loading:
- Compute the full-resolution STFT synchronously when a file loads instead of
  the desktop overview-then-deferred-high-res path, which relied on many
  main-loop iterations yielding to the browser and appeared to stall partway.
- Allow the wasm heap to grow (INITIAL_MEMORY + ALLOW_MEMORY_GROWTH) so longer
  recordings fit now that everything is computed up front.

Exports:
- Add Platform_OfferFileToUser(): no-op on desktop (file is already on disk);
  on web it reads the just-written file from MEMFS and triggers a browser
  download, then unlinks the temp copy. Wired into PNG and WAV export, which
  now show just the filename in the status message.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 11:48:47 -07:00
tyler 6347eb172e fix(web): repair Emscripten build after module split + font move
The web build had bit-rotted since the last successful build (Apr 12):

- build_web.sh only compiled spectrogram.c + platform_web.c, but commit
  3a8f20b split the code into 9 modules — link failed with undefined
  symbols. Now compiles all app modules (kept in sync with rspektrum.make,
  swapping platform_linux -> platform_web).
- Dropped -DPLATFORM_WEB from the app-module compile/link: the platform
  refactor (b6942d8) added a `Platform` enum whose PLATFORM_WEB enumerator
  collides with the macro. Web behavior is selected by linking
  platform_web.c, not the macro, so the define was never needed by our code
  (raylib still gets it in its own build).
- Removed the stale `fonts/DejaVuSansMono.ttf` preload (font moved to
  resources/fonts/); resources@resources already bundles it and the runtime
  loads it relative to the resources dir.
- platform_web.c: include <errno.h> for ENOSYS (this stub had never compiled).
- build_web.sh: skip the slow raylib rebuild when libraylib.a already exists.

Verified: `./build_web.sh release` exits 0 and produces html/js/wasm/data;
font is packaged; all artifacts serve 200 via python http.server and the
wasm has valid magic bytes.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 11:15:31 -07:00
tyler b6942d8577 Refactor: extract platform abstraction for subprocess spawning
Move all Unix-specific syscalls (fork, execvp, waitpid, strerror, /tmp)
into a platform layer so the same spectrogram.c can target Windows
(CreateProcess) and WebAssembly (stubs). Key changes:

- src/platform.h: public API with spawn handle, error codes, path helpers
- src/platform_linux.c: fork/execvp implementation, /tmp, strerror
- src/platform_win32.c: CreateProcess implementation, temp dir lookup
- src/platform_web.c: stub implementations (no subprocess support on web)
- src/spectrogram.c: consume only platform.h; replace pid_t/fork/execvp
  with Platform_SpawnChild/WaitForChild; use Platform_GetTempDir() for
  /tmp path; replace strdup with malloc/memcpy for portability
- Build: add platform_*.c to gmake, Premake, and build_web.sh
2026-05-14 18:16:21 -07:00