spiffyscore

Check-in [b5a8b20242]
Login
Overview
SHA1:b5a8b202425e299491f6a7e3d9f1dd7502f81244
Date: 2011-11-03 18:34:00
User: brian
Comment:Fixed program to now handle notes with accidentals
Timelines: family | ancestors | descendants | both | feature/diskin2
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2011-11-03
18:49
[1bc01ba9c9] Closed-Leaf: By magic, fixed problem with not all bass notes playing via diskin2 (user: brian, tags: feature/diskin2)
18:34
[b5a8b20242] Fixed program to now handle notes with accidentals (user: brian, tags: feature/diskin2)
2011-11-01
19:46
[c9abf46a9f] Got diskin2 sample method partially working; it won't play all of the files, though (user: brian, tags: feature/diskin2)
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Modified parse.py from [2afbfc4534] to [a8d0994825].

     4      4   
     5      5   from ply import lex, yacc
     6      6   class Note():
     7      7       def __init__(self, value, duration=1, octave=8):
     8      8           self.value = value
     9      9           self.duration = duration
    10     10           self.octave = octave
    11         -        self.accidental = None
    12     11       def __repr__(self):
    13     12           return "Note %s %s %s" % (self.value, self.duration, self.octave)
    14     13   
    15     14   class Chord():
    16     15       def __init__(self, value, duration=1, chord_type="major", octave=5):
    17     16           self.value = value
    18     17           self.duration = duration
................................................................................
    42     41           "NODE",
    43     42       )
    44     43   
    45     44       t_ignore = " |"
    46     45   
    47     46       t_BASENOTE = r"[A-Ga-g]"
    48     47   #    t_BASENOTE = r"I+V?|VI*|i+v?|vi*"
    49         -    t_ACCIDENTAL = r"\^{1,2}|_{1,2}|="
           48  +    t_ACCIDENTAL = r"\^{1}|_{1}|="
    50     49       t_REST = r"z"
    51     50       t_OCTAVE = r"'+|,+"
    52     51       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"
    53     52       t_PAREN = "\(|\)"
    54     53       t_SYNCOPATE = "\+|-"
    55     54       t_NODE = r"\([a-zA-Z0-9_-]+\)"
    56     55   
................................................................................
   120    119           '''
   121    120           note.syncopate = p[2]
   122    121   
   123    122   
   124    123       def p_accidental(p):
   125    124           '''note : ACCIDENTAL note
   126    125           '''
   127         -        p[2].accidental = p[1]
          126  +        if p[1] == "^":
          127  +            p[2].value += "#"
          128  +        else:
          129  +            p[2].value += "b"
   128    130           p[0] = p[2]
   129    131   
   130    132       def p_octave(p):
   131    133           '''note : note OCTAVE
   132    134           '''
   133    135           count = len(p[2])
   134    136           increment_or_decrement = 1 if p[2].startswith("'") else -1
................................................................................
   151    153       def p_node(p):
   152    154           '''node : NODE
   153    155           '''
   154    156           p[0] = tree.Tree(p[1].strip("(").strip(")"))
   155    157   
   156    158   
   157    159       def p_error(p):
          160  +#        import ipdb
          161  +#        ipdb.set_trace()
   158    162           print p
   159    163           raise Exception("Syntax error at '%s' of element type %s" % (p.value, p.type))
   160    164           
   161    165       yacc.yacc()
   162    166   
   163    167       return yacc.parse(score)

Modified spiffyscore.py from [7509ae0a18] to [d189f30210].

   117    117   #                },
   118    118                   "follow_instr": {  # Instrument 'melody'
   119    119                       "score_line": "i3 %(time)f %(duration)f 7000 %(octave)d.%(note)s",
   120    120   #                    "sync": "lead_instr",
   121    121                       "octave": 2,
   122    122                       "duration": 30,
   123    123                       "grammars": {  # Notes for this instrument to use in this piece
   124         -                        "u": ["E F G E (v)"],
   125         -                        "v": ["G A A A (e)", "G A A A (v)"],
   126         -                        "e": ["B A G A (v)"],
          124  +                        "u": ["A ^A B C ^C D ^D E F ^F G ^G"],
          125  +#                        "u": ["E F G E (v)"],
          126  +#                        "v": ["G A A A (e)", "G A A A (v)"],
          127  +#                        "e": ["B A G A (v)"],
   127    128                       },
   128    129                   },
   129    130               },
   130    131           },
   131    132       }
   132    133       print '''f1 0 512 10 1
   133    134   f2 0 8192 10 .24 .64 .88 .76 .06 .5 .34 .08
................................................................................
   253    254               total += n.duration
   254    255       return total
   255    256   
   256    257   
   257    258   def generate_csound_score(score, score_line, t):
   258    259       csound_note_values = {
   259    260           "C": "00",
   260         -        "C#": "01",
          261  +        "C#": "01", "Db": "01",
   261    262           "D": "02",
   262         -        "D#": "03",
          263  +        "D#": "03", "Eb": "03",
   263    264           "E": "04",
   264    265           "F": "05",
   265         -        "F#": "06",
          266  +        "F#": "06", "Gb": "06",
   266    267           "G": "07",
   267         -        "G#": "08",
          268  +        "G#": "08", "Ab": "08",
   268    269           "A": "09",
   269         -        "A#": "10",
          270  +        "A#": "10", "Bb": "10",
   270    271           "B": "11",
   271    272       }
   272    273       csound_score = []
   273    274       for token in score:
   274    275           if isinstance(token, parse.Chord):  # Chords
   275    276               for note in token.chord: 
   276    277                   note = csound_note_values[note]
          278  +                csound_score.append(score_line % {"time": t, "octave": token.octave, "note": note, "duration": token.duration})
   277    279                   csound_score.append(score_line % {"time": t, "octave": token.octave, "note": note, "duration": token.duration})
   278    280           elif isinstance(token, parse.Note):  # Individual notes
   279    281               note = csound_note_values[token.value]
   280    282               csound_score.append(score_line % {"time": t, "octave": token.octave, "note": note, "duration": token.duration})
   281    283           elif isinstance(token, tree.Tree):
   282    284               continue
   283    285           t += token.duration
   284    286       return csound_score
   285    287   
   286    288   
   287    289   if __name__ == "__main__": main()