spiffyscore

Check-in [872ae93059]
Login
Overview
SHA1:872ae930598cac24eced9515f360579eee52d6e2
Date: 2011-11-16 00:14:47
User: brian
Comment:If I move from csound to midi I should actually rename function with 'csound' in the name
Timelines: family | ancestors | descendants | both | develop
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2011-11-17
19:55
[f8034c7dfb] Removed leftover csound function lines that got printed. Also disabled ipdb so I get concise stacktraces. Also made program crash when your score pointed to a non-existant node. Previously that just generated an invalid MIDI file (somehow...) (user: brian, tags: develop)
2011-11-16
00:14
[872ae93059] If I move from csound to midi I should actually rename function with 'csound' in the name (user: brian, tags: develop)
2011-11-15
22:12
[680f187463] Removed useless samples and test csound files now that we're no longer using csound (user: brian, tags: develop)
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

parse.py became a regular file with contents [bcac1af73f].


Modified spiffyscore.py from [caa7e9ffa7] to [5ac9fc3252].

    15     15   import tree
    16     16   
    17     17   random.seed(time.time())
    18     18   mymidi = midifile(15)
    19     19   
    20     20   def main():
    21     21       composition = {
    22         -        "fm_test": {
    23         -            "intro": {
    24         -                "melody": {  # Instrument 'melody'
    25         -                    "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s 2 6 5 1",
    26         -                    "octave": 8,
    27         -                    "duration": 10,
    28         -                    "grammars": {  # Notes for this instrument to use in this piece
    29         -                        "u": ["G/2 G/2 | G/4 G/4 A/4 A/4 | A/2 A/2 | G | G | A | A | A3 (w)"],
    30         -                        "w": ["E | E | F | F | G/2 G/2 | G3 (u)"],
    31         -                    },
    32         -                },
    33         -            },
    34         -        },
    35         -        "verse1": {
    36         -            "intro": {
    37         -                "melody": {  # Instrument 'melody'
    38         -                    "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s 1",
    39         -                    "octave": 8,
    40         -                    "duration": 10,
    41         -                    "grammars": {  # Notes for this instrument to use in this piece
    42         -                        "u": ["G/2 G/2 | G/4 G/4 A/4 A/4 | A/2 A/2 | G | G | A | A | A3 (w)"],
    43         -                        "w": ["E | E | F | F | G/2 G/2 | G3 (u)"],
    44         -                    },
    45         -                },
    46         -            },
    47         -            "body": {
    48         -                "melody": {  # Instrument 'melody'
    49         -                    "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s 1",
    50         -                    "octave": 8,
    51         -                    "duration": 10,
    52         -                    "grammars": {  # Notes for this instrument to use in this piece
    53         -                        "u": ["C | G/2 G/2 | G/2 G/2 | C | B, | F' | C | F | C | B | F | (w)"],
    54         -                        "w": ["E/4 A/4 D/4 G/4 | F/4 F/4 B2 | (u)"],
    55         -                    },
    56         -                },
    57         -            },
    58         -            "outro": {
    59         -                "melody": {  # Instrument 'melody'
    60         -                    "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s 1",
    61         -                    "octave": 8,
    62         -                    "duration": 10,
    63         -                    "grammars": {  # Notes for this instrument to use in this piece
    64         -                        "u": ["C/4 C/4 C/4 C/4 | z2"],
    65         -                    },
    66         -                },
    67         -            },
    68         -        },
    69         -        "verse2": {
    70         -            "body": {
    71         -                "melody": {  # Instrument 'melody'
    72         -                    "score_line": "i2 %(time)f %(duration)f 7000 %(octave)d.%(note)s 1",
    73         -                    "octave": 8,
    74         -                    "duration": 30,
    75         -                    "grammars": {  # Notes for this instrument to use in this piece
    76         -                        "u": ["C | C | C | C | F/2 F/2 | F/2 F/2 | (u)", "D | D | G/2 A/2 | D | D | (u)"],
    77         -                    },
    78         -                },
    79         -                "harmony": {  # Instrument 'melody'
    80         -                    "score_line": "i3 %(time)f %(duration)f 4000 %(octave)d.%(note)s 2 3 5 3",
    81         -                    "octave": 8,
    82         -                    "duration": 30,
    83         -                    "grammars": {  # Notes for this instrument to use in this piece
    84         -                        "u": ["C | C | z | C | C | z/2 F/4 F/2 F/2 | F/2 F/2 | z (u)", "D | D | G/2 A/2 | D | D | z (u)"],
    85         -                    },
    86         -                },
    87         -                "percussion": {  # Instrument 'melody'
    88         -                    "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(note)s %(octave)d.%(note)s 0 6",
    89         -                    "octave": 8,
    90         -                    "duration": 30,
    91         -                    "grammars": {  # Notes for this instrument to use in this piece
    92         -                        "u": ["C/4 C/4 C/4 C/4 | F/2 F/2 | F/2 F/2 | (u)", "D/4 D/4 G/4 A/4 | D | D | (v)"],
    93         -                        "v": ["C | D | E | F | E | D | C | (u)",],
    94         -                    },
    95         -                },
    96         -            },
    97         -            "outro": {
    98         -                "percussion": {  # Instrument 'melody'
    99         -                    "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(note)s %(octave)d.%(note)s 0 6",
   100         -                    "octave": 8,
   101         -                    "duration": 30,
   102         -                    "grammars": {  # Notes for this instrument to use in this piece
   103         -                        "u": ["C/4 C/4 C/4 C/4"],
   104         -                    },
   105         -                },
   106         -            },
   107         -        },
   108         -        "sync_test": {
           22  +        "intro": {
   109     23               "body": {
   110     24                   "lead_instr": {  # Instrument 'melody'
   111     25                       "channel": 6,
   112     26                       "octave": 4,
   113     27                       "duration": 30,
   114     28                       "grammars": {  # Notes for this instrument to use in this piece
   115         -#                        "u": ["A ^A B C ^C D ^D E F ^F G ^G"],
   116         -                        "u": ["A/2, B/2, C/2 D/2 (u)", "D/2' D/2' D/2' D/2' (x)"],
           29  +                        "u": ["A/2, B/2, C/2 D/2 (u)", "D2' D2' D2' D2' (x)"],
   117     30                           "v": ["C/2 C/2 C/2 C/2 (w)"],
   118     31                           "w": ["E/2 F/2 E/2 F/2 (u)"],
   119     32                           "x": ["z4 (v)"],
   120     33                       },
   121     34                   },
   122         -                "follow_instr": {  # Instrument 'melody'
   123         -                    "channel": 0,
           35  +                "follow_instr": {  # Instrument 'bass'
           36  +                    "channel": 4,
   124     37                       "sync": "lead_instr",
   125     38                       "octave": 2,
   126     39                       "duration": 30,
   127     40                       "grammars": {  # Notes for this instrument to use in this piece
   128         -#                        "u": ["A ^A B C ^C D ^D E F ^F G ^G"],
   129     41                           "u": ["E F G E (v)"],
   130     42                           "v": ["G A A A (e)", "G A A A (v)"],
   131     43                           "e": ["B A G A (u)"],
   132     44                           "x": ["z4 (e)"],
   133     45                       },
   134     46                   },
   135         -#                "instr2": {  # Instrument 'melody'
   136         -#                    "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(note)s %(octave)d.%(note)s 0 6",
   137         -#                    "score_line": "i1 %(time)f %(duration)f 7000 %(octave)d.%(note)s %(octave)d.%(note)s",
   138         -#                    "octave": 5,
   139         -#                    "duration": 30,
   140         -#                    "grammars": {  # Notes for this instrument to use in this piece
   141         -##                        "u": ["A ^A B C ^C D ^D E F ^F G ^G"],
   142         -#                        "u": ["A/2, B/2, C/2 D/2 (u)", "D/2' D/2' D/2' D/2' (v)"],
   143         -#                        "v": ["C/2 C/2 C/2 C/2 (w)"],
   144         -#                        "w": ["E/2 F/2 E/2 F/2 (u)"],
   145         -#                    },
   146         -#                },
   147     47               },
   148     48           },
   149     49       }
   150     50       print '''f1 0 512 10 1
   151     51   f2 0 8192 10 .24 .64 .88 .76 .06 .5 .34 .08
   152     52   f3 0 1025 10 1
   153     53   t 0 60
   154     54       '''
   155     55   
   156     56       section_start = 0
   157         -#    for section in ["verse1", "verse2"]:
   158         -    for section in ["sync_test"]:
           57  +    for section in ["intro"]:
   159     58           print "; Section " + section
   160     59           subsection_start = section_start
   161     60           section = composition[section]
   162     61           for subsection in ["intro", "body", "outro"]:
   163     62               try:
   164     63                   print "; Subsection " + subsection
   165     64                   subsection = section[subsection]
................................................................................
   178     77                   track = 0
   179     78                   for instr in ordered_instrs:
   180     79                       print ";Instrument " + instr
   181     80                       instr = subsection[instr]
   182     81                       max_time = instr["duration"]
   183     82                       instr_score, syncs = render_instr(instr, syncs, max_time)
   184     83                       instrs.append(instr_score)
   185         -                    generate_csound_score(instr_score, track, instr["channel"], subsection_start)
           84  +                    midify_instr_score(instr_score, track, instr["channel"], subsection_start)
   186     85                   longest_score = max(instrs, key=lambda i: score_len(i))
   187     86                   subsection_start += score_len(longest_score)
   188     87                   section_start += score_len(longest_score)
   189     88                   track += 1
   190     89               except KeyError:
   191     90                   pass
   192     91       with open("out.mid", "wb") as outfile:
................................................................................
   276    175       return total
   277    176   
   278    177   
   279    178   def get_midi_note(octave, note):
   280    179       return note + 12 * (octave+1)
   281    180   
   282    181   
   283         -def generate_csound_score(score, track, channel, t):
          182  +def midify_instr_score(score, track, channel, t):
   284    183       # Assume get_midi_note()
   285    184       global mymidi
   286    185   
   287    186       for token in score:
   288    187           if isinstance(token, parse.Chord):  # Chords
   289    188               for note in token.chord: 
   290    189                   note = get_midi_note(token.octave, note)