Skip to content

Instantly share code, notes, and snippets.

@lonetwin
Created September 26, 2013 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lonetwin/6718319 to your computer and use it in GitHub Desktop.
Save lonetwin/6718319 to your computer and use it in GitHub Desktop.
Python functions to generate the names of the notes for various musical scales, meant to be used for quick reference when practising the guitar.
#!/usr/bin/env python
notes = ['a', 'a#', 'b', 'c', 'c#', 'd', 'd#', 'e', 'f', 'f#', 'g', 'g#'] * 2
chroma = lambda x: [ i for i in notes[ notes.index(x): ] + notes[ :notes.index(x) ] ] + [x]
major = lambda x: ( chroma(x)[:5] + [chroma(x)[5]] + chroma(x)[5:12] )[::2] + [x]
major_penta = lambda x: [ i for idx, i in enumerate(major(x)) if idx not in (3, 6) ]
minor_penta = lambda x: ( major_penta( notes[ notes.index(x) + 3 ])[:-1] * 2)[-6:]
"""
# for example
for i in 'abcdefg':
print '-------------------------------'
print 'Chromatic Scale in %s: %s' % (i, ', '.join(chroma(i)[:13]))
print 'Major Scale in %s: %s' % (i, ', '.join(major(i)))
print 'Major Pentatonic Scale in %s: %s' % (i, ', '.join(major_penta(i)))
print 'Minor Pentatonic Scale in %s: %s' % (i, ', '.join(minor_penta(i)))
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment