-#!/usr/bin/env python
+#!/usr/bin/env python3
-from Tkinter import *
+from tkinter import *
from scales import *
current_scale = "C"
current_mode = "C"
class ScalesFrame(Frame):
- def __init__(self, master=None, app=None):
- Frame.__init__(self, master)
- self.app = app
- self.grid()
- self.createWidgets()
-
- def closure(self, text):
- def handler():
- global current_scale, current_mode
- current_scale = text
- return handler
-
- def createWidgets(self):
- self.v = IntVar()
- for i, button in enumerate(scales):
- self.button = Radiobutton(self, text=str(button), command=self.closure(str(button)),
- variable=self.v, value=i)
- self.button.deselect()
- self.button.grid(row=0, column=i)
+ def __init__(self, master=None, app=None):
+ Frame.__init__(self, master)
+ self.app = app
+ self.grid()
+ self.createWidgets()
+
+ def closure(self, text):
+ def handler():
+ global current_scale, current_mode
+ current_scale = text
+ return handler
+
+ def createWidgets(self):
+ self.v = IntVar()
+ for i, button in enumerate(scales):
+ self.button = Radiobutton(self, text=str(button), command=self.closure(str(button)),
+ variable=self.v, value=i)
+ self.button.deselect()
+ self.button.grid(row=0, column=i)
class ModeFrame(Frame):
- scales = [ {"name": "Major", "formula" : [2, 2, 1, 2, 2, 2, 1], "chords": "I ii iii IV V vidim vii"},
- {"name": "Harmonic Minor", "formula" : [2, 1, 2, 2, 1, 3, 1],
- "chords": "i iidim IIIaug iv V VI viidim"},
- {"name": "Natural Minor", "formula" : [2, 1, 2, 2, 1, 2, 2], "chords": "i iidim III iv v VI VII"},
- ]
-
- def __init__(self, master=None, app=None):
- Frame.__init__(self, master)
- self.app = app
- self.grid()
- self.createWidgets(master)
- self.currentSelec = None
- self.poll()
-
- def closure(self, text):
- def handler():
- global current_scale, current_mode
- current_mode = modes[text]
- print "current scale %s, current mode %s" % (current_scale, current_mode)
- s = Scale(scale=current_scale, mode=current_mode)
- self.app.outputLabel.configure(text=str(s))
- return handler
-
-
- def createWidgets(self, master):
- self.listbox = Listbox(master)
- for scale in self.scales:
- self.listbox.insert(END, scale["name"])
- self.listbox.grid()
-
- def poll(self):
- # necessary because of a limitation
- # of tkinter
-
- global current_scale # ok, crappy design.
- now = self.listbox.curselection()
- #if now != self.currentSelec and now != ():
- if now != ():
- self.app.updateWidgets(self.scales[int(now[0])], current_scale)
- self.currentSelec = now
- self.after(250, self.poll)
-
- def update(self, currentSelection):
- # notify the parent class of the change
- # in the list
- return
+ scales = [ {"name": "Major", "formula" : [2, 2, 1, 2, 2, 2, 1], "chords": "I ii iii IV V vidim vii"},
+ {"name": "Harmonic Minor", "formula" : [2, 1, 2, 2, 1, 3, 1],
+ "chords": "i iidim IIIaug iv V VI viidim"},
+ {"name": "Natural Minor", "formula" : [2, 1, 2, 2, 1, 2, 2], "chords": "i iidim III iv v VI VII"},
+ ]
+
+ def __init__(self, master=None, app=None):
+ Frame.__init__(self, master)
+ self.app = app
+ self.grid()
+ self.createWidgets(master)
+ self.currentSelec = None
+ self.poll()
+
+ def closure(self, text):
+ def handler():
+ global current_scale, current_mode
+ current_mode = modes[text]
+ print(f"current scale {current_scale}, current mode {current_mode}")
+ s = Scale(scale=current_scale, mode=current_mode)
+ self.app.outputLabel.configure(text=str(s))
+ return handler
+
+
+ def createWidgets(self, master):
+ self.listbox = Listbox(master)
+ for scale in self.scales:
+ self.listbox.insert(END, scale["name"])
+ self.listbox.grid()
+
+ def poll(self):
+ # necessary because of a limitation
+ # of tkinter
+
+ global current_scale # ok, crappy design.
+ now = self.listbox.curselection()
+ #if now != self.currentSelec and now != ():
+ if now != ():
+ self.app.updateWidgets(self.scales[int(now[0])], current_scale)
+ self.currentSelec = now
+ self.after(250, self.poll)
+
+ def update(self, currentSelection):
+ # notify the parent class of the change
+ # in the list
+ return
class Application(Frame):
- def __init__(self, master=None):
- Frame.__init__(self, master)
- self.grid()
- self.createWidgets()
-
- def createWidgets(self):
- self.outputLabel = Label(self, text="Select a scale and a mode")
-
- self.scalesLabel = LabelFrame(self, text="Root note")
- self.scalesLabel.grid()
- self.scalesFrame = ScalesFrame(master=self.scalesLabel, app=self)
-
- self.modesLabel = LabelFrame(self, text="Scale")
- self.modesLabel.grid()
- self.modesFrame = ModeFrame(master=self.modesLabel, app=self)
-
- self.derivedChordsFrame = LabelFrame(self, text="Derived Chords")
- self.derivedChordsFrame.grid()
- self.derivedChordsLabel = Label(master=self.derivedChordsFrame, text=ModeFrame.scales[0]["chords"])
- self.derivedChordsLabel.pack()
-
- self.outputLabel.grid()
-
- self.quitButton = Button(self, text="Quit", command=self.quit)
- self.quitButton.grid()
-
- def updateWidgets(self, currentListSelection, currentNote):
- s = Scale(currentNote, currentListSelection["formula"])
- self.outputLabel.configure(text=str(s))
- if "chords" in currentListSelection:
- self.derivedChordsLabel.configure(text=currentListSelection["chords"])
+ def __init__(self, master=None):
+ Frame.__init__(self, master)
+ self.grid()
+ self.createWidgets()
+
+ def createWidgets(self):
+ self.outputLabel = Label(self, text="Select a scale and a mode")
+
+ self.scalesLabel = LabelFrame(self, text="Root note")
+ self.scalesLabel.grid()
+ self.scalesFrame = ScalesFrame(master=self.scalesLabel, app=self)
+
+ self.modesLabel = LabelFrame(self, text="Scale")
+ self.modesLabel.grid()
+ self.modesFrame = ModeFrame(master=self.modesLabel, app=self)
+
+ self.derivedChordsFrame = LabelFrame(self, text="Derived Chords")
+ self.derivedChordsFrame.grid()
+ self.derivedChordsLabel = Label(master=self.derivedChordsFrame, text=ModeFrame.scales[0]["chords"])
+ self.derivedChordsLabel.pack()
+
+ self.outputLabel.grid()
+
+ self.quitButton = Button(self, text="Quit", command=self.quit)
+ self.quitButton.grid()
+
+ def updateWidgets(self, currentListSelection, currentNote):
+ s = Scale(currentNote, currentListSelection["formula"])
+ self.outputLabel.configure(text=str(s))
+ if "chords" in currentListSelection:
+ self.derivedChordsLabel.configure(text=currentListSelection["chords"])
if __name__ == "__main__":
- root = Tk()
- app = Application(master=root)
- app.master.title("Scaletool")
- app.mainloop()
+ root = Tk()
+ app = Application(master=root)
+ app.master.title("Scaletool")
+ app.mainloop()
return len(self._data)
def __getitem__(self, i):
- if i >= len(self._data):
- i = i % len(self._data)
+ if i >= len(self._data):
+ i = i % len(self._data)
return self._data[i]
def __delitem__(self, i):
- del self._data[i]
+ del self._data[i]
def index(self, i):
- return self._data.index(i)
+ return self._data.index(i)
def turn(self):
- # Scales turn in reverse-order
+ # Scales turn in reverse-order
first = self._data.pop(0)
self._data.append(first)
return self._data[-1]
def turn_until(self, value):
- while self.first() != value:
- self.turn()
+ while self.first() != value:
+ self.turn()
def turn_ntimes(self, times):
- i = 0
- while i < times:
- self.turn()
- i += 1
+ i = 0
+ while i < times:
+ self.turn()
+ i += 1
scales = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
modes = {"Ionian" : "C", "Dorian" : "D", "Phrygian" : "E", "Lydian" : "F",
- "Mixolydian" : "G", "Aeolian" : "A", "Locrian" : "B"}
+ "Mixolydian" : "G", "Aeolian" : "A", "Locrian" : "B"}
class Scale:
- def __init__(self, scale="C", formula=[2, 2, 1, 2, 2, 2, 1]):
- self.start = Ring(["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"])
- # We store a modified scale as numbers : 1 means no sharp or flat, 0.5, one flat, 1.5 one sharp
- self.formula = formula
- self.transpose_scale(scale)
- #self.change_mode(mode)
-
- def transpose_scale(self, start_letter):
- self.start.turn_until(start_letter)
-
- def change_mode(self, mode_letter):
- v = ["C", "D", "E", "F", "G", "A", "B"]
- self.values.turn_ntimes(v.index(mode_letter))
-
- def __str__(self):
- retscale = self.start[0] + " "
- notes = self.start
- translation_table = { "Cb": "B",
- "Db" : "C#",
- "Eb" : "D#",
- "Fb" : "E",
- "Gb" : "F#",
- "Ab" : "G#",
- "Bb" : "A#",
- "B#" : "C",
- "E#" : "F",
- }
-
- i = 0
- j = 0
- while i < 11 and j < 6: # reduce(lambda x,y: x+y, self.values)
- n = self.formula[j]
- retscale += notes[i+n]
- i += n
- j += 1 # Don't forget to increment j to avoid looping.
- retscale += " "
- return retscale
+ def __init__(self, scale="C", formula=[2, 2, 1, 2, 2, 2, 1]):
+ self.start = Ring(["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"])
+ # We store a modified scale as numbers : 1 means no sharp or flat, 0.5, one flat, 1.5 one sharp
+ self.formula = formula
+ self.transpose_scale(scale)
+ #self.change_mode(mode)
+
+ def transpose_scale(self, start_letter):
+ self.start.turn_until(start_letter)
+
+ def change_mode(self, mode_letter):
+ v = ["C", "D", "E", "F", "G", "A", "B"]
+ self.values.turn_ntimes(v.index(mode_letter))
+
+ def __str__(self):
+ retscale = self.start[0] + " "
+ notes = self.start
+ translation_table = { "Cb": "B",
+ "Db" : "C#",
+ "Eb" : "D#",
+ "Fb" : "E",
+ "Gb" : "F#",
+ "Ab" : "G#",
+ "Bb" : "A#",
+ "B#" : "C",
+ "E#" : "F",
+ }
+
+ i = 0
+ j = 0
+ while i < 11 and j < 6: # reduce(lambda x,y: x+y, self.values)
+ n = self.formula[j]
+ retscale += notes[i+n]
+ i += n
+ j += 1 # Don't forget to increment j to avoid looping.
+ retscale += " "
+ return retscale
if __name__ == "__main__":
- s = Scale("C", [2, 1, 1, 2, 2, 2, 1])
- print str(s)
+ s = Scale("C", [2, 1, 1, 2, 2, 2, 1])
+ print(str(s))