Skip to content

Add STK to the WASM package with embedded samples - #50

Merged
vlazzarini merged 1 commit into
csound:developfrom
hlolli:feat/stk-wasm
Oct 14, 2026
Merged

vlazzarini merged 1 commit into
csound:developfrom
hlolli:feat/stk-wasm

Conversation

@hlolli

@hlolli hlolli commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Adds plugins.stk to @csound/plugins. Its single stkops.wasm file includes all 41 bundled raw-wave samples, so STK instruments work without extra downloads or wave-path setup.

CMake generates byte arrays from the samples. At module initialization, the adapter writes them to Csound's virtual filesystem and sets STK's wave path. An explicit RAWWAVE_PATH takes precedence. The STK_EMBED_RAWWAVES option defaults to on for WASM and off for native builds.

STK keeps its C++ exception handling. Nix builds a separate static libc++/libc++abi runtime and the LLVM WASM unwinder, and removes the compiler wrapper's forced -fno-exceptions flag so CMake can choose the mode per target. A small CMake target builds the unwinder's WASM source because LLVM 21's main target also selects unsupported assembly. This adds no source patches and works with the currently pinned Csound SDK and browser releases.

Validation: the Nix WASM build and npm pack pass. All 11 runtime tests pass, covering four sampled STK instruments, STK loaded alone, a custom sample directory, a caught missing-sample error, and the existing plugins loaded together. The npm archive includes the STK and LLVM unwinder license notices.

Summary by CodeRabbit

  • New Features
    • Added the STK plugin to the WebAssembly package.
    • STK instruments can use bundled raw-wave samples without requiring separate sample files. A custom RAWWAVE_PATH continues to take precedence.
  • Bug Fixes
    • Improved handling of missing STK samples so errors are reported instead of escaping as WebAssembly exceptions.

@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: csound/plugins/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 017b940c-67a9-41fe-a676-6cf9a1ace206
📥 Commits

Reviewing files that changed from the base of the PR and between 50c0e81 and 3833218.

📒 Files selected for processing: 12
  • 7.x/cmake/WasmPlugins.cmake
  • 7.x/src/stk/CMakeLists.txt
  • 7.x/src/stk/EmbedRawwaves.cmake
  • 7.x/src/stk/stkOpcodes.cpp
  • THIRD_PARTY.md
  • index.d.ts
  • index.js
  • wasm/README.md
  • wasm/default.nix
  • wasm/libunwind/CMakeLists.txt
  • wasm/scripts/build.sh
  • wasm/tests/runtime.test.js

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

The WASM build now enables STK with exception support and bundled raw-wave samples. The package exports and stages the STK plugin, and runtime tests cover rendering, sample-path overrides, and missing samples.

Changes: STK WASM build

Layer / File(s) Summary
Exception-enabled build setup
7.x/cmake/WasmPlugins.cmake, wasm/default.nix, wasm/libunwind/CMakeLists.txt, 7.x/src/stk/CMakeLists.txt
The WASM build configures STK with C++ exceptions, builds and links a static libunwind, and enables STK opcodes.
Embedded raw-wave samples
7.x/src/stk/CMakeLists.txt, 7.x/src/stk/EmbedRawwaves.cmake, 7.x/src/stk/stkOpcodes.cpp
The build can generate embedded data from bundled .raw files. When embedding is enabled and RAWWAVE_PATH is empty, initialization stages the files in .csound-stk-rawwaves; a supplied path bypasses staging.
Packaging and runtime validation
index.js, index.d.ts, wasm/scripts/build.sh, wasm/default.nix, wasm/tests/runtime.test.js, wasm/README.md, THIRD_PARTY.md
The package exports and stages stkops.wasm. Tests cover STK rendering, standalone loading, custom sample paths, and missing samples. Documentation and notices include STK and libunwind.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Csound as Csound module initialization
  participant Path as RAWWAVE_PATH
  participant Samples as Embedded raw-wave table
  participant VFS as Csound virtual filesystem
  Csound->>Path: Check configured path
  alt Path is empty
    Csound->>Samples: Read embedded sample data
    Samples->>VFS: Write samples to .csound-stk-rawwaves
    Csound->>Path: Use .csound-stk-rawwaves
  else Path is nonempty
    Csound->>Path: Use supplied path
  end
Loading
Merge Risk: ⚪ Minimal · up to 38332

No actionable merge-blocking issue is established; the change is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 5 files. (7 skipped: 7… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely summarizes the primary change: adding STK to the WASM package with embedded samples.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 5 files. (7 skipped: 7 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@vlazzarini
vlazzarini merged commit 563dde0 into csound:develop Oct 14, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants