← 输入框|github.com|刷新
Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Music Notes

Music notation written in readable HTML, rendered as SVG in the browser. Custom elements are the source data; a separate score model preserves musical structure and exact timing. VexFlow 5.0.0 supplies engraving primitives and locally bundled music fonts. No font CDN is required.

This is a source project, not a published npm package. The notation workbook demonstrates the renderer; a separate Author workspace supports composition, reading, and page preparation using the same musical DOM and engraving system. Listen plays the current accepted score in the browser and downloads the same synthesized audio as a WAV file.

The third-party notices preserve the renderer and bundled font licenses. Production builds include a copy as THIRD_PARTY_NOTICES.txt.

Run

Use Node 22.12 or newer on a supported even-numbered Node release.

npm install
npm run dev

Open /index.html for the notation workbook or /author.html for Author. They are separate entry points: the workbook does not load the authoring application.

The workbook contains eleven original studies: pitch spelling, 7/8, 15/8, 5/4, mixed and nested tuplets, improvisation notation, piano voices, ensemble layout, quarter-tones with a single-line rhythm part, 3 roads music, and articulations with relative interval harmonies. The ensemble shows the same music twice: first with automatic wrapping, then with optional author-chosen line and page breaks, for twelve score views in total.

Author opens recovered local work or a blank staff. Write offers explicit pitch and rhythm entry, voices, tuplets, harmony, performance instructions, and undo/redo. Read hides entry controls and holds the reading width until you refit it. Listen adds play/pause, stop, starting tempo, note highlighting and WAV download. Pages composes the selected score or part into paper-sized pages with independent layout settings and human page-turn review. Parts retain authored pitches; no transposition is implied. See the Author workspace guide for the controls, recovery, source editing, and printing workflow.

In Write, the fixed Write notes / Select controls share a compact palette. Write notes resumes the saved writing destination without replacing the selected music or an unapplied Properties draft. Click the staff to place a single pitched note or an ordinary rest; prepare the drag handle in note options when you want to drag instead. Ordinary rests work on pitched, rhythm and three-roads staves without inventing a pitch. Full-measure rests, chords, rhythm notes, road notes and slashes retain explicit Insert / Enter routes. The preview and musical boundary are validated before one undoable edit.

To change an existing note, choose Select, click it, then use Pitch or Value. Pitch covers letter, octave and all nine supported alterations; desktop Flat / Natural / Sharp shortcuts remain available. Notes and rests both delete with Delete or Backspace. Shared values apply to the exact selected set, while attached marks and relationships have separate routes. Native popovers and customizable native selects keep these edits independent of the next-entry recipe.

More uses spare space beside the chosen writing frame or opens a deliberate task sheet. It does not shrink the paper or change its wrapping. Return restores the visible musical position, independently of selection. With the score focused, N / R chooses a note or ordinary rest, Enter writes the recipe, and Left / Right moves the writing destination through existing events and bars. The blank, rhythm and three-roads starter templates begin with an unwritten draft bar; Add measure remains an explicit creation of written silence.

Routine notation notices stay in Review, so completing a bar does not move the staff. Pointer feedback starts with the proposed pitch or rest value, and Keyboard shortcuts keeps longer help out of the writing surface until needed. Eligible Add + insert names its new bar before creating it.

The selected-event editor also offers Attached marks. Add or remove articulations, ornaments, and three-roads interval harmonies, then apply the draft as one undoable change. These children stay with their event through duplication, source edits, and compatible event conversions.

Author attempts local recovery saves after a short pause in editing. Saves use Web Locks to coordinate cooperating tabs; browsers without that coordination do not silently fall back to unsafe autosaving. Storage failures and conflicts remain visible. Download project keeps a portable copy, including layout settings and unapplied source drafts. Browser storage is not a backup.

Install on iPad, iPhone, or desktop

In Safari on iPad or iPhone, open Author, choose Share → Add to Home Screen, leave Open as Web App enabled if shown, then tap Add. Launch the new Music Notes icon to use Author without browser tabs or an address bar. iPadOS retains control over the status bar, Home indicator, and multitasking; standalone mode does not force exclusive use of the screen. See Apple’s installation instructions. Desktop browsers that support installation offer their own Install app command. These instructions are also available in Author’s Document → Install Music Notes.

Both entry pages share manifest.json, a stable installation identity, and an Author launch URL. The workbook stays within the app’s scope. All manifest URLs are relative to its location, so root and /music-notes/ builds work without escaping their deployment prefix. Orientation is unrestricted for portrait, landscape, and windowed use. The edge-to-edge viewport uses all four env(safe-area-inset-*, 0px) values to protect controls, dialogs, and popovers from notches and the Home indicator. Zoom remains enabled.

Open the installed app online once and check Document → Install Music Notes for “Ready for offline use.” Production Author installs a service worker that atomically saves and integrity-checks that release’s HTML, scripts (including Listen), styles, fonts, manifest and icons. You can then reopen, compose, listen and export offline. The workbook becomes available offline after Author completes setup; opening the workbook alone does not download Author. HTTPS (or localhost for testing) is required. Development mode does not register a worker.

Updates download in the background and activate after all Music Notes windows close. There is no forced reload or replacement of an open editor. The worker serves a consistent cached release, cleans only its own deployment’s old caches, and never caches compositions or unrelated requests. Online startup verifies the offline files and repairs missing assets only when their bytes match that release. Browser and installed-app storage can be separate, so Download project before switching and Open project inside the installed app to bring your composition with you. System storage eviction can remove offline files and recovery data; keep project backups.

The original vector artwork is app.svg. Committed PNGs cover Apple’s 152px/167px/180px Home Screen icons, 192px/512px app icons, and a maskable icon with its essential artwork in the central safe zone; SVG, PNG and ICO favicons cover tabs and older browsers. Regenerate them with the pinned Playwright Chromium:

npx playwright install chromium
node scripts/generate-app-icons.mjs

With Vite on port 5175, run node scripts/check-install-browser.mjs for reproducible Chromium/WebKit phone and tablet checks. INSTALL_TEST_URL selects another server; INSTALL_TEST_OUTPUT saves screenshots. These checks inject safe-area values to verify every view’s dock and native popover bounds. They do not emulate actual OS insets or an onscreen keyboard.

A physical iPhone/iPad check is still needed for Home Screen installation, launch, rotation, multitasking, keyboard use, and project import; desktop WebKit cannot reproduce iPadOS’s installation UI.

GitHub Pages

The source lives on main; the generated site is published from the root of gh-pages in Westbrook/music-notes. The workbook and Author remain separate entries.

npm ci
npm run build:pages
npm run check:bundle
npx playwright install chromium
npm run test:pages:browser

The pages build mode sets Vite's base to /music-notes/, including asset URLs and Author's workbook links. Ordinary npm run dev and npm run build keep the root base. The production browser check serves dist at the project prefix, uses isolated browser storage, and checks navigation, engraving, WAV export, installation metadata, decoded icons, and offline startup. Use TEST_BROWSER=webkit for the same checks in WebKit. For a root build, run npm run build then TEST_BASE_PATH=/ npm run test:pages:browser.

After running the relevant repository checks and committing the source to main:

git push origin main
npm run deploy:pages

deploy:pages rebuilds the site, checks bundle budgets, and uses the pinned gh-pages tool to commit and push dist to origin/gh-pages. It preserves deployment history and includes .nojekyll. Only built assets are published; tests, local compositions and the independent progress report are not site routes. GitHub Settings → Pages must use Deploy from a branch, gh-pages, / (root). Publishing requires Git access to git@github.com:Westbrook/music-notes.git.

Write a measure

<script type="module" src="/src/components/index.ts"></script>

<music-staff clef="treble">
  <music-measure>
    <music-meter top="7" bottom="8" groups="2+2+3"></music-meter>
    <music-tempo marking="Even eighths" bpm="144" beat="eighth"></music-tempo>
    <music-note pitch="D4" duration="quarter"></music-note>
    <music-note pitch="F4" duration="quarter"></music-note>
    <music-note pitch="A4" duration="quarter" dots="1"></music-note>
  </music-measure>
  <music-measure end-bar="final">
    <music-rest measure></music-rest>
  </music-measure>
</music-staff>

Always close custom elements explicitly: <music-note ...></music-note>, not <music-note ... />. The second measure inherits the meter. Its measure rest fills 7/8; a duration="whole" rest instead lasts one whole note.

Use the elements in your own app

The music-* elements are prepared as a package within this repo: the root package.json declares the entry point, types, and sideEffects, and npm run build:lib emits the built package to dist-lib/. They are browser-only and have no Vite dependency — the stylesheet is embedded in the shadow root, and the engraving adapter is lazy-loaded on first render.

import 'music-notes'; // registers every element as a side effect

Importing the package re-exports the element classes, readScore / serializeScore / describeScore, the score model types, and the engraving types. Wait for renderComplete before reading geometry or exporting the score, and check diagnostics for errors rather than assuming success. See the consuming guide for the full API, and npm run check:library to build and smoke-test the built output.

Supported foundation

  • Treble, bass, alto, and tenor clefs; major/minor key signatures; explicit pitch spelling, accidental cancellation, dots, rests, ties, and chords.
  • Quarter-tone and three-quarter-tone accidentals in 24-EDO, with readable qf, qs, tqf, and tqs pitch suffixes and Stein–Zimmermann glyphs.
  • Simple, compound, and additive meters with declared beat groups. Durations from breve through 128th; exact tuplet ratios with mixed values, rests, and nesting.
  • A pitch-free, single-line staff using music-staff notation="rhythm" and music-rhythm, including ordinary noteheads, beams, tuplets, rests, and ties across bars or systems.
  • 3 roads music using music-staff notation="three-roads" and music-road direction="higher|same|lower": prescribed slash-head rhythm on the original staff's top, middle, and bottom lines, with performer-chosen relative pitches and no clef or key.
  • Note-attached accents, staccato, tenuto, marcato, staccatissimo, and fermatas; trills, turns, inverted turns, and upper/lower mordents on single pitches and road events.
  • Three-roads interval harmonies 1–13, optionally flat or sharp, above or below the chosen main pitch: 5 above F adds C; b3 below B♭ adds G. Each figure belongs to its notehead, and harmony tones do not change the next road's reference.
  • Independent voices, aligned staves, braces/brackets, tempo and dynamics, rehearsal marks, harmony text, directions, and beat or rhythmic slashes.
  • Automatic responsive systems, optional line/page breaks, measure numbering, configurable print width, a textual score representation, diagnostics, and source IDs used by Author's selection and editing commands.

Invalid or unsupported notation is diagnosed rather than presented as a successful engraving. See the authoring guide for grammar, defaults, and the browser API, and the design review for the acceptance criteria and limits.

Automatic wrapping is the default: no break attributes or measure-count limit are needed. All parts wrap together as the available width changes. A short opening pickup stays with the following bar when they fit, without adding a layout instruction to the source.

Set max-measures only to impose an upper limit; it does not promise that many measures will fit. A measure's break-before="line" or break-before="page" forces that boundary even when more music could fit. keep-with-next adds an author's preference for neighboring measures. Explicit breaks, a measure limit, or insufficient space take precedence over both that preference and automatic pickup grouping.

The demo's print controls have separate jobs:

  • Use print layout on screen (680px) switches the scores to their fixed print width. It changes score wrapping, not zoom or paper size. Short examples may look unchanged because they already fit; narrow windows can scroll the fixed layout. Uncheck it to restore responsive wrapping.
  • Open print dialog… requests browser printing of the whole workbook: all twelve score views, including both ensemble layouts, with headings and explanations. It waits for rendering and blocks the request if a score reports an error. It uses the fixed print layouts whether the checkbox is checked or not. The toolbar, source snippets, and score transcripts are omitted from print.

For your own page, print-preview selects the fixed layout on screen and print-width sets its width in CSS pixels (default 680). This is not a preview of physical paper pages. A print request cannot confirm that a dialog appeared or that pages were produced correctly. If no dialog opens, open the workbook in a browser with printing support and use its Print command once the notation has finished loading and errors are resolved.

Author's Pages view is separate from this workbook control. It lays out complete SVG systems on Letter or A4 pages and uses those page elements for Print / Save as PDF. Choose matching paper and orientation in the browser dialog, 100% scale, no additional browser margins, and no browser headers or footers. Unapplied Source changes, musical errors, and physical fit errors block printing; incomplete music requires correction, an applicable intentional-short-measure review, or explicitly marked draft output. Review the final PDF or paper before use; a print request does not verify it.

Architecture

Authored DOM
       ↓
DOM reader → typed score + source map + diagnostics
       ↓
Exact musical validation → system planning → VexFlow SVG

src/model owns pitch, meter, rational durations, and validation without depending on a browser or renderer. src/dom reads and serializes the authoring grammar. src/engraving handles notation and system layout. src/components observes source changes and manages rendering, accessibility, and browser lifecycle, with Lit templates for score presentation and stable mounts for engraved SVG.

src/authoring adds commands, session history, portable projects, local recovery, part projections, and page composition. Its accepted light DOM remains the editable musical source; model snapshots, SVG, and page previews are projections. Visual commands and Apply source validate changes before committing them.

Author's Lit components live in src/authoring/ui; its entry point is src/authoring/bootstrap.ts. The workbook toolbar, view switch, Source editor, navigator, and score viewport own shadow roots with explicit properties and events. Workspace and panel frames arrange complete caller-owned regions through named slots. The top-level shell, Properties/shared selection controls, musical source, and physical pages retain their native logical boundaries.

Editor transactions, workspace choices, form drafts, and workbook controls use independent signal-polyfill and signal-utils stores with readonly selectors. SignalController connects views and releases subscriptions on disconnect. ControlScope registers only owned control roots; composed focus/geometry helpers and public score projection snapshots preserve interaction across slots and shadow roots. Native controls and measured score nodes retain their identities across updates. See UI and state architecture for component APIs and reuse. Initial delivery is about 50.7 kB gzip for the workbook and 641.6 kB for Author, within the 51 kB / 642 kB build budgets.

The design system defines shared control tokens, choice-group styling, responsive behavior, and accessibility conventions for future UI work.

When embedding the notation library, edit source attributes or component properties to change music. Do not edit the generated SVG. Canonical score serialization keeps musical values and IDs, not the original HTML formatting or all application metadata; download an Author project to retain the complete document.

Verify

npm test
npm run typecheck
npm run check:icons
npm run build
npm run check:bundle

Tests cover musical semantics, DOM parsing/serialization, layout, authoring commands and history, projects and recovery, part projections, page planning, and native select enhancement. The workbook supplies visual cases to inspect at desktop, narrow, and print widths. Automated checks do not establish that every possible score has ideal engraving or page turns.

With the dev server running, open /tests/browser.html on the same origin and select Run browser regressions. This checks visible-ink spacing, rests, ties, nested tuplets, ensemble joins, native resize boundaries, source edits, lifecycle behavior, and fixed print preview; it is separate from npm test.

Open /tests/authoring-browser.html and select Run Author regressions for the actual Author controls, recovery, native selects, parts, and physical page composition. Its fixtures use separate recovery slots and intercept print requests; they do not establish that a native dialog appeared, a PDF was saved, fonts were embedded, or paper output matched the preview.

With Vite running, node scripts/check-select-kind-browser.mjs verifies the Select Note/Rest palette, immediate middle-line notes across clefs and key signatures, keyboard input, Undo, and responsive layouts in the pinned Chromium browser using isolated recovery. Set SELECT_TEST_URL if Vite uses a port other than 5173.

With Vite running, node scripts/check-touch-meter-browser.mjs verifies phone-width touch multi-selection, triplet edits, range selectors, shorter-meter overflow, and Undo using isolated recovery. Set TOUCH_TEST_BROWSER=webkit for WebKit or TOUCH_TEST_URL for a different server. Browser touch emulation does not establish physical-device gesture behavior.

Open /tests/shadow-dom-browser.html and select Run shadow component checks for independent component state, slots, native labels/descriptions and form behavior, composed focus and scrolling, popover placement, Source return focus, and isolated score IDs. These are DOM/native-API checks, not screen-reader or trusted keyboard/touch qualification.

Open /tests/icon-options-browser.html to check synchronous Phosphor/Bravura SVG delivery through native select cloning, accessible labels, form values, and icon opacity. npm run check:icons separately verifies that standalone production bundles remove unused icon definitions and have no deferred icon or font dependencies. The UI architecture guide describes icon imports and control layouts.

Open /tests/notation-browser.html and select Run notation expansion checks for actual quarter-tone glyphs, one-line rhythm engraving, rests, beams, tuplets, ties, mixed-staff alignment, and resize/print projection checks. The fixtures remain visible for review; the notation expansion record states the supported scope and performer checks.

Open /tests/three-roads-browser.html for the three-road line spacing, slash heads, relative directions, ties, rests, accessibility, and responsive/print checks. In Author, start with the 3 roads music template or change an all-rest staff to that notation, then enter road events with Higher (top), Same (middle), or Lower (bottom). Choose a starting reference pitch before playing; rests preserve it, and tied middle-road continuations sustain it.

Open /tests/event-markings-browser.html and select Run event marking checks for articulation and ornament glyphs, head-relative harmony figures, dense combinations, source edits, ties, parts, and responsive/print geometry. The markings guide explains the notation and its limits; the final workbook study shows the new HTML elements in use.

Current limits include instrument transposition, cross-staff beams, independent polymeter, arbitrary microtonal tuning beyond the supported quarter-tone spellings, tuplets spanning barlines, general slurs, arbitrary graphical notation, and automatic page-turn optimization. Author uses native browser printing, not a direct PDF generator. Inspect final pages with the intended paper, margins, and playing tempo before performing.

Listen uses current accepted music from the selected score or part, including the authored octaves, rather than a prior export or recovery snapshot. Pending Source and form drafts must be applied or discarded in Write first. Its portable brass-like synthesizer supports notes, chords, rests, quarter-tones, ties, tuplets, written tempo changes, dynamics and basic articulation. It plays written measures once; repeat expansion, ornament/fermata performance, and unspecified rhythm/slash/three-roads pitch interpretations are not included. Playback details disclose these limits. WAV exports and playback share one rendered buffer; no rendering service or remote sound assets are used. The audio controller loads on demand (about 4.8 kB gzip).

With Vite running, node scripts/check-view-docks-browser.mjs checks the bottom Read and Pages docks, native navigation and settings, responsive disclosures, and print-request visibility using memory-only recovery. Set DOCK_TEST_URL for a different server port. It does not verify saved PDFs or native print dialogs.

For the isolated Listen browser check, start the dev server on 127.0.0.1:5173, run npx playwright install chromium once, then npm run test:listen:browser. Playwright is pinned to 1.62.1 and uses its matching browser builds. Set LISTEN_TEST_BROWSER=firefox or LISTEN_TEST_BROWSER=webkit to run the same check in those engines after installing them with Playwright. The fixture uses memory-only recovery. LISTEN_TEST_URL changes the server URL; LISTEN_TEST_OUTPUT changes the evidence directory (default /tmp/music-notes-listen-browser). The script exercises the real controls, verifies the octave in the WAV, changes tempo, checks draft guards and cache invalidation, and checks desktop/mobile layout.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages