Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
university
music_proj
Commits
648459ca
Commit
648459ca
authored
May 28, 2019
by
Kamal Nasser
Browse files
packet server mess
parent
1574d431
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
150 additions
and
4 deletions
+150
-4
pyo_handler.py
pyo_handler.py
+6
-4
socket-server/server.py
socket-server/server.py
+144
-0
No files found.
pyo_handler.py
View file @
648459ca
...
...
@@ -54,18 +54,19 @@ class PyoHandler:
s
=
[]
#### 1 ####
#
#### 1 ####
# 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()))
#
s.append(
pyo.Sine(.2, mul=0.5, add=0.5).out(
self._get_next_out())
)
#
#
s.append(pyo.SuperSaw().out(self._get_next_out()))
#### 2 ####
w
=
pyo
.
Sine
(
freq
=
7
).
out
(
self
.
_get_next_out
())
l
=
pyo
.
LFO
(
freq
=
w
,
type
=
2
).
out
(
self
.
_get_next_out
())
#sl = pyo.SineLoop(freq=w, feedback=l, mul=1).out(self._get_next_out())
s
.
append
(
w
)
s
.
append
(
l
)
#rev = pyo.Delay(sl, delay=[.25, .5]).out(self._get_next_out())
self
.
synths
.
append
(
s
)
...
...
@@ -95,4 +96,5 @@ class PyoHandler:
fr
=
fr
*
fr
/
600
# start the first sound wave
self
.
synths
[
idx
][
0
].
setFreq
(
fr
)
self
.
synths
[
idx
][
0
].
setMul
(
mul
)
\ No newline at end of file
self
.
synths
[
idx
][
0
].
setMul
(
mul
*
bal
)
#self.synths[idx][0].setPhase(bal)
\ No newline at end of file
socket-server/server.py
0 → 100644
View file @
648459ca
import
threading
import
eventlet
import
socketio
import
time
eventlet
.
monkey_patch
()
from
rtscs_param_receivers.optitrack_param_receiver.optitrack_packet_receiver
import
OptitrackPacketReceiver
import
optirx_utils
from
utils
import
clip_value
,
remap_range
,
round_to_precision
import
math
#eventlet.monkey_patch()
DEFAULT_NOTE_DURATION_PRECISION
=
0.125
# rh roll implemented for future use
DEFAULT_OPTITRACK_RANGES_DICT
=
{
'x'
:
(
-
0.9
,
1.5
),
'y'
:
(
-
2.1
,
1.2
),
'z'
:
(
-
0.1
,
2
),
'rh_roll'
:
(
-
180
,
180
)
}
DEFAULT_RTSCS_PARAM_RANGES_DICT
=
{
#'frequency': (0, 700),
#'sins': (0, 0.45),
'frequency'
:
(
0
,
7
),
'sins'
:
(
0
,
7
),
'amplitude'
:
(
0.1
,
1
),
'numerical_hint'
:
(
0
,
1
)
}
sio
=
socketio
.
Server
(
cors_allowed_origins
=
None
)
app
=
socketio
.
WSGIApp
(
sio
)
@
sio
.
on
(
'connect'
)
def
connect
(
sid
,
environ
):
print
(
'connect '
,
sid
)
#eventlet.spawn(deb, sio)
#sio.emit("rh", [1, 2, 3])
@
sio
.
on
(
'my message'
)
def
message
(
sid
,
data
):
print
(
'message '
,
data
)
@
sio
.
on
(
'disconnect'
)
def
disconnect
(
sid
):
print
(
'disconnect '
,
sid
)
def
start_sio
():
eventlet
.
wsgi
.
server
(
eventlet
.
listen
((
''
,
5000
)),
app
)
def
transform_params
(
rh_position
,
rh_roll
,
lh_position
=
None
):
"""
Transforms OptiTrack params into rtscs params
:param rh_position: a (x, y, z) tuple holding the position of the right hand "rigid body"
:param rh_roll: roll angle in degrees of the right hand "rigid body"
:param lh_position: a (x, y, z) tuple holding the position of the left hand "rigid body"
:return: rtscs params tuple as defined in BaseRtscsParamReceiver.get_rtscs_params()
"""
is_sustain
=
False
# TODO: derive is_sustain from distance between rh_position and lh_position
transformed_params
=
rh_position
+
[
rh_roll
,
is_sustain
]
# Remap rh position onto rtscs internal ranges
# x -> frequency
# y -> number of waves which define the complex wave.
# z -> amplitude.
for
i
,
mapped_pair
in
enumerate
(((
'x'
,
'frequency'
),
(
'y'
,
'sins'
),
(
'z'
,
'amplitude'
),
(
'rh_roll'
,
'numerical_hint'
))):
source_low
=
DEFAULT_OPTITRACK_RANGES_DICT
[
mapped_pair
[
0
]][
0
]
source_high
=
DEFAULT_OPTITRACK_RANGES_DICT
[
mapped_pair
[
0
]][
1
]
destination_low
=
DEFAULT_RTSCS_PARAM_RANGES_DICT
[
mapped_pair
[
1
]][
0
]
destination_high
=
DEFAULT_RTSCS_PARAM_RANGES_DICT
[
mapped_pair
[
1
]][
1
]
# clip Optritrack param to the limits of its defined valid range
transformed_params
[
i
]
=
clip_value
(
transformed_params
[
i
],
source_low
,
source_high
)
# translate Optritrack param to rtscs param
transformed_params
[
i
]
=
remap_range
(
transformed_params
[
i
],
source_low
,
source_high
,
destination_low
,
destination_high
)
# convert frequency and number of sins to int
for
i
in
range
(
1
):
transformed_params
[
i
]
=
int
(
round
(
transformed_params
[
i
]))
# round amplitude factor to precision
transformed_params
[
2
]
=
round_to_precision
(
transformed_params
[
2
],
DEFAULT_NOTE_DURATION_PRECISION
)
return
transformed_params
def
get_rtscs_params_body
(
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
return
transform_params
(
rh_position
,
rh_roll
)
optritrack_packet_recv
=
OptitrackPacketReceiver
(
'127.0.0.1'
)
# adjust OptiTrack server IP if needed
optritrack_packet_recv
.
start
()
def
motive_data
():
while
True
:
packet
=
optritrack_packet_recv
.
get_last_packet
()
rh
=
optirx_utils
.
get_first_rigid_body
(
packet
)
if
rh
is
not
None
:
p
=
get_rtscs_params_body
(
rh
)
print
(
p
)
sio
.
emit
(
"rh"
,
p
)
eventlet
.
sleep
(
1
)
def
deb
(
s
):
while
True
:
s
.
emit
(
"rh"
,
[
1
,
2
])
eventlet
.
sleep
(
1
)
print
(
"ok"
)
#eventlet.spawn(motive_data)
#eventlet.wsgi.server(eventlet.listen(('', 5000)), app)
#motive_data()
while
True
:
packet
=
optritrack_packet_recv
.
get_last_packet
()
rh
=
optirx_utils
.
get_first_rigid_body
(
packet
)
print
(
rh
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment