Note Class¶
The muspy.Note
class is a container for musical notes.
Attributes | Description | Type | Default |
---|---|---|---|
time | Start time | int | |
duration | Note duration, in time steps | int | |
pitch | Note pitch as a MIDI note number | int (0-127) | |
velocity | Note velocity | int (0-127) |
Hint
muspy.Note
has a property end with setter and getter implemented, which can be handy sometimes.
-
class
muspy.
Note
(time: int, pitch: int, duration: int, velocity: Optional[int] = None, pitch_str: Optional[str] = None)[source] A container for note.
-
adjust_time
(func: Callable[[int], int], attr: Optional[str] = None, recursive: bool = True) → muspy.classes.Note[source] Adjust the timing of the note.
Parameters: Returns: Return type: Object itself.
-
clip
(lower: int = 0, upper: int = 127) → muspy.classes.Note[source] Clip the velocity of the note.
Parameters: Returns: Return type: Object itself.
-
copy
() → BaseType Return a shallow copy of the object.
This is equivalent to
copy.copy(self)()
.Returns: Return type: Shallow copy of the object.
-
deepcopy
() → BaseType Return a deep copy of the object.
This is equivalent to
copy.deepcopy(self)()
Returns: Return type: Deep copy of the object.
-
end
End time of the note.
-
classmethod
from_dict
(dict_: Mapping[KT, VT_co]) → BaseType Return an instance constructed from a dictionary.
Instantiate an object whose attributes and the corresponding values are given as a dictionary.
Parameters: dict (dict or mapping) – A dictionary that stores the attributes and their values as key-value pairs, e.g., {“attr1”: value1, “attr2”: value2}. Returns: Return type: Constructed object.
-
is_valid
(attr: Optional[str] = None, recursive: bool = True) → bool 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: Optional[str] = None, recursive: bool = True) → bool Return True if an attribute is of a valid type.
This will apply recursively to an attribute’s attributes.
Parameters: Returns: - bool – Whether the attribute is of a valid type.
- recursive (bool) – Whether to apply recursively. Defaults to True.
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: bool = True) → str Return the attributes as a string in a YAML-like format.
Parameters: skip_missing (bool) – Whether to skip attributes with value None or those that are empty lists. Defaults to True. Returns: Stored data as a string in a YAML-like format. Return type: str See also
muspy.Base.print()
- Print the attributes in a YAML-like format.
-
print
(skip_missing: bool = True) Print the attributes in a YAML-like format.
Parameters: skip_missing (bool) – Whether to skip attributes with value None or those that are empty lists. Defaults to True. See also
muspy.Base.pretty_str()
- Return the the attributes as a string in a YAML-like format.
-
start
Start time of the note.
-
to_ordered_dict
(skip_missing: bool = True, deepcopy: bool = True) → collections.OrderedDict 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
-
transpose
(semitone: int) → muspy.classes.Note[source] Transpose the note by a number of semitones.
Parameters: semitone (int) – Number of semitones to transpose the note. A positive value raises the pitch, while a negative value lowers the pitch. Returns: Return type: Object itself.
-
validate
(attr: Optional[str] = None, recursive: bool = True) → BaseType Raise an error if an attribute has an invalid type or value.
This will apply recursively to an attribute’s attributes.
Parameters: Returns: 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: Optional[str] = None, recursive: bool = True) → BaseType Raise an error if an attribute is of an invalid type.
This will apply recursively to an attribute’s attributes.
Parameters: Returns: 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.
-