Une bibliothèque Lua autour de la théorie musicale (cf Github).
Quelques remarques :
print
pour afficher les valeurs
entrées, et les valeurs des tableaux sont montrées ;show
plutôt que print
;
Ctrl+L
efface la fenêtre des sorties ;nil
signifie « absence de valeur », vous avez donc
tapé quelque chose que le système n’a pas compris.Constantes qui correspondent à un nom de note :
Dans l’ordre alphabétique : A Ab Af As B Bb Bbb Bf Bff Bs C C2s Cb Cf Cs D Db Df Do Do2d Dob Dod Ds E Eb Ebb Ef Eff Es F F2s Fa Fa2d Fab Fad Fb Ff Fs G Gb Gf Gs La Lab Lad Mi Mib Mibb Mid Re Reb Red Si Sib Sibb Sid Sol Solb Sold.
Constantes représentant une note, dont la valeur est le numéro MIDI correspondant (l’octave va de 0 à 9, A4 vaut par exemple 69, b représente un bémol (notation francophone et anglophone), f et s signifient resp. « flat » et « sharp », d signifie « dièse », bb ou ff double bémol, 2s ou 2d double dièse) :
Certains tests dépendent de la configuration par défaut :
LANG_NOTE_NAMES = 'fr'
«en» pour A B C, «fr» pour Do Re MiLANG_FLATS_STYLE = 'b'
seulement valable pour les notes en anglais, b ou fLANG_CHORD_NAMES = 'en'
si vide, le système utilise LANG_NOTE_NAMES
Si les tests ne sont pas suffisants pour comprendre le rôle de la fonction, d’autres commentaires (en anglais) figurent dans le code source.
Deg Deg: Deg(1) + Deg(3, -1) => Deg(3, -1) Deg: I => Deg(1) Deg: II + Deg(2) => Deg(3) Deg: tostring(Deg(1) + Deg(3, -1)) => "bIII" Deg: tostring(I) => "I" chromatic_jump chromatic_jump( C, 2) => Re chromatic_jump(Do, 1) => Reb chromatic_jump(Do, 2) => Re chromatic_jump(Do, -1) => Si chromatic_jump(Do, -2) => Sib chromatic_jump(Eb, 2) => Fa chromatic_jump(Mi, 1) => Fa chromatic_jump(Mi, 2) => Fad fifth_name fifth_name(A) => E fifth_name(G) => D fifth_name(La) => Mi fifth_name(Sol) => Re fourth_name fourth_name(A) => D fourth_name(G) => C fourth_name(La) => Re fourth_name(Sol) => Do midi_diff midi_diff(A, A) => 0 midi_diff(A, G) => 2 midi_diff(Ab, A) => -1 midi_diff(As, A) => 1 midi_diff(B , C) => -1 midi_diff(C , B) => 1 mode mode( 0, "M" ) => {Do, Re, Mi , Fa, Sol, La , Si} mode( 3, "m" ) => {Fad, Sold, La, Si, Dod, Re, Mi} mode(-3, "m" ) => {Do, Re, Mib, Fa, Sol, Lab, Sib} mode(-3, "mh") => {Do, Re, Mib, Fa, Sol, Lab, Si} mode(-3, "mm") => {Do, Re, Mib, Fa, Sol, La , Si} name_and_alteration name_and_alteration(A ) => A, 0 name_and_alteration(Ab) => A, -1 name_and_alteration(As) => A, 1 name_and_alteration(La ) => La, 0 name_and_alteration(Lab) => La, -1 name_and_alteration(Lad) => La, 1 name_and_alteration(Sib) => Si, -1 name_to_note_name name_to_note_name(C ) => Do name_to_note_name(Cs) => Dod name_to_note_name(Do) => Do name_to_note_name(Dod) => Dod next_name next_name(A) => B next_name(Ab) => B next_name(As) => B next_name(G) => A next_name(Gb) => A next_name(Gs) => A next_name(La) => Si next_name(Lab) => Si next_name(Lad) => Si next_name(Sol) => La next_name(Solb) => La next_name(Sold) => La note_name_to_chord_name note_name_to_chord_name(Do) => C note_name_to_chord_name(Dod) => Cs note_name_to_chord_name(Re) => D note_name_to_chord_name(Red) => Ds offset_in_circle offset_in_circle(1, 7, 1) => 2 offset_in_circle(7, 7, 1) => 1 previous_name previous_name(A) => G previous_name(Ab) => G previous_name(As) => G previous_name(B) => A previous_name(Bb) => A previous_name(Bs) => A previous_name(La) => Sol previous_name(Lab) => Sol previous_name(Lad) => Sol previous_name(Si) => La previous_name(Sib) => La previous_name(Sid) => La second_name second_name(A) => B second_name(G) => A second_name(La) => Si second_name(Sol) => La seventh_name seventh_name(A) => G seventh_name(B) => A seventh_name(La) => Sol seventh_name(Si) => La sixth_name sixth_name(A) => F sixth_name(B) => G sixth_name(La) => Fa sixth_name(Si) => Sol third_name third_name(A) => C third_name(G) => B third_name(La) => Do third_name(Sol) => Si
→ for i=-6, 6 do print(i) show(mode(i, "M")) end -6 {Solb, Lab, Sib, Dob, Reb, Mib, Fa} -5 {Reb, Mib, Fa, Solb, Lab, Sib, Do} -4 {Lab, Sib, Do, Reb, Mib, Fa, Sol} -3 {Mib, Fa, Sol, Lab, Sib, Do, Re} -2 {Sib, Do, Re, Mib, Fa, Sol, La} -1 {Fa, Sol, La, Sib, Do, Re, Mi} 0 {Do, Re, Mi, Fa, Sol, La, Si} 1 {Sol, La, Si, Do, Re, Mi, Fad} 2 {Re, Mi, Fad, Sol, La, Si, Dod} 3 {La, Si, Dod, Re, Mi, Fad, Sold} 4 {Mi, Fad, Sold, La, Si, Dod, Red} 5 {Si, Dod, Red, Mi, Fad, Sold, Lad} 6 {Fad, Sold, Lad, Si, Dod, Red, Mid} → for i=-6, 6 do print(i) show(mode(i, "m")) end -6 {Mib, Fa, Solb, Lab, Sib, Dob, Reb} -5 {Sib, Do, Reb, Mib, Fa, Solb, Lab} -4 {Fa, Sol, Lab, Sib, Do, Reb, Mib} -3 {Do, Re, Mib, Fa, Sol, Lab, Sib} -2 {Sol, La, Sib, Do, Re, Mib, Fa} -1 {Re, Mi, Fa, Sol, La, Sib, Do} 0 {La, Si, Do, Re, Mi, Fa, Sol} 1 {Mi, Fad, Sol, La, Si, Do, Re} 2 {Si, Dod, Re, Mi, Fad, Sol, La} 3 {Fad, Sold, La, Si, Dod, Re, Mi} 4 {Dod, Red, Mi, Fad, Sold, La, Si} 5 {Sold, Lad, Si, Dod, Red, Mi, Fad} 6 {Red, Mid, Fad, Sold, Lad, Si, Dod} → for i=-6, 6 do print(i) show(mode(i, "mh")) end -6 {Mib, Fa, Solb, Lab, Sib, Dob, Re} -5 {Sib, Do, Reb, Mib, Fa, Solb, La} -4 {Fa, Sol, Lab, Sib, Do, Reb, Mi} -3 {Do, Re, Mib, Fa, Sol, Lab, Si} -2 {Sol, La, Sib, Do, Re, Mib, Fad} -1 {Re, Mi, Fa, Sol, La, Sib, Dod} 0 {La, Si, Do, Re, Mi, Fa, Sold} 1 {Mi, Fad, Sol, La, Si, Do, Red} 2 {Si, Dod, Re, Mi, Fad, Sol, Lad} 3 {Fad, Sold, La, Si, Dod, Re, Mid} 4 {Dod, Red, Mi, Fad, Sold, La, Sid} 5 {Sold, Lad, Si, Dod, Red, Mi, Fa2d} 6 {Red, Mid, Fad, Sold, Lad, Si, Do2d} → for i=-6, 6 do print(i) show(mode(i, "mm")) end -6 {Mib, Fa, Solb, Lab, Sib, Do, Re} -5 {Sib, Do, Reb, Mib, Fa, Sol, La} -4 {Fa, Sol, Lab, Sib, Do, Re, Mi} -3 {Do, Re, Mib, Fa, Sol, La, Si} -2 {Sol, La, Sib, Do, Re, Mi, Fad} -1 {Re, Mi, Fa, Sol, La, Si, Dod} 0 {La, Si, Do, Re, Mi, Fad, Sold} 1 {Mi, Fad, Sol, La, Si, Dod, Red} 2 {Si, Dod, Re, Mi, Fad, Sold, Lad} 3 {Fad, Sold, La, Si, Dod, Red, Mid} 4 {Dod, Red, Mi, Fad, Sold, Lad, Sid} 5 {Sold, Lad, Si, Dod, Red, Mid, Fa2d} 6 {Red, Mid, Fad, Sold, Lad, Sid, Do2d}