JuliaMusic / MusicXML.jl

MusicXML in Julia
MIT License
14 stars 7 forks source link

Incompletely specified MusicXML files fail to read #46

Closed vilim closed 4 years ago

vilim commented 4 years ago

The construction of MidiInstrumets and Notes fails for some files I exported through music21 in Python, because some elements are not specified. Even though defaults are provided in types.jl, the XML parser complains with errors like:

MethodError: Cannot `convert` an object of type Nothing to an object of type UInt64
Closest candidates are:
  convert(::Type{T}, !Matched::EzXML.NodeType) where T<:Integer at C:\Users\vilim\.julia\packages\EzXML\ZNwhK\src\node.jl:37
  convert(::Type{T}, !Matched::EzXML.ReaderType) where T<:Integer at C:\Users\vilim\.julia\packages\EzXML\ZNwhK\src\streamreader.jl:55
  convert(::Type{T}, !Matched::Unitful.Quantity) where T<:Real at C:\Users\vilim\.julia\packages\Unitful\ytsW0\src\conversion.jl:141
  ...

Stacktrace:
 [1] MusicXML.Note(::MusicXML.Pitch, ::Nothing, ::Nothing, ::Nothing, ::Nothing, ::String, ::Nothing, ::Nothing, ::EzXML.Node) at C:\Users\vilim\.julia\dev\MusicXML\src\types.jl:526
 [2] MusicXML.Note(::EzXML.Node) at C:\Users\vilim\.julia\packages\AcuteML\csjnr\src\@aml\@aml_create\get_struct_xml_.jl:53
...

the offending part of the XML file is for example:

<note>
  <grace/>
  <pitch>
    <step>G</step>
    <octave>4</octave>
  </pitch>
  <voice>1</voice>
  <type>16th</type>
  <stem>up</stem>
  <beam number="1">end</beam>
  <beam number="2">end</beam>
</note>
aminya commented 4 years ago

This is because the duration field is missing. Are grace notes always without duration? I did not know this and have made duration field mandatory. I will fix it in the next release.

aminya commented 4 years ago

The fixes are available now. Please let me know if you encountered any other errors.

vilim commented 4 years ago

Thank you! I switched to MIDI for this project, but will have a look again when I try other pieces of music.