spiffyscore

Diff
Login

Differences From Artifact [b9f73ddafd]:

To Artifact [9c47a4ff24]:


7
8
9
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26
...
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
...
144
145
146
147
148
149
150
151
152
153
154
155
156
        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=.5, chord_type="major"):
        self.value = value
        self.duration = duration
        self.chord_type = chord_type

    def __repr__(self):
        return "Chord %s %s %s" % (self.value, self.duration, self.chord_type)


class Rest():
    def __init__(self, duration=.25):
        self.duration = duration
    def __repr__(self):
        return "Rest node %s" % self.duration
................................................................................

    def p_chord(p):
        '''chord : QUOTE pitch QUOTE
                | QUOTE pitch CHORD_TYPE QUOTE
        '''
        pitch = p[2].value
        pitch = pitch.upper()
        p[0] = Chord(value=pitch)
        if len(p) > 3:
            p[0].chord_type = p[3]


    def p_accidental(p):
        '''pitch : ACCIDENTAL pitch
        '''
................................................................................
                | REST NOTE_LENGTH
        '''
        p[0] = Rest()
        if len(p) > 2:
            p[0].duration = p[2]

    def p_error(p):
        print "Syntax error at '%s' of element type %s" % (p.value, p.type)
        
    yacc.yacc()

    #print yacc.parse("GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD")
    return yacc.parse(score)







|



>

|







 







|







 







|





7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
...
145
146
147
148
149
150
151
152
153
154
155
156
157
        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=.5, 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)


class Rest():
    def __init__(self, duration=.25):
        self.duration = duration
    def __repr__(self):
        return "Rest node %s" % self.duration
................................................................................

    def p_chord(p):
        '''chord : QUOTE pitch QUOTE
                | QUOTE pitch CHORD_TYPE QUOTE
        '''
        pitch = p[2].value
        pitch = pitch.upper()
        p[0] = Chord(value=pitch, octave=default_octave)
        if len(p) > 3:
            p[0].chord_type = p[3]


    def p_accidental(p):
        '''pitch : ACCIDENTAL pitch
        '''
................................................................................
                | REST NOTE_LENGTH
        '''
        p[0] = Rest()
        if len(p) > 2:
            p[0].duration = p[2]

    def p_error(p):
        raise Exception("Syntax error at '%s' of element type %s" % (p.value, p.type))
        
    yacc.yacc()

    #print yacc.parse("GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD")
    return yacc.parse(score)