Skip to content

Instantly share code, notes, and snippets.

@notpushkin
Created December 23, 2020 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notpushkin/990e2c418719e27e20f27ed3c1a6c9f2 to your computer and use it in GitHub Desktop.
Save notpushkin/990e2c418719e27e20f27ed3c1a6c9f2 to your computer and use it in GitHub Desktop.
Double or halve stepchart BPM
def to_pairs(xs):
seq = iter(xs)
while True:
try:
x = next(seq)
except StopIteration:
return
try:
y = next(seq)
except StopIteration:
yield (x, None)
return
yield (x, y)
def dilute_measure(m, new_length):
if (new_length % len(m)) != 0:
raise Exception(f"can't dilute {len(m)} to {new_length}")
add_bars = new_length // len(m) - 1
return sum(map(list, zip(m, *(repeat("0000") for _ in range(add_bars)))), [])
def lcm(x, y):
return (x * y) // gcd(x, y)
def join_measures(m, n):
new_length = lcm(len(m), len(n))
return dilute_measure(m, new_length) + dilute_measure(n, new_length)
def halve_bpm(measures):
return [join_measures(a, b) for a, b in to_pairs(measures)]
def double_bpm(measures):
return sum(([m[:len(m)//2], m[len(m)//2:]] for m in measures), [])
def notes_loads(notes):
return [m.strip().split("\n") for m in notes.split(",")]
def notes_dumps(measures):
return "\n,".join("\n".join(m) for m in measures)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment