-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosc-player.py
executable file
·148 lines (94 loc) · 3.75 KB
/
osc-player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 13 09:25:19 2017
@author: anwaldt
"""
########################################################################################
# Start Stuff
########################################################################################
import numpy as np
import time
import jack
from pythonosc import udp_client
from pythonosc import osc_message_builder as omb
from os import listdir
from os.path import isfile, join
import argparse
########################################################################################
#
########################################################################################
def osc_player(oscPath):
osc_client = udp_client.SimpleUDPClient("127.0.0.1", 50001)
osc_client.send_message("/poll",' ')
########################################################################################
#
########################################################################################
jack_client = jack.Client('osc-player')
jack_client.activate();
########################################################################################
#
########################################################################################
oscFiles = [f for f in listdir(oscPath) if isfile(join(oscPath, f))]
N = len(oscFiles)
t=[]
ID = []
x=[]
y=[]
for i in oscFiles:
print(["loading".__add__(i)])
positions = np.loadtxt(oscPath.__add__(i), delimiter='\t', usecols=(1,2,3,4))
msg = omb.OscMessageBuilder(address="/source/new")
msg.add_arg(str(i) , "s")
msg.add_arg("point")
msg.add_arg("1", "s")
msg.add_arg(positions[1,2], "f")
msg.add_arg(positions[1,3], "f")
msg.add_arg(1.0, "f") #orientation
msg.add_arg(1.0, "f")
#msg.add_arg(1, "i")
#msg.add_arg("1", "s")
msg.add_arg(False,"F")
msg.add_arg(False,"F")
msg.add_arg(False,"F")
msg=msg.build()
osc_client.send(msg)
t.append(positions[:,0])
ID.append(positions[:,1])
x.append(positions[:,2])
y.append(positions[:,3])
print('All files read - ready for playback!')
jackPos = jack_client.transport_frame
last_jackPos= jackPos;
while 1:
#print(jackPos)
#print(last_jackPos)
jackPos = jack_client.transport_frame
if jackPos != last_jackPos:
for i in range(0,N):
#print(str(i) + "position")
tmpIdx = np.argmin(np.abs(t[i] -jackPos))
msg = omb.OscMessageBuilder(address="/source/position")
msg.add_arg(ID[i][tmpIdx])
msg.add_arg(x[i][tmpIdx]*5)
msg.add_arg(y[i][tmpIdx]*- 5)
msg=msg.build()
osc_client.send(msg)
last_jackPos = jackPos;
time.sleep(0.020)
#########################################################################################
##
#########################################################################################
#
#
#
#
#########################################################################################
##
#########################################################################################
if __name__== "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--oscpath",
default =".",help="The osc-path")
args = parser.parse_args()
osc_player(args.oscpath)