chordsheetjs
    Preparing search index...

    Class Song

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

    Hierarchy

    • MetadataAccessors
      • Song
    Index
    • Creates a new {Song} instance

      Parameters

      • metadata: Record<string, string | string[]> | Metadata | null = null

        {Record<string, string | string[]>|Metadata} predefined metadata

      Returns Song

    lines: Line[] = []

    The Line items of which the song consists

    • get 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.

      Returns Metadata

    • 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(s) set to the specified value(s).

      • 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: string | string[] | null

        The value to set, or null to remove the directive

      Returns Song

      The changed song

      song.changeMetadata('author', 'John');
      song.changeMetadata('composer', ['Jane', 'John']);
      song.changeMetadata('key', null); // Remove key directive
    • Returns a copy of the song with the metadata changed. It will:

      • update the metadata
      • update any existing directive matching the metadata key
      • insert a new directive if it does not exist

      Parameters

      • metadata: Record<string, string | string[] | null>

        The metadata to change

      Returns Song

      song.changeMetadata({
      author: 'John',
      composer: ['Jane', 'John'],
      key: null, // Remove key directive
      });
    • Returns a copy of the song with the capo eliminated, like ChordPro's decapo setting. It changes:

      • all chords, those are transposed up by the capo amount so they sound the same without a capo
      • the song key in metadata and any existing key directive, to the sounding key
      • the value for capo in metadata and any existing capo directive, which are removed

      The song is returned unchanged when it has no usable capo, or when any of its keys cannot be parsed.

      Returns Song

      The changed song

    • 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: (_line: Line) => Line | null

        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 all chords normalized to the specified key. See Chord#normalize.

      Parameters

      • key: string | Key | null = null

        the key to normalize to

      • options: { normalizeSuffix?: boolean } = {}

        options

        • OptionalnormalizeSuffix?: boolean

          whether to normalize the chord suffixes

      Returns Song

    • 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: number | null

        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: string | number | null

        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: { accidental?: Accidental | null; normalizeChordSuffix?: boolean } = {}

        options

        • Optionalaccidental?: Accidental | null
        • 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 accidental.

      Examples:

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

      Parameters

      • accidental: Accidental

        the new accidental

      Returns Song

      the changed song