-
Notifications
You must be signed in to change notification settings - Fork 0
Home
The chord_list dictionary defines various chords, detailing their structure based on intervals (measured in semitones). Each chord is represented by an array of semitones that define its unique sound when constructed from a root note.
This section will help you understand:
- How chords are defined and constructed.
- Examples of generating chords.
- A full list of available chords in the library.
A chord is a combination of two or more notes played together, forming harmony. For instance:
- A major chord has the formula
[root, +4 semitones, +7 semitones]. - A minor chord differs slightly with the formula
[root, +3 semitones, +7 semitones].
Chords can have variations like 7ths, 9ths, augmented, diminished, and more, each adding richness to the sound.
The chord_list dictionary provides chord formulas in semitones relative to the root note. You can use these formulas to calculate the actual notes of the chord in any key.
To construct a C Major chord (maj):
- Start with the root note,
C. - Add the semitones from the
chord_list['maj']formula:[4, 7].-
C+4 semitones=E -
C+7 semitones=G
-
- The C Major chord is
C-E-G.
The get_chord function allows you to generate the notes of a specific chord based on a root note and a chord type. It utilizes the chord_list dictionary to determine the intervals for the requested chord.
def get_chord(root: str, chord_type: str) -> list:
"""
Generate the notes of a chord based on the root note and chord type.
Args:
root (str): The root note as a string.
chord_type (str): The type of chord to generate (e.g., 'maj', 'min', 'dim').
Returns:
list: A list of notes for the chord.
"""- The function takes two parameters:
-
rootan string like (A,A#,B,...). -
chord_type(the type of chord from thechord_listdictionary).
-
- It calculates the chord by adding the intervals defined in
chord_list[chord_type]to the root note.
from pysongtool import PySongTool
tool = PySongTool()
root = G
chord_type = 'min'
g_minor_chord = tool.get_chord(root, chord_type)
print(g_minor_chord) # Output: [G, A#, D]The all_chords function generates a dictionary of all possible chords for a given root note. It is useful when you want to see all chord variations available for a specific note.
def all_chords(root: str) -> dict:
"""
Generate all available chords for a given root note.
Args:
root (str): The root note as a string.
Returns:
dict: A dictionary where keys are chord types and values are lists of notes.
"""- The function takes one parameter:
-
rootThe root note as a string..
-
- It iterates through all available chord types in the
chord_listdictionary and calculates the corresponding notes for each chord. - Returns a dictionary with chord types as keys and the generated notes as values.
from pysongtool import PySongTool
tool = PySongTool()
root = C
c_all_chords = tool.all_chords(root)
print(c_all_chords)
# Output:
# {
# 'maj': [C, E G], # C Major
# 'min': [C, D#, G], # C Minor
# 'dim': [C, D#, F#], # C Diminished
# 'maj7': [C, E, G, A#], # C Major 7th
# 'min7': [C, D#, G, A#], # C Minor 7th
# ...
# }If you know the root note and chord type you need, use get_chord to quickly generate it.
from pysongtool import PySongTool
tool = PySongTool()
root = D
chord_type = 'maj7'
d_maj7 = tool.get_chord(root, chord_type)
print(d_maj7) # Output: [D, F#, A,C#]When you want to explore all possible chord variations for a particular note, use all_chords.
from pysongtool import PySongTool
tool = PySongTool()
root = A
a_all_chords = tool.all_chords(root)
print(a_all_chords)
# Output:
# {
# 'maj': [A, C#, E], # A Major
# 'min': [A, C, E], # A Minor
# ...
# }| Function | Purpose | Input | Output |
|---|---|---|---|
get_chord |
Generate a specific chord for a root note. |
root, chord_type (str) |
List of notes. |
all_chords |
Generate all chords for a given root note. | root |
Dict of all chord types with notes. |
Below is the complete list of available chords in the chord_list dictionary:
| Chord Name | Semitone Intervals | Description |
|---|---|---|
maj |
[4, 7] |
Major |
maj7 |
[4, 7, 10] |
Major 7th |
maj7M |
[4, 7, 11] |
Major 7th (Modified) |
min |
[3, 7] |
Minor |
min7 |
[3, 7, 10] |
Minor 7th |
min7M |
[3, 7, 11] |
Minor 7th (Modified) |
sus2 |
[2, 7] |
Suspended 2nd |
sus4 |
[5, 7] |
Suspended 4th |
6 |
[4, 7, 9] |
Major 6th |
dim |
[3, 6, 10] |
Diminished |
maj9 |
[4, 7, 10, 14] |
Major 9th |
min9 |
[3, 7, 10, 14] |
Minor 9th |
maj11 |
[4, 7, 10, 14, 17] |
Major 11th |
min11 |
[3, 7, 10, 14, 17] |
Minor 11th |
maj13 |
[4, 7, 10, 14, 17, 21] |
Major 13th |
min13 |
[3, 7, 10, 14, 17, 21] |
Minor 13th |
7 |
[4, 7, 10] |
Dominant 7th |
7b5 |
[4, 7, 9, 10] |
Dominant 7th Flat 5 (Altered) |
7b9 |
[4, 7, 10, 13] |
Dominant 7th Flat 9 |
7#9 |
[4, 7, 10, 14] |
Dominant 7th Sharp 9 |
aug |
[4, 8] |
Augmented |
aug7 |
[4, 8, 10] |
Augmented 7th |
dim7 |
[3, 6, 9] |
Diminished 7th |
half-dim |
[3, 6, 10] |
Half-Diminished (m7b5) |
9 |
[4, 7, 10, 14] |
Dominant 9th |
add9 |
[4, 7, 14] |
Major Add 9 |
madd9 |
[3, 7, 14] |
Minor Add 9 |
- Each chord formula is based on semitone intervals.
- You can construct chords for any root note using these formulas.
- The library supports basic chords (e.g.,
maj,min) as well as extended chords (e.g.,maj13,dim7).