Note

Notes contain the simplest possible musical events, consisting of pitch, duration, etc.  The music library provides several functions to create musical notes.  It also provides several others to retrieve or modify attributes (e.g., pitch) or existing notes.

Here are functions used to create musical notes.  Each of these functions creates a new Note object, so you need to save it in a variable (or other memory location).

FunctionDescription
Note(pitch, duration)Creates a new note, where pitch is 0-127, and duration is a float (e.g., 1.0 is a quarter note).
Note(pitch, duration, dynamic)Creates a new note, where pitch is 0-127, duration is a float, and dynamic is 0-127.
Note(pitch, duration, dynamic, pan)Creates a new note, where pitch is 0-127, duration is a float, dynamic is 0-127, and pan is 0.0 (left) to 1.0 (right).
Note(pitch, duration, dynamic, pan, length)Creates a new note, where pitch is 0-127, duration is a float, dynamic is 0-127, pan is 0.0 (left) to 1.0 (right), and length is a float.

You can create a note as follows:

n = Note(A4, HN)

Once a note n has been created, the following functions are available:

FunctionDescription
n.getPitch()Returns the pitch (0-127) of note n.
n.setPitch(pitch)Sets the pitch (0-127) of note n.
n.getDuration()Returns the duration (a float) of note n.
n.setDuration(duration)Sets the duration (a float) of note n.
n.getDynamic()Returns the dynamic (0-127) of note n.
n.setDynamic(dynamic)Sets the dynamic (0-127) of note n.
n.getPan()Returns the pan (0.0-1.0) of note n.
n.setPan(pan)Sets the pan (0.0-1.0) of note n.
n.getLength()Returns the length of note n (same units as duration).  Whereas duration determines the printed (notation) value of a note, the length of a note determines how long the note actually sounds. Length is automatically set to 90% of note duration. For example, a QN note (1.0 duration) normally has 0.9 length.
n.setLength(length)Sets the length of note n (same units as duration). Length is normally set to 90% of note duration (so that different notes sound separate when played). Setting the length of a note allows for variations in how legato or staccato a note sounds. For example, to make a QN note (1.0 duration) sound legato, you should set its length to 1.0.
n.isRest()Checks if note n is a rest or a note with pitch.  Returns a Boolean value (True or False).
n.copy()Returns a new note with the same attributes as note n.  This is used to create a copy to be modified, while the original note is not affected.

Creating Notes using Frequencies

Notes may also be created using a frequency (instead of pitch):

n = Note(440.0, HN)

When working with frequencies, the following functions may also be used:

FunctionDescription
n.getFrequency()Returns the frequency of note n (in Hertz).
n.setFrequency(freq)Sets the frequency of note n (in Hertz).
n.getPitchBend()Returns the difference between pitch (int) and frequency (float) of note n, in pitch bend units (-8191 to 8192, where 0 means no bend).