abcjs
repository·main·Indexed 25 days ago
https://github.com/paulrosen/abcjsA JavaScript library for rendering standard ABC music notation in web browsers. It supports sheet music visualization as SVG, MIDI generation, and audio playback. Key features include the renderAbc function, a Synth API for audio synthesis, interactive editing via Editor and EditArea classes, and support for string tablature and jazz-style chord grids.
What's inside abcjs
- abcjs is a JavaScript library designed for rendering standard music notation (ABC notation) directly in a web browser. It allows developers to incorporate sheet music into websites, generate MIDI files, or play music directly in the browser. It can be used as a standard library integration or via a Greasemonkey script to transform ABC text on existing websites.
Understanding Absolute and Relative Elements
mainIn the abcjs engraving model, musical notation is composed of two types of objects that work together:
- Absolute Element: A visual piece of music that moves as a single unit (e.g., a key signature containing multiple sharp symbols). It has an X and Y position in the SVG and contains an array of Relative Elements.
- Relative Element: Glyphs that are attached to an Absolute Element. They use relative positioning to stay attached to their parent (e.g., a trill, a flat sign, a stem, or a dot attached to a note head).
How the abcjs engraver processes music notation
mainThe abcjs engraver takes the output from the parser and processes it through three main stages to transform musical data into a visual, interactive SVG:
- Element Creation: The parser's output structure is traversed to create musical elements.
- Layout: The engine runs separate algorithms for horizontal and vertical positioning once element sizes are known.
- Drawing: The engine traverses the structure one final time to render each element into the SVG based on the calculated layout.
Configure midi.js as a peerDependency
mainStarting from version 6.0.0-beta.26,
midi.jsis no longer a direct dependency but apeerDependency. If you are using the old style of sound generation that requiresmidi.js, you must include it in yourpackage.json:"midi": "https://github.com/paulrosen/MIDI.js.git#abcjs"Note: This requirement does not apply if you are using the minified version of the library via a
<script>tag.Access the abcjs documentation
mainThe official documentation for abcjs has moved. For the most up-to-date guides, API references, and tutorials, visit https://docs.abcjs.net.Use chordGrid for jazz-style chord views
mainIn version 6.6.0 and later, you can use the
chordGridoption within therenderAbcparameters to display chords in a layout similar to traditional jazz lead sheets.Available options:
chordGrid: "noMusic": Displays only the chords.chordGrid: "withMusic": Prints the chords above the standard music notation.
Configure the default soundfont
mainabcjs uses a default soundfont for audio playback. If you need to use a specific soundfont (for example, to revert to the older
FluidR3_GMstyle), use thesoundFontUrloption when calling the synth functions.To use the older soundfont, set:
soundFontUrl: "https://paulrosen.github.io/midi-js-soundfonts/FluidR3_GM/"Run abcjs using Docker Compose
mainYou can run the
abcjsapplication using Docker Compose. The setup builds the image from the local directory and maps the local source code andnode_modulesinto the container to allow for development.Note that the host port for the application is determined by the environment variable
$abcjs_docs.services: app: image: abcjs build: . container_name: abcjs volumes: - .:/srv/app - ./node_modules:/srv/app/node_modules ports: - $abcjs_docs:8080Render string tablature
mainString tablature can be rendered by adding a specific option to therenderAbcparameters. Refer to the official tablature documentation for specific implementation details.Style the audio control warning
mainIf you are using
abcjs-audio.cssand want to hide the CSS warning element when styling the audio control with your own custom CSS, add the following rule:.abcjs-css-warning { display: none; }Use the abcjs Editor and EditArea for interactive editing
mainFor building interactive music editors, use theEditorandEditAreaclasses provided by the library.Create MIDI files from ABC notation
mainUse the
createfunction to convert an ABC tune object into MIDI data. This function processes the ABC notation, extracts metadata (title, key, meter), and translates musical events (notes, text, instrument programs) into a MIDI format.Parameters
abcTune: An object representing the ABC tune, which must implement methods likesetUpAudio(options),getKeySignature(),getMeterFraction(), andmillisecondsPerMeasure().options(optional): An object to configure the MIDI creation process.
Options
options.pan: An array of panning values (integers) corresponding to each track in the ABC tune. If provided,options.pan[i]sets the pan for tracki.
Return Value
Returns the raw MIDI data (typically a Uint8Array or similar buffer) generated from the tune.