- Python 44.7%
- JavaScript 34.4%
- CSS 12.9%
- HTML 5.5%
- Shell 1.6%
- Other 0.9%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .claude/skills/verify | ||
| deploy | ||
| doc | ||
| render | ||
| samples | ||
| web | ||
| web_old | ||
| .dockerignore | ||
| .gitignore | ||
| CLAUDE.md | ||
| README.md | ||
| start.sh | ||
| update-project.sh | ||
Scores
A page to view MuseScore files: a list of scores, and a score view that plays the audio and highlights the current measure. See doc/PLAN.md.
Run locally
./start.sh
This renders everything in inbox/ into data/, keeps watching the inbox (every 5 s), and serves the site at http://localhost:8000/. On the first run an empty inbox is filled with the files from samples/. Add scores on the upload page (http://localhost:8000/upload/) or by dropping .mscz, .musicxml or .mxl files into inbox/.
Locally there is no Authelia: the upload API (render/api.py --dev) also serves the site and treats you as logged in as $USER, so delete buttons show on the overview. Run DEV_USER= ./start.sh to see the site as a logged-in user outside the scores-upload group (no delete or edit buttons).
MuseScore is found via MUSESCORE_BIN, then mscore/mscore4portable/musescore in PATH, then the Flatpak org.musescore.MuseScore. Otherwise the most recently modified MuseScore*.AppImage in ~/Applications, ~/app or ~/Downloads (or MUSESCORE_APPIMAGE) is extracted to .cache/musescore/, so FUSE isn't needed.
Settings: INBOX, FONTS, PORT, INTERVAL, DEV_USER (see the top of start.sh).
Fonts
MuseScore draws all text into the SVGs and PDFs, so a score that uses a font the renderer doesn't have (often a decorative title font) is rendered with a substitute. MuseScore's own fonts (Edwin, FreeSerif, Leland, MuseJazz, …) always work.
The upload page lists the missing fonts and the scores that use them. Upload the .ttf/.otf files there, like a score. They go to fonts/ (in SCORES_DIR on the server), which the renderer uses besides the system fonts, and the affected scores are rendered again. Fonts are never served to visitors, but check the font's license before uploading it. Locally, fonts installed on your system count as well.
Deploy (Docker)
deploy/compose.yaml runs three containers: render (the watcher), api (uploads/deletes, internal only) and web (nginx serving web/ and data/, proxying /api/). inbox/, data/ and fonts/ are directories in SCORES_DIR on the Docker host, usually on a share the host mounts. They are bind-mounted with create_host_path: false, so a container doesn't start when one of them is missing (e.g. the share isn't mounted) instead of running on an empty directory. web gets data/ only, read-only.
- On the Docker host, create the score directory with its three subdirectories, owned by a uid/gid such as 1000:1000:
mkdir -p /mnt/web-data/scores/{inbox,data,fonts} && chown -R 1000:1000 /mnt/web-data/scores(on an NFS share with root squash, run this as that user). git clone … && cd scores && cp deploy/.env.example deploy/.env, then setSCORES_DIR,SCORES_UID/SCORES_GID(owner of the directory),NPM_IP,AUTHELIA_URL(for the logout link) andSCORES_PORT.docker compose -f deploy/compose.yaml up -d --build- In Nginx Proxy Manager, add a proxy host for the score domain pointing at
<docker-host>:<SCORES_PORT>, with a Let's Encrypt certificate and "Force SSL". Leave "Cache Assets" off: NPM then caches.js/.css/images itself, ignoring the site'sCache-Control(old scripts after an update), and serves them from alocationof its own that skips Authelia. Then configure Authelia as described below.
Updating: ./update-project.sh (git pull, rebuild and restart, then docker image prune -f for the old images). To update MuseScore, change MUSESCORE_URL in deploy/Dockerfile; it must be at least the desktop version.
Authelia
The whole site needs a login: there is no public access. Two Authelia groups decide what a user may do:
scores: view the scores.scores-upload: also upload, delete and edit details (/upload/and/api/).
The examples use scores.example.com for the site and auth.example.com for Authelia (4.38 or newer).
Authelia configuration.yml: the rules are checked in order, and the first match wins.
access_control:
default_policy: deny
rules:
- domain: scores.example.com
resources: ['^/(upload|api)/']
subject: 'group:scores-upload'
policy: one_factor # or two_factor
- domain: scores.example.com # everyone else on these paths
resources: ['^/(upload|api)/']
policy: deny
- domain: scores.example.com # viewing
subject: ['group:scores', 'group:scores-upload']
policy: one_factor
session:
cookies:
- domain: example.com # must cover the score domain
authelia_url: https://auth.example.com
authelia_url must be on the cookie's domain. If the score site is on a different domain than your other Authelia apps, add a second cookie entry with its own Authelia URL on that domain (and a proxy host for it in NPM). Authelia refuses to start otherwise.
Logged-out users are sent to the login page on every path. Users in scores see the site without delete and edit buttons, and get 403 on /upload/. Users in neither group get 403 everywhere.
Users (file backend, users_database.yml): add a group to an existing user, or add a new user. The password hash comes from authelia crypto hash generate argon2.
users:
alice: # existing user: full access
displayname: Alice
password: '$argon2id$...'
email: alice@example.com
groups: [admins, scores-upload]
brass-guest: # new user: view only
displayname: Brass guest
password: '$argon2id$...' # authelia crypto hash generate argon2 --password '...'
email: brass-guest@example.com
groups: [scores]
Authelia reads the file at startup, or on every change with authentication_backend.file.watch: true. A guest only gets into your other apps if their rules let any logged-in user in, so check those rules use a subject too.
NPM proxy host → Advanced → Custom Nginx Configuration: replace authelia:9091 with the address NPM uses to reach Authelia. Because this defines location /, NPM leaves out its own, so every request goes through Authelia.
location = /internal/authelia/authz {
internal;
proxy_pass http://authelia:9091/api/authz/auth-request;
proxy_set_header X-Original-Method $request_method;
proxy_set_header X-Original-URL $scheme://$http_host$request_uri;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Content-Length "";
proxy_set_header Connection "";
proxy_pass_request_body off;
proxy_http_version 1.1;
}
location / {
auth_request /internal/authelia/authz;
auth_request_set $user $upstream_http_remote_user;
auth_request_set $redirection_url $upstream_http_location;
error_page 401 =302 $redirection_url;
client_max_body_size 20m;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Remote-User $user; # replaces any Remote-User sent by the client
proxy_pass $forward_scheme://$server:$port;
}
# Public share links: no login. The inner nginx serves such requests only
# below /share/ (pages and audio of shared scores), nothing else.
location /share/ {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Remote-User "";
proxy_set_header Scores-Public 1;
proxy_pass $forward_scheme://$server:$port;
}
Don't add further location blocks here: one without auth_request would serve its paths without a login. /share/ is the one exception: the Scores-Public header makes the inner nginx answer 404 to anything outside /share/, also for paths with .. in them. The API trusts Remote-User, which is only safe because web accepts connections from NPM_IP alone and NPM sets the header from Authelia's answer. Don't publish SCORES_PORT beyond your LAN.
Share links
On a score page, users in scores-upload can create a public link (https://scores.example.com/share/<token>). Anyone with it can view the pages and play the audio without logging in. The PDFs, MusicXML and original file are not reachable through it, and the page offers no downloads. (The SVG pages and the MP3 are streamed to the browser, so someone determined can still save them.) "Remove link" kills the link; sharing again gives a new one. Without the location /share/ block in NPM, share links ask for a login like everything else.
To check, in a private window: https://scores.example.com/, /data/scores.json and /api/me all redirect to the login page, while a share link opens (and /share/../data/scores.json does not). Logged in with scores-upload, /api/me returns {"user": "alice"}; with only scores, it returns 403.
Storage
SCORES_DIR must support hard links and flock. Local disks and NFS do, SMB/CIFS often doesn't: uploads use os.link and the watcher locks data/.render.lock.
Development
python3 -m unittest discover -s render # unit and API tests
pylint --recursive=y render # lint
python3 render/render.py --out data --debug-overlay <slug> # draw measure boxes into data/<slug>/page-N.debug.svg
python3 render/render.py --inbox inbox --out data --force <slug> # re-render one score