]> khamidou — GitHub mirrors - scaletool.git/commitdiff
added a chord display functionality
authorkhamidou <khamidou@gmail.com>
Thu, 11 Aug 2011 14:09:06 +0000 (16:09 +0200)
committerkhamidou <khamidou@gmail.com>
Thu, 11 Aug 2011 14:09:06 +0000 (16:09 +0200)
app.py
scales.py

diff --git a/app.py b/app.py
index b14bf2bc55b005361476cf7fb894263c6620e9c4..11775f21e4701d334fdd5ea1faae97900550e31e 100755 (executable)
--- a/app.py
+++ b/app.py
@@ -17,23 +17,29 @@ class ScalesFrame(Frame):
                def handler():
                        global current_scale, current_mode
                        current_scale = 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):
+               self.v = IntVar()
                for i, button in enumerate(scales):
-                       self.button = Radiobutton(self, text=str(button), command=self.closure(str(button)))
+                       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]},
+                       {"name": "Natural Minor", "formula" : [2, 1, 2, 2, 1, 2, 2]},
+               ]
+
        def __init__(self, master=None, app=None):
                Frame.__init__(self, master)
                self.app = app
                self.grid()
-               self.createWidgets()
+               self.createWidgets(master)
+               self.currentSelec = None
+               self.poll()
        
        def closure(self, text):
                def handler():
@@ -45,12 +51,28 @@ class ModeFrame(Frame):
                return handler
 
 
-       def createWidgets(self):
-               for i, button in enumerate(modes):
-                       self.button = Radiobutton(self, text=str(button), command=self.closure(str(button)))
-                       self.button.deselect()
-                       self.button.grid(row=0, column=i)
+       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):
@@ -59,21 +81,31 @@ class Application(Frame):
                self.createWidgets()
        
        def createWidgets(self):
-               self.outputLabel = Label(self, text="Placeholder")
+               self.outputLabel = Label(self, text="Select a scale and a mode")
 
-               self.scalesLabel = LabelFrame(self, text="Scale")
+               self.scalesLabel = LabelFrame(self, text="Root note")
                self.scalesLabel.grid()
                self.scalesFrame = ScalesFrame(master=self.scalesLabel, app=self)
 
-               self.modesLabel = LabelFrame(self, text="Modes")
+               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="ho")
+               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()
index 9ee7a24c86bdbd01b45e0c7297111a61dd22a721..bdb70e4e9d3fd5df39c81842aea5dd48efa9233c 100644 (file)
--- a/scales.py
+++ b/scales.py
@@ -83,7 +83,7 @@ class Scale:
                i = 0
                j = 0
                while i < 11 and j < 6: # reduce(lambda x,y: x+y, self.values)
-                       n = self.formula[i]
+                       n = self.formula[j]
                        retscale += notes[i+n]
                        i += n 
                        j += 1 # Don't forget to increment j to avoid looping.