Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 def _stop(self):
     sprout(self._fade_out)
     events.unlisten('facing_back', self.chord_change)
     events.unlisten('facing_front', self.chord_change)
Exemplo n.º 8
0
 def __init__(self, channel=1):
     self._beat_registry = []
     self._tasks = []
     self.locked_pitches = {}
     MidiPlayer.__init__(self, channel)
     sprout(self._sustainLoop)
Exemplo n.º 9
0
 def start_quantize(self, beat):
     self.beat = beat
     self._quantize = True
     sprout(self._quantize_loop)
Exemplo n.º 10
0
 def _start(self):
     sprout(kinect.calc_speed)
Exemplo n.º 11
0
 def _stop(self):
     sprout(self._fade_out)
     events.unlisten('facing_front', self.front_shift)
     events.unlisten('facing_back', self.back_shift)
Exemplo n.º 12
0
 def ramp(self, fromVel, toVel, duration):
     sprout(self._ramp, fromVel, toVel, duration)
Exemplo n.º 13
0
    
    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)
        
    
Exemplo n.º 14
0
 def _start(self):
     sprout(kinect.calc_speed)
Exemplo n.º 15
0
 def fade(self, start=0, finish=1, duration=10):
     self.vel_multiplier = start
     sprout(self._fade, start, finish, duration)
Exemplo n.º 16
0
 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)
Exemplo n.º 17
0
 def __init__(self):
     sprout(self.collect)
Exemplo n.º 18
0
 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)
Exemplo n.º 19
0
 def _stop(self):
     sprout(self._fade_out)
     events.unlisten('facing_front', self.front_shift)
     events.unlisten('facing_back', self.back_shift)
Exemplo n.º 20
0
 def start(self, hit=False):
     self.playing = True
     if hit:
         sprout(self._hit_play)
     else:
         sprout(self._play)
Exemplo n.º 21
0
 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)
Exemplo n.º 22
0
 def play(self):
     self._start()
     self.playing = True
     sprout(self._play_loop)
Exemplo n.º 23
0
 def play(self):
     self._start()
     self.playing = True
     sprout(self._play_loop)
Exemplo n.º 24
0
 def start(self, hit=False):
     self.playing = True
     if hit:
         sprout(self._hit_play)
     else:
         sprout(self._play)
Exemplo n.º 25
0
 def start(self):
     self.playing = True
     sprout(self._play)
Exemplo n.º 26
0
 def start(self):
     self.playing = True
     sprout(self._play)
Exemplo n.º 27
0
 def _stop(self):
     sprout(self._fade_out)
     events.unlisten('facing_back', self.chord_change)
     events.unlisten('facing_front', self.chord_change)
Exemplo n.º 28
0
 def __init__(self):
     self.calculate = True
     sprout(self._calculate)
Exemplo n.º 29
0
 def ramp(self, fromVel, toVel, duration):
     sprout(self._ramp, fromVel, toVel, duration)
Exemplo n.º 30
0
 def __init__(self):
     sprout(self.collect)
Exemplo n.º 31
0
 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)
Exemplo n.º 32
0
 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)
Exemplo n.º 33
0
    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)
Exemplo n.º 34
0
 def fade(self, start=0, finish=1, duration=10):
     self.vel_multiplier = start
     sprout(self._fade, start, finish, duration)
Exemplo n.º 35
0
 def run(self):
     sprout(kinect.calc_speed)
     self.playing = True
     for hand in "lefthand", "righthand":
         sprout(self._run_hand, hand)
Exemplo n.º 36
0
 def run(self):
     sprout(kinect.calc_speed)
     self.playing = True
     for hand in 'lefthand', 'righthand':
         sprout(self._run_hand, hand)