Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Chord.from_note_index() so it chooses the correct accidentals #39

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pythagorasisreal
Copy link

I have noticed that the from_note_index class method does some possibly undesirable things with accidentals. For example,

from pychord import Chord
Chord.from_note_index(3,'','Emaj')`

returns <Chord: Ab>.

I have used your SHARPED_SCALE constant and a helper function utils.sharp_or_flat to use the underlying scale to determine the correct accidental. In this example, this makes the function return `<Chord: G#>' instead, which is more conventional.

It also makes TestChordFromNoteIndex.test_note_2 from test_chord.py pass (it was previously failing).

root = scale[:-3]
# if scale is minor, get sharp/flat from relative major
if scale[-3:] == 'min':
root = SCALE_VAL_DICT[root][3]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this always returns D# or Eb, is it what do you intended?

Do you mean below?

root = SCALE_VAL_DICT[root][(NOTE_VAL_DICT(root) + 3) % 12]

@yuma-m
Copy link
Owner

yuma-m commented Jun 20, 2020

Hi @pythagorasisreal,

Thank you for your contribution and sorry for the late reply.
I added a review comment, could you kindly confirm it?

root = root_options[0]
else:
correct_accidental = sharp_or_flat(scale)
correct_index = ['FLATTED','SHARPED'].index(correct_accidental)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
correct_index = ['FLATTED','SHARPED'].index(correct_accidental)
correct_index = ['FLATTED', 'SHARPED'].index(correct_accidental)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants