spiffyscore

Check-in [87435601e4]
Login
Overview
Comment:Made some changes to the parser. Don't remember what.
Timelines: family | ancestors | master
Files: files | file ages | folders
SHA1: 87435601e4038963fe1778ef7599b8347d0b420b
User & Date: brian on 2011-06-12 20:32:21
Other Links: branch diff | manifest | tags
Context
2011-06-12
20:32
Made some changes to the parser. Don't remember what. Leaf check-in: 87435601e4 user: brian tags: master
2011-02-10
23:50
Program generates a render order for the instruments based on their sync order check-in: 689adc054e user: brian@linux-85dd.site tags: master
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Modified cfg.py from [e9b556b4f3] to [3cbe823f2f].

    28     28                   try:
    29     29                       render_order = topsort.topsort([[composition[movement][section][instrument]["sync"], instrument] if "sync" in composition[movement][section][instrument].keys() else [None, instrument] for instrument in composition[movement][section]])
    30     30                   except topsort.CycleError as ex:
    31     31                       print "Your instruments are synced in a circle! This makes no sense!"
    32     32                       print movement, section
    33     33                       print ex
    34     34                       sys.exit(1)
           35  +                while None in render_order:
           36  +                    render_order.remove(None)
           37  +                for instrument in render_order:
           38  +                    grammars = composition[movement][section][instrument]["grammars"]
           39  +                    for grammar in grammars:
           40  +                        if isinstance(grammars[grammar], list):
           41  +                            for option in range(len(grammar)):
           42  +                                grammars[grammar][option] = parse.parse(grammars[grammar][option])
           43  +                        else:
           44  +                            grammars[grammar] = parse.parse(grammars[grammar])
           45  +                    print instrument, movement, section
           46  +                    print grammars
           47  +
           48  +
           49  +def generate_score_phrase(grammar, grammars):
           50  +    count_length = 
           51  +    while count_length < 100000:
           52  +    
           53  +
    35     54                   
    36     55   
    37     56   #    for comp_name in progression.split():
    38     57   #        comp_start_time = max_t
    39     58   #        for instr_name, instr in composition[comp_name].iteritems():
    40     59   #            generated_score = generate_score(instr["score"], instr["grammars"])  # Fill in the scores by generating them based on the grammars
    41     60   ##            print generated_score

Modified parse.py from [3ec57c3fbe] to [c06717e335].

    13     13   class Chord():
    14     14       def __init__(self, value, duration=.5, chord_type="major", octave=5):
    15     15           self.value = value
    16     16           self.duration = duration
    17     17           self.chord_type = chord_type
    18     18           self.octave = octave
    19     19       def __repr__(self):
    20         -        return "Chord %s %s %s" % (self.value, self.duration, self.chord_type, self.octave)
           20  +        return "Chord %s %d %s %s" % (self.value, self.duration, self.chord_type, self.octave)
    21     21   
    22     22   class Rest():
    23     23       def __init__(self, duration=.25):
    24     24           self.duration = duration
    25     25       def __repr__(self):
    26     26           return "Rest node %s" % self.duration
    27     27   
................................................................................
    33     33           "BASENOTE",
    34     34           "ACCIDENTAL",
    35     35           "REST",
    36     36           "OCTAVE",
    37     37           "CHORD_TYPE",
    38     38           "PAREN",
    39     39           "SYNCOPATE",
           40  +        "NODE",
    40     41       )
    41     42   
    42     43       t_ignore = " |"
    43     44   
    44         -    #t_BASENOTE = r"[A-Ga-g]"
    45     45       t_BASENOTE = r"I+V?|VI*|i+v?|vi*"
    46     46       t_ACCIDENTAL = r"\^{1,2}|_{1,2}|="
    47     47       t_REST = r"z"
    48     48       t_OCTAVE = r"'+|,+"
    49         -    t_CHORD_TYPE = r"m|7|m7|0|o|\+|mb5|sus|sus4|maj7|mmaj7|7sus4|dim|dim7|7b5|m7b5|6|b6|m6|mb6|46|maj9|9|add9|7b9|m9"
           49  +    t_CHORD_TYPE = r"m|7|m7|0|o|mb5|sus|sus4|maj7|mmaj7|7sus4|dim|dim7|7b5|m7b5|6|b6|m6|mb6|46|maj9|9|add9|7b9|m9"
    50     50       t_PAREN = "\(|\)"
    51     51       t_SYNCOPATE = "\+|-"
           52  +#    t_NODE = "\w*(?!(([Vv][Ii]{0,3})|([Ii][Vv]?)))\w+"
           53  +    t_NODE = "\S+"
    52     54   
    53     55       def t_NOTE_LENGTH(t):
    54     56           r"/?\d+"
    55     57           multiplier = float(t.value.strip("/"))
    56     58           if t.value.startswith("/"):
    57     59               multiplier = 1/multiplier
    58     60           t.value = multiplier
................................................................................
    67     69   
    68     70       # Parse (yacc)
    69     71   
    70     72       def p_note_list(p):
    71     73           '''score : score note
    72     74                    | score chord
    73     75                    | score rest
           76  +                 | score node
    74     77           '''
    75     78           p[0] = p[1] + [p[2]]
    76     79   
    77     80       def p_score(p):
    78     81           '''score : note
    79     82                    | chord
    80     83                    | rest
    81     84           '''
    82     85           p[0] = [p[1]]
    83     86   
           87  +
           88  +    def p_node(p):
           89  +        '''node : NODE
           90  +        '''
           91  +        p[0] = p[1]
           92  +
    84     93   
    85     94       def p_chord_length(p):
    86     95           ''' chord : chord NOTE_LENGTH
    87     96           '''
    88     97           new_note = p[1]
    89     98           new_note.duration = p[2]
    90     99           p[0] = new_note
................................................................................
   101    110       def p_chord(p):
   102    111           '''chord : PAREN note PAREN
   103    112                    | PAREN note CHORD_TYPE PAREN
   104    113           '''
   105    114           pitch = p[2].value
   106    115           pitch = pitch.upper()
   107    116           p[0] = Chord(value=pitch, octave=default_octave)
   108         -        if len(p) > 3:
          117  +        if len(p) > 4:
   109    118               p[0].chord_type = p[3]
   110    119   
   111    120   
   112    121       def p_note_syncopate(p):
   113    122           ''' note : note SYNCOPATE
   114    123           '''
   115         -        note.syncopate = p[2]
          124  +        p[1].syncopate = p[2]
          125  +        p[0] = p[1]
   116    126   
   117    127   
   118    128       def p_accidental(p):
   119    129           '''note : ACCIDENTAL note
   120    130           '''
   121    131           p[2].accidental = p[1]
   122    132           p[0] = p[2]

Added score.yaml version [29fd4ba47c].

            1  +---
            2  +chorus:
            3  +    core:
            4  +        rhythm:
            5  +            csound_line: i1 %(time)f %(duration)f 7000 %(octave)d.%(note)s %(octave)d.%(note)s 0 6
            6  +            max_duration: 80
            7  +            sync: timbre
            8  +            octave: 7
            9  +            sustain: 1
           10  +            grammars:
           11  +                u: 
           12  +                    - (I) (ii)/4 (ii)/4 (IV)/2 (V)2 (IV) (ii) x u
           13  +                    - (I) (vii) (III) y u
           14  +                    - (I) (v) (IV) u u
           15  +                w: (i) (VII)2 (VI)/4 (V)/4 (i)/4 (VII)2 (VI) (V) w u
           16  +                x: (III/2) (VI)/2 (III)/2 (vii)2 (i)2 (V) u
           17  +                y: (I) (vi)2 (IV) (V) y y u
           18  +
           19  +        timbre:
           20  +            csound_line: i3 %(time)f %(duration)f 2000 %(octave)d.%(note)s 2 3 5 3
           21  +            max_duration: 80
           22  +            sync: melody
           23  +            sustain: 1
           24  +            octave: 6
           25  +            grammars:
           26  +                u: 
           27  +                    - I2+ VII2 V2 VI2 I2 IV/2 V/2 III2 u
           28  +                    - I2- IV2 V2 IV I V2 III2 II2. u
           29  +
           30  +        melody:
           31  +            csound_line: i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s 2
           32  +            max_duration: 80
           33  +            octave: 8
           34  +            grammars: 
           35  +                u: 
           36  +                    - I V/2 V/2 V/2 I VII
           37  +                    - IV' I IV I VII IV
           38  +                w: III/4 VI/4 II/4 V/4 VI/4 IV/4 VII2
           39  +                x: I/2 I/2 VI IV/2 V2 z I/2 I/2 VI IV/2 V