Skip to content

Commit

Permalink
Fix fret transpose
Browse files Browse the repository at this point in the history
  • Loading branch information
amits97 committed Feb 19, 2024
1 parent 5e1382f commit a05f68e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "naadan-chords",
"version": "0.80.6",
"version": "0.80.7",
"homepage": "https://www.naadanchords.com/",
"private": true,
"dependencies": {
Expand Down
33 changes: 12 additions & 21 deletions src/containers/ContentParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,6 @@ export default class ContentParser extends Component {
//Chords regex
const notes = "[CDEFGAB]";
const tabBeginning = "(?!\\|)";
const fretNumbers = [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
];
const chords =
"(maj7|maj|min7|min|sus2|sus4|m7|m6add9|m7sus2|6sus2|7sus4|add9|add4|5add14|m|5|6|7|dim)?";
const flat = "(b)?";
Expand Down Expand Up @@ -176,12 +161,18 @@ export default class ContentParser extends Component {
tabLineStrings[i] = tabLineStrings[i].replace(
tabsFretNumbersOnlyRegex,
(match, p1, originalFretPosition) => {
const i =
(Number(originalFretPosition) + this.state.transposeAmount) %
fretNumbers.length;
let newFretPosition = `${
fretNumbers[i < 0 ? i + fretNumbers.length : i]
}`;
let newFretPosition =
Number(originalFretPosition) + this.state.transposeAmount;

if (newFretPosition < 0) {
newFretPosition = newFretPosition + 12;
}

if (newFretPosition > 17) {
newFretPosition = newFretPosition - 12;
}

newFretPosition = `${newFretPosition}`;
return p1 + newFretPosition;
}
);
Expand Down

0 comments on commit a05f68e

Please sign in to comment.