From 1a1718973bb7b786656129077327fce57fc04ae6 Mon Sep 17 00:00:00 2001 From: Thomas Lindner Date: Mon, 23 Dec 2024 17:17:12 +0100 Subject: [PATCH] increase pitch range, allow "comments" in csv --- freude.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/freude.py b/freude.py index 2d41492..5c8832e 100755 --- a/freude.py +++ b/freude.py @@ -16,7 +16,7 @@ parser.add_argument("--bpm", default=60, type=float, help="beats per minute") args = parser.parse_args() # starting from C3 = 130.81 Hz -frequencies = [2 ** (i / 12) * 130.81 for i in range(24)] +frequencies = [2 ** (i / 12) * 130.81 for i in range(36)] # duration of 1/16th beat base_duration = 60 / args.bpm / 16 @@ -30,9 +30,12 @@ with open(args.output, "w") as f: for filename in args.input: with open(filename, "r") as notes: for pitch, duration, pause in csv.reader(notes): + if pitch == "": + # skip comment + continue pitch = int(pitch) - if pitch < -12 or pitch > 11: - sys.exit("pitch goes from -12 == C3 to 11 == B4") + if pitch + 12 < 0 or pitch + 12 > len(frequencies) - 1: + sys.exit(f"pitch goes from -12 to {len(frequencies) - 1 - 12}") duration = int(duration) pause = int(pause) if duration < 1 or pause < 0: