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

- constructor

### Properties

- clefSigns

### Accessors

- circleOfFifths
- enharmonicRoles
- enharmonics
- noteValues

### Methods

- _pitchToVexKey
- addFlat
- addFlats
- addSharp
- addSharps
- circleOfFifthsIndex
- closestTonic
- findPitchForRole
- findRoleOfPitch
- flagStateFromNote
- gcdMap
- getEnharmonic
- getEnharmonicInKey
- getEnharmonics
- getKeyFriendlyEnharmonic
- getKeyOffset
- getKeySignatureKey
- letterChangedOctave
- midiPitchToSmoPitch
- notesFromLetters
- pitchArraysMatch
- pitchToEasyScore
- pitchToLedgerLine
- pitchToStaffLine
- smoIntToPitch
- smoPitchToInt
- smoPitchToMidiString
- smoPitchesToIntArray
- smoPitchesToVexKeys
- smoScalePitchMatch
- splitIntoValidDurations
- vexKeySigWithOffset
- vexKeySignatureTranspose
- vexToCannonical
- vexToSmoKey
- vexToSmoPitch

## Constructors

### constructor

- new SmoMusic(): SmoMusic

- #### Returns SmoMusic

## Properties

### Static clefSigns

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

- Defined in src/smo/data/music.ts:384

an array of clefs and the xml information they map to

## Accessors

### Static circleOfFifths

- get circleOfFifths(): PitchKey[]

- - Defined in src/smo/data/music.ts:201

  A note array (sans octave) in key-signature order

  #### Returns PitchKey[]

### Static enharmonicRoles

- get enharmonicRoles(): Record<string, KeySignatureRole[]>

- - Defined in src/smo/data/music.ts:408

  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[]>

### Static enharmonics

- get enharmonics(): Record<string, string[]>

- - Defined in src/smo/data/music.ts:950

  return a map of enharmonics for choosing or cycling. notes are in vexKey form.

  #### Returns Record<string, string[]>

### Static noteValues

- get noteValues(): Record<string, VexNoteValue>

- - Defined in src/smo/data/music.ts:144

  Ported from vex, used to convert pitches to numerical values

  #### Returns Record<string, VexNoteValue>

## Methods

### Static _pitchToVexKey

- _pitchToVexKey(smoPitch: Pitch): string

- - Defined in src/smo/data/music.ts:722

  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

  - ##### smoPitch: Pitch

  #### Returns string

### Static addFlat

- addFlat(smoPitch: Pitch): Pitch

- - Defined in src/smo/data/music.ts:268

  Get pitch to the left in circle of fifths

  #### Parameters

  - ##### smoPitch: Pitch

  #### Returns Pitch

### Static addFlats

- addFlats(smoPitch: Pitch, distance: number): Pitch

- - Defined in src/smo/data/music.ts:295

  Add distance sharps/flats to given key

  #### Parameters

  - ##### smoPitch: Pitch

  - ##### distance: number

  #### Returns Pitch

### Static addSharp

- addSharp(smoPitch: Pitch): Pitch

- - Defined in src/smo/data/music.ts:259

  Get pitch to the right in circle of fifths

  #### Parameters

  - ##### smoPitch: Pitch

  #### Returns Pitch

### Static addSharps

- addSharps(smoPitch: Pitch, distance: number): Pitch

- - Defined in src/smo/data/music.ts:277

  Add @param {number} - sharps

  #### Parameters

  - ##### smoPitch: Pitch

  - ##### distance: number

  #### Returns Pitch

### Static circleOfFifthsIndex

- circleOfFifthsIndex(smoPitch: Pitch): number

- - Defined in src/smo/data/music.ts:245

  gives the index into circle-of-fifths array for a pitch, considering enharmonics.

  #### Parameters

  - ##### smoPitch: Pitch

  #### Returns number

### Static closestTonic

- closestTonic(smoPitch: Pitch, vexKey: string, direction: number): Pitch

- - Defined in src/smo/data/music.ts:1006

  Return a pitch a diatonic step away from SmoPitch in vexKey

  #### Parameters

  - ##### smoPitch: Pitch

  - ##### vexKey: string

  - ##### direction: number

  #### Returns Pitch

### Static findPitchForRole

- findPitchForRole(role: string, keySignature: string, transposedPitch: Pitch): Pitch

- - Defined in src/smo/data/music.ts:690

  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

### Static findRoleOfPitch

- findRoleOfPitch(smoPitch: Pitch, keySignature: string): string

- - Defined in src/smo/data/music.ts:671

  Find the harmonic role for the given pitch

  #### Parameters

  - ##### smoPitch: Pitch

  - ##### keySignature: string

  #### Returns string

### Static flagStateFromNote

- flagStateFromNote(clef: Clef, note: SmoNote): number

- - Defined in src/smo/data/music.ts:372

  return flag state (up === 1 or down === 2) based on pitch and clef if auto

  #### Parameters

  - ##### clef: Clef

  - ##### note: SmoNote

  #### Returns number

### Static gcdMap

- gcdMap(duration: number): number[]

- - Defined in src/smo/data/music.ts:1616

  break the duration up into an array of durations, to split a long note up between bars when pasting.

  #### Parameters

  - ##### duration: number

  #### Returns number[]

### Static getEnharmonic

- getEnharmonic(vexKey: string): string

- - Defined in src/smo/data/music.ts:987

  return the next note from the cycle in `getEnharmonics`

  #### Parameters

  - ##### vexKey: string

  #### Returns string

### Static getEnharmonicInKey

- getEnharmonicInKey(smoPitch: Pitch, keySignature: string): Pitch

- - Defined in src/smo/data/music.ts:1045

  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

### Static getEnharmonics

- getEnharmonics(vexKey: string): string[]

- - Defined in src/smo/data/music.ts:972

  Get enharmonic equivalent of given notes for cycle/choose

  #### Parameters

  - ##### vexKey: string

  #### Returns string[]

### Static getKeyFriendlyEnharmonic

- getKeyFriendlyEnharmonic(letter: string, keySignature: string): string

- - Defined in src/smo/data/music.ts:1096

  fix the enharmonic to match the key, if possible

  example

    `getKeyFriendlyEnharmonic('b','eb'); => returns 'bb' return vex string` 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

  - ##### letter: string

  - ##### keySignature: string

  #### Returns string

### Static getKeyOffset

- getKeyOffset(pitch: Pitch, offset: number): Pitch

- - Defined in src/smo/data/music.ts:1287

  Transpose a `Pitch` `offset` 1/2 steps

  #### Parameters

  - ##### pitch: Pitch

  - ##### offset: number

  #### Returns Pitch

### Static getKeySignatureKey

- getKeySignatureKey(letter: PitchLetter, keySignature: string): string

- - Defined in src/smo/data/music.ts:1124

  // 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

  - ##### letter: PitchLetter

  - ##### keySignature: string

  #### Returns string

### Static letterChangedOctave

- letterChangedOctave(one: PitchLetter, two: PitchLetter): number

- - Defined in src/smo/data/music.ts:1269

  Indicate if a change from letter note 'one' to 'two' needs us to adjust the octave due to the `SmoMusic.letterPitchIndex` (b0 is higher than c0)

  #### Parameters

  - ##### one: PitchLetter

  - ##### two: PitchLetter

  #### Returns number

### Static midiPitchToSmoPitch

- midiPitchToSmoPitch(midiPitch: string): Pitch

- - Defined in src/smo/data/music.ts:775

  filled in from the midi routines borrowed from // https://github.com/grimmdude/MidiWriterJS

  #### Parameters

  - ##### midiPitch: string

    pitch from MIDIwrite

  #### Returns Pitch

  SMO pitch

### Static notesFromLetters

- notesFromLetters(startPitch: Pitch, clef: Clef, keySignature: string, duration: string, letters: string): SmoNote[]

- - Defined in src/smo/data/music.ts:1207

  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[]

### Static pitchArraysMatch

- pitchArraysMatch(ar1: Pitch[], ar2: Pitch[]): boolean

- - Defined in src/smo/data/music.ts:853

  compare pitches for frequency match

  #### Parameters

  - ##### ar1: Pitch[]

  - ##### ar2: Pitch[]

  #### Returns boolean

### Static pitchToEasyScore

- pitchToEasyScore(smoPitch: Pitch): string

- - Defined in src/smo/data/music.ts:742

  convert smo pitch to easy score (vex) format. Mostly used for debugging and generating Vex test cases

  #### Parameters

  - ##### smoPitch: Pitch

  #### Returns string

  - a string that can be converted to a VEX routine, with some difficulty

### Static pitchToLedgerLine

- pitchToLedgerLine(clef: Clef, pitch: Pitch): number

- - Defined in src/smo/data/music.ts:354

  Return the number of ledger lines based on the pitch and clef

  #### Parameters

  - ##### clef: Clef

  - ##### pitch: Pitch

  #### Returns number

  number where 0 is the top staff line

### Static pitchToStaffLine

- pitchToStaffLine(clef: Clef, pitch: Pitch): number

- - Defined in src/smo/data/music.ts:365

  Return the number of ledger lines based on the pitch and clef

  #### Parameters

  - ##### clef: Clef

  - ##### pitch: Pitch

  #### Returns number

  number where 0 is the top staff line

### Static smoIntToPitch

- smoIntToPitch(intValue: number): Pitch

- - Defined in src/smo/data/music.ts:902

  Convert a number to a SMO pitch

  #### Parameters

  - ##### intValue: number

    number of 1/2 steps from `c0`

  #### Returns Pitch

### Static smoPitchToInt

- smoPitchToInt(pitch: Pitch): number

- - Defined in src/smo/data/music.ts:886

  convert a pitch to an integer value, used for transpositions, intervals, etc.

  #### Parameters

  - ##### pitch: Pitch

  #### Returns number

### Static smoPitchToMidiString

- smoPitchToMidiString(smoPitch: Pitch): string

- - Defined in src/smo/data/music.ts:752

  convert a pitch to a format expected by the MIDI writer

  #### Parameters

  - ##### smoPitch: Pitch

    pitch to convert

  #### Returns string

  pitch in MIDI string format.

### Static smoPitchesToIntArray

- smoPitchesToIntArray(pitches: Pitch[]): number[]

- - Defined in src/smo/data/music.ts:873

  convert pitches to integer pitch representations by calling smoPitchToInt

  #### Parameters

  - ##### pitches: Pitch[]

    Smo pitches

  #### Returns number[]

### Static smoPitchesToVexKeys

- smoPitchesToVexKeys(pitchAr: Pitch[], keyOffset: number, noteHead: null | string): string[]

- - Defined in src/smo/data/music.ts:317

  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

### Static smoScalePitchMatch

- smoScalePitchMatch(p1: Pitch, p2: Pitch): boolean

- - Defined in src/smo/data/music.ts:339

  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

  - ##### p1: Pitch

  - ##### p2: Pitch

  #### Returns boolean

### Static splitIntoValidDurations

- splitIntoValidDurations(ticks: number): number[]

- - Defined in src/smo/data/music.ts:1516

  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[]

### Static vexKeySigWithOffset

- vexKeySigWithOffset(vexKey: string, offset: number): string

- - Defined in src/smo/data/music.ts:936

  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

### Static vexKeySignatureTranspose

- vexKeySignatureTranspose(key: string, transposeIndex: number): string

- - Defined in src/smo/data/music.ts:1227

  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

### Static vexToCannonical

- vexToCannonical(vexKey: string): string

- - Defined in src/smo/data/music.ts:193

  return Vex canonical note enharmonic - e.g. Bb to A#

  #### Parameters

  - ##### vexKey: string

  #### Returns string

### Static vexToSmoKey

- vexToSmoKey(vexPitch: string): PitchKey

- - Defined in src/smo/data/music.ts:822

  Convert to smo pitch, without octave `['f#'] => [{letter:'f',accidental:'#'}]`

  #### Parameters

  - ##### vexPitch: string

  #### Returns PitchKey

### Static vexToSmoPitch

- vexToSmoPitch(vexPitch: string): Pitch

- - Defined in src/smo/data/music.ts:804

  Turns vex pitch string into smo pitch, e.g. `cn/4 => {'c','n',4}`

  #### Parameters

  - ##### vexPitch: string

  #### Returns Pitch

  SmoPitch

Generated using TypeDoc