def note(self, pitch=60, dur=1, velocity=80, layer=0, keycode=None, affect=True): if pitch in self.locked_pitches and keycode != self.locked_pitches[pitch]: #print 'restricted pitch',pitch return if self.silence: return if velocity <= 1 and type(velocity) is float: adjusted_velocity = int(round(scale(velocity, 0., 1., *self.velocity_scale))) else: adjusted_velocity = int(round(scale(velocity, 0, 127, *self.velocity_scale))) if self.sustain: dur = 0.1 # set duration to minimum, since pedal will be down anyway. if affect: self._addFunc(MidiPlayer.note, self, pitch, dur, adjusted_velocity, layer) else: MidiPlayer.note(self, pitch, dur, velocity, layer)
def _sustainLoop(self): while True: MidiPlayer.setSustain(self, self.sustain) time.sleep(1.)
def __init__(self, channel=1): self._beat_registry = [] self._tasks = [] self.locked_pitches = {} MidiPlayer.__init__(self, channel) sprout(self._sustainLoop)