Tutorial 1 - The Note Class

mingus.core.notes provides a way to work with notes. However, what if we want to work with notes in different octaves? Or what if we want to set the amplitude or some effects on a note? This Note class solves those problems and also provides the cornerstone of the mingus.containers package.

>>> from mingus.containers import Note

Creating and Setting Notes

Defining and setting notes is pretty easy and can be done in a variety of ways.

>>> Note("C")
>>> Note("C", 4)
>>> Note("C", 5)
>>> Note("C-3")
>>> n = Note()
>>> n.set_note("C", 5)
>>> n

Note Attributes

The attributes name, octave and dynamics are always set and accessible from the outside:

>>> c = Note("C")
>>> c
>>> c.name
>>> c.octave
>>> c.dynamics

The dynamics dictionary can be used to store additional information such as volume and effects.

NB If you are using the mingus.midi package: setting the velocity, channel and bpm attribute will have an effect on the output.

A Better Note to Integer Converter

A problem with mingus.core.notes.note_to_int is that it returns integers in the range 0-11. This would mean that ‘Cb’ and ‘B’ are both 11. This can be helpful, but when you are dealing with octaves you don’t want this. The Note class fixes this and also overloads the int() function to make it simpler to use:

>>> int(Note("C", 4))
>>> int(Note("Cb", 4))
>>> int(Note("B", 4))

A Better Integer to Note Converter

The opposite of the previous function is from_int(integer), which sets the note to the corresponding integer where 0 is a C on octave 0, 12 is a C on octave 1, etc.

>>> c = Note()
>>> c.from_int(12)

Methods on Notes


Changing the octave can be done by setting the octave attribute, but the following methods can also be used:

>>> a = Note("A", 5)
>>> a
>>> a.octave_up()
>>> a
>>> a.octave_down()
>>> a
>>> a.change_octave(+2)
>>> a.change_octave(-2)


To move a Note an interval up or down, you can use the function transpose(interval, up=True). The interval should be valid interval shorthand (see the [tutorialIntervals interval tutorial])

>>> a = Note("A")
>>> a.transpose("3")
>>> a
>>> a.transpose("4", up=False)
>>> a


Converting from and to hertz can be done using the from_hertz(hertz, standard_pitch=440) and to_hertz(standard_pitch=440) functions, where standard_pitch can be used to set the pitch of A-4, from which the rest is calculated.

Migrated Methods

Some of the functions in mingus.core.notes were added to the Note class as methods for convenience.

>>> a = Note("A")
>>> a
>>> a.augment()
>>> a
>>> a.diminish()
>>> a
>>> a.to_major()
>>> a
>>> a.to_minor()
>>> a
>>> a = Note("A#b#b")
>>> a.remove_redundant_accidentals()

You can learn more about mingus.containers.Note in the reference section