Skip to content

Instantly share code, notes, and snippets.

@matteobertozzi
Last active August 14, 2020 01:14
Show Gist options
  • Select an option

  • Save matteobertozzi/6095916 to your computer and use it in GitHub Desktop.

Select an option

Save matteobertozzi/6095916 to your computer and use it in GitHub Desktop.
guitar scales
#!/usr/bin/env python
NOTES = ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#']
note_name = lambda n: NOTES[n % len(NOTES)]
SCALES = {
'Major (Ionian)': [2, 2, 1, 2, 2, 2, 1],
'Major Pentatonic': [2, 2, 3, 2, 3],
'Natural minor (Aeolian)' : [2,1,2,2,1,2,2],
'Harmonic minor': [2,1,2,2,1,3,1],
'Melodic minor': [2,1,2,2,2,2,1],
'Minor Pentatonic': [3,2,2,3,2],
'Blues': [3,2,1,1,3,2],
'Arabic': [1,3,1,2,1,3,1],
'Aeolian':[2, 1, 2, 2, 1, 2, 2],
'Locryan':[1, 2, 2, 1, 2, 2, 2],
'Ionian':[2, 2, 1, 2, 2, 2, 1],
'Dorian':[2, 1, 2, 2, 2, 1, 2],
'Phrygian': [1, 2, 2, 2, 1, 2, 2],
'Phrygian Dominant': [1,3,1,2,1,2,2],
'Lydian':[2, 2, 2, 1, 2, 2, 1],
'Mixolydian':[2, 2, 1, 2, 2, 1, 2],
'Balinese': [1, 2, 4, 1, 4],
'Bartok': [2, 2, 2, 1, 2, 1, 2],
'Bizantine': [1, 3, 1, 2, 1, 3, 1],
'Diminished': [2, 1, 2, 1, 2, 1, 2, 1],
'Iowato': [1, 4, 1, 4, 2],
'Kumoi': [1, 4, 2, 1, 4],
'Hirajoshi': [2, 1, 4, 1, 4],
'Japanese': [1, 4, 2, 1, 4],
'In Sen': [1, 4, 2, 3, 2],
'Spanish': [1,3,1,2,1,2,2],
'Spanish 8 Tone': [1, 2, 1, 1, 1, 2, 2, 2],
}
def scale(intervals):
for key, key_name in enumerate(NOTES):
note = key
scale_notes = []
for i in intervals:
note += i
scale_notes.append(note % len(NOTES))
yield key, scale_notes
def tuning(first):
first = NOTES.index(first)
yield first % len(NOTES)
for x in [5, 5, 5, 4, 5]:
first += x
yield first % len(NOTES)
def guitar(tuning, scale=None):
frets = [1, 3, 5, 7, 9, 12, 15, 17, 19, 21, 23]
tuning = list(tuning)
print '+----' * 24 + '+'
if scale is None:
for t in reversed([t + 1 for t in tuning]):
print '| %s |' % ' | '.join(['%-2s' % note_name(t + i) for i in xrange(24)])
else:
def print_note(key, fret):
note = (key + fret) % len(NOTES)
if note not in scale:
return ' '
string_no = tuning.index(key - 1)
prev_string = tuning[string_no - 1 if string_no > 0 else 4]
prev_string_notes = [(prev_string + i) % len(NOTES) for i in xrange(24)]
cur_string_notes = [(key + i) % len(NOTES) for i in xrange(24)]
fret %= 12
return '<>' if fret == cur_string_notes.index(scale[-1]) else note_name(note)
for t in reversed([t + 1 for t in tuning]):
print '| %s |' % ' | '.join(['%-2s' % print_note(t, i) for i in xrange(24)])
print '+----' * 24 + '+'
print ' %s ' % ' '.join(['%-2s' % (i if i in frets else ' ') for i in xrange(1, 25)])
if __name__ == '__main__':
for scale_name, scale_intervals in sorted(SCALES.iteritems()):
for key, intervals in scale(scale_intervals):
print '%20s: %-2s -> %s' % (scale_name, note_name(key), ' '.join(['%-2s' % note_name(x) for x in intervals]))
print
print
print [note_name(x) for x in tuning('E')]
guitar(tuning('D#'))
for scale_name, scale_intervals in sorted(SCALES.iteritems()):
for key, intervals in scale(scale_intervals):
print '%20s: %-2s -> %s' % (scale_name, note_name(key), ' '.join(['%-2s' % note_name(x) for x in intervals]))
guitar(tuning('D#'), intervals)
print
print '\n' * 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment