music-modes-mini.html
001| from sys import stdout
002|
003|
004| ModeNames = [
005| 'Lydian','Ionian','Mixolydian','Dorian',
006| 'Aeolian','Phrygian','Locrian'
007| ]
008|
009|
010| ModeIntervals = [
011| [1, 2, 2, 2, 1, 2, 2, 1],
012| [1, 2, 2, 1, 2, 2, 2, 1],
013| [2, 2, 2, 1, 2, 2, 1, 2],
014| [2, 2, 1, 2, 2, 2, 1, 2],
015| [2, 2, 1, 2, 2, 1, 2, 2],
016| [2, 1, 2, 2, 2, 1, 2, 2],
017| [2, 1, 2, 2, 1, 2, 2, 2],
018| ]
019|
020|
021| Flat = '\u266d'
022| Sharp = '\u266f'
023| Flat2 = '\u266d\u266d'
024| Sharp2 = '\u266f\u266f'
025|
026|
027| BaseNotes = [
028| 'A','B'+Flat,'B','C','C'+Sharp,'D',
029| 'E'+Flat,'E','F','F'+Sharp,'G','G'+Sharp
030| ]
031|
032|
033| NoteTable = {
034| 'A':('A'+Flat2,'A'+Flat,'A','A'+Sharp,'A'+Sharp2),
035| 'B':('B'+Flat2,'B'+Flat,'B','B'+Sharp,'B'+Sharp2),
036| 'C':('C'+Flat2,'C'+Flat,'C','C'+Sharp,'C'+Sharp2),
037| 'D':('D'+Flat2,'D'+Flat,'D','D'+Sharp,'D'+Sharp2),
038| 'E':('E'+Flat2,'E'+Flat,'E','E'+Sharp,'E'+Sharp2),
039| 'F':('F'+Flat2,'F'+Flat,'F','F'+Sharp,'F'+Sharp2),
040| 'G':('G'+Flat2,'G'+Flat,'G','G'+Sharp,'G'+Sharp2),
041| }
042|
043|
044| def Note2Str (t):
045| base = t[0]
046| more = 2 + t[1]
047| return NoteTable[base][more]
048|
049|
050| def Str2Note (nt):
051| base = nt[0]
052| more = nt[1:2]
053| if more == Sharp: return (base, +1)
054| if more == Flat: return (base, -1)
055| return (base, 0)
056|
057|
058| def NoteAbove (nt):
059| if nt == 'G': return 'A'
060| return chr(ord(nt)+1)
061|
062|
063| def generate_scale (first_note=('C',0), mode_index=0):
064| mode = ModeIntervals[mode_index]
065| mode_name = ModeNames[mode_index]
066|
067| def next_note (nt, d):
068| nxnt = NoteAbove(nt[0])
069| if nt[0] in ['B', 'E']:
070| flag = nt[1]+(d-1)
071| else:
072| flag = nt[1]-(2-d)
073| return (nxnt, flag)
074|
075| scale = [first_note]
076| for dist in mode[1:7]:
077| note = next_note(scale[-1], dist)
078| scale.append(note)
079|
080| return (mode_name, [Note2Str(n) for n in scale])
081|
082|
083| def generate_section (first_note=('C',0)):
084| scales = []
085|
086| for mode in range(7):
087| notes = generate_scale(first_note, mode)
088| scales.append(notes)
089|
090| return scales
091|
092|
093| def generate_table ():
094| table = []
095|
096| for key in [3,2,1,0,11,10,9,8,7,6,5,4]:
097| note = Str2Note(BaseNotes[key])
098| sect = generate_section(note)
099| table.append(sect)
100|
101| return table
102|
103|
104|
105| def main (*args):
106| fmt = '%-11s| %-3s %-3s %-3s %-3s %-3s %-3s %-3s|'
107|
108| def display_table (table, stream=stdout):
109| for section in table:
110| for mode,scale in section:
111| print(fmt % (mode,*scale), file=stream)
112| print(file=stream)
113| print(file=stream)
114|
115| table = generate_table()
116| display_table(table)
117|
118| return table
119|
120|
121| if __name__ == "__main__":
122| print('autorun: %s' % argv[0])
123| rv = main(*argv[1:])
124| print()
125|
126| '''eof'''
127|