Skip to content

Automatic graphical note representation #30

@aminya

Description

@aminya
Member

A custom method for Measure should be defined that uses attributes to fill note fields.
aminya/AcuteML.jl#107

Activity

aminya

aminya commented on May 12, 2020

@aminya
MemberAuthor

blocked by aminya/AcuteML.jl#130, but the basic code is written:

@aml mutable struct Measure "measure"
    attributes::UN{Attributes} = nothing, "~"
    notes::Vector{Note}, "note"
    @creator begin
        notes = note_graphics(notes, attributes)
    end
end

"""
Finds the graphical representation of a note based on attributes.divisions and note.duration

# Examples
notes = [
Note(pitch = Pitch(step = "G", alter = 0, octave = 5), duration =  1),
Note(pitch = Pitch(step = "G", alter = +1, octave = 5), duration =  1),
Note(pitch = Pitch(step = "B", alter = 0, octave = 5), duration =  1),
Note(pitch = Pitch(step = "A", alter = +1, octave = 5), duration =  1),
Note(rest = Rest(), duration =  4), # Rest
Note(pitch = Pitch(step = "A", alter = 0, octave = 5), duration =  4),
Note(pitch = Pitch(step = "B", alter = 0, octave = 5), duration =  4),
]
MusicXML.note_graphics(notes, Attributes())
"""
function note_graphics(notes, attributes)
    for inote=1:length(notes)
        actual_duration = notes[inote].duration//attributes.divisions
        type = note_graphics_map[actual_duration]
        notes[inote].type = type
    end
    return notes
end

const note_graphics_map = Dict(
    1//256 => "1024th",
    1//128 => "512th",
    1//64 => "256th",
    1//32 => "128th",
    1//16 => "64th",
    1//8 => "32nd",
    1//4 => "16th",
    1//2 => "eighth",
    1 => "quarter",
    2 => "half",
    4 => "whole",
    # "breve"
    # "long"
    # "maxima"
)
aminya

aminya commented on Jun 13, 2020

@aminya
MemberAuthor

The blocking issue is merged now. It should be possible to fix this.

linked a pull request that will close this issue on Jun 13, 2020
self-assigned this
on Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @aminya

    Issue actions

      Automatic graphical note representation · Issue #30 · JuliaMusic/MusicXML.jl