Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*.jl.cov
*.jl.mem
/docs/build/
Manifest.toml
Manifest.toml
myscore.musicxml
68 changes: 65 additions & 3 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,11 @@ slash::UN{YN} = nothing, "~"
```

steal_time_previous: The steal-time-previous attribute indicates the percentage of time to steal from the previous note for the grace note.

steal_time_following: The steal-time-following attribute indicates the percentage of time to steal from the following note for the grace note, as for appoggiaturas.

slash: The slash attribute for a grace note is yes for slashed eighth notes.

[More info](https://usermanuals.musicxml.com/MusicXML/Content/CT-MusicXML-grace.htm)
```
"""
Expand Down Expand Up @@ -559,7 +559,7 @@ tie:
pitch::UN{Pitch} = nothing, "~"
rest::UN{Rest} = nothing, "~"
unpitched::UN{Unpitched} = nothing, "~"
duration::UN{UInt} = grace === nothing ? nothing : 1, "~"
duration::UN{Int} = grace === nothing ? nothing : 1, "~"
chord::UN{Chord} = nothing, "~"
# voice
type::UN{String} = nothing, "~"
Expand All @@ -586,6 +586,64 @@ notes: See [`Note`](@ref) doc
attributes::UN{Attributes} = nothing, "~"
notes::Vector{Note}, "note"
end

################################################################
"""
Finds and fixes the graphical representation of the notes for the given measures.
"""
function note_graphics(measures::Vector{Measure})
last_attributes = Attributes()
for i = 1:length(measures)
if !isnothing(measures[i].attributes)
last_attributes = measures[i].attributes
end
measures[i].notes = note_graphics(measures[i].notes, last_attributes)
end
return measures
end

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

# Examples
```julia
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::Vector{Note}, attributes::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"
)
################################################################
"""
Part
Expand All @@ -603,8 +661,12 @@ measures: See [`Measure`](@ref) doc
"""
@aml mutable struct Part "part"
id::String = "P1", att"~"
@creator begin
measures = note_graphics(measures)
end
measures::Vector{Measure}, "measure"
end

################################################################
"""
ScorePartwise
Expand Down