Skip to content

Instantly share code, notes, and snippets.

@lanky
Created October 22, 2019 20:44
Show Gist options
  • Save lanky/5023fdb6b426c1c4ba1353318c5db6b6 to your computer and use it in GitHub Desktop.
Save lanky/5023fdb6b426c1c4ba1353318c5db6b6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import diagram
import copy
import attrdict
import yaml
from diagram.utils import dict_merge
CONFIG="""
---
Em_after_G:
title: Em (after G)
positions: "x232"
fingers: "-132"
# let us not forget that strings are 0-indexed
extras:
- string: 1
fret: 4
finger: 4
"""
def convert_int(item):
if isinstance(item, int):
return item
if isinstance(item, str):
if item.isdigit():
return int(item)
else:
return None
class MultiFingerChord(diagram.UkuleleChord):
def __init__(self, **kwargs):
extras = kwargs.get('extras')
if extras is not None:
del kwargs['extras']
super(MultiFingerChord, self).__init__(
positions=kwargs.get('positions', None),
fingers=kwargs.get('fingers', None),
barre=kwargs.get('barre', None),
title=kwargs.get('title', None),
style=kwargs.get('style', None),
)
self.extras = extras
def draw(self):
super(MultiFingerChord, self).draw()
if self.extras is not None:
for e in self.extras:
print(e)
self.fretboard.add_marker(
string=e['string'],
fret=e['fret'],
label=e['finger']
)
def main():
CFG = yaml.safe_load(CONFIG)
for chord, cfg in CFG.items():
test_chord = MultiFingerChord(**cfg)
test_chord.save('{}.svg'.format(chord))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment