Guest User

Untitled

a guest
Nov 22nd, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.01 KB | None | 0 0
  1. # Ligeti, Musica Ricercata No.7
  2.  
  3.  
  4. from operator import truediv
  5. import pyo
  6.  
  7.  
  8. SERVER = pyo.Server(audio="jack", jackname="No.7")
  9. RH_TEMPO, LH_TEMPO = 176, 180
  10. RH_TENUTO, LH_TENUTO = 1000, 50
  11.  
  12. def assign_device(device="Qsynth"):
  13. "sets the device as midi output device"
  14. for devices in pyo.pa_get_devices_infos():
  15. for idx, d in devices.items():
  16. if d["name"].startswith(device):
  17. SERVER.setMidiOutputDevice(d)
  18. SERVER.boot().start()
  19.  
  20. assign_device()
  21.  
  22.  
  23. class Voice():
  24.  
  25. last_phrase = False
  26.  
  27. def __init__(self, name, notes, durs, register, tempo, chnl, timestamp, velocity, start_delay=0, run=True):
  28. self.name = name
  29. self.notes = notes
  30. self.notes_last_idx = len(notes) - 1
  31. self.idx = 0
  32. self.durs = durs
  33. self.register = register
  34. self.pulse_dur = truediv(self.tempo_to_seconds(tempo), 7) if self.register.upper().startswith("B") else self.tempo_to_seconds(tempo)
  35. self.chnl = chnl
  36. self.timestamp = timestamp
  37. self.velocity = velocity
  38. self.start_delay = start_delay
  39. self.seq = pyo.Seq(time=self.pulse_dur, seq=durs)
  40. if run:
  41. self.ca = pyo.CallAfter(self.seq.play, self.start_delay)
  42. self.trig_func = pyo.TrigFunc(self.seq, self.sing)
  43.  
  44. def tempo_to_seconds(self, tempo):
  45. pulse_dur = truediv(60, tempo)
  46. return pulse_dur
  47.  
  48. def sing(self, ):
  49. pitch = self.notes[self.idx]
  50. if pitch != 0:
  51. if pitch == 96: # 96 = c''''
  52. Voice.last_phrase = True
  53. if Voice.last_phrase:
  54. if self.register.upper().startswith("B"):
  55. if self.notes[0] < 65: # 65 = f'
  56. self.notes = [n + 12 for n in self.notes]
  57. self.ca = pyo.CallAfter(self.change_to_last_octave, self.tempo_to_seconds(116) * 30)
  58. SERVER.noteout(pitch, self.velocity, self.chnl)
  59. SERVER.noteout(pitch, 0, self.chnl, self.timestamp)
  60. if self.idx == self.notes_last_idx:
  61. if self.register.upper().startswith("B"):
  62. self.idx = 0
  63. else:
  64. print self.name, "finished"
  65. self.seq.stop()
  66. else:
  67. self.idx += 1
  68.  
  69. def change_to_last_octave(self, ):
  70. self.notes = [n + 12 for n in self.notes]
  71. self.ca = pyo.CallAfter(self.truncate_first_four_notes, 7)
  72.  
  73. def truncate_first_four_notes(self, ):
  74. self.notes = self.notes[4:]
  75. self.notes_last_idx = len(self.notes) - 1
  76. self.idx = 0
  77. self.ca = pyo.CallAfter(self.truncate_first_five_notes, 5)
  78.  
  79. def truncate_first_five_notes(self, ):
  80. self.notes = self.notes[1:]
  81. self.notes_last_idx = len(self.notes) - 1
  82. self.idx = 0
  83. self.ca = pyo.CallAfter(self.trill, 3)
  84.  
  85. def trill(self, ):
  86. self.durs = [truediv(d, 4) for d in self.durs]
  87. self.seq.seq = self.durs
  88. self.ca = pyo.CallAfter(self.shut_down, 6)
  89.  
  90. def shut_down(self, ):
  91. self.seq.stop()
  92. print self.name, "said goodbye!"
  93.  
  94.  
  95. soprano = Voice("Soprano",
  96. (72, 70, 74, 72, 74, 70, 77, 75, 74, 72, 70, 74, 72, # page 22
  97. 70, 69, 65, 67, 69, 70, 69, 72, 70, 69, 65, 69, 67,
  98. 65, 69, 70, 69, 72, 74, 75, 74, 70, 74, 72,
  99. 70, 69, 65, 69, 67,
  100. 0, 72, 70, 74, 72, 74, 70, 77, 75, 74, # page 23
  101. 72, 70, 74, 72, 70, 69, 65, 67, 69, 70, 69, 72, 70, 69, 65,
  102. 69, 67, 65, 69, 70, 69, 72, 74, 75, 74, 70, 74, 77,
  103. 75, 74, 72, 70, 69, 65, 69, 67, 0,
  104. 84, 82, 86, 84, 86, 82, 89, 87, 86, 84,
  105. 82, 86, 84, 82, 81, 77, 79, 81, 82, 81, 84, # page 24
  106. 82, 81, 77, 81, 79, 77, 81, 82, 81,
  107. 84, 86, 87, 86, 82, 86, 84, 82, 81, 77, 81, 79,
  108. 0, 72, 70, 74, 0, 75, 79, 77,
  109. 79, 75, 82, 80, 79, 77, 75, 79, 77,
  110. 75, 74, 70, 72, 74, 75, 74, 77, 75, 74, 70, 74, 72, # page 25
  111. 0, 84, 86, 87, 86, 82, 89, 87, 86, 84,
  112. 82, 81, 77, 79, 81, 82, 81, 84, 82, 81, 77, 81, 79, 0,
  113. 96, 94, 98, 96, 98, 99, 98, 94, 101, 99, 98, 96),
  114. [7, 1, 1, 7, 1, 1, 5, .5, .5, 1, 1, 1, 6, # page 22
  115. .5, .5, 1.5, .25, .25, 1, 1, 5, .5, .5, 1, 2, 7,
  116. .25, .25, .5, 1, 5, 1, 1, 1, 1, 1, 5,
  117. .5, .5, 1, 2, 6,
  118. 3, 4, 1, 1, 7, 1, 1, 5, .5, .5, # page 23
  119. 1, 1, 1, 6, .5, .5, 1.5, .25, .25, 1, 1, 5, .5, .5, 1,
  120. 2, 4, .25, .25, .5, 1, 5, 1, 1, 1, 1, 1, 3,
  121. .5, .5, 4, .5, .5, 1, 2, 6, 3,
  122. 4, 1, 1, 6, 1, 1, 4, .5, .5, 3,
  123. 1, 1, 6, .5, .5, 1.5, .25, .25, 1, 1, 8, # page 24
  124. .5, .5, 1, 1, 8, .25, .25, 1.5, 1,
  125. 3, 1, 1, 1, 1, 1, 4, .5, .5, 1, 3, 7,
  126. 3, 7, 1, 1, 1, 1, 1, 10,
  127. 1, 1, 2, .5, .5, 4, 1, 1, 7,
  128. .5, .5, 1.5, .25, .25, 1, 1, 4, .5, .5, 1, 2, 7, # page 25
  129. 3, 5, 1, 1, 1, 1, 2, .5, .5, 3,
  130. .5, .5, 1.5, .25, .25, 1, 1, 2, .5, .5, 1, 1, 8, 3,
  131. 4, 1, 1, 5, 1, 1, 1, 1, 3, .5, .5, 11], "Soprano", RH_TEMPO, 1, RH_TENUTO, 120, 5)
  132.  
  133. alto = Voice("Alto",
  134. (0, 69, 67, 70, 69, 70, 67, 72, 70, # page 23
  135. 69, 67, 63, 65, 63, 62,
  136. 58, 60, 69, 70, 72, 70, 67, 70, 69,
  137. 63, 62, 58, 60, 0,
  138. 0, 77, 75, 79, 77, 79, 75, 82, 80, 79,
  139. 77, 75, 79, 77, 75, 74, 70, 0, 72, 74, # page 24
  140. 75, 74, 77, 75, 74, 70, 74, 72, 70, 74, 75,
  141. 74, 77, 79, 80, 79, 75, 79, 77, 75, 74, 70, 74, 72,
  142. 0, 69, 67, 70, 72,
  143. 74, 70, 77, 75, 74, 72, 70, 74, 72, 70, 69, 65,
  144. 67, 69, 70, 69, 72, 70, 68, 70, 69, 65, 69, 67, # page 25
  145. 0, 81, 82, 84, 82, 79, 81,
  146. 0, 77, 72, 0,
  147. 93, 91, 94, 93, 94, 96, 94, 91, 93),
  148. [3, 4, 1, 1, 7, 1, 1, 3, 3, # page 23
  149. 1, 1, 1, 10, 7, 1,
  150. 2, 6, 5, 1, 1, 1, 1, 1, 6,
  151. 3, 1, 2, 6, 3,
  152. 3, 4, 1, 1, 6, 1, 1, 3, .5, .5,
  153. 4, 1, 1, 9, .5, .5, 1, .5, .25, .25, # page 24
  154. 1, 1, 6, .5, .5, 1, 1, 5, .25, .25, 2.5,
  155. 1, 3, 1, 1, 1, 1, 1, 4, .5, .5, 1, 1, 7,
  156. 3, 7, 1, 1, 6,
  157. 1, 1, 2, .5, .5, 8, 1, 1, 4, .5, .5, 1.5,
  158. .25, .25, 1, 1, 1, 4, 3, .5, .5, 1, 1, 10, # page 25
  159. 3, 5, 1, 1, 1, 1, 6,
  160. 1, 9, 8, 3,
  161. 4, 1, 1, 5, 1, 1, 1, 1, 15],
  162. "Alto", RH_TEMPO, 2, RH_TENUTO, 120, soprano.start_delay + 81 * soprano.pulse_dur)
  163.  
  164. tenor = Voice("Tenor",
  165. (69, # page 24, line 4, 2nd bar from end
  166. 70, 67, 72, 70, 69, 67, 63, 65,
  167. 63, 65 # page 25
  168. ),
  169. [6, # page 24, line 4, 2nd bar from end
  170. 1, 1, 2, 1, 8, 1, 1, 19,
  171. 4, 7 # page 25
  172. ], "Tenor", RH_TEMPO, 3, RH_TENUTO, 120, alto.start_delay + 177 * alto.pulse_dur)
  173.  
  174. bass = Voice("Bass", (53, 48, 51, 46, 48, 43, 41), [1], "Bass", LH_TEMPO, 4, LH_TENUTO, 60, 0)
  175.  
  176. SERVER.gui(locals(), exit=False)
Add Comment
Please, Sign In to add comment