martijnversluis / ChordSheetJS

A JavaScript library for parsing and formatting ChordPro chord sheets
GNU General Public License v2.0
311 stars 48 forks source link

Transpose using chromatic scales (ex. C, C#, Db...) instead of numbers #563

Closed ljfreelancer88 closed 4 months ago

ljfreelancer88 commented 2 years ago

Based on the documentation, it can transpose the chords within the lyrics using numbers? Is it possible to transpose using chromatic scales? chord.transpose('C')

const chord = parseChord('C/E');
const chord2 = chord.transpose(-4);
chord2.toString(); // -> "Ab/C"
martijnversluis commented 2 years ago

Hey @ljfreelancer88. Thanks for reaching out.

Currently that is only possible for songs, assuming the original key is known.

So when parsing:

{key: C}
[C]Whisper words of [G]wisdom, let it [F]be [C/E] [Dm] [C]

you can do:

const song = new ChordProParser().parse(sheet).changeKey('E');

If the song key is not set, you can do:

const song = new ChordProParser().parse(sheet).setKey('C').changeKey('E');

Please note Song is immutable, so all the methods return a new song object. They don't change the object in-place.

For chords this is not (yet) possible, but I'll add a ticket to the board!

martijnversluis commented 1 year ago

Hey @ljfreelancer88. I'm revisiting this issue, but I'm wondering how you would expect this to work. Chords are unaware of the current key, so they wouldn't know how to transpose to another key.

A way to solve your issue would be to calculate the distance between keys using Key.distance(), and subsequently transpose the chords using the calculated number of semitones.