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
b4dc1137
Commit
b4dc1137
authored
May 02, 2019
by
Kamal Nasser
Browse files
multiple bodies
parent
df2e03d8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
21 deletions
+69
-21
optirx_utils.py
optirx_utils.py
+6
-0
pyo_handler.py
pyo_handler.py
+29
-16
rtscs_controllers/sequential_rtscs_controller.py
rtscs_controllers/sequential_rtscs_controller.py
+9
-3
rtscs_param_receivers/optitrack_param_receiver/optitrack_param_receiver.py
...vers/optitrack_param_receiver/optitrack_param_receiver.py
+25
-2
No files found.
optirx_utils.py
View file @
b4dc1137
...
...
@@ -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
:
...
...
pyo_handler.py
View file @
b4dc1137
...
...
@@ -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
.
synth
2
.
setFreq
(
fr
*
15
/
3
)
self
.
synth
3
.
setFreq
(
fr
*
1.25
)
self
.
synth
4
.
setFreq
(
fr
*
7
/
2
)
self
.
synth
s
[
idx
][
1
]
.
setFreq
(
fr
*
7
/
3
)
self
.
synth
s
[
idx
][
2
]
.
setFreq
(
fr
*
1.25
)
self
.
synth
s
[
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
rtscs_controllers/sequential_rtscs_controller.py
View file @
b4dc1137
...
...
@@ -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.0
5
)
time
.
sleep
(
0.0
1
)
...
...
rtscs_param_receivers/optitrack_param_receiver/optitrack_param_receiver.py
View file @
b4dc1137
...
...
@@ -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
,
6
00
),
'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
,
7
00
),
'sins'
:
(
0
,
0.
4
5
),
'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.
...
...
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