musicscore.midi
- class musicscore.midi.Midi(value: float | int, accidental: Accidental | None = None, *args, **kwargs)[source]
Bases:
MusicTreeParent type:
NoteChild type:
AccidentalMidi is the representation of a Pitch with its midi value, and accidental sign. This object is used to create a Chord consisting of one or more pitches. The midi representation of a rest is a Midi object with value 0.
- add_child(child: [<class 'musicscore.accidental.Accidental'>]) Accidental[source]
child’s _update method will be called after adding.
- Parameters:
child –
- Returns:
child
- Return type:
- add_tie(type: str) None[source]
A
XMLTiechild of typestartorstopwill be added toparent_noteobject- Parameters:
type –
start,stop- Exception:
ValueError
- get_beat(*args, **kwargs) Beat
MusicTreemethodThis method can be used for
ScoreandPart,MeasureandStaffandVoice- Parameters:
- Return type:
- get_beats() List[Beat]
MusicTreemethodThis method can be used for
ScoreandPart,Measure,StaffandVoice.- Returns:
a flat list of all beats.
- Return type:
List[
Beat]
- get_children_of_type(type) List[Tree]
Treemethod- Returns:
list of added children of type.
- Return type:
List[
Tree]
- get_chord(*args, **kwargs) Chord
MusicTreemethodThis method can be used for
ScoreandPart,Measure,Staff,VoiceandBeat- Parameters:
args – can be used instead of
kwargs. A mixture of args and kwargs is not allowed.kwargs –
part_number,measure_number,staff_number,voice_number,beat_number,chord_numberdepending on musicscore’s class. AStafffor example needsvoice_number,beat_numberandchord_numberwhile aScoreneeds all keyword arguments.
- Return type:
- get_chords() List[Chord]
MusicTreemethodThis method can be used for
ScoreandPart,MeasureandStaff,VoiceandBeat- Returns:
a flat list of all chords.
- Return type:
List[
Chord]
- get_coordinates_in_tree() str
Treemethod- Returns:
0 for
root. 1, 2, … for layer 1. Other layers: x.y.z…. Example: 3.2.2 => third child of secod child of second child of the root.- Return type:
str
>>> class TestTree(Tree): ... def _check_child_to_be_added(self, child): ... return True >>> root = TestTree() >>> root.get_coordinates_in_tree() '0' >>> child1 = root.add_child(TestTree()) >>> child2 = root.add_child(TestTree()) >>> grandchild1 = child2.add_child(TestTree()) >>> grandchild2 = child2.add_child(TestTree()) >>> child1.get_coordinates_in_tree() '1' >>> child2.get_coordinates_in_tree() '2' >>> grandchild1.get_coordinates_in_tree() '2.1' >>> grandchild2.get_coordinates_in_tree() '2.2'
- get_indentation() str
Treemethod- Returns:
indentation according to
level(layer number). As default it is used for creating tabs intree_representation- Return type:
str
- get_layer(level: int, key: Callable | None = None) list
Treemethod- Parameters:
level – layer number where 0 is the
root.key – An optional callable for each node in the layer.
- Returns:
All nodes on this level. The leaves of branches which are shorter than the given level will be repeated on this and all following layers.
- Return type:
list
- get_leaves(key: Callable | None = None) list
Treemethod- Parameters:
key – An optional callable to be called on each leaf.
- Returns:
nested list of leaves or values of key(leaf) for each leaf
- Return type:
nested list of
Tree
- get_measure(*args, **kwargs) Measure
MusicTreemethodThis method can be used for
ScoreandPart- Parameters:
args – can be used instead of
kwargs. A mixture of args and kwargs is not allowed.kwargs –
part_number,measure_numberdepending on musicscore’s class.
- Return type:
- get_part(*args, **kwargs) Part
MusicTreemethodThis method can be used for
Score- Parameters:
args – can be used instead of
kwargs. A mixture of args and kwargs is not allowed.kwargs –
part_number.
- Return type:
- get_staff(*args, **kwargs) Staff
MusicTreemethodThis method can be used for
Score,PartandMeasure- Parameters:
args – can be used instead of
kwargs. A mixture of args and kwargs is not allowed.kwargs –
part_number,measure_number,staff_numberdepending on musicscore’s class.
- Return type:
- get_staff_number()[source]
- Returns:
get manually set staff number (necessary for cross-staff notation)
- get_voice(*args, **kwargs) Voice
MusicTreemethodThis method can be used for
ScoreandPart,MeasureandStaff- Parameters:
args – can be used instead of
kwargs. A mixture of args and kwargs is not allowed.kwargs –
part_number,measure_number,staff_number,voice_numberdepending on musicscore’s class.
- Return type:
- remove(child: Tree) None
TreemethodChild’s parent will be set to
Noneand child will be removed from list of children.- Parameters:
child –
- Returns:
None
- replace_child(old, new, index: int = 0) None
Treemethod- Parameters:
old – child or function
new – child
index – index of old child in the list of its appearances
- Returns:
None
- reversed_path_to_root() Iterator[Tree]
Treemethod- Returns:
path from self upwards through all ancestors up to the
root.
- tree_representation(key: Callable | None = None, tab: Callable | None = None) str
Treemethod- Parameters:
key – An optional callable if
Nonecompact_reprproperty of each node is called.tab – An optional callable if
Noneget_indentation()method of each node is called.
- Returns:
a representation of all nodes as string in tree form.
- Return type:
str
- property accidental: Accidental
Set or get
Accidentalobject associated with this midi. If it is set toNoneanAccidentalobject will be created.
- property compact_repr: str
Treeproperty- Returns:
compact representation of a node. Default is the string representation. This property is used as default in the
tree_representationmethod and can be customized in subclasses to get the most appropriate representation.- Return type:
str
- property is_leaf: bool
Treeproperty- Returns:
Trueif self has no children.Falseif self has one or more children.- Return type:
bool
- property is_root: bool
Treeproperty- Returns:
Trueif self has no parent, elseFalse.- Return type:
bool
- property level: int
Treeproperty- Returns:
0forroot,1, 2 etc.for each layer of children- Return type:
nonnegative int
>>> class TestTree(Tree): ... def _check_child_to_be_added(self, child): ... return True >>> root = TestTree() >>> root.level 0 >>> ch = root.add_child(TestTree()).add_child(TestTree()).add_child(TestTree()) >>> ch.level 3
- property name: str
- Returns:
a string like
C#3consisting ofstep,accidental sign(or value) andoctave. Midi with value 0 returnsrestas its name.
- property next: Tree | None
Treeproperty- Returns:
next sibling.
Noneif this is the last current child of the parent.- Return type:
- property notehead: XMLNotehead | None
Set or get notedhead property. This can be
Noneor anXMLNoteheadobject. It is possible to set this property with a valid notehead value of type str. For permitted values seeXMLNotehead.
- property octave: int
- Returns:
octave number of this midi.
- property previous: Tree | None
Treeproperty- Returns:
previous sibling.
Noneif this is the first child of the parent.- Return type:
- property show_accidental_signs: str
MusicTreepropertyIf show_accidental_signs is set to None the first get_quantized of ancestors which is
FalseorTruewill be returned.If
show_accidental_signsis set to None it will be converted todefault_show_accidental_signsPossible show_accidental_signs are: None, ‘modern’, ‘traditional’
- Type:
Optional[str]
- Return type:
str
- property value: float | int
Set and get value of midi. A valid value must be of type
floatorintand can be between12and127.
- class musicscore.midi.MidiNote(octave: object, accidental_sign: object = None, *args: object, **kwargs: object)[source]
Bases:
MidiParent class of shorthand midi names: C, D, E, F, G, A, B. Example C(4, ‘#’) = C(4, ‘sharp’) = C(4, sharp)
- class musicscore.midi.A(octave: object, accidental_sign: object = None, *args: object, **kwargs: object)[source]
Bases:
MidiNote
- class musicscore.midi.B(octave: object, accidental_sign: object = None, *args: object, **kwargs: object)[source]
Bases:
MidiNote
- class musicscore.midi.C(octave: object, accidental_sign: object = None, *args: object, **kwargs: object)[source]
Bases:
MidiNote
- class musicscore.midi.D(octave: object, accidental_sign: object = None, *args: object, **kwargs: object)[source]
Bases:
MidiNote
- class musicscore.midi.E(octave: object, accidental_sign: object = None, *args: object, **kwargs: object)[source]
Bases:
MidiNote
- class musicscore.midi.F(octave: object, accidental_sign: object = None, *args: object, **kwargs: object)[source]
Bases:
MidiNote
- class musicscore.midi.G(octave: object, accidental_sign: object = None, *args: object, **kwargs: object)[source]
Bases:
MidiNote
- musicscore.midi.get_accidental_mode(midi_value: float | int, accidental_sign: str | None = None) str[source]
- Parameters:
midi_value – a valid midi value in half steps (int or float)
accidental_sign –
double-flat,flat-flat,bb,ff–three-quarters-flat–flat,b,f–quarter-flat–None,natural–quarter-sharp–sharp,#,s–three-quarters-sharp–double-sharp,sharp-sharp,x,##,ss
- Returns:
accidental_mode:
standard,enharmonic,flat,sharp,force-flat,force-sharp