Skip to content

Commit c99f18e

Browse files
authored
Fix the second note of Gm and Gdim (#108)
This PR is a workaround for #107. I think there should be a better way to handle this special case: #107 (comment)
1 parent 8807a40 commit c99f18e

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

pychord/utils.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,28 @@ def val_to_note(
3333
if index is None or quality is None:
3434
return SCALE_VAL_DICT[scale][val]
3535

36+
# NOTE: Is there a better way to implement this?
3637
is_flatted = (
37-
(quality.find("dim") >= 0 and index == 1)
38+
(quality.startswith("dim") and index == 1)
3839
or (
3940
(
4041
quality.find("b5") >= 1
4142
or quality.find("-5") >= 1
42-
or quality.find("dim") >= 0
43+
or quality.startswith("dim")
4344
)
4445
and index == 2
4546
)
4647
or ((quality == "dim7") and index == 3)
4748
or ((quality.find("b9") >= 1 or quality.find("-9") >= 1) and index == 4)
49+
# TODO: Remove special logic below for Gm
50+
or (
51+
val == 10
52+
and index == 1
53+
and (
54+
(quality.startswith("m") and not quality.startswith("maj"))
55+
or quality.startswith("dim")
56+
)
57+
)
4858
)
4959
if is_flatted:
5060
temp = SCALE_VAL_DICT[scale][(val + 1) % 12]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "pychord"
7-
version = "1.3.1"
7+
version = "1.3.2"
88
description = "Package to handle musical chords"
99
readme = "README.md"
1010
requires-python = ">=3.8"

test/test_component.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
import unittest
22

33
from parameterized import parameterized
4+
45
from pychord import Chord
56

67

78
class TestChordComponent(unittest.TestCase):
89
@parameterized.expand(
910
[
1011
("C", [0, 4, 7], ["C", "E", "G"]),
12+
("Gm", [7, 10, 14], ["G", "Bb", "D"]),
1113
("Am", [9, 12, 16], ["A", "C", "E"]),
1214
("Bdim", [11, 14, 17], ["B", "D", "F"]),
1315
("Cdim", [0, 3, 6], ["C", "Eb", "Gb"]),
1416
("Dbdim", [1, 4, 7], ["Db", "Fb", "Abb"]),
1517
("Ddim", [2, 5, 8], ["D", "F", "Ab"]),
1618
("Gbdim", [6, 9, 12], ["Gb", "Bbb", "Dbb"]),
19+
("Gdim", [7, 10, 13], ["G", "Bb", "Db"]),
1720
("Cdim7", [0, 3, 6, 9], ["C", "Eb", "Gb", "Bbb"]),
1821
("Dbdim7", [1, 4, 7, 10], ["Db", "Fb", "Abb", "Bb"]),
1922
("Dbaug", [1, 5, 9], ["Db", "F", "A"]),
2023
("Eaug", [4, 8, 12], ["E", "G#", "B#"]),
2124
("CM9/D", [-10, 0, 4, 7, 11], ["D", "C", "E", "G", "B"]),
2225
("Fsus4", [5, 10, 12], ["F", "Bb", "C"]),
2326
("G7", [7, 11, 14, 17], ["G", "B", "D", "F"]),
27+
("Gm7", [7, 10, 14, 17], ["G", "Bb", "D", "F"]),
2428
("C6", [0, 4, 7, 9], ["C", "E", "G", "A"]),
2529
("C#m7b9b5", [1, 4, 7, 11, 14], ["C#", "E", "G", "B", "D"]),
2630
("Db5", [1, 8], ["Db", "Ab"]),

0 commit comments

Comments
 (0)