spiffyscore

Check-in [f8034c7dfb]
Login
Overview
SHA1:f8034c7dfb4f7667550169cfa3dc3541fd418429
Date: 2011-11-17 19:55:50
User: brian
Comment: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...)
Timelines: family | ancestors | descendants | both | develop
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2011-11-27
02:03
[821ac3e4d6] Added a volume offset parameter to each instrument. Fixed a bug that kept instruments from always being rendered, and one that broke midi files. (user: brian, tags: develop)
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)
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Modified spiffyscore.py from [5ac9fc3252] to [87c5508f41].

     1      1   #!/usr/bin/env python
     2      2   
     3      3   from __future__ import division
     4         -import ipdb
            4  +#import ipdb
     5      5   import os
     6      6   import random
     7      7   import sys
     8      8   import time
     9      9   
    10     10   from midiutil.MidiFile import MIDIFile as midifile
    11     11   import parse
................................................................................
    18     18   mymidi = midifile(15)
    19     19   
    20     20   def main():
    21     21       composition = {
    22     22           "intro": {
    23     23               "body": {
    24     24                   "lead_instr": {  # Instrument 'melody'
    25         -                    "channel": 6,
    26         -                    "octave": 4,
    27         -                    "duration": 30,
           25  +                    "channel": 8,
           26  +                    "octave": 5,
           27  +                    "duration": 60,
    28     28                       "grammars": {  # Notes for this instrument to use in this piece
    29         -                        "u": ["A/2, B/2, C/2 D/2 (u)", "D2' D2' D2' D2' (x)"],
    30         -                        "v": ["C/2 C/2 C/2 C/2 (w)"],
    31         -                        "w": ["E/2 F/2 E/2 F/2 (u)"],
           29  +                        "u": ["C2' B2 A3 D3 B C' D C2' z (u)", "C2' C2' C2' C2' (x)"],
           30  +                        "v": ["G2 F2 E2 F2 D5 (u)", "B/4 C/4' B/4 A/4 D2 z"],
    32     31                           "x": ["z4 (v)"],
    33     32                       },
    34     33                   },
    35     34                   "follow_instr": {  # Instrument 'bass'
    36     35                       "channel": 4,
    37     36                       "sync": "lead_instr",
    38     37                       "octave": 2,
    39         -                    "duration": 30,
           38  +                    "duration": 60,
           39  +                    "grammars": {  # Notes for this instrument to use in this piece
           40  +                        "u": ["C/2 C/2 C/2 z/2 (u)"],
           41  +                    },
           42  +                },
           43  +            },
           44  +        },
           45  +        "section1": {
           46  +            "body": {
           47  +                "lead_instr": {  # Instrument 'melody'
           48  +                    "channel": 6,
           49  +                    "octave": 5,
           50  +                    "duration": 60,
           51  +                    "grammars": {  # Notes for this instrument to use in this piece
           52  +                        "u": ["C E A F G z (u)", "C E A F G z (v)"],
           53  +                        "v": ["A/2 D/2 G/2 C/2 | F/2 B/2 E/2 z/2 | (u)"],
           54  +                    },
           55  +                },
           56  +                "follow_instr": {  # Instrument 'bass'
           57  +                    "channel": 4,
           58  +                    "sync": "lead_instr",
           59  +                    "octave": 2,
           60  +                    "duration": 60,
    40     61                       "grammars": {  # Notes for this instrument to use in this piece
    41         -                        "u": ["E F G E (v)"],
    42         -                        "v": ["G A A A (e)", "G A A A (v)"],
    43         -                        "e": ["B A G A (u)"],
    44         -                        "x": ["z4 (e)"],
           62  +                        "u": ["C/2 C/2 C/2 z/2 (u)"],
    45     63                       },
    46     64                   },
    47     65               },
    48     66           },
    49     67       }
    50         -    print '''f1 0 512 10 1
    51         -f2 0 8192 10 .24 .64 .88 .76 .06 .5 .34 .08
    52         -f3 0 1025 10 1
    53         -t 0 60
    54         -    '''
    55     68   
    56     69       section_start = 0
    57         -    for section in ["intro"]:
    58         -        print "; Section " + section
           70  +    for section in ["intro", "section1"]:
           71  +        print "Section " + section
    59     72           subsection_start = section_start
    60     73           section = composition[section]
    61     74           for subsection in ["intro", "body", "outro"]:
    62     75               try:
    63         -                print "; Subsection " + subsection
           76  +                print "Subsection " + subsection
    64     77                   subsection = section[subsection]
    65     78   
    66     79                   unordered_instrs = []
    67     80                   for instr in subsection:
    68     81                       subsection[instr]["name"] = instr
    69     82                       if not "sync" in subsection[instr].keys():
    70     83                           subsection[instr]["sync"] = None
................................................................................
    72     85                   ordered_instrs = topsort.topsort(unordered_instrs)
    73     86                   ordered_instrs.remove(None)  # None used as a placeholder for sort order for instruments with no sync setting
    74     87   
    75     88                   instrs = []
    76     89                   syncs = {}
    77     90                   track = 0
    78     91                   for instr in ordered_instrs:
    79         -                    print ";Instrument " + instr
           92  +                    print "Instrument " + instr
    80     93                       instr = subsection[instr]
    81     94                       max_time = instr["duration"]
    82     95                       instr_score, syncs = render_instr(instr, syncs, max_time)
    83     96                       instrs.append(instr_score)
    84     97                       midify_instr_score(instr_score, track, instr["channel"], subsection_start)
    85     98                   longest_score = max(instrs, key=lambda i: score_len(i))
    86     99                   subsection_start += score_len(longest_score)
................................................................................
   136    149               grammar = sync_node
   137    150           else:
   138    151               grammar = random.choice(time_filtered_grammars.keys())
   139    152       if score is None:
   140    153           grammar = random.choice(time_filtered_grammars.keys())
   141    154       elif instr["sync"] is None:
   142    155           grammar = get_next_node(score);
          156  +        if grammar not in instr["grammars"].keys():
          157  +            raise Exception("You tried to direct a grammar to a node that doesn't exist")
   143    158       phrases = time_filtered_grammars[grammar]
   144    159       if instr["name"] not in syncs.keys():
   145    160           syncs[instr["name"]] = []
   146    161       syncs[instr["name"]].append({"node": grammar, "time": current_time})
   147    162   
   148    163       return random.choice(phrases), syncs
   149    164