musif.musicxml package

Submodules

musif.musicxml.common module

musif.musicxml.common.fix_repeats(score: music21.stream.base.Score)[source]

Fix the repeat sign in the score by ensuring that all the parts have the same signs

musif.musicxml.common.get_notes_and_measures(part: music21.stream.base.Part) Tuple[List[music21.note.Note], List[music21.note.Note], List[music21.stream.base.Measure], List[music21.stream.base.Measure]][source]

Obtains lists of notes, tied notes, measures, measures that containg notes, and notes and rests. Information that is useful in the subsequent process of extraction.

Parameters:

part (Part) – Music21 part to extract the info from.

musif.musicxml.common.is_voice(part: music21.stream.base.Part) bool[source]

Returns True if the part is a singer part, otherwise returns False

Parameters:

part (Part) – Music21 part to check if it’s a singer part

musif.musicxml.common.name_parts(score: music21.stream.base.Score)[source]

This function assign a name to each part in the score. If a name is already present, we keep it there, otherwise, we create a name of type missingName# where # is an incremental number,

musif.musicxml.common.split_layers(score: music21.stream.base.Score, split_keywords: List[str])[source]

Function used to split possible layers. Those instruments that include to parts in the same staff will be separated in two diferent parts so they can be treated separately.

Parameters:
  • score (Score) – Music21 score to scan and separate parts in it according to split_keywords list

  • split_keywords (List[str]) – List containing key words of instruments susceptible to be splitted. i.e. [oboe, viola]

musif.musicxml.constants module

musif.musicxml.constants.FAMILY_TO_ABBREVIATION = {'brass': 'br', 'general': 'gen', 'percussion': 'perc', 'strings': 'str', 'voice': 'voice', 'wind': 'ww', 'woodwinds': 'ww'}

Dictionary containing abbreviation of each family

musif.musicxml.constants.SCORING_FAMILY_ORDER = ['ww', 'br', 'perc', 'pluc', 'voice', 'str']

better documentation here!

Type:

List of families in the order we want them TODO

musif.musicxml.constants.SCORING_ORDER = ['fl', 'ob', 'eh', 'cl', 'bn', 'hn', 'tpt', 'tb', 'clno', 'timp', 'tamb', 'triang', 'mand', 'salt', 'vv', 'cv', 'eq', 'fch', 'sop', 'alt', 'ten', 'bar', 'bbar', 'bas', 'vn', 'va', 'viol', 'vc', 'bs']

better documentation here!

Type:

List of sounds/instruments in the order we want them TODO

musif.musicxml.constants.SOUND_TO_ABBREVIATION = {'a pistoni': 'crt', 'accordion': 'acc', 'alto': 'alt', 'alto flute': 'afl', 'archi': 'str', 'armonica a bocco': 'hca', 'armonium': 'harm', 'arpa': 'hp', 'arpeggione': 'arp', 'bagpipe': 'bag', 'banjo': 'bjo', 'baritone': 'bar', 'baritone oboe': 'bob', 'baritono': 'bryt', 'baryton': 'bryt', 'bass': 'bass', 'bass baritone': 'bbar', 'bass clarinet': 'bcl', 'bass flute': 'bfl', 'bass guitar': 'bgtr', 'bass oboe': 'bob', 'basset clarinet': 'bstcl', 'basset horn': 'bsthn', 'basso continuo': 'bs', 'bassoon': 'bn', 'bell': 'bell', 'bells': 'bell', 'bicchieri de vetro': 'ghca', 'bowl organ': 'ghca', 'brass instruments': 'br', 'bugle': 'bug', 'campanelli': 'gl', 'celesta': 'cel', 'cello': 'vc', 'cembalo': 'hpd', 'cetara': 'cit', 'cetra': 'cit', 'cetra da tavola': 'zith', 'chalumeau': 'cm', "child's voice": 'cv', "children's chorus": 'cch', 'chimes': 'bell', 'chitarra': 'gtr', 'chitarra elettrica': 'egtr', 'ciaramella': 'shw', 'cimbalom': 'cimb', 'cittern': 'cit', 'clarinet': 'cl', 'clarinetti': 'cl', 'clarinetto': 'cl', 'clarinetto contrabbasso': 'cbcl', 'clarinetto di bassetto': 'bstcl', 'clarino': 'tpt', 'clavicembalo': 'hpd', 'clavichord': 'clvd', 'clavicordo': 'clvd', 'concertina': 'conc', 'continuo': 'bs', 'continuous bass': 'bs', 'contrabass clarinet': 'cbcl', 'contrabasso': 'db', 'contrabassoon': 'cbn', 'contrafagotto': 'cbn', 'contralto': 'alt', 'cor anglais': 'eh', 'corna de segnale': 'bug', 'cornet': 'crt', 'cornett': 'crtt', 'cornetta': 'crt', 'cornetto': 'crtt', 'corno': 'hn', 'corno di bassetto': 'bsthn', 'corno inglese': 'eh', 'coro di fanciulli': 'cch', 'coro femminile': 'fch', 'coro maschile': 'mch', 'coro miste': 'ch', 'coro unisono': 'uch', 'cromorno': 'crh', 'crumhorn': 'crh', 'domra': 'dom', 'double bass': 'db', 'dulcian': 'dlcn', 'dulciana': 'dlcn', 'dulcimer': 'dulc', 'electric bass': 'bgtr', 'electric guitar': 'egtr', 'electric piano': 'epf', 'electronic instruments': 'elec', 'english horn': 'eh', 'equal voices': 'eq', 'erhu': 'erhu', 'eufonio': 'euph', 'euphonium': 'euph', 'fagoto': 'bn', 'female chorus': 'fch', 'fife': 'fife', 'fiffaro': 'fife', 'flageolet': 'flag', 'flagioletto': 'flag', 'flauto': 'fl', 'flauto a becco': 'rec', 'flauto di pan': 'pan', 'flauto dolce': 'rec', 'flauto piccolo': 'picc', 'flauto tenor': 'fda', 'flicorni': 'sxh', 'flicorno soprano': 'fgh', 'flugelhorn': 'fgh', 'flute': 'fl', "flute d'amore": 'fda', 'gamba': 'viol', 'ghironda': 'vie', 'glass harmonica': 'ghca', 'glassarmonica': 'ghca', 'glockenspiel': 'gl', 'guitar': 'gtr', 'harmonica': 'hca', 'harmonium': 'harm', 'harp': 'hp', 'harpsichord': 'hpd', 'heckelfono': 'heck', 'heckelphone': 'heck', 'horn': 'hn', 'hurdy-gurdy': 'vie', 'keyboard instrument': 'kbd', 'lira': 'lyre', 'liuto': 'lute', 'lute': 'lute', 'lyra tedesca': 'vie', 'lyre': 'lyre', 'male chorus': 'mch', 'mandolin': 'mand', 'mandolino': 'mand', 'marimba': 'mar', 'metallofono': 'gl', 'mezzo-soprano': 'mez', 'mezzosoprano': 'mez', 'mixed chorus': 'ch', 'mouth organ': 'hca', 'multiple soloists': 'vv', 'musette': 'mus', 'musette de cour': 'mus', 'narrator': 'nar', 'narratore': 'nar', 'oboe': 'ob', 'oboe baritono': 'bob', "oboe d'amore": 'oda', 'ocarina': 'oca', 'onde martenot': 'om', 'ondes martenot': 'om', 'ophicleide': 'oph', 'orchestra': 'orch', 'organ': 'org', 'organo': 'org', 'ottavino': 'picc', 'oud': 'oud', 'pan flute': 'pan', 'pan-pipes': 'pan', 'pedal piano': 'pfped', 'percussion': 'perc', 'piano': 'pf', 'piano 3 hands': 'pf3h', 'piano 4 hands': 'pf4h', 'piano 5 hands': 'pf5h', 'piano 6 hands': 'pf6h', 'piano di destra': 'pfrh', 'piano di sinistra': 'pflh', 'piano left hand': 'pflh', 'piano right hand': 'pfrh', 'pianoforte': 'pf', 'pianoforte 3 mani': 'pf3h', 'pianoforte 4 mani': 'pf4h', 'pianoforte 5 mani': 'pf5h', 'pianoforte 6 mani': 'pf6h', 'pianoforte elettrico': 'epf', 'pianoforte organistico': 'pfped', 'piccolo': 'picc', 'piccolo trumpet': 'ptpt', 'piffaro': 'shw', 'pipa': 'pipa', 'rebec': 'reb', 'rebeca': 'reb', 'reciter': 'nar', 'recorder': 'rec', 'ribeca': 'reb', 'sackbut': 'skbt', 'salmoè': 'cm', 'salterio': 'dulc', 'sarrusofono': 'sar', 'sarrusophone': 'sar', 'sassofono': 'sax', 'saxhorn': 'sxh', 'saxofono': 'sax', 'saxophone': 'sax', 'serpent': 'srp', 'serpentone': 'srp', 'shawm': 'shw', 'sheng': 'sheng', 'silofono': 'xyl', 'sintetizzatore': 'syn', 'siringa': 'pan', 'sitar': 'sit', 'slide trumpet': 'stpt', 'solo': 'v', 'soprano': 'sop', 'string instruments': 'str', 'strumento a fiato di legno': 'ww', 'strumento a fiato di ottone': 'br', 'strumento a percussione': 'perc', 'strumento a tastiera': 'kbd', 'strumento elettrica': 'elec', 'synthesizer': 'syn', 'tenor': 'ten', 'tenor flute': 'fda', 'tenore': 'ten', 'theremin': 'thrm', 'timpani': 'timp', 'tromba': 'tpt', 'tromba a tirarsi': 'stpt', 'trombino': 'ptpt', 'trombone': 'tbn', 'trumpet': 'tpt', 'tuba': 'tba', 'tuba di wagner': 'wag', 'ukelele': 'uke', 'ukulele': 'uke', 'unison chorus': 'uch', 'vibrafono': 'vib', 'vibraphone': 'vib', 'vielle': 'vie', 'viol': 'viol', 'viola': 'va', "viola d'amore": 'vda', 'viola da gamba': 'viol', 'viola pomposa': 'vap', 'violin': 'vn', 'violino': 'vn', 'violoncello': 'vc', 'violone': 'vlne', 'voce': 'v', 'voce di fanciullo': 'cv', 'voci': 'vv', 'voci pari': 'eq', 'voice': 'v', 'voices': 'vv', 'vuvuzela': 'vuv', 'wagner tuba': 'wag', 'woodwind instruments': 'ww', 'xiao': 'xiao', 'xilofono': 'xyl', 'xylophone': 'xyl', 'zink': 'crtt', 'zither': 'zith'}

Dictionary connecting each instrument name in a musicxml to an abbreviation

musif.musicxml.constants.SOUND_TO_FAMILY = {'': 'keyboard', '5th voice': 'voice', '6th voice': 'voice', 'a high trumpet': 'brass', 'a ob': 'woodwinds', 'a small trumpet or tenor trombone': 'brass', 'additions to any wind instrument to indicate a tuning other than standard tuning': 'general', 'also for unspecified bass instrument': 'brass', 'althorn': 'brass', 'alto': 'voice', 'alto saxophone': 'woodwinds', 'alto trombone': 'brass', 'alto viola': 'strings', 'an unspecified or unknown chorus part': 'voice', 'antique cymbals': 'percussion', 'archlute': 'plucked', 'b ob': 'woodwinds', 'baritone': 'voice', 'baritone horn': 'brass', 'baritone saxophone': 'woodwinds', 'baritone trombone': 'brass', 'barrel organ': 'keyboard', 'baryton': 'strings', 'bass': 'voice', 'bass clarinet': 'woodwinds', 'bass drum': 'percussion', 'bass electric guitar': 'plucked', 'bass horn': 'brass', 'bass trombone': 'brass', 'bass tuba': 'brass', 'bass viola da gamba': 'strings', "basse d'harmonie": 'brass', 'basset horn': 'woodwinds', 'basso continuo': 'strings', 'bassoon': 'woodwinds', 'bell': 'percussion', 'bell lyre': 'percussion', 'bells': 'percussion', 'birds singing': 'percussion', 'bombarde': 'woodwinds', 'bombardino': 'brass', 'bombardon': 'brass', "boys' choir": 'voice', 'brass instruments': 'general', 'bugle': 'brass', 'cantus': 'voice', 'carillon': 'percussion', 'castanets': 'percussion', 'celesta': 'keyboard', 'cello': 'strings', 'cembalo': 'keyboard', 'chalumeau': 'woodwinds', "children's choir": 'voice', 'chimes': 'percussion', 'chinese cymbal': 'percussion', 'chirimía': 'woodwinds', 'choir': 'voice', 'chorus': 'voice', 'cimbalom': 'percussion', 'cimbasso': 'brass', 'cl in a \t\t\tcor in e|b': 'general', 'clairon': 'brass', 'clarinet': 'woodwinds', 'clarinet in a': 'woodwinds', 'clarinet in c': 'woodwinds', 'clarino': 'brass', 'clarion': 'brass', 'clavecin': 'keyboard', 'claves': 'percussion', 'clavicembalo': 'keyboard', 'clavichord': 'keyboard', 'conga drums': 'percussion', 'congas': 'percussion', 'continuous solo instrument in a work': 'general', 'contrabass': 'strings', 'contrabassoon': 'woodwinds', 'contralto': 'voice', 'cor anglais': 'woodwinds', 'cornet': 'brass', 'cornett': 'brass', 'cornettino': 'brass', 'cornetto': 'brass', 'corno da caccia': 'brass', 'cuckoo': 'percussion', 'cymbal': 'percussion', 'dessus': 'voice', 'discant': 'voice', 'discantus': 'voice', 'double bass': 'strings', 'double bassoon': 'woodwinds', 'drum': 'percussion', 'drum with snares off': 'percussion', 'drums': 'percussion', 'dugetto': 'brass', 'dulcimer': 'percussion', 'electric': 'electric', 'electric guitar': 'plucked', 'english': 'general', 'english horn': 'woodwinds', 'etc. four hands': 'keyboard', 'euphonium': 'brass', 'examples': 'general', 'e|b clarinet': 'woodwinds', 'e|b horn': 'brass', 'fanfare trumpet': 'brass', 'fiddle': 'strings', 'fife': 'woodwinds', 'finger cymbals': 'percussion', 'flautino': 'woodwinds', 'flauto dolce': 'woodwinds', 'flauto quarto': 'woodwinds', 'flicorno': 'brass', 'flugelhorn': 'brass', 'flute': 'woodwinds', 'flute in e|b': 'woodwinds', "flûte d'amour": 'woodwinds', 'french horn': 'brass', "girls' choir": 'voice', 'glass harmonica': 'percussion', 'glock': 'percussion', 'gong': 'percussion', 'guitar': 'plucked', 'handbell': 'percussion', 'harmonium': 'keyboard', 'harp': 'plucked', 'harpsichord': 'keyboard', 'heckelphone': 'woodwinds', 'helicon': 'brass', 'highest voice': 'voice', 'horn': 'brass', 'keyed bugle': 'brass', 'keyed trumpet': 'brass', 'lituus': 'brass', 'lute': 'plucked', 'lyre': 'plucked', 'mandolin': 'plucked', 'maracas': 'percussion', 'marimba': 'percussion', 'mellophone': 'brass', "mens' choir": 'voice', 'mezzo soprano': 'voice', 'musical clock': 'percussion', 'musical glasses': 'percussion', 'nightingale': 'percussion', 'oboe': 'woodwinds', "oboe d'amore": 'woodwinds', 'oboe da caccia': 'woodwinds', 'oboe di silva': 'woodwinds', 'oboe grande': 'woodwinds', 'ocarina': 'woodwinds', 'ophicleide': 'brass', 'orchestra': 'general', 'organ': 'keyboard', 'organ four hands': 'keyboard', 'organo a rullo': 'keyboard', 'ottavino': 'woodwinds', 'parade drum': 'percussion', 'percussion': 'percussion', 'physharmonica': 'keyboard', 'piano': 'keyboard', 'piano four hands': 'keyboard', 'piccolo': 'woodwinds', 'piccolo oboe': 'woodwinds', 'piston': 'brass', 'plucked instrument': 'plucked', 'pommer': 'woodwinds', 'post horn': 'brass', 'principale': 'brass', 'psaltery': 'plucked', 'quinta vox': 'voice', 'ratchet': 'percussion', 'rattle': 'percussion', 'recorder': 'woodwinds', 'requinto': 'plucked', 'rotary valve cornet': 'brass', 'saxhorn': 'brass', 'saxophone': 'woodwinds', 'serpent': 'brass', 'sexta vox': 'voice', 'shawm': 'woodwinds', 'sleigh bells': 'percussion', 'small bell': 'percussion', 'snare drum': 'percussion', 'solo violin part': 'strings', 'solo vocal part': 'voice', 'sopranino recorder': 'woodwinds', 'soprano': 'voice', 'soprano saxophone': 'woodwinds', 'spinet': 'keyboard', 'spoken voice': 'voice', 'spoons': 'percussion', 'string drum': 'percussion', 'strings': 'general', 'suspended cymbal': 'percussion', 'tabor': 'percussion', 'taille de hautbois': 'woodwinds', 'tam tam': 'percussion', 'tambourine': 'percussion', 'tenor': 'voice', 'tenor bassoon': 'woodwinds', 'tenor drum': 'percussion', 'tenor horn': 'brass', 'tenor oboe': 'woodwinds', 'tenor saxophone': 'woodwinds', 'tenor trombone': 'brass', 'tenor viola da gamba': 'strings', 'tenoron': 'woodwinds', 'the alto part in a chorus': 'voice', 'the bass part in a chorus': 'voice', 'the soprano part in a chorus': 'voice', 'the tenor part in a chorus': 'voice', 'theorbo': 'plucked', 'thoroughbass': 'strings', 'timbales': 'percussion', 'timpani': 'percussion', 'tiple': 'voice', 'tom tom': 'percussion', 'transverse flute': 'woodwinds', 'treble viola da gamba': 'strings', 'triangle': 'percussion', 'trombone': 'brass', 'trumpet': 'brass', 'tuba': 'brass', 'turkish drum': 'percussion', 'usually brass': 'brass', 'vagans': 'voice', 'valve horn': 'brass', 'valve trombone': 'brass', 'valve trumpet': 'brass', 'vibraphone': 'percussion', 'viola': 'strings', 'viola basso': 'strings', 'viola bastarda': 'strings', "viola d'amore": 'strings', 'viola da braccio': 'strings', 'viola da gamba': 'strings', 'viola pomposa': 'strings', 'violetta': 'strings', 'violetta marina': 'strings', 'violin': 'strings', 'violin concertino': 'strings', 'violin principale': 'strings', 'violin ripieno': 'strings', 'violoncello': 'strings', 'violone': 'strings', 'virginal': 'keyboard', 'voice': 'voice', 'vox humana': 'woodwinds', 'wind band': 'brass', 'winds': 'general', "womens' choir": 'voice', 'woodwinds': 'woodwinds', 'xylophone': 'percussion', 'zink': 'brass', 'zither': 'plucked', 'zufoletto': 'woodwinds'}

Dictionary containing the family of each instrument (sound)

musif.musicxml.key module

musif.musicxml.key.get_key_and_mode(score: music21.stream.base.Score) Tuple[music21.key.Key, str, str][source]

Returns abbreviated designation of keys (uppercase for major mode; lowercase for minor mode)

Example

if key == ‘D- major’: return ‘Db’

Parameters:

score

musif.musicxml.key.get_key_signature_type(key_signature: str) str[source]

Returns the key signature type (‘bb) for flats, ‘ss’ for sharps, and ‘nn’ for naturals

Parameters:

key_signature (str) – Music21 key to take the info from

musif.musicxml.key.get_name_from_key(score_key: music21.key.Key) Tuple[str, str][source]

Returns abbreviated designation of keys (uppercase for major mode; lowercase for minor mode)

Example

if key == ‘D- major’: return ‘Db’

Parameters:

score (Score) – Music21 score to take the info from

musif.musicxml.repeat module

musif.musicxml.scoring module

musif.musicxml.scoring.extract_sound(part: music21.stream.base.Part, config: ExtractConfiguration) str[source]

Returns sound name for a specific part based on the sound name Part: VnI -> Sound name: Vn :param part: Part to get abbreviaton from :type part: str :param cfg: ExtractConfiguration object :type cfg: ExtractConfiguration

musif.musicxml.scoring.to_abbreviation(part: music21.stream.base.Part, parts: List[music21.stream.base.Part], cfg: ExtractConfiguration) str[source]

Returns abbreviation name for a specific part based on the sound name

Parameters:
  • part (str) – Part to get abbreviaton from

  • parts (List[part]) – List of parts in the score

  • cfg (ExtractConfiguration) – ExtractConfiguration object

musif.musicxml.tempo module

class musif.musicxml.tempo.TempoGroup2(value)[source]

Bases: Enum

Contains constants refering to grouped tempo on the second level that will be used by the tempo module.

FAST = 'Fast'
MODERATE = 'Moderate'
NA = 'NA'
SLOW = 'Slow'
musif.musicxml.tempo.extract_numeric_tempo(file_path: str) int | None[source]

Finds the numeric tempo in a musixml file by looking at the tempo marking in the xml code.

Parameters:
  • file_path (str)

  • from. (Path to xml file to get the tempo)

musif.musicxml.tempo.get_number_of_beats(time_signature: str) int[source]

Returns the number of beats corresponding to a time signature.

By default, this returns the numerator, with the exceptions when the numerator is 6, 9, or 12 and when the time signature is C or 3/8. If it is empty, it returns 1. If it is “NA”, it returns pd.NA.

Parameters:

time_signature (str) – Time signature in the form of string separated by ‘/’ to obtain the time signature type.

musif.musicxml.tempo.get_tempo_grouped_1(tempo: str) str[source]

Returns a 1st level of grouping for the tempo markings, removing secondary labels and diminutive endings.

Parameters:
  • tempo (str)

  • from. (Tempo string in italian to be extract the group)

musif.musicxml.tempo.get_tempo_grouped_2(tempo_grouped_1: str) str[source]

Returns a 2nd level of grouping for the tempo markings.

Parameters:
  • tempo_grouped_1 (str)

  • get_tempo_grouped_1 (Tempo string got from)

musif.musicxml.tempo.get_time_signature_type(time_signature: str) str[source]

Given a time signature, it returns the correspondent type.

Parameters:
  • time_signature (str)

  • type. (Time signature in the form of string separated by '/' to obtain the time signature)