Class Chord

Chord building, accept more notations than builtin HA chords.

Accepts also strings that look pretty with My Chord font but means nothing (", ', ! for °, Ø, Δ)...

Section

SectionSummary
ChordsChord class and other chords utility functions, like extracting chords from the chord line of a staff.

Summary

FieldTypeSummary
BassOctaveintOctave of the bass
ChordOctaveintOctave of the fundamental of the chord, before inversion
InversionintChord inversion: fundamental state, 1 to 4 up, 1 to 4 one octave down.
IsAugmentedboolIs this chord augmented?
IsDiminishedboolIs this chord diminished?
IsMajorboolIs this chord major?
IsMinorboolIs this chord minor?
Return typeFunction and summary
Chordnew(string chordName, Chord previousChord)
Build a chord from its name
tablebassNote()
Get the bass note Anglo-Saxon name, pitch and accidental.
tablenotes(int numberOfNotes)
Get the chord's notes in notes anglo-saxon names, pitch and preferred accidental.
intnumberOfNotes()
Get the number of notes in the chord.
stringtoASCIIName()
Get the ASCII name of the Chord.
stringtoNumbers()
Get the chord in numbers, for example 1 3 5 for major, 1 3b 5 for minor.

Fields

int Chord:ChordOctave

Octave of the fundamental of the chord, before inversion

int Chord:BassOctave

Octave of the bass

int Chord:Inversion

Chord inversion: fundamental state, 1 to 4 up, 1 to 4 one octave down.

One of these constants from MSDefine:

  • INVERSION_FUNDAMENTAL
  • INVERSION_1ST
  • INVERSION_2ND
  • INVERSION_3RD
  • INVERSION_4TH
  • INVERSION_1ST_BOTTOM
  • INVERSION_2ND_BOTTOM
  • INVERSION_3RD_BOTTOM
  • INVERSION_4TH_BOTTOM

bool Chord:IsMajor

Is this chord major?

bool Chord:IsMinor

Is this chord minor?

bool Chord:IsDiminished

Is this chord diminished?

bool Chord:IsAugmented

Is this chord augmented?

Methods

Chord:new(string chordName, Chord previousChord)

Build a chord from its name

ParameterTypeDefaultDescription
chordNamestring Chord name, for example F#m, FaØ, Réb/Sib, C#dim7, Lamadd9
previousChordChordnilIf this chord is only a bass movement (for example /Bb, use the previous chord to complete it
Return
Chord: A chord object.

Chord:toASCIIName()

Get the ASCII name of the Chord.

Sharp and flats are # and b, natural is =, Δ is Maj7, and Ø is m7b5.

Return
string:

Chord:numberOfNotes()

Get the number of notes in the chord.

Bass is omitted.

Return
int:

Chord:toNumbers()

Get the chord in numbers, for example 1 3 5 for major, 1 3b 5 for minor.

Return
string:

Chord:notes(int numberOfNotes)

Get the chord's notes in notes anglo-saxon names, pitch and preferred accidental.

The structure returned is a indexed table. Each element is a table with following properties:

  • RealName: Real name of note, may be incompatible with HA in extrema.
  • CompatibleName: sanitized name compatible with HA, Symbol.AngloSaxonName
  • Pitch: Pitch between 0 and 127
  • Accidental: constant from MSDefine (NATURAL, SHARP, FLAT...) for Symbol.Accidental
local c = Chord:new("C#Maj7")
local notes = c:notes()
print(getn(notes)) --> 4
print(notes[1].RealName) --> "C#4"
print(notes[1].CompatibleName) --> "C#4"
print(notes[1].Pitch) --> 61
print(notes[1]) --> Accidental=SHARP
print(notes[2].RealName) --> "E4"
print( notes[2].Pitch) --> 64
print(notes[2].Accidental) --> NATURAL
-- ...
Bass note is not returned.

ParameterTypeDefaultDescription
numberOfNotesintnilMinimum number of notes for the chord. 4 notes for C returns C E G + C. If the chord contains more notes, it won't be limited to this parameter: 4 notes for C9 returns C E G Bb D. If nil, no minimum of number of notes.
Return
table:
See
Chord:bassNote

Chord:bassNote()

Get the bass note Anglo-Saxon name, pitch and accidental.

The structure returned is a table similar to one element (one note) returned by Chord:notes().

This table properties are:

  • RealName: Real name of note, may be incompatible with HA in extrema.
  • CompatibleName: sanitized name compatible with HA, Symbol.AngloSaxonName
  • Pitch: Pitch between 0 and 127
  • Accidental: constant from MSDefine (NATURAL, SHARP, FLAT...) for Symbol.Accidental
D/C will return this table:
local c = Chord:new("D/C")
local bass = c:bassNote()
print(bass.RealName) --> "C2"
print(bass.CompatibleName) --> "C2"
print(bass.Pitch) --> 36
print(bass.Accidental) --> NATURAL

Return
table: