Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function getDigitalPattern(chord) {
chord = Harmony.getTonalChord(chord);
const intervals = Chord.intervals(chord);
if (intervals.includes('3m')) {
return [1, 3, 4, 5];
} else if (intervals.includes('3M')) {
return [1, 2, 3, 5];
} else {
return [1, 1, 1, 1];
}
}
export function getDegreeInChord(degree, chord) {
chord = Harmony.getTonalChord(chord);
const intervals = Chord.intervals(chord);
const tokens = Chord.tokenize(chord);
return Distance.transpose(tokens[0], findDegree(degree, intervals));
}
public static quality(chord: string): ChordQuality {
if (!Chord.exists(chord)) {
throw new ChordSymbolException(
'Unrecognized chord symbol: ' +
`${chord}`);
}
const intervals = Chord.intervals(chord);
const qualities = CHORD_QUALITY_INTERVALS.map(
cqis => cqis.every(cqi => intervals.includes(cqi)));
const i = qualities.indexOf(true);
const j = qualities.lastIndexOf(true);
if (i >= 0 && i === j) {
return i;
} else {
return ChordQuality.Other;
}
}
}
export function getDegreeInChord(degree, chord) {
chord = Harmony.getTonalChord(chord);
const intervals = Chord.intervals(chord);
const tokens = Chord.tokenize(chord);
return Distance.transpose(tokens[0], findDegree(degree, intervals));
}
export function chordHasIntervals(chord, intervals) {
chord = Harmony.getTonalChord(chord);
const has = Chord.intervals(chord);
return intervals.reduce((match, current) => {
const isOptional = current.includes('?');
const isForbidden = current.includes('!');
if (isOptional) {
current = current.replace('?', '');
return (!hasDegree(getDegreeFromInterval(current), has) ||
has.includes(current)) && match;
}
if (isForbidden) {
current = current.replace('!', '');
return !hasDegree(getDegreeFromInterval(current), has);
}
return has.includes(current) && match;
}, true);
}
export function chordHasIntervals(chord, intervals) {
chord = Harmony.getTonalChord(chord);
const has = Chord.intervals(chord);
return intervals.reduce((match, current) => {
const isOptional = current.includes('?');
const isForbidden = current.includes('!');
if (isOptional) {
current = current.replace('?', '');
return (!hasDegree(getDegreeFromInterval(current), has) ||
has.includes(current)) && match;
}
if (isForbidden) {
current = current.replace('!', '');
return !hasDegree(getDegreeFromInterval(current), has);
}
return has.includes(current) && match;
}, true);
}
/** Returns true if the given degree is present in the intervals */