cuthbertLab / music21

music21 is a Toolkit for Computational Musicology
https://www.music21.org/
Other
2.13k stars 402 forks source link

Chord clarifciation #1697

Closed float3 closed 8 months ago

float3 commented 8 months ago

music21 version

9.2.0b

Problem summary using Chord.pitchedCommonName

E G# B: E-major triad E Ab B: enharmonic equivalent to major triad above E E Ab Cb: enharmonic equivalent to major triad above Cb E G# Cb: enharmonic equivalent to major triad above Cb

I don't understand why the last two aren't the same as the second

also the following two code snippets generate very different outputs, in ways that don't make sense to me

#!/usr/bin/env python3
if __name__ == "__main__":
    import itertools
    import json

    from music21 import chord

    notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]

    dict = {}
    dict[0] = ""
    for r in range(1, 13):
        combinations = itertools.combinations(range(12), r)
        for combination in combinations:
            chord_notes = [notes[i] for i in combination]
            c = chord.Chord(
                chord_notes
            ).pitchedCommonName  # check if pitchedCommonName contains enharmonic equivalent
            # also look into keycontext
            bitmask = sum(1 << i for i in combination)
            dict[bitmask] = c

    with open("../ts/src/chords.json", "w") as outfile:
        json.dump(dict, outfile)
#!/usr/bin/env python3
if __name__ == "__main__":
    import itertools
    import json

    from music21 import chord

    dict = {}
    dict[0] = ""
    for r in range(1, 13):
        combinations = itertools.combinations(range(12), r)
        for combination in combinations:
            c = chord.Chord(combination).pitchedCommonName
            bitmask = sum(1 << i for i in combination)
            dict[bitmask] = c

    with open("../ts/src/chords.json", "w") as outfile:
        json.dump(dict, outfile)
float3 commented 8 months ago

I'm trying to generate LUT with all possible chords (enharmonically)

this is the LUT generated with the first code snippet

this is the second code snippet

one of my confusions, for example are:

  "8": "E-",
  "1024": "B-",
jacobtylerwalls commented 8 months ago

E Ab Cb: enharmonic equivalent to major triad above Cb E G# Cb: enharmonic equivalent to major triad above Cb I don't understand why the last two aren't the same as the second

This is because in those two examples, you've presumably omitted octaves. Cb is lower than E in the default octave, so the sonority really is "over Cb" where Cb is the bass, not the root.

You probably wanted:

c = chord.Chord('E4 Ab4 Cb5')

Or some variation.

If there's another issue you'd like to present, please annotate the two outputs with expected vs. actual results so that I'm not being asked to debug a script. Thanks.