Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic graphical note representation #30

Open
aminya opened this issue Mar 1, 2020 · 2 comments · May be fixed by #49
Open

Automatic graphical note representation #30

aminya opened this issue Mar 1, 2020 · 2 comments · May be fixed by #49
Assignees

Comments

@aminya
Copy link
Member

aminya commented Mar 1, 2020

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

@aminya
Copy link
Member Author

aminya commented May 12, 2020

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
Copy link
Member Author

aminya commented Jun 13, 2020

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

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

Successfully merging a pull request may close this issue.

1 participant