concertina_helper.output_utils
1from __future__ import annotations 2from collections.abc import Iterable 3 4from .layouts.bisonoric import AnnotatedBisonoricFingering 5from .type_defs import Direction 6 7 8def condense(fingerings: Iterable[AnnotatedBisonoricFingering]) -> str: 9 ''' 10 Given a sequence of fingerings, 11 returns a compact, tab delimitted string representation 12 of the entire sequence, up to 20 fingerings. 13 14 Buttons to hit while pushing are represented like this: 15 > ➀➁➂ 16 17 while buttons for the pull are represented: 18 > ➊➋➌ 19 ''' 20 chars = { 21 Direction.PUSH: '➀➁➂➃➄➅➆➇➈➉⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳', 22 Direction.PULL: '➊➋➌➍➎➏➐➑➒➓⓫⓬⓭⓮⓯⓰⓱⓲⓳⓴' 23 } 24 25 f_list = list(fingerings) 26 max_len = len(chars[Direction.PUSH]) 27 if len(f_list) > max_len: 28 raise ValueError( 29 f'Length of fingerings ({len(f_list)}) ' 30 f'greater than allowed ({max_len})') 31 32 left = [[''] * row_len for row_len in f_list[0].fingering.left_mask.shape] 33 right = [[''] * row_len for row_len in f_list[0].fingering.right_mask.shape] 34 35 for index, f in enumerate(f_list): 36 for i, row in enumerate(f.fingering.left_mask): 37 for j, button in enumerate(row): 38 if button: 39 left[i][j] += chars[f.fingering.direction][index] 40 for i, row in enumerate(f.fingering.right_mask): 41 for j, button in enumerate(row): 42 if button: 43 right[i][j] += chars[f.fingering.direction][index] 44 45 lines = [] 46 for left_row, right_row in zip(left, right): 47 line = [] 48 for finger_string in left_row: 49 line.append(finger_string or '.') 50 line.append(' ') 51 for finger_string in right_row: 52 line.append(finger_string or '.') 53 lines.append(' '.join(line)) 54 return '\n'.join(lines)
def
condense( fingerings: collections.abc.Iterable[concertina_helper.layouts.bisonoric.AnnotatedBisonoricFingering]) -> str:
9def condense(fingerings: Iterable[AnnotatedBisonoricFingering]) -> str: 10 ''' 11 Given a sequence of fingerings, 12 returns a compact, tab delimitted string representation 13 of the entire sequence, up to 20 fingerings. 14 15 Buttons to hit while pushing are represented like this: 16 > ➀➁➂ 17 18 while buttons for the pull are represented: 19 > ➊➋➌ 20 ''' 21 chars = { 22 Direction.PUSH: '➀➁➂➃➄➅➆➇➈➉⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳', 23 Direction.PULL: '➊➋➌➍➎➏➐➑➒➓⓫⓬⓭⓮⓯⓰⓱⓲⓳⓴' 24 } 25 26 f_list = list(fingerings) 27 max_len = len(chars[Direction.PUSH]) 28 if len(f_list) > max_len: 29 raise ValueError( 30 f'Length of fingerings ({len(f_list)}) ' 31 f'greater than allowed ({max_len})') 32 33 left = [[''] * row_len for row_len in f_list[0].fingering.left_mask.shape] 34 right = [[''] * row_len for row_len in f_list[0].fingering.right_mask.shape] 35 36 for index, f in enumerate(f_list): 37 for i, row in enumerate(f.fingering.left_mask): 38 for j, button in enumerate(row): 39 if button: 40 left[i][j] += chars[f.fingering.direction][index] 41 for i, row in enumerate(f.fingering.right_mask): 42 for j, button in enumerate(row): 43 if button: 44 right[i][j] += chars[f.fingering.direction][index] 45 46 lines = [] 47 for left_row, right_row in zip(left, right): 48 line = [] 49 for finger_string in left_row: 50 line.append(finger_string or '.') 51 line.append(' ') 52 for finger_string in right_row: 53 line.append(finger_string or '.') 54 lines.append(' '.join(line)) 55 return '\n'.join(lines)
Given a sequence of fingerings, returns a compact, tab delimitted string representation of the entire sequence, up to 20 fingerings.
Buttons to hit while pushing are represented like this:
➀➁➂
while buttons for the pull are represented:
➊➋➌