๐ŸŽผ A sheet music to polylines renderer

Overview

legumes

๐ŸŽผ A sheet music to polylines renderer

Samples | Online Editor | API | Syntax

In goes a midi file or a simple markup format, and out comes โœจ polylines โœจ , which can then be used for animation, plotting and various procedural drawing fun.

๐Ÿšง This project is a work in progress and currently supports a subset of sheet music notation. Errors and ugliness might occur from time to time*. For professional quality scorewriting, check out https://en.wikipedia.org/wiki/List_of_scorewriters instead. ๐Ÿšง

Features

  • Supports most everyday classical music symbols;
  • Exports polylines, svg, pdf, gif, midi and more;
  • Lightweight: < 150KB minified; No dependencies;
  • Uses Hershey Fonts for text and symbols; You can load custom hershey fonts for rendering unicode etc;
  • Includes basic animation and handdrawn effects generator;
  • Use as browser/node.js library or commandline interface.

For examples, below are the first couple measures of Grieg's "Solitary Wanderer", typeset in legumes, with regular, animated and hand-drawn styles:

You can find at the bottom of this document the full score, or better yet, Checkout the samples folder for a more comprehensive showcase featuring music by various composers!

*legumes is an acronym for Lingdong's Erratic and Generally Useless Musical Engraving System.

Usage

The easiest way to try out the project is by using the Online Editor, which supports syntax highlighting and midi playback. For more advanced usage, there're commandline and programming interfaces, described below:

Commandline

The legc executable included in the repo is a shebang'ed node.js script. You can easily invoke it in the commandline via ./legc (or legc if placed/aliased in PATH) if you have node.js installed.

Minimal example, rendering a score to SVG:

legc --format svg samples/minuet_G.txt > output.svg

Another example, render a score to an animated svg, specifying some rendering options:

legc --format svg-anim \
  --stem-length 3 --title-text-size 28 --page-margin-x 120\
  samples/minuet_G.txt > output.svg

The commandline tool supports some 50+ rendering/export options, view the full list by typing:

legc --help

Programming

Built JavaScript files acn be found in dist/ folder. Import them via

">
<script src="dist/legumes.min.js">script>

or

const legumes = require("dist/legumes");

You can find the full API doc here, but here's a minimal example:

const txt = fs.readFileSync("samples/minuet_G.txt").toString();

// build a score from the text-based markup
const score = legumes.parse_txt(txt);

// compile the score to pre-compute properties for drawing
legumes.compile_score(score);

// draw the score
let drawing = legumes.render_score(score);

// export drawing to SVG format
let svg = legumes.export_svg(drawing)

fs.writeFileSync("output.svg",svg);
// document.body.innerHTML = svg;

You can configure rendering options via the CONFIG object, e.g. :

legumes.CONFIG.STEM_LENGTH = 3;
legumes.CONFIG.DURATION_BASED_SPACING = 0.07;
legumes.CONFIG.LYRIC_SCALE = 0.8;

Midi files can also be rendered, but note that midi is not a suitable format storing sheet music, and educated guesses has to be made converting it to one:

let bytes_in = Array.from(new Uint8Array(fs.readFileSync("input.mid")));
let midi_file = legumes.parse_midi(bytes_in);
let score = legumes.score_from_midi(midi_file);
legumes.compile_score(score);
fs.writeFileSync("output.svg", legumes.export_svg(drawing));

What one could do, is read a midi file, and export it as markup text, make improvements by hand, and render the latter instead:

let bytes_in = Array.from(new Uint8Array(fs.readFileSync("input.mid")));
let midi_file = legumes.parse_midi(bytes_in);
let score = legumes.score_from_midi(midi_file);
let txt = legumes.export_txt(score);
fs.writeFileSync("score.txt", txt);

In addition to the supported input file formats, you can construct your own score object to feed into legumes, as long as it conforms to the interface:

interface Score_itf{
  title:       string[];
  composer:    string[];
  tempo?:      Tempo_itf;
  instruments: Instrument_group_itf[];
  slurs:       Slur_itf[];
  measures:    Measure_itf[];
  crescs:      Cresc_itf[];
}

You can find more details about these interfaces in API doc and src/common.ts.

legumes render with several stages. You can unplug the final polylines output and write a custom renderer that interprets the computed element layout. For example, visualize the elements with export_mock_svg routine:

let drawing = legumes.render_score(score,{compute_polylines:false});
let svg = legumes.export_mock_svg(drawing)

More details can be found in src/drawing.ts.


Special thanks to my friend @jiangzoi (Computational music major at CMU) and my mother (piano teacher) for advice and help on sheet music, of which I came to realize I know little as I progress with the project.

Issues & Pull request are welcome.

You might also like...

Music bot that uses Lavalink for its audio player

Music bot that uses Lavalink for its audio player

Msv Music ๐ŸŽต A Advanced Discord Music Bot Made With Lavalink And Have Many Premium Features with filters and more willl be add soon About Msv Music ๐Ÿšง

Jan 4, 2022

A multi-purpose discord bot, that has 100+ commands. Includes ๐ŸŽถ Music, ๐Ÿ“ท Image Generation, ๐Ÿ“Š Leaderboard, and more!

Cleckzie An open-source, multi-purpose discord bot, made with JavaScript. Has useful categories like: ๐ŸŽถ Music - filter, seek, queue, volume and more.

Jul 2, 2022

Discord.js Music Bot with buttons and slash support!

Music Bot Vote for us! (Please) How to use? Download the repo, create a .env file, and add your token into it. You need to change guildOnly to your gu

Nov 24, 2022

A self-hosted, completely private and free music streaming server compatible with Synology Audio Station's web browser interface and smartphone apps.

A self-hosted, completely private and free music streaming server compatible with Synology Audio Station's web browser interface and smartphone apps.

Open Audio Server Open Audio Server is a music streaming server compatible with Audio Station by Synology. Audio Station creates your own private serv

Dec 11, 2022

ALi a powerful Discord bot that includes Utility, Fun, Music, Moderation, and much more! (Beta)

ALi a powerful Discord bot that includes Utility, Fun, Music, Moderation, and much more! (Beta)

ALi ALi a powerful Discord Bot Invite ALi ยท Report Bug ยท Request Feature ๐ŸŽญ Futures Music Moderation Fun Economy Utility More ๐Ÿš€ Installation You can

Oct 17, 2022

A Discord.js Music Bot, which connects via Lavalink and erela.js

A Discord.js Music Bot, which connects via Lavalink and erela.js

Discord.js Lavalink Music Bot using erela.js A Advance Discord Music Bot Like Hydra Erela.js docs Note this Discord Bot Repository is the Same as for

Dec 9, 2022

Discord Music Made Simple.

boat-discord Inspiration This project was made because of the shutdown of Groovy and Rhythm. This project was inspired by the connecting two APIs work

Nov 9, 2022

Web Application that represents a music player using the spotify API, React, JS, CSS, HTML, nodeJS, Firebase, material-ui, JSON and other technologies. Made by Yohan Hmaiti

Web Application that represents a music player using the spotify API, React, JS, CSS, HTML,  nodeJS, Firebase, material-ui, JSON and other technologies. Made by Yohan Hmaiti

Web Application that represents a music player using the spotify API, React, JS, CSS, HTML, nodeJS, Firebase, material-ui, JSON and other technologies. Made by Yohan Hmaiti

Jan 8, 2022

This is a powerful discord bot for music!

Music Bot This is a music bot that is very powerful. Have 24/7 music channels if you want! ๐Ÿ“‘ Installation To use the project correctly you will need

Dec 21, 2021
Iโ€™m a very useful music bot that can make you play a music with a simple command! I have a lot of good commands that you can have a better experience playing your favorites songs!

Iโ€™m a very useful music bot that can make you play a music with a simple command! I have a lot of good commands that you can have a better experience playing your favorites songs!

Hugo Kishi 2 Aug 16, 2022
Music-Player - Music player application built with HTML, CSS and vanilla JavaScript

Music-Player Music player application built with HTML, CSS and vanilla JavaScrip

Karthik Umashankar 1 Feb 10, 2022
A mobile app for playing music on Resonate, an open source music streaming co-op.

stream2own Play fair. Website | Twitter | Contributing | Developer Guide ?? Resonate Stream App A mobile app for playing music on Resonate, an open so

Peter Klingelhofer 12 Dec 28, 2022
A decentralized Music Ownership System developed on Truffle Suite and React Bootstrap to allow Music artists to upload their content to the blockchain, that can be streamed by users

A decentralized Music Ownership System developed on Truffle Suite and React Bootstrap to allow Music artists to upload their content to the blockchain, that can be streamed by users.

M. Adil Fayyaz 10 Sep 5, 2022
JavaScript plugin for playing sounds and music in browsers

JavaScript plugin for playing sounds on user actions and page events. Version: 3.0.7 Project page and demos Download ZIP Support the plugin on GitHub

Denis Ineshin 704 Sep 24, 2022
VexFlow 3 - A JavaScript library for rendering music notation and guitar tablature.

VexFlow 3 - A JavaScript library for rendering music notation and guitar tablature.

Mohit Cheppudira 3.5k Jan 6, 2023
A simple package to download music tracks from spotify ๐ŸŽต

A simple package to download music tracks from spotify ??

Alen Yohannan 26 Dec 25, 2022
โšก Discord bot with economy, gambling, music, fun, moderation features based on discord.js v12

Crucian Crucian is my discord bot with simple structure based on discord.js Click Here to invite Crucian to your server Author Crucian ยฉ Apoo Authored

apoow3b 3 Jul 26, 2021
An adorable lavalink discord music bot that has a lot of features inside it.

Laffey An adorable lavalink discord music bot that has a lot of features inside it. First Project of Weeb-Devs Features: โœ“ High quality โœ“ Support filt

null 81 Dec 31, 2022
The #1 cross-platform open source music player

Rhyme The #1 Open-Source Music Player Discord: Matrix: A beautiful looking music player which supports Local music files Create custom playlists view

Rhyme Music Player 51 Apr 13, 2022