- What note is a minor 3rd above a B?
- What are the scale tones of a Gb Harmonic Minor?
- What relation is the C# note to an A Major scale? (Major 3rd)
- What accidentals should be displayed for the perfect 4th note of a G Major scale?
- etc.
The API is part of VexFlow, and can be used independently of the rendering API. Take a look at music.js in the VexFlow GitHub repository for the complete reference. There's also a handy key management library for building scores in keymanager.js.
I'm currently working on updating the VexFlow Tutorial with a quickstart on the music theory API, but meanwhile, here are some teasers (pulled straight out of the tests).
// What does C note consist of?
var parts = music.getNoteParts("c");
equals(parts.root, "c");
equals(parts.accidental, null);
// What does C# note consist of?
var parts = music.getNoteParts("c#");
equals(parts.root, "c");
equals(parts.accidental, "#");
// What is a flat-5th above C?
var value = music.getRelativeNoteValue(music.getNoteValue("c"),
music.getIntervalValue("b5"));
equals(value, music.getNoteValue("gb");
equals(value, music.getNoteValue("f#");
// What is the C quality of a Db?
equals(music.getRelativeNoteName("c", music.getNoteValue("db")), "c#");
// What are the tones of a C major scale?
var c_major = music.getScaleTones(
music.getNoteValue("c"), Vex.Flow.Music.scales.major);
// result: ["c", "d", "e", "f", "g", "a", "b"]
// What is the interval between a C and a D?
equals(music.getCanonicalIntervalName(music.getIntervalBetween(
music.getNoteValue("c"), music.getNoteValue("d"))), "M2");
![]() |
| Smarter Accidentals |
Notice how the accidentals are correctly picked according to the rules of standard notation? Yep, so do I.
We also have lots more tests -- over 750 of them! Try running them on your browser and tell me how long it takes.
That's all folks!

Tests completed in 3834 milliseconds.
ReplyDelete754 tests of 754 passed, 0 failed.
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16
My test results:
ReplyDelete------------
Google Chrome 12.0.712.0 dev
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.27 (KHTML, like Gecko) Chrome/12.0.712.0 Safari/534.27
Tests completed in 1866 milliseconds.
754 tests of 754 passed, 0 failed.
------------
Firefox 4.0
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0) Gecko/20100101 Firefox/4.0
Tests completed in 5200 milliseconds.
754 tests of 754 passed, 0 failed.
------------
IE 9
Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET4.0C; .NET4.0E; InfoPath.3)
Tests completed in 3388 milliseconds.
218 tests of 248 passed, 30 failed.
------------
Opera 11.01
Opera/9.80 (Windows NT 6.1; U; en) Presto/2.7.62 Version/11.01
Tests completed in 2000 milliseconds.
754 tests of 754 passed, 0 failed.
------------
Nice work on the theory API, especially for smarter accidentals. And the tests were fast:
ReplyDeleteTests completed in 2561 milliseconds.
754 tests of 754 passed, 0 failed.
(Firefox 4, Mac OS X 10.6)
1620 milliseconds
ReplyDeleteMozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16
Running Chrome with WAY too many tabs open.. at least 40+
It's really coming along! We should get together again. I've moved back to the city actually and am living out in Williamsburg.
Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.16 Safari/534.24
ReplyDeleteTests completed in 4093 milliseconds.
754 tests of 754 passed, 0 failed.
This is on an ancient 1.26 GHz P3 machine though.
As a musician and a software engineer, I am very impressed by this work to date. I believe that it could become an important development.
ReplyDeleteCongratulations and keep up the good work.
Awesome work! I'm starting to work on a digital music theory textbook with some interactive features. Can't wait to try some of this stuff!
ReplyDeleteNice. I have some of this set up in a few projects but nothing as complete as this. great example.
ReplyDeleteMozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.215 Safari/535.1
ReplyDeleteTests completed in 1367 milliseconds.
754 tests of 754 passed, 0 failed.
Would like to say that your work is awesome!
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1
ReplyDeleteTests completed in 1377 milliseconds.
754 tests of 754 passed, 0 failed.
AWESOME lib. Can't wait to put it to use.