Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
request.onload = (e) => {
let songText = request.responseText
let song
try {
song = SongParser.load(songText)
} catch (e) {
console.log(e)
return reject(`Failed to parse: ${name}`)
}
// transpose to middle c
let root = parseNote(song[0].note)
song = song.transpose(60 - root)
resolve(song)
}
notesForChord(root, shape, blockStart, blockStop) {
let maxPitch = this.minPitchInRange(blockStart, blockStop)
let chordRoot = this.rootBelow(root, maxPitch)
let chordNotes = Chord.notes(chordRoot, shape)
if (parseNote(chordNotes[2]) > maxPitch) {
chordRoot = addInterval(chordRoot, -OCTAVE_SIZE)
chordNotes = Chord.notes(chordRoot, shape)
}
let rate = this.options.rate || 1
let bpm = this.song.metadata.beatsPerMeasure || 2
let out = []
this.inDivisions(blockStart, blockStop, 1 + rate, (start, stop, k) => {
if (k % bpm == 0) {
// root on beat
out.push(
new SongNote(chordNotes[0], start, stop - start)
)
} else {
triggerNoteDown(note) {
if (this.props.onKeyDown) {
this.props.onKeyDown(note);
}
if (this.props.midiOutput) {
this.props.midiOutput.noteOn(parseNote(note), 100)
}
}
expect(sharpNames.map((n) => parseNote(n))).toEqual([
24,25,26,27,28,29,30,31,32,33,34,35,36
function staffRange(staff, noteRange) {
if (noteRange) {
return [
noteName(Math.max(noteRange[0], parseNote(staff.range[0]))),
noteName(Math.min(noteRange[1], parseNote(staff.range[1])))
]
} else {
return staff.range
}
}
}
if (haveFinished) {
playingNotes = playingNotes.filter(note => {
let finished = beat >= note.start + note.duration
if (finished) {
midiOutput.noteOff(parseNote(note.note))
}
return !finished
})
}
while (notes[currentIdx] && (beat >= notes[currentIdx].start)) {
let note = notes[currentIdx]
midiOutput.noteOn(parseNote(note.note), 100)
playingNotes.push(note)
currentIdx += 1
}
if (currentIdx >= notes.length && playingNotes.length == 0) {
timer.stop("finish")
}
}
})
onNoteStart(note) {
let noteStart = note.getStart()
if (noteStart >= this.state.loopRight) {
return
}
if (noteStart < this.state.loopLeft) {
return
}
if (this.state.playNotes && this.props.midiOutput) {
this.props.midiOutput.noteOn(parseNote(note.note), 100)
}
if (this.state.enablePauseOnMiss) {
let currentSong = this.state.song
if (!this.hitNotes.has(note)) {
window.setTimeout(() => {
if (this.state.song != currentSong) {
return
}
if (!this.state.songTimer.running) {
return
}
if (this.hitNotes.has(note)) {
return
if (first.length != notes.length) {
return false;
}
if (anyOctave) {
let noteSet = {}
notes.forEach((n) => noteSet[n.replace(/\d+$/, "")] = true)
return first.every((n) => noteSet[n.replace(/\d+$/, "")])
} else {
const pitches = notes.map(parseNote)
return first.map(parseNote).every((n) => pitches.indexOf(n) >= 0)
}
} else {
if (anyOctave) {
return notes.length == 1 && notesSame(notes[0], first)
} else {
return notes.length == 1 && parseNote(notes[0]) == parseNote(first)
}
}
}
onNoteStop(note) {
if (this.state.playNotes && this.props.midiOutput) {
this.props.midiOutput.noteOff(parseNote(note.note), 100)
}
}
renderKeySignature() {
let keySignature = this.props.keySignature
if (!keySignature) {
return;
}
if (keySignature.count == 0) {
return;
}
let ksCenter = parseNote(this.props.keySignatureCenter)
if (keySignature.isFlat()) { ksCenter -= 2 }
let sigNotes = keySignature.notesInRange(ksCenter - 10, ksCenter + 2)
let topOffset = this.props.upperRow
let sigClass = keySignature.isFlat() ? "flat" : "sharp";
let src = keySignature.isFlat() ? "/static/svg/flat.svg" : "/static/svg/sharp.svg";
return <div>
{sigNotes.map((n, i) => {
let fromTop = topOffset - noteStaffOffset(n);
let style = {
top: `${Math.floor(fromTop * 25/2)}%`,
left: `${i * 20}px`</div>