fork download
  1. #!/usr/bin/python2
  2. book = """Let the Priests of the Raven of dawn,
  3. no longer in deadly black, with hoarse note
  4. curse the sons of joy. Nor his accepted
  5. brethren, whom, tyrant, he calls free lay the
  6. bound or build the roof. Nor pale religious
  7. letchery call that virginity, that wishes
  8. but acts not.
  9.  
  10. For every thing that lives is Holy."""
  11.  
  12. craw = [
  13. 'a;43_24',
  14. 'b;44_24',
  15. 'c;46_24',
  16. 'd;48_24',
  17. 'e;49_24',
  18. 'f;51_24',
  19. 'g;53_24',
  20. 'h;55_24',
  21. 'i;43_96',
  22. 'j;44_96',
  23. 'k;46_96',
  24. 'l;48_96',
  25. 'm;49_96',
  26. 'n;51_96',
  27. 'o;53_96',
  28. 'p;55_96',
  29. 'q;43_192',
  30. 'r;44_192',
  31. 's;46_192',
  32. 't;48_192',
  33. 'u;49_192',
  34. 'v;51_192',
  35. 'w;53_192',
  36. 'x;55_192',
  37. 'y;43_384',
  38. 'z;44_384',
  39. ' ;-12_24',
  40. ', ;-12_240',
  41. '\n;-12_384',
  42. ':\n;-12_768',
  43. '. ;-12_960']
  44. chars = {}
  45. for cline in craw:
  46. char = cline.split(';')
  47. chars[char[1]] = char[0]
  48.  
  49. import string, sys
  50. book = string.replace(book, ' ', '')
  51. book = string.replace(book, '\n', '')
  52.  
  53. f = open(sys.argv[1], 'r')
  54.  
  55. tracks = {}
  56.  
  57. while 1:
  58. line = f.readline()
  59. if not line:
  60. break
  61. line = line.strip('\n').split(', ')
  62. try:
  63. tracks[int(line[0])]
  64. except KeyError:
  65. tracks[int(line[0])] = []
  66. tracks[int(line[0])].append(line[1:])
  67.  
  68. #print tracks
  69.  
  70.  
  71. notes = {}
  72. for tid in tracks.keys():
  73. track = tracks[tid]
  74. notelist = []
  75. lasttime = 0
  76. for event in track:
  77. # print event
  78. note = None
  79. if event[1] == 'Note_on_c':
  80. if int(event[0]) != lasttime:
  81. #there was a delay
  82. d = int(event[0])-lasttime
  83. note = 0
  84. elif event[1] == 'Note_off_c':
  85. d = int(event[0]) - lasttime
  86. note = int(event[3])
  87. if note != None:
  88. d = d
  89. #num = note+d
  90. #print 'Note:\t%d\tDur:\t%d\tNum:\t%d' % (note, d, num)
  91. notelist.append([lasttime, note, d])
  92. lasttime = int(event[0])
  93. notes[tid] = notelist
  94.  
  95. message = ''
  96.  
  97. for notenum in range(len(notes[2])):
  98. note = notes[2][notenum]
  99. key = str(note[1]-12)+'_'+str(note[2])
  100. try:
  101. message += chars[key]
  102. except KeyError:
  103. message += key
  104. #print "oops: "+key
  105. # try:
  106. # message += book[num]
  107. # except IndexError:
  108. # message += '_'
  109.  
  110. print message
  111.  
  112. #print len(book)
  113.  
Runtime error #stdin #stdout 0.03s 6692KB
stdin
Standard input is empty
stdout
Standard output is empty