The Chord Transposer is a TypeScript/JavaScript library designed to manipulate and transpose chords within text-based songs. This library is intended for browser use and offers functionalities to parse song texts, identify chord positions, and apply transformations like transposing and highlighting chords.
- Chord Parsing: Parses song texts to identify and extract chords.
- Chord Transposition: Allows shifting chords up or down by a specified interval.
- HTML Tag Insertion: Supports highlighting chords by inserting HTML tags around them.
Once installed, import the chords-transposer
library into your project,
import Transposer from "chords-transposer";
Create a Transposer object by passing the chord progression string:
const song = "Gm F Gm Eb B F B Gm";
const transposer = new Transposer(song);
Retrieve the chord progression with HTML span tags for styling:
const chordsWithTags = transposer.getWithTags();
console.log(chordsWithTags);
The output will be:
<span class="chords-highlighted">Gm</span> <span class="chords-highlighted">F</span> <span class="chords-highlighted">Gm</span> <span class="chords-highlighted">Eb</span> <span class="chords-highlighted">B</span> <span class="chords-highlighted">F</span> <span class="chords-highlighted">B</span> <span class="chords-highlighted">Gm</span>
Transpose the chord progression by shifting the scale:
const shiftedChords = transposer.shiftScaleBy(1).getWithTags();
console.log(shiftedChords);
Transpose the chord progression by specifying the original and target keys:
const transposedChords = transposer.shiftScaleFromTo("G", "A").getWithTags();
console.log(transposedChords);
Combine multiple scale shifts for complex transpositions:
const complexTransposition = transposer.shiftScaleBy(1).shiftScaleBy(1).shiftScaleBy(1).getWithTags();
console.log(complexTransposition);
The library exposes the following main methods:
constructor(song: string)
: Initializes the library with the song text.shiftScaleBy(shiftBy: number)
: Shifts chords by the specified number of semitones.shiftScaleFromTo(from: string, to: string)
: Shifts chords from a specific chord to another.getWithTags()
: Returns the updated song text with HTML tags around chords.
Refer to the library source code or documentation for more detailed API information.
Contributions to this library are welcome! If you encounter issues or have ideas for enhancements, feel free to create an issue or pull request on the GitHub repository.
This library is licensed under the MIT License.