Home

MusicXML

Powerful MusicXML reading and writing package for Julia.

Installation

] add https://github.com/JuliaMusic/MusicXML.jl

Usage Example

using MusicXML

# Reads musicxml file and then extracts the data, builds all the types and stores them in proper format.
doc = readmusicxml(joinpath("examples", "musescore.musicxml"))

# Example1:
# Prints Each instrument name and then the pitches

# Extracting each instrument information
scprts = doc.scorepartwise.partlist.scoreparts

# Extracting parts
prts = doc.scorepartwise.parts

# Extracting each part
for prt in prts

    ind = findfirst(x -> prt.ID == x.ID, scprts) # returns the index of scorepart that matches the ID of part

    # printing the instrument name
    println(scprts[ind].name)

    # Extracting each measure of the part
    for msr in prt.measures

        # Extracting notes of each measure
        for nt in msr.notes

            if !isnothing(nt.pitch)
            # print pitch of the note
                println(nt.pitch)
            end

        end


    end
end

Types and Functions

You can use among these exported types and functions:

I/O functions

readmusicxml, parsemusicxml

Types:

Doc, Scorepartwise, Part, Measure, Note, Unpitched, Rest, Pitch, Attributes, Time, Transpose, Clef, Key, Partlist, Scorepart, Midiinstrument, Mididevice, Scoreinstrument

Utilities

pitch2xml, xml2pitch
Attributes

Arguments

  • divisions::Int16
  • key::Key
  • time::Time
  • staves::Union{Nothing, UInt16}
  • instruments::Union{Nothing,UInt16}
  • clef::Union{Nothing,Clef}
  • transpose::Union{Nothing,Transpose}
  • xml::Node

A type to hold the data for the attributes of a musicxml measure

The attributes element contains musical information that typically changes on measure boundaries. This includes key and time signatures, clefs, transpositions, and staving. When attributes are changed mid-measure, it affects the music in score order, not in MusicXML document order.

key: See Key doc

divisions: Musical notation duration is commonly represented as fractions. The divisions element indicates how many divisions per quarter note are used to indicate a note's duration. For example, if duration = 1 and divisions = 2, this is an eighth note duration. Duration and divisions are used directly for generating sound output, so they must be chosen to take tuplets into account. Using a divisions element lets us use just one number to represent a duration for each note in the score, while retaining the full power of a fractional representation. If maximum compatibility with Standard MIDI 1.0 files is important, do not have the divisions value exceed 16383.

time: See Time doc

staves: The staves element is used if there is more than one staff represented in the given part (e.g., 2 staves for typical piano parts). If absent, a value of 1 is assumed. Staves are ordered from top to bottom in a part in numerical order, with staff 1 above staff 2.

instruments: The instruments element is only used if more than one instrument is represented in the part (e.g., oboe I and II where they play together most of the time). If absent, a value of 1 is assumed.

clef: See Clef doc

More info

source
MusicXML.ClefType.
Clef

Arguments

  • sign::String
  • line::Int16
  • xml::Node

A type to hold clef information for a measure in musicxml file.

Clefs are represented by a combination of sign, line, and clef-octave-change elements. Clefs appear at the start of each system unless the print-object attribute has been set to "no" or the additional attribute has been set to "yes".

sign: The sign element represents the clef symbol: G, F, C, percussion, TAB, jianpu, none. More info

line: Line numbers are counted from the bottom of the staff. Standard values are 2 for the G sign (treble clef), 4 for the F sign (bass clef), 3 for the C sign (alto clef) and 5 for TAB (on a 6-line staff).

More info

source
MusicXML.KeyType.
Key

Arguments

  • fifth::Int8
  • mode::Union{Nothing,String}
  • xml::Node

A type to hold key information for a measure in musicxml file.

The key element represents a key signature. Both traditional and non-traditional key signatures are supported. The optional number attribute refers to staff numbers. If absent, the key signature applies to all staves in the part.

fifth: number of flats or sharps in a traditional key signature. Negative numbers are used for flats and positive numbers for sharps, reflecting the key's placement within the circle of fifths

mode: major, minor, dorian, phrygian, lydian, mixolydian, aeolian, ionian, locrian, none

More info

source
Measure

Arguments

  • attributes::Union{Nothing,Attributes}
  • notes::Vector{Note}
  • xml::Node

A type to hold the data for a musicxml measure

attributes: See Attributes doc notes: See Note doc

source
Mididevice

Arguments

  • port::Int16
  • ID::String
  • xml::Node

The midi-device type corresponds to the DeviceName meta event in Standard MIDI Files. Unlike the DeviceName meta event, there can be multiple midi-device elements per MusicXML part starting in MusicXML 3.0.

source
Midiinstrument

Arguments

  • channel::UInt8 # 0 to 15
  • program::UInt8
  • volume::UInt8
  • pan::Int8
  • ID::String
  • xml::Node

Midiinstrument type holds information about the sound of a midi instrument.

http://www.music-software-development.com/midi-tutorial.html - Part 4

Status byte : 1100 CCCC

Data byte 1 : 0XXX XXXX

Examples

Midiinstrument(0,1,127,0)
source
MusicXML.NoteType.
Note

Arguments

  • pitch::Pitch
  • rest::Rest
  • unpitched::Unpitched
  • duration::UInt
  • TODO voice
  • type::String
  • accidental::String
  • TODO tie::Union{Nothing,Tie} # start, stop, nothing TODO
  • TODO lyric
  • xml::Node

Notes are the most common type of MusicXML data. The MusicXML format keeps the MuseData distinction between elements used for sound information and elements used for notation information (e.g., tie is used for sound, tied for notation). Thus grace notes do not have a duration element. Cue notes have a duration element, as do forward elements, but no tie elements. Having these two types of information available can make interchange considerably easier, as some programs handle one type of information much more readily than the other.

pitch: See Pitch doc

duration : See MIDI.Note doc

type: Type indicates the graphic note type, Valid values (from shortest to longest) are 1024th, 512th, 256th, 128th, 64th, 32nd, 16th, eighth, quarter, half, whole, breve, long, and maxima. The size attribute indicates full, cue, or large size, with full the default for regular notes and cue the default for cue and grace notes.

accidental: The accidental type represents actual notated accidentals. Editorial and cautionary indications are indicated by attributes. Values for these attributes are "no" if not present. Specific graphic display such as parentheses, brackets, and size are controlled by the level-display attribute group. Empty accidental objects are not allowed. If no accidental is desired, it should be omitted. sharp, flat, natural, double sharp, double flat, parenthesized accidental

tie:

More info

source
MusicXML.PartType.
Part

Arguments

  • measures::Vector{Measure}
  • ID::String
  • xml::Node

A type to hold the data for a part in musicxml file.

measures: See Measure doc

source
Partlist

Arguments

  • TODO partgroup
  • scoreparts::Vector{Scorepart}
  • xml::Node

Holds scoreparts and partgroup.

See Scorepart doc

source
MusicXML.PitchType.
Pitch

Arguments

  • step::String
  • alter::Float16
  • octave::Int8
  • xml::Node

Holds musicxml pitch data. MusicXML pitch data is represented as a combination of the step of the diatonic scale, the chromatic alteration, and the octave.

Use step, alter, octave = pitch2xml(pitch) and pitch = xml2pitch(step, alter, octave) for conversions between midi pitch and musicxml pitch

source
MusicXML.RestType.
Rest

Arguments

  • rest::Bool
  • xml::Node

The rest element indicates notated rests or silences. Rest elements are usually empty, but placement on the staff can be specified using display-step and display-octave elements. If the measure attribute is set to yes, this indicates this is a complete measure rest.

The display-step-octave group contains the sequence of elements used by both the rest and unpitched elements. This group is used to place rests and unpitched elements on the staff without implying that these elements have pitch. Positioning follows the current clef. If percussion clef is used, the display-step and display-octave elements are interpreted as if in treble clef, with a G in octave 4 on line 2. If not present, the note is placed on the middle line of the staff, generally used for a one-line staff.

source
Scoreinstrument

Arguments

  • name::String
  • ID::String
  • xml::Node

The score-instrument type represents a single instrument within a score-part. As with the score-part type, each score-instrument has a required ID attribute, a name, and an optional abbreviation. A score-instrument type is also required if the score specifies MIDI 1.0 channels, banks, or programs. An initial midi-instrument assignment can also be made here. MusicXML software should be able to automatically assign reasonable channels and instruments without these elements in simple cases, such as where part names match General MIDI instrument names.

source
Scorepart

Arguments

  • name::String
  • scoreinstrument::Scoreinstrument
  • mididevice::Mididevice
  • midiinstrument::Midiinstrument
  • ID::String
  • xml::Node

Holds information about one Scorepart in a score

Each MusicXML part corresponds to a track in a Standard MIDI Format 1 file. The score-instrument elements are used when there are multiple instruments per track. The midi-device element is used to make a MIDI device or port assignment for the given track or specific MIDI instruments. Initial midi-instrument assignments may be made here as well.

scoreinstrument: See Scoreinstrument doc mididevice: See Mididevice doc midiinstrument: See Midiinstrument doc

More info

Examples

Scorepart(name = "Violin",midiinstrument = midiinstrument(0,1,127,0), ID = "P1")
source
scorePartwise

Arguments

  • TODO identification
  • TODO defaults
  • partlist::Partlist
  • parts::Vector{Part}
  • xml::Node

A type to hold the data for a musicxml file.

source
MusicXML.TimeType.
Time

Arguments

  • signature::Array{Int8,1}
  • xml::Node

Time signatures are represented by the beats element for the numerator and the beat-type element for the denominator.

source
Transpose

Arguments

  • diatonic::Int8
  • chromatic::Int8
  • octaveChange::Union{Nothing,Int8}
  • double::Union{Nothing,Bool}
  • xml::Node

A type to hold transpose information for a measure in musicxml file.

If the part is being encoded for a transposing instrument in written vs. concert pitch, the transposition must be encoded in the transpose element using the transpose type.

diatonic: The diatonic element specifies the number of pitch steps needed to go from written to sounding pitch. This allows for correct spelling of enharmonic transpositions.

chromatic: The chromatic element represents the number of semitones needed to get from written to sounding pitch. This value does not include octave-change values; the values for both elements need to be added to the written pitch to get the correct sounding pitc

octaveChange: The octave-change element indicates how many octaves to add to get from written pitch to sounding pitch.

double: If the double element is present, it indicates that the music is doubled one octave down from what is currently written (as is the case for mixed cello / bass parts in orchestral literature).

More info

source
Unpitched

Arguments

  • unpitched::Bool
  • xml::Node

The unpitched type represents musical elements that are notated on the staff but lack definite pitch, such as unpitched percussion and speaking voice.

source
parsemusicxml(s)

Parses musicxml from a string and then extracts the data, builds all the types and stores them in proper format.

Examples

data = parsemusicxml(s)
source
MusicXML.pitch2xmlMethod.
pitch2xml(pitch)

Return the musicxmls values of the given pitch

Modified from MIDI.jl

Examples:

pitch = xml2pitch(step, alter, octave)
source
readmusicxml(filepath)

Reads musicxml file and then extracts the data, builds all the types and stores them in proper format.

Examples

data = readmusicxml(joinpath("examples", "musescore.musicxml"))
source
MusicXML.xml2pitchMethod.
xml2pitch(step, alter, octave) -> Int

Return the pitch value of the given note

Modified from MIDI.jl

Examples:

step, alter, octave = pitch2xml(pitch)
source
extractdata(doc)

Extracts musicxml data, builds all the types and stores them in proper format.

This function is not exported. Use readmusicxml and parsemusicxml instead.

Examples

data = extractdata(doc)
source