Getting started
To get started with Verovio, you need to load the JavaScript library in a web page. If you were building your own website, you may choose to host this on your own servers, but in this tutorial we will use a version that is hosted on the Verovio website.
You can start with the following HTML page:
<html>
<head>
<script src="https://www.verovio.org/javascript/latest/verovio-toolkit-wasm.js" defer></script>
</head>
<body>
<h1>Hello Verovio!</h1>
<div id="notation"></div>
</body>
</html>
Save this in a plain text file somewhere on your hard-drive, and then open it with your browser. (The name does not matter, but it should end in .html
; verovio.html
is a good choice.) You should text in a large font that says “Hello Verovio!” but not much else. If you have your browser console open (discussed in the introduction), you should see no errors.
To start Verovio, you should add the following to your page in the head, after the <script>
tag that loads the Verovio toolkit:
<script>
document.addEventListener("DOMContentLoaded", (event) => {
verovio.module.onRuntimeInitialized = () => {
let tk = new verovio.toolkit();
}
});
</script>
(If you are unsure, scroll to the bottom of this page; the full example is given below.)
When you refresh your page, you should still see nothing, and there should be no errors in the browser console. To help you understand what this is doing, let’s start from the inside out.
The line tk = new verovio.toolkit();
creates a new instance of the Verovio toolkit. This is what we will eventually use to render the notation. However, we first need to wait until the Verovio library is fully downloaded and ready to use by your browser. The verovio.module.onRuntimeInitialized
line, and the document.addEventListener
lines do just that – they tell your browser to wait until other things have happened before trying to work with Verovio. This is a good, safe way to ensure all the requirements are met before we try to start working with Verovio.
Logging to the Console
While you are developing, it can be useful to write little notes to yourself to let you know what types of data you have, or to see what is happening at any given point in your code. As you proceed to more advanced uses you may wish to explore the browser’s built-in debugger, but until then a quick and easy way to do this is to use your browser’s error console.
In your page, just after the line where you instantiate a new Verovio toolkit, insert the following:
console.log("Verovio has loaded!");
When you refresh your page, you can see this note to yourself appear in the browser console. If no other errors appear, this gives you a critical pieces of information: Your browser has reached that point in execution, which means it has successfully loaded and initialized Verovio. If you do not see this, go back through the examples to see where you may have gone wrong. If you still cannot find this, you can find the full example for this stage of the tutorial below.
End of Section 1
At the end of this first section you should have a working web page, with a message printed to your browser console, and no other errors showing up. In the next section we will look at how to load and render some basic music notation in this page.
Full example
<html>
<head>
<script src="https://www.verovio.org/javascript/latest/verovio-toolkit-wasm.js" defer></script>
<script>
document.addEventListener("DOMContentLoaded", (event) => {
verovio.module.onRuntimeInitialized = () => {
let tk = new verovio.toolkit();
console.log("Verovio has loaded!");
}
});
</script>
</head>
<body>
<h1>Hello Verovio!</h1>
<div id="notation"></div>
</body>
</html>