spiffyscore

Check-in [db1df2f460]
Login
Overview
Comment:TLD now accepts ordering of movements. Also, fixed bug that caused all movements and instruments to play simultaneously.
Timelines: family | ancestors | descendants | both | tld
Files: files | file ages | folders
SHA1: db1df2f46097d17176d49bbcc03494a7f4421d85
User & Date: spiffytech@gmail.com on 2010-11-17 06:27:03
Other Links: branch diff | manifest | tags
Context
2010-11-17
06:57
Note duration is now counted as fraction of a whole note, as measured based on BPM check-in: 5a35ffdd27 user: spiffytech@gmail.com tags: tld
06:27
TLD now accepts ordering of movements. Also, fixed bug that caused all movements and instruments to play simultaneously. check-in: db1df2f460 user: spiffytech@gmail.com tags: tld
05:32
Now supports minor chords check-in: f02f66468f user: spiffytech@gmail.com tags: tld
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Modified cfg.py from [79cec58b40] to [f043e9a785].

     8      8   import parse
     9      9   
    10     10   def main():
    11     11       key = "A"
    12     12   
    13     13       composition = {
    14     14           "a": {  # Movement block 'a' for reuse throughout the piece
    15         -#            "melody": {  # Instrument 'melody'
    16         -#                "csound_parameters": {
    17         -#                    "instrument": 1,
    18         -#                },
    19         -#                "grammars": {  # Notes for this instrument to use in this piece
    20         -#                    "u": ["I V V V I I IV u u", "I IV u u", "I VII IV u u"  , "e"],
    21         -#                    "e": [""],
    22         -#                },
    23         -#                "score": "u u u",
    24         -#            },
           15  +            "melody": {  # Instrument 'melody'
           16  +                "csound_parameters": {
           17  +                    "instrument": 1,
           18  +                },
           19  +                "grammars": {  # Notes for this instrument to use in this piece
           20  +                    "u": ["I V V V I I IV u u", "I IV u u", "I VII IV u u"  , "e"],
           21  +#                    "u": ["I I I I u u", "e"],
           22  +                    "e": [""],
           23  +                },
           24  +                "score": "u u u u u",
           25  +            },
    25     26               "rhythm": {
    26     27                   "csound_parameters": {
    27     28                       "instrument": 1,
    28     29                   },
    29     30                   "grammars": {
    30     31   #                    "u": ['"I" "ii"/4 "ii"/4 "IV"/2 "V"2 "IV" "I" u u', '"I" "vii" "IV" u u', '"I" "v" "IV" u u', "e"],
    31     32                       "u": ['"i" "I" "ii" "II" "v" "V" u', "e"],
    32     33                       "e": [""]
    33     34                   },
    34     35                   "score": "u u u",
    35     36               },
    36     37           },
    37         -#        "b": {
    38         -#            "melody": {  # Instrument 'melody'
    39         -#                "csound_parameters": {
    40         -#                    "instrument": 1,
    41         -#                },
    42         -#                "grammars": {  # Notes for this instrument to use in this piece
    43         -#                    "u": ["I V I I/2 IV/2 u u", "I4 IV u u", "I IV IV VI V u u"  , "e"],
    44         -#                    "e": [""],
    45         -#                },
    46         -#                "score": "u u u",
    47         -#            },
    48         -#            "rhythm": {
    49         -#                "csound_parameters": {
    50         -#                    "instrument": 1,
    51         -#                },
    52         -#                "grammars": {
    53         -#                    "u": ['"I" "IV"/2 "V"2 "IV" "I" u u', '"I" "VII" "IV" u u', '"I" "V" "IV" u u', "e"],
    54         -#                    "e": [""]
    55         -#                },
    56         -#                "score": "u u u",
    57         -#            },
    58         -#        },
           38  +        "b": {
           39  +            "melody": {  # Instrument 'melody'
           40  +                "csound_parameters": {
           41  +                    "instrument": 1,
           42  +                },
           43  +                "grammars": {  # Notes for this instrument to use in this piece
           44  +                    "u": ["I V I I/2 IV/2 u u", "I2 IV u u", "I IV IV VI V u u" , "e"],
           45  +#                    "u": ["I IV I V u u u", "e"],
           46  +                    "e": [""],
           47  +                },
           48  +                "score": "u u u",
           49  +            },
           50  +            "rhythm": {
           51  +                "csound_parameters": {
           52  +                    "instrument": 1,
           53  +                },
           54  +                "grammars": {
           55  +                    "u": ['"I" "IV"/2 "V"2 "IV" "I" u u', '"I" "VII" "IV" u u', '"I" "V" "IV" u u', "e"],
           56  +                    "e": [""]
           57  +                },
           58  +                "score": "u u u",
           59  +            },
           60  +        },
    59     61       }
    60     62   
    61         -    for comp_name, comp in composition.iteritems():
    62         -        for instr_name, instr in comp.iteritems():
           63  +    max_t = 0  # max time encountered so far. Used for movement timing
           64  +    progression = "a b"
           65  +    for comp_name in progression.split():
           66  +        instr_start_time = max_t
           67  +        for instr_name, instr in composition[comp_name].iteritems():
    63     68               generated_score = generate_score(instr["score"], instr["grammars"])  # Fill in the scores by generating them based on the grammars
    64         -#                composition[comp_name][instr_name][grammar]["score"] = parse.parse(generate_score)  # Return Node/Chord objects
    65     69               score = parse.parse(generated_score)  # Return Node/Chord objects
    66     70   
    67     71               # Generate timestamps for the notes 
    68         -            t = 0
           72  +            t = instr_start_time
    69     73               for note in range(len(score)):
    70     74                   score[note].time = t
    71     75                   t += score[note].duration
           76  +                max_t = t if t > max_t else max_t
           77  +#                print "end note,", max_t
    72     78               composition[comp_name][instr_name]["score"] = score
           79  +#            print "end instr,", max_t
    73     80   
    74         -    # Must be done after all note times keyed in, else you c,an't coordinate melodies with the rhythm chords
    75         -    for comp_name, comp in composition.iteritems():
    76         -        for instr_name, instr in comp.iteritems():
           81  +    # Must be done after all note times keyed in, else you can't coordinate melodies with the rhythm chords
           82  +    for comp_name in progression.split():
           83  +        for instr_name, instr in composition[comp_name].iteritems():
    77     84               composition[comp_name][instr_name]["score"] = transliterate_score(composition[comp_name][instr_name]["score"], key)
    78     85   #            print "\nMovement %s instrument %s" % (comp_name, instr_name)
    79     86   #            print composition[comp_name][instr_name]["score"] 
    80     87               print "f1  0   256 10  1 0 3   ; sine wave function table"
    81     88               final_score = generate_csound_score(composition[comp_name][instr_name]["score"])
    82     89               for line in final_score:
    83     90                   print line
................................................................................
    98    105       while 1:
    99    106           found_substitution = False
   100    107           for key,value in grammars.iteritems():
   101    108               if score.find(key) != -1:
   102    109                   found_substitution = True
   103    110                   while score.find(key) != -1:
   104    111                       score = score.replace(key, random.choice(grammars[key]), 1)
   105         -                    if len(score.split()) > 200:
          112  +                    if len(score.split()) > 20:
   106    113                           score = score.replace("u", "")
   107    114                           score = score.replace("e", "")
   108    115                           return score
   109    116           if found_substitution is False:
   110    117               break
   111    118       return score
   112    119   
................................................................................
   150    157           "F#": "06",
   151    158           "G": "07",
   152    159           "G#": "08",
   153    160           "A": "09",
   154    161           "A#": "10",
   155    162           "B": "11",
   156    163       }
   157         -    t = 0 
   158    164       csound_score = []
   159    165       for token in score:
   160    166           if isinstance(token, parse.Chord):  # Chords
   161    167               for note in token.chord: 
   162    168                   note = csound_note_values[note]
   163         -                csound_score.append("i2 %(time)f 1 7000 %(octave)d.%(note)s %(octave)d.%(note)s 0 6" % {"time": t, "octave": random.choice([7,8]), "note": note})
   164         -            t += 1
          169  +                csound_score.append("i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s %(octave)d.%(note)s 0 6" % {"time": token.time, "octave": random.choice([7,8]), "note": note, "duration": token.duration})
   165    170           else:  # Individual notes
   166    171               note = csound_note_values[token.value]
   167         -            csound_score.append("i2 %(time)f 1 7000 %(octave)d.%(note)s %(octave)d.%(note)s 0 6" % {"time": t, "octave": random.choice([8,9]), "note": note})
   168         -            t += .25
          172  +            csound_score.append("i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s %(octave)d.%(note)s 0 6" % {"time": token.time, "octave": random.choice([8,9]), "note": note, "duration": token.duration})
   169    173       return csound_score
   170    174   
   171    175   
   172    176   if __name__ == "__main__": main() 

Modified parse.py from [b7fd05b171] to [00dc77f47f].

     7      7           self.duration = duration
     8      8           self.octave = octave
     9      9           self.accidental = None
    10     10       def __repr__(self):
    11     11           return "Note %s %s %s" % (self.value, self.duration, self.octave)
    12     12   
    13     13   class Chord():
    14         -    def __init__(self, value, duration=.25, chord_type="major"):
           14  +    def __init__(self, value, duration=.5, chord_type="major"):
    15     15           self.value = value
    16     16           self.duration = duration
    17     17           self.chord_type = chord_type
    18     18       def __repr__(self):
    19     19           return "Chord %s %s %s" % (self.value, self.duration, self.chord_type)
    20     20   
    21     21   

Modified test.sco from [7126d43817] to [8d380ffb70].

     1      1   f1  0   256 10  1 0 3   ; sine wave function table
     2         -i2 0.000000 1 7000 7.11 7.11 0 6
     3         -i2 0.000000 1 7000 7.04 7.04 0 6
     4         -i2 0.000000 1 7000 8.08 8.08 0 6
     5         -i2 1.000000 1 7000 8.11 8.11 0 6
     6         -i2 1.000000 1 7000 8.04 8.04 0 6
     7         -i2 1.000000 1 7000 8.08 8.08 0 6
     8         -i2 2.000000 1 7000 8.01 8.01 0 6
     9         -i2 2.000000 1 7000 8.06 8.06 0 6
    10         -i2 2.000000 1 7000 8.09 8.09 0 6
    11         -i2 3.000000 1 7000 7.01 7.01 0 6
    12         -i2 3.000000 1 7000 7.06 7.06 0 6
    13         -i2 3.000000 1 7000 8.09 8.09 0 6
    14         -i2 4.000000 1 7000 7.06 7.06 0 6
    15         -i2 4.000000 1 7000 7.09 7.09 0 6
    16         -i2 4.000000 1 7000 7.01 7.01 0 6
    17         -i2 5.000000 1 7000 8.06 8.06 0 6
    18         -i2 5.000000 1 7000 7.09 7.09 0 6
    19         -i2 5.000000 1 7000 7.01 7.01 0 6
    20         -i2 6.000000 1 7000 7.11 7.11 0 6
    21         -i2 6.000000 1 7000 7.04 7.04 0 6
    22         -i2 6.000000 1 7000 8.08 8.08 0 6
    23         -i2 7.000000 1 7000 8.11 8.11 0 6
    24         -i2 7.000000 1 7000 7.04 7.04 0 6
    25         -i2 7.000000 1 7000 7.08 7.08 0 6
    26         -i2 8.000000 1 7000 8.01 8.01 0 6
    27         -i2 8.000000 1 7000 8.06 8.06 0 6
    28         -i2 8.000000 1 7000 7.09 7.09 0 6
    29         -i2 9.000000 1 7000 8.01 8.01 0 6
    30         -i2 9.000000 1 7000 7.06 7.06 0 6
    31         -i2 9.000000 1 7000 8.09 8.09 0 6
    32         -i2 10.000000 1 7000 8.06 8.06 0 6
    33         -i2 10.000000 1 7000 7.09 7.09 0 6
    34         -i2 10.000000 1 7000 8.01 8.01 0 6
    35         -i2 11.000000 1 7000 8.06 8.06 0 6
    36         -i2 11.000000 1 7000 8.09 8.09 0 6
    37         -i2 11.000000 1 7000 8.01 8.01 0 6
    38         -i2 12.000000 1 7000 7.11 7.11 0 6
    39         -i2 12.000000 1 7000 7.04 7.04 0 6
    40         -i2 12.000000 1 7000 8.08 8.08 0 6
    41         -i2 13.000000 1 7000 7.11 7.11 0 6
    42         -i2 13.000000 1 7000 8.04 8.04 0 6
    43         -i2 13.000000 1 7000 7.08 7.08 0 6
    44         -i2 14.000000 1 7000 7.01 7.01 0 6
    45         -i2 14.000000 1 7000 7.06 7.06 0 6
    46         -i2 14.000000 1 7000 7.09 7.09 0 6
    47         -i2 15.000000 1 7000 8.01 8.01 0 6
    48         -i2 15.000000 1 7000 8.06 8.06 0 6
    49         -i2 15.000000 1 7000 7.09 7.09 0 6
    50         -i2 16.000000 1 7000 8.06 8.06 0 6
    51         -i2 16.000000 1 7000 8.09 8.09 0 6
    52         -i2 16.000000 1 7000 7.01 7.01 0 6
    53         -i2 17.000000 1 7000 7.06 7.06 0 6
    54         -i2 17.000000 1 7000 7.09 7.09 0 6
    55         -i2 17.000000 1 7000 7.01 7.01 0 6
            2  +i2 0.000000 0.250000 7000 8.09 8.09 0 6
            3  +i2 0.250000 0.250000 7000 9.02 9.02 0 6
            4  +i2 0.500000 0.250000 7000 9.09 9.09 0 6
            5  +i2 0.750000 0.250000 7000 9.04 9.04 0 6
            6  +i2 1.000000 0.250000 7000 8.04 8.04 0 6
            7  +i2 1.250000 0.250000 7000 8.04 8.04 0 6
            8  +i2 1.500000 0.250000 7000 8.09 8.09 0 6
            9  +i2 1.750000 0.250000 7000 9.09 9.09 0 6
           10  +i2 2.000000 0.250000 7000 8.02 8.02 0 6
           11  +i2 2.250000 0.250000 7000 8.09 8.09 0 6
           12  +i2 2.500000 0.250000 7000 9.04 9.04 0 6
           13  +i2 2.750000 0.250000 7000 8.04 8.04 0 6
           14  +i2 3.000000 0.250000 7000 9.04 9.04 0 6
           15  +i2 3.250000 0.250000 7000 9.09 9.09 0 6
           16  +i2 3.500000 0.250000 7000 9.09 9.09 0 6
           17  +i2 3.750000 0.250000 7000 8.02 8.02 0 6
           18  +f1  0   256 10  1 0 3   ; sine wave function table
           19  +i2 0.000000 0.500000 7000 7.11 7.11 0 6
           20  +i2 0.000000 0.500000 7000 7.04 7.04 0 6
           21  +i2 0.000000 0.500000 7000 7.08 7.08 0 6
           22  +i2 0.500000 0.500000 7000 7.11 7.11 0 6
           23  +i2 0.500000 0.500000 7000 8.04 8.04 0 6
           24  +i2 0.500000 0.500000 7000 8.08 8.08 0 6
           25  +i2 1.000000 0.500000 7000 8.01 8.01 0 6
           26  +i2 1.000000 0.500000 7000 7.06 7.06 0 6
           27  +i2 1.000000 0.500000 7000 7.09 7.09 0 6
           28  +i2 1.500000 0.500000 7000 8.01 8.01 0 6
           29  +i2 1.500000 0.500000 7000 7.06 7.06 0 6
           30  +i2 1.500000 0.500000 7000 8.09 8.09 0 6
           31  +i2 2.000000 0.500000 7000 7.06 7.06 0 6
           32  +i2 2.000000 0.500000 7000 8.09 8.09 0 6
           33  +i2 2.000000 0.500000 7000 8.01 8.01 0 6
           34  +i2 2.500000 0.500000 7000 8.06 8.06 0 6
           35  +i2 2.500000 0.500000 7000 8.09 8.09 0 6
           36  +i2 2.500000 0.500000 7000 7.01 7.01 0 6
           37  +i2 3.000000 0.500000 7000 8.11 8.11 0 6
           38  +i2 3.000000 0.500000 7000 8.04 8.04 0 6
           39  +i2 3.000000 0.500000 7000 8.08 8.08 0 6
           40  +i2 3.500000 0.500000 7000 8.11 8.11 0 6
           41  +i2 3.500000 0.500000 7000 7.04 7.04 0 6
           42  +i2 3.500000 0.500000 7000 8.08 8.08 0 6
           43  +i2 4.000000 0.500000 7000 8.01 8.01 0 6
           44  +i2 4.000000 0.500000 7000 7.06 7.06 0 6
           45  +i2 4.000000 0.500000 7000 8.09 8.09 0 6
           46  +i2 4.500000 0.500000 7000 7.01 7.01 0 6
           47  +i2 4.500000 0.500000 7000 7.06 7.06 0 6
           48  +i2 4.500000 0.500000 7000 7.09 7.09 0 6
           49  +i2 5.000000 0.500000 7000 7.06 7.06 0 6
           50  +i2 5.000000 0.500000 7000 7.09 7.09 0 6
           51  +i2 5.000000 0.500000 7000 8.01 8.01 0 6
           52  +i2 5.500000 0.500000 7000 8.06 8.06 0 6
           53  +i2 5.500000 0.500000 7000 8.09 8.09 0 6
           54  +i2 5.500000 0.500000 7000 8.01 8.01 0 6
           55  +f1  0   256 10  1 0 3   ; sine wave function table
           56  +i2 6.000000 2.000000 7000 9.09 9.09 0 6
           57  +i2 8.000000 0.250000 7000 9.02 9.02 0 6
           58  +i2 8.250000 0.250000 7000 8.09 8.09 0 6
           59  +i2 8.500000 0.250000 7000 9.04 9.04 0 6
           60  +i2 8.750000 0.250000 7000 8.09 8.09 0 6
           61  +i2 9.000000 0.500000 7000 8.09 8.09 0 6
           62  +i2 9.500000 0.500000 7000 9.02 9.02 0 6
           63  +i2 10.000000 0.250000 7000 9.09 9.09 0 6
           64  +i2 10.250000 0.250000 7000 9.02 9.02 0 6
           65  +i2 10.500000 0.250000 7000 9.02 9.02 0 6
           66  +i2 10.750000 0.250000 7000 8.06 8.06 0 6
           67  +i2 11.000000 0.250000 7000 9.04 9.04 0 6
           68  +i2 11.250000 0.250000 7000 8.09 8.09 0 6
           69  +i2 11.500000 0.250000 7000 9.02 9.02 0 6
           70  +i2 11.750000 0.250000 7000 9.02 9.02 0 6
           71  +i2 12.000000 0.250000 7000 9.06 9.06 0 6
           72  +i2 12.250000 0.250000 7000 8.04 8.04 0 6
           73  +f1  0   256 10  1 0 3   ; sine wave function table
           74  +i2 6.000000 0.500000 7000 8.11 8.11 0 6
           75  +i2 6.000000 0.500000 7000 8.04 8.04 0 6
           76  +i2 6.000000 0.500000 7000 8.08 8.08 0 6
           77  +i2 6.500000 0.500000 7000 7.04 7.04 0 6
           78  +i2 6.500000 0.500000 7000 8.09 8.09 0 6
           79  +i2 6.500000 0.500000 7000 8.11 8.11 0 6
           80  +i2 7.000000 2.000000 7000 8.06 8.06 0 6
           81  +i2 7.000000 2.000000 7000 8.09 8.09 0 6
           82  +i2 7.000000 2.000000 7000 8.01 8.01 0 6
           83  +i2 9.000000 0.500000 7000 7.04 7.04 0 6
           84  +i2 9.000000 0.500000 7000 8.09 8.09 0 6
           85  +i2 9.000000 0.500000 7000 7.11 7.11 0 6
           86  +i2 9.500000 0.500000 7000 8.11 8.11 0 6
           87  +i2 9.500000 0.500000 7000 7.04 7.04 0 6
           88  +i2 9.500000 0.500000 7000 7.08 7.08 0 6
           89  +i2 10.000000 0.500000 7000 7.11 7.11 0 6
           90  +i2 10.000000 0.500000 7000 7.04 7.04 0 6
           91  +i2 10.000000 0.500000 7000 8.08 8.08 0 6
           92  +i2 10.500000 0.500000 7000 8.04 8.04 0 6
           93  +i2 10.500000 0.500000 7000 8.09 8.09 0 6
           94  +i2 10.500000 0.500000 7000 7.11 7.11 0 6
           95  +i2 11.000000 2.000000 7000 7.06 7.06 0 6
           96  +i2 11.000000 2.000000 7000 7.09 7.09 0 6
           97  +i2 11.000000 2.000000 7000 8.01 8.01 0 6
           98  +i2 13.000000 0.500000 7000 7.04 7.04 0 6
           99  +i2 13.000000 0.500000 7000 8.09 8.09 0 6
          100  +i2 13.000000 0.500000 7000 8.11 8.11 0 6
          101  +i2 13.500000 0.500000 7000 7.11 7.11 0 6
          102  +i2 13.500000 0.500000 7000 8.04 8.04 0 6
          103  +i2 13.500000 0.500000 7000 8.08 8.08 0 6
          104  +i2 14.000000 0.500000 7000 8.11 8.11 0 6
          105  +i2 14.000000 0.500000 7000 7.04 7.04 0 6
          106  +i2 14.000000 0.500000 7000 7.08 7.08 0 6
          107  +i2 14.500000 0.500000 7000 8.06 8.06 0 6
          108  +i2 14.500000 0.500000 7000 7.09 7.09 0 6
          109  +i2 14.500000 0.500000 7000 7.01 7.01 0 6
          110  +i2 15.000000 0.500000 7000 7.04 7.04 0 6
          111  +i2 15.000000 0.500000 7000 8.09 8.09 0 6
          112  +i2 15.000000 0.500000 7000 8.11 8.11 0 6
          113  +i2 15.500000 0.500000 7000 7.11 7.11 0 6
          114  +i2 15.500000 0.500000 7000 7.04 7.04 0 6
          115  +i2 15.500000 0.500000 7000 7.08 7.08 0 6
          116  +i2 16.000000 0.500000 7000 8.04 8.04 0 6
          117  +i2 16.000000 0.500000 7000 7.09 7.09 0 6
          118  +i2 16.000000 0.500000 7000 8.11 8.11 0 6
          119  +i2 16.500000 2.000000 7000 8.06 8.06 0 6
          120  +i2 16.500000 2.000000 7000 7.09 7.09 0 6
          121  +i2 16.500000 2.000000 7000 8.01 8.01 0 6
          122  +i2 18.500000 0.500000 7000 7.04 7.04 0 6
          123  +i2 18.500000 0.500000 7000 7.09 7.09 0 6
          124  +i2 18.500000 0.500000 7000 8.11 8.11 0 6
          125  +i2 19.000000 0.500000 7000 8.11 8.11 0 6
          126  +i2 19.000000 0.500000 7000 8.04 8.04 0 6
          127  +i2 19.000000 0.500000 7000 7.08 7.08 0 6

Modified todo.org from [0747c315e6] to [11f927dcbf].

     1         -* Features [1/4]
            1  +* Features [1/5]
     2      2   - [X] Top-down composition
     3      3   - [ ] Transition the melody between chords appropriately
     4      4   - [ ] Set maximum song length
     5      5   - [ ] Need to support all chord types
            6  +- [ ] Doesn't handle rest notes
     6      7   
     7         -* Bugs [1/5]
     8         -- [ ] TLD resets clock for each movement
     9         -- [ ] TLD doesn't accept an ordering for the movements
    10         -- [X] Doesn't handle minor chords
    11         -- [ ] Duration syntax is absolute, not relative to BPM
            8  +* Bugs [3/5]
            9  +- [X] TLD resets clock for each movement
           10  +- [X] TLD doesn't accept an ordering for the movements
           11  +- [X] Doesn't handle minor chords    
           12  +- [ ] Calculated duration is absolute, not relative to BPM
    12     13   - [ ] Chords don't respect octaves
    13     14   
    14     15   
    15         -* Structure [0/2]
           16  +* Structure [0/3]    
    16     17   - [ ] Chords should be composed of Notes, not ordinary arrays
    17     18   - [ ] Generate score with proper generation tools
           19  +- [ ] Store csound score lines with instruments