Add support for english notations

This commit is contained in:
Phyks 2013-08-15 17:50:56 +02:00
parent 7c7941ee4f
commit c43809e021
2 changed files with 22 additions and 7 deletions

View File

@ -32,6 +32,11 @@ This program allows you to write a simple music sheet without always looking for
* RE, MI, FA, SOL, LA, SI, DO (where LA is 440Hz)
* RE2, MI2, FA2, SOL2, LA2, SI2, DO2 (where LA is 880Hz).
or the english corresponding notations :
* D0, E0, F0, G0, A, B, C (where A is 440Hz)
* D, E, F, G, A2, B2, C2 (where A2 is 880Hz)
Length is any integer you want. It will define the length of the note (play with both _length_ and _bpm_ (during playback) params to get what you want).
You can use the _-o_ (_--output_) option with a filename as argument to store the generated music sheet to this specific file.

View File

@ -20,6 +20,9 @@ for opt, arg in opts:
"(corresponding to LA = 440Hz) and RE2, MI2, FA2, SOL2, LA2, "
"SI2, DO2 (corresponding to LA2 = 880Hz)")
print("\nYou can also use the corresponding english notations D0, E0, "
"F0, G0, A (440Hz), B, C, D, E, F, G, A2, B2")
print("\nTo quit, just enter \"quit\" as note")
sys.exit()
@ -31,12 +34,16 @@ continue_while = True
notes = {"RE": 294, "MI": 330, "FA": 349, "SOL": 392, "LA": 440, "SI": 494,
"DO": 523, "RE2": 587, "MI2": 659, "FA2": 699, "SOL2": 794,
"LA2": 880, "SI2": 988}
partition = ''
notes_english = {"D0": 294, "E0": 330, "F0": 349, "G0": 392, "A": 440,
"B": 494, "C": 523, "D": 587, "E": 659, "F": 699, "G": 794,
"A2": 880, "B2": 988}
music_sheet = ''
while continue_while:
note = input("Note ? ")
if note.lower() == "quit":
if note.lower() == "quit" or note.lower() == "q":
continue_while = False
continue
@ -48,16 +55,19 @@ while continue_while:
continue_while = False
sys.exit("[ERROR] Entered length is not a number.")
if note.upper() not in notes.keys():
sys.exit("[ERROR] Unknown note "+note+".")
if note.upper() in notes.keys():
music_sheet += str(notes[note.upper()])+":"+str(length)+"\n"
elif note.upper() in notes_english.keys():
music_sheet += str(notes_english[note.upper()])+":"+str(length)+"\n"
else:
partition += str(notes[note.upper()])+":"+str(length)+"\n"
print("\nPartition :\n"+partition)
sys.exit("[ERROR] Unknown note "+note+".")
print("\nMusic sheet :\n"+music_sheet)
if output != '':
try:
with open(output, 'w') as output_fh:
output_fh.write(partition)
output_fh.write(music_sheet)
except:
sys.exit("[ERROR] Unable to write music sheet to the specified output"
"file.")