• Stars
    star
    230
  • Rank 169,491 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 3 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐ŸŽผ A sheet music to polylines renderer

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.

More Repositories

1

shan-shui-inf

Procedurally generated Chinese landscape painting.
HTML
5,464
star
2

fishdraw

procedurally generated fish drawings
JavaScript
2,197
star
3

qiji-font

้ฝŠไผ‹้ซ” - typeface from Ming Dynasty woodblock printed books
Python
1,245
star
4

rrpl

Describing Chinese Characters with Recursive Radical Packing Language (RRPL)
JavaScript
846
star
5

linedraw

Convert images to vectorized line drawings for plotters.
Python
744
star
6

wax

A tiny programming language that transpiles to C, C++, Java, TypeScript, Python, C#, Swift, Lua and WebAssembly ๐Ÿš€
C
730
star
7

q5xjs

A small and fast alternative (experimental) implementation of p5.js
JavaScript
526
star
8

nonflowers

Procedurally generated paintings of nonexistent flowers.
JavaScript
503
star
9

skeleton-tracing

A new algorithm for retrieving topological skeleton as a set of polylines from binary images
C
488
star
10

cope

A modern IDE for writing classical Chinese poetry ๆ ผๅพ‹่ฏ—็ผ–่พ‘็จ‹ๅบ
JavaScript
458
star
11

ndwfc

๐ŸŒŠ๐Ÿ’ฅ N-dimensional Wave Function Collapse with infinite canvas
JavaScript
308
star
12

psvg

Programmable Scalable Vector Graphics -- drawings that draw themselves
TypeScript
297
star
13

magic-square-poems

Discovering magic squares in Tang Dynasty poems
C
188
star
14

handpose-facemesh-demos

๐ŸŽฅ๐ŸคŸ 8 minimalistic templates for tfjs mediapipe handpose and facemesh
JavaScript
185
star
15

Hermit

A man. A horse. A nature.
Python
167
star
16

Processing-Demos-for-The-Pocket-Handbook-of-Image-Processing-Algorithms

Processing Demos made when reading the book *The Pocket Handbook for Image Processing Algorithms in C*
Processing
127
star
17

chinese-hershey-font

Convert Chinese Characters to Single-Line Fonts using Computer Vision
Python
123
star
18

edges2calligraphy

Using pix2pix to convert scribbles to Chinese calligraphy
JavaScript
114
star
19

tk-fangsong-font

ๅ‰”้ชจไปฟๅฎ‹: Experimental Fang Song style Chinese font
Python
111
star
20

grand-timeline

Interactive grand unified timeline of 30,800 ancient Chinese people / ๅคไบบๅ…จ่กจ
JavaScript
109
star
21

hfmath

Render LaTeX math with Hershey Fonts
TypeScript
91
star
22

wechit

WeChat in Terminal (ๅพฎไฟก็ปˆ็ซฏ็‰ˆ)
Python
88
star
23

VisionOSC

PoseOSC + FaceOSC + HandOSC + OcrOSC + CatOSC + DogOSC
Objective-C++
85
star
24

wasm-fun

Non-trivial programs in hand-written WebAssembly
WebAssembly
77
star
25

PoseOSC

๐Ÿ“น๐Ÿคธโ€โ™‚๏ธ๐Ÿคพโ€โ™€๏ธ๐Ÿคบ PoseNet + OSC: send realtime human pose estimation data to your apps
JavaScript
76
star
26

ci-ren

Generative Chinese poetry
Python
74
star
27

r1b

A thermal-printer-oriented, 1-bit graphics rasterizer for 2D and 3D
C
70
star
28

squiggy

vector brushstroke library
TypeScript
63
star
29

asciimare

3D engine powered by ASCII art
Python
61
star
30

Okb.js

Procedural generation toolkit for Javascript - noises, randomness, curves, and more
HTML
58
star
31

ofxPoissonFill

Poisson filling shader for OpenFrameworks
C++
56
star
32

p5-hershey-js

p5.js Hershey Vector Font Library
JavaScript
50
star
33

pmst

๐ŸŽจ Poor Man's Style Transfer - Painting an image with the style of another, without machine learning
C++
48
star
34

zdic-cli

An offline command-line interface to zdic.net dictionary (ๆผขๅ…ธ)
JavaScript
47
star
35

interesting-polygon-archive

Collection of polygon data in various formats for testing computational geometry algorithms.
Processing
46
star
36

Loshu.js

A linear algebra library for JavaScript ๐Ÿ”ข
JavaScript
46
star
37

skeletonization-js

Javascript implementation of image skeletonization
JavaScript
41
star
38

ttf2hershey

Convert True Type Fonts (.ttf) to Hershey vector fonts
Python
40
star
39

fv

An experimental approach to expressing vector math in js (tagged template literals)
JavaScript
30
star
40

t43

A tiny 3D slicer written from scratch
C
30
star
41

LingDong-

Automatically keep my Github profile README updated with a python script and Github Actions
Python
28
star
42

PContour

Processing/Java library for finding contours in binary images
HTML
27
star
43

srcsnap

screenshot-driven version tracking
JavaScript
21
star
44

dbn.js

Recreation of John Maeda's "Design By Numbers" programming environment in JavaScript
JavaScript
17
star
45

TrackpadOSC

๐Ÿ’ป๐Ÿ‘‹โœŒ๏ธ๐Ÿ‘‰Send mac's multitouch trackpad read-out through OSC
Objective-C
17
star
46

xcessing

Friendly Processing-like interface to X11/Xlib in C
C
16
star
47

wax4vscode

Extension for the wax programming language in VS Code (highlight + transpile + run)
TypeScript
15
star
48

svg2pl

convert svg to polylines
C
14
star
49

lbll

tiny experimental language for limited environments
C
14
star
50

fast-many-face-detection-with-cpp-or-openframeworks-on-mac-using-neural-networks

Fast Many Face Detection with C++/OpenFrameworks on macOS using Neural Networks
C++
14
star
51

machining-projection-map

JavaScript
8
star
52

avrlass

AVR Lightweight Assembler (and disassembler)
JavaScript
6
star
53

60-212

JavaScript
5
star
54

teapot.lua

1 path tracer written in pure lua, 1 file, 0 dependencies.
Lua
5
star
55

Hello-World

Lorem Ipsum
3
star
56

cvDictUI

opencv-python tool for generating interactive GUI from any python dictionary
Python
3
star
57

lingdong

LingDong's project links
JavaScript
2
star