-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathscalecharts.py
executable file
·188 lines (151 loc) · 6 KB
/
scalecharts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env python3
import sys
from tkinter import *
from collections import OrderedDict
# This program creates a guitar scale gui from grid elements, and fills them in color-coded appropriately.
# https://github.com/crawsome/GuitarScaleChart
# 2017 Colin Burke, et al contributors from Github :-)
# Get Note name from a 0-11 INT
def getnotename(tonename):
notedict = ['E ', 'F ', 'F#', 'G ', 'Ab',
'A ', 'Bb', 'B ', 'C ', 'Db', 'D ', 'Eb']
return notedict[tonename % 12]
# Contains int offsets, based on note string, added for convenience, which
# is simply offset relative to C.
def getoffset_tonename(tonename):
scaleref = {
'E ': 0, 'F ': 1, 'F#': 2, 'G ': 3, 'Ab': 4, 'A ': 5, 'Bb': 6, 'B ': 7, 'C ': 8, 'Db': 9, 'D ': 10,
'Eb': 11}
return scaleref[tonename]
# Return array that is rotated circular
def rotate(l, n):
return l[-n:] + l[:-n]
scales = OrderedDict([
('Major', [0, 2, 2, 1, 2, 2, 2, 1]),
('Natural minor', [0, 2, 1, 2, 2, 1, 2, 2]),
('Harmonic minor', [0, 2, 1, 2, 2, 1, 3, 1]),
('Melodic minor', [0, 2, 1, 2, 2, 2, 2, 2]),
('Dorian mode', [0, 2, 1, 2, 2, 2, 1, 2]),
('Phrygian mode', [0, 1, 2, 2, 2, 1, 2, 2]),
('Lydian mode', [0, 2, 2, 2, 1, 2, 2, 1]),
('Mixolydian mode', [0, 2, 2, 1, 2, 2, 1, 2]),
('Locrian mode', [0, 1, 2, 2, 1, 2, 2, 2]),
('Ahava raba mode', [0, 1, 3, 1, 2, 1, 2, 2]),
('Minor pentatonic', [0, 3, 2, 2, 3, 2]),
('Pentatonic', [0, 2, 2, 3, 2, 3]),
('Blues', [0, 3, 2, 1, 1, 3]),
('5 chord', [0, 7]),
('Major chord', [0, 4, 3]),
('Minor chord', [0, 3, 4]),
('Diminished chord', [0, 3, 3]),
('Augmented chord', [0, 4, 4]),
('Sus2 chord', [0, 2, 5]),
('Sus4 chord', [0, 5, 2]),
('Maj7 chord', [0, 4, 3, 4]),
('min7 chord', [0, 3, 4, 3]),
('7 chord', [0, 4, 3, 3]),
('min7b5 chord', [0, 3, 3, 4]),
('dim7 chord', [0, 3, 3, 3]),
('9 chord', [0, 4, 3, 3, 4]),
('Maj9 chord', [0, 4, 3, 4, 3]),
('m9 chord', [0, 3, 4, 3, 4]),
('11 chord', [0, 4, 3, 3, 4, 3]),
('Maj11 chord', [0, 4, 3, 4, 3, 3]),
('min11 chord', [0, 3, 4, 3, 4, 3]),
])
# returns a scale of 16 notes, from the key tonic + 24
def makescale(keyroot, keyopt):
keywheel = []
keywheel.extend(scales[keyopt])
filler = 0
# fill array with 16 notes relevant to key and option.
ourscale = []
lenvar = len(keywheel) # of notes we use (2 octaves of key notes)
for inte in range(lenvar):
filler += keywheel[inte % len(keywheel)]
ourscale.append(int(filler + getoffset_tonename(keyroot)))
return ourscale
# fetches a default scale
ourscale = makescale('E ', 'Major')
# Used for note offsets
e = 0
# high e = (e+4), b = (e-1), g = (e+7), d = (e+2),a = (e+9), low e = (e+4)
# added to each string to offset and identify the notes.
offsetArray = [e, e + 7, e + 3, e + 10, e + 5, e]
# default e Major
chartgui = Tk()
# our callback variables that change when menu options are selected
variable = StringVar(chartgui)
variable.set('E ')
variable2 = StringVar(chartgui)
variable2.set('Major')
# variable3 = StringVar(chartgui)
# variable3.set('View 1')
# for clearing all our values, used for the "Reset" button.
def resettable():
print("Tried to reset!")
for i in range(0, 25):
for gss in range(0, 6):
Label(chartgui, text=getnotename(i + offsetArray[gss])).grid(
row=gss + 2, column=i + 1, padx=0, pady=0)
# redraw our whole scale, the action for the "Apply" button
def applyit(val):
print("Trying to apply!")
# print("var1 = %s"%variable.get())
# print("var2 = %s"%variable2.get())
# print("var3 = %s"%variable3.get())
ourtonic = str(variable.get())
ourkey = str(variable2.get())
print(ourtonic)
print(ourkey)
ourscale = makescale(ourtonic, ourkey)
print(ourscale)
ournotes = []
for notes in ourscale:
ournotes.append(getnotename(notes))
print (ournotes)
# draw our whole scale
for i in range(0, 25):
for gss in range(0, 6):
start = offsetArray[gss]
# draw red for roots
if ourtonic == getnotename(i + start % 12):
Label(
chartgui, text=getnotename(i + start), bg='red').grid(row=gss + 2, column=i + 1,
padx=0, pady=0)
# draw yellow for notes in the scale
elif getnotename(i + start) in ournotes:
Label(
chartgui, text=getnotename(i + start), bg='yellow').grid(row=gss + 2, column=i + 1,
padx=0, pady=0)
# only write notename
else:
Label(chartgui, text=getnotename(i + start)).grid(
row=gss + 2, column=i + 1, padx=0, pady=0)
if __name__ == "__main__":
chartgui.geometry('640x280+400+300')
chartgui.title('GuitarScaleChart - Colin Burke, 2017')
ourx = 40
oury = 20
# For our fret (column) labels on top and bottom
for i in range(0, 25):
Label(chartgui, text=i, font='helvetica').grid(
row=0, column=i + 1, padx=0, pady=10)
Label(chartgui, text=i, font='helvetica').grid(
row=9, column=i + 1, padx=0, pady=10)
# For our string (row) labels
stringarray = ['E', 'B', 'G', 'D', 'A', 'E']
for gss in range(0, 6):
Label(chartgui, text=stringarray[gss], font="comicsans").grid(
row=gss + 2, column=0, padx=10, pady=0)
print(ourscale)
# draw our whole scale
applyit("")
keymenu = OptionMenu(
chartgui, variable, 'E ', 'F ', 'F#', 'G ', 'Ab', 'A ', 'Bb', 'B ', 'C ', 'Db', 'D ',
'Eb', command=applyit).place(x=ourx * 2, y=oury * 12)
scalemenu = OptionMenu(chartgui, variable2, *scales.keys(), command=applyit).place(
x=ourx * 4, y=oury * 12)
resetbutton = Button(chartgui, text=' Reset ', command=resettable).place(
x=ourx * 10, y=oury * 12)
chartgui.mainloop()