Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Ligeti, Musica Ricercata No.7
- from operator import truediv
- import pyo
- SERVER = pyo.Server(audio="jack", jackname="No.7")
- RH_TEMPO, LH_TEMPO = 176, 180
- RH_TENUTO, LH_TENUTO = 1000, 50
- def assign_device(device="Qsynth"):
- "sets the device as midi output device"
- for devices in pyo.pa_get_devices_infos():
- for idx, d in devices.items():
- if d["name"].startswith(device):
- SERVER.setMidiOutputDevice(d)
- SERVER.boot().start()
- assign_device()
- class Voice():
- last_phrase = False
- def __init__(self, name, notes, durs, register, tempo, chnl, timestamp, velocity, start_delay=0, run=True):
- self.name = name
- self.notes = notes
- self.notes_last_idx = len(notes) - 1
- self.idx = 0
- self.durs = durs
- self.register = register
- self.pulse_dur = truediv(self.tempo_to_seconds(tempo), 7) if self.register.upper().startswith("B") else self.tempo_to_seconds(tempo)
- self.chnl = chnl
- self.timestamp = timestamp
- self.velocity = velocity
- self.start_delay = start_delay
- self.seq = pyo.Seq(time=self.pulse_dur, seq=durs)
- if run:
- self.ca = pyo.CallAfter(self.seq.play, self.start_delay)
- self.trig_func = pyo.TrigFunc(self.seq, self.sing)
- def tempo_to_seconds(self, tempo):
- pulse_dur = truediv(60, tempo)
- return pulse_dur
- def sing(self, ):
- pitch = self.notes[self.idx]
- if pitch != 0:
- if pitch == 96: # 96 = c''''
- Voice.last_phrase = True
- if Voice.last_phrase:
- if self.register.upper().startswith("B"):
- if self.notes[0] < 65: # 65 = f'
- self.notes = [n + 12 for n in self.notes]
- self.ca = pyo.CallAfter(self.change_to_last_octave, self.tempo_to_seconds(116) * 30)
- SERVER.noteout(pitch, self.velocity, self.chnl)
- SERVER.noteout(pitch, 0, self.chnl, self.timestamp)
- if self.idx == self.notes_last_idx:
- if self.register.upper().startswith("B"):
- self.idx = 0
- else:
- print self.name, "finished"
- self.seq.stop()
- else:
- self.idx += 1
- def change_to_last_octave(self, ):
- self.notes = [n + 12 for n in self.notes]
- self.ca = pyo.CallAfter(self.truncate_first_four_notes, 7)
- def truncate_first_four_notes(self, ):
- self.notes = self.notes[4:]
- self.notes_last_idx = len(self.notes) - 1
- self.idx = 0
- self.ca = pyo.CallAfter(self.truncate_first_five_notes, 5)
- def truncate_first_five_notes(self, ):
- self.notes = self.notes[1:]
- self.notes_last_idx = len(self.notes) - 1
- self.idx = 0
- self.ca = pyo.CallAfter(self.trill, 3)
- def trill(self, ):
- self.durs = [truediv(d, 4) for d in self.durs]
- self.seq.seq = self.durs
- self.ca = pyo.CallAfter(self.shut_down, 6)
- def shut_down(self, ):
- self.seq.stop()
- print self.name, "said goodbye!"
- soprano = Voice("Soprano",
- (72, 70, 74, 72, 74, 70, 77, 75, 74, 72, 70, 74, 72, # page 22
- 70, 69, 65, 67, 69, 70, 69, 72, 70, 69, 65, 69, 67,
- 65, 69, 70, 69, 72, 74, 75, 74, 70, 74, 72,
- 70, 69, 65, 69, 67,
- 0, 72, 70, 74, 72, 74, 70, 77, 75, 74, # page 23
- 72, 70, 74, 72, 70, 69, 65, 67, 69, 70, 69, 72, 70, 69, 65,
- 69, 67, 65, 69, 70, 69, 72, 74, 75, 74, 70, 74, 77,
- 75, 74, 72, 70, 69, 65, 69, 67, 0,
- 84, 82, 86, 84, 86, 82, 89, 87, 86, 84,
- 82, 86, 84, 82, 81, 77, 79, 81, 82, 81, 84, # page 24
- 82, 81, 77, 81, 79, 77, 81, 82, 81,
- 84, 86, 87, 86, 82, 86, 84, 82, 81, 77, 81, 79,
- 0, 72, 70, 74, 0, 75, 79, 77,
- 79, 75, 82, 80, 79, 77, 75, 79, 77,
- 75, 74, 70, 72, 74, 75, 74, 77, 75, 74, 70, 74, 72, # page 25
- 0, 84, 86, 87, 86, 82, 89, 87, 86, 84,
- 82, 81, 77, 79, 81, 82, 81, 84, 82, 81, 77, 81, 79, 0,
- 96, 94, 98, 96, 98, 99, 98, 94, 101, 99, 98, 96),
- [7, 1, 1, 7, 1, 1, 5, .5, .5, 1, 1, 1, 6, # page 22
- .5, .5, 1.5, .25, .25, 1, 1, 5, .5, .5, 1, 2, 7,
- .25, .25, .5, 1, 5, 1, 1, 1, 1, 1, 5,
- .5, .5, 1, 2, 6,
- 3, 4, 1, 1, 7, 1, 1, 5, .5, .5, # page 23
- 1, 1, 1, 6, .5, .5, 1.5, .25, .25, 1, 1, 5, .5, .5, 1,
- 2, 4, .25, .25, .5, 1, 5, 1, 1, 1, 1, 1, 3,
- .5, .5, 4, .5, .5, 1, 2, 6, 3,
- 4, 1, 1, 6, 1, 1, 4, .5, .5, 3,
- 1, 1, 6, .5, .5, 1.5, .25, .25, 1, 1, 8, # page 24
- .5, .5, 1, 1, 8, .25, .25, 1.5, 1,
- 3, 1, 1, 1, 1, 1, 4, .5, .5, 1, 3, 7,
- 3, 7, 1, 1, 1, 1, 1, 10,
- 1, 1, 2, .5, .5, 4, 1, 1, 7,
- .5, .5, 1.5, .25, .25, 1, 1, 4, .5, .5, 1, 2, 7, # page 25
- 3, 5, 1, 1, 1, 1, 2, .5, .5, 3,
- .5, .5, 1.5, .25, .25, 1, 1, 2, .5, .5, 1, 1, 8, 3,
- 4, 1, 1, 5, 1, 1, 1, 1, 3, .5, .5, 11], "Soprano", RH_TEMPO, 1, RH_TENUTO, 120, 5)
- alto = Voice("Alto",
- (0, 69, 67, 70, 69, 70, 67, 72, 70, # page 23
- 69, 67, 63, 65, 63, 62,
- 58, 60, 69, 70, 72, 70, 67, 70, 69,
- 63, 62, 58, 60, 0,
- 0, 77, 75, 79, 77, 79, 75, 82, 80, 79,
- 77, 75, 79, 77, 75, 74, 70, 0, 72, 74, # page 24
- 75, 74, 77, 75, 74, 70, 74, 72, 70, 74, 75,
- 74, 77, 79, 80, 79, 75, 79, 77, 75, 74, 70, 74, 72,
- 0, 69, 67, 70, 72,
- 74, 70, 77, 75, 74, 72, 70, 74, 72, 70, 69, 65,
- 67, 69, 70, 69, 72, 70, 68, 70, 69, 65, 69, 67, # page 25
- 0, 81, 82, 84, 82, 79, 81,
- 0, 77, 72, 0,
- 93, 91, 94, 93, 94, 96, 94, 91, 93),
- [3, 4, 1, 1, 7, 1, 1, 3, 3, # page 23
- 1, 1, 1, 10, 7, 1,
- 2, 6, 5, 1, 1, 1, 1, 1, 6,
- 3, 1, 2, 6, 3,
- 3, 4, 1, 1, 6, 1, 1, 3, .5, .5,
- 4, 1, 1, 9, .5, .5, 1, .5, .25, .25, # page 24
- 1, 1, 6, .5, .5, 1, 1, 5, .25, .25, 2.5,
- 1, 3, 1, 1, 1, 1, 1, 4, .5, .5, 1, 1, 7,
- 3, 7, 1, 1, 6,
- 1, 1, 2, .5, .5, 8, 1, 1, 4, .5, .5, 1.5,
- .25, .25, 1, 1, 1, 4, 3, .5, .5, 1, 1, 10, # page 25
- 3, 5, 1, 1, 1, 1, 6,
- 1, 9, 8, 3,
- 4, 1, 1, 5, 1, 1, 1, 1, 15],
- "Alto", RH_TEMPO, 2, RH_TENUTO, 120, soprano.start_delay + 81 * soprano.pulse_dur)
- tenor = Voice("Tenor",
- (69, # page 24, line 4, 2nd bar from end
- 70, 67, 72, 70, 69, 67, 63, 65,
- 63, 65 # page 25
- ),
- [6, # page 24, line 4, 2nd bar from end
- 1, 1, 2, 1, 8, 1, 1, 19,
- 4, 7 # page 25
- ], "Tenor", RH_TEMPO, 3, RH_TENUTO, 120, alto.start_delay + 177 * alto.pulse_dur)
- bass = Voice("Bass", (53, 48, 51, 46, 48, 43, 41), [1], "Bass", LH_TEMPO, 4, LH_TENUTO, 60, 0)
- SERVER.gui(locals(), exit=False)
Add Comment
Please, Sign In to add comment