-
Notifications
You must be signed in to change notification settings - Fork 2
/
rchordata.py
executable file
·30 lines (23 loc) · 1.2 KB
/
rchordata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
# coding=utf-8
import argparse
from utils import render, build_diff_dict, get_instrument, INSTRUMENT_CHOICES
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Find chords by giving me notes')
parser.add_argument('notes', nargs='+',
help='space separated notes: start from 1st string (E on guitar). '
'Use "0" for open string and "x" for not played string.')
parser.add_argument('-i', '--instrument', dest='instrument',
choices=INSTRUMENT_CHOICES.keys(), default='mando',
help='instrument/tuning to search')
args = parser.parse_args()
STRINGS, CHORDS = get_instrument(args.instrument)
by_diff = build_diff_dict(CHORDS)
if len(args.notes) != len(STRINGS):
raise ValueError('You have provided less or more notes. %s has %d strings.' %
(args.instrument.capitalize(), len(STRINGS)))
notes = tuple(map(lambda x: int(x) if x != 'x' else -1, args.notes))
matches = [name for name, patt in CHORDS if notes == patt]
if matches:
render(notes, STRINGS)
print('\nIs known as: %s\n' % ', '.join(matches))