Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("gets notes in F MajorScale", function() {
let scale = new MajorScale("F");
// TODO: should be Bb5
expect(scale.getRange(5)).toEqual([
"F5", "G5", "A5", "Bb5", "C6", "D6", "E6", "F6"
]);
});
it("gets enharmonic spelling of notes for key", function() {
let key = new KeySignature(-3) // b e a
let notes = new MajorScale(key.name()).getRange(4).map((n) => key.enharmonic(n))
expect(notes).toEqual([
"Eb4", "F4", "G4", "Ab4", "Bb4", "C5", "D5", "Eb5"
])
})
})
export function testRandomNotes() {
let scale = new MajorScale("C")
// let notes = scale.getLooseRange("A4", "C7")
let notes = scale.getLooseRange("C3", "C7")
let r = new RandomNotes(notes, {})
let totalCount = 0
let counts = {}
for (let note of notes) {
counts[note] = 0
}
for (let i = 0; i < 10000; i++) {
for (let group of r.handGroups()) {
for (let n of group) {
counts[n] += 1
}
it("gets notes in C MajorScale", function() {
let scale = new MajorScale("C");
expect(scale.getRange(5)).toEqual([
"C5", "D5", "E5", "F5", "G5", "A5", "B5", "C6"
]);
});
it("converts degree to note name", function() {
let scale = new MajorScale("G")
expect(scale.degreeToName(1)).toEqual("G")
expect(scale.degreeToName(2)).toEqual("A")
expect(scale.degreeToName(3)).toEqual("B")
expect(scale.degreeToName(4)).toEqual("C")
expect(scale.degreeToName(5)).toEqual("D")
expect(scale.degreeToName(6)).toEqual("E")
expect(scale.degreeToName(7)).toEqual("F#")
expect(scale.degreeToName(8)).toEqual("G")
expect(scale.degreeToName(9)).toEqual("A")
})
it("gets scale degrees for G major", function() {
let scale = new MajorScale("G")
let range = scale.getLooseRange("C5", "C6")
expect(range.map(scale.getDegree.bind(scale))).toEqual([
4, 5, 6, 7, 1, 2, 3, 4
])
})
it("gets notes in loose range for scale", function() {
let scale = new MajorScale("G");
let range = scale.getLooseRange("C5", "C6")
expect(range).toEqual([
"C5", "D5", "E5", "F#5", "G5", "A5", "B5", "C6"
]);
});
getKeyRange() {
let notes = new MajorScale("C").getRange(3, 24, 2);
return [notes[0], notes[notes.length - 1]];
}
create: function(staff, keySignature, options) {
let scale = new MajorScale(keySignature)
let progressionInputs = this.inputs.find(i => i.name == "progression")
let progression = progressionInputs.values.find(v => v.name == options.progression)
return new ProgressionGenerator(scale, staff.range, progression.value, options)
}
},
constructor(keySignature, opts={}) {
this.noteCount = opts.notes || 3
this.keySignature = keySignature
if (opts.commonNotes > 0) {
this.commonNotes = opts.commonNotes
}
this.generator = new MersenneTwister()
if (keySignature.isChromatic()) {
this.scale = keySignature.defaultScale()
} else {
switch (opts.scale) {
case "major":
this.scale = new MajorScale(keySignature.name())
break
case "natural minor":
this.scale = new MinorScale(keySignature.name())
break
case "harmonic minor":
this.scale = new HarmonicMinorScale(keySignature.name())
break
case "melodic minor":
this.scale = new AscendingMelodicMinorScale(keySignature.name())
break
case "major blues":
this.scale = new MajorBluesScale(keySignature.name())
break
default:
this.scale = keySignature.defaultScale()
}