Class: Part


A part of a Section.

Represents a musical idea, such as a melody, bassline, or drum groove. Produces musical notes whose Pitch (normally) depends on the Scale and Harmony of the containing Section

See the overview on the documentation homepage.


new Part(options)

Name Type Description
options Object
Name Type Attributes Default Description
channel Number

The MIDI channel that this part's notes will output to.

When using realtime MIDI output, the channel you use depends on what receives the MIDI. For example, you can use this to route to different tracks in your DAW.

For MIDI file output, the part channel determines which MIDI file track will be used.

Using the same channel for multiple parts can be used to, for example, create polyrhythms or counterpoint.

Must be provided unless this instance is constructed by the containing Section, in which case it will default to the index+1 within that section's parts list.

mode String <optional>

Determines how the containing Section interprets pitch numbers in this Part. Depending on the mode, pitch numbers will be relative to the section's Scale or the current Chord of the section's Harmony.

Any integer pitch number is allowed as long as it produces a valid MIDI pitch value (TODO explain/link). When there are no more pitches in the scale/chord because the pitch number is too large, it wraps around to the beginning of the scale/chord an octave up. Negative numbers go downward and wrap around an octave down. TODO: is there a better place to explain this (in Scale/Chord)?

Note: When the pitch is a Pitch object, that pitch will be produced and the mode has no effect.

Supported mode values:

  • "scale" - Pitch numbers are relative to the section's scale and only produce notes from that scale.

    0 is the scale's first pitch, 1 is the scale's second pitch, 2 is the third, and so on. When the index wraps around, it produces the scale's first pitch an octave up. Negative numbers go down the octaves (-1 is the scale's last pitch an octave down).

    Use "scale" mode to explore scales while ignoring the current harmony/chords.

  • "chromatic" - Produces any pitch relative to the scale's first note.

    0 is the scale's first pitch. 1 is the next pitch higher regardless of whether it's in the scale or not. -1 is the next lower pitch below 0.

    Use "chromatic" mode to remove pitch constraints when using relative pitch numbers.

  • "lead" - Similar to "scale" mode, except 0 starts from the first note of the current chord.

    Use "lead" mode for melodies.

  • "bass" - Similar to "scale" mode, except 0 starts from the root note of the current chord (ignoring any chord inversions). TODO: document Chord inversions and link

    Use "bass" mode for basslines.

  • "chord" - Produces the current chord.

    0 is exactly the current chord, 1 is the next chord inversion up, -1 is the next chord inversion down, and so on.

    Use "chord" mode to play the chord progression.

  • "arpeggio" - arpeggiates the current chord.

    A pitch value 0 is the chord's first pitch, 1 is the chord's second pitch, 2 is the third, and so on.

    Use "arpeggio" mode to play the chord progression one note at a time.

  • null (no mode) - If no mode is set, pitch numbers are ambiguous and all pitches must be Pitch objects.

    Use no mode / pitch objects for drum parts.

The supported modes are available via static Part.MODES constants of this class.

pitches Iterable
rhythm Rhythm | String | Iterable | Object <optional>>1)

Either a Rhythm object, or options for the Rhythm constructor. When a String or Iterable, it's used as the pattern option for the Rhythm constructor (for convenience). Otherwise, it's treated as the entire options object for the constructor.

pulse Number <optional>

When the rhythm option is a String, this gets passed to the Rhythm constructor.

octave Number <optional>
length Number <optional>

The length of the part in beats.

Must be provided when the looped option is true.

Also note the containing Section will default its length to the max length of its parts, so set your section and/or part lengths accordingly.

looped Boolean <optional>

If true, this part will repeat infinitely, starting from the beginning each time the part length is reached.

delay Number <optional>

Delays the start of the part (relative to the start of the containing Section) by the given number of beats.




(static, constant) MODES

Constants for all supported Part.mode options. See constructor documentation for descriptions.

Name Type Description
BASS String
CHORD String
LEAD String
SCALE String



The [Symbol.iterator]() generator function* that implements the iterable protocol

Inherited From: