NOTES = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']

MODE_PATTERNS = {
    'Ionian':     [2,2,1,2,2,2,1],
    'Dorian':     [2,1,2,2,2,1,2],
    'Phrygian':   [1,2,2,2,1,2,2],
    'Lydian':     [2,2,2,1,2,2,1],
    'Mixolydian': [2,2,1,2,2,1,2],
    'Aeolian':    [2,1,2,2,1,2,2],
    'Locrian':    [1,2,2,1,2,2,2],
}

def build_scale(root, pattern):
    idx = NOTES.index(root)
    scale = [NOTES[idx]]
    for step in pattern[:-1]:
        idx = (idx + step) % 12
        scale.append(NOTES[idx])
    return ' '.join(scale)

lines = [
    "TITLE: Modal Scale Reference",
    "DOMAIN: Music Theory",
    "CONCEPTS: Modes, scales, Dorian, Phrygian, Lydian, Mixolydian, Aeolian, Locrian, Ionian, intervals, note spelling",
    "CONTENT TYPE: Reference",
    "---",
    ""
]

for mode, pattern in MODE_PATTERNS.items():
    for root in NOTES:
        scale = build_scale(root, pattern)
        lines.append(f"The notes in the {root} {mode} scale are {scale}.")

with open('Books/Music/Theory/Modal_Scale_Reference.txt', 'w') as f:
    f.write('\n'.join(lines))

print("Done.")