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).

 

Function Description
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).

Below are functions used to retrieve and modify attributes of existing notes.  It is assumed that a note has already been created, for example, as follows:

 

Function Description
n.getPitch() Retrieves the pitch (0-127) of note n.
n.setPitch(pitch) Sets the pitch (0-127) of note n.
n.getDuration() Retrieves the duration (a float) of note n.
n.setDuration(duration) Sets the duration (a float) of note n.
n.getDynamic() Retrieves the dynamic (0-127) of note n.
n.setDynamic(dynamic) Sets the dynamic (0-127) of note n.
n.getPan() Retrieves the pan (0.0-1.0) of note n.
n.setPan(pan) Sets the pan (0.0-1.0) of note n.
n.getLength() Retrieves 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.

 

Finally, here are some helper note functions:

 

Function Description
Note.freqToMidiPitch(freq) Converts freq (a float) in Hertz (e.g., 440.0) to the equivalent MIDI pitch (e.g., 69).
Note.midiPitchToFreq(pitch) Converts pitch (0-127) from a MIDI value to the equivalent frequency in Hertz (a float).