Track Class
The muspy.Track class is a container for music tracks. In MusPy, each track contains only one instrument.
Attributes |
Description |
Type |
Default |
|---|---|---|---|
program |
MIDI program number |
int (0-127) |
0 |
is_drum |
If it is a drum track |
bool |
False |
name |
Track name |
str |
|
notes |
Musical notes |
list of |
[] |
chords |
Chords |
list of |
[] |
lyrics |
Lyrics |
list of |
[] |
annotations |
Annotations |
list of |
[] |
(MIDI program number is based on General MIDI specification; see here.)
- class muspy.Track(program=0, is_drum=False, name=None, notes=None, chords=None, lyrics=None, annotations=None)[source]
A container for music track.
- program
Program number, according to General MIDI specification [1]. Valid values are 0 to 127.
- Type:
int, default: 0 (Acoustic Grand Piano)
- is_drum
Whether it is a percussion track.
- Type:
bool, default: False
- name
Track name.
- Type:
str, optional
- notes
Musical notes.
- Type:
list of
muspy.Note, default: []
- chords
Chords.
- Type:
list of
muspy.Chord, default: []
- annotations
Annotations.
- Type:
list of
muspy.Annotation, default: []
- lyrics
Lyrics.
- Type:
list of
muspy.Lyric, default: []
Note
Indexing a Track object returns the note at a certain index. That is,
track[idx]returnstrack.notes[idx]. Length of a Track object is the number of notes. That is,len(track)returnslen(track.notes).References
- adjust_time(func, attr=None, recursive=True)
Adjust the timing of time-stamped objects.
- append(obj)
Append an object to the corresponding list.
This will automatically determine the list attributes to append based on the type of the object.
- Parameters:
obj – Object to append.
- copy()
Return a shallow copy of the object.
This is equivalent to
copy.copy(self)().- Return type:
Shallow copy of the object.
- deepcopy()
Return a deep copy of the object.
This is equivalent to
copy.deepcopy(self)()- Return type:
Deep copy of the object.
- extend(other, deepcopy=False)
Extend the list(s) with another object or iterable.
- Parameters:
other (
muspy.ComplexBaseor iterable) – If an object of the same type is given, extend the list attributes with the corresponding list attributes of the other object. If an iterable is given, callmuspy.ComplexBase.append()for each item.deepcopy (bool, default: False) – Whether to make deep copies of the appended objects.
- Return type:
Object itself.
- fix_type(attr=None, recursive=True)
Fix the types of attributes.
- classmethod from_dict(dict_, strict=False, cast=False)
Return an instance constructed from a dictionary.
Instantiate an object whose attributes and the corresponding values are given as a dictionary.
- Parameters:
- Return type:
Constructed object.
- is_valid(attr=None, recursive=True)
Return True if an attribute has a valid type and value.
This will recursively apply to an attribute’s attributes.
- Parameters:
- Returns:
Whether the attribute has a valid type and value.
- Return type:
See also
muspy.Base.validate()Raise an error if an attribute has an invalid type or value.
muspy.Base.is_valid_type()Return True if an attribute is of a valid type.
- is_valid_type(attr=None, recursive=True)
Return True if an attribute is of a valid type.
This will apply recursively to an attribute’s attributes.
- Parameters:
- Returns:
Whether the attribute is of a valid type.
- Return type:
See also
muspy.Base.validate_type()Raise an error if a certain attribute is of an invalid type.
muspy.Base.is_valid()Return True if an attribute has a valid type and value.
- pretty_str(skip_missing=True)
Return the attributes as a string in a YAML-like format.
- Parameters:
skip_missing (bool, default: True) – Whether to skip attributes with value None or those that are empty lists.
- Returns:
Stored data as a string in a YAML-like format.
- Return type:
See also
muspy.Base.print()Print the attributes in a YAML-like format.
- print(skip_missing=True)
Print the attributes in a YAML-like format.
- Parameters:
skip_missing (bool, default: True) – Whether to skip attributes with value None or those that are empty lists.
See also
muspy.Base.pretty_str()Return the the attributes as a string in a YAML-like format.
- remove_duplicate(attr=None, recursive=True)
Remove duplicate items from a list attribute.
- remove_invalid(attr=None, recursive=True)
Remove invalid items from a list attribute.
- sort(attr=None, recursive=True)
Sort a list attribute.
- to_ordered_dict(skip_missing=True, deepcopy=True)
Return the object as an OrderedDict.
Return an ordered dictionary that stores the attributes and their values as key-value pairs.
- Parameters:
- Returns:
A dictionary that stores the attributes and their values as key-value pairs, e.g., {“attr1”: value1, “attr2”: value2}.
- Return type:
OrderedDict
- validate(attr=None, recursive=True)
Raise an error if an attribute has an invalid type or value.
This will apply recursively to an attribute’s attributes.
- Parameters:
- Return type:
Object itself.
See also
muspy.Base.is_valid()Return True if an attribute has a valid type and value.
muspy.Base.validate_type()Raise an error if an attribute is of an invalid type.
- validate_type(attr=None, recursive=True)
Raise an error if an attribute is of an invalid type.
This will apply recursively to an attribute’s attributes.
- Parameters:
- Return type:
Object itself.
See also
muspy.Base.is_valid_type()Return True if an attribute is of a valid type.
muspy.Base.validate()Raise an error if an attribute has an invalid type or value.
- get_end_time(is_sorted=False)[source]
Return the time of the last event.
This includes notes, chords, lyrics and annotations.
- Parameters:
is_sorted (bool, default: False) – Whether all the list attributes are sorted.
- clip(lower=0, upper=127)[source]
Clip the velocity of each note.