May 23, 2014Musical.jsHere is musical.js, which is a small (less than 17K minified) javascript library that can translate from ABC notation into WebAudio, for playing simple tunes on any modern browser. It has no dependencies, and it can be used as a plain script, an AMD module, or as a node.js module. It also includes a simple synthesizer for creating your own instrument, including a basic electric piano sound. The library is really simple to use. Basically, include the script musical.js, and then: piano = new Instrument('piano'); piano.play('ccggaag2'); Then with any WebAudio browser, you will be Baahing with the Black Sheep, Twinkling with the Stars, or singing your ABCs with me. The notation used is called ABC Notation, and it is used for a lot of simple sheet music online. Less-simple music can be played just as easily. Here are some short examples: Minuet, September, Sonata and Moonlight. The library comes out of work from beefing up music support in Pencil Code. The WebAudio sequencer in that library has improved enough that it deserves to be a separate library. You can also play with it as part of the turtle library on pencil code here: that example is a simple interactive piano keyboard where you can see the keys. Have fun. Let me know if you encounter any problems, or if you have any ideas for improvements. Always looking for open-source contributions. Posted by David at May 23, 2014 03:39 PMComments
Hi David, thanks for musical.js. I incorportated it in a project to draw notes for table harp. How can I achieve that musical.js obeys the speed denoted in the Q: directive: (e.g. Q:1/4=120) B. Posted by: Bernhard at June 23, 2014 10:47 AMHello David, Hi David, The class is great and the piano is very well imitated. I am trying to use it in a chord maker program Has the class by chance a method for doing pause and resume ? Best regards Posted by: job at July 5, 2018 03:59 PMAwesome piece of code :-) At https://gospelriver.com/play_abc/ is a sample that behaves weirdly: Set Q:120 and it plays at a good temp but quits about half way through (2 phrases) This is on Windows. On my iPad it quits just a couple of measures in. That smells like a timing issue . . . Any clues? Thanks so much. Another html in my testbed, same song, same behavior: -----------------
var inst = new Instrument('piano'); Since mine is the last comment and it is a bit of a downer I wanted to give credit where credit is due. We figured out the issue above and have made several other minor fixes, including support for fermatas. We are basing a significant hymnbook on this little library because it is cross platform. Rosen’s abcjs sounds better and we are using it for scores . . . But it uses a different method for playback that severely limits cross platform playback. This litte guy is the engine that could. I just didn’t want to leave a bad impression. Posted by: Alfred Corduan at June 5, 2020 09:58 AMPost a comment
|
Copyright 2014 © David Bau. All Rights Reserved. |