mirror of
https://github.com/kennethreitz/pytheory.git
synced 2026-06-05 06:46:14 +00:00
9da3ac8b28
- circle_of_fifths.py — visualize keys around the circle - chord_identifier.py — identify chords from notes and fingerings - key_explorer.py — explore keys, signatures, progressions, borrowed chords - temperament_comparison.py — compare equal, Pythagorean, and meantone - chord_tension.py — analyze tension, consonance, and voice leading - world_scales.py — scales from 6 musical traditions - fretboard_explorer.py — instruments, tunings, capo transposition - midi_converter.py — MIDI ↔ note ↔ frequency reference - progression_writer.py — famous progressions, Nashville numbers, random generation - interval_trainer.py — interval names, songs, and consonance ranking - overtone_series.py — harmonics and why chords sound good - key_detection.py — detect keys from melodies and chord progressions Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
"""Identify chords from notes or guitar fingerings."""
|
|
|
|
from pytheory import Chord, Fretboard
|
|
|
|
print("=== Chord Identification from Notes ===")
|
|
print()
|
|
|
|
test_chords = [
|
|
("C", "E", "G"),
|
|
("A", "C", "E"),
|
|
("G", "B", "D", "F"),
|
|
("D", "F#", "A"),
|
|
("Bb", "D", "F"),
|
|
("E", "G#", "B"),
|
|
("C", "Eb", "Gb"),
|
|
("C", "G"),
|
|
("C", "F", "G"),
|
|
("C", "D", "G"),
|
|
]
|
|
|
|
for notes in test_chords:
|
|
chord = Chord.from_tones(*notes)
|
|
name = chord.identify() or "Unknown"
|
|
print(f" {', '.join(notes):20s} → {name}")
|
|
|
|
print()
|
|
print("=== Chord Identification from Guitar Fingerings ===")
|
|
print()
|
|
|
|
fb = Fretboard.guitar()
|
|
|
|
# Common guitar chord shapes
|
|
shapes = [
|
|
("Open C", (0, 1, 0, 2, 3, 0)),
|
|
("Open G", (3, 0, 0, 0, 2, 3)),
|
|
("Open D", (2, 3, 2, 0, 0, 0)),
|
|
("Open Am", (0, 1, 2, 2, 0, 0)),
|
|
("Open Em", (0, 0, 0, 2, 2, 0)),
|
|
("Barre F", (1, 1, 2, 3, 3, 1)),
|
|
("Power E5", (0, 0, 0, 0, 2, 0)),
|
|
]
|
|
|
|
for label, positions in shapes:
|
|
f = fb.fingering(*positions)
|
|
name = f.identify() or "Unknown"
|
|
print(f" {label:12s} {f} → {name}")
|