Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SmoMusic

Helper functions that build on the VX music theory routines, and other utilities I wish were in VF.Music but aren't

Note on pitch and duration format

We use some VEX music theory routines and frequently need to convert formats from SMO format. We also use the same 'ticks' abstraction for durations.

Smo uses pitch JSON:

    {note:'c',accidental:'#',octave:4}

Vex usually uses a canonical string:

`'c#/4'`

Depending on the operation, the octave might be omitted

Smo uses a JSON for duration always:

    {numerator:4096,denominator:1,remainder:0}

Vex uses a letter duration ('4' or 'q'for 1/4 note) and 'd' for dot.

I try to indicate whether I am using vex or smo notation in the function name. Duration methods start around line 1100

Hierarchy

  • SmoMusic

Index

Constructors

Properties

clefSigns: Record<string, ClefSign> = ...

an array of clefs and the xml information they map to

Accessors

  • The purpose of this table is to keep consistent enharmonic spelling when transposing instruments in different keys. It is not theoritically complete, e.g. there is no reason to distinguish between #5 used as a leading tone for vi- or as an augmented chord, the spelling is the same. It does not show a preference for notes that don't have an obvious purpose in the key, e.g. it does not try to compute the equivalent to 'e#' in the key of 'c'. The computation of the 'intended key area' is beyond the scope of a music program to interpret.

    Returns Record<string, KeySignatureRole[]>

  • get enharmonics(): Record<string, string[]>
  • return a map of enharmonics for choosing or cycling. notes are in vexKey form.

    Returns Record<string, string[]>

Methods

  • _pitchToVexKey(smoPitch: Pitch): string
  • convert from SMO to VEX format so we can use the VexFlow tables and methods example: {letter,octave,accidental} object to vexKey string 'f#'

    Parameters

    Returns string

  • addFlats(smoPitch: Pitch, distance: number): Pitch
  • addSharps(smoPitch: Pitch, distance: number): Pitch
  • circleOfFifthsIndex(smoPitch: Pitch): number
  • gives the index into circle-of-fifths array for a pitch, considering enharmonics.

    Parameters

    Returns number

  • closestTonic(smoPitch: Pitch, vexKey: string, direction: number): Pitch
  • findPitchForRole(role: string, keySignature: string, transposedPitch: Pitch): Pitch
  • Given a harmonic role, find the pitch that matches it. If there is no one, just return the raw transposition

    Parameters

    • role: string
    • keySignature: string
    • transposedPitch: Pitch

    Returns Pitch

  • findRoleOfPitch(smoPitch: Pitch, keySignature: string): string
  • gcdMap(duration: number): number[]
  • break the duration up into an array of durations, to split a long note up between bars when pasting.

    Parameters

    • duration: number

    Returns number[]

  • getEnharmonic(vexKey: string): string
  • return the next note from the cycle in getEnharmonics

    Parameters

    • vexKey: string

    Returns string

  • getEnharmonicInKey(smoPitch: Pitch, keySignature: string): Pitch
  • When transposing, get the enharmonic that most closely fits the key getEnharmonicInKey returns an alternate to the given pitch, or the same pitch. getKeyFriendlyEnharmonic return a pitch for a given key, given the letter name only

    Parameters

    • smoPitch: Pitch
    • keySignature: string

    Returns Pitch

  • getEnharmonics(vexKey: string): string[]
  • Get enharmonic equivalent of given notes for cycle/choose

    Parameters

    • vexKey: string

    Returns string[]

  • getKeyFriendlyEnharmonic(letter: string, keySignature: string): string
  • fix the enharmonic to match the key, if possible

    example

    getKeyFriendlyEnharmonic('b','eb'); => returns 'bb' return vex string getEnharmonicInKeyreturns an alternate to the given pitch, or the same pitch.getKeyFriendlyEnharmonic` return a pitch for a given key, given the letter name only

    Parameters

    • letter: string
    • keySignature: string

    Returns string

  • getKeySignatureKey(letter: PitchLetter, keySignature: string): string
  • // given a letter pitch (a,b,c etc.), and a key signature, return the actual note // that you get without accidentals // SmoMusic.getKeySignatureKey('F','G'); // returns f#

    Parameters

    Returns string

  • midiPitchToSmoPitch(midiPitch: string): Pitch
  • notesFromLetters(startPitch: Pitch, clef: Clef, keySignature: string, duration: string, letters: string): SmoNote[]
  • Convenience function to create SmoNote[] from letters, with the correct accidental for the key signature, given duration, etc

    Parameters

    • startPitch: Pitch

      the pitch used to calculate the octave of the new note

    • clef: Clef
    • keySignature: string
    • duration: string

      vex duration

    • letters: string

      string of PitchLetter

    Returns SmoNote[]

  • pitchArraysMatch(ar1: Pitch[], ar2: Pitch[]): boolean
  • pitchToEasyScore(smoPitch: Pitch): string
  • convert smo pitch to easy score (vex) format. Mostly used for debugging and generating Vex test cases

    Parameters

    Returns string

    • a string that can be converted to a VEX routine, with some difficulty
  • pitchToLedgerLine(clef: Clef, pitch: Pitch): number
  • Return the number of ledger lines based on the pitch and clef

    Parameters

    Returns number

    number where 0 is the top staff line

  • pitchToStaffLine(clef: Clef, pitch: Pitch): number
  • Return the number of ledger lines based on the pitch and clef

    Parameters

    Returns number

    number where 0 is the top staff line

  • smoIntToPitch(intValue: number): Pitch
  • smoPitchToInt(pitch: Pitch): number
  • convert a pitch to an integer value, used for transpositions, intervals, etc.

    Parameters

    Returns number

  • smoPitchToMidiString(smoPitch: Pitch): string
  • convert a pitch to a format expected by the MIDI writer

    Parameters

    • smoPitch: Pitch

      pitch to convert

    Returns string

    pitch in MIDI string format.

  • smoPitchesToIntArray(pitches: Pitch[]): number[]
  • convert pitches to integer pitch representations by calling smoPitchToInt

    Parameters

    • pitches: Pitch[]

      Smo pitches

    Returns number[]

  • smoPitchesToVexKeys(pitchAr: Pitch[], keyOffset: number, noteHead: null | string): string[]
  • Convert array of smo pitches to vex keys, with adjustment for transpose and notehead

    Parameters

    • pitchAr: Pitch[]
    • keyOffset: number
    • noteHead: null | string

    Returns string[]

    • array of vex keyx
  • return true if the pitches match, except for octave. { letter: 'a', accidental: '#'}, { letter: 'a', accidental: '#'} returns true { letter: 'a', accidental: '#'}, { letter: 'b', accidental: 'b'} returns false

    Parameters

    Returns boolean

  • splitIntoValidDurations(ticks: number): number[]
  • Return array of valid note-lengths from an odd number of ticks, so we can come as close as possible to representing the ticks with notes

    Parameters

    • ticks: number

    Returns number[]

  • vexKeySigWithOffset(vexKey: string, offset: number): string
  • Consider instrument transpose when setting key - e.g. Eb for Bb instruments is F. Note: return value is not a valid VEX key signature. Use vexKeySignatureTranspose for that.

    Parameters

    • vexKey: string
    • offset: number

    Returns string

  • vexKeySignatureTranspose(key: string, transposeIndex: number): string
  • return the key signature, transposed a number of 1/2 steps in Vex key format

    Parameters

    • key: string

      start key

    • transposeIndex: number

      number of 1/2 steps

    Returns string

    • vex key
  • vexToCannonical(vexKey: string): string
  • return Vex canonical note enharmonic - e.g. Bb to A#

    Parameters

    • vexKey: string

    Returns string

  • vexToSmoPitch(vexPitch: string): Pitch

Generated using TypeDoc