At the beginning of the question, we were given a lista
, call for notas
, that is to say...
notas = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
This list is nothing more than the chromatic scale of Dó
. In this situation we don’t have modos
(mode major or minor).
Of course, on this list, in addition to the natural notes (C, D, E, F, G, A, B)
, we also have the bumpy notes (C#, D#, F#, G#, A#)
, that we can also call banknotes sustenizadas
.
These notes, they’re not inside the list by chance. Yeah, they’re also podem formar
chords. In this case, it is the sharp chords.
In the case of chord formation, there are several guys. For agility purposes, in this post, I will focus only on the chord Greater. For - in its most basic form - it is formed by only three notes and two intervals.
As notes evening:
- Tonic: 1st degree of scale;
- By means of: 3rd degree of scale;
- Dominant: 5th degree of scale.
And the breaks will be:
- Tuesday: 4 semitones between tonic and upon;
- Thursday: 7 semitones between tonic and dominant.
Observing: Intervals shall always be counted from tonic.
Adopting the tonic as being the bass of the chord, that is, positioning the tonic as the most serious note of the chord (1st note of the chord), we can implement the following script.
notas = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
while (baixo := input('Baixo do acorde desejado: ').upper()) not in notas:
print('Valor INVÁLIDO!')
triade = [notas[(notas.index(baixo) + i) % 12] for i in (0, 4, 7)]
print(f'{baixo}M:', *triade)
This script requests the bass of the desired chord. Then it checks whether the bottom typed by the user is, in fact, valid, that is, checks whether the bottom typed by the user, in fact, is in the list notes. While the entered value is invalid, the script will display an error message and prompt the chord bass again. If the entered value is valid, the program will advance its execution.
Next time, the script will mount the desired chord with the help of list comprehension.
Note that in this step the block for go through the tuple (0, 4, 7). This tuple is formed by the size of the respective ranges.
The 0, is the null range. The value 4 corresponds to the range of tuesday and the value 7, corresponds to the range of just fifth.
For each loop iteration the respective desired note is mounted, obtaining with the following code:
notas[(notas.index(baixo) + i) % 12]
The function of this code is basically to identify the note, whose bottom index is in the list notes. And, for this, it is calculated the REMNANT of the actual division between the sum of (notes.index(low) with its said interval i and the value 12. The value 12 matches the list size notes.
Once mounted the chord it will be displayed using the following format:
print(f'{baixo}M:', *triade)
This format displays the name of bass together with the designation of major (M), followed by two points ":" and followed by the unpacking of the triad (*Triad).
Testing the code:
When executing the code and entering the value...
A
...and press Enter, we will get as a result:
AM: A C# E
In this way, we received as a result the name of the chord, along with its way, together with the notes of the abovementioned agreement.