How to use the st/song_parser.load function in st

To help you get started, we’ve selected a few st examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github leafo / sightreading.training / static / js / components / ear_training / melody_recognition_exercise.es6 View on Github external
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)
        }
github leafo / sightreading.training / static / spec / parser_spec.es6 View on Github external
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),
github leafo / sightreading.training / static / spec / parser_spec.es6 View on Github external
it("loads empty song", function() {
    let song = SongParser.load("ks0")
    expect([...song]).toEqual([])
  })
github leafo / sightreading.training / static / spec / parser_spec.es6 View on Github external
it("parses keysignature into metadata", function() {
    let song = SongParser.load(`
      ks-5
      c5
    `)

    expect(song.metadata).toEqual({
      keySignature: -5,
      beatsPerMeasure: 4,
    })
  })
github leafo / sightreading.training / static / spec / parser_spec.es6 View on Github external
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"]],
    ])
  })
})
github leafo / sightreading.training / static / spec / parser_spec.es6 View on Github external
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),
github leafo / sightreading.training / static / js / components / pages / play_along_page.es6 View on Github external
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
    }
  }