Skip to content

Commit

Permalink
save both ends of ranges in transpose runs
Browse files Browse the repository at this point in the history
I finally started working on #1.  I'll start with some changes
to find_transpose_runs that the new functionality will need.

- Add a docstring
- Save both ends of range: highest and lowest semitone
  • Loading branch information
pinobatch committed Mar 12, 2019
1 parent 68c5e86 commit ccaba34
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions tools/pentlyas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,24 +1298,30 @@ def add_pattern_note(self, word):
else:
raise ValueError("unknown pitched pattern note %s" % word)

# in a way that minimizes TRANSPOSE transitions
@staticmethod
def find_transpose_runs(data):
hi = None
runs = [[0, None]]
"""Break a list into runs of pitches up to 24 semitones apart.
Elements that are strings are ignored, as are sequences whose first
element is not an int.
Return a list of tuples, one for each run
[starting index of run, lowest semitone in run, highest semitone in run]
"""
runs = [[0, None, None]]
for i, note in enumerate(data):
if isinstance(note, str):
continue
pitch = note[0]
if not isinstance(pitch, int):
continue
lo = min(runs[-1][-1], pitch) if runs[-1][-1] is not None else pitch
hi = max(hi, pitch) if hi is not None else pitch
lo = min(runs[-1][1], pitch) if runs[-1][1] is not None else pitch
hi = max(runs[-1][2], pitch) if runs[-1][1] is not None else pitch
if hi - lo > 24:
runs.append([i, pitch])
hi = pitch
runs.append([i, pitch, pitch])
else:
runs[-1][-1] = lo
runs[-1][1:3] = lo, hi
return [tuple(i) for i in runs]

@staticmethod
Expand Down

0 comments on commit ccaba34

Please sign in to comment.