Commit b4dc1137 authored by Kamal Nasser's avatar Kamal Nasser

multiple bodies

parent df2e03d8
......@@ -14,6 +14,12 @@ def get_first_rigid_body(optirx_packet):
return None
def get_all_rigid_bodies(optirx_packet):
if type(optirx_packet) is rx.FrameOfData and len(optirx_packet.rigid_bodies) > 0:
return optirx_packet.rigid_bodies
return None
def get_rigid_body_by_id(id, optirx_packet):
if type(optirx_packet) is rx.FrameOfData and len(optirx_packet.rigid_bodies) > 0:
for body in optirx_packet.rigid_bodies:
......
......@@ -5,7 +5,6 @@ This class is responsible for creating a PYO server
and manipulating the PYO commands that actually create the sound
"""
class PyoHandler:
def __init__(self):
# start the pyo server with the following parameters
......@@ -13,26 +12,40 @@ class PyoHandler:
self.s.start()
# each synth is a sin sound wave
#self.synth = pyo.SuperSaw()
self.synth = pyo.Sine()
self.synth2 = pyo.Sine(.2, mul=0.5, add=0.5).out(2)
self.synth3 = pyo.Sine(.2, mul=0.5, add=0.5).out(3)
#self.synth4 = pyo.Sine(.2, mul=0.5, add=0.5).out(4)
self.synth4 = pyo.SuperSaw()
self._next_out = 1
self.synths = []
self._make_synths()
self._make_synths()
def _get_next_out(self):
o = self._next_out
self._next_out += 1
return o
def _make_synths(self):
s = []
s.append(pyo.Sine().out(self._get_next_out()))
s.append(pyo.Sine(.2, mul=0.5, add=0.5).out(self._get_next_out()))
s.append(pyo.Sine(.2, mul=0.5, add=0.5).out(self._get_next_out()))
# self.synth4 = pyo.Sine(.2, mul=0.5, add=0.5).out(4)
s.append(pyo.SuperSaw().out(self._get_next_out()))
self.synths.append(s)
def change_pyo(self, fr, bal, mul):
def change_pyo(self, idx, fr, bal, mul):
# change the pyo parameters:
# fr = frequency
# mul = volume
fr = fr*fr/600
# start the first sound wave
self.synth.out(1)
self.synth.setFreq(fr)
self.synth.setMul(mul)
self.synths[idx][0].setFreq(fr)
self.synths[idx][0].setMul(mul)
# adding more sin waves for the Y axis
self.synth2.setFreq(fr * 15 / 3)
self.synth3.setFreq(fr * 1.25)
self.synth4.setFreq(fr * 7 / 2)
self.synths[idx][1].setFreq(fr * 7 / 3)
self.synths[idx][2].setFreq(fr * 1.25)
self.synths[idx][3].setFreq(fr * 7 / 1.5)
# changing the amplitude of the waves according to position in Y axis
self.synth2.setMul(mul*bal)
self.synth3.setMul(mul*bal)
self.synth4.setMul(mul*bal)
\ No newline at end of file
self.synths[idx][1].setMul(mul*bal)
self.synths[idx][2].setMul(mul*bal)
self.synths[idx][3].setMul(mul*bal)
\ No newline at end of file
......@@ -2,6 +2,7 @@ import threading
import time
from rtscs_controllers.base_rtscs_controller import BaseRtscsController
from pyo_handler import PyoHandler
import optirx_utils
class SequentialRtscsController(BaseRtscsController):
......@@ -22,10 +23,15 @@ class SequentialRtscsController(BaseRtscsController):
a = PyoHandler()
while not self._is_shutdown_requested():
# get rtscs params form BaseRtscsParamReceiver
transposition, vel_shift, tempo_factor, hint, is_sustain = self._param_receiver.get_rtscs_params()
PyoHandler.change_pyo(a, transposition, vel_shift, tempo_factor)
packet = self._param_receiver._optirx_packet_receiver.get_last_packet()
bodies = optirx_utils.get_all_rigid_bodies(packet)
idx = 0
for body in bodies:
transposition, vel_shift, tempo_factor, hint, is_sustain = self._param_receiver.get_rtscs_params_body(body)
PyoHandler.change_pyo(a, idx, transposition, vel_shift, tempo_factor)
idx += 1
# sleep for duration of msg.time between msgs
time.sleep(0.05)
time.sleep(0.01)
......
......@@ -7,8 +7,8 @@ import optirx_utils
DEFAULT_NOTE_DURATION_PRECISION = 0.125
# rh roll implemented for future use
DEFAULT_OPTITRACK_RANGES_DICT = {'x': (-1.5, 1.3), 'y': (0.0, 2.0), 'z': (-1.5, 1.7), 'rh_roll': (-180, 180)}
DEFAULT_RTSCS_PARAM_RANGES_DICT = {'frequency': (0, 600), 'sins': (0, 0.5),
DEFAULT_OPTITRACK_RANGES_DICT = {'x': (-2, 1.8), 'y': (0.0, 3.0), 'z': (-1.9, 2), 'rh_roll': (-180, 180)}
DEFAULT_RTSCS_PARAM_RANGES_DICT = {'frequency': (0, 700), 'sins': (0, 0.45),
'amplitude': (0.1, 1), 'numerical_hint': (0, 1)}
......@@ -97,6 +97,29 @@ class OptitrackParamReceiver(BaseRtscsParamReceiver):
return transformed_params
def get_rtscs_params_body(self, rh):
"""
Get input from the OptiTrack system streaming engine, transform the data to rtscs_params and return it.
"""
if rh is None or rh.mrk_mean_error == 0:
return 0, 0, 1, 0, False
# mul by -1 to fix flipped coordinates if not fully compatible Motive calibration square
rh_position = list(rh.position) # map(lambda coordinate: -1 * coordinate, rh.position)
# Convert right hand convention to left hand convention for Motive 1.73+ used with CS-200
rh_position[0] = -rh_position[0]
# For convenience convert roll angle from radians to degrees
rh_roll = math.degrees(optirx_utils.orientation2radians(rh.orientation)[0])
# print rh_position
# print rh_roll; return
transformed_params = self.transform_params(rh_position, rh_roll)
# print transformed_params
return transformed_params
def get_rtscs_params(self):
"""
Get input from the OptiTrack system streaming engine, transform the data to rtscs_params and return it.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment