Represents a song in a chord sheet. Currently a chord sheet can only have one song.

Hierarchy

  • MetadataAccessors
    • Song

Constructors

  • Creates a new {Song} instance

    Parameters

    • metadata: {} = {}

      {Object|Metadata} predefined metadata

    Returns Song

Properties

lines: Line[] = []

The Line items of which the song consists

metadata: Metadata

The song's metadata. When there is only one value for an entry, the value is a string. Else, the value is an array containing all unique values for the entry.

Accessors

  • get bodyLines(): Line[]
  • Returns the song lines, skipping the leading empty lines (empty as in not rendering any content). This is useful if you want to skip the "header lines": the lines that only contain meta data.

    Returns Line[]

    The song body lines

Methods

  • Returns a copy of the song with the key set to the specified key. It changes:

    • the value for key in the metadata set
    • any existing key directive
    • all chords, those are transposed according to the distance between the current and the new key

    Parameters

    • newKey: string | Key

      The new key.

    Returns Song

    The changed song

  • Returns a copy of the song with the directive value set to the specified value.

    • when there is a matching directive in the song, it will update the directive
    • when there is no matching directive, it will be inserted If value is null it will act as a delete, any directive matching name will be removed.

    Parameters

    • name: string

      The directive name

    • value: null | string

      The value to set, or null to remove the directive

    Returns Song

  • Returns all unique chords used in the song

    Returns string[]

    the chords

  • Change the song contents inline. Return a new Item to replace it. Return null to remove it.

    Parameters

    • func: MapItemsCallback

      the callback function

    Returns Song

    the changed song

    // transpose all chords:
    song.mapItems((item) => {
    if (item instanceof ChordLyricsPair) {
    return item.transpose(2, 'D');
    }

    return item;
    });
  • Change the song contents inline. Return a new Line to replace it. Return null to remove it.

    Parameters

    • func: MapLinesCallback

      the callback function

    Returns Song

    the changed song

    // remove lines with only Tags:
    song.mapLines((line) => {
    if (line.items.every(item => item instanceof Tag)) {
    return null;
    }

    return line;
    });
  • Returns a copy of the song with the key value set to the specified capo. It changes:

    • the value for capo in the metadata set
    • any existing capo directive

    Parameters

    • capo: null | number

      the capo. Passing null will:

      • remove the current key from metadata
      • remove any capo directive

    Returns Song

    The changed song

  • Returns a copy of the song with the key value set to the specified key. It changes:

    • the value for key in the metadata set
    • any existing key directive

    Parameters

    • key: null | string | number

      the key. Passing null will:

      • remove the current key from metadata
      • remove any key directive

    Returns Song

    The changed song

  • Transposes the song by the specified delta. It will:

    Parameters

    • delta: number

      The number of semitones (positive or negative) to transpose with

    • Optionaloptions: { modifier?: null | Modifier; normalizeChordSuffix?: boolean } = {}

      options

      • Optionalmodifier?: null | Modifier
      • OptionalnormalizeChordSuffix?: boolean

        whether to normalize the chord suffixes after transposing

    Returns Song

    The transposed song

  • Transposes the song down by one semitone. It will:

    Parameters

    • Optionaloptions: { normalizeChordSuffix?: boolean } = {}

      options

      • OptionalnormalizeChordSuffix?: boolean

        whether to normalize the chord suffixes after transposing

    Returns Song

    The transposed song

  • Transposes the song up by one semitone. It will:

    Parameters

    • Optionaloptions: { normalizeChordSuffix?: boolean } = {}

      options

      • OptionalnormalizeChordSuffix?: boolean

        whether to normalize the chord suffixes after transposing

    Returns Song

    The transposed song

  • Returns a copy of the song with all chords changed to the specified modifier.

    Examples:

    song.useModifier('#');
    song.useModifier('b');

    Parameters

    • modifier: Modifier

      the new modifier

    Returns Song

    the changed song