# Chordino for WebAssembly: corresponding source

The chord finder analyses an audio file on your own device, with **Chordino** compiled to WebAssembly. This directory holds the source of
the two files your browser downloads for that, the scripts that build them, and the licence. Read `NOTICE.txt` first (who wrote what, under
which licence). The licence of the two files is the **GNU General Public License, version 2 or (at your option) any later version**; the
text is in `COPYING`.

## What is here

| File | What it is |
|---|---|
| `NOTICE.txt` | Copyright and licence of every part, with exact versions |
| `COPYING` | The GNU General Public License, version 2 |
| `chordino-wasm-build.tar.gz` | The two C++ files of this site (`src/`), the build scripts (`scripts/`), this README, a copy of `MANIFEST.json` |
| `nnls-chroma-4c5f214.tar.gz` | Chordino itself (the `nnls-chroma` repository) at commit `4c5f214a75cb354f8d8c933e161377c5b4d83713` |
| `vamp-plugin-sdk-44c2487.tar.gz` | Vamp Plugin SDK 2.10 at commit `44c2487763eb248a933e9eff9169cfadee375009` (the plugin side) |
| `vamp-1.1.0.tar.gz` | The PyPI source package `vamp` 1.1.0, unchanged; it carries the Vamp SDK 2.6 host adapters the build uses (the host side) |
| `SHA256SUMS` | sha256 of every file above (check with `shasum -a 256 -c SHA256SUMS`) |

The files being served (and the checksums to compare your build with):

| Served at | sha256 |
|---|---|
| `/chordino/28d6dc4c/chordino.wasm` | `28d6dc4cdd86c6775a1abfd86f9994fc57c3bf88d22830883b1c22121504eb9d` |
| `/chordino/28d6dc4c/chordino.mjs` | `54e2f9af4d5f088a91ee2a63b5306d12a1b47db9960108336e0ed99f3f74231f` |

`/chordino/MANIFEST.json` lists the same two hashes, the pinned sources, the compiler and the build flags.

## Rebuild the two files

You need Docker and a network connection (the compiler downloads the Boost headers, see `NOTICE.txt`). About three minutes.

```sh
mkdir work && cd work
# put chordino-wasm-build.tar.gz, nnls-chroma-4c5f214.tar.gz, vamp-plugin-sdk-44c2487.tar.gz, vamp-1.1.0.tar.gz here
tar xzf chordino-wasm-build.tar.gz && cd chordino-wasm
sh scripts/unpack-sources.sh ..          # unpacks the three source archives into _src/ (no network)
CHORDINO_WASM_EXTRA_LINK="-sENVIRONMENT=web,worker --closure=1" ./scripts/build.sh prod-webc-fast
shasum -a 256 _build/prod-webc-fast/chordino.wasm _build/prod-webc-fast/chordino.mjs     # compare with the table above
```

`scripts/build.sh` runs `emscripten/emsdk:7.0.0`, pinned by digest, and `scripts/in-container-build.sh` (inside it) holds every compiler
flag. Two builds from the same sources gave the same hashes.

Or fetch the exact sources from their public repositories instead of unpacking the archives: `sh scripts/fetch-sources.sh` (needs `git`,
`python3` and `pip`).

`scripts/smoke.mjs` is the check run on every build: Chordino looks for its chord dictionary through the file system, and a build made with
`-sFILESYSTEM=0` still compiles and runs but silently answers "no chord". It runs in Node, so it needs the variant built without
`CHORDINO_WASM_EXTRA_LINK` (`./scripts/build.sh prod-fast`, same code and flags, `node` added to the environments), and a 22.05 kHz mono WAV of
a song that is not shipped here. The served `chordino.wasm` is the same file for both variants.

## Changes to Chordino

None. Chordino's files are unmodified; this site only adds `src/plugin_factory.cpp` (exposes Chordino's plugin descriptor with its
default parameters) and `src/chordino_wasm.cpp` (a small host that feeds audio in chunks and reads the chord events back), and compiles
everything with Emscripten.

## Not in this directory

* The Boost 1.83.0 headers (26 MB): `https://github.com/emscripten-ports/boost/releases/download/boost-1.83.0/boost-headers-1.83.0.zip`,
  sha512 `82e3a64e55caac0254f9e6b179437ad9421943b8f73957285978dad16c24dcae6372c464909fdc085b9790662b6a3af5163140b1e456705e80fda51c5fe3c243`.
* The Emscripten 7.0.0 toolchain, its libc, libc++ and runtime: the Docker image named in `MANIFEST.json`.

Both are public and pinned. No lawyer has confirmed that naming them (instead of copying them here) is enough for those two parts.
