Created
May 30, 2018 03:22
-
-
Save embatbr/15d1b8f25facf866a72dac6d38fc163a to your computer and use it in GitHub Desktop.
Getting chromatic scale from diatonic scale (and also frequencies for all notes - with differences between flats and sharps).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""From diatonic to chromatic. Also, flat and sharp notes. | |
Take notice that flats and sharps are not actually equal. | |
""" | |
diatonic = { | |
'C': 264, | |
'D': 297, | |
'E': 330, | |
'F': 352, | |
'G': 396, | |
'A': 440, | |
'B': 495 | |
} | |
flat = lambda x: round(x*15/16, 2) | |
sharp = lambda x: round(x*16/15, 2) | |
flats_and_sharps = dict(diatonic) | |
for note in diatonic.keys(): | |
sharp_note = sharp(diatonic[note]) | |
flat_note = flat(diatonic[note]) | |
flats_and_sharps['%sb' % note] = flat_note | |
flats_and_sharps['%s#' % note] = sharp_note | |
flats_and_sharps = [(k, v) for (k, v) in flats_and_sharps.items()] | |
flats_and_sharps = sorted(flats_and_sharps, key=lambda x: x[1]) | |
print('All flat (b) and sharp (#) notes:') | |
for (note, freq) in flats_and_sharps: | |
print('%s %s' % (note.ljust(5), freq)) | |
def is_allowed(note): | |
return not (note.endswith('b') or note in ('E#', 'B#')) | |
chromatic = [note for (note, freq) in flats_and_sharps if is_allowed(note)] | |
print('\nChromatic scale:', ' '.join(chromatic)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment