Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Find notes in all Major, Harmonic Minor and Melodic Minor scales
- ## return answer to querying program (find_scales_chords_TkGUI.py)
- ## 11/12/14
- import scale_arp_chords_data as data
- import os
- import sys
- #----------------------------------------------------------------------
- def get_major_scale(find):
- """find the major scale, either # or b."""
- if find in ["C", "G", "D", "A", "E", "B", "F#", "C#"]:
- """major scales - sharps"""
- sharporflat = "#"
- elif find in ["F", "Bb", "Eb", "Ab", "Db", "Gb", "Cb"]:
- """major scales - flats"""
- sharporflat = "b"
- scalenotes = major_scales(find, sharporflat)
- return scalenotes
- #----------------------------------------------------------------------
- def major_scales(find, sharporflat):
- """build the major scale"""
- scaletemplate = ["C", "D", "E", "F", "G", "A", "B"]
- scale = scaletemplate
- while scale[0] != find:
- if sharporflat == "#":
- scale[3] = scale[3] + "#"
- newscale = scale[4:] + scale[:4]
- elif sharporflat == "b":
- scale[-1] = scale[-1] + "b"
- newscale = scale[3:] + scale[:3]
- scale = newscale
- scale.append(scale[0])
- return scale
- #----------------------------------------------------------------------
- def pure_minor(find, scaletype):
- """return the pure minor scale"""
- scaletemplate = ["C", "D", "E", "F", "G", "A", "B"]
- x = scaletemplate.index(find[0])
- transitscale = scaletemplate[x:] + scaletemplate[:x]
- relmajscale = transitscale[2]
- if scaletype == "minorsharps":
- sharporflat = "#"
- elif scaletype == "minorflats":
- if relmajscale in "BEADGC": ## add a flat to the name
- relmajscale = relmajscale + "b"
- sharporflat = "b"
- newscale = major_scales(relmajscale, sharporflat)
- pureminorscale = newscale[5:-1] + newscale[:5] + newscale[5:6]
- return pureminorscale
- #----------------------------------------------------------------------
- def harmonic_minor(scale):
- """raise the 7th"""
- minorscale = scale
- if minorscale[6][-1] == "#":
- raiseit = minorscale[6][:-1] + "X"
- elif minorscale[6][-1] == "b":
- raiseit = minorscale[6][:-1]
- else:
- raiseit = minorscale[6] + "#"
- minorscale[6] = raiseit
- return minorscale
- #----------------------------------------------------------------------
- def melodic_minor(scale):
- """Ascending Raise the sixth and seventh
- Descending lower the sixth and seventh"""
- minorscale = scale
- descendingpureminor = scale[:]
- descendingpureminor.reverse()
- if minorscale[5][-1] == "#":
- raiseit6 = minorscale[5][:-1] + "X"
- elif minorscale[5][-1] == "b":
- raiseit6 = minorscale[5][:-1]
- else:
- raiseit6 = minorscale[5] + "#"
- minorscale[5] = raiseit6 # raise the 6th
- minorscale = harmonic_minor(minorscale) # raise the 7th. use harmonic minor function
- minorscale.extend(descendingpureminor[1:]) # add the ascending scale less the first note
- return minorscale
- #----------------------------------------------------------------------
- def list_to_string(givenlist):
- """take a list and return a string"""
- stringfromlist = ' '.join(givenlist)
- return stringfromlist
- #----------------------------------------------------------------------
- def get_scale(find):
- """"""
- if "m" not in find: # NOT a MINOR scale. IS a MAJOR scale
- """major scales - sharps"""
- scalenotes = get_major_scale(find)
- scalename = find + " Major: "
- elif find[:-2] in ["A", "E", "B", "F#", "C#", "G#", "D#", "A#"]:
- scaletype = "minorsharps"
- pureminorscale = pure_minor(find, scaletype)
- if "hm" in find: ## harmonic minor
- scalenotes = harmonic_minor(pureminorscale)
- scalename = find[:-2] + " Harmonic Minor: "
- else: ## melodic minor
- scalenotes = melodic_minor(pureminorscale)
- scalename = find[:-2] + " Melodic Minor: "
- elif find[:-2] in ["D", "G", "C", "F", "Bb", "Eb", "Ab"]:
- scaletype = "minorflats"
- pureminorscale = pure_minor(find, scaletype)
- if "hm" in find: ## harmonic minor
- scalenotes = harmonic_minor(pureminorscale)
- scalename = find[:-2] + " Harmonic Minor: "
- else: ## melodic minor
- scalenotes = melodic_minor(pureminorscale)
- scalename = find[:-2] + " Melodic Minor: "
- return scalename, scalenotes
- #----------------------------------------------------------------------
- def raiseaccidental(note2check):
- """"""
- if len(note2check) == 1:
- newnote = note2check + "#"
- elif len(note2check) == 2:
- if note2check[1] == "#":
- newnote = note2check[0] + "X"
- elif note2check[1] == "b":
- newnote = note2check[0]
- return newnote
- #----------------------------------------------------------------------
- def loweraccidental(note2check):
- """"""
- if len(note2check) == 1:
- newnote = note2check + "b"
- elif len(note2check) == 2:
- if note2check[1] == "#":
- newnote = note2check[0]
- elif note2check[1] == "b":
- newnote = note2check + "b"
- return newnote
- #----------------------------------------------------------------------
- def get_chord(scale, chordname):
- """Chord mode"""
- chordnotes = []
- scalenotes = get_major_scale (scale)
- if chordname == "":
- chordnotes.extend([scalenotes[0], scalenotes[2], scalenotes[4]])
- chordname = scale + " major: "
- elif chordname == "m":
- newnote = loweraccidental(scalenotes[2])
- chordnotes.extend ([scalenotes [0], newnote, scalenotes [4]])
- chordname = scale + " minor: "
- elif chordname == "sus2":
- chordnotes.extend ([scalenotes [0], scalenotes [1], scalenotes [4]])
- chordname = scale + " sus2: "
- elif chordname == "sus4":
- chordnotes.extend ([scalenotes [0], scalenotes [3], scalenotes [4]])
- chordname = scale + " sus4: "
- elif chordname == "6":
- chordnotes.extend ([scalenotes [0], scalenotes [2], scalenotes [4], scalenotes[5]])
- chordname = scale + " 6th: "
- elif chordname == "m6":
- newnote = loweraccidental(scalenotes[2])
- chordnotes.extend ([scalenotes [0], newnote, scalenotes [4], scalenotes[5]])
- chordname = scale + " minor 6th: "
- elif chordname == "7":
- newnote = loweraccidental(scalenotes[6])
- chordnotes.extend ([scalenotes [0], scalenotes [2], scalenotes [4], newnote])
- chordname = scale + " 7th: "
- elif chordname == "M7":
- chordnotes.extend ([scalenotes [0], scalenotes [2], scalenotes [4], scalenotes[6]])
- chordname = scale + " major 7th: "
- elif chordname == "m7":
- newnote = loweraccidental(scalenotes[2])
- newnote2 = loweraccidental(scalenotes[6])
- chordnotes.extend ([scalenotes [0], newnote, scalenotes [4], newnote2])
- chordname = scale + " minor 7th: "
- elif chordname == "mM7":
- newnote = loweraccidental(scalenotes[2])
- chordnotes.extend ([scalenotes [0], newnote, scalenotes [4], scalenotes[6]])
- chordname = scale + " minor major 7th: "
- elif chordname == "+5":
- newnote = raiseaccidental(scalenotes[4])
- chordnotes.extend ([scalenotes [0], scalenotes [2], newnote])
- chordname = scale + " minor 6th: "
- elif chordname == "-5":
- newnote = loweraccidental(scalenotes[4])
- chordnotes.extend ([scalenotes [0], scalenotes [2], newnote])
- chordname = scale + " major -5: "
- elif chordname == "7+5":
- newnote = raiseaccidental(scalenotes [4])
- newnote2 = loweraccidental(scalenotes[6])
- chordnotes.extend ([scalenotes [0], scalenotes [2], newnote, newnote2])
- chordname = scale + " 7th+5: "
- elif chordname == "7-5":
- newnote = loweraccidental(scalenotes [4])
- newnote2 = loweraccidental(scalenotes[6])
- chordnotes.extend ([scalenotes [0], scalenotes [2], newnote, newnote2])
- chordname = scale + " 7th-5: "
- elif chordname == "9":
- newnote = loweraccidental(scalenotes[6])
- chordnotes.extend ([scalenotes [0], scalenotes [2], scalenotes [4], newnote, scalenotes [1]])
- chordname = scale + " 9th: "
- elif chordname == "m9":
- newnote = loweraccidental(scalenotes[2])
- newnote2 = loweraccidental(scalenotes[6])
- chordnotes.extend ([scalenotes [0], newnote, scalenotes [4], newnote2, scalenotes [1]])
- chordname = scale + " minor9th: "
- elif chordname == "7-9":
- newnote = loweraccidental(scalenotes [4])
- newnote2 = loweraccidental(scalenotes[1])
- chordnotes.extend ([scalenotes [0], scalenotes [2], newnote, newnote2])
- chordname = scale + " 7th-9: "
- elif chordname == "7+9":
- newnote = loweraccidental(scalenotes [4])
- newnote2 = raiseaccidental(scalenotes[1])
- chordnotes.extend ([scalenotes [0], scalenotes [2], newnote, newnote2])
- chordname = scale + " 7th-9: "
- elif chordname == "11":
- newnote = loweraccidental(scalenotes[6])
- chordnotes.extend ([scalenotes [0], scalenotes [2], scalenotes [4], newnote, scalenotes [3]])
- chordname = scale + " 11th: "
- elif chordname == "m11":
- newnote = loweraccidental(scalenotes[2])
- newnote2 = loweraccidental(scalenotes[6])
- chordnotes.extend ([scalenotes [0], newnote, scalenotes [4], newnote2, scalenotes [3]])
- chordname = scale + " minor11th: "
- elif chordname == "13":
- newnote = loweraccidental(scalenotes[6])
- chordnotes.extend ([scalenotes [0], scalenotes [2], scalenotes [4], newnote, scalenotes [5]])
- chordname = scale + " 13th: "
- elif chordname == "m13":
- newnote = loweraccidental(scalenotes[2])
- newnote2 = loweraccidental(scalenotes[6])
- chordnotes.extend ([scalenotes [0], newnote, scalenotes [4], newnote2, scalenotes [5]])
- chordname = scale + " minor13th: "
- elif chordname == "dim":
- newnote = loweraccidental(scalenotes[2])
- newnote2 = loweraccidental(scalenotes[4])
- chordnotes.extend ([scalenotes [0], newnote, newnote2])
- chordname = scale + " diminished: "
- elif chordname == "m-5":
- newnote = loweraccidental(scalenotes[2])
- newnote2 = loweraccidental(scalenotes[4])
- chordnotes.extend ([scalenotes [0], newnote, newnote2])
- chordname = scale + " diminished: "
- elif chordname == "dim7":
- newnote = loweraccidental(scalenotes[2])
- newnote2 = loweraccidental(scalenotes[4])
- chordnotes.extend ([scalenotes [0], newnote, newnote2, scalenotes[5]])
- chordname = scale + " diminished7th: "
- else:
- chordnotes.extend("No such Chord.")
- return chordname, chordnotes
- #----------------------------------------------------------------------
- def main(find, mode):
- if mode == "Scale Mode":
- if len(find) > 1:
- find = find[0].upper() + find[1:]
- else:
- find = find.upper()
- if find in data.scalenames:
- scale_n_notes = get_scale(find)
- stringfy = list_to_string (scale_n_notes[1])
- totalanswer = scale_n_notes[0] + stringfy
- else:
- totalanswer = "No such scale"
- return totalanswer
- elif mode == "Chord Mode":
- ## make the query variables
- find = find[0].upper() + find[1:] # capitalize the 1st. character
- if len(find) > 1 and "#" in find[1] or len(find) > 1 and "b" in find[1]:
- scale = find[:2]
- chordname = find[2:]
- else:
- scale = find[0]
- chordname = find[1:]
- ## if chord is valid get it!
- if chordname in data.chordnames and scale in data.valid:
- chord_notes = get_chord(scale, chordname)
- stringfy = list_to_string (chord_notes[1])
- totalanswer = chord_notes[0] + stringfy
- else:
- totalanswer = "No such chord"
- return totalanswer
- if __name__ == '__main__':
- getscale = "A"
- mode = "Scale Mode"
- scale = main(getscale, mode)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement