From 789e7c10bc8765d498ba9f1e4c3eac35b64b41e7 Mon Sep 17 00:00:00 2001 From: Houyhnhnm Date: Thu, 7 Jun 2018 14:16:34 +0200 Subject: render rhythms to score --- utils.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'utils.py') diff --git a/utils.py b/utils.py index fa37568..23995ae 100644 --- a/utils.py +++ b/utils.py @@ -8,23 +8,34 @@ def depth(myList, counter): counter += 1 depthList = [] for item in myList: - if isinstance(item, list): - depthList.append(depth(item, counter)) - else: - depthList.append(counter) + if isinstance(item, list): + depthList.append(depth(item, counter)) + else: + depthList.append(counter) return depthList def flatten(pool): - res = [] - for v in pool: - if isinstance(v, list): - res += flatten(v) - else: - if isinstance(v, int) or isinstance(v, str): - res.append(v) - return res + res = [] + for v in pool: + if isinstance(v, list): + res += flatten(v) + else: + if isinstance(v, int) or isinstance(v, str): + res.append(v) + return res def isOversliced(bars): targets = [bar > 0 and bar < 2.5 for bar in bars] return (True in targets) +def firstNonNegative(lst): + for x in lst: + if x >= 0: + return x + return 0 + +def lastNonPositive(lst): + for x in list(reversed(lst)): + if x <= 0: + return x + return 0 \ No newline at end of file -- cgit v1.2.3