-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6dbec46
commit c1b3631
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Author: [email protected] | ||
# Tested with Python3 | ||
# python major_scale.py C | ||
# ['C', 'D', 'E', 'F', 'G', 'A', 'B', 'C'] | ||
|
||
import argparse | ||
|
||
__doc__ = '''Script prints out major scale start from input note.''' | ||
|
||
notes = ('A', 'Bb', 'B', 'C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab') | ||
noteno = len(notes) | ||
WHOLE = 2 | ||
HALF = 1 | ||
|
||
|
||
def next_steps(note, steps=HALF): | ||
idx = notes.index(note) | ||
for step in range(steps): | ||
idx = (idx + 1) % noteno | ||
return notes[idx] | ||
|
||
|
||
def major_scale(start): | ||
out = [] | ||
out.append(start) | ||
n = start | ||
for step in [WHOLE, WHOLE, HALF, WHOLE, WHOLE, WHOLE, HALF]: | ||
n = next_steps(n, step) | ||
out.append(n) | ||
|
||
return out | ||
|
||
|
||
def main(): | ||
argp = argparse.ArgumentParser() | ||
argp.add_argument('note', help='Note starts the major scale') | ||
args = argp.parse_args() | ||
print(major_scale(args.note)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |