1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#!/usr/bin/env python
import tree
from ply import lex, yacc
class Note():
def __init__(self, value, duration=1 octave=8):
self.value = value
self.duration = duration
self.octave = octave
self.accidental = None
def __repr__(self):
return "Note %s %s %s" % (self.value, self.duration, self.octave)
class Chord():
def __init__(self, value, duration=1, chord_type="major", octave=5):
self.value = value
self.duration = duration
self.chord_type = chord_type
self.octave = octave
def __repr__(self):
return "Chord %s %s %s" % (self.value, self.duration, self.chord_type, self.octave)
|
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#!/usr/bin/env python
import tree
from ply import lex, yacc
class Note():
def __init__(self, value, duration=.25, octave=8):
self.value = value
self.duration = duration
self.octave = octave
self.accidental = None
def __repr__(self):
return "Note %s %s %s" % (self.value, self.duration, self.octave)
class Chord():
def __init__(self, value, duration=.25, chord_type="major", octave=5):
self.value = value
self.duration = duration
self.chord_type = chord_type
self.octave = octave
def __repr__(self):
return "Chord %s %s %s" % (self.value, self.duration, self.chord_type, self.octave)
|
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
new_note.duration = p[2]
p[0] = new_note
def p_chord_length(p):
''' chord : chord NOTE_LENGTH
'''
new_note = p[1]
new_note.duration = p[2]
p[0] = new_note
def p_chord(p):
'''chord : QUOTE pitch QUOTE
| QUOTE pitch CHORD_TYPE QUOTE
'''
|
|
|
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
new_note.duration = p[2]
p[0] = new_note
def p_chord_length(p):
''' chord : chord NOTE_LENGTH
'''
new_note = p[1]
new_note.duration = 4*p[2]
p[0] = new_note
def p_chord(p):
'''chord : QUOTE pitch QUOTE
| QUOTE pitch CHORD_TYPE QUOTE
'''
|
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
def p_rest(p):
''' rest : REST
| REST NOTE_LENGTH
'''
p[0] = Rest()
if len(p) > 2:
p[0].duration = p[2]
def p_node(p):
'''node : NODE
'''
p[0] = tree.Tree(p[1].strip("(").strip(")"))
|
|
|
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
def p_rest(p):
''' rest : REST
| REST NOTE_LENGTH
'''
p[0] = Rest()
if len(p) > 2:
p[0].duration = 4*p[2]
def p_node(p):
'''node : NODE
'''
p[0] = tree.Tree(p[1].strip("(").strip(")"))
|