-
Hello, I want to convert an XML file to Humdrum data using the verovio library. There is a section in the documentation related to this, but I couldn't fully understand it. How can I accomplish this task? The reason I want to get this output is that I want to use the "Humdrum Notation Plugin" to display and manipulate music notes on a webpage. I want to create a slider that follows the notes along with MIDI input for controlling them. If you have any other method recommendations for this process, I would be happy to hear them. Thank you in advance. Normally, I render it as SVG. My code:
I use latest version. package.json:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
On the command line, MusicXML files can be converted to Humdrum with this verovio command: verovio --from musicxml-hum input.musicxml --to humdrum -o output.krn The So in Javascript you would add these two options:
Then do (from memory, so you can tell me if there are any problems): tk.setOptions(options);
tk.loadData(musicXMLData);
let humdrum = tk.getHumdrum(); Another possibility is to drag-and-drop a MusicXML file onto VHV (https://verovio.humdrum.org) and then go to "File → Convert to Humdrum":
unzip file.mxl This will unzip the musicxml file with some arbitrary name, and the directory METADATA that can be deleted. Resulting in: You can then copy-and-paste the text editor contents, or use "File → Save editor contents" to download the file (as
To save with the name That all said, you can use MusicXML data as input into the Humdrum Notation Plugin. For a demo, go to "File → Save as HTML": Click to view HTML webpage code that uses HNP to display the music notation as MusicXML<html>
<head>
<title>My Score</title>
<script src="https://plugin.humdrum.org/scripts/humdrum-notation-plugin-worker.js">
</script>
</head>
<body>
<script>
displayHumdrum({
source: "my-score",
autoResize: "true",
header: "true"
});
<!-- See https://plugin.humdrum.org/options/#list for more display options -->
</script>
<script type="text/x-humdrum" id="my-score">
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 4.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="4.0">
<work>
<work-title>Untitled score</work-title>
</work>
<identification>
<creator type="composer">Composer / arranger</creator>
<encoding>
<software>MuseScore 4.2.0</software>
<encoding-date>2024-03-23</encoding-date>
<supports element="accidental" type="yes"/>
<supports element="beam" type="yes"/>
<supports element="print" attribute="new-page" type="no"/>
<supports element="print" attribute="new-system" type="no"/>
<supports element="stem" type="yes"/>
</encoding>
</identification>
<defaults>
<scaling>
<millimeters>6.99911</millimeters>
<tenths>40</tenths>
</scaling>
<page-layout>
<page-height>1596.77</page-height>
<page-width>1233.87</page-width>
<page-margins type="even">
<left-margin>85.7252</left-margin>
<right-margin>85.7252</right-margin>
<top-margin>85.7252</top-margin>
<bottom-margin>85.7252</bottom-margin>
</page-margins>
<page-margins type="odd">
<left-margin>85.7252</left-margin>
<right-margin>85.7252</right-margin>
<top-margin>85.7252</top-margin>
<bottom-margin>85.7252</bottom-margin>
</page-margins>
</page-layout>
<appearance>
<line-width type="light barline">1.8</line-width>
<line-width type="heavy barline">5.5</line-width>
<line-width type="beam">5</line-width>
<line-width type="bracket">4.5</line-width>
<line-width type="dashes">1</line-width>
<line-width type="enclosure">1</line-width>
<line-width type="ending">1.1</line-width>
<line-width type="extend">1</line-width>
<line-width type="leger">1.6</line-width>
<line-width type="pedal">1.1</line-width>
<line-width type="octave shift">1.1</line-width>
<line-width type="slur middle">2.1</line-width>
<line-width type="slur tip">0.5</line-width>
<line-width type="staff">1.1</line-width>
<line-width type="stem">1</line-width>
<line-width type="tie middle">2.1</line-width>
<line-width type="tie tip">0.5</line-width>
<line-width type="tuplet bracket">1</line-width>
<line-width type="wedge">1.2</line-width>
<note-size type="cue">70</note-size>
<note-size type="grace">70</note-size>
<note-size type="grace-cue">49</note-size>
</appearance>
<music-font font-family="Leland"/>
<word-font font-family="Edwin" font-size="10"/>
<lyric-font font-family="Edwin" font-size="10"/>
</defaults>
<part-list>
<score-part id="P1">
<part-name>Piano</part-name>
<part-abbreviation>Pno.</part-abbreviation>
<score-instrument id="P1-I1">
<instrument-name>Piano</instrument-name>
<instrument-sound>keyboard.piano</instrument-sound>
</score-instrument>
<midi-device id="P1-I1" port="1"></midi-device>
<midi-instrument id="P1-I1">
<midi-channel>1</midi-channel>
<midi-program>1</midi-program>
<volume>78.7402</volume>
<pan>0</pan>
</midi-instrument>
</score-part>
</part-list>
<part id="P1">
<measure number="1" width="212.80">
<print>
<system-layout>
<system-margins>
<left-margin>50.00</left-margin>
<right-margin>799.62</right-margin>
</system-margins>
<top-system-distance>170.01</top-system-distance>
</system-layout>
</print>
<attributes>
<divisions>1</divisions>
<key>
<fifths>0</fifths>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<note default-x="80.22" default-y="-15.00">
<pitch>
<step>C</step>
<octave>5</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>down</stem>
</note>
<note default-x="110.61" default-y="-10.00">
<pitch>
<step>D</step>
<octave>5</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>down</stem>
</note>
<note default-x="141.01" default-y="-5.00">
<pitch>
<step>E</step>
<octave>5</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>down</stem>
</note>
<note default-x="171.40" default-y="0.00">
<pitch>
<step>F</step>
<octave>5</octave>
</pitch>
<duration>1</duration>
<voice>1</voice>
<type>quarter</type>
<stem>down</stem>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>
</script>
</body>
</html> A caveat is that the MusicXML file should not contain the string Resulting webpage display: Errors in MusicXML to Humdrum can be reported on the humlib issues page. humlib also contains a command-line program called musicxml2hum file.musicxml > file.krn
This program also does not handle compressed MusicXML files ( unzip file.mxl This will unzip a MusicXML file (with an internal assigned name) that you can then run through To install git clone https://github.com/craigsapp/humlib
cd humlib
make
sudo make install # sudo is usually required The executable will be created in |
Beta Was this translation helpful? Give feedback.
-
I have not used the npm version of verovio yet, so @lpugin or @WolfgangDrescher can clarify. Probably there are some missing interface functions to make the conversion from MusicXML to Humdrum possible. I see https://github.com/rism-digital/verovio/blob/develop/emscripten/npm/src/emscripten-proxy.js#L45-L46
Maybe adding a function in that file called
https://github.com/rism-digital/verovio/blob/develop/src/toolkit.cpp#L221-L223 Loading MusicXML from HNP should not have any time penalty, because I think it will used the Another thing to check is if Humdrum is enabled in your version of the npm package, which can be compiled with or without Humdrum capabilities. See the -H that disables Humdrum: https://github.com/rism-digital/verovio/blob/develop/emscripten/buildNpmPackage But in that case the |
Beta Was this translation helpful? Give feedback.
I have not used the npm version of verovio yet, so @lpugin or @WolfgangDrescher can clarify. Probably there are some missing interface functions to make the conversion from MusicXML to Humdrum possible.
I see
getHumdrum
in the npm interface code:https://github.com/rism-digital/verovio/blob/develop/emscripten/npm/src/emscripten-proxy.js#L45-L46
https://github.com/rism-digital/verovio/blob/develop/emscripten/npm/src/verovio-toolkit.js#L66-L68
setOptions
andloadData
are there, so in theory it should work.Maybe adding a function in that file called
convertMusicXMLToHumdrum(data)
would be good, which would import viamusicxml-hum
and export viagetHumdrum
.musicxml-hum
it is note listed in …