Class: Pitch

Pitch

A Pitch is an immutable representation of the frequency of a musical note. It consists of a PitchClass and an octave number. It has an underlying value for MIDI pitch, which supports the range 0 to 127 (inclusive).

Constructor

new Pitch(value, octaveopt)

Parameters:
Name Type Attributes Default Description
value number | PitchClass | string

The numeric pitch value, or a PitchClass, or a string of the pitch class name and optional octave. See examples below.

octave number <optional>
4

The octave to use when the first argument is a PitchClass or a string without the octave. The octave should be in the range -1 to 9 (inclusive) to avoid invalid pitch values.

Source:
Example
// The following are equivalent:
new Pitch(60);
new Pitch(new PitchClass('C'), 4);
new Pitch(new PitchClass('C')); // default octave is 4
new Pitch('C4');
new Pitch('C', 4);
new Pitch('C'); // default octave is 4

Members

(static) MAX_VALUE

The maximum pitch value supported by MIDI: 127. Note the minimum value is 0.

Source:

(readonly) name :string

The canonical name for this Pitch.

Type:
  • string
Source:

(readonly) octave :number

Type:
  • number
Source:

(readonly) pitchClass :PitchClass

Type:
Source:

(readonly) value :number

The MIDI pitch value. Should be in the range 0 to 127 (inclusive).

Type:
  • number
Source:

Methods

add(value) → {Pitch}

Return a new Pitch whose value is the sum of this Pitch's value and the given value

Parameters:
Name Type Description
value number

the value to add to this Pitch's value

Source:
Returns:
Type
Pitch