def __init__(self, joints=None, max_port=5555): if joints is None: self.joints = [ 'righthand', 'lefthand', 'rightfoot', 'leftfoot', 'head', 'torso' ] else: self.joints = joints self.coords = {k: (0., 0., 0.) for k in self.joints} self.prev_coords = {k: (0., 0., 0.) for k in self.joints} self.joint_speed = {k: False for k in self.joints} self.speed_piano = { 'lefthand': { X: 0, Y: 0 }, 'righthand': { X: 0, Y: 0 } } self.kinect_client = OSCClient() self.max_client = OSCClient() self.server = OSCServer(('127.0.0.1', 12345)) self.kinect_client.connect(('127.0.0.1', 12346)) self.max_client.connect(('127.0.0.1', max_port)) self.server.addMsgHandler('default', self.process_message) self.flipped = False self.speed = 0. self.speed_ramp = 0. sprout(self.server.serve_forever) sprout(self._remind_synapse)
def note(self, pitch=60, dur=1, velocity=80, layer=0, keycode=None): if self.midi_out is None: warnings.warn( "No midi out was set for the object {}. Ignoring note message." .format(self)) return sprout(self._in, pitch, dur, velocity, layer, keycode)
def stop_all(): for section in open_sections: sprout(section.stop) events.disable() for pitch in [octave*12+p for p in (0,1,2,3,4,5,6,7,8,9,10,11) for octave in (0,1,2,3,4,5,6,7,8)]: midi.note(pitch, 5., 127, 5) midi.setSustain(False) print 'stopping' midi.silence = True
def stop_all(): for section in open_sections: sprout(section.stop) events.disable() for pitch in [ octave * 12 + p for p in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) for octave in (0, 1, 2, 3, 4, 5, 6, 7, 8) ]: midi.note(pitch, 5., 127, 5) midi.setSustain(False) print 'stopping' midi.silence = True
def _detect_patterns(self): if len(self._beat_registry) <= self.pattern_period: return; past_events = self._beat_registry[0] present_events = self._beat_registry[self.pattern_period] patterns = [] self._beat_registry = self._beat_registry[-7:] for event1 in past_events: for event2 in present_events: if event1[0] == event2[0]: # if the 2 beats contain the same pitch patterns.append((event1[0], (event1[1]+event2[1])/2, (event1[2]+event2[2])/2)) for pattern in patterns: print "found a pattern:",pattern sprout(self._pattern_loop, pattern)
def __init__(self, joints=None, max_port=5555): if joints is None: self.joints = ['righthand', 'lefthand', 'rightfoot', 'leftfoot', 'head', 'torso'] else: self.joints = joints self.coords = {k:(0.,0.,0.) for k in self.joints} self.prev_coords = {k:(0.,0.,0.) for k in self.joints} self.joint_speed = {k:False for k in self.joints} self.speed_piano = {'lefthand':{X:0, Y:0}, 'righthand':{X:0, Y:0}} self.kinect_client = OSCClient() self.max_client = OSCClient() self.server = OSCServer(('127.0.0.1', 12345)) self.kinect_client.connect(('127.0.0.1', 12346)) self.max_client.connect(('127.0.0.1', max_port)) self.server.addMsgHandler('default', self.process_message) self.flipped = False self.speed = 0. self.speed_ramp = 0. sprout(self.server.serve_forever) sprout(self._remind_synapse)
def _stop(self): sprout(self._fade_out) events.unlisten('facing_back', self.chord_change) events.unlisten('facing_front', self.chord_change)
def __init__(self, channel=1): self._beat_registry = [] self._tasks = [] self.locked_pitches = {} MidiPlayer.__init__(self, channel) sprout(self._sustainLoop)
def start_quantize(self, beat): self.beat = beat self._quantize = True sprout(self._quantize_loop)
def _start(self): sprout(kinect.calc_speed)
def _stop(self): sprout(self._fade_out) events.unlisten('facing_front', self.front_shift) events.unlisten('facing_back', self.back_shift)
def ramp(self, fromVel, toVel, duration): sprout(self._ramp, fromVel, toVel, duration)
def sendToKinect(self, address, items): self._sendMsg(self.kinect_client, address, items) def sendToMax(self, address, items): self._sendMsg(self.max_client, address, items) @staticmethod def _sendMsg(client, address, items): m = OSCMessage() m.setAddress(address) m.append(items) client.send(m) def poll(): while True: kinect.sendToMax('/coords', kinect.coords['head']) kinect.sendToMax('/area', kinect.area) kinect.sendToMax('/speed', kinect.speed_ramp) kinect.sendToMax('/lhspeedx', kinect.speed_piano['lefthand'][X]) kinect.sendToMax('/lhspeedy', kinect.speed_piano['lefthand'][Y]) time.sleep(0.05) if (__name__ == '__main__'): with Kinect() as kinect: sprout(poll) while True: time.sleep(1)
def fade(self, start=0, finish=1, duration=10): self.vel_multiplier = start sprout(self._fade, start, finish, duration)
def chord(self, pitches, dur, velocity, layer=0, keycode=None): self._out(pitches[0], dur, velocity, layer) if pitches > 1: sprout(self._chord, pitches[1:], dur, velocity, layer, keycode)
def __init__(self): sprout(self.collect)
def detect(self, send_token=None): if send_token is None and self.send_token is not None: send_token = self.send_token sprout(self._detect_loop, send_token)
def start(self, hit=False): self.playing = True if hit: sprout(self._hit_play) else: sprout(self._play)
def note(self, pitch=60, dur=1, velocity=80, layer=0, keycode=None): if self.midi_out is None: warnings.warn("No midi out was set for the object {}. Ignoring note message.".format(self)) return sprout(self._in, pitch, dur, velocity, layer, keycode)
def play(self): self._start() self.playing = True sprout(self._play_loop)
def start(self): self.playing = True sprout(self._play)
def __init__(self): self.calculate = True sprout(self._calculate)
def run(self): sprout(kinect.calc_speed) self.playing = True for hand in "lefthand", "righthand": sprout(self._run_hand, hand)
def run(self): sprout(kinect.calc_speed) self.playing = True for hand in 'lefthand', 'righthand': sprout(self._run_hand, hand)