Skip to content
anstepp edited this page Nov 29, 2020 · 6 revisions

The Note object allows you to create a Py2MusicXML note.

Creating a note is relatively simple. The arguments are: duration, octave, and pitch class. You can simple assign your Note to a variable name:

our_first_note = Note(1, 4, 0)

And there is a quarter note middle c assigned to our_first_note.

More sophisticated examples can be created.

An example:

# a chromatic scale in quarter notes

chromatic_scale = []

for x in range(12):
    chromatic_scale.append(Note(1, 4, x))

For a chromatic scale starting on middle c in quarter notes.

Chromatic Scale

It can coexist with Rest objects in a list that is fed to a Part object. You can print a note, and it will give the duration, octave, and pitch class.

The Note object is "smart" enough to deal with you feeding an impractical pitch class, like -5 or 20. It will sort out the difference modulo 12, then correct the octave. For instance, if you make these two notes:

correct_down = Note(4, 4, -5)
correct_up = Note(4, 4, 20)

Py2MusicXML will act as though you made these notes:

correct_up = Note(4, 3, 7)
correct_down = Note(4, 5, 7)

You can feed Py2MusicXML a long series of numbers as pitch classes, and it will correct any pitch classes outside 0-11. This is useful for data sonification, or a procedure where you could generate pitches outside those boundaries.

Clone this wiki locally