Skip to content
bbloomfPublic
forked from frmatthew/exsurge

About

A JavaScript library for rendering Gregorian Chant in square note notation

Resources

Stars

18 stars

Watchers

5 watching

Forks

 
 

Latest commit

 

History

1,178 Commits

Folders and files

Repository files navigation

exsurge

A JavaScript library for rendering Gregorian Chant in square note notation

Synopsis

exsurge allows developers to create SVG images of square note notation from gabc notation. These SVGs can then be inserted in the DOM or used for presentation purposes.

CI

Live Browser Example

Want to see gabc code rendered to chant on the fly? Try going here.

Code Example

First, create a ChantContext which contains the settings for how the chant will be rendered:

var ctxt = new exsurge.ChantContext();

Then, create a ChantScore from gabc code:

var gabc = "(f3) EC(ce!fg)CE(f) *(,) ad(fe~)vé(f!gwhf)nit(f) (,)"
var mappings = exsurge.Gabc.createMappingsFromSource(ctxt, gabc);
var score = new exsurge.ChantScore(ctxt, mappings, true);

Finally, let the ChantScore handle the layout process, and use the SVG however you want:

// perform layout on the chant
score.performLayout(ctxt, function() {
  score.layoutChantLines(ctxt, 1000, function() {

    // render the score to svg code
    var svgNode = document.createElement('div');
    var innerHtml = score.createDrawable(ctxt);
    svgNode.innerHTML = innerHtml;
    document.body.appendChild(svgNode);
  });
});

St. Gall neumes (NABC)

exsurge draws Gregorio's NABC, the St. Gall or Laon neumes that gabc with a nabc-lines header has after |s in its notes, above the staff (and a second line of it below the staff), given a font to draw it with. The fonts are converted from Gregorio's: gregall and gresgmodern for St. Gall neumes, traced from the manuscripts and drawn anew, and grelaon for Laon neumes. They're under the SIL Open Font License (see below), so they aren't in exsurge's bundle: import them from exsurge-ts/nabc-gregall, exsurge-ts/nabc-gresgmodern or exsurge-ts/nabc-grelaon, or load dist/nabc-gregall.min.js (and so on) after exsurge, which defines exsurgeNabcGregall (and so on).

import { gregall } from "exsurge-ts/nabc-gregall";

ctxt.nabcFonts = [gregall];
var gabc = "nabc-lines: 1;\n%%\n(f3) AL(ef~|ta>)le(fg/hggf|peclhgpi)lú(ef~|ta>)ia.(f.|ta-) (,)";

ctxt.nabcSize, ctxt.nabcAlignment and ctxt.nabcVisibility change its size, how it lines up with the notes and whether each line of it is drawn, as Gregorio's \gresetnabcfont, \gresetnabcalignment and \gresetnabc do.

Motivation

Very few good chant layout software exist for developers. exsurge allows web developers to insert beautiful chant into their workflow with the simplicity of a little JavaScript.

Developer Installation

exsurge is written in TypeScript, in src/. After grabbing the repo from github, it's a simple matter of using npm to build exsurge:

npm install
npm run build

This makes:

  • dist/esm/: ES modules with their typings, which the package's module and types point to
  • dist/exsurge.min.js: a minified UMD bundle, which the package's main points to (and dist/exsurge.js, the same unminified)
  • dist/nabc-gregall.min.js, dist/nabc-gresgmodern.min.js and dist/nabc-grelaon.min.js (and dist/esm/nabc/): the glyphs that exsurge draws Gregorio's NABC (St. Gall and Laon neumes) with, which aren't in exsurge's bundle, and which the package's exsurge-ts/nabc-gregall, exsurge-ts/nabc-gresgmodern and exsurge-ts/nabc-grelaon entry points point to (see the license, below)

src/nabc/ is converted from the fonts of Gregorio by tools/convert-nabc-font.mjs.

Alternatively, you can run npm run dev which will watch and rebuild the UMD bundle after each saved change. test/index.html is a page to try exsurge in a browser, once it's built; serve the repository and open it.

API Reference

Under construction...

Sung pitches across clef changes

score.getPlaybackPitches() returns a Map<Note, number> of the pitch each note is sung at, in half steps. Playback clients should use it for both sound and range, rather than the notes' written pitch.toInt(): the two differ by octaves after a change between a C clef and an F clef.

The notation doesn't say how the octaves of the two kinds of clef relate; the custos before the change does. So the first note after the first such change in a score is sung where that custos shows it, under the clef the custos is drawn with:

  • where an explicit custos ((a+::f3)) is written, if it is on that note;
  • otherwise where an automatic custos (z0) is placed, whether the source has one or not. That is the note's own staff position (an F clef's F being reckoned as the one above a C clef's C, as Gregorio reckons it), or an octave nearer when that is beyond where a custos is drawn.

The custos of a change is the last one before it. An automatic custos after an explicit one is the one for the change, so the explicit one before it, which is for something else, is not looked at: in (::h+) <nlba>*~Et introíbit.</nlba>() (Zz0f3), h+ shows where the return begins, and the verse after it is sung where the z0 shows its first note.

Each kind of clef then keeps its octave through later changes, so an antiphon that comes back after its verse is sung as it was before, unless an explicit custos shows another octave. Changes between clefs of the same kind, and to other clefs, are sung as they are written.

Nothing is changed in the score: the written notes, accidentals and custodes are as they would be otherwise, and the pitches need no layout. Call it again after Gabc.updateMappingsFromSource() and score.updateNotations().

Tests

npm test lints the code, type-checks it, and runs the tests (with Vitest). npm run test:watch runs the tests as files change.

The golden tests (test/golden/) draw a collection of gabc, covering each kind of notation, marking and text and the settings that change the layout, in each way exsurge can draw it: the svg string, the svg tree, svg DOM nodes and on a canvas. They compare what's drawn with the snapshots in test/golden/__snapshots__/, as do the tests of the minified bundle and the ES modules (test/bundle.test.ts), which build exsurge as it is published. After a change that is meant to change what exsurge draws, look over the changes to the snapshots and update them with npx vitest -u.

npm run test:reference compares what the source draws with what another version drew, on the golden tests at other widths and on random gabc, e.g. EXSURGE_REFERENCE=v1.30.1 npm run test:reference.

npm run bench times parsing, layout and drawing an svg.

Contributors

Under construction...

License

MIT License: http://adampritchard.mit-license.org/ or see the LICENSE file.

The glyphs for NABC in src/nabc/ (and what's built from them: dist/esm/nabc/, the dist/nabc-*.min.js bundles and the exsurge-ts/nabc-* entry points) are converted from Gregorio's gregall, gresgmodern and grelaon fonts, copyright © 2014–2026 Jakub Jelinek and © 2011 Association Saint-Benoît, Notre-Dame de Bellaigue, and are under the SIL Open Font License 1.1, not the MIT License: see the LICENSE-OFL.txt file.

About

A JavaScript library for rendering Gregorian Chant in square note notation

Resources

Stars

18 stars

Watchers

5 watching

Forks

Releases

Packages

Contributors

Languages