Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let generator
if (this.state.continuousMelody && this.currentNotes) {
// reuse the same generator so the melody is smooth
generator = this.state.currentNotes.generator
generator.notes = notes // replace notes with the new set generated
generator.notesPerColumn = this.state.notesPerColumn
} else {
generator = new RandomNotes(notes, {
smoothness: 6,
notes: this.state.notesPerColumn,
hands: 1,
})
}
// create a test melody
let list = new NoteList([], { generator })
list.fillBuffer(this.state.notesPerMelody)
if (this.state.melodyDirection == "asc") {
console.warn("sorted asc")
list.sort((rowA, rowB) => parseNote(rowA[0]) - parseNote(rowB[0]))
}
if (this.state.melodyDirection == "desc") {
console.warn("sorted desc")
list.sort((rowA, rowB) => parseNote(rowB[0]) - parseNote(rowA[0]))
}
this.props.midiOutput.playNoteList(list).then(() => {
this.setState({ playing: false })
})
it("matches with singular notes, anyOctave", function () {
const notes = new NoteList([
"D5",
"C5",
])
expect(notes.matchesHead(["D5"], true)).toBe(true)
expect(notes.matchesHead(["D6"], true)).toBe(true)
expect(notes.matchesHead(["C5"], true)).toBe(false)
// singular notes wrapped in array
const notes2 = new NoteList([
["D5"],
["C5"],
])
expect(notes2.matchesHead(["D5"], true)).toBe(true)
expect(notes2.matchesHead(["D6"], true)).toBe(true)
expect(notes2.matchesHead(["C5"], true)).toBe(false)
})
])
expect(notes.matchesHead(["D5"])).toBe(true)
expect(notes.matchesHead(["D6"])).toBe(false)
expect(notes.matchesHead(["C5"])).toBe(false)
// singular notes wrapped in array
const notes2 = new NoteList([
["D5"],
["C5"],
])
expect(notes2.matchesHead(["D5"])).toBe(true)
expect(notes2.matchesHead(["C5"])).toBe(false)
const enharmonic = new NoteList([ "C#4" ])
expect(enharmonic.matchesHead(["Db4"])).toBe(true)
const enharmonic2 = new NoteList([ "Bb4" ])
expect(enharmonic2.matchesHead(["A#4"])).toBe(true)
// wrapped
const enharmonic3 = new NoteList([ ["C#4"] ])
expect(enharmonic3.matchesHead(["Db4"])).toBe(true)
const enharmonic4 = new NoteList([ ["Bb4"] ])
expect(enharmonic4.matchesHead(["A#4"])).toBe(true)
})
expect(notes.matchesHead(["D6"])).toBe(false)
expect(notes.matchesHead(["C5"])).toBe(false)
// singular notes wrapped in array
const notes2 = new NoteList([
["D5"],
["C5"],
])
expect(notes2.matchesHead(["D5"])).toBe(true)
expect(notes2.matchesHead(["C5"])).toBe(false)
const enharmonic = new NoteList([ "C#4" ])
expect(enharmonic.matchesHead(["Db4"])).toBe(true)
const enharmonic2 = new NoteList([ "Bb4" ])
expect(enharmonic2.matchesHead(["A#4"])).toBe(true)
// wrapped
const enharmonic3 = new NoteList([ ["C#4"] ])
expect(enharmonic3.matchesHead(["Db4"])).toBe(true)
const enharmonic4 = new NoteList([ ["Bb4"] ])
expect(enharmonic4.matchesHead(["A#4"])).toBe(true)
})
checkForMatch() {
if (!this.state.currentNotes || !this.state.noteHistory) {
return
}
if (this.state.noteHistory.length < this.state.currentNotes.length) {
return
}
while (this.state.noteHistory.length > this.state.currentNotes.length) {
this.state.noteHistory.shift()
}
if (this.state.noteHistory.toString() == this.state.currentNotes.toString()) {
this.setState({
noteHistory: new NoteList([]),
locked: true,
successes: this.state.successes + 1,
statusMessage: "You got it"
})
setTimeout(() => {
this.setState({
locked: false,
statusMessage: null
})
this.pushMelody()
}, 1000)
}
}
),
...this.state.currentGeneratorSettings
}
let generatorInstance = generator.create.call(
generator,
this.state.currentStaff,
this.state.keySignature,
generatorSettings
)
var notes
switch (generator.mode) {
case "notes":
notes = new NoteList([], { generator: generatorInstance })
break
case "chords":
notes = new ChordList([], { generator: generatorInstance })
break
}
if (!notes) {
throw new Error(`unknown generator mode: ${generator.mode}`)
}
notes.fillBuffer(this.state.bufferSize)
return this.setState({ notes: notes })
}