Skip to content
Murilo R.B Silva edited this page Dec 20, 2024 · 1 revision

Chord Documentation

Overview

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:

  1. How chords are defined and constructed.
  2. Examples of generating chords.
  3. A full list of available chords in the library.

What is a Chord?

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.


How to Use the Chord List

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.

Example: Constructing a C Major Chord

To construct a C Major chord (maj):

  1. Start with the root note, C.
  2. Add the semitones from the chord_list['maj'] formula: [4, 7].
    • C + 4 semitones = E
    • C + 7 semitones = G
  3. The C Major chord is C-E-G.

Functions

1. get_chord

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.

Function Signature:

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

How It Works:

  • The function takes two parameters:
    1. root an string like (A,A#,B,...).
    2. chord_type (the type of chord from the chord_list dictionary).
  • It calculates the chord by adding the intervals defined in chord_list[chord_type] to the root note.

Example: Generate a G Minor Chord

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]

2. all_chords

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.

Function Signature:

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

How It Works:

  • The function takes one parameter:
    • root The root note as a string..
  • It iterates through all available chord types in the chord_list dictionary and calculates the corresponding notes for each chord.
  • Returns a dictionary with chord types as keys and the generated notes as values.

Example: Generate All Chords for C

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

Usage Scenarios

1. Use get_chord to Generate Specific Chords

If you know the root note and chord type you need, use get_chord to quickly generate it.

Example: Get a D Major 7th Chord

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#]

2. Use all_chords to Explore All Chords for a Root Note

When you want to explore all possible chord variations for a particular note, use all_chords.

Example: Find All Chords for A

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

Summary of Functions

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.


Full Chord List

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

Key Points

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