-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_ear_training.py
83 lines (63 loc) · 1.84 KB
/
gen_ear_training.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import genanki
import random
from shared import *
from mingus.midi import fluidsynth
import time
def main():
fluidsynth.init('piano.sf2')
fluidsynth.play_Note(48,0,100)
time.sleep(1)
add_all_cards()
# =================================================
card_priorities = {}
def chord_to_notes(s):
note, base = sorted([ (n, i) for i, n in enumerate(notes) if s.startswith(n) ], key=lambda x: -len(x[0]))[0]
chord_notes = [ base ] + list(map(lambda x: (x + base)%12, chord_type_map[s[len(note):]]))
idx_to_note = { i: n for i,n in enumerate(notes) }
return list(map(idx_to_note.get, chord_notes))
def add_card(q_id, q, a, priority):
card_priorities.setdefault(priority, [])
card_priorities[priority].append([ q_id, q, a ])
def add_all_cards():
for k in sorted(card_priorities.keys()):
for i, (q_id, q, a) in enumerate(card_priorities[k]):
p = '%05d' % k + ' ' + '%05d' % i
card = QuestionNote(model = my_model, fields = [ p, q_id, q, a ])
my_deck.add_note(card)
class QuestionNote(genanki.Note):
@property
def guid(self):
return genanki.guid_for(self.fields[1])
random.seed("piano-ear-training")
model_id = random.randrange(1 << 30, 1 << 31)
deck_id = random.randrange(1 << 30, 1 << 31)
style = """
.card {
font-family: times;
font-size: 30px;
text-align: center;
color: black;
background-color: white;
}
"""
my_model = genanki.Model(
model_id,
'Simple Model',
fields=[
{'name': 'priority'},
{'name': 'q_id'},
{'name': 'Question'},
{'name': 'Answer'}
],
templates=[
{
'name': 'Card 1',
'qfmt': '{{Question}}',
'afmt': '{{FrontSide}}<hr id="answer">{{Answer}}',
}
],
css = style)
my_deck = genanki.Deck(deck_id = deck_id,
name = 'Piano Ear Training')
main()
genanki.Package(my_deck).write_to_file('piano-ear-training.apkg')