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)
}it("loads song with 6/8 time", function() {
let song = SongParser.load(`
ts6/8
m0 {
c5
d5.2
|
g4.3
}
m1 {
c6
}
`)
matchNotes(song, [
new SongNote("C5", 0, 0.5),
new SongNote("D5", 0.5, 1),it("loads empty song", function() {
let song = SongParser.load("ks0")
expect([...song]).toEqual([])
})it("parses keysignature into metadata", function() {
let song = SongParser.load(`
ks-5
c5
`)
expect(song.metadata).toEqual({
keySignature: -5,
beatsPerMeasure: 4,
})
})it("loads song with autochords", function() {
let song = SongParser.load(`
ts6/8
m0 $g
m1 $bbm
`)
expect(song.metadata.beatsPerMeasure).toEqual(3)
expect(song.autoChords).toEqual([
[0, ["G", "M"]],
[3, ["Bb", "m"]],
])
})
})g5
a5
b5
`)
matchNotes(song, [
new SongNote("C#5", 0, 1),
new SongNote("D5", 1, 1),
new SongNote("E5", 2, 1),
new SongNote("F#5", 3, 1),
new SongNote("G5", 4, 1),
new SongNote("A5", 5, 1),
new SongNote("B5", 6, 1),
])
let song2 = SongParser.load(`
ks-2
c5
d5
e5
f5
g5
a5
b5
`)
matchNotes(song2, [
new SongNote("C5", 0, 1),
new SongNote("D5", 1, 1),
new SongNote("Eb5", 2, 1),
new SongNote("F5", 3, 1),
new SongNote("G5", 4, 1),refreshSong() {
let code = this.state.currentSongCode
try {
let song = SongParser.load(code, this.songParserParams())
this.setSong(song)
} catch(e) {
this.setState({
songError: e.message
})
return
}
}