Class Chord

The Chord class holds a collection of pitches that represent a chord.

Examples:

const chord = new Chord().setRoot(36).addPitches([40, 43]);
chord.contains(40) //Returns true
chord.contains(41) //Returns false
chord.fitPitch(44) //Returns 43
chord.getPitch(1) //Returns 40

Hierarchy

  • Chord

Implements

Constructors

  • Returns Chord

Properties

nameGenerator: ((Chord: any) => string) = null

Type declaration

    • (Chord: any): string
    • Holds a function which will be used for any chord that needs to recalculate what its name is.

      Example:

      const scale = shimi.ScaleTemplate.major.create(shimi.pitch('Eb'));
      const finder = new shimi.ChordFinder().withDefaultChordLookups();
      shimi.Chord.nameGenerator = (chord) => {
      const result = finder.lookupChord(chord.pitches, chord.root, null, scale);
      if (result == null)
      return null;
      return result.name
      .replace('{r}', scale.getPitchName(result.root))
      .replace('{r}', scale.getPitchName(result.bass));
      };

      Parameters

      • Chord: any

      Returns string

Accessors

  • get bass(): number
  • The bass note of the chord.

    Returns number

  • get name(): string
  • Holds the name of the chord.

    Each time a pitch on the chord gets changed, the name property gets wiped out. So long as the static nameGenerator property has been set, then the next time an attempt is made to get the name, it will be automatically recalculated.

    Returns string

  • get pitches(): number[]
  • Contains the pitches that make up the chord.

    Intended for read use only. To modify the chord, use addPitch, addPitches & removePitches methods.

    Pitches should always be held in ascending order.

    Returns number[]

  • get root(): number
  • The root note of the chord.

    Setting this property is the same as calling the setRoot method.

    Returns number

  • set root(pitch: number): void
  • Parameters

    • pitch: number

    Returns void

  • get typeName(): string
  • Returns the name of this type. This can be used rather than instanceof which is sometimes unreliable.

    Returns string

Methods

  • Adds one or more pitches to a chord, based on chord degrees. For example, addDegrees([3,5]) would add a 3rd & 5th to the chord. The degrees added will always default to the major/perfect variety, though if the scale parameter is used, then the minor/diminished/augmented versions can be used if they would be deemed to be a better fit within the scale. If you want to force the use of the minor/diminished version of the degree, then the degree can be provided as a negative, for example: addDegrees([-3,5])

    Returns

    Returns the chord instance, so that method calls can be chained together.

    Parameters

    • degrees: number[]

      The degrees of the chord to be added.

    • scale: Scale = null

      Optional, used to allow for better fitting pitch selection.

    Returns Chord

  • Adds a new pitch to the chord. This method ensures that pitches are stored in ascending order.

    Returns

    Returns the chord instance, so that method calls can be chained together.

    Parameters

    • pitch: string | number

      The pitch to add to the chord. This is only added if the chord doesn't already contain the pitch. Can also take pitch names, see the pitch method for more information.

    Returns Chord

  • Adds multiple new pitches to the chord. This method ensures that pitches are stored in ascending order.

    Returns

    Returns the chord instance, so that method calls can be chained together.

    Parameters

    • pitches: (string | number)[]

      The pitches to add to the chord. Each one will only be added if the chord doesn't already contain the pitch. Can also take pitch names, see the pitch method for more information.

    Returns Chord

  • Returns true if the chord contains the passed in pitch. The method doesn't care if the pitches are in different octaves.

    Parameters

    • pitch: string | number

      The pitch to check if contained by the chord. Can also take pitch names, see the pitch method for more information.

    Returns boolean

  • Creates a copy of the chord.

    Returns Chord

  • Returns a pitch near to the passed in pitch, but which should fit better with the notes within the chord.

    Returns

    Returns a new pitch number

    Parameters

    • pitch: string | number

      The pitch which we want to fit to the chord. Can also take pitch names, see the pitch method for more information.

    • Optional options: Partial<FitPitchOptions>

      The options allow us to configure how we want the pitch to be fitted to the chord

    Returns number

  • Returns a pitch from the chord based on its degree. To use this, you must have set the chord root.

    Example:

    new shimi.Chord().setRoot(36).addPitches([40, 43]).getPitchByDegree(5) => 43
    new shimi.Chord().setRoot(36).addPitches([40, 43]).getPitchByDegree(8) => 48
    new shimi.Chord().setRoot(36).addPitches([40, 43]).getPitchByDegree(9) => 50

    Returns

    Returns a number representing the pitch at the specified degree.

    Parameters

    • degree: number

      The degree of the chord to fetch

    • Optional scale: Scale

      Used to find which pitch to use when the chord doesn't contain the requested degree.

    Returns number

  • Returns a pitch from the chord based on its index. Allows indices below zero or above pitches.length to fetch pitches from additional registers.

    Example:

    new shimi.Chord().addPitches([36, 40, 43]).getPitchByIndex(2) => 43
    new shimi.Chord().addPitches([36, 40, 43]).getPitchByIndex(3) => 48
    new shimi.Chord().addPitches([36, 40, 43]).getPitchByIndex(-1) => 31

    Returns

    Returns a number representing the pitch at the specified index

    Parameters

    • index: number

      The index of the pitch to fetch within the chord

    Returns number

  • Modifies the pitches within a chord up/down octaves so that they are nearer to the desired pitch

    Returns

    Returns the chord instance which the method was called on.

    Parameters

    • pitch: string | number

      The pitch which the chord should be moved closer to

    • allowInversions: boolean = false

      Defaults to false, meaning the entire chord must be moved up/down as one. If true, then single pitches within the chord can be moved, allowing for inversions.

    Returns Chord

  • Removes pitches from the chord that match the passed in condition.

    Returns

    Returns the chord instance, so that method calls can be chained together.

    Parameters

    • condition: ((pitch: number) => boolean)

      The condition to determine how to remove pitches, for example: pitch => pitch % 2 == 0 would remove all even numbered pitches from the chord.

        • (pitch: number): boolean
        • Parameters

          • pitch: number

          Returns boolean

    Returns Chord

  • Sets the root pitch of the chord, also adds the root pitch to the list of pitches if the chord doesn't already contain it.

    Returns

    Returns the chord instance, so that method calls can be chained together.

    Parameters

    • pitch: string | number

      The pitch to be set as the new chord root. Can also take pitch names, see the pitch method for more information.

    Returns Chord

  • Modifies the chord in place, transposing the pitches within the chord up/down by the specified number of semitones.

    Parameters

    • semitones: number

    Returns void

Generated using TypeDoc