Code Monkey home page Code Monkey logo

abcjs-vexflow-renderer's Introduction

abcjs-vexflow-renderer

screenshot

VexFlow renderer for abcjs. Usage:

import { AbcjsVexFlowRenderer, Vex } from 'abcjs-vexflow-renderer';
import abcText from './abc_tune.txt';

const whereToRender = document.getElementById('musicDiv');

// generate a VexFlow renderer & context
const renderer = new Vex.Flow.Renderer(whereToRender, Vex.Flow.Renderer.Backends.SVG);
renderer.resize(500, 500);
const context = renderer.getContext();

// set up rendering options
const renderOptions = {
  xOffset: 3,
  widthFactor: 1.7,
  lineHeight: 185,
  clefWidth: 60,
  meterWidth: 25,
  repeatWidthModifier: 35,
  keySigAccidentalWidth: 10,
  tabsVisibility: 1,
  voltaHeight: 25,
  renderWidth: 500,
  tuning: AbcjsVexFlowRenderer.TUNINGS.GUITAR_STANDARD // see tunings.js for all tunings and instruments
};

// generate the tune object
const tune = AbcjsVexFlowRenderer.getTune(abcText, renderOptions);

// draw to the vexflow context
AbcjsVexFlowRenderer.drawToContext(context, tune);

Testing and Development

git clone https://github.com/MatthewDorner/abcjs-vexflow-renderer

cd abcjs-vexflow-renderer

yarn

Once environment is ready, npm run-script start will launch an HTML visual comparison tool that shows ABC tunes rendered via abcjs' built-in renderer in comparison to this library. To supply a custom set of tunes, place the file at visual-tool/tunes.txt. The jest command will run the test suite, and will produce an HTML test coverage report in the coverage folder.

About

I created this library for my React Native app, React Native Songbook. I decided to write this code because I wanted to include guitar tab, because VexFlow works in React Native, and because I wanted precise control over positioning and spacing to make the content usable on phones and tablets. This library is able to automatically generate tablature for most ABC tunes. "Most" currently means a single voice set to chords. More complex music may not render correctly, and not all ABC features are implemented.

Features currently supported:

  • Repeat signs
  • Multiple endings
  • Chord symbols
  • Grace Notes
  • Tuplets
  • Ties
  • Slurs
  • Some ornamentation
  • Tabs for multiple fretted instruments, fiddle fingerings, tin whistle and harmonica

Features not supported, TODO:

  • Multiple voices
  • Lyrics
  • Non-treble clef
  • Transposition

Harmonica tabs legend:

  • b = blow bend (b = half step, bb = whole step, etc.)
  • d = draw bend
  • ob = overblow
  • od = overdraw

abcjs-vexflow-renderer's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

abcjs-vexflow-renderer's Issues

Support ties/slurs

VexFlow supports this via Curve and StaveTie. I think Curve can be used for everything. The problem I've had so far is in the case where a tie/slur begins on the last note of the last measure of one line, and is meant to connect to a note at the beginning of the next line. If you tell VexFlow to do this like a normal tie/slur, it'll draw the curve across the entire page diagonally.

I've seen sheet music handle it like this:
tie example

But I can't figure out how to do this in VexFlow. I tried inserting a GhostNote and drawing the curve between the real note and the ghost note, but it gives an error. I think it was something like getTiePositionX doesn't exist.

Use abcjs-vexflow-renderer as conversion script from abc to svg

Hey,
I like the graphical output from this project very much! Thank you for making it public Matthew.

I presume that this might not be the scope of this project, but nevertheless I wonder how an example would look like, that reads an abc file from hard disk, renders it as svg (or perhaps also as png) and saves the result on hard disk. Using this library as an offline conversion tool might not be the idea behind writing things in javascript but maybe it is still possible.

What do you think? Is this possible and could you give me some hook how I could get started?

Best,
Nico

Dependencies not compatible with Nodejs 15 and above

Hey,
I tried to install the project dependencies with yarn as described in the Readme.md but received the following error:

Building: /home/user/.nvm/versions/node/v19.0.1/bin/node /home/user/code/abcjs-vexflow-renderer/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli   '/home/user/.nvm/versions/node/v19.0.1/bin/node',
gyp verb cli   '/home/user/code/abcjs-vexflow-renderer/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose',
gyp verb cli   '--libsass_ext=',
gyp verb cli   '--libsass_cflags=',
gyp verb cli   '--libsass_ldflags=',
gyp verb cli   '--libsass_library='
gyp verb cli ]
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp verb `which` failed     at getNotFoundError (/home/user/code/abcjs-vexflow-renderer/node_modules/which/which.js:13:12)
gyp verb `which` failed     at F (/home/user/code/abcjs-vexflow-renderer/node_modules/which/which.js:68:19)
gyp verb `which` failed     at E (/home/user/code/abcjs-vexflow-renderer/node_modules/which/which.js:80:29)
gyp verb `which` failed     at /home/user/code/abcjs-vexflow-renderer/node_modules/which/which.js:89:16
gyp verb `which` failed     at /home/user/code/abcjs-vexflow-renderer/node_modules/isexe/index.js:42:5
gyp verb `which` failed     at /home/user/code/abcjs-vexflow-renderer/node_modules/isexe/mode.js:8:5
gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:199:21)
gyp verb `which` failed  python2 Error: not found: python2
gyp verb `which` failed     at getNotFoundError (/home/user/code/abcjs-vexflow-renderer/node_modules/which/which.js:13:12)
gyp verb `which` failed     at F (/home/user/code/abcjs-vexflow-renderer/node_modules/which/which.js:68:19)
gyp verb `which` failed     at E (/home/user/code/abcjs-vexflow-renderer/node_modules/which/which.js:80:29)
gyp verb `which` failed     at /home/user/code/abcjs-vexflow-renderer/node_modules/which/which.js:89:16
gyp verb `which` failed     at /home/user/code/abcjs-vexflow-renderer/node_modules/isexe/index.js:42:5
gyp verb `which` failed     at /home/user/code/abcjs-vexflow-renderer/node_modules/isexe/mode.js:8:5
gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:199:21) {
gyp verb `which` failed   code: 'ENOENT'
gyp verb `which` failed }
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` succeeded python /usr/bin/python
gyp ERR! configure error 
gyp ERR! stack Error: Command failed: /usr/bin/python -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gyp ERR! stack SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
gyp ERR! stack 
gyp ERR! stack     at ChildProcess.exithandler (node:child_process:412:12)
gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
gyp ERR! stack     at maybeClose (node:internal/child_process:1098:16)
gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:304:5)
gyp ERR! System Linux 6.0.6-1-MANJARO
gyp ERR! command "/home/user/.nvm/versions/node/v19.0.1/bin/node" "/home/user/code/abcjs-vexflow-renderer/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /home/user/code/abcjs-vexflow-renderer/node_modules/node-sass
gyp ERR! node -v v19.0.1
gyp ERR! node-gyp -v v3.8.0

Googling around revealed that this has to do with incompatible nodejs to package version.

I performed some tests with different Nodejs versions and found out, that it breaks beginning with Nodejs 15, versions below 15 work and can be build and used like described in the Readme, above and including 15 do not work. Maybe you would want to update your dependencies to work with an up-to-date Nodejs or maybe at least hint towards this problem in the Readme.md file to save people the time it takes to debug and find the cause.

Best,
Nico

Tab Stems and longer beams

Hi Matthew,
is it possible to display Tab Note Stems wih your renderer?
canvas

Also I would like to know if there is an easy way to render beams of four notes like in the example here:
canvas1

Thanks,
Simon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.