How to use the st/music.parseNote 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 / js / auto_chords.es6 View on Github external
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 {
github leafo / sightreading.training / static / js / components / keyboard.es6 View on Github external
triggerNoteDown(note) {
    if (this.props.onKeyDown) {
      this.props.onKeyDown(note);
    }

    if (this.props.midiOutput) {
      this.props.midiOutput.noteOn(parseNote(note), 100)
    }
  }
github leafo / sightreading.training / static / spec / music_spec.es6 View on Github external
    expect(sharpNames.map((n) => parseNote(n))).toEqual([
      24,25,26,27,28,29,30,31,32,33,34,35,36
github leafo / sightreading.training / static / js / data.es6 View on Github external
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
  }
}
github leafo / sightreading.training / static / js / song_note_list.es6 View on Github external
}

        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")
        }
      }
    })
github leafo / sightreading.training / static / js / components / pages / play_along_page.es6 View on Github external
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
github leafo / sightreading.training / static / js / note_list.es6 View on Github external
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)
      }

    }
  }
github leafo / sightreading.training / static / js / components / pages / play_along_page.es6 View on Github external
onNoteStop(note) {
    if (this.state.playNotes && this.props.midiOutput) {
      this.props.midiOutput.noteOff(parseNote(note.note), 100)
    }
  }
github leafo / sightreading.training / static / js / components / staves.es6 View on Github external
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) =&gt; {
        let fromTop = topOffset - noteStaffOffset(n);
        let style = {
          top: `${Math.floor(fromTop * 25/2)}%`,
          left: `${i * 20}px`</div>