JuliaMusic / MusicXML.jl

MusicXML in Julia
MIT License
13 stars 7 forks source link

Use AML instead #2

Closed aminya closed 5 years ago

aminya commented 5 years ago

Add AML as a dependency and backend and use its @aml keyword for the definition of the types. https://github.com/aminya/AML.jl

aminya commented 5 years ago

AML, that automatically creates/extracts HTML/XML files from Julia types! Actually MusicXML.jl was my inspiration for that project. Now that AML is getting better and better, I will take the MusicXML.jl backend to AML, which is much better, and allows fast and compact development.

For example instead of https://github.com/JuliaMusic/MusicXML.jl/blob/b1f01d6fd3343ae3a7125d376701e15ee71ebb9b/src/MusicXML.jl#L85:

@aml struct Scoreinstrument "score-instrument"
    name::String, "name"
    ID::String, a"id"
end

, AML will generate xml constructors and extractors automatically!

So AML will generate all of this from the previous definition:

struct Scoreinstrument
    name::String
    ID::String
    xml::Node
end

# xml constructor
function Scoreinstrument(name,ID)
    xml = ElementNode("score-instrument")
    addelement!(xml, "instrument-name", string(name))
    xml["id"] = ID * "-I1"
    return Scoreinstrument(name, ID, xml)
end

# xml extractor
function Scoreinstrument(xml::Node)

    name = findfirstcontent("/instrument-name",xml)
    ID = xml["id"][end-3:end]
    return Scoreinstrument(name, ID, xml)
end
Scoreinstrument(x::Scoreinstrument) = Scoreinstrument(x.xml)

Scoreinstrument(n::Nothing) = nothing
aminya commented 5 years ago

By doing this the number of lines of codes is almost reduced to half. image

aminya commented 5 years ago

Closed by https://github.com/JuliaMusic/MusicXML.jl/commit/d36a4541c57b4542ca2c8ea38f79091cbfbb1d79