Skip to content

Commit

Permalink
Merge pull request #32 from JuliaMusic/renametypes
Browse files Browse the repository at this point in the history
Rename types
  • Loading branch information
aminya authored Mar 4, 2020
2 parents 9e41c1e + 5d49a34 commit 416ff98
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 115 deletions.
70 changes: 38 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Powerful MusicXML reading and writing package for Julia.
```
# Creating Example
```julia
@MX begin # adds `MX.` to the name of all MusicXML types
using MusicXML

## Part List
Expand All @@ -39,20 +40,20 @@ attributes1_piano = Attributes(
)

measure1_notes_piano = [
NoteX(pitch = Pitch(step = "C", alter = 0, octave = 4), duration = 4),
NoteX(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 4),
NoteX(pitch = Pitch(step = "E", alter = 0, octave = 4), duration = 4),
NoteX(pitch = Pitch(step = "F", alter = +1, octave = 4), duration = 4),
Note(pitch = Pitch(step = "C", alter = 0, octave = 4), duration = 4),
Note(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 4),
Note(pitch = Pitch(step = "E", alter = 0, octave = 4), duration = 4),
Note(pitch = Pitch(step = "F", alter = +1, octave = 4), duration = 4),
]

measure2_notes_piano = [
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 5), duration = 1),
NoteX(pitch = Pitch(step = "G", alter = +1, octave = 5), duration = 1),
NoteX(pitch = Pitch(step = "B", alter = 0, octave = 5), duration = 1),
NoteX(pitch = Pitch(step = "A", alter = +1, octave = 5), duration = 1),
NoteX(rest = Rest(), duration = 4), # Rest
NoteX(pitch = Pitch(step = "A", alter = 0, octave = 5), duration = 4),
NoteX(pitch = Pitch(step = "B", alter = 0, octave = 5), duration = 4),
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),
]

measures_piano = [
Expand All @@ -76,30 +77,30 @@ attributes1_guitar = Attributes(

measure1_notes_guitar = [
# G Major chord for a bar
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 2), duration = 16, chord = Chord()),
NoteX(pitch = Pitch(step = "B", alter = 0, octave = 2), duration = 16, chord = Chord()),
NoteX(pitch = Pitch(step = "D", alter = 0, octave = 3), duration = 16, chord = Chord()),
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 3), duration = 16, chord = Chord()),
NoteX(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 16, chord = Chord()),
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 4), duration = 16, chord = Chord()),
Note(pitch = Pitch(step = "G", alter = 0, octave = 2), duration = 16, chord = Chord()),
Note(pitch = Pitch(step = "B", alter = 0, octave = 2), duration = 16, chord = Chord()),
Note(pitch = Pitch(step = "D", alter = 0, octave = 3), duration = 16, chord = Chord()),
Note(pitch = Pitch(step = "G", alter = 0, octave = 3), duration = 16, chord = Chord()),
Note(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 16, chord = Chord()),
Note(pitch = Pitch(step = "G", alter = 0, octave = 4), duration = 16, chord = Chord()),
]

measure2_notes_guitar = [
# G Major chord for half a bar
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 2), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "B", alter = 0, octave = 2), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "D", alter = 0, octave = 3), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 3), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 4), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "G", alter = 0, octave = 2), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "B", alter = 0, octave = 2), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "D", alter = 0, octave = 3), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "G", alter = 0, octave = 3), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "G", alter = 0, octave = 4), duration = 8, chord = Chord()),

# G Major chord for half a bar
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 2), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "B", alter = 0, octave = 2), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "D", alter = 0, octave = 3), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 3), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 4), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "G", alter = 0, octave = 2), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "B", alter = 0, octave = 2), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "D", alter = 0, octave = 3), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "G", alter = 0, octave = 3), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "G", alter = 0, octave = 4), duration = 8, chord = Chord()),
]

measures_guitar = [
Expand All @@ -116,6 +117,7 @@ partlist = partlist,
parts = [part_piano, part_guitar],
)

end # end @MX

writemusicxml("myscore.musicxml", score)
```
Expand Down Expand Up @@ -179,6 +181,11 @@ readmusicxml, parsemusicxml

## Typess:

Since MusicXML's types are not exported from the package to avoid conflicts with the similarly named types from other libraries (such as `Dates.Time`, `MIDI.Note`),
1) you should either `import` the types yourself if you are sure that there is no conflict.
2) or us `MX.` before the type names (which `MX` is an alias for `MusicXML`)
3) or use `@MX` macro, which adds `MX.` automatically to the type names. See `@MX` docstring for examples.

```
ScorePartwise
partlist (PartList)
Expand Down Expand Up @@ -218,7 +225,7 @@ ScorePartwise
chromatic
octaveChange
double
notes (Vector{NoteX})
notes (Vector{Note})
pitch (Pitch)
step
alter
Expand All @@ -235,10 +242,9 @@ For fieldnames, if it is a Vector it has `s` at the end of the word.

For types, names are capitalized for each word (Camel convention):
```
ScorePartwise, Part, Measure, NoteX, Unpitched, Rest, Pitch, Chord, Attributes, Time, Transpose, Clef, Key, PartList, ScorePart, MidiInstrument, MidiDevice, ScoreInstrument
ScorePartwise, Part, Measure, Note, Chord, Unpitched, Rest, Pitch, Attributes, Time, Transpose, Clef, Key, PartList, ScorePart, MidiInstrument, MidiDevice, ScoreInstrument
```


## Utilities
```julia
pitch2xml, xml2pitch
Expand Down
24 changes: 12 additions & 12 deletions deps/SnoopCompile/precompile/precompile_MusicXML.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
function _precompile_()
ccall(:jl_generating_output, Cint, ()) == 1 || return nothing
precompile(Tuple{typeof(findfirst),Function,Array{ScorePart,1}})
precompile(Tuple{typeof(getproperty),Measure,Symbol})
precompile(Tuple{typeof(getproperty),NoteX,Symbol})
precompile(Tuple{typeof(getproperty),PartList,Symbol})
precompile(Tuple{typeof(getproperty),ScorePartwise,Symbol})
precompile(Tuple{typeof(isnothing),Pitch})
precompile(Tuple{typeof(iterate),Array{Measure,1}})
precompile(Tuple{typeof(iterate),Array{NoteX,1}})
precompile(Tuple{typeof(iterate),Array{Part,1}})
precompile(Tuple{typeof(println),Base.PipeEndpoint,Pitch})
precompile(Tuple{typeof(println),Pitch})
precompile(Tuple{typeof(findfirst),Function,Array{MusicXML.ScorePart,1}})
precompile(Tuple{typeof(getproperty),MusicXML.Measure,Symbol})
precompile(Tuple{typeof(getproperty),MusicXML.Note,Symbol})
precompile(Tuple{typeof(getproperty),MusicXML.PartList,Symbol})
precompile(Tuple{typeof(getproperty),MusicXML.ScorePartwise,Symbol})
precompile(Tuple{typeof(isnothing),MusicXML.Pitch})
precompile(Tuple{typeof(iterate),Array{MusicXML.Measure,1}})
precompile(Tuple{typeof(iterate),Array{MusicXML.Note,1}})
precompile(Tuple{typeof(iterate),Array{MusicXML.Part,1}})
precompile(Tuple{typeof(println),Base.PipeEndpoint,MusicXML.Pitch})
precompile(Tuple{typeof(println),MusicXML.Pitch})
precompile(Tuple{typeof(readmusicxml),String})
precompile(Tuple{typeof(sizeof),Pitch})
precompile(Tuple{typeof(sizeof),MusicXML.Pitch})
end
60 changes: 31 additions & 29 deletions docs/src/creating.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Creating

```julia
@MX begin # adds `MX.` to the name of all MusicXML types
using MusicXML

## Part List
Expand All @@ -27,20 +28,20 @@ attributes1_piano = Attributes(
)

measure1_notes_piano = [
NoteX(pitch = Pitch(step = "C", alter = 0, octave = 4), duration = 4),
NoteX(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 4),
NoteX(pitch = Pitch(step = "E", alter = 0, octave = 4), duration = 4),
NoteX(pitch = Pitch(step = "F", alter = +1, octave = 4), duration = 4),
Note(pitch = Pitch(step = "C", alter = 0, octave = 4), duration = 4),
Note(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 4),
Note(pitch = Pitch(step = "E", alter = 0, octave = 4), duration = 4),
Note(pitch = Pitch(step = "F", alter = +1, octave = 4), duration = 4),
]

measure2_notes_piano = [
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 5), duration = 1),
NoteX(pitch = Pitch(step = "G", alter = +1, octave = 5), duration = 1),
NoteX(pitch = Pitch(step = "B", alter = 0, octave = 5), duration = 1),
NoteX(pitch = Pitch(step = "A", alter = +1, octave = 5), duration = 1),
NoteX(rest = Rest(), duration = 4), # Rest
NoteX(pitch = Pitch(step = "A", alter = 0, octave = 5), duration = 4),
NoteX(pitch = Pitch(step = "B", alter = 0, octave = 5), duration = 4),
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),
]

measures_piano = [
Expand All @@ -64,30 +65,30 @@ attributes1_guitar = Attributes(

measure1_notes_guitar = [
# G Major chord for a bar
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 2), duration = 16, chord = Chord()),
NoteX(pitch = Pitch(step = "B", alter = 0, octave = 2), duration = 16, chord = Chord()),
NoteX(pitch = Pitch(step = "D", alter = 0, octave = 3), duration = 16, chord = Chord()),
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 3), duration = 16, chord = Chord()),
NoteX(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 16, chord = Chord()),
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 4), duration = 16, chord = Chord()),
Note(pitch = Pitch(step = "G", alter = 0, octave = 2), duration = 16, chord = Chord()),
Note(pitch = Pitch(step = "B", alter = 0, octave = 2), duration = 16, chord = Chord()),
Note(pitch = Pitch(step = "D", alter = 0, octave = 3), duration = 16, chord = Chord()),
Note(pitch = Pitch(step = "G", alter = 0, octave = 3), duration = 16, chord = Chord()),
Note(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 16, chord = Chord()),
Note(pitch = Pitch(step = "G", alter = 0, octave = 4), duration = 16, chord = Chord()),
]

measure2_notes_guitar = [
# G Major chord for half a bar
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 2), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "B", alter = 0, octave = 2), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "D", alter = 0, octave = 3), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 3), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 4), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "G", alter = 0, octave = 2), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "B", alter = 0, octave = 2), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "D", alter = 0, octave = 3), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "G", alter = 0, octave = 3), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "G", alter = 0, octave = 4), duration = 8, chord = Chord()),

# G Major chord for half a bar
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 2), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "B", alter = 0, octave = 2), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "D", alter = 0, octave = 3), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 3), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 8, chord = Chord()),
NoteX(pitch = Pitch(step = "G", alter = 0, octave = 4), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "G", alter = 0, octave = 2), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "B", alter = 0, octave = 2), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "D", alter = 0, octave = 3), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "G", alter = 0, octave = 3), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "D", alter = 0, octave = 4), duration = 8, chord = Chord()),
Note(pitch = Pitch(step = "G", alter = 0, octave = 4), duration = 8, chord = Chord()),
]

measures_guitar = [
Expand All @@ -104,6 +105,7 @@ partlist = partlist,
parts = [part_piano, part_guitar],
)

end # end @MX

writemusicxml("myscore.musicxml", score)
```
9 changes: 7 additions & 2 deletions docs/src/types.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Types

Since MusicXML's types are not exported from the package to avoid conflicts with the similarly named types from other libraries (such as `Dates.Time`, `MIDI.Note`),
1) you should either `import` the types yourself if you are sure that there is no conflict.
2) or us `MX.` before the type names (which `MX` is an alias for `MusicXML`)
3) or use `@MX` macro, which adds `MX.` automatically to the type names. See `@MX` docstring for examples.

```
ScorePartwise
partlist (PartList)
Expand Down Expand Up @@ -39,7 +44,7 @@ ScorePartwise
chromatic
octaveChange
double
notes (Vector{NoteX})
notes (Vector{Note})
pitch (Pitch)
step
alter
Expand All @@ -56,7 +61,7 @@ For fieldnames, if it is a Vector it has `s` at the end of the word.

For types, names are capitalized for each word (Camel convention):
```
ScorePartwise, Part, Measure, NoteX, Unpitched, Rest, Pitch, Chord, Attributes, Time, Transpose, Clef, Key, PartList, ScorePart, MidiInstrument, MidiDevice, ScoreInstrument
ScorePartwise, Part, Measure, Note, Chord, Unpitched, Rest, Pitch, Attributes, Time, Transpose, Clef, Key, PartList, ScorePart, MidiInstrument, MidiDevice, ScoreInstrument
```


Expand Down
Loading

0 comments on commit 416ff98

Please sign in to comment.