@@ -586,6 +586,64 @@ notes: See [`Note`](@ref) doc
586
586
attributes:: UN{Attributes} = nothing , " ~"
587
587
notes:: Vector{Note} , " note"
588
588
end
589
+
590
+ # ###############################################################
591
+ """
592
+ Finds and fixes the graphical representation of the notes for the given measures.
593
+ """
594
+ function note_graphics (measures:: Vector{Measure} )
595
+ last_attributes = Attributes ()
596
+ for i = 1 : length (measures)
597
+ if ! isnothing (measures[i]. attributes)
598
+ last_attributes = measures[i]. attributes
599
+ end
600
+ measures[i]. notes = note_graphics (measures[i]. notes, last_attributes)
601
+ end
602
+ return measures
603
+ end
604
+
605
+ """
606
+ Finds the graphical representation of a note based on attributes.divisions and note.duration
607
+
608
+ # Examples
609
+ ```julia
610
+ notes = [
611
+ Note(pitch = Pitch(step = "G", alter = 0, octave = 5), duration = 1),
612
+ Note(pitch = Pitch(step = "G", alter = +1, octave = 5), duration = 1),
613
+ Note(pitch = Pitch(step = "B", alter = 0, octave = 5), duration = 1),
614
+ Note(pitch = Pitch(step = "A", alter = +1, octave = 5), duration = 1),
615
+ Note(rest = Rest(), duration = 4), # Rest
616
+ Note(pitch = Pitch(step = "A", alter = 0, octave = 5), duration = 4),
617
+ Note(pitch = Pitch(step = "B", alter = 0, octave = 5), duration = 4),
618
+ ]
619
+ MusicXML.note_graphics(notes, Attributes())
620
+ ```
621
+ """
622
+ function note_graphics (notes:: Vector{Note} , attributes:: Attributes )
623
+ for inote= 1 : length (notes)
624
+ actual_duration = notes[inote]. duration// attributes. divisions
625
+ type = note_graphics_map[actual_duration]
626
+ notes[inote]. type = type
627
+ end
628
+ return notes
629
+ end
630
+
631
+ const note_graphics_map = Dict (
632
+ 1 // 256 => " 1024th" ,
633
+ 1 // 128 => " 512th" ,
634
+ 1 // 64 => " 256th" ,
635
+ 1 // 32 => " 128th" ,
636
+ 1 // 16 => " 64th" ,
637
+ 1 // 8 => " 32nd" ,
638
+ 1 // 4 => " 16th" ,
639
+ 1 // 2 => " eighth" ,
640
+ 1 => " quarter" ,
641
+ 2 => " half" ,
642
+ 4 => " whole" ,
643
+ # "breve"
644
+ # "long"
645
+ # "maxima"
646
+ )
589
647
# ###############################################################
590
648
"""
591
649
Part
@@ -603,8 +661,12 @@ measures: See [`Measure`](@ref) doc
603
661
"""
604
662
@aml mutable struct Part " part"
605
663
id:: String = " P1" , att " ~"
664
+ @creator begin
665
+ measures = note_graphics (measures)
666
+ end
606
667
measures:: Vector{Measure} , " measure"
607
668
end
669
+
608
670
# ###############################################################
609
671
"""
610
672
ScorePartwise
0 commit comments