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.
IsAugmentedbooleanIs this chord augmented?
IsDiminishedbooleanIs this chord diminished?
IsMajorbooleanIs this chord major?
IsMinorbooleanIs this chord minor?
Return typeFunction and summary
Chordnew(string chordName, Chord previousChord, int chordOctave, int bassOctave, int inversion)
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

boolean Chord:IsMajor

Is this chord major?

boolean Chord:IsMinor

Is this chord minor?

boolean Chord:IsDiminished

Is this chord diminished?

boolean Chord:IsAugmented

Is this chord augmented?

Methods

Chord:new(string chordName, Chord previousChord, int chordOctave, int bassOctave, int inversion)

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
chordOctaveint4Octave of chord notes, 4 is the middle-C on piano, and the 440 Hz A.
bassOctaveint2Octave for basses
inversionintINVERSION_FUNDAMENTALChord inversion, 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
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: string

Chord:numberOfNotes()

Get the number of notes in the chord.

Bass is omitted.

Return
int: int

Chord:toNumbers()

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

Return
string: 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
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: table
See
Chord:bassNote
Example


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

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

Return
table: table
Example


 local c = Chord:new("D/C") -- D major + C bass
 local bass = c:bassNote()
 print(bass.RealName) --> "C2"
 print(bass.CompatibleName) --> "C2"
 print(bass.Pitch) --> 36
 print(bass.Accidental) --> NATURAL